Skip to content

Commit

Permalink
[naga wgsl] all swizzle components must be either color or dimension (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
sagudev authored Aug 31, 2024
1 parent 04618b3 commit 585f4a1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
8 changes: 7 additions & 1 deletion naga/src/front/wgsl/lower/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
}

Expand Down
18 changes: 18 additions & 0 deletions naga/tests/wgsl_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
"###,
);
}

0 comments on commit 585f4a1

Please sign in to comment.