From ff85f684da2d0c9876ec5545819faca1cbabe564 Mon Sep 17 00:00:00 2001 From: Jesse Welnick Date: Sun, 28 Mar 2021 17:54:04 +0900 Subject: [PATCH] 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..3de9e1de54 --- /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)] image: &Image2d, + #[spirv(uniform_constant)] image_array: &Image2dArray, + #[spirv(uniform_constant)] cubemap: &Cubemap, + #[spirv(uniform_constant)] 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..2b3b440e13 --- /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)] image: &Image2d, + #[spirv(uniform_constant)] image_array: &Image2dArray, + #[spirv(uniform_constant)] sampler: &Sampler, + #[spirv(uniform_constant)] 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..328c800664 --- /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)] image: &Image2d, + #[spirv(uniform_constant)] image_array: &Image2dArray, + #[spirv(uniform_constant)] sampler: &Sampler, + #[spirv(uniform_constant)] 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..84dc06aae0 --- /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)] image: &Image2d, + #[spirv(uniform_constant)] 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..0ff1709bed --- /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)] image: &Image2d, + #[spirv(uniform_constant)] 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..a9cd5df1b2 --- /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)] image: &Image2d, + #[spirv(uniform_constant)] 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..a5dbfef909 --- /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)] image2d: &Image2d, + #[spirv(uniform_constant)] 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..ae4d8cb2df --- /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)] image2d: &Image2d, + #[spirv(uniform_constant)] 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..efa616d91e --- /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)] image2d: &Image2d, + #[spirv(uniform_constant)] 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); +}