Skip to content

Commit 119eb51

Browse files
authored
Fix game_of_life shader relying on Naga bug (#18951)
# Objective The game of life example shader relies on a Naga bug ([6397](gfx-rs/wgpu#6397) / [4536](gfx-rs/wgpu#4536)). In WGSL certain arithmetic operations must be explicitly parenthesized ([reference](https://www.w3.org/TR/WGSL/#operator-precedence-associativity)). Naga doesn't enforce that (and also the precedence order is [messed up](gfx-rs/wgpu#4536 (comment))). So this example may break soon. This is the only sample shader having this issue. ## Solution added parentheses ## Testing ran the example before and after the fix with `cargo run --example compute_shader_game_of_life`
1 parent 78d9f05 commit 119eb51

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

assets/shaders/game_of_life.wgsl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ fn hash(value: u32) -> u32 {
1212
var state = value;
1313
state = state ^ 2747636419u;
1414
state = state * 2654435769u;
15-
state = state ^ state >> 16u;
15+
state = state ^ (state >> 16u);
1616
state = state * 2654435769u;
17-
state = state ^ state >> 16u;
17+
state = state ^ (state >> 16u);
1818
state = state * 2654435769u;
1919
return state;
2020
}
@@ -27,7 +27,7 @@ fn randomFloat(value: u32) -> f32 {
2727
fn init(@builtin(global_invocation_id) invocation_id: vec3<u32>, @builtin(num_workgroups) num_workgroups: vec3<u32>) {
2828
let location = vec2<i32>(i32(invocation_id.x), i32(invocation_id.y));
2929

30-
let randomNumber = randomFloat(invocation_id.y << 16u | invocation_id.x);
30+
let randomNumber = randomFloat((invocation_id.y << 16u) | invocation_id.x);
3131
let alive = randomNumber > 0.9;
3232
let color = vec4<f32>(f32(alive));
3333

0 commit comments

Comments
 (0)