From 08d34356adf6a67fb11d0204718eb126f611c136 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 23 Sep 2025 10:48:00 +1000 Subject: [PATCH 1/5] Rename `parsing_error` as `parse_error`. `parsing_error` reads strangely. `parse_error` is much more normal. --- crates/spirv-std/macros/src/lib.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/crates/spirv-std/macros/src/lib.rs b/crates/spirv-std/macros/src/lib.rs index 504478b5ae..b28dd46d4c 100644 --- a/crates/spirv-std/macros/src/lib.rs +++ b/crates/spirv-std/macros/src/lib.rs @@ -333,7 +333,7 @@ impl syn::parse::Parse for DebugPrintfInput { } } -fn parsing_error(message: &str, span: Span) -> TokenStream { +fn parse_error(message: &str, span: Span) -> TokenStream { syn::Error::new(span, message).to_compile_error().into() } @@ -391,7 +391,7 @@ fn debug_printf_inner(input: DebugPrintfInput) -> TokenStream { if ch == '%' { ch = match chars.next() { Some('%') => continue, - None => return parsing_error("Unterminated format specifier", span), + None => return parse_error("Unterminated format specifier", span), Some(ch) => ch, }; @@ -401,7 +401,7 @@ fn debug_printf_inner(input: DebugPrintfInput) -> TokenStream { ch = match chars.next() { Some(ch) => ch, None => { - return parsing_error( + return parse_error( "Unterminated format specifier: missing type after precision", span, ); @@ -415,7 +415,7 @@ fn debug_printf_inner(input: DebugPrintfInput) -> TokenStream { ch = match chars.next() { Some(ch) => ch, None => { - return parsing_error( + return parse_error( "Unterminated format specifier: missing type after decimal point", span, ); @@ -426,7 +426,7 @@ fn debug_printf_inner(input: DebugPrintfInput) -> TokenStream { ch = match chars.next() { Some(ch) => ch, None => { - return parsing_error( + return parse_error( "Unterminated format specifier: missing type after fraction precision", span, ); @@ -441,20 +441,20 @@ fn debug_printf_inner(input: DebugPrintfInput) -> TokenStream { Some('3') => 3, Some('4') => 4, Some(ch) => { - return parsing_error(&format!("Invalid width for vector: {ch}"), span); + return parse_error(&format!("Invalid width for vector: {ch}"), span); } - None => return parsing_error("Missing vector dimensions specifier", span), + None => return parse_error("Missing vector dimensions specifier", span), }; ch = match chars.next() { Some(ch) => ch, - None => return parsing_error("Missing vector type specifier", span), + None => return parse_error("Missing vector type specifier", span), }; let ty = match map_specifier_to_type(ch, &mut chars) { Some(ty) => ty, _ => { - return parsing_error( + return parse_error( &format!("Unrecognised vector type specifier: '{ch}'"), span, ); @@ -466,7 +466,7 @@ fn debug_printf_inner(input: DebugPrintfInput) -> TokenStream { let ty = match map_specifier_to_type(ch, &mut chars) { Some(ty) => ty, _ => { - return parsing_error( + return parse_error( &format!("Unrecognised format specifier: '{ch}'"), span, ); From 34f10302f4a6145065543ef1f544f77e94bc6722 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 23 Sep 2025 10:56:24 +1000 Subject: [PATCH 2/5] Remove extraneous whitespace in `lod_type`. --- crates/spirv-std/macros/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/spirv-std/macros/src/lib.rs b/crates/spirv-std/macros/src/lib.rs index b28dd46d4c..71270a164a 100644 --- a/crates/spirv-std/macros/src/lib.rs +++ b/crates/spirv-std/macros/src/lib.rs @@ -701,7 +701,7 @@ impl VisitMut for SampleImplRewriter { let lod_type = if self.0 & SAMPLE_PARAM_EXPLICIT_LOD_MASK != 0 { "ExplicitLod" } else { - "ImplicitLod " + "ImplicitLod" }; let s = s.replace("$LOD", lod_type); From eb73a89a161e1f7180d93bfc38eb65c59b7d562f Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 23 Sep 2025 14:20:47 +1000 Subject: [PATCH 3/5] Simplify `sample_type_impls!`. - The first `@single_rule` rule just repeats the contents of the subsequent four `@single_rule` rules. So just call them. - The subsequent four `@single_rule` rules don't need to handle repetition, because the first rule handles that. --- crates/spirv-std/src/image/params.rs | 54 +++++++--------------------- 1 file changed, 13 insertions(+), 41 deletions(-) diff --git a/crates/spirv-std/src/image/params.rs b/crates/spirv-std/src/image/params.rs index b4da908e55..1d2e813d66 100644 --- a/crates/spirv-std/src/image/params.rs +++ b/crates/spirv-std/src/image/params.rs @@ -20,27 +20,39 @@ pub trait SampleType: Scalar { /// Helper macro to implement `SampleType` of various formats for various scalar types. macro_rules! sample_type_impls { ($($fmt:ident : $n:tt*$s:ty => ($v1:ty, $v2:ty, $v3:ty, $v4:ty)),+ $(,)?) => { - $(sample_type_impls!{@single_rule, $fmt : $n*$s => ($v1,$v2,$v3,$v4)})+ + $(sample_type_impls! { @single_rule, $fmt : $n*$s => ($v1,$v2,$v3,$v4) })+ }; (@single_rule, $fmt:ident : n*$s:ty => ($v1:ty, $v2:ty, $v3:ty, $v4:ty)) => { + sample_type_impls! { @single_rule, $fmt: 1*$s => ($v1, $v2, $v3, $v4) } + sample_type_impls! { @single_rule, $fmt: 2*$s => ($v1, $v2, $v3, $v4) } + sample_type_impls! { @single_rule, $fmt: 3*$s => ($v1, $v2, $v3, $v4) } + sample_type_impls! { @single_rule, $fmt: 4*$s => ($v1, $v2, $v3, $v4) } + }; + (@single_rule, $fmt:ident : 1*$s:ty => ($v1:ty, $v2:ty, $v3:ty, $v4:ty)) => { impl SampleType<{ ImageFormat::$fmt as u32 }, 1> for $s { type SampleResult = $v1; type Vec2 = $v2; type Vec3 = $v3; type Vec4 = $v4; } + }; + (@single_rule, $fmt:ident : 2*$s:ty => ($v1:ty, $v2:ty, $v3:ty, $v4:ty)) => { impl SampleType<{ ImageFormat::$fmt as u32 }, 2> for $s { type SampleResult = $v2; type Vec2 = $v2; type Vec3 = $v3; type Vec4 = $v4; } + }; + (@single_rule, $fmt:ident : 3*$s:ty => ($v1:ty, $v2:ty, $v3:ty, $v4:ty)) => { impl SampleType<{ ImageFormat::$fmt as u32 }, 3> for $s { type SampleResult = $v3; type Vec2 = $v2; type Vec3 = $v3; type Vec4 = $v4; } + }; + (@single_rule, $fmt:ident : 4*$s:ty => ($v1:ty, $v2:ty, $v3:ty, $v4:ty)) => { impl SampleType<{ ImageFormat::$fmt as u32 }, 4> for $s { type SampleResult = $v4; type Vec2 = $v2; @@ -48,46 +60,6 @@ macro_rules! sample_type_impls { type Vec4 = $v4; } }; - (@single_rule, $($fmt:ident : 1*$s:ty => ($v1:ty, $v2:ty, $v3:ty, $v4:ty)),+ $(,)?) => { - $( - impl SampleType<{ ImageFormat::$fmt as u32 }, 1> for $s { - type SampleResult = $v1; - type Vec2 = $v2; - type Vec3 = $v3; - type Vec4 = $v4; - } - )+ - }; - (@single_rule, $($fmt:ident : 2*$s:ty => ($v1:ty, $v2:ty, $v3:ty, $v4:ty)),+ $(,)?) => { - $( - impl SampleType<{ ImageFormat::$fmt as u32 }, 2> for $s { - type SampleResult = $v2; - type Vec2 = $v2; - type Vec3 = $v3; - type Vec4 = $v4; - } - )+ - }; - (@single_rule, $($fmt:ident : 3*$s:ty => ($v1:ty, $v2:ty, $v3:ty, $v4:ty)),+ $(,)?) => { - $( - impl SampleType<{ ImageFormat::$fmt as u32 }, 3> for $s { - type SampleResult = $v3; - type Vec2 = $v2; - type Vec3 = $v3; - type Vec4 = $v4; - } - )+ - }; - (@single_rule, $($fmt:ident : 4*$s:ty => ($v1:ty, $v2:ty, $v3:ty, $v4:ty)),+ $(,)?) => { - $( - impl SampleType<{ ImageFormat::$fmt as u32 }, 4> for $s { - type SampleResult = $v4; - type Vec2 = $v2; - type Vec3 = $v3; - type Vec4 = $v4; - } - )+ - }; } sample_type_impls! { From 4fce3d2ef883a4fa9b0a9823e7593d3efcd2e302 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 23 Sep 2025 10:52:01 +1000 Subject: [PATCH 4/5] Remove an unnecessary `pub`. --- crates/spirv-std/macros/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/spirv-std/macros/src/lib.rs b/crates/spirv-std/macros/src/lib.rs index 71270a164a..183b78fc47 100644 --- a/crates/spirv-std/macros/src/lib.rs +++ b/crates/spirv-std/macros/src/lib.rs @@ -561,7 +561,7 @@ fn is_grad(i: usize) -> bool { struct SampleImplRewriter(usize, syn::Type); impl SampleImplRewriter { - pub fn rewrite(mask: usize, f: &syn::ItemImpl) -> syn::ItemImpl { + fn rewrite(mask: usize, f: &syn::ItemImpl) -> syn::ItemImpl { let mut new_impl = f.clone(); let mut ty_str = String::from("SampleParams<"); From 2b20d8255f337d3e80a88b20502d3822ca01f685 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 23 Sep 2025 10:40:47 +1000 Subject: [PATCH 5/5] Fix some formatting. --- crates/spirv-std/macros/src/lib.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/spirv-std/macros/src/lib.rs b/crates/spirv-std/macros/src/lib.rs index 183b78fc47..4ef6f95b3e 100644 --- a/crates/spirv-std/macros/src/lib.rs +++ b/crates/spirv-std/macros/src/lib.rs @@ -265,7 +265,9 @@ pub fn gpu_only(_attr: TokenStream, item: TokenStream) -> TokenStream { #[cfg(not(target_arch="spirv"))] #[allow(unused_variables)] #(#attrs)* #vis #sig_cpu { - unimplemented!(concat!("`", stringify!(#fn_name), "` is only available on SPIR-V platforms.")) + unimplemented!( + concat!("`", stringify!(#fn_name), "` is only available on SPIR-V platforms.") + ) } #[cfg(target_arch="spirv")]