Skip to content

feat(shader): dump recompiled SPIR-V modules with APS5_DUMP_SPIRV - #19967

Open
blawesom wants to merge 4 commits into
boykopovar:mainfrom
blawesom:fix/agc-pixel-interlock-gfx11-race
Open

blawesom wants to merge 4 commits into
boykopovar:mainfrom
blawesom:fix/agc-pixel-interlock-gfx11-race

Conversation

@blawesom

@blawesom blawesom commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

What

Add APS5_DUMP_SPIRV=<hex code address>|all: the recompiler writes the final SPIR-V module returned for each matching program to spirv-<stage>-<address>.spv in the working directory, mirroring APS5_DUMP_IR. The switch is registered as neutral for the shader disk cache key and documented in docs/dev/ENVIRONMENT.md; agc_spirv_dump_tests checks the complete header and instruction stream, compares every word with the final result.spirv, validates with spirv-val when SPIRV-Tools is enabled, and verifies that a real cache hit recreates the same dump. docs/dev/debt/changes/ records the #18770 findings.

Why for #18770: the recompiled PixelInterlockOrderedEXT module whose critical section (volatile coherent loads, bounds-checked RMW split across coverage-gated blocks) drops one of 64 ordered-interlock writes on RADV GFX11/NAVI31 can now be dumped exactly and run through a standalone Vulkan harness on the affected hardware — the isolation step the issue thread identified as next. This PR deliberately does not change the interlock emission: on this machine's GFX12 (RX 9070 XT, RADV 26.2.4) the failure does not reproduce (30/30 runs at 64 layers, 10/10 with 512 layers), so no emission change could be validated here, and the issue's matrix (fails only gfx1100 + RADV; passes RDNA2 + RADV, lavapipe, GFX12 + RADV, RDNA3.5 + AMD proprietary) points at RADV's GFX11 POPS path.

Tested

CachyOS Linux (kernel 7.3.4), GCC 16.2.1, no title. All builds used at most 12 CPUs. Baseline 089d2df72e4a; final head 7079f58a6916.

  • Release full build with BUILD_TESTING=ON and ANYPS5_ENABLE_SPIRV_TOOLS=ON: pass. Full CTest: 6409/6409 passed, 180.19 s, no test over 30 s. check_skips.py reports nine host-coverage skips; the same nine reproduce on main (details in the validation comment).
  • AMD Radeon RX 9070 XT (RADV GFX1201), Mesa 26.2.6-arch3.1, Vulkan 1.4.354, with Khronos validation 1.4.363.0 and VK_LAYER_LSFGVK_frame_generation disabled: vulkan_validation_gate.py on agc_driver_pixel_interlock, two iterations per build. Four selections of the RX 9070 XT, four confirmed layer insertions, no missing-layer messages, no validation diagnostics and no new VUID-, SYNC-HAZARD- or UNASSIGNED- IDs; gate exit 0.
  • agc_spirv_dump, agc_spirv_dump_full, agc_spirv_dump_none: 3/3 passed. Each checks final-module equality and recreation on a real cache hit with in-test spirv-val enabled.
  • Manual RX 9070 XT interlock run: 10/10 draws passed, 11 modules dumped (8 compute, 1 vertex, 2 fragment); all passed spirv-val, and both fragment modules contain OpBeginInvocationInterlockEXT/OpEndInvocationInterlockEXT.
  • rebase_verify.py: all four commits preserved. check_conventions.py --base origin/main: pass. pr_overlap.py --branch failed closed on unresolved comparisons against older conflicting PRs; its only concrete same-line/new-file match was this PR against its own previous head.

NAVI31 is not available here, so this validates the diagnostic tooling and GFX12 behaviour, not the original NAVI31 failure or a fix for #18770. Full upstream Linux PR CI still needs the maintainer-controlled manual Build dispatch.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt and the licence notice of code adapted from upstream (see AGENTS.md)
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none (diagnostic tooling for AGC: agc_driver_pixel_interlock drops one of 64 overlapping interlock writes on RDNA3 (RADV NAVI31) — ~90% of runs, passes on RDNA2 + lavapipe #18770; the issue stays open pending a NAVI31-verified fix)
  • Unblocks: none
  • GPUs tested: AMD Radeon RX 9070 XT (RADV GFX1201), Mesa RADV 26.2.6-arch3.1, CachyOS Linux 7.3.4 — GPU-backed AGC tests and the focused baseline/candidate interlock comparison with Khronos validation 1.4.363.0
  • AI-assisted: yes

@github-actions

github-actions Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 24523 docs/dev/ENVIRONMENT.md L49

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 1896 docs/dev/ENVIRONMENT.md
PR 4472 docs/dev/ENVIRONMENT.md
PR 5609 core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.cpp
PR 5925 core/shader/recompiler/ShaderDiskCache.cpp
PR 6186 docs/dev/ENVIRONMENT.md
PR 6280 core/shader/recompiler/ShaderDiskCache.cpp
PR 6412 core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.cpp
PR 6488 core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.cpp
PR 6924 core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.cpp
docs/dev/ENVIRONMENT.md
PR 7085 core/shader/recompiler/ShaderDiskCache.cpp
PR 7275 docs/dev/ENVIRONMENT.md
PR 7642 core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.cpp
docs/dev/ENVIRONMENT.md
PR 7643 docs/dev/ENVIRONMENT.md
PR 7684 core/shader/recompiler/ShaderDiskCache.cpp
PR 9345 docs/dev/ENVIRONMENT.md
PR 9356 core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.cpp
docs/dev/ENVIRONMENT.md
PR 9387 core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.cpp
docs/dev/ENVIRONMENT.md
PR 9508 core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.cpp
docs/dev/ENVIRONMENT.md
PR 9712 docs/dev/ENVIRONMENT.md
PR 9852 core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.cpp
docs/dev/ENVIRONMENT.md
PR 9897 core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.cpp
PR 10193 core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.cpp
docs/dev/ENVIRONMENT.md
PR 10359 core/shader/recompiler/Recompiler.cpp
PR 10442 docs/dev/ENVIRONMENT.md
PR 10652 core/shader/recompiler/Recompiler.cpp
PR 10894 docs/dev/ENVIRONMENT.md
PR 11435 docs/dev/ENVIRONMENT.md
PR 11436 docs/dev/ENVIRONMENT.md
PR 11483 core/shader/recompiler/Recompiler.cpp
PR 11551 core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.cpp
PR 12324 core/shader/recompiler/Recompiler.cpp
docs/dev/ENVIRONMENT.md
PR 12746 docs/dev/ENVIRONMENT.md
PR 12828 core/shader/recompiler/Recompiler.cpp
PR 12840 core/shader/recompiler/Recompiler.cpp
docs/dev/ENVIRONMENT.md
PR 12849 docs/dev/ENVIRONMENT.md
PR 12944 core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.cpp
PR 13863 docs/dev/ENVIRONMENT.md
PR 13920 docs/dev/ENVIRONMENT.md
PR 13928 core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.cpp
docs/dev/ENVIRONMENT.md
PR 13929 core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.cpp
docs/dev/ENVIRONMENT.md
PR 14032 core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.cpp
PR 14262 docs/dev/ENVIRONMENT.md
PR 14853 core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.cpp
PR 14871 core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.cpp
PR 14944 core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.cpp
PR 15456 docs/dev/ENVIRONMENT.md
PR 15570 docs/dev/ENVIRONMENT.md
PR 16217 docs/dev/ENVIRONMENT.md
PR 16260 core/shader/recompiler/ShaderDiskCache.cpp
PR 16391 core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.cpp
PR 16793 docs/dev/ENVIRONMENT.md
PR 16831 docs/dev/ENVIRONMENT.md
PR 17056 core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.cpp
PR 17557 docs/dev/ENVIRONMENT.md
PR 17719 docs/dev/ENVIRONMENT.md
PR 17729 docs/dev/ENVIRONMENT.md
PR 18173 docs/dev/ENVIRONMENT.md
PR 18226 docs/dev/ENVIRONMENT.md
PR 19697 docs/dev/ENVIRONMENT.md
PR 20030 core/shader/recompiler/Recompiler.cpp
PR 20111 core/shader/recompiler/Recompiler.cpp
PR 20172 docs/dev/ENVIRONMENT.md
PR 20248 core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.cpp
docs/dev/ENVIRONMENT.md
PR 20315 docs/dev/ENVIRONMENT.md
PR 20519 core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.cpp
docs/dev/ENVIRONMENT.md
PR 21225 docs/dev/ENVIRONMENT.md
PR 21238 docs/dev/ENVIRONMENT.md
PR 21649 docs/dev/ENVIRONMENT.md
PR 22071 core/shader/recompiler/Recompiler.cpp
docs/dev/ENVIRONMENT.md
PR 22190 docs/dev/ENVIRONMENT.md
PR 22424 core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.cpp
docs/dev/ENVIRONMENT.md
PR 22434 docs/dev/ENVIRONMENT.md
PR 22546 docs/dev/ENVIRONMENT.md
PR 22647 core/shader/recompiler/Recompiler.cpp
docs/dev/ENVIRONMENT.md
PR 23242 core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.cpp
docs/dev/ENVIRONMENT.md
PR 23975 docs/dev/ENVIRONMENT.md
PR 24327 docs/dev/ENVIRONMENT.md
PR 24445 docs/dev/ENVIRONMENT.md
PR 24631 docs/dev/ENVIRONMENT.md
PR 24661 docs/dev/ENVIRONMENT.md
PR 25010 core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.cpp
PR 26165 docs/dev/ENVIRONMENT.md

@blawesom

Copy link
Copy Markdown
Contributor Author

Local end-to-end validation of this branch (head 8931aa23), run 2026-11-15 on the author's machine — all gates green. Diagnostic tooling for #18770; no emission change, as stated in the body.

  • Merge baseline: git merge-tree --write-tree origin/main HEAD exits 0 against current origin/main (78276498ecf) — no conflicts.
  • Build (12-core cap on a 16-core box): export CMAKE_BUILD_PARALLEL_LEVEL=12 GOMAXPROCS=12, cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON, cmake --build build --parallel 12 → 8359 targets, exit 0, ~5m10s wall.
  • Focused GPU tests on AMD Radeon RX 9070 XT (RADV GFX1201, Mesa 26.2.6, Vulkan 1.4.354) with ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer (validation layer 1.4.363 found at ~/.local/opt/vulkan-validation-layers, injected via VK_LAYER_PATH since it is not in system paths):
    ctest --test-dir build -R "agc_spirv_dump|agc_driver_pixel_interlock|agc_bda_atomics|agc_shader_memory" --output-on-failure -V → 6/6 Passed (agc_spirv_dump{,_full,_none}, agc_driver_pixel_interlock, agc_bda_atomics, agc_shader_memory). Log contains Insert instance layer "VK_LAYER_KHRONOS_validation", no was not found but was requested by env var VK_INSTANCE_LAYERS, 0 VUID- lines.
  • Conventions: python3 tools/check_conventions.py --base origin/main → pass. python3 tools/pr_overlap.py --branch fix/agc-pixel-interlock-gfx11-race → exit 2 here (~90 ancient PR refs unfetchable in this environment); the confirmed overlap list is docs-only (ENVIRONMENT.md, debt/shader.md) plus Recompiler.cpp/ShaderDiskCache.cpp also touched by feat(agc): read color-target merges through typed storage images #17056, feat(agc): emulate mesh pipeline draws with a compute pass when VK_EXT_mesh_shader is unavailable #17611, perf(agc): drop pending units a compute dispatch is proven to overwrite (APS5_PROVEN_OVERWRITE) #18369 — worth a manual look at merge time.
  • Acceptance reproducer: APS5_DUMP_SPIRV=all ./build/tests/agc_driver_pixel_interlock_tests dumped 10 modules (7 compute, 1 vertex, 2 fragment); all pass spirv-val; both fragment modules show PixelInterlockOrderedEXT with OpBegin/EndInvocationInterlockEXT spanning the coverage-gated RMW. Single-address form (APS5_DUMP_SPIRV=<hex> under setarch -R) dumps exactly one module; deadbeef or unset dump nothing; agc_spirv_dump_tests removes its own dump file.

Caveats: this machine is GFX12, so the #18770 NAVI31 failure does not reproduce here (expected — this PR is diagnostic only). This build has ANYPS5_ENABLE_SPIRV_TOOLS at its default OFF, so the in-test spvtools validation was compiled out; system spirv-val/spirv-dis covered it. Unrelated pre-existing loader noise in the log: liblsfg-vk-layer.so implicit-layer init error and "radv is not a conformant Vulkan implementation" warnings.

Logs and worktree: /tmp/opencode/wt-19967/logs/ (configure.log, build.log, ctest.log, conventions.log, pr_overlap.log, reproducer.log). No push performed; branch left at 8931aa23. AI-assisted: yes.

@domx4q

domx4q commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Ran the Tested section's set with the Khronos validation layer actually loaded, since the layer could not be installed on the machine the PR was tested on.

Setup: Arch Linux (kernel 7.3.4), GCC 16.2.1, Release, NVIDIA GeForce RTX 4090 (vendor 0x10de, device 0x2684, Ada), proprietary driver 620.70.06, Vulkan 1.4.357, Khronos validation layer 1.4.363.1. Head 8931aa23ec merged onto main 89b0eef7ab with --no-ff, clean merge. Main baseline is a Release build of 89b0eef7ab on the same machine.

ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer \
ctest --test-dir build -R 'agc_spirv_dump|agc_driver_pixel_interlock|agc_bda_atomics|agc_shader_memory' -V
main 89b0eef7ab this PR
Result 4 passed (4) 7 passed (7)
Insert instance layer "VK_LAYER_KHRONOS_validation" 1 1
was not found but was requested by env var VK_INSTANCE_LAYERS 0 0
VUID- none none

agc_spirv_dump, agc_spirv_dump_full and agc_spirv_dump_none are new and absent on main; they pass. Of this set only agc_driver_pixel_interlock creates a Vulkan device (on both sides), so the layer is inserted once per log; it picked the RTX 4090 and passes with the recompiler change. The dump tests, agc_bda_atomics and agc_shader_memory* run without a device.

No new VUID- errors; all focused tests pass on Ada.

AI-assisted: yes (Claude Code)

Adds APS5_DUMP_SPIRV=<hex code address>|all to write the final recompiled
module to spirv-<stage>-<address>.spv, mirroring APS5_DUMP_IR, to support
issue boykopovar#18770: the exact PixelInterlockOrderedEXT module that drops an
ordered-interlock write on RADV GFX11 can now be run through a standalone
Vulkan harness on the affected hardware. Covered by agc_spirv_dump_tests.
@blawesom
blawesom force-pushed the fix/agc-pixel-interlock-gfx11-race branch from 8931aa2 to 7079f58 Compare November 20, 2026 16:41
@blawesom

Copy link
Copy Markdown
Contributor Author

Refreshed and validated head 7079f58a6916, rebased directly onto current main 089d2df72e4a. All build commands were capped at 12 CPUs.

Implementation corrections since the earlier run

  • Dumping now happens after result materialization, so the file matches the final recompiler result, including specialized and cached variants.
  • Write/open/close failures are checked, in-process writes are serialized, and the three CTest modes are RUN_SERIAL to prevent filename races.
  • Tests compare every dumped word with result.spirv.Words(), delete the first file, then require and validate a second dump on a real variant-cache hit.
  • The debt entry is in docs/dev/debt/changes/; no new code comments remain. Later vertex-only gl_Layer pipeline rewrites are outside the documented recompiler-result dump scope.

Linux validation (CachyOS, kernel 7.3.4, GCC 16.2.1, no title)

  • Release build with BUILD_TESTING=ON and ANYPS5_ENABLE_SPIRV_TOOLS=ON: pass.

  • Full CTest: 6409/6409 passed, 180.19 s, no test over 30 s.

  • check_skips.py: nine unexpected host-coverage skips, not a clean skip audit. The exact same nine tests and reasons reproduce on main:

    agc_buffer_upload_pending_gpu_copy{,_bytes}, agc_driver_image_array_{rows,window}_past_layer_limit, agc_driver_linear_target_dma_buf_refusal, agc_driver_scattered_runs, agc_driver_sparse_dma_buf_import, agc_driver_wide_line_register_readback, agc_host_import_sparse.

    Their fixture preconditions are unavailable on this host (RADV array/udmabuf limits, strictLines, or compared host imports). No candidate-only skip appeared.

Focused AMD validation

  • GPU: AMD Radeon RX 9070 XT (RADV GFX1201).
  • Driver: Mesa 26.2.6-arch3.1, Vulkan device API 1.4.354.
  • Layer: Khronos validation 1.4.363.0, locally injected with VK_LAYER_PATH; VK_LAYER_LSFGVK_frame_generation disabled to avoid its unrelated loader errors.
  • tools/vulkan_validation_gate.py: agc_driver_pixel_interlock, 2 iterations per build, baseline/candidate alternation, cold AnyPS5 shader cache and explicit GPU selection.
  • Result: exit 0, one selected test on each side, four test executions total; status=complete, problems=[], new_diagnostics={}.
  • All four logs show the RX 9070 XT selected and Insert instance layer "VK_LAYER_KHRONOS_validation"; no missing-layer line, VUID-, SYNC-HAZARD-, UNASSIGNED-, or LSFG library error appears.

Dump acceptance

  • agc_spirv_dump{,_full,_none}: 3/3 passed, with in-test spirv-val enabled and cache-hit recreation checked.
  • Manual APS5_DUMP_SPIRV=all agc_driver_pixel_interlock_tests: 10/10 interlock draws passed; 11 modules dumped (8 compute, 1 vertex, 2 fragment), all passed external spirv-val; both fragment modules contain ordered-interlock begin/end operations.
  • rebase_verify.py: all four commits preserved. check_conventions.py --base origin/main: pass.
  • pr_overlap.py --branch: failed closed because comparisons against older conflicting PRs could not all be completed; its concrete same-line/new-file result was only this PR against its own previous head. I am not treating that as a clean global overlap result.

This host is GFX12, not NAVI31. The run validates the diagnostic tooling and current GFX12 behaviour; it does not claim to reproduce or fix the original #18770 NAVI31 failure. Full upstream Linux PR CI still requires a maintainer with write access to dispatch the Build workflow.

@blawesom
blawesom marked this pull request as ready for review November 20, 2026 16:41

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed — looks good

The change adds an opt-in final SPIR-V dump and focused tests; I found no verified blocking defect in the inspected code.

What I ran

Reviewed head 7079f58a6916f7e6ee19c22242c2586e9c508b12 using repo_read.py against the prepared review artifacts and repository source. No tests or build checks were run.

Results

Check Result Note
Source review passed All five included changed files read
Build and tests not run Author-reported results were not independently run

Findings

Blocking

None.

Non-blocking

None.

Not verified

No build or test commands were run. Author reports 6,409 CTest passes and focused SPIR-V dump tests, but those results were not independently verified. The excluded debt note docs/dev/debt/changes/fix-agc-pixel-interlock-gfx11-race.md was not read; it was excluded by the prepared review rules. The review bundle's files.json was unavailable through the reader, so excluded-file details beyond the description and manifest were not verified.

To get this to a good state

Nothing is required.

This branch has not been deployed

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

Labels

agc libSceAgc* build docs shader core/shader

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants