Unintended branch optimization

My updated understanding:

  1. One GPUBuffer for both passes.
    Under the hood, queue.writeBuffer (or whatever staging copy you use) only schedules a write OP; the GPU doesn’t necessarily “sample” the contents at the moment you bind the group, but rather when it actually executes that draw command.
  2. Second write overwrote the first.
    By the time the GPU gets around to executing the first pass’s draw call, my second uniform update has already overwritten it’s contents into it’s underlying GPU buffer. Both passes end up seeing the last‐written data.

Fix:
Use two separate GPUBuffers with two separate bindgroups used to represent the same uniform in the vertex shader used by both draw calls; use bindgroup_pass_1 for the first render pass, then use bindgroup_pass_2 for the second render pass.

2 Likes