Skip to content

[hal vulkan] Work around Mali r20 zero-sized dispatch, depth-stencil layout and workgroup limit bugs - #9

Open
matthargett wants to merge 3 commits into
review-base/trunk-60cef2be8from
fix/vulkan-mali-r20-workarounds-20261126
Open

matthargett wants to merge 3 commits into
review-base/trunk-60cef2be8from
fix/vulkan-mali-r20-workarounds-20261126

Conversation

@matthargett

@matthargett matthargett commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Connections

Found running the WebGPU CTS with cts_runner on a Mali-G52 MC2 (Arm proprietary Vulkan 1.1 driver v1.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.

  1. Zero-sized dispatch. vkCmdDispatch with a zero dimension stalls for about six seconds, and (0, 0, 0) loses the device. dispatch_workgroups now returns early, as the GLES backend does. Not keyed on the driver.
  2. Depth read-only, stencil writable. A draw that writes stencil while the attachment is in DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL stalls for about nine seconds and loses the device. A new Workarounds::AVOID_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_LAYOUT uses DEPTH_STENCIL_ATTACHMENT_OPTIMAL instead, for barriers, attachments and pipelines alike. Set for ARM_PROPRIETARY drivers up to r20, the only release tested.
  3. Workgroup count limit. The driver reports maxComputeWorkGroupCount as u32::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

  • macOS: cargo fmt --check and clippy for wgpu-hal are clean; the wgpu-hal unit tests pass, including a new one for the driver version parsing.
  • Mali-G52, cts_runner built from trunk 60cef2be8 and from this branch.

Zero-sized dispatch:

Direct dispatches with a zero dimension on the Mali-G52, before and after

Depth-stencil layouts on depth24plus-stencil8 (dRO/sRO: depth/stencil read-only):

Render passes with read-only depth or stencil on the Mali-G52, before and after

Workgroup limit:

The two CTS cases that depend on maxComputeWorkgroupsPerDimension, before and after

  • CTS compute_pass validation, readonly_depth_stencil and 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.
  • With all four PRs applied, a full run of cts_runner/test.lst on 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 marked fails-if(vulkan).
  • Not tested on other Mali driver releases, on desktop Vulkan, or on the Adreno 540, where a zero-sized dispatch is also known to hang.

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.

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`.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-26T22:21:28.622742Z d9fd27c PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +280 to +283
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant