Skip to content

Commit 4f3096a

Browse files
committed
Add other cases to tests
1 parent 5ac7369 commit 4f3096a

File tree

7 files changed

+122
-10
lines changed

7 files changed

+122
-10
lines changed

crates/spirv-std/src/image/params.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ impl<V: Vector<I, 3>, I: Integer> ImageCoordinateSubpassData<I, { Arrayed::True
197197

198198
/// Marker trait for query size results based on image dimension and arraying.
199199
///
200-
/// Unlike `ImageCoordinate`, this trait represents the SPIR-V size query results:
200+
/// This trait represents the SPIR-V size query results:
201201
/// - 1D images return a scalar
202202
/// - 2D/Cube/Rect images return 2 components (Cube returns face width/height)
203203
/// - 3D images return 3 components
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// build-pass
2+
// compile-flags: -C target-feature=+ImageQuery,+SampledRect
3+
4+
use spirv_std::spirv;
5+
use spirv_std::{Image, arch};
6+
7+
#[spirv(fragment)]
8+
pub fn main(
9+
#[spirv(descriptor_set = 0, binding = 0)] rect_storage: &Image!(rect, type=f32, sampled=false),
10+
#[spirv(descriptor_set = 1, binding = 1)] rect_storage_array: &Image!(rect, type=f32, sampled=false, arrayed),
11+
output: &mut glam::UVec3,
12+
) {
13+
// Rect images only support query_size (not query_size_lod)
14+
let rect_size: glam::UVec2 = rect_storage.query_size();
15+
16+
// Arrayed rect images return 3D size (width, height, array_layers)
17+
let rect_array_size: glam::UVec3 = rect_storage_array.query_size();
18+
19+
*output = glam::UVec3::new(rect_size.x, rect_size.y, rect_array_size.z);
20+
}

tests/compiletests/ui/image/query/sampled_image_multisampled_query_size.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// Test `OpImageQuerySize` on multisampled `SampledImage`
21
// build-pass
32
// compile-flags: -C target-feature=+ImageQuery
43

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,53 @@
1-
// Test `OpImageQuerySizeLod` on `SampledImage`
21
// build-pass
3-
// compile-flags: -C target-feature=+ImageQuery
2+
// compile-flags: -C target-feature=+ImageQuery,+Sampled1D
43

54
use spirv_std::spirv;
65
use spirv_std::{Image, arch, image::SampledImage};
76

87
#[spirv(fragment)]
98
pub fn main(
10-
#[spirv(descriptor_set = 0, binding = 0)] sampled_image2d: &SampledImage<
9+
#[spirv(descriptor_set = 0, binding = 0)] sampled_image1d: &SampledImage<
10+
Image!(1D, type=f32, sampled),
11+
>,
12+
#[spirv(descriptor_set = 1, binding = 1)] sampled_image1d_array: &SampledImage<
13+
Image!(1D, type=f32, arrayed, sampled),
14+
>,
15+
#[spirv(descriptor_set = 2, binding = 2)] sampled_image2d: &SampledImage<
1116
Image!(2D, type=f32, sampled),
1217
>,
13-
#[spirv(descriptor_set = 1, binding = 1)] sampled_image2d_array: &SampledImage<
18+
#[spirv(descriptor_set = 3, binding = 3)] sampled_image2d_array: &SampledImage<
1419
Image!(2D, type=f32, arrayed, sampled),
1520
>,
16-
#[spirv(descriptor_set = 2, binding = 2)] sampled_image3d: &SampledImage<
21+
#[spirv(descriptor_set = 4, binding = 4)] sampled_image3d: &SampledImage<
1722
Image!(3D, type=f32, sampled),
1823
>,
19-
output: &mut glam::UVec3,
24+
#[spirv(descriptor_set = 5, binding = 5)] sampled_image3d_array: &SampledImage<
25+
Image!(3D, type=f32, arrayed, sampled),
26+
>,
27+
output: &mut glam::UVec4,
2028
) {
21-
// For sampled images, we need to use query_size_lod
29+
// 1D images return scalar
30+
let size_1d: u32 = sampled_image1d.query_size_lod(0);
31+
32+
// 1D arrayed images return 2 components (width, array_layers)
33+
let size_1d_array: glam::UVec2 = sampled_image1d_array.query_size_lod(0);
34+
35+
// 2D images return 2 components
2236
let size_2d: glam::UVec2 = sampled_image2d.query_size_lod(0);
37+
38+
// 2D arrayed images return 3 components
2339
let size_2d_array: glam::UVec3 = sampled_image2d_array.query_size_lod(0);
40+
41+
// 3D images return 3 components
2442
let size_3d: glam::UVec3 = sampled_image3d.query_size_lod(0);
2543

26-
*output = glam::UVec3::new(size_2d.x, size_2d_array.y, size_3d.z);
44+
// 3D arrayed images return 4 components (width, height, depth, array_layers)
45+
let size_3d_array: glam::UVec4 = sampled_image3d_array.query_size_lod(0);
46+
47+
*output = glam::UVec4::new(
48+
size_1d,
49+
size_1d_array.y,
50+
size_2d.x + size_3d.z,
51+
size_3d_array.w,
52+
);
2753
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// build-fail
2+
// normalize-stderr-test "\S*/crates/spirv-std/src/" -> "$SPIRV_STD_SRC/"
3+
// compile-flags: -C target-feature=+ImageQuery,+SampledRect
4+
5+
use spirv_std::{Image, arch, spirv, image::SampledImage};
6+
7+
#[spirv(fragment)]
8+
pub fn main(
9+
#[spirv(descriptor_set = 0, binding = 0)] rect_sampled: &SampledImage<
10+
Image!(rect, type=f32, sampled),
11+
>,
12+
output: &mut glam::UVec2,
13+
) {
14+
// This should fail because rect images don't support query_size_lod
15+
*output = rect_sampled.query_size_lod(0);
16+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
error[E0277]: the trait bound `Image<f32, 4, 2, 0, 0, 1, 0, 4>: HasQuerySizeLod` is not satisfied
2+
--> $DIR/sampled_image_rect_query_size_lod_err.rs:15:28
3+
|
4+
15 | *output = rect_sampled.query_size_lod(0);
5+
| ^^^^^^^^^^^^^^ the trait `HasQuerySizeLod` is not implemented for `Image<f32, 4, 2, 0, 0, 1, 0, 4>`
6+
|
7+
= help: the following other types implement trait `HasQuerySizeLod`:
8+
Image<SampledType, 0, DEPTH, ARRAYED, 0, SAMPLED, FORMAT, COMPONENTS>
9+
Image<SampledType, 1, DEPTH, ARRAYED, 0, SAMPLED, FORMAT, COMPONENTS>
10+
Image<SampledType, 2, DEPTH, ARRAYED, 0, SAMPLED, FORMAT, COMPONENTS>
11+
Image<SampledType, 3, DEPTH, ARRAYED, 0, SAMPLED, FORMAT, COMPONENTS>
12+
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`
13+
--> /image.rs:1138:12
14+
|
15+
1124 | pub fn query_size_lod<Size: ImageSizeQuery<u32, DIM, ARRAYED> + Default>(
16+
| -------------- required by a bound in this associated function
17+
...
18+
1138 | >: HasQuerySizeLod,
19+
| ^^^^^^^^^^^^^^^ required by this bound in `SampledImage::<Image<SampledType, DIM, DEPTH, ARRAYED, spirv_std::::image::{impl#9}::{constant#0}, SAMPLED, FORMAT, COMPONENTS>>::query_size_lod`
20+
21+
error: aborting due to 1 previous error
22+
23+
For more information about this error, try `rustc --explain E0277`.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// build-pass
2+
// compile-flags: -C target-feature=+ImageQuery,+Sampled1D,+SampledBuffer
3+
4+
use spirv_std::spirv;
5+
use spirv_std::{Image, arch};
6+
7+
#[spirv(fragment)]
8+
pub fn main(
9+
#[spirv(descriptor_set = 0, binding = 0)] buffer_image: &Image!(buffer, type=f32, sampled=false),
10+
#[spirv(descriptor_set = 1, binding = 1)] storage_1d: &Image!(1D, type=f32, sampled=false),
11+
#[spirv(descriptor_set = 2, binding = 2)] storage_1d_array: &Image!(1D, type=f32, sampled=false, arrayed),
12+
#[spirv(descriptor_set = 3, binding = 3)] storage_3d_array: &Image!(3D, type=f32, sampled=false, arrayed),
13+
output: &mut glam::UVec4,
14+
) {
15+
// Buffer images return scalar (number of texels)
16+
let buffer_size: u32 = buffer_image.query_size();
17+
18+
// 1D storage images return scalar
19+
let size_1d: u32 = storage_1d.query_size();
20+
21+
// 1D arrayed storage images return 2 components
22+
let size_1d_array: glam::UVec2 = storage_1d_array.query_size();
23+
24+
// 3D arrayed storage images return 4 components
25+
let size_3d_array: glam::UVec4 = storage_3d_array.query_size();
26+
27+
*output = glam::UVec4::new(buffer_size, size_1d, size_1d_array.y, size_3d_array.w);
28+
}

0 commit comments

Comments
 (0)