From ce4264c622b7df5f1ef10c6c2f8da0df4a777098 Mon Sep 17 00:00:00 2001 From: Jesse Welnick Date: Sun, 28 Mar 2021 17:54:04 +0900 Subject: [PATCH 1/2] feat: Added instructions for depth reference and project coordinate image instructions --- crates/spirv-std/src/textures.rs | 468 +++++++++++++++++- .../ui/image/sample_depth_reference/sample.rs | 19 + .../sample_depth_reference/sample_gradient.rs | 23 + .../sample_depth_reference/sample_lod.rs | 19 + .../sample.rs | 14 + .../sample_gradient.rs | 16 + .../sample_lod.rs | 14 + .../sample_with_project_coordinate/sample.rs | 14 + .../sample_gradient.rs | 15 + .../sample_lod.rs | 14 + 10 files changed, 615 insertions(+), 1 deletion(-) create mode 100644 tests/ui/image/sample_depth_reference/sample.rs create mode 100644 tests/ui/image/sample_depth_reference/sample_gradient.rs create mode 100644 tests/ui/image/sample_depth_reference/sample_lod.rs create mode 100644 tests/ui/image/sample_depth_reference_with_project_coordinate/sample.rs create mode 100644 tests/ui/image/sample_depth_reference_with_project_coordinate/sample_gradient.rs create mode 100644 tests/ui/image/sample_depth_reference_with_project_coordinate/sample_lod.rs create mode 100644 tests/ui/image/sample_with_project_coordinate/sample.rs create mode 100644 tests/ui/image/sample_with_project_coordinate/sample_gradient.rs create mode 100644 tests/ui/image/sample_with_project_coordinate/sample_lod.rs diff --git a/crates/spirv-std/src/textures.rs b/crates/spirv-std/src/textures.rs index b6aac362a9..e49247c69b 100644 --- a/crates/spirv-std/src/textures.rs +++ b/crates/spirv-std/src/textures.rs @@ -44,6 +44,7 @@ impl Image2d { result } } + #[spirv_std_macros::gpu_only] /// Sample the image at a coordinate by a lod pub fn sample_by_lod>( @@ -71,6 +72,7 @@ impl Image2d { } result } + #[spirv_std_macros::gpu_only] /// Sample the image based on a gradient formed by (dx, dy). Specifically, ([du/dx, dv/dx], [du/dy, dv/dy]) pub fn sample_by_gradient>( @@ -101,6 +103,278 @@ impl Image2d { } result } + + #[spirv_std_macros::gpu_only] + pub fn sample_with_project_coordinate>( + &self, + sampler: Sampler, + project_coordinate: impl Vector, + ) -> V { + unsafe { + let mut result = Default::default(); + asm!( + "%image = OpLoad _ {this}", + "%sampler = OpLoad _ {sampler}", + "%project_coordinate = OpLoad _ {project_coordinate}", + "%sampledImage = OpSampledImage _ %image %sampler", + "%result = OpImageSampleProjImplicitLod _ %sampledImage %project_coordinate", + "OpStore {result} %result", + result = in(reg) &mut result, + this = in(reg) self, + sampler = in(reg) &sampler, + project_coordinate = in(reg) &project_coordinate, + ); + result + } + } + + #[spirv_std_macros::gpu_only] + /// Sample the image with a project coordinate by a lod + pub fn sample_with_project_coordinate_by_lod>( + &self, + sampler: Sampler, + project_coordinate: impl Vector, + lod: f32, + ) -> V { + let mut result = Default::default(); + unsafe { + asm!( + "%image = OpLoad _ {this}", + "%sampler = OpLoad _ {sampler}", + "%project_coordinate = OpLoad _ {project_coordinate}", + "%lod = OpLoad _ {lod}", + "%sampledImage = OpSampledImage _ %image %sampler", + "%result = OpImageSampleProjExplicitLod _ %sampledImage %project_coordinate Lod %lod", + "OpStore {result} %result", + result = in(reg) &mut result, + this = in(reg) self, + sampler = in(reg) &sampler, + project_coordinate = in(reg) &project_coordinate, + lod = in(reg) &lod + ); + } + result + } + + #[spirv_std_macros::gpu_only] + /// Sample the image with a project coordinate based on a gradient formed by (dx, dy). Specifically, ([du/dx, dv/dx], [du/dy, dv/dy]) + pub fn sample_with_project_coordinate_by_gradient>( + &self, + sampler: Sampler, + project_coordinate: impl Vector, + gradient_dx: impl Vector, + gradient_dy: impl Vector, + ) -> V { + let mut result = Default::default(); + unsafe { + asm!( + "%image = OpLoad _ {this}", + "%sampler = OpLoad _ {sampler}", + "%project_coordinate = OpLoad _ {project_coordinate}", + "%gradient_dx = OpLoad _ {gradient_dx}", + "%gradient_dy = OpLoad _ {gradient_dy}", + "%sampledImage = OpSampledImage _ %image %sampler", + "%result = OpImageSampleProjExplicitLod _ %sampledImage %project_coordinate Grad %gradient_dx %gradient_dy", + "OpStore {result} %result", + result = in(reg) &mut result, + this = in(reg) self, + sampler = in(reg) &sampler, + project_coordinate = in(reg) &project_coordinate, + gradient_dx = in(reg) &gradient_dx, + gradient_dy = in(reg) &gradient_dy, + ); + } + result + } + + #[spirv_std_macros::gpu_only] + /// Sample the image's depth reference + pub fn sample_depth_reference( + &self, + sampler: Sampler, + coordinate: impl Vector, + depth_reference: f32, + ) -> f32 { + let mut result = Default::default(); + unsafe { + asm!( + "%image = OpLoad _ {this}", + "%sampler = OpLoad _ {sampler}", + "%coordinate = OpLoad _ {coordinate}", + "%depth_reference = OpLoad _ {depth_reference}", // not required to do this way, but done for consistency + "%sampledImage = OpSampledImage _ %image %sampler", + "%result = OpImageSampleDrefImplicitLod _ %sampledImage %coordinate %depth_reference", + "OpStore {result} %result", + result = in(reg) &mut result, + this = in(reg) self, + sampler = in(reg) &sampler, + coordinate = in(reg) &coordinate, + depth_reference = in(reg) &depth_reference, + ); + } + result + } + + #[spirv_std_macros::gpu_only] + /// Sample the image's depth reference based on an explicit lod + pub fn sample_depth_reference_by_lod( + &self, + sampler: Sampler, + coordinate: impl Vector, + depth_reference: f32, + lod: f32, + ) -> f32 { + let mut result = Default::default(); + unsafe { + asm!( + "%image = OpLoad _ {this}", + "%sampler = OpLoad _ {sampler}", + "%coordinate = OpLoad _ {coordinate}", + "%depth_reference = OpLoad _ {depth_reference}", + "%lod = OpLoad _ {lod}", + "%sampledImage = OpSampledImage _ %image %sampler", + "%result = OpImageSampleDrefExplicitLod _ %sampledImage %coordinate %depth_reference Lod %lod", + "OpStore {result} %result", + result = in(reg) &mut result, + this = in(reg) self, + sampler = in(reg) &sampler, + coordinate = in(reg) &coordinate, + depth_reference = in(reg) &depth_reference, + lod = in(reg) &lod, + ) + } + result + } + + #[spirv_std_macros::gpu_only] + /// Sample the image's depth reference based on a gradient formed by (dx, dy). + /// Specifically, ([du/dx, dv/dx], [du/dy, dv/dy]) + pub fn sample_depth_reference_by_gradient( + &self, + sampler: Sampler, + coordinate: impl Vector, + depth_reference: f32, + gradient_dx: impl Vector, + gradient_dy: impl Vector, + ) -> f32 { + let mut result = Default::default(); + unsafe { + asm!( + "%image = OpLoad _ {this}", + "%sampler = OpLoad _ {sampler}", + "%coordinate = OpLoad _ {coordinate}", + "%depth_reference = OpLoad _ {depth_reference}", + "%gradient_dx = OpLoad _ {gradient_dx}", + "%gradient_dy = OpLoad _ {gradient_dy}", + "%sampledImage = OpSampledImage _ %image %sampler", + "%result = OpImageSampleDrefExplicitLod _ %sampledImage %coordinate %depth_reference Grad %gradient_dx %gradient_dy", + "OpStore {result} %result", + result = in(reg) &mut result, + this = in(reg) self, + sampler = in(reg) &sampler, + coordinate = in(reg) &coordinate, + depth_reference = in(reg) &depth_reference, + gradient_dx = in(reg) &gradient_dx, + gradient_dy = in(reg) &gradient_dy, + ); + } + result + } + + #[spirv_std_macros::gpu_only] + /// Sample the image's depth reference with the project coordinate + pub fn sample_depth_reference_with_project_coordinate( + &self, + sampler: Sampler, + project_coordinate: impl Vector, + depth_reference: f32, + ) -> f32 { + let mut result = Default::default(); + unsafe { + asm!( + "%image = OpLoad _ {this}", + "%sampler = OpLoad _ {sampler}", + "%project_coordinate = OpLoad _ {project_coordinate}", + "%depth_reference = OpLoad _ {depth_reference}", // not required to do this way, but done for consistency + "%sampledImage = OpSampledImage _ %image %sampler", + "%result = OpImageSampleProjDrefImplicitLod _ %sampledImage %project_coordinate %depth_reference", + "OpStore {result} %result", + result = in(reg) &mut result, + this = in(reg) self, + sampler = in(reg) &sampler, + project_coordinate = in(reg) &project_coordinate, + depth_reference = in(reg) &depth_reference, + ); + } + result + } + + #[spirv_std_macros::gpu_only] + /// Sample the image's depth reference with the project coordinate based on an explicit lod + pub fn sample_depth_reference_with_project_coordinate_by_lod( + &self, + sampler: Sampler, + coordinate: impl Vector, + depth_reference: f32, + lod: f32, + ) -> f32 { + let mut result = Default::default(); + unsafe { + asm!( + "%image = OpLoad _ {this}", + "%sampler = OpLoad _ {sampler}", + "%coordinate = OpLoad _ {coordinate}", + "%depth_reference = OpLoad _ {depth_reference}", + "%lod = OpLoad _ {lod}", + "%sampledImage = OpSampledImage _ %image %sampler", + "%result = OpImageSampleProjDrefExplicitLod _ %sampledImage %coordinate %depth_reference Lod %lod", + "OpStore {result} %result", + result = in(reg) &mut result, + this = in(reg) self, + sampler = in(reg) &sampler, + coordinate = in(reg) &coordinate, + depth_reference = in(reg) &depth_reference, + lod = in(reg) &lod, + ) + } + result + } + + #[spirv_std_macros::gpu_only] + /// Sample the image's depth reference with the project coordinate based on a gradient formed by (dx, dy). + /// Specifically, ([du/dx, dv/dx], [du/dy, dv/dy]) + pub fn sample_depth_reference_with_project_coordinate_by_gradient( + &self, + sampler: Sampler, + coordinate: impl Vector, + depth_reference: f32, + gradient_dx: impl Vector, + gradient_dy: impl Vector, + ) -> f32 { + let mut result = Default::default(); + unsafe { + asm!( + "%image = OpLoad _ {this}", + "%sampler = OpLoad _ {sampler}", + "%coordinate = OpLoad _ {coordinate}", + "%depth_reference = OpLoad _ {depth_reference}", + "%gradient_dx = OpLoad _ {gradient_dx}", + "%gradient_dy = OpLoad _ {gradient_dy}", + "%sampledImage = OpSampledImage _ %image %sampler", + "%result = OpImageSampleProjDrefExplicitLod _ %sampledImage %coordinate %depth_reference Grad %gradient_dx %gradient_dy", + "OpStore {result} %result", + result = in(reg) &mut result, + this = in(reg) self, + sampler = in(reg) &sampler, + coordinate = in(reg) &coordinate, + depth_reference = in(reg) &depth_reference, + gradient_dx = in(reg) &gradient_dx, + gradient_dy = in(reg) &gradient_dy, + ); + } + result + } + /// Fetch a single texel with a sampler set at compile time #[spirv_std_macros::gpu_only] pub fn fetch(&self, coordinate: impl Vector) -> V @@ -223,6 +497,7 @@ impl Image2dArray { result } } + #[spirv_std_macros::gpu_only] /// Sample the image at a coordinate by a lod pub fn sample_by_lod>( @@ -250,6 +525,7 @@ impl Image2dArray { } result } + #[spirv_std_macros::gpu_only] /// Sample the image based on a gradient formed by (dx, dy). Specifically, ([du/dx, dv/dx], [du/dy, dv/dy]) pub fn sample_by_gradient>( @@ -280,6 +556,100 @@ impl Image2dArray { } result } + + #[spirv_std_macros::gpu_only] + /// Sample the image's depth reference + pub fn sample_depth_reference( + &self, + sampler: Sampler, + coordinate: impl Vector, + depth_reference: f32, + ) -> f32 { + let mut result = Default::default(); + unsafe { + asm!( + "%image = OpLoad _ {this}", + "%sampler = OpLoad _ {sampler}", + "%coordinate = OpLoad _ {coordinate}", + "%depth_reference = OpLoad _ {depth_reference}", // not required to do this way, but done for consistency + "%sampledImage = OpSampledImage _ %image %sampler", + "%result = OpImageSampleDrefImplicitLod _ %sampledImage %coordinate %depth_reference", + "OpStore {result} %result", + result = in(reg) &mut result, + this = in(reg) self, + sampler = in(reg) &sampler, + coordinate = in(reg) &coordinate, + depth_reference = in(reg) &depth_reference, + ); + } + result + } + + #[spirv_std_macros::gpu_only] + /// Sample the image's depth reference based on an explicit lod + pub fn sample_depth_reference_by_lod( + &self, + sampler: Sampler, + coordinate: impl Vector, + depth_reference: f32, + lod: f32, + ) -> f32 { + let mut result = Default::default(); + unsafe { + asm!( + "%image = OpLoad _ {this}", + "%sampler = OpLoad _ {sampler}", + "%coordinate = OpLoad _ {coordinate}", + "%depth_reference = OpLoad _ {depth_reference}", + "%lod = OpLoad _ {lod}", + "%sampledImage = OpSampledImage _ %image %sampler", + "%result = OpImageSampleDrefExplicitLod _ %sampledImage %coordinate %depth_reference Lod %lod", + "OpStore {result} %result", + result = in(reg) &mut result, + this = in(reg) self, + sampler = in(reg) &sampler, + coordinate = in(reg) &coordinate, + depth_reference = in(reg) &depth_reference, + lod = in(reg) &lod, + ) + } + result + } + + #[spirv_std_macros::gpu_only] + /// Sample the image's depth reference based on a gradient formed by (dx, dy). + /// Specifically, ([du/dx, dv/dx], [du/dy, dv/dy]) + pub fn sample_depth_reference_by_gradient( + &self, + sampler: Sampler, + coordinate: impl Vector, + depth_reference: f32, + gradient_dx: impl Vector, + gradient_dy: impl Vector, + ) -> f32 { + let mut result = Default::default(); + unsafe { + asm!( + "%image = OpLoad _ {this}", + "%sampler = OpLoad _ {sampler}", + "%coordinate = OpLoad _ {coordinate}", + "%depth_reference = OpLoad _ {depth_reference}", + "%gradient_dx = OpLoad _ {gradient_dx}", + "%gradient_dy = OpLoad _ {gradient_dy}", + "%sampledImage = OpSampledImage _ %image %sampler", + "%result = OpImageSampleDrefExplicitLod _ %sampledImage %coordinate %depth_reference Grad %gradient_dx %gradient_dy", + "OpStore {result} %result", + result = in(reg) &mut result, + this = in(reg) self, + sampler = in(reg) &sampler, + coordinate = in(reg) &coordinate, + depth_reference = in(reg) &depth_reference, + gradient_dx = in(reg) &gradient_dx, + gradient_dy = in(reg) &gradient_dy, + ); + } + result + } } #[spirv(image_type( @@ -320,6 +690,7 @@ impl Cubemap { result } } + #[spirv_std_macros::gpu_only] /// Sample the image at a coordinate by a lod pub fn sample_by_lod>( @@ -347,8 +718,9 @@ impl Cubemap { } result } + #[spirv_std_macros::gpu_only] - /// Sample the image based on a gradient formed by (dx, dy). Specifically, ([du/dx, dv/dx], [du/dy, dv/dy]) + /// Sample the image based on a gradient formed by (dx, dy). Specifically, ([du/dx, dv/dx, dw/dx], [du/dy, dv/dy, dw/dy]) pub fn sample_by_gradient>( &self, sampler: Sampler, @@ -377,6 +749,100 @@ impl Cubemap { } result } + + #[spirv_std_macros::gpu_only] + /// Sample the image's depth reference + pub fn sample_depth_reference( + &self, + sampler: Sampler, + coordinate: impl Vector, + depth_reference: f32, + ) -> f32 { + let mut result = Default::default(); + unsafe { + asm!( + "%image = OpLoad _ {this}", + "%sampler = OpLoad _ {sampler}", + "%coordinate = OpLoad _ {coordinate}", + "%depth_reference = OpLoad _ {depth_reference}", // not required to do this way, but done for consistency + "%sampledImage = OpSampledImage _ %image %sampler", + "%result = OpImageSampleDrefImplicitLod _ %sampledImage %coordinate %depth_reference", + "OpStore {result} %result", + result = in(reg) &mut result, + this = in(reg) self, + sampler = in(reg) &sampler, + coordinate = in(reg) &coordinate, + depth_reference = in(reg) &depth_reference, + ); + } + result + } + + #[spirv_std_macros::gpu_only] + /// Sample the image's depth reference based on an explicit lod + pub fn sample_depth_reference_by_lod( + &self, + sampler: Sampler, + coordinate: impl Vector, + depth_reference: f32, + lod: f32, + ) -> f32 { + let mut result = Default::default(); + unsafe { + asm!( + "%image = OpLoad _ {this}", + "%sampler = OpLoad _ {sampler}", + "%coordinate = OpLoad _ {coordinate}", + "%depth_reference = OpLoad _ {depth_reference}", + "%lod = OpLoad _ {lod}", + "%sampledImage = OpSampledImage _ %image %sampler", + "%result = OpImageSampleDrefExplicitLod _ %sampledImage %coordinate %depth_reference Lod %lod", + "OpStore {result} %result", + result = in(reg) &mut result, + this = in(reg) self, + sampler = in(reg) &sampler, + coordinate = in(reg) &coordinate, + depth_reference = in(reg) &depth_reference, + lod = in(reg) &lod, + ) + } + result + } + + #[spirv_std_macros::gpu_only] + /// Sample the image's depth reference based on a gradient formed by (dx, dy). + /// Specifically, ([du/dx, dv/dx, dw/dx], [du/dy, dv/dy, dw/dy]) + pub fn sample_depth_reference_by_gradient( + &self, + sampler: Sampler, + coordinate: impl Vector, + depth_reference: f32, + gradient_dx: impl Vector, + gradient_dy: impl Vector, + ) -> f32 { + let mut result = Default::default(); + unsafe { + asm!( + "%image = OpLoad _ {this}", + "%sampler = OpLoad _ {sampler}", + "%coordinate = OpLoad _ {coordinate}", + "%depth_reference = OpLoad _ {depth_reference}", + "%gradient_dx = OpLoad _ {gradient_dx}", + "%gradient_dy = OpLoad _ {gradient_dy}", + "%sampledImage = OpSampledImage _ %image %sampler", + "%result = OpImageSampleDrefExplicitLod _ %sampledImage %coordinate %depth_reference Grad %gradient_dx %gradient_dy", + "OpStore {result} %result", + result = in(reg) &mut result, + this = in(reg) self, + sampler = in(reg) &sampler, + coordinate = in(reg) &coordinate, + depth_reference = in(reg) &depth_reference, + gradient_dx = in(reg) &gradient_dx, + gradient_dy = in(reg) &gradient_dy, + ); + } + result + } } #[spirv(sampled_image)] diff --git a/tests/ui/image/sample_depth_reference/sample.rs b/tests/ui/image/sample_depth_reference/sample.rs new file mode 100644 index 0000000000..9e7bcc3e45 --- /dev/null +++ b/tests/ui/image/sample_depth_reference/sample.rs @@ -0,0 +1,19 @@ +// Test `OpImageSampleDrefImplicitLod` +// build-pass + +use spirv_std::{arch, Cubemap, Image2d, Image2dArray, Sampler}; + +#[spirv(fragment)] +pub fn main( + #[spirv(uniform_constant, descriptor_set = 0, binding = 0)] image: &Image2d, + #[spirv(uniform_constant, descriptor_set = 1, binding = 1)] image_array: &Image2dArray, + #[spirv(uniform_constant, descriptor_set = 2, binding = 2)] cubemap: &Cubemap, + #[spirv(uniform_constant, descriptor_set = 3, binding = 3)] sampler: &Sampler, + output: &mut f32, +) { + let v2 = glam::Vec2::new(0.0, 1.0); + let v3 = glam::Vec3A::new(0.0, 0.0, 1.0); + *output = image.sample_depth_reference(*sampler, v2, 1.0); + *output += image_array.sample_depth_reference(*sampler, v3, 1.0); + *output += cubemap.sample_depth_reference(*sampler, v3, 1.0); +} diff --git a/tests/ui/image/sample_depth_reference/sample_gradient.rs b/tests/ui/image/sample_depth_reference/sample_gradient.rs new file mode 100644 index 0000000000..2ad5301b0b --- /dev/null +++ b/tests/ui/image/sample_depth_reference/sample_gradient.rs @@ -0,0 +1,23 @@ +// Test `OpImageSampleDrefExplicitLod` +// build-pass + +use spirv_std::{arch, Cubemap, Image2d, Image2dArray, Sampler}; + +#[spirv(fragment)] +pub fn main( + #[spirv(uniform_constant, descriptor_set = 0, binding = 0)] image: &Image2d, + #[spirv(uniform_constant, descriptor_set = 1, binding = 1)] image_array: &Image2dArray, + #[spirv(uniform_constant, descriptor_set = 2, binding = 2)] sampler: &Sampler, + #[spirv(uniform_constant, descriptor_set = 3, binding = 3)] cubemap: &Cubemap, + output: &mut f32, +) { + let v2 = glam::Vec2::new(0.0, 1.0); + let v2_dx = glam::Vec2::new(0.0, 1.0); + let v2_dy = glam::Vec2::new(0.0, 1.0); + let v3 = glam::Vec3A::new(0.0, 0.0, 1.0); + let v3_dx = glam::Vec3A::new(0.0, 1.0, 0.5); + let v3_dy = glam::Vec3A::new(0.0, 1.0, 0.5); + *output = image.sample_depth_reference_by_gradient(*sampler, v2, 1.0, v2_dx, v2_dy); + *output += image_array.sample_depth_reference_by_gradient(*sampler, v3, 1.0, v2_dx, v2_dy); + *output += cubemap.sample_depth_reference_by_gradient(*sampler, v3, 1.0, v3_dx, v3_dy); +} diff --git a/tests/ui/image/sample_depth_reference/sample_lod.rs b/tests/ui/image/sample_depth_reference/sample_lod.rs new file mode 100644 index 0000000000..76d3b1e219 --- /dev/null +++ b/tests/ui/image/sample_depth_reference/sample_lod.rs @@ -0,0 +1,19 @@ +// Test `OpImageSampleDrefExplicitLod` +// build-pass + +use spirv_std::{arch, Cubemap, Image2d, Image2dArray, Sampler}; + +#[spirv(fragment)] +pub fn main( + #[spirv(uniform_constant, descriptor_set = 0, binding = 0)] image: &Image2d, + #[spirv(uniform_constant, descriptor_set = 1, binding = 1)] image_array: &Image2dArray, + #[spirv(uniform_constant, descriptor_set = 2, binding = 2)] sampler: &Sampler, + #[spirv(uniform_constant, descriptor_set = 3, binding = 3)] cubemap: &Cubemap, + output: &mut f32, +) { + let v2 = glam::Vec2::new(0.0, 1.0); + let v3 = glam::Vec3A::new(0.0, 0.0, 1.0); + *output = image.sample_depth_reference_by_lod(*sampler, v2, 1.0, 0.0); + *output += image_array.sample_depth_reference_by_lod(*sampler, v3, 1.0, 0.0); + *output += image_array.sample_depth_reference_by_lod(*sampler, v3, 1.0, 0.0); +} diff --git a/tests/ui/image/sample_depth_reference_with_project_coordinate/sample.rs b/tests/ui/image/sample_depth_reference_with_project_coordinate/sample.rs new file mode 100644 index 0000000000..959bc42ba6 --- /dev/null +++ b/tests/ui/image/sample_depth_reference_with_project_coordinate/sample.rs @@ -0,0 +1,14 @@ +// Test `OpImageSampleProjDrefImplicitLod` +// build-pass + +use spirv_std::{arch, Image2d, Sampler}; + +#[spirv(fragment)] +pub fn main( + #[spirv(uniform_constant, descriptor_set = 0, binding = 0)] image: &Image2d, + #[spirv(uniform_constant, descriptor_set = 1, binding = 1)] sampler: &Sampler, + output: &mut f32, +) { + let v3 = glam::Vec3A::new(0.0, 0.0, 1.0); + *output = image.sample_depth_reference_with_project_coordinate(*sampler, v3, 1.0); +} diff --git a/tests/ui/image/sample_depth_reference_with_project_coordinate/sample_gradient.rs b/tests/ui/image/sample_depth_reference_with_project_coordinate/sample_gradient.rs new file mode 100644 index 0000000000..a458b06f11 --- /dev/null +++ b/tests/ui/image/sample_depth_reference_with_project_coordinate/sample_gradient.rs @@ -0,0 +1,16 @@ +// Test `OpImageSampleProjDrefExplicitLod` +// build-pass + +use spirv_std::{arch, Image2d, Sampler}; + +#[spirv(fragment)] +pub fn main( + #[spirv(uniform_constant, descriptor_set = 0, binding = 0)] image: &Image2d, + #[spirv(uniform_constant, descriptor_set = 1, binding = 1)] sampler: &Sampler, + output: &mut f32, +) { + let v2_dx = glam::Vec2::new(0.0, 1.0); + let v2_dy = glam::Vec2::new(0.0, 1.0); + let v3 = glam::Vec3A::new(0.0, 0.0, 1.0); + *output = image.sample_depth_reference_with_project_coordinate_by_gradient(*sampler, v3, 1.0, v2_dx, v2_dy); +} diff --git a/tests/ui/image/sample_depth_reference_with_project_coordinate/sample_lod.rs b/tests/ui/image/sample_depth_reference_with_project_coordinate/sample_lod.rs new file mode 100644 index 0000000000..95e40149b2 --- /dev/null +++ b/tests/ui/image/sample_depth_reference_with_project_coordinate/sample_lod.rs @@ -0,0 +1,14 @@ +// Test `OpImageSampleProjDrefExplicitLod` +// build-pass + +use spirv_std::{arch, Image2d, Sampler}; + +#[spirv(fragment)] +pub fn main( + #[spirv(uniform_constant, descriptor_set = 0, binding = 0)] image: &Image2d, + #[spirv(uniform_constant, descriptor_set = 1, binding = 1)] sampler: &Sampler, + output: &mut f32, +) { + let v3 = glam::Vec3A::new(0.0, 0.0, 1.0); + *output = image.sample_depth_reference_with_project_coordinate_by_lod(*sampler, v3, 1.0, 0.0); +} diff --git a/tests/ui/image/sample_with_project_coordinate/sample.rs b/tests/ui/image/sample_with_project_coordinate/sample.rs new file mode 100644 index 0000000000..dc8c8d0e39 --- /dev/null +++ b/tests/ui/image/sample_with_project_coordinate/sample.rs @@ -0,0 +1,14 @@ +// Test `OpImageSampleProjImplicitLod` +// build-pass + +use spirv_std::{arch, Image2d, Sampler}; + +#[spirv(fragment)] +pub fn main( + #[spirv(uniform_constant, descriptor_set = 0, binding = 0)] image2d: &Image2d, + #[spirv(uniform_constant, descriptor_set = 1, binding = 1)] sampler: &Sampler, + output: &mut glam::Vec4, +) { + let v3 = glam::Vec3::new(0.0, 1.0, 0.5); + *output = image2d.sample_with_project_coordinate(*sampler, v3); +} diff --git a/tests/ui/image/sample_with_project_coordinate/sample_gradient.rs b/tests/ui/image/sample_with_project_coordinate/sample_gradient.rs new file mode 100644 index 0000000000..aa5c8b95cf --- /dev/null +++ b/tests/ui/image/sample_with_project_coordinate/sample_gradient.rs @@ -0,0 +1,15 @@ +// Test `OpImageSampleProjExplicitLod` +// build-pass + +use spirv_std::{arch, Image2d, Sampler}; + +#[spirv(fragment)] +pub fn main( + #[spirv(uniform_constant, descriptor_set = 0, binding = 0)] image2d: &Image2d, + #[spirv(uniform_constant, descriptor_set = 1, binding = 1)] sampler: &Sampler, + output: &mut glam::Vec4, +) { + let v2 = glam::Vec2::new(0.0, 1.0); + let v3 = glam::Vec3::new(0.0, 1.0, 0.5); + *output = image2d.sample_with_project_coordinate_by_gradient(*sampler, v3, v2, v2); +} diff --git a/tests/ui/image/sample_with_project_coordinate/sample_lod.rs b/tests/ui/image/sample_with_project_coordinate/sample_lod.rs new file mode 100644 index 0000000000..3e9e19c182 --- /dev/null +++ b/tests/ui/image/sample_with_project_coordinate/sample_lod.rs @@ -0,0 +1,14 @@ +// Test `OpImageSampleProjExplicitLod` +// build-pass + +use spirv_std::{arch, Image2d, Sampler}; + +#[spirv(fragment)] +pub fn main( + #[spirv(uniform_constant, descriptor_set = 0, binding = 0)] image2d: &Image2d, + #[spirv(uniform_constant, descriptor_set = 1, binding = 1)] sampler: &Sampler, + output: &mut glam::Vec4, +) { + let v3 = glam::Vec3::new(0.0, 1.0, 0.5); + *output = image2d.sample_with_project_coordinate_by_lod(*sampler, v3, 0.0); +} From 6d2db9a9ee26c82d018767733b55d5679fe1ec01 Mon Sep 17 00:00:00 2001 From: Jesse Welnick Date: Mon, 29 Mar 2021 18:41:48 +0900 Subject: [PATCH 2/2] docs: add alias annotation for methods in spirv-std/src/textures.rs --- crates/spirv-std/src/textures.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/crates/spirv-std/src/textures.rs b/crates/spirv-std/src/textures.rs index e49247c69b..86aa662956 100644 --- a/crates/spirv-std/src/textures.rs +++ b/crates/spirv-std/src/textures.rs @@ -22,6 +22,7 @@ pub struct Image2d { impl Image2d { #[spirv_std_macros::gpu_only] + #[doc(alias = "OpImageSampleImplicitLod")] pub fn sample>( &self, sampler: Sampler, @@ -46,6 +47,7 @@ impl Image2d { } #[spirv_std_macros::gpu_only] + #[doc(alias = "OpImageSampleExplicitLod")] /// Sample the image at a coordinate by a lod pub fn sample_by_lod>( &self, @@ -74,6 +76,7 @@ impl Image2d { } #[spirv_std_macros::gpu_only] + #[doc(alias = "OpImageSampleExplicitLod")] /// Sample the image based on a gradient formed by (dx, dy). Specifically, ([du/dx, dv/dx], [du/dy, dv/dy]) pub fn sample_by_gradient>( &self, @@ -105,6 +108,7 @@ impl Image2d { } #[spirv_std_macros::gpu_only] + #[doc(alias = "OpImageSampleProjImplicitLod")] pub fn sample_with_project_coordinate>( &self, sampler: Sampler, @@ -129,6 +133,7 @@ impl Image2d { } #[spirv_std_macros::gpu_only] + #[doc(alias = "OpImageSampleProjExplicitLod")] /// Sample the image with a project coordinate by a lod pub fn sample_with_project_coordinate_by_lod>( &self, @@ -157,6 +162,7 @@ impl Image2d { } #[spirv_std_macros::gpu_only] + #[doc(alias = "OpImageSampleProjExplicitLod")] /// Sample the image with a project coordinate based on a gradient formed by (dx, dy). Specifically, ([du/dx, dv/dx], [du/dy, dv/dy]) pub fn sample_with_project_coordinate_by_gradient>( &self, @@ -188,6 +194,7 @@ impl Image2d { } #[spirv_std_macros::gpu_only] + #[doc(alias = "OpImageSampleDrefImplicitLod")] /// Sample the image's depth reference pub fn sample_depth_reference( &self, @@ -216,6 +223,7 @@ impl Image2d { } #[spirv_std_macros::gpu_only] + #[doc(alias = "OpImageSampleDrefExplicitLod")] /// Sample the image's depth reference based on an explicit lod pub fn sample_depth_reference_by_lod( &self, @@ -247,6 +255,7 @@ impl Image2d { } #[spirv_std_macros::gpu_only] + #[doc(alias = "OpImageSampleDrefExplicitLod")] /// Sample the image's depth reference based on a gradient formed by (dx, dy). /// Specifically, ([du/dx, dv/dx], [du/dy, dv/dy]) pub fn sample_depth_reference_by_gradient( @@ -282,6 +291,7 @@ impl Image2d { } #[spirv_std_macros::gpu_only] + #[doc(alias = "OpImageSampleProjDrefImplicitLod")] /// Sample the image's depth reference with the project coordinate pub fn sample_depth_reference_with_project_coordinate( &self, @@ -310,6 +320,7 @@ impl Image2d { } #[spirv_std_macros::gpu_only] + #[doc(alias = "OpImageSampleProjDrefExplicitLod")] /// Sample the image's depth reference with the project coordinate based on an explicit lod pub fn sample_depth_reference_with_project_coordinate_by_lod( &self, @@ -341,6 +352,7 @@ impl Image2d { } #[spirv_std_macros::gpu_only] + #[doc(alias = "OpImageSampleProjDrefExplicitLod")] /// Sample the image's depth reference with the project coordinate based on a gradient formed by (dx, dy). /// Specifically, ([du/dx, dv/dx], [du/dy, dv/dy]) pub fn sample_depth_reference_with_project_coordinate_by_gradient( @@ -377,6 +389,7 @@ impl Image2d { /// Fetch a single texel with a sampler set at compile time #[spirv_std_macros::gpu_only] + #[doc(alias = "OpImageFetch")] pub fn fetch(&self, coordinate: impl Vector) -> V where V: Vector, @@ -416,6 +429,7 @@ pub struct StorageImage2d { impl StorageImage2d { /// Read a texel from an image without a sampler. #[spirv_std_macros::gpu_only] + #[doc(alias = "OpImageRead")] pub fn read(&self, coordinate: impl Vector) -> V where I: Integer, @@ -440,6 +454,7 @@ impl StorageImage2d { /// Write a texel to an image without a sampler. #[spirv_std_macros::gpu_only] + #[doc(alias = "OpImageWrite")] pub unsafe fn write( &self, coordinate: impl Vector, @@ -475,6 +490,7 @@ pub struct Image2dArray { impl Image2dArray { #[spirv_std_macros::gpu_only] + #[doc(alias = "OpImageSampleImplicitLod")] pub fn sample>( &self, sampler: Sampler, @@ -499,6 +515,7 @@ impl Image2dArray { } #[spirv_std_macros::gpu_only] + #[doc(alias = "OpImageSampleExplicitLod")] /// Sample the image at a coordinate by a lod pub fn sample_by_lod>( &self, @@ -527,6 +544,7 @@ impl Image2dArray { } #[spirv_std_macros::gpu_only] + #[doc(alias = "OpImageSampleExplicitLod")] /// Sample the image based on a gradient formed by (dx, dy). Specifically, ([du/dx, dv/dx], [du/dy, dv/dy]) pub fn sample_by_gradient>( &self, @@ -558,6 +576,7 @@ impl Image2dArray { } #[spirv_std_macros::gpu_only] + #[doc(alias = "OpImageSampleDrefImplicitLod")] /// Sample the image's depth reference pub fn sample_depth_reference( &self, @@ -586,6 +605,7 @@ impl Image2dArray { } #[spirv_std_macros::gpu_only] + #[doc(alias = "OpImageSampleDrefExplicitLod")] /// Sample the image's depth reference based on an explicit lod pub fn sample_depth_reference_by_lod( &self, @@ -617,6 +637,7 @@ impl Image2dArray { } #[spirv_std_macros::gpu_only] + #[doc(alias = "OpImageSampleDrefExplicitLod")] /// Sample the image's depth reference based on a gradient formed by (dx, dy). /// Specifically, ([du/dx, dv/dx], [du/dy, dv/dy]) pub fn sample_depth_reference_by_gradient( @@ -668,6 +689,7 @@ pub struct Cubemap { impl Cubemap { #[spirv_std_macros::gpu_only] + #[doc(alias = "OpSampledImage")] pub fn sample>( &self, sampler: Sampler, @@ -692,6 +714,7 @@ impl Cubemap { } #[spirv_std_macros::gpu_only] + #[doc(alias = "OpImageSampleExplicitLod")] /// Sample the image at a coordinate by a lod pub fn sample_by_lod>( &self, @@ -720,6 +743,7 @@ impl Cubemap { } #[spirv_std_macros::gpu_only] + #[doc(alias = "OpImageSampleExplicitLod")] /// Sample the image based on a gradient formed by (dx, dy). Specifically, ([du/dx, dv/dx, dw/dx], [du/dy, dv/dy, dw/dy]) pub fn sample_by_gradient>( &self, @@ -751,6 +775,7 @@ impl Cubemap { } #[spirv_std_macros::gpu_only] + #[doc(alias = "OpImageSampleDrefImplicitLod")] /// Sample the image's depth reference pub fn sample_depth_reference( &self, @@ -779,6 +804,7 @@ impl Cubemap { } #[spirv_std_macros::gpu_only] + #[doc(alias = "OpImageSampleDrefExplicitLod")] /// Sample the image's depth reference based on an explicit lod pub fn sample_depth_reference_by_lod( &self, @@ -810,6 +836,7 @@ impl Cubemap { } #[spirv_std_macros::gpu_only] + #[doc(alias = "OpImageSampleDrefExplicitLod")] /// Sample the image's depth reference based on a gradient formed by (dx, dy). /// Specifically, ([du/dx, dv/dx, dw/dx], [du/dy, dv/dy, dw/dy]) pub fn sample_depth_reference_by_gradient( @@ -853,6 +880,7 @@ pub struct SampledImage { impl SampledImage { #[spirv_std_macros::gpu_only] + #[doc(alias = "OpImageSampleImplicitLod")] pub fn sample>(&self, coordinate: impl Vector) -> V { unsafe { let mut result = Default::default();