Potential sync bug when two compute pipelines access same buffer that is written to via queue.write_buffer
?
#3918
Closed
LukasKalbertodt
started this conversation in
General
Replies: 1 comment 2 replies
-
If you are submitting multiple let encoder = create_command_encoder();
write_buffer();
encoder.begin_compute_pass();
encoder.begin_render_pass();
write_buffer();
encoder.begin_compute_pass();
encoder.begin_render_pass(); then the second compute pass would not see the cleared buffer you wanted; the actual order of operations will be |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am not sure if this should be an issue instead, but I am very unsure about this all, so I'm just throwing it out here.
I built a GPU driven renderer that consists of a compute pass, which culls whole clusters, and a render pass that renders the surviving clusters via multi draw indirect. Roughly much what is described here. Three buffers are important:
cluster_buffer
, containing a list of clusters. This is written by the CPU and read by the compute pass.count_buffer
which is only 4 bytes large. Cleared by the CPU and used in the compute pass byatomic_add()
ing to it, using the returned number as an index into the indirect buffer.indirect_buffer
: contains a list of draw calls. Written by the compute pass.The actual draw call is
multi_draw_indexed_indirect_count(indirect_buffer, 0, count_buffer, 0, _)
. Before each compute pass, the count buffer is cleared. The indirect buffer is not touched, as it's just being overwritten from the start again.Now to the actual problem: for whatever reason, I cleared the count buffer via
queue.write_buffer(&count_buffer, 0, &[0u8; 4])
and not viaencoder.clear_buffer(&count_buffer, 0, None);
. Thewrite_buffer
approach worked for a while, until I performed multiple (cull+draw) operations per frame (for shadow map generation). Suddenly, I got flickering geometry and lots of other weird effects. Nothing made any sense anymore. After quite a bit of debugging and trying things out, I switched that one line toencoder.clear_buffer
and that solved all problems. (Vulkan, Linux, Nvidia)I'm glad it now works, but I'm not sure if this is something wgpu could improve? Or is this documented undefined behavior and I was simply a dumbo? Could anyone point me to additional resources on this?
On the other hand, if this sounds like a bug, I can provide more information or try to provide a minimal example.
(Thanks a ton for wgpu!!)
Beta Was this translation helpful? Give feedback.
All reactions