Skip to content

spirv: make image texels available after the write and visible before the read - #1155

Merged
RyanTheTide merged 1 commit into
aurora-wipfrom
w8B/spirv-image-texel-avail-vis
Nov 27, 2026
Merged

RyanTheTide merged 1 commit into
aurora-wipfrom
w8B/spirv-image-texel-avail-vis

Conversation

@joshuaswarren

Copy link
Copy Markdown

What

Fix MakeTexelAvailable and MakeTexelVisible barrier placement in src/compiler/spirv/spirv_to_nir.c:vtn_handle_image() for SpvOpImageRead, SpvOpImageSparseRead, and SpvOpImageWrite.

OpImageWrite with MakeTexelAvailable and OpImageRead with MakeTexelVisible describe the texel of that very access. vtn_handle_image() split their memory semantics with vtn_split_barrier_semantics(), which puts MakeAvailable before the operation and MakeVisible after it. That placement is right for release/acquire atomics, but for plain image reads and writes it placed the texel write outside its own availability barrier and the texel read before its own visibility barrier. Because nir_lower_memory_model marks only writes that precede a MakeAvailable barrier as coherent, the image store stayed non-coherent.

Plain image reads and writes carry no Acquire or Release bits, so swapping before_semantics and after_semantics for SpvOpImageRead, SpvOpImageSparseRead, and SpvOpImageWrite places MakeTexelAvailable after the write and MakeTexelVisible before the read. Image atomics keep the existing placement.

Adds opimageread_vis and opimagewrite_avail in src/compiler/spirv/tests/avail_vis.cpp asserting the exact intrinsic order (visible barrier before image_deref_load, available barrier after image_deref_store). Both fail on aurora-wip (90b5a80e55c) and pass with this change.

No runtime switches, no environment variables, and no chip gates.

Verification

Unit tests (exact head 09d42db9a90 on aurora-wip 90b5a80e55c, native aarch64 clang release build)

  • spirv_tests: 32/32 passed (including AvailabilityVisibility 9/9: opimageread_vis, opimagewrite_avail, opimageread_vis_opimagewrite_avail_coherent).
  • Full native aarch64 Borealis/AGX unit suite (mesa:asahi): 212/212 passed (0 fail, 0 skip, 0 timeout).

Hardware CTS results (same driver with and without this change)

  • 16-inch MacBook Pro M1 Max (G13C):
    • dEQP-VK.memory_model.message_passing.ext.u32.coherent.*.{device,queuefamily}.payload_local.image.guard_local.*.comp (30 cases): 30/30 deterministic Fail (6/6 runs) -> 30/30 Pass (3/3 runs).
    • dEQP-VK.memory_model.* and dEQP-VK.subgroups.basic.* (18,600 cases): 2,283 Pass, 16,317 NotSupported, 0 Fail (30 Fail -> Pass, 0 Pass -> other).
    • 20,683-case bf16, precision, cooperative_matrix, and compute.pipeline suite: 0 status changes.
  • 13-inch MacBook Pro M1 (G13G) and M2 Max (G14C):
    • Same 30 cases: 30/30 Pass (3/3 runs); same 18,600-case memory model + subgroups list and 20,683-case compute/coopmat/bf16/precision list: 0 status changes.

Risk

Very low. Six-line swap in vtn_handle_image() scoped strictly to SpvOpImageRead, SpvOpImageSparseRead, and SpvOpImageWrite (none of which can carry Acquire/Release semantics). Image atomics are unchanged. No performance impact (zero extra instructions outside the affected MakeTexelAvailable/MakeTexelVisible memory-model path).

… the read

OpImageWrite with MakeTexelAvailable and OpImageRead with MakeTexelVisible
describe the texel of that very access. vtn_handle_image split their
semantics with vtn_split_barrier_semantics, which places MakeAvailable
before the operation and MakeVisible after it. That is right for a release
or acquire atomic, but it put a texel write outside its own availability
operation. nir_lower_memory_model marks only the writes that precede a
MakeAvailable barrier as coherent, so the store stayed non-coherent.

On G13C (M1 Max) a devicecoherent image payload published across
workgroups then failed: dEQP-VK.memory_model.message_passing.ext
u32.coherent.*.{device,queuefamily}.payload_local.image.guard_local.*.comp
(30 cases, deterministic, 30 of 30 in 6 of 6 runs, with and without the
dependency-tracked CDM barrier). The failing and passing shader pairs had
identical barrier and cache-flush sequences; the only difference in the
disassembly was the coherent flag on the image write. Four cache flush
variants did not change the result.

Swap the two sides for ImageRead, ImageSparseRead and ImageWrite. These
carry no Acquire or Release bits, so only the MakeTexel semantics move.
Atomics keep the old placement.

Add opimageread_vis and opimagewrite_avail to the availability and
visibility unit tests. They assert the order, which the existing tests
do not: the available barrier follows the image store and the visible
barrier precedes the image load. Both fail on the parent commit
(barrier position 10 vs load 9, and barrier 14 vs store 15) and pass with
this change; the 27 spirv_tests pass.

Results on G13C (aurora 12.6 prerelease kernel), same driver with and
without the change:
- the 30 cases: Pass in 3 of 3 runs
- memory_model.* and subgroups.basic.* (18,600 cases): 2,283 Pass,
  16,317 NotSupported, 0 Fail; 30 Fail -> Pass, 0 Pass -> other
- the 20,683-case bf16, precision, cooperative_matrix and
  compute.pipeline list: 0 status changes

Same lists on G13G (M1) and G14C (M2 Max) with and without the change:
the 30 cases pass in 3 of 3 runs, the memory model and subgroup list has
0 status changes (these chips already passed the 30 cases without the
change), and the 20,683-case list has 0 status changes.

Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com>
@joshuaswarren
joshuaswarren requested review from a team as code owners November 26, 2026 19:54
@chatgpt-codex-connector

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

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

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

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-26T19:54:11.487203Z
We couldn’t complete this review. Comment @codex review to try again.
09d42db PR opened
🔒 Security Review ❌ Failed 2026-11-26T19:54:17.638187Z
We couldn’t complete this review. Comment @codex security review to try again.
09d42db 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

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@chatgpt-codex-connector

Copy link
Copy Markdown

The account paying for this security review has reached its Codex usage limits. The payer can check the Codex usage dashboard. For personal accounts, using credits requires enabling “Use credits for security reviews” in Code review settings. If you do not manage the paying account, contact this repository's admins.

@RyanTheTide RyanTheTide 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.

Verdict: MERGE at 09d42db9a90c

Blockers: none

Checked: Read the diff against the SPIR-V spec wording: MakeTexelAvailable is an availability operation after the write, MakeTexelVisible a visibility operation before the read, so swapping the split for OpImageRead/OpImageSparseRead/OpImageWrite is right; these ops cannot carry Acquire/Release bits, so nothing else moves, and image atomics keep the release/acquire placement. Shared Mesa code with no driver or chip condition. Tests fail without the fix: I disabled the swap in the batch tree and rebuilt spirv_tests: opimageread_vis and opimagewrite_avail both FAIL, the other 7 pass; with the fix all 9 pass. Since this is core spirv_to_nir code, it is also worth sending upstream.

Evidence

Local Mesa gate (stands in for CI; buildbox x86 docker aurora/hk6356-mesa-x86-tests:local, clang release with asserts, -Dbuild-tests=true -Dtools=asahi,drm-shim, meson test --suite asahi --suite poly):

  • base aurora-wip 90211df6816: 335/335 OK.
  • batch build: 90211df6816 with 22 open PR heads merged on top (#1133 #1137 #1155 #1136 #1140 #1157 #1158 #1160 #1164 #1165 #1167 #1168 #1170 #1171 #1172 #1175 #1182 #1183 #1185 #1187 #1190 #1191; each also merges cleanly alone, and into current aurora-wip d2e883ab2e3): 335/336 OK. The one failure, agx3_cmat_mixed_mma8, reproduces with #1187 alone on the base (329/330) and is caused by that PR's new test; nothing else in the batch fails.
  • spirv_tests in the batch build: OK; AvailabilityVisibility.* 9/9. Negative control (swap disabled): 2 FAILED (opimageread_vis, opimagewrite_avail), 7 passed.

This was referenced Nov 27, 2026
@RyanTheTide

Copy link
Copy Markdown

09d42db J473 M2 mini (G14G B0, 7.3.0-aurora-fleet89) PASS: memory_model.* 2,976 pass / 15,554 not supported / 0 fail (18,530 cases, every listed case ran), 0 GPU faults, Enforcing, 0 failed, 0 AVC; system Mesa untouched

Details
  • Build: exact head 09d42db (git archive of the PR head, no merge), release with assertions on (-Dbuildtype=release -Db_ndebug=false -Dvulkan-drivers=asahi), built natively on aarch64 Fedora 45 in a container. vulkaninfo with the overlay: Apple M2 (G14G B0), Mesa 26.3.0-devel (git-09d42db9a9), Borealis.
  • Loaded through VK_DRIVER_FILES only. /usr/lib64/libvulkan_asahi.so sha256 9b40d2912963... before and after. Shader cache off.
  • CTS: deqp-vk 1.4.7.1 (3fd4ea318fe2), dEQP-VK.memory_model.* in full, 4 parallel processes, no crashes.
  • Kernel log over the run: 0 GPU faults, recoveries, timeouts or rejected submits. 0 AVC, 0 failed units, Enforcing.

@RyanTheTide

Copy link
Copy Markdown

09d42db9a90c Neo (J700, Apple A18 Pro / G17P B1, 7.3.0-aurora-fleet89, default cmdline) PASS: Borealis overlay ICD (-Dbuildtype=release -Db_ndebug=false, sha256: d2c5b4189faf..., combined disjoint overlay on aurora-wip@e1b5658fe695 with this PR's touched files verified 0-byte diff vs merge(aurora-wip, head)), meson test --suite asahi 214/214 PASS, spirv_tests 1/1 PASS; live VK CTS (J=1, MemoryMax=3G): dEQP-VK.memory_model.message_passing.* (--deqp-fraction=1,10) 202/920 PASS / 0 FAIL (718 NotSupported), dEQP-VK.memory_model.* (--deqp-fraction=1,25) 147/739 PASS / 0 FAIL (592 NotSupported), dEQP-VK.memory_model.shared.* 210/210 PASS / 0 FAIL; 0 GPU faults/recoveries, 0 failed units, SELinux Enforcing, 0 new AVC denials, stock /usr/lib64/libvulkan_asahi.so untouched.

@RyanTheTide
RyanTheTide merged commit 1e793d8 into aurora-wip Nov 27, 2026
@RyanTheTide
RyanTheTide deleted the w8B/spirv-image-texel-avail-vis branch November 27, 2026 13:21
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.

2 participants