Skip to content
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
28 changes: 15 additions & 13 deletions crates/spirv-std/macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -333,7 +335,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()
}

Expand Down Expand Up @@ -391,7 +393,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,
};

Expand All @@ -401,7 +403,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,
);
Expand All @@ -415,7 +417,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,
);
Expand All @@ -426,7 +428,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,
);
Expand All @@ -441,20 +443,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,
);
Expand All @@ -466,7 +468,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,
);
Expand Down Expand Up @@ -561,7 +563,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<");

Expand Down Expand Up @@ -701,7 +703,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);

Expand Down
54 changes: 13 additions & 41 deletions crates/spirv-std/src/image/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,74 +20,46 @@ pub trait SampleType<const FORMAT: u32, const COMPONENTS: u32>: 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;
type Vec3 = $v3;
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! {
Expand Down