Skip to content

Commit 585f4a1

Browse files
authored
[naga wgsl] all swizzle components must be either color or dimension (#6187)
1 parent 04618b3 commit 585f4a1

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

naga/src/front/wgsl/lower/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,13 @@ impl Components {
907907
*comp = Self::letter_component(ch).ok_or(Error::BadAccessor(name_span))?;
908908
}
909909

910-
Ok(Components::Swizzle { size, pattern })
910+
if name.chars().all(|c| matches!(c, 'x' | 'y' | 'z' | 'w'))
911+
|| name.chars().all(|c| matches!(c, 'r' | 'g' | 'b' | 'a'))
912+
{
913+
Ok(Components::Swizzle { size, pattern })
914+
} else {
915+
Err(Error::BadAccessor(name_span))
916+
}
911917
}
912918
}
913919

naga/tests/wgsl_errors.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2371,3 +2371,21 @@ fn local_const_from_global_var() {
23712371
"###,
23722372
);
23732373
}
2374+
2375+
#[test]
2376+
fn only_one_swizzle_type() {
2377+
check(
2378+
"
2379+
const ok1 = vec2(0.0, 0.0).xy;
2380+
const ok2 = vec2(0.0, 0.0).rg;
2381+
const err = vec2(0.0, 0.0).xg;
2382+
",
2383+
r###"error: invalid field accessor `xg`
2384+
┌─ wgsl:4:36
2385+
2386+
4 │ const err = vec2(0.0, 0.0).xg;
2387+
│ ^^ invalid accessor
2388+
2389+
"###,
2390+
);
2391+
}

0 commit comments

Comments
 (0)