From 354648af9a7c7a3cb8dce5a4638ab670697c20e3 Mon Sep 17 00:00:00 2001 From: firestar99 Date: Mon, 1 Dec 2025 12:30:56 +0100 Subject: [PATCH 1/2] image texel write: compiletests with explicit formats, fails for scalar formats --- .../ui/image/write_format_scalar.rs | 16 ++++++++++ .../ui/image/write_format_scalar.stderr | 30 +++++++++++++++++++ .../ui/image/write_format_vec2.rs | 17 +++++++++++ .../ui/image/write_format_vec4.rs | 16 ++++++++++ 4 files changed, 79 insertions(+) create mode 100644 tests/compiletests/ui/image/write_format_scalar.rs create mode 100644 tests/compiletests/ui/image/write_format_scalar.stderr create mode 100644 tests/compiletests/ui/image/write_format_vec2.rs create mode 100644 tests/compiletests/ui/image/write_format_vec4.rs diff --git a/tests/compiletests/ui/image/write_format_scalar.rs b/tests/compiletests/ui/image/write_format_scalar.rs new file mode 100644 index 0000000000..2bf227358c --- /dev/null +++ b/tests/compiletests/ui/image/write_format_scalar.rs @@ -0,0 +1,16 @@ +// Test `OpImageWrite` +// build-pass + +use spirv_std::glam::*; +use spirv_std::spirv; +use spirv_std::{Image, arch}; + +#[spirv(fragment)] +pub fn main( + texels: f32, + #[spirv(descriptor_set = 0, binding = 0)] image: &Image!(2D, format = r32f, sampled = false), +) { + unsafe { + image.write(UVec2::new(0, 1), texels); + } +} diff --git a/tests/compiletests/ui/image/write_format_scalar.stderr b/tests/compiletests/ui/image/write_format_scalar.stderr new file mode 100644 index 0000000000..0cab7d6441 --- /dev/null +++ b/tests/compiletests/ui/image/write_format_scalar.stderr @@ -0,0 +1,30 @@ +error[E0277]: the trait bound `f32: Vector` is not satisfied + --> $DIR/write_format_scalar.rs:14:39 + | +LL | image.write(UVec2::new(0, 1), texels); + | ----- ^^^^^^ the trait `Vector` is not implemented for `f32` + | | + | required by a bound introduced by this call + | + = help: the following other types implement trait `Vector`: + `BVec2` implements `Vector` + `BVec3` implements `Vector` + `BVec4` implements `Vector` + `DVec2` implements `Vector` + `DVec3` implements `Vector` + `DVec4` implements `Vector` + `IVec2` implements `Vector` + `IVec3` implements `Vector` + and 8 others +note: required by a bound in `Image::::write` + --> /home/firestar99/workspace/rust-gpu/crates/spirv-std/src/image.rs:805:22 + | +LL | pub unsafe fn write( + | ----- required by a bound in this associated function +... +LL | texels: impl Vector, + | ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Image::::write` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/compiletests/ui/image/write_format_vec2.rs b/tests/compiletests/ui/image/write_format_vec2.rs new file mode 100644 index 0000000000..8de4821a6a --- /dev/null +++ b/tests/compiletests/ui/image/write_format_vec2.rs @@ -0,0 +1,17 @@ +// Test `OpImageWrite` +// build-pass +// compile-flags: -C target-feature=+StorageImageExtendedFormats + +use spirv_std::glam::*; +use spirv_std::spirv; +use spirv_std::{Image, arch}; + +#[spirv(fragment)] +pub fn main( + texels: Vec2, + #[spirv(descriptor_set = 0, binding = 0)] image: &Image!(2D, format = rg32f, sampled = false), +) { + unsafe { + image.write(UVec2::new(0, 1), texels); + } +} diff --git a/tests/compiletests/ui/image/write_format_vec4.rs b/tests/compiletests/ui/image/write_format_vec4.rs new file mode 100644 index 0000000000..8ae9df41ea --- /dev/null +++ b/tests/compiletests/ui/image/write_format_vec4.rs @@ -0,0 +1,16 @@ +// Test `OpImageWrite` +// build-pass + +use spirv_std::glam::*; +use spirv_std::spirv; +use spirv_std::{Image, arch}; + +#[spirv(fragment)] +pub fn main( + texels: Vec4, + #[spirv(descriptor_set = 0, binding = 0)] image: &Image!(2D, format = rgba32f, sampled = false), +) { + unsafe { + image.write(UVec2::new(0, 1), texels); + } +} From 7efddcdea73d44512d612fe062338df12edb5c8c Mon Sep 17 00:00:00 2001 From: firestar99 Date: Mon, 1 Dec 2025 12:33:28 +0100 Subject: [PATCH 2/2] image texel write: change texel write arg from any vector to `SampleResult`, allows scalars * breakage: no longer allows any vector, type must match image format * allows texel writes into single-component scalar textures --- crates/spirv-std/src/image.rs | 10 +++---- tests/compiletests/ui/image/issue_527.rs | 2 +- tests/compiletests/ui/image/write.rs | 5 ++-- .../ui/image/write_format_scalar.stderr | 30 ------------------- 4 files changed, 9 insertions(+), 38 deletions(-) delete mode 100644 tests/compiletests/ui/image/write_format_scalar.stderr diff --git a/crates/spirv-std/src/image.rs b/crates/spirv-std/src/image.rs index 9fa844d087..f1f72f676e 100644 --- a/crates/spirv-std/src/image.rs +++ b/crates/spirv-std/src/image.rs @@ -4,7 +4,7 @@ pub use self::params::{ImageCoordinate, ImageCoordinateSubpassData, ImageSizeQue #[cfg(target_arch = "spirv")] use crate::VectorTruncateInto; pub use crate::macros::Image; -use crate::{Float, Integer, Sampler, Vector}; +use crate::{Float, Integer, Sampler}; #[cfg(target_arch = "spirv")] use core::arch::asm; use sample_with::{NoneTy, SampleParams, SomeTy}; @@ -799,10 +799,10 @@ impl< /// Write a texel to an image without a sampler. #[crate::macros::gpu_only] #[doc(alias = "OpImageWrite")] - pub unsafe fn write( + pub unsafe fn write( &self, coordinate: impl ImageCoordinate, - texels: impl Vector, + texels: SampledType::SampleResult, ) where I: Integer, { @@ -873,10 +873,10 @@ impl< /// Write a texel to an image without a sampler. #[crate::macros::gpu_only] #[doc(alias = "OpImageWrite")] - pub unsafe fn write( + pub unsafe fn write( &self, coordinate: impl ImageCoordinate, - texels: impl Vector, + texels: SampledType::SampleResult, ) where I: Integer, { diff --git a/tests/compiletests/ui/image/issue_527.rs b/tests/compiletests/ui/image/issue_527.rs index 1e81023671..41d4b85863 100644 --- a/tests/compiletests/ui/image/issue_527.rs +++ b/tests/compiletests/ui/image/issue_527.rs @@ -16,7 +16,7 @@ pub fn main_cs( let p1 = &points_buffer[i + 1]; if p0.x == position.x && p1.y == position.y { unsafe { - image.write(position, vec2(1.0, 0.0)); + image.write(position, vec4(3.0, 2.0, 1.0, 0.0)); }; } } diff --git a/tests/compiletests/ui/image/write.rs b/tests/compiletests/ui/image/write.rs index 34dfae1350..9f24373cc8 100644 --- a/tests/compiletests/ui/image/write.rs +++ b/tests/compiletests/ui/image/write.rs @@ -2,15 +2,16 @@ // build-pass // compile-flags: -C target-feature=+StorageImageWriteWithoutFormat +use spirv_std::glam::*; use spirv_std::spirv; use spirv_std::{Image, arch}; #[spirv(fragment)] pub fn main( - texels: glam::Vec2, + texels: Vec2, #[spirv(descriptor_set = 0, binding = 0)] image: &Image!(2D, type=f32, sampled=false), ) { unsafe { - image.write(glam::UVec2::new(0, 1), texels); + image.write(UVec2::new(0, 1), Vec4::from((texels, 0., 0.))); } } diff --git a/tests/compiletests/ui/image/write_format_scalar.stderr b/tests/compiletests/ui/image/write_format_scalar.stderr deleted file mode 100644 index 0cab7d6441..0000000000 --- a/tests/compiletests/ui/image/write_format_scalar.stderr +++ /dev/null @@ -1,30 +0,0 @@ -error[E0277]: the trait bound `f32: Vector` is not satisfied - --> $DIR/write_format_scalar.rs:14:39 - | -LL | image.write(UVec2::new(0, 1), texels); - | ----- ^^^^^^ the trait `Vector` is not implemented for `f32` - | | - | required by a bound introduced by this call - | - = help: the following other types implement trait `Vector`: - `BVec2` implements `Vector` - `BVec3` implements `Vector` - `BVec4` implements `Vector` - `DVec2` implements `Vector` - `DVec3` implements `Vector` - `DVec4` implements `Vector` - `IVec2` implements `Vector` - `IVec3` implements `Vector` - and 8 others -note: required by a bound in `Image::::write` - --> /home/firestar99/workspace/rust-gpu/crates/spirv-std/src/image.rs:805:22 - | -LL | pub unsafe fn write( - | ----- required by a bound in this associated function -... -LL | texels: impl Vector, - | ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Image::::write` - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0277`.