From 585f4a103660dfa0cb1a7fcea49ebd066fa75a48 Mon Sep 17 00:00:00 2001 From: Samson <16504129+sagudev@users.noreply.github.com> Date: Sat, 31 Aug 2024 11:08:34 +0200 Subject: [PATCH] [naga wgsl] all swizzle components must be either color or dimension (#6187) --- naga/src/front/wgsl/lower/mod.rs | 8 +++++++- naga/tests/wgsl_errors.rs | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/naga/src/front/wgsl/lower/mod.rs b/naga/src/front/wgsl/lower/mod.rs index 100d91c614..2e6fa0533f 100644 --- a/naga/src/front/wgsl/lower/mod.rs +++ b/naga/src/front/wgsl/lower/mod.rs @@ -907,7 +907,13 @@ impl Components { *comp = Self::letter_component(ch).ok_or(Error::BadAccessor(name_span))?; } - Ok(Components::Swizzle { size, pattern }) + if name.chars().all(|c| matches!(c, 'x' | 'y' | 'z' | 'w')) + || name.chars().all(|c| matches!(c, 'r' | 'g' | 'b' | 'a')) + { + Ok(Components::Swizzle { size, pattern }) + } else { + Err(Error::BadAccessor(name_span)) + } } } diff --git a/naga/tests/wgsl_errors.rs b/naga/tests/wgsl_errors.rs index 76f3d56687..61d5b9816f 100644 --- a/naga/tests/wgsl_errors.rs +++ b/naga/tests/wgsl_errors.rs @@ -2371,3 +2371,21 @@ fn local_const_from_global_var() { "###, ); } + +#[test] +fn only_one_swizzle_type() { + check( + " + const ok1 = vec2(0.0, 0.0).xy; + const ok2 = vec2(0.0, 0.0).rg; + const err = vec2(0.0, 0.0).xg; + ", + r###"error: invalid field accessor `xg` + ┌─ wgsl:4:36 + │ +4 │ const err = vec2(0.0, 0.0).xg; + │ ^^ invalid accessor + +"###, + ); +}