Repository navigation
fix(agc): copy only the dwords a shader changed back from a GPU-copied buffer - #6185
Conversation
|
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.
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.
|
|
The overlap with #6182 is the option list in the test binary's main (tests/Recorder.cpp), both add a |
# Conflicts: # core/libs/prx/libSceAgcDriver/CMakeLists.txt # core/libs/prx/libSceAgcDriver/Execution/include/GuestMemory.hpp # core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp # core/libs/prx/libSceAgcDriver/tests/Pm4.cpp # docs/dev/debt/libSceAgcDriver.md
…back # Conflicts: # core/libs/prx/libSceAgcDriver/CMakeLists.txt
✅ NVIDIA GPU test: passedPR head
Unstable on main (1, these also failed in recent main runs on this machine; not counted against this PR)Failing on main too (3, not counted against this PR)Validated but not compared (2, not in the main baseline's validation pass)Validation IDs already present on main (5 IDs in 480 tests)Skipped (44)ReproduceAutomated build and test on a contributor's NVIDIA machine; it does not replace upstream CI. A new comment is posted for each new push. Full logs. |
|
Correction: In the previous review (at head should-fix Findings
Freshness Envelope
Cross-PR Ledger
|
CnRJay
left a comment
There was a problem hiding this comment.
Points on 6185:
-
Known data loss accepted in a comment.
GuestBufferMemory.cppadds a comment block: "Accepted trade-off ... a CPU write between the copy-in and the copy-back is rolled back at the unaligned ends of a range, in a region that is not 4-byte aligned and without a shadow copy". That is a lost guest store for some inputs. The repo rule is exact-or-throw: either make the unaligned ends correct or throw for them and record the gap indocs/dev/debt/libSceAgcDriver.md. A comment is neither. -
Comments in code. The same block, and others in this diff, break the no-comments rule. Please remove them.
-
Speed claim. The point of the change is a smaller copy-back. Please attach
tools/trace_digest.pysummaries of main and the change, same machine and scene, and say what the changed-dword detection costs per submission on a large buffer. -
Negative control. Does the new test fail with the fix reverted, and is there a case with a CPU store between copy-in and copy-back at an unaligned end?
|
A Windows data point from a title, in case it helps scope this PR. It is not a review of the change. Space Adventure Cobra: The Awakening (PPSA17337) has an intermittent crash with a symptom similar to the PPSA15304 one in the description. The fault is on I ran 90 s boots, alternating, with a save present, on Windows 11 22621 with an AMD RX 6700 XT and driver 26.10.1:
All three crashes are at the same instruction. So this PR does not prevent Cobra's crash. A diagnostic build logging buffer copy-backs and staging stores of 4 KiB or more recorded none in a crashing boot. That points to a different write path for this title, not the one this PR changes. I'm tracing it with a build that logs every large guest-memory write with its caller. Nothing here bears on the PPSA15304 result. |
# Conflicts: # core/libs/prx/libSceAgcDriver/tests/Recorder.cpp # core/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_recorder_tests.cmake
✅ NVIDIA GPU test: passedPR head
Unstable on main (3, these also failed in recent main runs on this machine; not counted against this PR)Failing on main too (3, not counted against this PR)Validated but not compared (2, not in the main baseline's validation pass)Validation IDs already present on main (4 IDs in 495 tests)Skipped (45)ReproduceAutomated build and test on a contributor's NVIDIA machine; it does not replace upstream CI. A new comment is posted for each new push. Full logs. |
Superseabas
left a comment
There was a problem hiding this comment.
Windows run of head f0a15aeb5e merged onto current main b28bb77217 (clean merge, local only), on two GPUs, plus a read of the change against @CnRJay's points.
Windows 11 Home 10.0.26200, Ryzen 7 7700X, WinLibs GCC 16.2.0 (x86_64-ucrt-posix-seh, r3), Release, BUILD_TESTING=ON. ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, every test of agc_driver_recorder_tests and agc_driver_pm4_tests, ANYPS5_GPU selecting the device (confirmed by Selected GPU):
| GPU | Driver | main |
merged |
|---|---|---|---|
NVIDIA GeForce RTX 5070 Ti (10de:2c05) |
621.01 | 132 of 132 | 134 of 134 |
AMD Radeon Graphics, Ryzen 7 7700X iGPU (1002:164e) |
AMD 26.10.1 | 132 of 132 | 134 of 134 |
- No
VUID-lines and no missing-layer line on either side. agc_changed_copy,agc_copied_write_backandagc_bda_stagingwithAPS5_TRACE_COPY_BACK=1, 3 runs per GPU: each run logs[copy-back] ... 1 dwords where the shader and the CPU changed the same bytes; the CPU's bytes were kept, and none logsstaged write-backs copy their whole ranges, so the kernel path ran rather than the fallback.check_conventions.py --base mainpasses on the merge.
On the earlier review points, at this head:
- The
Accepted trade-offblock is not new:mainalready has it, and it says a CPU write into a staged range is rolled back across the whole written element range. This PR edits it to the remaining case, the unaligned ends. The same case is written out in theDevice-local stagingentry ofdocs/dev/debt/libSceAgcDriver.md, so the gap is recorded there. Whether the code comment should go now that the debt entry carries it is for a maintainer; CONVENTIONS allows debt comments only from a human. - The other comment change is also an edit of an existing
maincomment, not a new one. - The PR does not claim a speed change, so the
trace_digest.pyrule for speed claims does not seem to apply. - Negative control: the description says
agc_copied_write_backfails withWriteChanged, and @ahmadmuj's red check reproduced the CPU-side one. The unaligned-end case is the recorded gap, so no test expects it to keep the CPU's bytes.
One question on the kernel: StagingCopyBack.comp reads the import's dword (held) and writes the whole dword back when stored != 0. A CPU store into another byte of that same dword between the read and the write is rolled back. The window is much smaller than the whole-range copy it replaces, but the debt entry says a CPU store in between survives. Would it be worth either a compare-and-swap loop on the target dword, or a sentence in the debt entry for that race?
Smaller: if the copy-back pipeline cannot be created, RecordChangedCopy prints [gpu] staged write-backs copy their whole ranges and the whole range is copied as before. The debt entry lists the other cases that fall back to the whole copy, but not this one.
AI-assisted: yes (Claude Code)
What
A buffer region that is staged in device memory (a region the GPU copies in and later copies back,
GuestBufferMemory) was copied back whole when its batch completed, and the CPU write-back path stored every byte that differed from the uploaded bytes. A store the title made into the region after the upload, in bytes the shader never touched or in bytes it touched as well, was overwritten with the GPU's copy of the stale bytes. PPSA15304 corrupted its guest heap this way: the allocator's free-list link in a block it had released after waiting for its label was replaced by texel data, and the title faulted on the next allocation.Two changes:
GuestMemory::WriteChangedKeepingGuest, which stores a byte only where the result differs from the uploaded byte and guest memory still holds the uploaded byte, so a CPU write made after the upload wins (the SSE path masks with both compares; the tail loop does the same).WriteChangedand its other callers (image mirrors, heap mirrors, storage images, tiled colour targets) are unchanged.StagingCopyBack.comp, buffer device addresses) that applies the same per-byte rule to each dword: the shader's bytes land where they differ from the snapshot and the import still holds the snapshot's byte. Unaligned edges copy as before.APS5_NO_CHANGED_COPY_BACK=1restores the whole copies,APS5_CHANGED_COPY_ALWAYS=1makes the kernel store every byte, andAPS5_TRACE_COPY_BACK=1counts the dwords where the shader and the CPU changed the same bytes.Tested
Linux, Ubuntu 24.04, NVIDIA GeForce RTX 5080 (driver 595.99.02). Tests:
testWriteChangedKeepingGuestKeepsCpuWrites(tests/Pm4.cpp) for the per-byte rule of the CPU write-back.agc_copied_write_back(tests/Recorder.cpp): a dispatch over a CPU-copied buffer, CPU stores after the batch completed and before the write-back (a conflicting dword, an untouched dword and a byte inside a dword the shader changed), checked after the write-back and on the next use of the buffer. It fails withWriteChangedin place ofWriteChangedKeepingGuest.changedCopyTests(tests/Recorder.cpp): 70000 dwords with whole-dword and single-byte changes on both sides; every byte is checked against the per-byte rule, and the trace counter against the dwords where both sides changed a byte.bdaStagingTests: CPU stores into the import after the copy-in, one in a byte the fill leaves alone inside a filled dword and one outside the filled range, checked after the copy-back.The tests of
agc_driver_recorder_testsandagc_driver_pm4_testspass onmain(95) and on the change (97,agc_changed_copyandagc_copied_write_backadded) withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_LAYER_KHRONOS_validation, with 0VUID-lines in either log; the staging, changed-copy, copied write-back, PM4 and storage write-back tests also pass withAPS5_NO_CHANGED_COPY_BACK=1. In PPSA15304 the earlier per-dword kernel ran through the section after the first drop with no divergence reported by the trace counter; the title's remaining heap corruption came from the deferred DCC key stores, fixed in the follow-up PR.Checklist
main; no other open PR implements the same functions.mdfiles or images added to the repository