Skip to content

Add Image::fetch_with_lod #361

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

Merged
merged 6 commits into from
Aug 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions crates/spirv-std/src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<I>(
&self,
coordinate: impl ImageCoordinate<I, DIM, ARRAYED>,
lod: u32,
) -> SampledType::SampleResult
where
I: Integer,
{
self.fetch_with(coordinate, sample_with::lod(lod))
}
}

impl<
Expand Down
13 changes: 13 additions & 0 deletions tests/compiletests/ui/image/fetch_with_lod.rs
Original file line number Diff line number Diff line change
@@ -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;
}
12 changes: 6 additions & 6 deletions tests/compiletests/ui/image/gather_err.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ error[E0277]: the trait bound `Image<f32, 0, 2, 0, 0, 1, 0, 4>: HasGather` is no
Image<SampledType, 3, DEPTH, ARRAYED, 0, SAMPLED, FORMAT, COMPONENTS>
Image<SampledType, 4, DEPTH, ARRAYED, 0, SAMPLED, FORMAT, COMPONENTS>
note: required by a bound in `Image::<SampledType, DIM, DEPTH, ARRAYED, spirv_std::::image::{impl#1}::{constant#0}, SAMPLED, FORMAT, COMPONENTS>::gather`
--> $SPIRV_STD_SRC/image.rs:199:15
--> $SPIRV_STD_SRC/image.rs:215:15
|
192 | pub fn gather<F>(
208 | pub fn gather<F>(
| ------ required by a bound in this associated function
...
199 | Self: HasGather,
215 | Self: HasGather,
| ^^^^^^^^^ required by this bound in `Image::<SampledType, DIM, DEPTH, ARRAYED, spirv_std::::image::{impl#1}::{constant#0}, SAMPLED, FORMAT, COMPONENTS>::gather`

error[E0277]: the trait bound `Image<f32, 2, 2, 0, 0, 1, 0, 4>: HasGather` is not satisfied
Expand All @@ -28,12 +28,12 @@ error[E0277]: the trait bound `Image<f32, 2, 2, 0, 0, 1, 0, 4>: HasGather` is no
Image<SampledType, 3, DEPTH, ARRAYED, 0, SAMPLED, FORMAT, COMPONENTS>
Image<SampledType, 4, DEPTH, ARRAYED, 0, SAMPLED, FORMAT, COMPONENTS>
note: required by a bound in `Image::<SampledType, DIM, DEPTH, ARRAYED, spirv_std::::image::{impl#1}::{constant#0}, SAMPLED, FORMAT, COMPONENTS>::gather`
--> $SPIRV_STD_SRC/image.rs:199:15
--> $SPIRV_STD_SRC/image.rs:215:15
|
192 | pub fn gather<F>(
208 | pub fn gather<F>(
| ------ required by a bound in this associated function
...
199 | Self: HasGather,
215 | Self: HasGather,
| ^^^^^^^^^ required by this bound in `Image::<SampledType, DIM, DEPTH, ARRAYED, spirv_std::::image::{impl#1}::{constant#0}, SAMPLED, FORMAT, COMPONENTS>::gather`

error: aborting due to 2 previous errors
Expand Down
8 changes: 4 additions & 4 deletions tests/compiletests/ui/image/query/query_levels_err.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ error[E0277]: the trait bound `Image<f32, 4, 2, 0, 0, 1, 0, 4>: HasQueryLevels`
Image<SampledType, 2, DEPTH, ARRAYED, MULTISAMPLED, SAMPLED, FORMAT, COMPONENTS>
Image<SampledType, 3, DEPTH, ARRAYED, MULTISAMPLED, SAMPLED, FORMAT, COMPONENTS>
note: required by a bound in `Image::<SampledType, DIM, DEPTH, ARRAYED, MULTISAMPLED, SAMPLED, FORMAT, COMPONENTS>::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::<SampledType, DIM, DEPTH, ARRAYED, MULTISAMPLED, SAMPLED, FORMAT, COMPONENTS>::query_levels`

error: aborting due to 1 previous error
Expand Down
6 changes: 3 additions & 3 deletions tests/compiletests/ui/image/query/query_lod_err.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ error[E0277]: the trait bound `Image<f32, 4, 2, 0, 0, 1, 0, 4>: HasQueryLevels`
Image<SampledType, 2, DEPTH, ARRAYED, MULTISAMPLED, SAMPLED, FORMAT, COMPONENTS>
Image<SampledType, 3, DEPTH, ARRAYED, MULTISAMPLED, SAMPLED, FORMAT, COMPONENTS>
note: required by a bound in `Image::<SampledType, DIM, DEPTH, ARRAYED, MULTISAMPLED, SAMPLED, FORMAT, COMPONENTS>::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::<SampledType, DIM, DEPTH, ARRAYED, MULTISAMPLED, SAMPLED, FORMAT, COMPONENTS>::query_lod`

error: aborting due to 1 previous error
Expand Down
8 changes: 4 additions & 4 deletions tests/compiletests/ui/image/query/query_size_err.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ error[E0277]: the trait bound `Image<f32, 1, 2, 0, 0, 1, 0, 4>: HasQuerySize` is
Image<SampledType, 2, DEPTH, ARRAYED, 0, 2, FORMAT, COMPONENTS>
and 6 others
note: required by a bound in `Image::<SampledType, DIM, DEPTH, ARRAYED, MULTISAMPLED, SAMPLED, FORMAT, COMPONENTS>::query_size`
--> $SPIRV_STD_SRC/image.rs:1015:15
--> $SPIRV_STD_SRC/image.rs:1031:15
|
1013 | pub fn query_size<Size: ImageSizeQuery<u32, DIM, ARRAYED> + Default>(&self) -> Size
1029 | pub fn query_size<Size: ImageSizeQuery<u32, DIM, ARRAYED> + 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::<SampledType, DIM, DEPTH, ARRAYED, MULTISAMPLED, SAMPLED, FORMAT, COMPONENTS>::query_size`

error: aborting due to 1 previous error
Expand Down
6 changes: 3 additions & 3 deletions tests/compiletests/ui/image/query/query_size_lod_err.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ error[E0277]: the trait bound `Image<f32, 4, 2, 0, 0, 1, 0, 4>: HasQuerySizeLod`
Image<SampledType, 2, DEPTH, ARRAYED, 0, SAMPLED, FORMAT, COMPONENTS>
Image<SampledType, 3, DEPTH, ARRAYED, 0, SAMPLED, FORMAT, COMPONENTS>
note: required by a bound in `Image::<SampledType, DIM, DEPTH, ARRAYED, spirv_std::::image::{impl#7}::{constant#0}, SAMPLED, FORMAT, COMPONENTS>::query_size_lod`
--> $SPIRV_STD_SRC/image.rs:1061:15
--> $SPIRV_STD_SRC/image.rs:1077:15
|
1056 | pub fn query_size_lod<Size: ImageSizeQuery<u32, DIM, ARRAYED> + Default>(
1072 | pub fn query_size_lod<Size: ImageSizeQuery<u32, DIM, ARRAYED> + Default>(
| -------------- required by a bound in this associated function
...
1061 | Self: HasQuerySizeLod,
1077 | Self: HasQuerySizeLod,
| ^^^^^^^^^^^^^^^ required by this bound in `Image::<SampledType, DIM, DEPTH, ARRAYED, spirv_std::::image::{impl#7}::{constant#0}, SAMPLED, FORMAT, COMPONENTS>::query_size_lod`

error: aborting due to 1 previous error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ error[E0277]: the trait bound `Image<f32, 4, 2, 0, 0, 1, 0, 4>: HasQuerySizeLod`
Image<SampledType, 2, DEPTH, ARRAYED, 0, SAMPLED, FORMAT, COMPONENTS>
Image<SampledType, 3, DEPTH, ARRAYED, 0, SAMPLED, FORMAT, COMPONENTS>
note: required by a bound in `SampledImage::<Image<SampledType, DIM, DEPTH, ARRAYED, spirv_std::::image::{impl#9}::{constant#0}, SAMPLED, FORMAT, COMPONENTS>>::query_size_lod`
--> /image.rs:1226:12
--> /image.rs:1242:12
|
1212 | pub fn query_size_lod<Size: ImageSizeQuery<u32, DIM, ARRAYED> + Default>(
1228 | pub fn query_size_lod<Size: ImageSizeQuery<u32, DIM, ARRAYED> + Default>(
| -------------- required by a bound in this associated function
...
1226 | >: HasQuerySizeLod,
1242 | >: HasQuerySizeLod,
| ^^^^^^^^^^^^^^^ required by this bound in `SampledImage::<Image<SampledType, DIM, DEPTH, ARRAYED, spirv_std::::image::{impl#9}::{constant#0}, SAMPLED, FORMAT, COMPONENTS>>::query_size_lod`

error: aborting due to 1 previous error
Expand Down
Loading