Skip to content

Commit

Permalink
Fix shader binding bug (#356)
Browse files Browse the repository at this point in the history
Fix a bug where the render shader attempts to bind the `Spawner` storage
buffer as read-only, but that struct is defined as containing an atomic
variable, which according to the WGSL specification requires write
access. Add a pipeline define `SPAWNER_READONLY` to redefine that struct
field as non-atomic, to allow read-only binding.
  • Loading branch information
djeedai authored Jul 30, 2024
1 parent 2705b2a commit 05016ec
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1154,7 +1154,7 @@ impl SpecializedRenderPipeline for ParticlesRenderPipeline {
.create_bind_group_layout("hanabi:buffer_layout_render", &entries);

let mut layout = vec![self.view_layout.clone(), particles_buffer_layout];
let mut shader_defs = vec![];
let mut shader_defs = vec!["SPAWNER_READONLY".into()];

// Key: PARTICLE_TEXTURE
if key.has_image {
Expand Down
5 changes: 5 additions & 0 deletions src/render/vfx_common.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ struct Spawner {
inverse_transform: mat3x4<f32>, // transposed (row-major)
spawn: i32,
seed: u32,
// Can't use storage<read> with atomics
#ifdef SPAWNER_READONLY
count: i32,
#else
count: atomic<i32>,
#endif
effect_index: u32,
#ifdef SPAWNER_PADDING
{{SPAWNER_PADDING}}
Expand Down

0 comments on commit 05016ec

Please sign in to comment.