Skip to content
This repository was archived by the owner on Oct 31, 2025. It is now read-only.

Add a new experimental API to set additional image operands#1039

Merged
oisyn merged 9 commits intomainfrom
aux-fetch-params
Apr 21, 2023
Merged

Add a new experimental API to set additional image operands#1039
oisyn merged 9 commits intomainfrom
aux-fetch-params

Conversation

@oisyn
Copy link
Copy Markdown
Contributor

@oisyn oisyn commented Apr 20, 2023

This PR adds a new experimental API to set additional image operands when sampling textures. Currently, it supports bias, lod, grad and sample_index operands.

Usage:

use spirv_std::spirv;
use spirv_std::{arch, image::sample_with, image::ImageWithMethods, Image, Sampler};

#[spirv(fragment)]
pub fn main(
    #[spirv(descriptor_set = 0, binding = 0)] sampler: &Sampler,
    #[spirv(descriptor_set = 0, binding = 1)] image1: &Image!(2D, type=f32, sampled, multisampled),
    #[spirv(descriptor_set = 0, binding = 2)] image2: &Image!(2D, type=f32, sampled),
    output: &mut glam::Vec4,
) {
    let t1 = image1.fetch_with(glam::IVec2::new(0, 0), sample_with::sample_index(1));
    let t2 = image2.sample_with(*sampler, glam::Vec2::new(0.5, 0.5), sample_with::bias(1.0));
    let t3 = image2.sample_with(*sampler, glam::Vec2::new(0.5, 0.5), sample_with::lod(2.0));
    let t4 = image2.sample_with(
        *sampler,
        glam::Vec2::new(0.5, 0.5),
        sample_with::grad(glam::Vec2::new(0.5, 0.5), glam::Vec2::new(0.5, 0.5)),
    );
    *output = t1 + t2 + t3 + t4;
}

Technically the API supports chaining of multiple operands, e.g. sample_with::bias(3.0).sample_index(1), although none of the currently supported operands can logically be combined.

The sampling methods are part of the image::ImageWithMethods trait, and it supports the following methods:

  • fetch_with
  • gather_with
  • sample_with
  • sample_depth_reference_with
  • sample_with_project_coordinate_with
  • sample_depth_reference_with_project_coordinate_with

Future improvements: support more operands, pervent combining mutually exclusive operands, and better error messaging when you use an unsupported operand on a specific sampling function.

@oisyn oisyn force-pushed the aux-fetch-params branch from 9a08ba8 to 42617d8 Compare April 21, 2023 14:27
@oisyn oisyn changed the title WIP Image operands Add a new experimental API to set additional image operands Apr 21, 2023
@oisyn oisyn marked this pull request as ready for review April 21, 2023 15:49
@oisyn oisyn enabled auto-merge (rebase) April 21, 2023 16:17
@oisyn oisyn merged commit 51dec9f into main Apr 21, 2023
@oisyn oisyn deleted the aux-fetch-params branch April 21, 2023 16:42
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants