diff --git a/crates/spirv-std/src/image.rs b/crates/spirv-std/src/image.rs index 361cd1cf29..d07710cef0 100644 --- a/crates/spirv-std/src/image.rs +++ b/crates/spirv-std/src/image.rs @@ -162,6 +162,22 @@ impl< } result.truncate_into() } + + /// Fetch a single texel at a mipmap `lod` with a sampler set at compile time + /// + /// `lod` is also known as `level` in WGSL's `textureLoad` + #[crate::macros::gpu_only] + #[doc(alias = "OpImageFetch")] + pub fn fetch_with_lod( + &self, + coordinate: impl ImageCoordinate, + lod: u32, + ) -> SampledType::SampleResult + where + I: Integer, + { + self.fetch_with(coordinate, sample_with::lod(lod)) + } } impl< diff --git a/tests/compiletests/ui/image/fetch_with_lod.rs b/tests/compiletests/ui/image/fetch_with_lod.rs new file mode 100644 index 0000000000..1b2662de46 --- /dev/null +++ b/tests/compiletests/ui/image/fetch_with_lod.rs @@ -0,0 +1,13 @@ +// build-pass + +use spirv_std::spirv; +use spirv_std::{Image, arch}; + +#[spirv(fragment)] +pub fn main( + #[spirv(descriptor_set = 0, binding = 0)] image: &Image!(2D, type=f32, sampled), + output: &mut glam::Vec4, +) { + let texel = image.fetch_with_lod(glam::IVec2::new(0, 1), 0); + *output = texel; +} diff --git a/tests/compiletests/ui/image/gather_err.stderr b/tests/compiletests/ui/image/gather_err.stderr index 550fdfd018..a2d0519500 100644 --- a/tests/compiletests/ui/image/gather_err.stderr +++ b/tests/compiletests/ui/image/gather_err.stderr @@ -9,12 +9,12 @@ error[E0277]: the trait bound `Image: HasGather` is no Image Image note: required by a bound in `Image::::gather` - --> $SPIRV_STD_SRC/image.rs:199:15 + --> $SPIRV_STD_SRC/image.rs:215:15 | -192 | pub fn gather( +208 | pub fn gather( | ------ required by a bound in this associated function ... -199 | Self: HasGather, +215 | Self: HasGather, | ^^^^^^^^^ required by this bound in `Image::::gather` error[E0277]: the trait bound `Image: HasGather` is not satisfied @@ -28,12 +28,12 @@ error[E0277]: the trait bound `Image: HasGather` is no Image Image note: required by a bound in `Image::::gather` - --> $SPIRV_STD_SRC/image.rs:199:15 + --> $SPIRV_STD_SRC/image.rs:215:15 | -192 | pub fn gather( +208 | pub fn gather( | ------ required by a bound in this associated function ... -199 | Self: HasGather, +215 | Self: HasGather, | ^^^^^^^^^ required by this bound in `Image::::gather` error: aborting due to 2 previous errors diff --git a/tests/compiletests/ui/image/query/query_levels_err.stderr b/tests/compiletests/ui/image/query/query_levels_err.stderr index c49926bd05..dd3220d9f3 100644 --- a/tests/compiletests/ui/image/query/query_levels_err.stderr +++ b/tests/compiletests/ui/image/query/query_levels_err.stderr @@ -10,12 +10,12 @@ error[E0277]: the trait bound `Image: HasQueryLevels` Image Image note: required by a bound in `Image::::query_levels` - --> $SPIRV_STD_SRC/image.rs:951:15 + --> $SPIRV_STD_SRC/image.rs:967:15 | -949 | pub fn query_levels(&self) -> u32 +965 | pub fn query_levels(&self) -> u32 | ------------ required by a bound in this associated function -950 | where -951 | Self: HasQueryLevels, +966 | where +967 | Self: HasQueryLevels, | ^^^^^^^^^^^^^^ required by this bound in `Image::::query_levels` error: aborting due to 1 previous error diff --git a/tests/compiletests/ui/image/query/query_lod_err.stderr b/tests/compiletests/ui/image/query/query_lod_err.stderr index e985e690b5..868bab22da 100644 --- a/tests/compiletests/ui/image/query/query_lod_err.stderr +++ b/tests/compiletests/ui/image/query/query_lod_err.stderr @@ -10,12 +10,12 @@ error[E0277]: the trait bound `Image: HasQueryLevels` Image Image note: required by a bound in `Image::::query_lod` - --> $SPIRV_STD_SRC/image.rs:980:15 + --> $SPIRV_STD_SRC/image.rs:996:15 | -974 | pub fn query_lod( +990 | pub fn query_lod( | --------- required by a bound in this associated function ... -980 | Self: HasQueryLevels, +996 | Self: HasQueryLevels, | ^^^^^^^^^^^^^^ required by this bound in `Image::::query_lod` error: aborting due to 1 previous error diff --git a/tests/compiletests/ui/image/query/query_size_err.stderr b/tests/compiletests/ui/image/query/query_size_err.stderr index c94971162e..cdbd9245f5 100644 --- a/tests/compiletests/ui/image/query/query_size_err.stderr +++ b/tests/compiletests/ui/image/query/query_size_err.stderr @@ -15,12 +15,12 @@ error[E0277]: the trait bound `Image: HasQuerySize` is Image and 6 others note: required by a bound in `Image::::query_size` - --> $SPIRV_STD_SRC/image.rs:1015:15 + --> $SPIRV_STD_SRC/image.rs:1031:15 | -1013 | pub fn query_size + Default>(&self) -> Size +1029 | pub fn query_size + Default>(&self) -> Size | ---------- required by a bound in this associated function -1014 | where -1015 | Self: HasQuerySize, +1030 | where +1031 | Self: HasQuerySize, | ^^^^^^^^^^^^ required by this bound in `Image::::query_size` error: aborting due to 1 previous error diff --git a/tests/compiletests/ui/image/query/query_size_lod_err.stderr b/tests/compiletests/ui/image/query/query_size_lod_err.stderr index bbad070b0a..69662c8e79 100644 --- a/tests/compiletests/ui/image/query/query_size_lod_err.stderr +++ b/tests/compiletests/ui/image/query/query_size_lod_err.stderr @@ -10,12 +10,12 @@ error[E0277]: the trait bound `Image: HasQuerySizeLod` Image Image note: required by a bound in `Image::::query_size_lod` - --> $SPIRV_STD_SRC/image.rs:1061:15 + --> $SPIRV_STD_SRC/image.rs:1077:15 | -1056 | pub fn query_size_lod + Default>( +1072 | pub fn query_size_lod + Default>( | -------------- required by a bound in this associated function ... -1061 | Self: HasQuerySizeLod, +1077 | Self: HasQuerySizeLod, | ^^^^^^^^^^^^^^^ required by this bound in `Image::::query_size_lod` error: aborting due to 1 previous error