fix(shader): mask writes after barrier-safe BDA faults #7392
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7392"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T04:28:04Z.
What
Keep compute invocations participating in
s_barrierafter a BDA read fault, while recording the fault per lane and suppressing that lane's later writes, atomics and exports. The checked BDA read result is propagated back to the correct lane half. The regression tests cover all-fault and mixed valid/faulting lanes around a barrier. Hull and mesh barrier handling remains outside this change and is recorded in shader technical debt.This is stacked on #6416. Its original fault-lane commit and the follow-up author's commit remain attributed to their respective authors.
Tested
1002:13c0), driver 32.0.21036.18, Windows 11 Enterprise build 26200.main(3de84fa1),git diff --checkandpython3 tools/check_conventions.py --base upstream/mainpass. The runtime tests were not rerun after the rebase.Checklist
main; no other open PR implements the barrier-write fixImported from boykopovar/AnyPS5. Originally posted by DavidAmsellem on 2026-10-18T22:59:34Z.
This PR fails two tests that pass on
main, and it is not vendor specific: it also fails onlavapipe, which is what CI runs.
Built
1c5a918bcmerged intomain0bc3003f8, Release,BUILD_TESTING=ON, Linux Mint 22.3(Ubuntu 24.04 base), GCC 13.3, on an RX 7900 XT (RADV NAVI31, Mesa 25.2.8).
mainmain+ this PRagc_shader_memoryagc_driver_bda_span_readsMessages:
agc_driver_bda_span_readsalso reports, before that line:Both failures reproduce with
ANYPS5_GPU=llvmpipeon the same build, so this is independent of thedriver rather than an AMD difference.
For completeness: this machine has no read-write access to
/dev/udmabuf, so the run prints theusual permission line and
agc_driver_guest_memory_lifetime_directfails here onmaintoo. Thatis unrelated: both tests above pass on plain
mainin exactly the same environment.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-19T00:13:14Z.
Tested at
1c5a918bcon Windows 11 (GCC 15.2.0, Release), on an RTX 5070 Ti (617.42) and an AMD Radeon iGPU, RDNA2 (1002:13c0, 32.0.21042.62,ANYPS5_GPU=AMD). Two tests fail with this PR on both GPUs, both merged ontomain9f25d0bf5and on the PR's own base3de84fa10:agc_shader_memory:BDA read functions: a read site does not call its span read function onceagc_driver_bda_span_reads:AGC graphics: BDA span reads: no unmapped fault report:(empty); it passed 0 of 5 runs on each GPU.By commit:
3de84fa10(base)451a8a201(#6416's commit)agc_driver_faulting_wave_invocationac131aba9(mask barrier compute writes after BDA read faults)1c5a918bc(head)The last case printed before the span failure is
wave32 barrier=1orwave64-mixed barrier=1on NVIDIA, andwave64-split barrier=0on AMD.Minor: the debt entry is under "Unknown function info" rather than "Functional".
AI-assisted: yes (Claude Code); results above were run on this machine.
Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-19T08:22:24Z.
Rebase handoff — rebased onto current
main(all three commits, authorship unchanged). One docs-debt conflict, unioned.Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release,
BUILD_TESTING=ON, AMD RX 9070 XT / RADV): builds; conventions pass; full suite green apart from the four knownmainregressions (#5444 Mesa, #7584 BDA, #7766, #7784), none from this PR.To pick it up:
Head is
27d15fb7e.Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-19T08:25:10Z.
One note on the handoff:
agc_shader_memory(a read site does not call its span read function once) andagc_driver_bda_span_reads(no unmapped fault report) fail on the rebased head — and fail identically on your own unrebased head, so they are the branch's own state, not the merge: the barrier-masking changes the read-fault path makes appear to change the span-call pattern the test counts and the fault-report case the span test expects. Everything else is green apart from the four knownmainregressions (#5444 Mesa, #7584 BDA, #7766, #7784). The handoff branch is still up for the rebase value with this caveat.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-19T16:52:22Z.
Thanks for the rebase handoff and the follow-up that pins these failures to the PR’s own change. I confirm the two cases are still unresolved:
agc_shader_memoryexpects one span-read call andagc_driver_bda_span_readsexpects the unmapped-fault report, and they fail on the reported PR heads while passing on main. I won’t treat the clean remainder of the suite or the rebase as resolving them; the change needs to preserve the barrier-safe write masking while restoring those read-path expectations.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-20T08:27:46Z.
Review status: the reported #7392 head
1c5a918bc5is still known to failagc_shader_memoryandagc_driver_bda_span_readson NVIDIA, AMD, and lavapipe, while the reported base passes. The rebase handoff at27d15fb7ecarries the same failures, so rebasing alone does not resolve them. Issue #6689 documents a different follow-up commit21745fa223with all-fault and mixed-lane tests reported passing 5/5 on RTX 5080 and AMD, but that evidence is from an older main and the compile-time cost remains unmeasured. I recommend holding merge until a corrected series passes both regressions on current main and reports the barrier-shader compile impact. No commits were added or pushed in this update.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-20T14:28:56Z.
Thanks for this. The branch conflicts with main only in
docs/dev/debt/shader.md, where main added two entries next to your new "BDA read faults" entry. We'll merge current main into the branch ourselves, keeping both sides, so there's nothing to do for that.One question on 1c5a918bc: the mixed valid/faulting barrier cases now run only when the device's native subgroup size is exactly 32, so they're also skipped on 64-wide hosts (RADV's default compute subgroup), not only on narrower ones. Is that intended, i.e. does the mixed layout assume 32 lanes? If they hold at 64,
>= 32would keep them running on AMD hardware.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-20T15:04:37Z.
We reproduced both failures on an RTX 4090 with this branch on current main (main alone passes 16/16), and narrowed them down in case it helps the corrected series:
agc_shader_memoryfails with "a read site does not call its span read function once". It passes again with ac131aba95'sbarrierComputemasking switched off, so that new rule is the cause.agc_driver_bda_span_readsfails in its wave64 non-coherent barrier case: a wave64 barrier program on a 32-lane host gets no "BDA access failed" report at all. It still fails with the masking switch off, so this one is in the spanned-wave fault path, not the switch.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-20T21:47:52Z.
Thanks for reproducing this on the RTX 4090 and separating the two failures. The
barrierComputemask accounts for theagc_shader_memorycall-count regression, while the wave64-on-32-laneagc_driver_bda_span_readsreport is independent and still missing with that switch off. Since the base passes and this head fails both cases, I agree this head needs a corrected series before it can be considered validated. Please keep the second failure in scope when updating the PR; the current focused pass on the original GPU set does not cover these newer regressions.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-20T21:52:41Z.
The mixed control expects valid lanes to write their two output dwords and faulting lanes to leave theirs unchanged;
RunFaultcompares the whole buffer against that per-work-item expectation. Thenative.subgroupSize == 32gate was intended to exercise the special wave64-on-32-host spanned case, not because the address pattern itself requires 32 lanes. I agree it unnecessarily skips the native 64-lane-host case; that case should also run (with>= 32). I have not changed the test on this already-failing head, so the expansion still needs to be included and validated with the corrected series.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-20T22:37:38Z.
Thanks, these current-main repros are useful. The 32-only gate was conservative because the fixture uses a 32-lane guest wave; I do not have evidence that the mixed-lane case requires a native 32-lane subgroup, so I can’t justify claiming wave64 coverage from the current test. Separately, both
agc_shader_memory(introduced by barrier-write masking) and the wave64agc_driver_bda_span_readsfailure remain real blockers even though the second reproduces with that switch disabled. I’m keeping the PR unready until the corrected series preserves the main behavior and reports the fault on the spanned-wave path; I won’t treat the existing passing subset as sufficient.Imported from boykopovar/AnyPS5. Originally posted by cookie42073-cmd on 2026-10-21T07:25:23Z.
Hey @MarcZX10, I’m starting a Windows repro of the two failures on
4b76e2c1d6644985ea78a5134a63cc8dca64eddb, using an RTX 4070 SUPER and a pinned current-main control. I’ll check the span-read call-count regression and the missing wave64 fault report separately, then share the patch and before/after logs here if I can verify a correction.Have you already started a corrected series? I’ll keep this work with #7392 rather than opening a competing PR, preserve the existing commit authors, and keep #6416 as the declared prerequisite. I also saw @Celegans12’s separate spanned-wave masking follow-up on #6416; I’ll flag any overlap before proposing changes to that path.
No fix or game result is being claimed yet. AI-assisted investigation and independent review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T07:27:37Z.
I have not started a corrected series. Please continue the focused repro on this PR and keep #6416 as the prerequisite; I will avoid a competing fix while you investigate. The separate span-read call-count and wave64 fault-report paths should stay isolated as you described.
Imported from boykopovar/AnyPS5. Originally posted by cookie42073-cmd on 2026-10-21T08:05:55Z.
Hey @MarcZX10, I reproduced both failures and have a separate test-only correction for each.
agc_shader_memorywas counting the old non-stopping helper in the barrier fixture. The emitter now calls the fault-returning_stophelper there. The correction keeps the five-call/two-adjacent-span checks, coherence, CAS and size checks, and checks that barriermainhas only its final return.s_noppadding fixes that observation without changing its input/output memory addresses. Each report must identify that case, and the whole 64 KiB output comparison and mixed 32-valid/32-faulting layout remain checked. The mixed controls now admit native subgroups>= 32, as discussed above.Tested against main
0c50cbf3e4a99e93389368e1e72a0d365cff3992plus PR head4b76e2c1d6644985ea78a5134a63cc8dca64eddb:Each corrected test also passed five fresh-process runs on each GPU: 20/20 test executions, with all 12 fault controls showing zero wrong output dwords every run. Vulkan was required, the AnyPS5 shader cache was disabled, and the requested Khronos validation layer actually loaded; neither side reports a VUID.
APS5_SPANNED_WAVEwas unset.As a negative control, disabling
barrierComputemakes both corrected tests fail: all 12 fault reports are still observed, but 8 barrier programs wrongly store output (128 dwords for all-fault cases, 64 for mixed). I restored the production source, checked its bytes and rebuilt before the final runs.Full Windows builds of pinned main, the original PR integration and the corrected integration passed with the same separate alignment workaround for
ImageArrayWindowPastLayerLimit.cpp. Untouched main fails that fixture'salignas(65536)on WinLibs; the workaround is included separately for reproducibility and is absent from these two correction commits. Conventions and whitespace checks pass. The full CTest suite was not run.Patch commits, authored as Blazing Cook:
e2227345e75092c40ce07b59eb5ef685b9fcbb5938f507ceb6031b756ed2876dce035245f5395e1dThe format-patches and combined diff apply cleanly to exact PR head
4b76e2c1. This handoff builds on Celegans12's and Amoenus's implementation and your fixture work; #6416 remains the prerequisite. Independent review covered the source, raw logs and final package.The representative large-barrier compile-time check is still open. I couldn't locate a public replay attachment in the checked sources. Could someone share a reduced barrier+BDA replay request, or run an A/B on an existing request and report exact commits, GPU/driver, preparation time, SPIR-V words and cold pipeline compilation/cache controls? Native64, AMD, other platforms and title validation also remain open; no title-unblock or performance claim is made. At the final overlap check,
f894ba69adds cache-path housekeeping and unrelated library/tool fixes; neither corrected fixture nor the barrier fault-mask source changed. Results above are for the pinned0c50cbf3integration.Public log copies replace local filesystem prefixes with placeholders; the private originals are retained. The archive records public-entry hashes and raw/public provenance hashes.
AI-assisted: yes.
AnyPS5-7392-tests-and-evidence-20261021.zip
ZIP SHA256: 0856cb1607fbf8ed298121a94e2f856580c6e22fa64cc9ac3bfbc5bc890eafc2
Imported from boykopovar/AnyPS5. Originally posted by Alexius0815 on 2026-10-22T15:23:10Z.
@MarcZX10 a compile-time measurement for the open point in your Tested section ("Compile time for a representative very large barrier compute shader has not been measured"). For this shader the PR makes the back-end compile much faster, not slower.
Shader. vkQuake (PPSA99010) compute
0x20bf7f400: 2748 code words, wave64, 14 barriers, 211 device stores. This is the kernel that keeps MoltenVK in the Metal compiler for over a minute (see #1). I saved its request withAPS5_DUMP_SHADERSand replayed the same.reqwithagc_shader_replay --spvtwice, on the community macOS stack before and after cherry-picking this PR's three commits (451a8a201, ac131aba9, 1c5a918bc). Both SPIR-V outputs went through SPIRV-Cross (--msl --msl-version 30100). I timed them with the system Metal compiler throughMTLDevice, the sameMTLCompilerServiceMoltenVK uses, on an Apple M4 (macOS 27.2):return;ifrecord_bda_faultare what costs the Metal back end. I tested two measurement-only arms on an earlier extraction of the same kernel from the shader cache (413k words, 63–81 s pipeline):newMTLComputePipelineStateat 8 and 12 s. So MoltenVK's own build of this kernel did not hit the cache that my standalone compile hit, possibly because its MSL or pipeline descriptor differs. I'm looking into that separately. It doesn't change the comparison above.I only measured compile time and didn't check the PR's fault semantics. Replay tool, scripts and timings are on the M4 if you want any other variant measured.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-11-01T19:59:01Z.
Review: COMMENTED
1. Stacked and not rerun. This is stacked on #6416 and the body says the runtime tests were not rerun after the rebase onto
main3de84fa1; onlygit diff --checkand the conventions script were. The five-run GPU results live in issue #6689, on the pre-rebase tree. Please rerun the BDA span-read tests on the current head.2. Compile-time and size cost is unmeasured. The body states the per-lane write mask "may affect compile time" for large barrier compute shaders and that no measurement was made. The mask is added to every write, atomic and export in a shader that has a barrier plus a BDA read, so SPIR-V size and variant compile time grow with the number of stores. Please give SPIR-V word counts and compile time for one large barrier shader before and after, and say whether shaders that have BDA reads but no fault possibility are affected.
3. Validation. The tests are BDA execution tests on two GPUs but no mention of running with
VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validationand comparing for newVUID-lines againstmain, which the shader recompiler rules require. A barrier inside divergent control flow is the kind of thing the layer and the SPIR-V validator complain about.4. Negative control for the mixed case.
RunFaultbuilds a mixed valid/faulting input and requires that valid lanes' writes land; does the test fail if the write mask is dropped (faulting lanes writing garbage) or if the barrier is skipped for faulting lanes? The body claims both lanes are covered but does not say the test was shown failing.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-02T04:56:54Z.
Review: COMMENTED
Replies checked — failing tests and four review points need answers, corrections not on branch
The 29 Oct NVIDIA run at this head reports three new failures, and the branch still conflicts with current main.
What I ran
39a016143547fd5d5ae866a78622240f58b0dcfd(OPEN, unchanged from batch).gh apicomments, reviews and review comments on #7392, newer than 2026-10-30T01:44:46Z, excluding MarcZX10 and bots.gh pr view 7392 --json body,statusCheckRollup; the 2026-10-29 TechLevelZero comment.git cat-file,git merge-tree --write-tree upstream/main 39a01614,git grepfor the write-mask gate andRunFault.Results
merge-treevs upstream/mainSpirvEmitter.cppagc_shader_memoryfails with production change; bothagc_driver_bda_span_readsvariants7664761651,f492498clinux,register-context,write-watchSKIPPEDFindings
RunFaultis atBdaSpanReads.cppL160. Write masking is gated atSpirvEmitter.cppL329 and applied to guest-state writes atSpirvFlowEmitter.cppL827, so "every write, atomic and export" is only partly right. Whether the test fails without the mask is not shown. Answer needed.Sources
github.com/boykopovar/AnyPS5@39a0161435/core/shader/recompiler/SpirvBackend/src/SpirvEmitter.cpp (L329)github.com/boykopovar/AnyPS5@39a0161435/core/shader/recompiler/SpirvBackend/src/SpirvFlowEmitter.cpp (L827)github.com/boykopovar/AnyPS5@39a0161435/core/libs/prx/libSceAgcDriver/tests/execution/BdaSpanReads.cpp (L160)Not verified
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.