Repository navigation
[hal vulkan] Work around Mali r20 zero-sized dispatch, depth-stencil layout and workgroup limit bugs - #9
Conversation
WebGPU allows `dispatchWorkgroups` with a zero in any dimension; it runs nothing. Vulkan allows it too, but Arm's proprietary Mali driver (seen with r20p0 on a Mali-G52 MC2) stalls for about six seconds on each such `vkCmdDispatch` and loses the device for `(0, 0, 0)`. Indirect dispatches with zero counts are not affected. Return early for these, as the GLES backend already does.
…ali r20 Arm's proprietary Mali driver (seen with r20p0 on a Mali-G52 MC2) loses the device when a draw writes stencil in a render pass whose depth-stencil attachment is in `DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL`, the layout wgpu uses for a pass with read-only depth and writable stencil. With a `D24_UNORM_S8_UINT` attachment the submission stalls for about nine seconds and the device is lost, whether or not the depth aspect is sampled in the pass. The same pass in `DEPTH_STENCIL_ATTACHMENT_OPTIMAL` renders correctly. The other mixed layout, and the fully read-only one, work. Add `Workarounds::AVOID_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_LAYOUT`, which replaces the layout wherever one is chosen for a barrier, a render pass attachment, or a pipeline's compatible render pass, so that they always agree. Set it for Arm's proprietary driver up to r20, the only release known to be affected. When the pass also samples the read-only depth aspect, the image is then sampled while in an attachment layout, which Vulkan does not allow. Nothing writes depth in such a pass, and the affected driver renders it correctly.
Arm's proprietary Mali driver (seen with r20p0 on a Mali-G52 MC2) reports `maxComputeWorkGroupCount` as `u32::MAX` in every dimension, with `maxComputeWorkGroupSize` of 384. wgpu passed that on as `max_compute_workgroups_per_dimension`, which fails the WebGPU CTS in two ways: the limit is expected to be no larger than the product of the three workgroup size limits, and `dispatchWorkgroups(limit + 1)` is expected to be a validation error, but that value does not fit in a `u32`. Clamp the limit to the product of the workgroup size limits, and to `u32::MAX - 1`.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d9fd27cffa
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if layout == vk::ImageLayout::DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL | ||
| && self.contains(Self::AVOID_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_LAYOUT) | ||
| { | ||
| vk::ImageLayout::DEPTH_STENCIL_ATTACHMENT_OPTIMAL |
There was a problem hiding this comment.
Preserve a sampleable layout for read-only depth attachments
On the affected Arm drivers, a valid render pass that samples its read-only depth aspect while writing stencil now transitions the image to DEPTH_STENCIL_ATTACHMENT_OPTIMAL, which does not permit sampling. wgpu-core/src/command/render.rs explicitly allows this combination, and the sampled-image descriptor created in wgpu-hal/src/vulkan/device.rs still declares a read-only layout. Consequently, safe API calls produce invalid Vulkan commands, causing validation errors and undefined behavior even if the tested Mali-G52 happens to render correctly. Use a Vulkan-valid fallback with consistent attachment, barrier, and descriptor layouts, or stop exposing the unsupported combination on these drivers.
AGENTS.md reference: AGENTS.md:L19-L19
Useful? React with 👍 / 👎.
Connections
Found running the WebGPU CTS with
cts_runneron a Mali-G52 MC2 (Arm proprietary Vulkan 1.1 driverv1.r20p0-01rel0, Android 10). Other fixes for the same device: #7, #8, #10. The "before" runs below end in deno_webgpu panics or hangs once the device is lost; #10 fixes those.Description
Three driver problems wgpu-hal can avoid, one commit each.
vkCmdDispatchwith a zero dimension stalls for about six seconds, and(0, 0, 0)loses the device.dispatch_workgroupsnow returns early, as the GLES backend does. Not keyed on the driver.DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMALstalls for about nine seconds and loses the device. A newWorkarounds::AVOID_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_LAYOUTusesDEPTH_STENCIL_ATTACHMENT_OPTIMALinstead, for barriers, attachments and pipelines alike. Set forARM_PROPRIETARYdrivers up tor20, the only release tested.maxComputeWorkGroupCountasu32::MAX. The limit is now clamped to the product of the workgroup size limits (56,623,104 here), which is what the CTS expects. Not keyed on the driver.Caveat for 2: when the pass also samples the read-only depth aspect, the image is sampled while in an attachment layout, which Vulkan doesn't allow. Nothing writes depth in such a pass and this driver renders it correctly (third probe in the second image). The alternative, hiding
READ_ONLY_DEPTH_STENCIL, would also turn off the fully read-only pass, which works.Testing
cargo fmt --checkand clippy for wgpu-hal are clean; the wgpu-hal unit tests pass, including a new one for the driver version parsing.cts_runnerbuilt from trunk60cef2be8and from this branch.Zero-sized dispatch:
Depth-stencil layouts on
depth24plus-stencil8(dRO/sRO: depth/stencil read-only):Workgroup limit:
compute_passvalidation,readonly_depth_stenciland the workgroup limit case, 34 cases: on trunk 12 report a result (one process aborts, one hangs); with this branch 30 pass and 4 are skipped, in 4 s.cts_runner/test.lston the device (54,915 of 54,931 cases; 16 left out to protect the phone's memory): 45,478 pass, 86 fail, 9,351 skip. 85 of the failures are in selectors markedfails-if(vulkan).Squash or Rebase?
Rebase. The three commits are independent.
LLM Use?
Claude Code (Claude Mythos 5.2) found the three problems on the device, reduced them to the probes in the images, wrote the code, ran the tests and drafted this description.