fix(agc): preserve GPU edge results after unchanged CPU writes #1918
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1918"
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 nikhilpanchal1 on 2026-10-08T23:47:03Z.
What
Addresses finding 2 of #865. A same-value CPU write dirties a page even when its bytes still hold the allocator fill. Storage-image writeback previously discarded the GPU results for that CPU-stamped edge, losing glyphs.
Keep immutable baselines for at most the two partial 64 KiB edges. Merge GPU results into bytes that still equal the baseline while preserving actual CPU edits. Newer driver stores retain ownership even when they write the same value; retired allocation identities cannot authorize a merge into replacement memory.
Capture baselines before uploads, clears, and copies return, waiting only for earlier physical writes overlapping an edge. Alias borrowing retains baseline ownership, and ordinary GPU writeback renews baselines from the exact immutable retiled output. Full-block ownership and upstream Windows import coverage policy remain intact.
Related open PR: #1599 targets the same finding with a whole-range equality check. This is an alternative implementation that also preserves GPU bytes beside real CPU edits in the same edge and distinguishes ordered driver stores from CPU page stamps. It has no dependency on that PR.
Tested
Linux Release build, GCC 14, Mesa 26.1.6 llvmpipe; Vulkan execution required.
f1451396.agc_driver_f32_denormal_flush: lane 20 FMA returns0x00800000versus expected0x00ffffff. It reproduces after rebuilding and running that target on an unmodified checkout of upstreamf1451396. Shader translation and this floating-point test are unchanged by this patch.ANYPS5_REQUIRE_VULKANis unset; the same setup fails with it set.This host lacks userfaultfd. The new Linux regression uses a test-only page-watch backend; allocation tracking, host imports, detiling, GPU commands, and readback are production code. Native write-watch and subgroup/rasterization capability skips are reported separately from passes. Windows and interactive title testing were not performed.
Checklist
main; competing implementation #1599 is disclosed aboveImported from boykopovar/AnyPS5. Originally posted by klosixgaming-arch on 2026-10-09T00:47:17Z.
Review: COMMENTED
I'm not approving this yet, and I want to be specific about why rather than rubber-stamp it. This is a large, intricate change to the write-back / write-tracking core, and I don't think the diff alone gives me enough grounded confidence to sign off.
What I'd want before this is approvable:
The core invariant isn't demonstrable from the diff. The whole point is "preserve GPU results in bytes that still equal the baseline, while keeping real CPU edits." That depends on the interaction of four new pieces —
MergeChangedCommitted's per-byte CAS againstoriginal,driverStoredOver/driverBlocks,edgeSnapshot'sallocationweak_ptr ownership, andfinishEdgeMerges'DriverStoredOvergate. The failure mode that matters (a GPU writeback being silently dropped on a CPU-stamped edge, or a CPU edit being overwritten by a stale GPU result) is exactly the class of bug that's easy to miss in review and hard to prove from reading. Can you point me to a concrete before/after capture — the specific glyph/edge that used to be lost and now survives — plus the test that fails onmainand passes here? The body references finding 2 of #865 and "glyphs", but I want the repro, not the claim.Competing implementation. You disclose #1599 targets the same finding with a whole-range equality check, and this is a "different" implementation. That's a maintainer decision, but I'd want it made before review, not after — otherwise two large divergent write-back rewrites both sit in review and one gets merged by accident. Which one is the project going with, and is this the chosen one?
The CAS merge assumes
originalis a trustworthy per-byte baseline. InMergeChangedCommitted,compare_exchange_strong(expected=original[byte], desired=current[byte])keeps a byte only if the current destination still equalsoriginal. If a CPU wrote to that byte after the baseline was captured but before this merge ran, the CAS would fail and the CPU write survives — good. But if the GPU and CPU both touched the byte, the GPU result wins. Is that the intended precedence, and is it stated in the debt entry? The body says "Newer driver stores retain ownership even when they write the same value" — I want that precedence made explicit and tested, because it's the load-bearing assumption.Pre-existing failure disclosure. You report
agc_driver_f32_denormal_flushfailing (lane 20 FMA0x00800000vs0x00ffffff) and claim it reproduces on unmodifiedf1451396. That's plausible (llvmpipe denormal handling), but it's exactly the kind of "it fails and I blame the host" that needs a clean proof. A short note with the exact command and the unmodified-checkout output would close it.I'm not asking you to prove it's wrong — I'm asking for the evidence that lets me verify the one thing that matters (GPU results not silently lost, CPU edits not clobbered) without having to fully simulate the ownership model in my head. If you can supply 1, 2 and 3, I'll re-review and this is very likely approvable.
Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-09T01:09:58Z.
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.
main)core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppL770docs/dev/TechnicalDebt.mdL248-249docs/dev/TechnicalDebt.mdL248-249docs/dev/TechnicalDebt.mdL248core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppL427core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppL1479, L1553-1556docs/dev/TechnicalDebt.mdL248-249Imported from boykopovar/AnyPS5. Originally posted by nikhilpanchal1 on 2026-10-09T04:02:45Z.
@klosixgaming-arch Thanks for the review. Added regression tests and documented the merge precedence in
97655b67: changed CPU bytes survive, same-value/ABA writes permit GPU merging, and newer driver stores block stale merges. The updated edge test passes locally, uncached and with synchronization validation; CI is still running.Native/title validation and the choice between #1599 and #1918 remain open.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T08:53:48Z.
Closing: #1599 fixes the same finding from #865 with a much smaller change and a title behind it. If it misses a case this one handles, please show it on #1599 with the title and what it loses on main.
Imported from boykopovar/AnyPS5. Originally posted by popcoder565 on 2026-10-09T09:32:10Z.
Native Windows run, since the description notes Windows wasn't tested. Setup: Windows 10 (19045), RTX 3060 Laptop (NVIDIA 616.92), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Head
97655b67merged ontomaind9484c71.The new
agc_storage_edge_writebackfails in every run (10 of 10, and in both full-suite runs):driverProvenanceTests(StorageEdgeWriteBack.cpp:418).std::arrayon the test thread's stack. On Windows that stack is inside the guest arena's range (8 GiB to0xFC00000000); here it was at0x49ab5f5350, andMemory::Watchedreports it as watched. On Linux the stack is outside that range.Everything else passes:
agc_driver_dcc_keys_first_writeandagc_driver_srgb8_color_targetpass 10/10 each; they exercise the late NVIDIA marks from #1434.agc_driver_recorder_tests, built explicitly: 3/3.No title was run.
🤖 Addressed by Claude Code
Imported from boykopovar/AnyPS5. Originally posted by nikhilpanchal1 on 2026-10-09T09:46:15Z.
@popcoder565 thanks for the native Windows run, seems you were right about the stack allocation. Fixed in eca4eee5: the untracked-range checks now use an address-only range outside the guest arena, and run before Vulkan setup so missing GPU support cannot hide them. All three assertions are preserved.
The updated regression passes 10/10 on Linux, plus three runs with Vulkan synchronization validation. I haven’t rerun it on native Windows; could you check the updated head when you have time?
Imported from boykopovar/AnyPS5. Originally posted by popcoder565 on 2026-10-09T10:27:39Z.
@nikhilpanchal1 thanks.
eca4eee5isn't on the PR branch yet; its head is still97655b67. I'll rerun the Windows check once it's pushed.Also, since #2096 merged, the branch conflicts with
main(51f69aa2) inTexture.cpp,Texture.hppandTechnicalDebt.md.🤖 Addressed by Claude Code
Imported from boykopovar/AnyPS5. Originally posted by nikhilpanchal1 on 2026-10-09T10:30:57Z.
@popcoder565 it's cause the PR is closed. You'll have to fetch from fork unfortunately
Imported from boykopovar/AnyPS5. Originally posted by popcoder565 on 2026-10-09T15:01:45Z.
@nikhilpanchal1 thanks. I hadn't noticed this was closed in favour of #1599 before my run. The branch also conflicts with
mainnow, so I'll leave eca4eee5 for now. If the regression test moves to #1599 or a new PR, I'll run it on Windows there.🤖 Addressed by Claude Code
Pull request closed