wgpu icon indicating copy to clipboard operation
wgpu copied to clipboard

Ensure safety of indirect draw/dispatch

Open kvark opened this issue 3 years ago • 4 comments

When doing an indirect draw, the range of vertices/indices to draw needs to be within the bounds of the active vertex and index buffers. Similarly, indirect dispatches must be within the limits of the workgroup count.

  • [x] #5714
  • [ ] Ensure safety of indirect draw
  • [ ] Enforce a no-op if the device does not have INDIRECT_FIRST_INSTANCE feature enabled.

kvark avatar Jan 28 '22 21:01 kvark

Here is a rough plan:

  1. wgpu-hal expects platform-dependent draw/dispatch buffer.
  2. the only thing exposed to the outside is the size of that buffer (for each kind of draw/draw indexed/dispatch)
  3. wgpu-hal command encoder gets a new fn prepare_indirect(src_buffer, src_offset, dst_buffer, dst_offset, kind, count). Under the hood it will be a compute operation that does clamping as well as copies of first instance/vertex.
  4. wgpu-core spawns a separate encoder to prepare indirect calls whenever it sees one, and orders it accordingly. It also manages the destination buffer as a temporary thing.

kvark avatar Feb 10 '22 18:02 kvark

When we get to this, we should also validate usage of the indirect-first-instance feature.

The value corresponding to firstInstance must be 0, unless the "indirect-first-instance" feature is enabled. If the "indirect-first-instance" feature is not enabled and firstInstance is not zero the drawIndirect() call will be treated as a no-op.

teoxoy avatar Jan 24 '24 11:01 teoxoy

I've updated the OP with the scope of remaining changes I'm aware need to happen.

ErichDonGubler avatar Sep 25 '24 20:09 ErichDonGubler

Downstream Firefox tracking for indirect dispatch: bug 1921342

ErichDonGubler avatar Sep 27 '24 02:09 ErichDonGubler

Downstream Firefox tracking for indirect draws: bug 1930972

ErichDonGubler avatar Nov 18 '24 17:11 ErichDonGubler