mirror of
https://github.com/bevyengine/bevy
synced 2024-11-24 21:53:07 +00:00
d261a86b9f
# Objective - Fixes #9670 - Avoid a crash in CI due to ``` thread 'Compute Task Pool (0)' panicked at /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wgpu-0.19.1/src/backend/wgpu_core.rs:3009:5: wgpu error: Validation Error Caused by: In Device::create_bind_group The adapter does not support read access for storages texture of format Rgba8Unorm ``` ## Solution - Use an `R32Float` texture instead of an `Rgba8Unorm` as it's a tier 1 texture format https://github.com/gpuweb/gpuweb/issues/3838 and is more supported - This should also improve support for webgpu in the next wgpu version
65 lines
No EOL
1.9 KiB
WebGPU Shading Language
65 lines
No EOL
1.9 KiB
WebGPU Shading Language
@group(0) @binding(0) var texture: texture_storage_2d<r32float, read_write>;
|
|
|
|
fn hash(value: u32) -> u32 {
|
|
var state = value;
|
|
state = state ^ 2747636419u;
|
|
state = state * 2654435769u;
|
|
state = state ^ state >> 16u;
|
|
state = state * 2654435769u;
|
|
state = state ^ state >> 16u;
|
|
state = state * 2654435769u;
|
|
return state;
|
|
}
|
|
|
|
fn randomFloat(value: u32) -> f32 {
|
|
return f32(hash(value)) / 4294967295.0;
|
|
}
|
|
|
|
@compute @workgroup_size(8, 8, 1)
|
|
fn init(@builtin(global_invocation_id) invocation_id: vec3<u32>, @builtin(num_workgroups) num_workgroups: vec3<u32>) {
|
|
let location = vec2<i32>(i32(invocation_id.x), i32(invocation_id.y));
|
|
|
|
let randomNumber = randomFloat(invocation_id.y * num_workgroups.x + invocation_id.x);
|
|
let alive = randomNumber > 0.9;
|
|
let color = vec4<f32>(f32(alive));
|
|
|
|
textureStore(texture, location, color);
|
|
}
|
|
|
|
fn is_alive(location: vec2<i32>, offset_x: i32, offset_y: i32) -> i32 {
|
|
let value: vec4<f32> = textureLoad(texture, location + vec2<i32>(offset_x, offset_y));
|
|
return i32(value.x);
|
|
}
|
|
|
|
fn count_alive(location: vec2<i32>) -> i32 {
|
|
return is_alive(location, -1, -1) +
|
|
is_alive(location, -1, 0) +
|
|
is_alive(location, -1, 1) +
|
|
is_alive(location, 0, -1) +
|
|
is_alive(location, 0, 1) +
|
|
is_alive(location, 1, -1) +
|
|
is_alive(location, 1, 0) +
|
|
is_alive(location, 1, 1);
|
|
}
|
|
|
|
@compute @workgroup_size(8, 8, 1)
|
|
fn update(@builtin(global_invocation_id) invocation_id: vec3<u32>) {
|
|
let location = vec2<i32>(i32(invocation_id.x), i32(invocation_id.y));
|
|
|
|
let n_alive = count_alive(location);
|
|
|
|
var alive: bool;
|
|
if (n_alive == 3) {
|
|
alive = true;
|
|
} else if (n_alive == 2) {
|
|
let currently_alive = is_alive(location, 0, 0);
|
|
alive = bool(currently_alive);
|
|
} else {
|
|
alive = false;
|
|
}
|
|
let color = vec4<f32>(f32(alive));
|
|
|
|
storageBarrier();
|
|
|
|
textureStore(texture, location, color);
|
|
} |