AGC: a storage surface refresh waits for the whole GPU when pending GPU writes overlap its DCC keys #3505

Closed
opened 2026-10-11 12:00:50 +00:00 by ThatsLeo · 6 comments
ThatsLeo commented 2026-10-11 12:00:50 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by ThatsLeo on 2026-10-11T12:00:50Z.


StorageTexture::ProvedKeys asks WaitForKeyWriters for the keys of a DCC surface whose uploaded keys are Uncompressed. When the recorder has a pending GPU write over the keys that is neither a known store nor a fill, it calls Recorder::SyncThrough, which finishes the recorder and waits for its fences (DccMetadata.cpp, WaitForKeyWriters). That happens on the draw path, once per refresh of such a surface.

In Stray (PPSA02101 v01.002, UE4), this wait is now the frame time. It runs at the calibration screen on main f1ae427b with the set in #2749, which removes the byte comparisons that came first:

  • APS5_PROFILE_DRAW: Graphics::Draw takes 8.5 to 9.0 ms per draw packet, about 9.1 s of every 10 s on the graphics worker (about 500 draw packets per 10 s, 2 FPS).
  • In three of four stack samples of that worker, it was in:
    vkWaitForFences <- Recorder::finish <- Recorder::SyncThrough <- WaitForKeyWriters <- StorageTexture::ProvedKeys <- StorageTexture::Refresh <- CachedStorageSurface
    
  • The CPU is mostly idle meanwhile.

I have no fix. The keys only have to be known before the CPU reads the surface's contents. The ways I can see:

  • keep them as GPU state until something reads them;
  • decide Uncompressed from the shader that writes them, as PendingStoreKeys and PendingFillsLeaveUncompressed already do for stores and fills.

Both are design questions for the DCC code. I can measure any branch on this title.

Setup: Fedora 44, GCC 16.2.1, Release, Intel Arc (Meteor Lake, Mesa 26.2.3 ANV).

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5800853248 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3505). Originally posted by [ThatsLeo](https://github.com/ThatsLeo) on 2026-10-11T12:00:50Z. --- `StorageTexture::ProvedKeys` asks `WaitForKeyWriters` for the keys of a DCC surface whose uploaded keys are `Uncompressed`. When the recorder has a pending GPU write over the keys that is neither a known store nor a fill, it calls `Recorder::SyncThrough`, which finishes the recorder and waits for its fences (`DccMetadata.cpp`, `WaitForKeyWriters`). That happens on the draw path, once per refresh of such a surface. In Stray (PPSA02101 v01.002, UE4), this wait is now the frame time. It runs at the calibration screen on `main` `f1ae427b` with the set in #2749, which removes the byte comparisons that came first: - `APS5_PROFILE_DRAW`: `Graphics::Draw` takes 8.5 to 9.0 ms per draw packet, about 9.1 s of every 10 s on the graphics worker (about 500 draw packets per 10 s, 2 FPS). - In three of four stack samples of that worker, it was in: ``` vkWaitForFences <- Recorder::finish <- Recorder::SyncThrough <- WaitForKeyWriters <- StorageTexture::ProvedKeys <- StorageTexture::Refresh <- CachedStorageSurface ``` - The CPU is mostly idle meanwhile. I have no fix. The keys only have to be known before the CPU reads the surface's contents. The ways I can see: - keep them as GPU state until something reads them; - decide `Uncompressed` from the shader that writes them, as `PendingStoreKeys` and `PendingFillsLeaveUncompressed` already do for stores and fills. Both are design questions for the DCC code. I can measure any branch on this title. Setup: Fedora 44, GCC 16.2.1, Release, Intel Arc (Meteor Lake, Mesa 26.2.3 ANV). AI-assisted: yes.
santhoshkumar-dev commented 2026-10-11 19:46:03 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by santhoshkumar-dev on 2026-10-11T19:46:03Z.


@ThatsLeo I have a branch for part of this and no title that reaches the path. Could you measure it on Stray the way you measured main?

Branch: https://github.com/santhoshkumar-dev/AnyPS5/tree/codex/dcc-pending-key-state (commit d1302782f, one commit on top of main a11c8f7f7). I can't open a PR for it yet because of the open-PR limit, so I'm asking here.

What it changes:

  • StorageTexture::ProvedKeys asks WaitForKeyWriters for every DCC surface, not only those whose uploaded keys are Uncompressed.
  • When the open recorder batch holds uniform fills that cover the surface's whole key range, WaitForKeyWriters takes the keys from those fills in record order (a later fill replaces only the bytes it covers) instead of calling SyncThrough. The answer is dropped on submission or on any guest mapping change.
  • PendingFillsLeaveUncompressed no longer counts a range covered by a writer of unknown value as uncompressed.

What it does not change: a pending writer whose result is unknown (a shader or a copy, not a fill) still syncs. Your report says the writer in Stray is neither a known store nor a fill, so this branch may not help there. A measurement would tell either way.

Useful numbers with APS5_PROFILE_DRAW=1, at the calibration screen, on main and on the branch:

  • Graphics::Draw time per draw packet ([draw] line)
  • the recorded store sync count and wait in the [recorder] line
  • keys proven: N sampled, N storage in the [rescache] line
  • if the frame time is unchanged, a stack sample of the graphics worker, to see whether it still reaches SyncThrough from WaitForKeyWriters

I tried Dreaming Sarah (PPSA02929). It has no DCC surfaces (0 key proofs, no [dcc] lines), so it says nothing about this change.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6112997961 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3505#issuecomment-6112997961). Originally posted by [santhoshkumar-dev](https://github.com/santhoshkumar-dev) on 2026-10-11T19:46:03Z. --- @ThatsLeo I have a branch for part of this and no title that reaches the path. Could you measure it on Stray the way you measured `main`? Branch: https://github.com/santhoshkumar-dev/AnyPS5/tree/codex/dcc-pending-key-state (commit d1302782f, one commit on top of `main` a11c8f7f7). I can't open a PR for it yet because of the open-PR limit, so I'm asking here. What it changes: - `StorageTexture::ProvedKeys` asks `WaitForKeyWriters` for every DCC surface, not only those whose uploaded keys are `Uncompressed`. - When the open recorder batch holds uniform fills that cover the surface's whole key range, `WaitForKeyWriters` takes the keys from those fills in record order (a later fill replaces only the bytes it covers) instead of calling `SyncThrough`. The answer is dropped on submission or on any guest mapping change. - `PendingFillsLeaveUncompressed` no longer counts a range covered by a writer of unknown value as uncompressed. What it does not change: a pending writer whose result is unknown (a shader or a copy, not a fill) still syncs. Your report says the writer in Stray is neither a known store nor a fill, so this branch may not help there. A measurement would tell either way. Useful numbers with `APS5_PROFILE_DRAW=1`, at the calibration screen, on `main` and on the branch: - `Graphics::Draw` time per draw packet (`[draw]` line) - the `recorded store` sync count and wait in the `[recorder]` line - `keys proven: N sampled, N storage` in the `[rescache]` line - if the frame time is unchanged, a stack sample of the graphics worker, to see whether it still reaches `SyncThrough` from `WaitForKeyWriters` I tried Dreaming Sarah (PPSA02929). It has no DCC surfaces (0 key proofs, no `[dcc]` lines), so it says nothing about this change.
ThatsLeo commented 2026-10-11 20:26:39 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by ThatsLeo on 2026-10-11T20:26:39Z.


@santhoshkumar-dev measured on Stray (PPSA02101 v01.002) at the brightness calibration screen. Intel Arc (Meteor Lake, Mesa 26.2.3 ANV), Fedora 44, Release, APS5_PROFILE_DRAW=1.

Main alone doesn't reach that screen, so both arms use the set from #2749 on main 8ec0e131. The only difference between the arms is your d1302782f, which cherry-picks cleanly. Each run is 180 s; the averages cover 100 to 180 s, by which point the screen is steady.

Run Graphics::Draw per packet recorded store syncs per 10 s Their wait per 10 s Presents per 10 s Keys proven per 10 s (sampled / storage)
without, run 1 8.33 ms 21.5 8.43 s 21.9 799 / 84
with, run 1 8.60 ms 41.3 8.47 s 21.0 841 / 82
with, run 2 7.98 ms 41.9 7.64 s 21.0 842 / 82

Frame time is unchanged: about 2.1 FPS either way. With the branch there are twice as many syncs, each about half as long, and the total wait is the same.

A stack sample of the graphics worker at 150 s still shows the same path: StorageTexture::Refresh → ProvedKeys → WaitForKeyWriters → Recorder::SyncThrough. That fits what you expected: in Stray the pending writer is not a fill, so the new fill path can't answer, and asking WaitForKeyWriters for every DCC surface adds syncs rather than removing them.

Two more baseline runs (without the branch) froze early: the log went silent at 62 and 93 s, with every thread waiting and the driver idle. One more baseline ran with a stall and is left out of the table. None of the runs with the branch froze, so I take this as an intermittent Stray startup hang that the branch doesn't cause, but it's worth knowing if you try it.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6113385320 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3505#issuecomment-6113385320). Originally posted by [ThatsLeo](https://github.com/ThatsLeo) on 2026-10-11T20:26:39Z. --- @santhoshkumar-dev measured on Stray (PPSA02101 v01.002) at the brightness calibration screen. Intel Arc (Meteor Lake, Mesa 26.2.3 ANV), Fedora 44, Release, `APS5_PROFILE_DRAW=1`. Main alone doesn't reach that screen, so both arms use the set from #2749 on `main` `8ec0e131`. The only difference between the arms is your `d1302782f`, which cherry-picks cleanly. Each run is 180 s; the averages cover 100 to 180 s, by which point the screen is steady. | Run | Graphics::Draw per packet | `recorded store` syncs per 10 s | Their wait per 10 s | Presents per 10 s | Keys proven per 10 s (sampled / storage) | |---|---|---|---|---|---| | without, run 1 | 8.33 ms | 21.5 | 8.43 s | 21.9 | 799 / 84 | | with, run 1 | 8.60 ms | 41.3 | 8.47 s | 21.0 | 841 / 82 | | with, run 2 | 7.98 ms | 41.9 | 7.64 s | 21.0 | 842 / 82 | Frame time is unchanged: about 2.1 FPS either way. With the branch there are twice as many syncs, each about half as long, and the total wait is the same. A stack sample of the graphics worker at 150 s still shows the same path: `StorageTexture::Refresh` → `ProvedKeys` → `WaitForKeyWriters` → `Recorder::SyncThrough`. That fits what you expected: in Stray the pending writer is not a fill, so the new fill path can't answer, and asking `WaitForKeyWriters` for every DCC surface adds syncs rather than removing them. Two more baseline runs (without the branch) froze early: the log went silent at 62 and 93 s, with every thread waiting and the driver idle. One more baseline ran with a stall and is left out of the table. None of the runs with the branch froze, so I take this as an intermittent Stray startup hang that the branch doesn't cause, but it's worth knowing if you try it. AI-assisted: yes.
santhoshkumar-dev commented 2026-10-11 20:33:34 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by santhoshkumar-dev on 2026-10-11T20:33:34Z.


@ThatsLeo thank you, that settles it. The branch does not help Stray, and asking WaitForKeyWriters for every DCC surface doubles the syncs, so I won't open a PR for it in this form. Thanks also for the note on the baseline freezes.

Fixing this needs to know what the pending writer over the keys is. Could you find out?

  • With APS5_TRACE_DCC_KEYS=1, is there any [dcc-keys] title fills keys 0x... line whose range covers the dccAddress of the surface being refreshed? The [dcc-keys] refresh 0x... lines name the surface. If no fill covers it, the writer is not a fill.
  • If it's not a fill, which packet writes that range: a compute dispatch (which shader), a draw whose color target has DCC, or a DMA/copy? And does it rewrite the whole key range or part of it, once per frame or more?
  • The surface's format and size would help too, to see whether the keys could be decided from the shader that writes them.

If it's easier, I can push a diagnostic commit to the branch that prints the pending writes over the key range (range, fill value or unknown, record order) at the SyncThrough in WaitForKeyWriters.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6113450687 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3505#issuecomment-6113450687). Originally posted by [santhoshkumar-dev](https://github.com/santhoshkumar-dev) on 2026-10-11T20:33:34Z. --- @ThatsLeo thank you, that settles it. The branch does not help Stray, and asking `WaitForKeyWriters` for every DCC surface doubles the syncs, so I won't open a PR for it in this form. Thanks also for the note on the baseline freezes. Fixing this needs to know what the pending writer over the keys is. Could you find out? - With `APS5_TRACE_DCC_KEYS=1`, is there any `[dcc-keys] title fills keys 0x...` line whose range covers the `dccAddress` of the surface being refreshed? The `[dcc-keys] refresh 0x...` lines name the surface. If no fill covers it, the writer is not a fill. - If it's not a fill, which packet writes that range: a compute dispatch (which shader), a draw whose color target has DCC, or a DMA/copy? And does it rewrite the whole key range or part of it, once per frame or more? - The surface's format and size would help too, to see whether the keys could be decided from the shader that writes them. If it's easier, I can push a diagnostic commit to the branch that prints the pending writes over the key range (range, fill value or unknown, record order) at the `SyncThrough` in `WaitForKeyWriters`.
ThatsLeo commented 2026-10-11 21:33:54 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by ThatsLeo on 2026-10-11T21:33:54Z.


@santhoshkumar-dev found it. I added a local diagnostic (not for upstream): every call that notes a pending write records who made it, and the sync in WaitForKeyWriters prints the noted writers that cover the key range. This is Stray at the calibration screen, on the same set as before, with APS5_TRACE_DCC_KEYS=1, over 150 s.

Surface. Every sync is for one surface:

  • 0x204fa60000, 3840×2160, guest format 71 (R16G16B16A16_SFLOAT on the host);
  • tile mode 7, 1 mip, 1 layer;
  • keys 0x2029780000+0x3fc00.

Writers. No title fills keys line appears at all, so the writer is not a fill packet. Each frame, in this order:

  1. The driver's own uncompressed key store: uncompressed store by first write (?) for surface 0x204fa60000, which fills the keys with 0xff.
  2. A compute dispatch of shader 0x200bc20000, noted over 0x2029780000+0x48000. That is the whole key range plus 0x8400 bytes past it.
  3. The storage refresh of the surface, which waits on that dispatch. The trace then reports refresh 0x204fa60000+0x3fc0000 keys uncompressed -> 0001.

This happens once per frame: 83 stores against 85 presents over 40 s.

The shader is a fill done in compute:

v_lshl_add_u32  v0, s8, 6, v0        ; global index = group * 64 + lane
s_load_dword    vcc_lo, s[4:5], 0    ; one dword read from memory
s_waitcnt       lgkmcnt(0)
v_mov_b32       v1, vcc_lo
buffer_store_dword v1, v0, s[0:3], 0 idxen
s_endpgm

It writes the same 32-bit value, loaded through the pointer in s[4:5], to every dword of the buffer. That's why the recorder sees an unknown write. The value sits in guest memory when the dispatch is recorded, and the range is the dispatch size × 64 × 4 bytes (here, presumably clamped by the buffer descriptor). So the dispatch could be recognized as a uniform fill: read the dword at dispatch time, when no pending write covers it, then note NotePendingFill or the key value instead of an unknown write. I haven't checked what the dword holds. The -> 0001 after the refresh suggests a fast-clear key value.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6114021492 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3505#issuecomment-6114021492). Originally posted by [ThatsLeo](https://github.com/ThatsLeo) on 2026-10-11T21:33:54Z. --- @santhoshkumar-dev found it. I added a local diagnostic (not for upstream): every call that notes a pending write records who made it, and the sync in `WaitForKeyWriters` prints the noted writers that cover the key range. This is Stray at the calibration screen, on the same set as before, with `APS5_TRACE_DCC_KEYS=1`, over 150 s. **Surface.** Every sync is for one surface: - `0x204fa60000`, 3840×2160, guest format 71 (`R16G16B16A16_SFLOAT` on the host); - tile mode 7, 1 mip, 1 layer; - keys `0x2029780000+0x3fc00`. **Writers.** No `title fills keys` line appears at all, so the writer is not a fill packet. Each frame, in this order: 1. The driver's own uncompressed key store: `uncompressed store by first write (?) for surface 0x204fa60000`, which fills the keys with 0xff. 2. A compute dispatch of shader `0x200bc20000`, noted over `0x2029780000+0x48000`. That is the whole key range plus 0x8400 bytes past it. 3. The storage refresh of the surface, which waits on that dispatch. The trace then reports `refresh 0x204fa60000+0x3fc0000 keys uncompressed -> 0001`. This happens once per frame: 83 stores against 85 presents over 40 s. **The shader is a fill done in compute:** ``` v_lshl_add_u32 v0, s8, 6, v0 ; global index = group * 64 + lane s_load_dword vcc_lo, s[4:5], 0 ; one dword read from memory s_waitcnt lgkmcnt(0) v_mov_b32 v1, vcc_lo buffer_store_dword v1, v0, s[0:3], 0 idxen s_endpgm ``` It writes the same 32-bit value, loaded through the pointer in `s[4:5]`, to every dword of the buffer. That's why the recorder sees an unknown write. The value sits in guest memory when the dispatch is recorded, and the range is the dispatch size × 64 × 4 bytes (here, presumably clamped by the buffer descriptor). So the dispatch could be recognized as a uniform fill: read the dword at dispatch time, when no pending write covers it, then note `NotePendingFill` or the key value instead of an unknown write. I haven't checked what the dword holds. The `-> 0001` after the refresh suggests a fast-clear key value. AI-assisted: yes.
santhoshkumar-dev commented 2026-10-11 22:08:48 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by santhoshkumar-dev on 2026-10-11T22:08:48Z.


@ThatsLeo great find, thank you. That gives a concrete fix:

  1. Recognize this kernel as a buffer fill, as BufferFill.cpp already does for three other fill kernels: read the dword behind s[4:5] when the dispatch is recorded (only when no pending GPU write covers it, otherwise it keeps running as a shader) and go through fillBuffer. The recorder then notes a fill of 0x40 over the keys instead of an unknown write.
  2. On main that alone would still sync, because PendingFillsLeaveUncompressed only answers when the fill leaves the keys uncompressed and 0001 doesn't. The branch's OpenFillValue answers it from the fill. I'll also restore the uploadedKeys == Uncompressed condition in ProvedKeys Edit: I'm keeping the branch's ProvedKeys as it is. Without it, a surface whose keys were uploaded as a clear code reads its key bytes while an unknown writer is still pending on the GPU, so the doubled syncs you measured were mostly that read waiting for the writer. Once this kernel is a known fill, OpenFillValue should answer both cases without a sync.

To match the kernel exactly I need the raw values rather than the disassembly (the existing fill kernels use buffer_store_format_x, so the opcode matters):

  • the code dwords of shader 0x200bc20000, through s_endpgm
  • the user data words (s[0:7], or however many there are: the V# and the pointer)
  • the dispatch packet (DISPATCH_DIRECT dimensions and initiator), and the compute stage's thread counts and TGID enable
  • the dword at s[4:5] (I expect 0x40404040), and whether any GPU work writes that address before the dispatch

I'll push the kernel recognizer to the same branch and ping you when it's ready to measure.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6114390927 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3505#issuecomment-6114390927). Originally posted by [santhoshkumar-dev](https://github.com/santhoshkumar-dev) on 2026-10-11T22:08:48Z. --- @ThatsLeo great find, thank you. That gives a concrete fix: 1. Recognize this kernel as a buffer fill, as `BufferFill.cpp` already does for three other fill kernels: read the dword behind `s[4:5]` when the dispatch is recorded (only when no pending GPU write covers it, otherwise it keeps running as a shader) and go through `fillBuffer`. The recorder then notes a fill of `0x40` over the keys instead of an unknown write. 2. On `main` that alone would still sync, because `PendingFillsLeaveUncompressed` only answers when the fill leaves the keys uncompressed and `0001` doesn't. The branch's `OpenFillValue` answers it from the fill. ~~I'll also restore the `uploadedKeys == Uncompressed` condition in `ProvedKeys`~~ **Edit:** I'm keeping the branch's `ProvedKeys` as it is. Without it, a surface whose keys were uploaded as a clear code reads its key bytes while an unknown writer is still pending on the GPU, so the doubled syncs you measured were mostly that read waiting for the writer. Once this kernel is a known fill, `OpenFillValue` should answer both cases without a sync. To match the kernel exactly I need the raw values rather than the disassembly (the existing fill kernels use `buffer_store_format_x`, so the opcode matters): - the code dwords of shader `0x200bc20000`, through `s_endpgm` - the user data words (`s[0:7]`, or however many there are: the V# and the pointer) - the dispatch packet (`DISPATCH_DIRECT` dimensions and initiator), and the compute stage's thread counts and TGID enable - the dword at `s[4:5]` (I expect `0x40404040`), and whether any GPU work writes that address before the dispatch I'll push the kernel recognizer to the same branch and ping you when it's ready to measure.
oneandonlydean commented 2026-10-14 02:45:26 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T02:45:26Z.


Status: step 1 of the fix above is on main with #4603 (the dword-fill kernel is taken as a buffer fill). #5380 (a dword fill of any inline constant) and #5497 (DCC keys behind the pattern-fill fast clear) cover the rest and are still open.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6159731304 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3505#issuecomment-6159731304). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-14T02:45:26Z. --- Status: step 1 of the fix above is on main with #4603 (the dword-fill kernel is taken as a buffer fill). #5380 (a dword fill of any inline constant) and #5497 (DCC keys behind the pattern-fill fast clear) cover the rest and are still open.
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5#3505
No description provided.