From 679457f9ed867b2242e9da8b56d98cdc6e5aeab3 Mon Sep 17 00:00:00 2001 From: firestar99 Date: Tue, 22 Sep 2026 18:13:37 +0200 Subject: [PATCH] disallow Vec3A for spirv intrinsics and asm --- CHANGELOG.md | 5 ++++ crates/spirv-std/src/arch/derivative.rs | 3 +-- crates/spirv-std/src/matrix.rs | 26 +++++++++---------- crates/spirv-std/src/scalar_or_vector.rs | 13 ++++++++++ crates/spirv-std/src/vector.rs | 1 - .../ui/arch/debug_printf_type_checking.stderr | 2 +- .../ui/image/sample_depth_reference/sample.rs | 2 +- .../sample_depth_reference/sample_gradient.rs | 8 +++--- .../sample_depth_reference/sample_lod.rs | 4 +-- .../sample.rs | 2 +- .../sample_gradient.rs | 2 +- .../sample_lod.rs | 2 +- 12 files changed, 43 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ece0016fb31..219cda59e0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] + +### 🚨BREAKING🚨️ + +- [PR#660](https://github.com/Rust-GPU/rust-gpu/pull/660) disallows `Vec3A` for SPIR-V intrinsics and asm. Migration: use Vec3 instead and convert back and forward with `Vec3::to_vec3a()` and `Vec3A::to_vec3()`. + ## [0.10.0](https://github.com/Rust-GPU/rust-gpu/compare/v0.10.0-alpha.1...v0.10.0) - 2026-10-01 Toolchain: `nightly-2026-07-03` (rustc 1.98.0) diff --git a/crates/spirv-std/src/arch/derivative.rs b/crates/spirv-std/src/arch/derivative.rs index 6d92a9f9f2b..39157a13830 100644 --- a/crates/spirv-std/src/arch/derivative.rs +++ b/crates/spirv-std/src/arch/derivative.rs @@ -1,4 +1,4 @@ -use crate::glam::{Vec2, Vec3, Vec3A, Vec4}; +use crate::glam::{Vec2, Vec3, Vec4}; use crate::sealed::Sealed; #[cfg(target_arch = "spirv")] @@ -148,4 +148,3 @@ unsafe impl Derivative for f32 {} unsafe impl Derivative for Vec2 {} unsafe impl Derivative for Vec3 {} unsafe impl Derivative for Vec4 {} -unsafe impl Derivative for Vec3A {} diff --git a/crates/spirv-std/src/matrix.rs b/crates/spirv-std/src/matrix.rs index e293619f6a4..1234a20d441 100644 --- a/crates/spirv-std/src/matrix.rs +++ b/crates/spirv-std/src/matrix.rs @@ -1,6 +1,6 @@ //! a set of common SPIR-V Matrices, used for intrinsics -use crate::glam::{Affine3A, Mat3, Mat3A, Mat4, Vec3, Vec3A}; +use crate::glam::{Affine3A, Mat3, Mat3A, Mat4, Vec3}; use core::fmt::{Debug, Display, Formatter}; /// A Matrix with 4 columns of [`Vec3`], very similar to glam's [`Affine3A`]. @@ -18,10 +18,10 @@ use core::fmt::{Debug, Display, Formatter}; #[spirv(matrix)] #[allow(missing_docs)] pub struct Matrix4x3 { - pub x_axis: Vec3A, - pub y_axis: Vec3A, - pub z_axis: Vec3A, - pub w_axis: Vec3A, + pub x_axis: Vec3, + pub y_axis: Vec3, + pub z_axis: Vec3, + pub w_axis: Vec3, } /// The `from_*` fn signatures should match [`Affine3A`], to make it easier to switch to [`Affine3A`] later. @@ -30,10 +30,10 @@ impl Matrix4x3 { /// Convert from glam's [`Affine3A`] pub fn from_affine3a(affine: Affine3A) -> Self { Self { - x_axis: affine.x_axis, - y_axis: affine.y_axis, - z_axis: affine.z_axis, - w_axis: affine.w_axis, + x_axis: affine.x_axis.to_vec3(), + y_axis: affine.y_axis.to_vec3(), + z_axis: affine.z_axis.to_vec3(), + w_axis: affine.w_axis.to_vec3(), } } @@ -61,11 +61,11 @@ impl Matrix4x3 { pub fn to_affine3a(self) -> Affine3A { Affine3A { matrix3: Mat3A { - x_axis: self.x_axis, - y_axis: self.y_axis, - z_axis: self.z_axis, + x_axis: self.x_axis.to_vec3a(), + y_axis: self.y_axis.to_vec3a(), + z_axis: self.z_axis.to_vec3a(), }, - translation: self.w_axis, + translation: self.w_axis.to_vec3a(), } } diff --git a/crates/spirv-std/src/scalar_or_vector.rs b/crates/spirv-std/src/scalar_or_vector.rs index 43ad56d455b..d4e54213b6b 100644 --- a/crates/spirv-std/src/scalar_or_vector.rs +++ b/crates/spirv-std/src/scalar_or_vector.rs @@ -1,3 +1,4 @@ +use crate::glam::Vec3A; use crate::{Scalar, Vector}; use core::num::NonZeroUsize; @@ -83,3 +84,15 @@ impl ScalarComposite for [T; N] { out } } + +/// `glam::Vec3A` is not considered a SPIR-V vector and thus needs a manual implementation +impl ScalarComposite for Vec3A { + #[inline] + fn transform(self, f: &mut F) -> Self { + Vec3A::new( + f.transform_scalar(self.x), + f.transform_scalar(self.y), + f.transform_scalar(self.z), + ) + } +} diff --git a/crates/spirv-std/src/vector.rs b/crates/spirv-std/src/vector.rs index 2a0106c36fc..6e6459a61a1 100644 --- a/crates/spirv-std/src/vector.rs +++ b/crates/spirv-std/src/vector.rs @@ -76,7 +76,6 @@ macro_rules! impl_vector { impl_vector! { glam::Vec2: [f32; 2]; glam::Vec3: [f32; 3]; - glam::Vec3A: [f32; 3]; glam::Vec4: [f32; 4]; glam::DVec2: [f64; 2]; glam::DVec3: [f64; 3]; diff --git a/tests/compiletests/ui/arch/debug_printf_type_checking.stderr b/tests/compiletests/ui/arch/debug_printf_type_checking.stderr index 0e6cd5e4546..86d2f734bed 100644 --- a/tests/compiletests/ui/arch/debug_printf_type_checking.stderr +++ b/tests/compiletests/ui/arch/debug_printf_type_checking.stderr @@ -116,7 +116,7 @@ LL | debug_printf!("%v2f", 11.0); | help: the trait `spirv_std::Vector` is implemented for `Vec2` --> $SPIRV_STD_SRC/vector.rs:71:12 - ::: $SPIRV_STD_SRC/vector.rs:93:1 + ::: $SPIRV_STD_SRC/vector.rs:92:1 | = note: in this macro invocation note: required by a bound in `spirv_std::debug_printf::assert_is_vector` diff --git a/tests/compiletests/ui/image/sample_depth_reference/sample.rs b/tests/compiletests/ui/image/sample_depth_reference/sample.rs index f0a379b2543..825a61f236e 100644 --- a/tests/compiletests/ui/image/sample_depth_reference/sample.rs +++ b/tests/compiletests/ui/image/sample_depth_reference/sample.rs @@ -13,7 +13,7 @@ pub fn main( output: &mut f32, ) { let v2 = glam::Vec2::new(0.0, 1.0); - let v3 = glam::Vec3A::new(0.0, 0.0, 1.0); + let v3 = glam::Vec3::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/compiletests/ui/image/sample_depth_reference/sample_gradient.rs b/tests/compiletests/ui/image/sample_depth_reference/sample_gradient.rs index e10213e6d51..ae8420e974d 100644 --- a/tests/compiletests/ui/image/sample_depth_reference/sample_gradient.rs +++ b/tests/compiletests/ui/image/sample_depth_reference/sample_gradient.rs @@ -14,7 +14,7 @@ pub fn main( 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 = glam::Vec3::new(0.0, 0.0, 1.0); *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); } @@ -37,8 +37,8 @@ pub fn main_cubemap( #[spirv(descriptor_set = 3, binding = 3)] cubemap: &Image!(3D, type=f32, sampled), output: &mut f32, ) { - 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); + let v3 = glam::Vec3::new(0.0, 0.0, 1.0); + let v3_dx = glam::Vec3::new(0.0, 1.0, 0.5); + let v3_dy = glam::Vec3::new(0.0, 1.0, 0.5); *output += cubemap.sample_depth_reference_by_gradient(*sampler, v3, 1.0, v3_dx, v3_dy); } diff --git a/tests/compiletests/ui/image/sample_depth_reference/sample_lod.rs b/tests/compiletests/ui/image/sample_depth_reference/sample_lod.rs index 39bda69dff1..5ff67674389 100644 --- a/tests/compiletests/ui/image/sample_depth_reference/sample_lod.rs +++ b/tests/compiletests/ui/image/sample_depth_reference/sample_lod.rs @@ -12,7 +12,7 @@ pub fn main( output: &mut f32, ) { let v2 = glam::Vec2::new(0.0, 1.0); - let v3 = glam::Vec3A::new(0.0, 0.0, 1.0); + let v3 = glam::Vec3::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); } @@ -35,6 +35,6 @@ pub fn main_cubemap( #[spirv(descriptor_set = 3, binding = 3)] cubemap: &Image!(3D, type=f32, sampled), output: &mut f32, ) { - let v3 = glam::Vec3A::new(0.0, 0.0, 1.0); + let v3 = glam::Vec3::new(0.0, 0.0, 1.0); *output += cubemap.sample_depth_reference_by_lod(*sampler, v3, 1.0, 0.0); } diff --git a/tests/compiletests/ui/image/sample_depth_reference_with_project_coordinate/sample.rs b/tests/compiletests/ui/image/sample_depth_reference_with_project_coordinate/sample.rs index b846e8b5f3a..d756b95dcd8 100644 --- a/tests/compiletests/ui/image/sample_depth_reference_with_project_coordinate/sample.rs +++ b/tests/compiletests/ui/image/sample_depth_reference_with_project_coordinate/sample.rs @@ -10,6 +10,6 @@ pub fn main( #[spirv(descriptor_set = 1, binding = 1)] sampler: &Sampler, output: &mut f32, ) { - let v3 = glam::Vec3A::new(0.0, 0.0, 1.0); + let v3 = glam::Vec3::new(0.0, 0.0, 1.0); *output = image.sample_depth_reference_with_project_coordinate(*sampler, v3, 1.0); } diff --git a/tests/compiletests/ui/image/sample_depth_reference_with_project_coordinate/sample_gradient.rs b/tests/compiletests/ui/image/sample_depth_reference_with_project_coordinate/sample_gradient.rs index d1f5aba513e..00da9fcec63 100644 --- a/tests/compiletests/ui/image/sample_depth_reference_with_project_coordinate/sample_gradient.rs +++ b/tests/compiletests/ui/image/sample_depth_reference_with_project_coordinate/sample_gradient.rs @@ -12,7 +12,7 @@ pub fn main( ) { 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 = glam::Vec3::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/compiletests/ui/image/sample_depth_reference_with_project_coordinate/sample_lod.rs b/tests/compiletests/ui/image/sample_depth_reference_with_project_coordinate/sample_lod.rs index 7c9e75693ad..1c0f2214739 100644 --- a/tests/compiletests/ui/image/sample_depth_reference_with_project_coordinate/sample_lod.rs +++ b/tests/compiletests/ui/image/sample_depth_reference_with_project_coordinate/sample_lod.rs @@ -10,6 +10,6 @@ pub fn main( #[spirv(descriptor_set = 1, binding = 1)] sampler: &Sampler, output: &mut f32, ) { - let v3 = glam::Vec3A::new(0.0, 0.0, 1.0); + let v3 = glam::Vec3::new(0.0, 0.0, 1.0); *output = image.sample_depth_reference_with_project_coordinate_by_lod(*sampler, v3, 1.0, 0.0); }