Skip to content

Commit

Permalink
[WebGPU] GPUComputePassEncoder.dispatch empty call is legal in WebGPU…
Browse files Browse the repository at this point in the history
…, but generates a validation error in Metal

https://bugs.webkit.org/show_bug.cgi?id=265907
<radar://119217365>

Reviewed by Dan Glastonbury.

Add validation for dispatch and dispatchIndirect which would otherwise
crash the GPU process running the validation CTS test suite.

* Source/WebGPU/WebGPU/ComputePassEncoder.mm:
(WebGPU::ComputePassEncoder::dispatch):
(WebGPU::ComputePassEncoder::dispatchIndirect):

Canonical link: https://commits.webkit.org/271588@main
  • Loading branch information
mwyrzykowski committed Dec 6, 2023
1 parent 627b31c commit 4425cc9
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Source/WebGPU/WebGPU/ComputePassEncoder.mm
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,20 @@

void ComputePassEncoder::dispatch(uint32_t x, uint32_t y, uint32_t z)
{
if (!(x * y * z))
return;

executePreDispatchCommands();
[m_computeCommandEncoder dispatchThreadgroups:MTLSizeMake(x, y, z) threadsPerThreadgroup:m_threadsPerThreadgroup];
}

void ComputePassEncoder::dispatchIndirect(const Buffer& indirectBuffer, uint64_t indirectOffset)
{
// FIXME: ensure higher levels perform validation on indirectOffset before reaching this callsite
if ((indirectOffset % 4) || !(indirectBuffer.usage() & WGPUBufferUsage_Indirect) || (indirectOffset + 3 * sizeof(uint32_t) > indirectBuffer.buffer().length)) {
makeInvalid();
return;
}

executePreDispatchCommands();
[m_computeCommandEncoder dispatchThreadgroupsWithIndirectBuffer:indirectBuffer.buffer() indirectBufferOffset:indirectOffset threadsPerThreadgroup:m_threadsPerThreadgroup];
}
Expand Down

0 comments on commit 4425cc9

Please sign in to comment.