Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 9 commits into from
Apr 21, 2023

Conversation

oisyn
Copy link
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 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 join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants