AGC: a recorded draw into a resident linear color target stores the whole target back over CPU stores made after the draw #8152
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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 Celegans12 on 2026-10-20T00:39:54Z.
Since #6892, a draw into a linear color target over imported memory is recorded, and
keepRecordedDrawrecords the store-back of the whole resident image (StorageTexture::FlushPending(..., "linear target")). That store-back runs on the GPU when the batch does. Anything the CPU stored into the target's memory after the draw was issued, in pixels the draw never touches, gets overwritten with the image's older contents. On hardware those pixels keep the CPU's bytes, and withAPS5_NO_RESIDENT_LINEAR=1(the synchronous copy-in/draw/copy-out path) they do too, since the copy-out has finished beforeDrawreturns.I found this while chasing a regression in Ghost of Yōtei (PPSA26344). On our tree merged with a recent
main, the player spawns in a T-pose under the map and the camera flies around; withAPS5_NO_RESIDENT_LINEAR=1the spawn is normal (two bisect runs with it, with different sets of our other switches, against one without it). The world runs store about 30-370 MiB per 10 s through the "linear target" write-back. I haven't proven that this rollback is what breaks Yōtei: it's the hazard I could reproduce, and it fits a title that renders data into linear targets that the CPU also writes.A small reproducer on top of
agc_driver_linear_target_resident: after the test's full draw andWaitIdle, draw again with the scissor covering the left half,memsetthe right half of each row from the CPU,WaitIdle, and check the right half. Onmain0393728fd3(RTX 3080 Laptop, driver 610.62, Windows 11) it fails with the right half rolled back to the first draw's pixels. With the resident path off it passes (the test's own "waited for the GPU" check has to be skipped for that run).@tibzejoker, since this is your change: would you rather fix the store-back (for example store only what the draw could have written, or only the dwords that changed from the image's copy-in, like #6185 does for buffers), or keep linear targets synchronous when the CPU writes into them? I'm happy to test a branch with Yōtei and to turn the reproducer into a PR test.
Details
Reproducer (added to
Expectintests/execution/LinearTargetResident.cpp, with ascissorWidthparameter on itsDrawhelper that setsstate.scissor):On
main:AGC graphics: the store-back of a recorded draw into a linear target overwrote row 0 outside the draw's scissor, which the CPU stored after the draw.Yōtei runs (our merge tree, same build and save, warm caches, 470-800 s each): w23m-c with the default path, T-pose/camera bug; w23m-b and w23m-d with
APS5_NO_RESIDENT_LINEAR=1, normal spawn.[storage]write-backs by reason in w23m-c:linear target33-84 per 10 s, 31.6-372.0 MiB.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-20T01:51:34Z.
I checked the current
writeBackLayerspath: when a CPU-written 64 KiB block differs from its baseline, write-back keeps that whole block. The proposed right-half assertion could therefore pass while also discarding the second draw's new pixels in the left half of the same blocks.Could the reproducer also seed the left half with a sentinel before the second, left-scissored draw, then assert that the left half contains the draw's output and the right half still contains
0x42? That would catch both halves of the ordering bug. I haven't run this variant; this is based on the current write-back logic.Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-20T03:05:22Z.
I ran your variant on current
main(c2b0159d6e, RTX 3080 Laptop, Windows 11), and on its own it doesn't show the left-half loss: both halves come out right in 5 of 5 runs.writeBackLayersand the linear-target store-back haven't changed since I filed this (the onlyTexture.cppchange since0393728fd3is #5480'sCopyRefusal), so this is the same code.The seed is what hides it. The CPU store into the left half makes the second draw re-upload the image first, and that upload is recorded too: the detile reads the import when the batch runs, which is after the test's
0x42memset. So the CPU's right half goes into the image and comes back out with the whole-image store-back. The rollback is masked, not fixed. I'd expect it to come back if the batch got submitted between the draw and the CPU store, but I haven't shown that. The keep rule you describe doesn't get to run in this sequence either.keepRecordedDrawcallsFlushPendingright after recording the draw, so the keep decision is made before the CPU writes anything after the draw, and the upload has already stamped the seed as in sync.APS5_TRACE_FLUSH=1prints no "keeps N CPU-written 64 KiB blocks" line.To check both halves without depending on the seed, the second draw now writes blue = 2.0, so its pixels differ from the first draw's. The test runs your seeded case and an unseeded one on separate targets. Without the seed,
mainkeeps the left half (all 512 pixels are the second draw's output) and loses the right one: 7,680 of 8,192 bytes are back to the first draw's values. The other 512 bytes only match by coincidence, since they're the0x42high byte of red for x = 32..63. WithAPS5_NO_RESIDENT_LINEAR=1, both cases pass in 5 of 5 runs.So I think your variant is worth keeping, mostly as a guard for the fix. A fix that moves the keep decision to batch completion would see the CPU's post-draw stores, and with whole-block keeping it would then drop the left half exactly as you describe. Both cases are in
repro/8152-linear-writeback(b1c835f80d, one commit onc2b0159d6e). Did you have a sequence in mind where the keep rule fires onmainas it is? If so, I'll add it as a third case.Details
agc_driver_linear_target_resident_testsonc2b0159d6eplus the commit above, NVIDIA GeForce RTX 3080 Laptop GPU, 5 runs per configuration (all 5 identical in each):With
APS5_TRACE_UPLOAD=1 APS5_TRACE_FLUSH=1onmain, only the seeded target re-uploads before its second draw, and neither write-back keeps a block:"0 left pixels already held the second draw's output when Draw returned" means nothing has run on the GPU yet when the CPU stores the right half. The old path has finished its copy-out by then (512).
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-20T06:43:07Z.
You were right: I do not have a sequence where the keep rule fires on main in the case I proposed. The seed causes a re-upload after the CPU store, and
keepRecordedDrawmakes its flush decision before later CPU writes, so my suggested keep-rule explanation was wrong. Your unseeded, different-output case shows the actual whole-target writeback ordering bug. I am correcting my local regression and fix direction around that case; thanks for running it and tracing the sequence.Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-20T16:26:57Z.
I ran #8246 with Yōtei: the reproducer and the PR's tests pass, but the game still spawns wrong with resident linear targets on. Details are in https://github.com/boykopovar/AnyPS5/pull/8246#issuecomment-6295776844.
Imported from boykopovar/AnyPS5. Originally posted by tibzejoker on 2026-10-21T09:41:29Z.
Thanks @Celegans12 for tracing this, and sorry for the hazard.
On the direction: I'd rather fix the store-back than make these targets synchronous again. Synchronous linear targets were the main thing #6892 removed for GTA V: in the prologue they cost one SubmitAndWait per draw, about 130 per 10 s, and going resident took it from 14.6 to 16.5 FPS. Merging only the bytes the draw could have changed against the copy-in baseline, as #8246 does and as #6185 does for buffers, keeps that gain and closes the rollback. So I'm for #8246's approach.
On the remaining Yōtei spawn: your sync control rules out ordering, so the wrong bytes must come from the baseline or the resident image itself. GTA V draws into resident linear targets all the time, which makes it a second title to test this on. Here, on an RTX 4090 with NVIDIA 616.92 on Windows, I'll run
main,main+ #8246 andmainwithAPS5_NO_RESIDENT_LINEAR=1, and look at two things:PrepareLinearDrawcosts per draw. @wachi35676 noted that nobody has measured it yet: it does a full copy into a 2x buffer before every recorded draw.I'll post the results here and on #8246.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by tibzejoker on 2026-10-21T17:37:44Z.
GTA V numbers for #8246 are posted there: https://github.com/boykopovar/AnyPS5/pull/8246. In short, rendering is correct and the spawn is normal on this title, and the committer cost per draw is +12 % against the resident path and +4 % against the synchronous one.
AI-assisted: yes (Claude Code)