You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The scenario:
A compute shader takes a storage buffer as read_write.
A buffer has both indirect and storage usages.
The buffer is in a BindGroup for use as the storage buffer with the compute shader.
The same buffer is used as the indirect buffer used for calling dispatchWorkgroupsIndirect.
WebGPU will have the validation error
[Buffer (unlabeled)] usage (BufferUsage::(Storage|Indirect)) includes writable usage and another usage in the same synchronization scope.
- While validating compute pass usage.
This is an incorrect error as the indirect buffer is read and/or copied before the compute is dispatched, and therefore not a race condition on the buffer by the GPU.
I'm not totally sure this is safe. Since dispatches have to broken up into chunks for scheduling (since dispatch can be larger than the number of shader lanes) it does seem possible the driver could read the indirect buffer after it's been written, at the very least to populate the @num_workgroups builtin, but it possibly could cause deeper logic bugs in the driver.
We would have to see what the Vulkan folks say, but even so, it would be hard to know for sure if it's safe in Metal, D3D12, and all existing Vulkan drivers.
D3D12 with legacy barriers would not support this use case. D3D12_RESOURCE_STATE_INDIRECT_ARGUMENT is a read-only state, and cannot be bound together with a read-write state like D3D12_RESOURCE_STATE_UNORDERED_ACCESS at the same time. D3D12 enhanced barriers can support this, but you need to be careful.
However, as @kainino0x suggests, if the compute shader itself writes over its own dispatch parameters, this is unsafe.
Note that we expect most WebGPU implementations do already be doing a copy of the indirect arguments for validation, so it might be safe after all. But that means that it would be unsafe when validation is disabled, which would be weird since the behavior of valid code would change between validation on vs. off.
The scenario:
A compute shader takes a storage buffer as read_write.
A buffer has both indirect and storage usages.
The buffer is in a BindGroup for use as the storage buffer with the compute shader.
The same buffer is used as the indirect buffer used for calling dispatchWorkgroupsIndirect.
WebGPU will have the validation error
This is an incorrect error as the indirect buffer is read and/or copied before the compute is dispatched, and therefore not a race condition on the buffer by the GPU.
Here is a repo example:
dispatch_indirect_error.html.txt
The text was updated successfully, but these errors were encountered: