Skip to content

[naga spv-out] Don't give types that contain a bool a layout - #8

Open
matthargett wants to merge 1 commit into
review-base/trunk-60cef2be8from
fix/naga-spv-bool-layout-decorations-20261126
Open

matthargett wants to merge 1 commit into
review-base/trunk-60cef2be8from
fix/naga-spv-bool-layout-decorations-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 r20p0, Android 10). Other fixes for the same device: #7, #9, #10.

Related upstream: gfx-rs/wgpu issue 7696 and PR 9295 are about explicit layout decorations on types in the Workgroup storage class. This is narrower (only types that contain a bool) but covers every storage class. It doesn't fix 7696.

Description

The SPIR-V backend decorates every array with ArrayStride and every struct member with Offset, from Naga's own layout, in which a bool is one byte. array<bool, 8> gets ArrayStride 1. SPIR-V gives OpTypeBool no size and such types are never host-shareable, so the decorations describe nothing.

This driver lays function, private and workgroup variables out by them anyway and reads a bool as a wider value, so neighbours overlap: element i of an array<bool, N> reads as a[i] || a[i + 1]. Arrays of bool vectors and of structs with bool members go wrong the same way, and a constant array<vec3<bool>, N> crashes the driver's shader compiler.

This leaves ArrayStride, Offset and MatrixStride off arrays and structs that contain a bool. It isn't keyed on the driver.

Testing

  • macOS: cargo fmt --check and clippy for naga are clean; all 423 naga tests pass. Eleven SPIR-V snapshots lose decorations and nothing else; spirv-val gives each the same verdict before and after.
  • Mali-G52, cts_runner built from trunk 60cef2be8 and from this branch. Each line fills the aggregate from a buffer at run time and copies it back out:

21 bool aggregate shapes read back on the Mali-G52, before and after

  • CTS bool_conversion and workgroupUniformLoad (execution), 116 cases: on trunk 81 pass, 12 fail and 23 have no result (the driver's compiler segfaults); all 116 pass with this branch.
  • 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 or on desktop Vulkan.

Squash or Rebase?

Single commit.

LLM Use?

Claude Code (Claude Mythos 5.2) found the wrong results on the device, narrowed them down with the probe in the image, wrote the change, ran the tests and drafted this description.

The SPIR-V backend decorated every array with `ArrayStride` and every struct
member with `Offset` (and `MatrixStride` for matrices), using Naga's own
layout, in which a `bool` is one byte. SPIR-V gives `OpTypeBool` no size, and
a type that contains a bool is never host-shareable, so these decorations
describe nothing a driver needs.

Arm's proprietary Mali driver (seen with r20p0 on a Mali-G52 MC2) lays
function, private and workgroup variables out by the decorations anyway, and
reads and writes a bool as a wider value. With `ArrayStride 1` the elements of
an `array<bool, N>` overlap: `a[i]` reads as `a[i] || a[i + 1]` for N >= 3.
Arrays of bool vectors, arrays of structs with bool members, and structs that
hold both a bool vector and other bools are read wrongly in the same way, and
a constant `array<vec3<bool>, N>` crashes the driver's shader compiler.

Leave the layout decorations off arrays and structs that contain a bool. This
does not address explicit layouts on other types used outside of buffers
(gfx-rs#7696).
@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:15.544002Z 8950020 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: 89500208d6

ℹ️ 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 +4178 to +4179
crate::TypeInner::Struct { ref members, .. } => {
members.iter().any(|member| contains_bool(types, member.ty))

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 Cache boolean containment per type instead of expanding shared subtypes

For shaders with nested structs that reuse the same member type, this recursion performs exponential work even though the type arena is small. For example, starting with S0 containing a u32 and defining each Sn with two S(n-1) members makes checking S27 visit hundreds of millions of nodes; its 512 MiB declared size is still below MAX_TYPE_SIZE. write_logical_layout repeats this traversal for every declared type, so a small, valid shader can stall SPIR-V compilation and monopolize the process handling untrusted shaders. Compute containment once per type in arena order, or memoize results by type handle.

AGENTS.md reference: AGENTS.md:L17-L17

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