AGC: a buffer whose range ends a few KiB into a stale depth plane stores the whole plane on every reused draw (PPSA31162 runs 3-10x slower) #8840

Closed
opened 2026-10-21 02:13:20 +00:00 by milescoviello · 10 comments
milescoviello commented 2026-10-21 02:13:20 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-21T02:13:20Z.


What happens

In Super Meat Boy 3D (PPSA31162), level 1-1 runs at one of a few different speeds on the same build, chosen per run. In the slow runs, one small buffer that most draws bind has a range that ends a few KiB inside a 3840x2160 depth plane. Every reuse of those draws then stores the whole 31.9 MiB plane into guest memory, about 240 times per frame.

Same machine, same main libs, same scripted route, 60 s measured in the level:

run presents per 10 s draw committer per draw depth plane store write-backs per 10 s
fast 30 to 42 27 to 35 us 306 to 455 (2.2 to 6.7 GB)
slow 5 to 9 200 to 330 us 1,547 to 1,837 (48 to 57 GB)

Twelve runs across main eea640a5bf, main a806c69bfe and #8756 split into these groups at random; none of the three builds decides it. The figures come from the [draw] pipelined and [storage] uploads by path lines. In a slow run's profile, the queue worker spends about 11 % of its samples in ShaderResources::Revalidate → FlushDepthPlanes → StorageTexture::FlushPending / writeBack.

Where it comes from

A temporary counter in FlushDepthPlanes, plus a print in Revalidate's directRegions loop, shows the slow runs' stores coming from one direct region:

[depthbuf] revalidate flush #301: region 308db10000-308db20c5c, 12 direct regions, plane 308db20000+1fe0000
[depthbuf]   buffer 308db10000+10c5c (ends 308db20c5c) role 7 written 0 adjustment 0  <- reaches the plane
[depthdiag] 5 s: 819 depth plane stores, 3 request kinds
  • The buffer is read-only ShaderData. Its base is 64 KiB-aligned, and its size changes by tens of bytes between frames and runs: 0x10c5c, 0x10c74, 0x10c8c, 0x10cb4. It looks like per-frame data whose descriptor range runs about 3 KiB past its 64 KiB block.
  • In slow runs the title places a 3840x2160 D32 plane (64 KiB Z swizzle, 0x1fe0000 bytes) right after that block. The buffer's last 0xc5c to 0xcb4 bytes then fall inside the plane's first 64 KiB block. In fast runs the plane sits elsewhere, and these stores don't happen.
  • Each depth-writing draw marks the plane stale. Each Revalidate of a reused build then calls FlushDepthPlanes over this region. That copies the whole depth image into the mirror storage image and writes all 510 blocks of the plane back, for a 3 KiB overlap. In the slow runs this happens about 900 times per 5 s.

I can't tell whether the shader ever reads those last 3 KiB. The descriptor says it may.

Why it isn't simply skipped

#7154 (@XairRrR) added these flushes so a buffer read of a depth plane sees the drawn depth. Uncharted (#4001) copies its depth plane through a raw buffer compute and needs that. So a buffer that overlaps a stale plane has to see current depth there, and the fix belongs in how much gets stored, not in whether it does.

Possible directions

  1. Store only the 64 KiB Z_X blocks that overlap the requested range, and keep the rest of the plane stale. This buffer needs one block of 510. Under SW_64KB_Z_X each block is a fixed 2D tile of the image, so the copy and the write-back can be limited to those tiles.
  2. Order the store before the reading draw on the GPU instead of finishing it from the CPU (if the slow runs' cost is mostly the wait rather than the bytes). I haven't separated the two yet.

@XairRrR, does (1) fit how you meant the stale-plane ranges to work, or would you rather handle this yourself? I'm happy to prototype it and measure the slow runs.

Environment

Ubuntu 24.04 (Linux 6.8), NVIDIA RTX 4070 Ti (595.99.02), GCC 13.3, Release libs. The title is Super Meat Boy 3D (PPSA31162), scripted from its map-load log lines.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5953029487 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/8840). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-21T02:13:20Z. --- ### What happens In Super Meat Boy 3D (PPSA31162), level 1-1 runs at one of a few different speeds on the same build, chosen per run. In the slow runs, one small buffer that most draws bind has a range that ends a few KiB inside a 3840x2160 depth plane. Every reuse of those draws then stores the whole 31.9 MiB plane into guest memory, about 240 times per frame. Same machine, same `main` libs, same scripted route, 60 s measured in the level: | run | presents per 10 s | draw committer per draw | `depth plane store` write-backs per 10 s | |---|---|---|---| | fast | 30 to 42 | 27 to 35 us | 306 to 455 (2.2 to 6.7 GB) | | slow | 5 to 9 | 200 to 330 us | 1,547 to 1,837 (48 to 57 GB) | Twelve runs across `main` eea640a5bf, `main` a806c69bfe and #8756 split into these groups at random; none of the three builds decides it. The figures come from the `[draw] pipelined` and `[storage] uploads by path` lines. In a slow run's profile, the queue worker spends about 11 % of its samples in `ShaderResources::Revalidate` → `FlushDepthPlanes` → `StorageTexture::FlushPending` / `writeBack`. ### Where it comes from A temporary counter in `FlushDepthPlanes`, plus a print in `Revalidate`'s `directRegions` loop, shows the slow runs' stores coming from one direct region: ``` [depthbuf] revalidate flush #301: region 308db10000-308db20c5c, 12 direct regions, plane 308db20000+1fe0000 [depthbuf] buffer 308db10000+10c5c (ends 308db20c5c) role 7 written 0 adjustment 0 <- reaches the plane [depthdiag] 5 s: 819 depth plane stores, 3 request kinds ``` - The buffer is read-only `ShaderData`. Its base is 64 KiB-aligned, and its size changes by tens of bytes between frames and runs: 0x10c5c, 0x10c74, 0x10c8c, 0x10cb4. It looks like per-frame data whose descriptor range runs about 3 KiB past its 64 KiB block. - In slow runs the title places a 3840x2160 D32 plane (64 KiB Z swizzle, 0x1fe0000 bytes) right after that block. The buffer's last 0xc5c to 0xcb4 bytes then fall inside the plane's first 64 KiB block. In fast runs the plane sits elsewhere, and these stores don't happen. - Each depth-writing draw marks the plane stale. Each `Revalidate` of a reused build then calls `FlushDepthPlanes` over this region. That copies the whole depth image into the mirror storage image and writes all 510 blocks of the plane back, for a 3 KiB overlap. In the slow runs this happens about 900 times per 5 s. I can't tell whether the shader ever reads those last 3 KiB. The descriptor says it may. ### Why it isn't simply skipped #7154 (@XairRrR) added these flushes so a buffer read of a depth plane sees the drawn depth. Uncharted (#4001) copies its depth plane through a raw buffer compute and needs that. So a buffer that overlaps a stale plane has to see current depth there, and the fix belongs in how much gets stored, not in whether it does. ### Possible directions 1. Store only the 64 KiB Z_X blocks that overlap the requested range, and keep the rest of the plane stale. This buffer needs one block of 510. Under `SW_64KB_Z_X` each block is a fixed 2D tile of the image, so the copy and the write-back can be limited to those tiles. 2. Order the store before the reading draw on the GPU instead of finishing it from the CPU (if the slow runs' cost is mostly the wait rather than the bytes). I haven't separated the two yet. @XairRrR, does (1) fit how you meant the stale-plane ranges to work, or would you rather handle this yourself? I'm happy to prototype it and measure the slow runs. ### Environment Ubuntu 24.04 (Linux 6.8), NVIDIA RTX 4070 Ti (595.99.02), GCC 13.3, Release libs. The title is Super Meat Boy 3D (PPSA31162), scripted from its map-load log lines. AI-assisted: yes (Claude Code)
milescoviello commented 2026-10-21 02:33:34 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-21T02:33:34Z.


A check on how much of the slow mode these stores explain. A diagnostic switch makes Revalidate's directRegions loop skip FlushDepthPlanes, keeping its CompletePendingCpuWrites. Same level, same machine, same main a806c69bfe plus the diagnostic, four runs:

run presents per 10 s committer per draw depth plane store write-backs per 10 s
1 33 to 40 25 to 27 us 396
2 37 to 40 29 to 30 us 439
3 39 to 42 21 to 22 us 399
4 34 to 38 25 to 26 us 340

All four land in the fast group. Without the switch, 7 of the 12 earlier runs were slow, so four fast runs in a row by chance is unlikely (about 3 %). The remaining 340 to 440 stores per 10 s come from the other flush sites, as in the fast runs. So in this title the slow mode is these stores and nothing else.

This switch is only a measurement. Skipping the flush breaks the coherence #7154 added for buffer reads of a plane, and it isn't a proposal.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6306562065 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/8840#issuecomment-6306562065). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-21T02:33:34Z. --- A check on how much of the slow mode these stores explain. A diagnostic switch makes `Revalidate`'s `directRegions` loop skip `FlushDepthPlanes`, keeping its `CompletePendingCpuWrites`. Same level, same machine, same `main` a806c69bfe plus the diagnostic, four runs: | run | presents per 10 s | committer per draw | `depth plane store` write-backs per 10 s | |---|---|---|---| | 1 | 33 to 40 | 25 to 27 us | 396 | | 2 | 37 to 40 | 29 to 30 us | 439 | | 3 | 39 to 42 | 21 to 22 us | 399 | | 4 | 34 to 38 | 25 to 26 us | 340 | All four land in the fast group. Without the switch, 7 of the 12 earlier runs were slow, so four fast runs in a row by chance is unlikely (about 3 %). The remaining 340 to 440 stores per 10 s come from the other flush sites, as in the fast runs. So in this title the slow mode is these stores and nothing else. This switch is only a measurement. Skipping the flush breaks the coherence #7154 added for buffer reads of a plane, and it isn't a proposal. AI-assisted: yes (Claude Code)
MarcZX10 commented 2026-10-21 03:34:25 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T03:34:25Z.


I traced the current path through FlushDepthPlanes and StorageTexture::FlushPending. There is a useful 64 KiB range-writeback mechanism in StorageTexture, but changing only the FlushPending(plane, fullPlaneBytes) call to use the requested range is not sufficient: StoreDepthPlane still copies the whole attachment into the mirror, and MarkWholeWritten() marks every unit pending. More importantly, DepthSurface::SyncFromMemory() has one plane-wide syncedGeneration; after a partial flush, a guest write to one untouched unit can trigger a whole-plane refresh and replace depth data that is still GPU-stale.

A safe partial flush appears to need all of these together: per-64 KiB stale tracking for the plane, a way to copy only selected Z_X tiles into the mirror (including pipe-bank XOR and edge tiles), and per-unit guest/GPU generation precedence so untouched stale tiles survive intervening guest writes. The stale units also need to remain registered across partial flushes, with pending state updated only after successful command recording. Without the tile-address mapping and generation work, a range-limited writeback risks silently returning stale mirror bytes or losing newer depth data. This is a source audit; I did not run a title or claim a fix.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6307378149 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/8840#issuecomment-6307378149). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-21T03:34:25Z. --- I traced the current path through `FlushDepthPlanes` and `StorageTexture::FlushPending`. There is a useful 64 KiB range-writeback mechanism in `StorageTexture`, but changing only the `FlushPending(plane, fullPlaneBytes)` call to use the requested range is not sufficient: `StoreDepthPlane` still copies the whole attachment into the mirror, and `MarkWholeWritten()` marks every unit pending. More importantly, `DepthSurface::SyncFromMemory()` has one plane-wide `syncedGeneration`; after a partial flush, a guest write to one untouched unit can trigger a whole-plane refresh and replace depth data that is still GPU-stale. A safe partial flush appears to need all of these together: per-64 KiB stale tracking for the plane, a way to copy only selected Z_X tiles into the mirror (including pipe-bank XOR and edge tiles), and per-unit guest/GPU generation precedence so untouched stale tiles survive intervening guest writes. The stale units also need to remain registered across partial flushes, with pending state updated only after successful command recording. Without the tile-address mapping and generation work, a range-limited writeback risks silently returning stale mirror bytes or losing newer depth data. This is a source audit; I did not run a title or claim a fix.
milescoviello commented 2026-10-21 03:46:47 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-21T03:46:47Z.


@MarcZX10 thanks, I agree. The plane-wide syncedGeneration is what makes a range-limited write-back unsafe on its own. After one, a guest write to an untouched unit would reload the whole plane over depth that is still only on the GPU. So option (1) needs your three parts together, and the per-unit generation precedence is the hard one.

Before anyone picks a direction, I'll measure where a slow run's time actually goes: the whole-image copy into the mirror, the 31.9 MiB write-back, or the wait for the GPU before it. If it's mostly the wait, option (2) (ordering the store before the reading draw on the GPU) may be the smaller change. I'll post the split here.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6307537689 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/8840#issuecomment-6307537689). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-21T03:46:47Z. --- @MarcZX10 thanks, I agree. The plane-wide `syncedGeneration` is what makes a range-limited write-back unsafe on its own. After one, a guest write to an untouched unit would reload the whole plane over depth that is still only on the GPU. So option (1) needs your three parts together, and the per-unit generation precedence is the hard one. Before anyone picks a direction, I'll measure where a slow run's time actually goes: the whole-image copy into the mirror, the 31.9 MiB write-back, or the wait for the GPU before it. If it's mostly the wait, option (2) (ordering the store before the reading draw on the GPU) may be the smaller change. I'll post the split here. AI-assisted: yes (Claude Code)
milescoviello commented 2026-10-21 03:56:07 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-21T03:56:07Z.


The split, from timers around the three parts of FlushDepthPlanes. Same level and machine, main a806c69bfe plus the diagnostics. The slow run:

part, per 5 s slow run (about 1,200 stores) per store
the locked section: the SyncFromMemory check and recording StoreDepthPlane's copy into the mirror 8.0 to 11.5 ms about 8 us
MarkWholeWritten 10.5 to 13.3 ms about 10 us
StorageTexture::FlushPending over the plane 3,714 to 3,992 ms about 3.1 ms

So nearly all the cost is the write-back of the whole 31.9 MiB plane, about 3.1 ms each time, which is close to 10 GB/s whether it's a copy or a wait. Recording the mirror copy is negligible. That calling thread spends about 75 % of its time in these write-backs. In the fast run of the same pair, 22 stores per 5 s took 5.4 ms in all.

This points at the bytes written back rather than the copy into the mirror. Limiting the write-back to the 64 KiB units a read overlaps would cut it by up to 510 times here (one unit in this title). It still needs the per-unit stale tracking and generation precedence you described, so that the units not written back keep the GPU's depth. I haven't split FlushPending itself into its GPU wait and its copy.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6307650550 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/8840#issuecomment-6307650550). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-21T03:56:07Z. --- The split, from timers around the three parts of `FlushDepthPlanes`. Same level and machine, `main` a806c69bfe plus the diagnostics. The slow run: | part, per 5 s | slow run (about 1,200 stores) | per store | |---|---|---| | the locked section: the `SyncFromMemory` check and recording `StoreDepthPlane`'s copy into the mirror | 8.0 to 11.5 ms | about 8 us | | `MarkWholeWritten` | 10.5 to 13.3 ms | about 10 us | | `StorageTexture::FlushPending` over the plane | 3,714 to 3,992 ms | about 3.1 ms | So nearly all the cost is the write-back of the whole 31.9 MiB plane, about 3.1 ms each time, which is close to 10 GB/s whether it's a copy or a wait. Recording the mirror copy is negligible. That calling thread spends about 75 % of its time in these write-backs. In the fast run of the same pair, 22 stores per 5 s took 5.4 ms in all. This points at the bytes written back rather than the copy into the mirror. Limiting the write-back to the 64 KiB units a read overlaps would cut it by up to 510 times here (one unit in this title). It still needs the per-unit stale tracking and generation precedence you described, so that the units not written back keep the GPU's depth. I haven't split `FlushPending` itself into its GPU wait and its copy. AI-assisted: yes (Claude Code)
MarcZX10 commented 2026-10-21 05:28:35 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T05:28:35Z.


Thanks, that split makes the optimization target much clearer: the 31.9 MiB FlushPending writeback accounts for nearly all of the slow-run time, while the CPU-side mirror copy and bookkeeping are small. The range-limited writeback still needs the per-unit stale state and generation precedence we discussed; otherwise an untouched GPU-stale tile can be replaced after a guest write. I agree the next useful evidence is separating wait time from bytes copied inside FlushPending, before choosing between range-limited stores and GPU ordering.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6308802500 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/8840#issuecomment-6308802500). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-21T05:28:35Z. --- Thanks, that split makes the optimization target much clearer: the 31.9 MiB `FlushPending` writeback accounts for nearly all of the slow-run time, while the CPU-side mirror copy and bookkeeping are small. The range-limited writeback still needs the per-unit stale state and generation precedence we discussed; otherwise an untouched GPU-stale tile can be replaced after a guest write. I agree the next useful evidence is separating wait time from bytes copied inside `FlushPending`, before choosing between range-limited stores and GPU ordering.
milescoviello commented 2026-10-21 06:49:27 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-21T06:49:27Z.


The split inside StorageTexture::FlushPending, for the "depth plane store" calls only. These are timers around its parts, plus two inside the write-back paths: buffer allocation and SubmitAndWait. Same level and machine, main a806c69bfe plus the diagnostics, three runs. Two came up in the slow mode, one in the fast mode.

part, per 5 s slow runs (850 to 1,140 stores) fast run (21 stores)
pending scan 2.9 to 4.1 ms 0.1 ms
GPU mutex wait 0.1 ms 0.0 ms
recorder wait before the store: Recorder::Sync() or FinishUpTo() 3,828 to 4,094 ms, 824 to 1,117 syncs and 9 to 17 finish-ups 0.0 ms, none
write-back (writeBack over the flushed images) 75 to 101 ms 2.5 to 2.9 ms
publish 19 to 25 ms 0.4 to 0.5 ms

Inside the write-back, every store took the GPU-direct path: 1,159 to 1,170 direct write-backs and none through the CPU per 5 s in the first slow run. It is recorded behind the open batch with no CPU wait. Buffer allocation is 0.1 ms per 5 s and SubmitAndWait 0 ms. The bytes still move on the GPU: 26,966 to 36,401 MiB (26.3 to 35.5 GiB) stored per 5 s in the slow runs, about 31.9 MiB per store, against 669 to 701 MiB in the fast run.

So the CPU side of the 3.1 ms isn't copying. It's about 3.4 to 4.7 ms per wait in Recorder::Sync(), which submits the open batch and waits for the GPU because that batch has a pending write over the plane. What the GPU runs during those waits includes the earlier stores' whole-plane retiles.

I haven't checked which recorded write each sync waits on. One candidate is in the code: the direct path ends with recorder->NotePendingWrite(firstStored, ...) over the stored span. That leaves the plane with a pending writer in the open batch, so the next store of the same plane in that batch would take the Sync() branch even with no draw in between. If that's what happens here, a range-limited store would cut the GPU bytes, but each store would still wait for the batch. Ordering the store on the GPU, or not counting the write-back's own pending write as a reason to sync, would remove the waits. I can count which writer the syncs see (a draw or the previous write-back) if that helps decide.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6309922662 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/8840#issuecomment-6309922662). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-21T06:49:27Z. --- The split inside `StorageTexture::FlushPending`, for the "depth plane store" calls only. These are timers around its parts, plus two inside the write-back paths: buffer allocation and `SubmitAndWait`. Same level and machine, `main` a806c69bfe plus the diagnostics, three runs. Two came up in the slow mode, one in the fast mode. | part, per 5 s | slow runs (850 to 1,140 stores) | fast run (21 stores) | |---|---|---| | pending scan | 2.9 to 4.1 ms | 0.1 ms | | GPU mutex wait | 0.1 ms | 0.0 ms | | recorder wait before the store: `Recorder::Sync()` or `FinishUpTo()` | **3,828 to 4,094 ms**, 824 to 1,117 syncs and 9 to 17 finish-ups | 0.0 ms, none | | write-back (`writeBack` over the flushed images) | 75 to 101 ms | 2.5 to 2.9 ms | | publish | 19 to 25 ms | 0.4 to 0.5 ms | Inside the write-back, every store took the GPU-direct path: 1,159 to 1,170 direct write-backs and none through the CPU per 5 s in the first slow run. It is recorded behind the open batch with no CPU wait. Buffer allocation is 0.1 ms per 5 s and `SubmitAndWait` 0 ms. The bytes still move on the GPU: 26,966 to 36,401 MiB (26.3 to 35.5 GiB) stored per 5 s in the slow runs, about 31.9 MiB per store, against 669 to 701 MiB in the fast run. So the CPU side of the 3.1 ms isn't copying. It's about 3.4 to 4.7 ms per wait in `Recorder::Sync()`, which submits the open batch and waits for the GPU because that batch has a pending write over the plane. What the GPU runs during those waits includes the earlier stores' whole-plane retiles. I haven't checked which recorded write each sync waits on. One candidate is in the code: the direct path ends with `recorder->NotePendingWrite(firstStored, ...)` over the stored span. That leaves the plane with a pending writer in the open batch, so the next store of the same plane in that batch would take the `Sync()` branch even with no draw in between. If that's what happens here, a range-limited store would cut the GPU bytes, but each store would still wait for the batch. Ordering the store on the GPU, or not counting the write-back's own pending write as a reason to sync, would remove the waits. I can count which writer the syncs see (a draw or the previous write-back) if that helps decide. AI-assisted: yes (Claude Code)
milescoviello commented 2026-10-21 07:22:39 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-21T07:22:39Z.


I counted which recorded write each of those syncs waits on. For the depth plane stores, the diagnostics tag every pending-write note over a plane: recorder entry, caller, and whether it came from the store's write-back, the StoreDepthPlane mirror copy, or the publish that ends FlushPending. When FlushPending takes the Sync() branch, it looks at the last note over the plane. Same level, slow mode. I added the tags over five runs, and each run's counts agreed with the earlier ones. The last run tags the publish separately, and its three 5 s windows give:

the open batch's last write over the plane syncs per 5 s
the previous store's write-back (writeBack) 0
the StoreDepthPlane copy into the mirror 0
a draw's or dispatch's storage write, a fill, a copy, or another image's write-back 0
the previous depth store's own publish: PublishShadow(address, bytes, scope, ...) at the end of FlushPending, noted through UnitShadow.cpp's NotePendingWrites 1,038 to 1,051 (all of them)

So the chain is store, publish, then the next store of the same plane. Each depth plane store ends by recording the publish of the plane's unit shadows into the import. The next store of that plane finds the publish as the open batch's pending writer and waits in Sync() (3.4 to 4.7 ms) for the GPU to finish it, then records its own retile and publish behind it. Nothing else wrote the plane in between, and no CPU write needed the bytes. The next store is itself recorded on the GPU after the publish, so the CPU wait doesn't order anything that the batch wouldn't already order.

My earlier guess, NotePendingWrite at the end of the direct write-back path, was wrong: none of the syncs wait on it.

That points at the GPU-ordering option rather than range-limited stores: let a depth plane store that will take the GPU-direct path skip the Sync() when the open writer over its range is only an earlier store or publish of the same plane. I haven't tried it yet. I can prototype that and check it against the depth and storage tests, unless you see a reason the CPU must observe the published bytes first, such as the keep-blocks decision or compareUntracked reading guest memory.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6310447038 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/8840#issuecomment-6310447038). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-21T07:22:39Z. --- I counted which recorded write each of those syncs waits on. For the depth plane stores, the diagnostics tag every pending-write note over a plane: recorder entry, caller, and whether it came from the store's write-back, the `StoreDepthPlane` mirror copy, or the publish that ends `FlushPending`. When `FlushPending` takes the `Sync()` branch, it looks at the last note over the plane. Same level, slow mode. I added the tags over five runs, and each run's counts agreed with the earlier ones. The last run tags the publish separately, and its three 5 s windows give: | the open batch's last write over the plane | syncs per 5 s | |---|---| | the previous store's write-back (`writeBack`) | 0 | | the `StoreDepthPlane` copy into the mirror | 0 | | a draw's or dispatch's storage write, a fill, a copy, or another image's write-back | 0 | | **the previous depth store's own publish**: `PublishShadow(address, bytes, scope, ...)` at the end of `FlushPending`, noted through `UnitShadow.cpp`'s `NotePendingWrites` | **1,038 to 1,051** (all of them) | So the chain is store, publish, then the next store of the same plane. Each depth plane store ends by recording the publish of the plane's unit shadows into the import. The next store of that plane finds the publish as the open batch's pending writer and waits in `Sync()` (3.4 to 4.7 ms) for the GPU to finish it, then records its own retile and publish behind it. Nothing else wrote the plane in between, and no CPU write needed the bytes. The next store is itself recorded on the GPU after the publish, so the CPU wait doesn't order anything that the batch wouldn't already order. My earlier guess, `NotePendingWrite` at the end of the direct write-back path, was wrong: none of the syncs wait on it. That points at the GPU-ordering option rather than range-limited stores: let a depth plane store that will take the GPU-direct path skip the `Sync()` when the open writer over its range is only an earlier store or publish of the same plane. I haven't tried it yet. I can prototype that and check it against the depth and storage tests, unless you see a reason the CPU must observe the published bytes first, such as the keep-blocks decision or `compareUntracked` reading guest memory. AI-assisted: yes (Claude Code)
milescoviello commented 2026-10-21 07:36:24 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-21T07:36:24Z.


I tried the GPU-ordering idea and it doesn't settle this, so I take back the last paragraph above.

Prototype (diagnostics only, APS5_DIAG_SKIP_OWN_PUBLISH_SYNC=1): a depth plane store skips Sync() when the open batch's last write over its plane is the previous depth store's publish. Same level, three runs:

slow runs before (sync on each store) two slow runs, sync skipped fast run, sync skipped
stores per 5 s 1,060 to 1,142 1,159 to 1,309 20
Sync() calls per 5 s 1,035 to 1,117 0 0
FinishUpTo() calls per 5 s 9 to 17 23 to 29 0
time waiting in those calls per 5 s 3,828 to 4,094 ms 3,545 to 3,734 ms 0 ms
presents per 10 s 6 to 9 9 to 10 20 to 21

Without the syncs, the open batch grows until something submits it. The next store then finds the plane's writer in flight and waits in FinishUpTo(), about 125 to 155 ms per wait, so the waiting is nearly the same. The GPU still moves about 31.9 MiB per store into the host import, around 8 GiB/s. That looks bound by the transfer to host memory rather than by the CPU-side ordering. Skipping the sync only overlaps a part of it.

So the bytes are the cost after all. A store limited to the units a read overlaps would cut the transfer, as you proposed, with the per-unit stale state and generation precedence you described. The prototype stays in my local diagnostics.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6310670971 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/8840#issuecomment-6310670971). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-21T07:36:24Z. --- I tried the GPU-ordering idea and it doesn't settle this, so I take back the last paragraph above. Prototype (diagnostics only, `APS5_DIAG_SKIP_OWN_PUBLISH_SYNC=1`): a depth plane store skips `Sync()` when the open batch's last write over its plane is the previous depth store's publish. Same level, three runs: | | slow runs before (sync on each store) | two slow runs, sync skipped | fast run, sync skipped | |---|---|---|---| | stores per 5 s | 1,060 to 1,142 | 1,159 to 1,309 | 20 | | `Sync()` calls per 5 s | 1,035 to 1,117 | 0 | 0 | | `FinishUpTo()` calls per 5 s | 9 to 17 | 23 to 29 | 0 | | time waiting in those calls per 5 s | 3,828 to 4,094 ms | 3,545 to 3,734 ms | 0 ms | | presents per 10 s | 6 to 9 | 9 to 10 | 20 to 21 | Without the syncs, the open batch grows until something submits it. The next store then finds the plane's writer in flight and waits in `FinishUpTo()`, about 125 to 155 ms per wait, so the waiting is nearly the same. The GPU still moves about 31.9 MiB per store into the host import, around 8 GiB/s. That looks bound by the transfer to host memory rather than by the CPU-side ordering. Skipping the sync only overlaps a part of it. So the bytes are the cost after all. A store limited to the units a read overlaps would cut the transfer, as you proposed, with the per-unit stale state and generation precedence you described. The prototype stays in my local diagnostics. AI-assisted: yes (Claude Code)
MarcZX10 commented 2026-10-21 07:44:17 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T07:44:17Z.


This separates the two costs: the skipped Sync() does not remove the wait, because it moves to FinishUpTo(), while the same full-plane transfer remains. That makes partial write-back the remaining plausible route to the measured win. The implementation still has to preserve per-unit stale state and CPU-write precedence; I would keep the prototype scoped to the requested Z_X units and compare untouched neighboring units against a control before treating it as safe.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6310799538 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/8840#issuecomment-6310799538). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-21T07:44:17Z. --- This separates the two costs: the skipped `Sync()` does not remove the wait, because it moves to `FinishUpTo()`, while the same full-plane transfer remains. That makes partial write-back the remaining plausible route to the measured win. The implementation still has to preserve per-unit stale state and CPU-write precedence; I would keep the prototype scoped to the requested Z_X units and compare untouched neighboring units against a control before treating it as safe.
milescoviello commented 2026-10-21 10:03:35 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-21T10:03:35Z.


@MarcZX10 the range-limited stores are up as #9026. They follow the requirements you set out here:

  • per-64 KiB stale state;
  • copying only the selected Z_X tiles into the mirror, with the pipe/bank XOR kept inside each block and the edge tiles clipped;
  • per-unit precedence of guest writes.

On the control you asked for, the new execution test checks the untouched neighbouring units in memory after each partial store. With write watching, a guest write into one unit of a partly stored plane keeps that unit's guest value. The units that are still stale keep the drawn depth, and a LESS draw then passes only over the guest-written unit.

On level 1-1, four alternating pairs: this change ran at 33 to 46 presents per 10 s in every run. Base ran at 2 to 27, and one of its runs hit the slow mode. The table is in the PR.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6313310141 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/8840#issuecomment-6313310141). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-21T10:03:35Z. --- @MarcZX10 the range-limited stores are up as #9026. They follow the requirements you set out here: - per-64 KiB stale state; - copying only the selected Z_X tiles into the mirror, with the pipe/bank XOR kept inside each block and the edge tiles clipped; - per-unit precedence of guest writes. On the control you asked for, the new execution test checks the untouched neighbouring units in memory after each partial store. With write watching, a guest write into one unit of a partly stored plane keeps that unit's guest value. The units that are still stale keep the drawn depth, and a LESS draw then passes only over the guest-written unit. On level 1-1, four alternating pairs: this change ran at 33 to 46 presents per 10 s in every run. Base ran at 2 to 27, and one of its runs hit the slow mode. The table is in the PR. AI-assisted: yes (Claude Code)
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#8840
No description provided.