d3d12: every batch gathers every reserved image in a GPU reservation again (about 50 GiB of copies a frame in ProjectScarlett gameplay on an RTX 5090) #678

Open
opened 2026-12-03 17:38:12 +00:00 by NickStallman · 1 comment
NickStallman commented 2026-12-03 17:38:12 +00:00 (Migrated from github.com)
Contributor

Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-12-03T17:38:12Z.


What happens

Once ProjectScarlett reaches gameplay, frames take 14–24 s on an RTX 5090 while the GPU's pipelines are almost idle. The time goes into QueuedCopies::record and the copies it queues: before each batch, every placed texture that lives in a GPU reservation is copied from its pages into its image again, and no texture is ever skipped as unchanged.

A build from before the page-mapping rework (9494fdb8, 106120ca) runs the same scene on the same machine at about 0.7 s a frame.

Setup

  • RTX 5090, driver 620.70, GE-Proton11-15, default settings.
  • Host profile line: wave=32-32 section-import=aliased descriptor-bytes=32/32 mesh=yes rays=yes doubles=yes.
  • 106120ca plus local fixes that keep the device alive into gameplay (#677 among them). The runs below are without #676; with #676 the frame time was the same (posted there).
  • A local trace counts what QueuedCopies::record is asked for and times its steps. I can open it as a PR if it is useful.

Numbers

Per report window of the trace. In gameplay one window is about one frame:

Phase Window Calls Textures read Skipped as unchanged Gathered Scattered Buffer copies CPU in record
Loading (typical) 5 s 110–160 820–1,500 0 1.0–2.4 GiB 0 100–160 k 0.03–0.07 s
Switch to gameplay 5 s 45 76,181 0 59.1 GiB 8.6 GiB 11.8 M 4.2 s
Gameplay, three frames 21.7 / 18.3 / 14.3 s 38 / 38 / 33 62,426 / 68,993 / 68,695 0 49.4 / 52.0 / 50.7 GiB 5.3 / 2.3 / 3.7 GiB 9.6 / 10.6 / 10.5 M 2.9 / 3.1 / 2.5 s

So each batch in gameplay gathers about 1,800 textures (about 1.4 GiB), 33–38 batches a frame. A frame also records about 225,000 detile dispatches and 580,000 image copies.

Around it, per frame after the first 200 s (old build in brackets):

  • frame time 18–21 s (0.68 s);
  • submission CPU time 6–8 s, of which placement 3.7–4.7 s and the host stage 2.5–3.6 s (0.37 s, of which the host stage 1–2 ms);
  • GPU memory waits summed over the queues 57–67 s (2.3 s);
  • texture readback 10–12 MiB/s (850 MiB/s);
  • TUXBOX_GPU_TIMING: 11–23 ms of timed pipeline work per second of wall time.

Why nothing is skipped

A second run tallied, for each texture read, which condition kept it from being skipped. Two runs, 485 s and 305 s; the split of the first row is from the second run:

Reason Reads (485 s run) Share
The caller did not allow a skip 1,261,531 58 %
— of which a later phase of an ordered batch (305 s run) 610,725 of 611,197 99.9 % of that row
— of which page-mapping bindings pending at the submission (305 s run) 472 of 611,197 0.1 % of that row
A watch was not clean: every one with cell value 10 (untracked and unmonitored) and XMem's reason 1 (not mapped) 892,969 41 %
No record of an earlier gather (first use) 15,306 0.7 %
Backed tiles, host pages or a recorded GPU write changed 0 0

All of these textures are reserved images. A record of the gather was kept for every one of them. XMem's range classification does not know the first host page the GPU reads under each texture.

Did the bytes change? For one texture in 64, the trace kept a digest of the first 4 KiB the GPU reads and compared it at the next gather: 38,407 the same, 30 changed (485 s run); 20,469 the same, 119 changed (305 s run). That is a sample of a prefix, not of whole textures, but it says the copies mostly refresh bytes that did not change.

Where the two conditions are

  • runtime/d3d12/src/device/placement/queue_use.rs, Batch::execute: with phases, record(part, may_skip && index == 0). Every phase after the first of an ordered batch gathers all its reads, because an earlier phase's write is not in flight yet when the skip is decided.
  • runtime/d3d12/src/device/placement/queue_copies.rs, unchanged and note_gather: the watches are made over the host pages gpu_hosts returns (watch_pages). On this machine XMem reports those ranges as not mapped, so the watch never reads clean or held and the texture is gathered again.
  • runtime/d3d12/src/device/placement.rs: may_skip = !gpu_mappings.bindings_pending(). This one is rarely the reason.

Ideas, not a plan

  • For a later phase, gather only the textures whose pages an earlier phase of the same submission writes, as far as the phases' write sets say.
  • Watch the pages by an address XMem tracks, or have the page mapping stamp a texture when a mapping or a write reaches its pages, so that an unchanged texture reads clean.
  • Whatever the skip, the textures a batch only reaches through a heap and did not read lately could be left out of the gather, as read residency does for backing.

I have not tried any of these. #668 looks at the neighbouring exclusivity gate and assumes reads are normally fresh, which they never are here, so the two may interact.

Not covered

  • One machine, one title, two short runs of the tally.
  • Why the watch is never clean, read from the code and not yet confirmed by a run: with section backing, the page address the gather watches is the page's place in XMem's own GPU view of the section (shared_pages.rs, chunk_view), which TuxBoxAcquireGpuTileBacking returns. XMem's watch only resolves the title's own mappings (tracking.rs, mappings.get(&at)), so for that address it answers "not mapped" (cell 10, reason 1) every time. If that's right, the skip can't pass under section backing on any vendor, only with private backing. A run with TUXBOX_XMEM_PRIVATE_VIEWS=1 is going now, and I'll add its result here.
  • @s3rius, #668 says reads are normally fresh on an RTX 5090. Which backing does that machine use (the section-import= value in the host profile line, and whether private views are on)? That may be the whole difference.

🤖 Generated with Claude Code

<!-- greyfinch-sync:brcly/TuxBox:issue:6774643586 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/issues/678). Originally posted by [NickStallman](https://github.com/NickStallman) on 2026-12-03T17:38:12Z. --- ## What happens Once ProjectScarlett reaches gameplay, frames take 14–24 s on an RTX 5090 while the GPU's pipelines are almost idle. The time goes into `QueuedCopies::record` and the copies it queues: before each batch, every placed texture that lives in a GPU reservation is copied from its pages into its image again, and no texture is ever skipped as unchanged. A build from before the page-mapping rework (9494fdb8, 106120ca) runs the same scene on the same machine at about 0.7 s a frame. ## Setup - RTX 5090, driver 620.70, GE-Proton11-15, default settings. - Host profile line: `wave=32-32 section-import=aliased descriptor-bytes=32/32 mesh=yes rays=yes doubles=yes`. - `106120ca` plus local fixes that keep the device alive into gameplay (#677 among them). The runs below are without #676; with #676 the frame time was the same (posted there). - A local trace counts what `QueuedCopies::record` is asked for and times its steps. I can open it as a PR if it is useful. ## Numbers Per report window of the trace. In gameplay one window is about one frame: | Phase | Window | Calls | Textures read | Skipped as unchanged | Gathered | Scattered | Buffer copies | CPU in `record` | |---|---|---|---|---|---|---|---|---| | Loading (typical) | 5 s | 110–160 | 820–1,500 | 0 | 1.0–2.4 GiB | 0 | 100–160 k | 0.03–0.07 s | | Switch to gameplay | 5 s | 45 | 76,181 | 0 | 59.1 GiB | 8.6 GiB | 11.8 M | 4.2 s | | Gameplay, three frames | 21.7 / 18.3 / 14.3 s | 38 / 38 / 33 | 62,426 / 68,993 / 68,695 | 0 | 49.4 / 52.0 / 50.7 GiB | 5.3 / 2.3 / 3.7 GiB | 9.6 / 10.6 / 10.5 M | 2.9 / 3.1 / 2.5 s | So each batch in gameplay gathers about 1,800 textures (about 1.4 GiB), 33–38 batches a frame. A frame also records about 225,000 detile dispatches and 580,000 image copies. Around it, per frame after the first 200 s (old build in brackets): - frame time 18–21 s (0.68 s); - submission CPU time 6–8 s, of which placement 3.7–4.7 s and the host stage 2.5–3.6 s (0.37 s, of which the host stage 1–2 ms); - GPU memory waits summed over the queues 57–67 s (2.3 s); - texture readback 10–12 MiB/s (850 MiB/s); - `TUXBOX_GPU_TIMING`: 11–23 ms of timed pipeline work per second of wall time. ## Why nothing is skipped A second run tallied, for each texture read, which condition kept it from being skipped. Two runs, 485 s and 305 s; the split of the first row is from the second run: | Reason | Reads (485 s run) | Share | |---|---|---| | The caller did not allow a skip | 1,261,531 | 58 % | | — of which a later phase of an ordered batch (305 s run) | 610,725 of 611,197 | 99.9 % of that row | | — of which page-mapping bindings pending at the submission (305 s run) | 472 of 611,197 | 0.1 % of that row | | A watch was not clean: every one with cell value 10 (untracked and unmonitored) and XMem's reason 1 (not mapped) | 892,969 | 41 % | | No record of an earlier gather (first use) | 15,306 | 0.7 % | | Backed tiles, host pages or a recorded GPU write changed | 0 | 0 | All of these textures are reserved images. A record of the gather was kept for every one of them. XMem's range classification does not know the first host page the GPU reads under each texture. Did the bytes change? For one texture in 64, the trace kept a digest of the first 4 KiB the GPU reads and compared it at the next gather: 38,407 the same, 30 changed (485 s run); 20,469 the same, 119 changed (305 s run). That is a sample of a prefix, not of whole textures, but it says the copies mostly refresh bytes that did not change. ## Where the two conditions are - `runtime/d3d12/src/device/placement/queue_use.rs`, `Batch::execute`: with phases, `record(part, may_skip && index == 0)`. Every phase after the first of an ordered batch gathers all its reads, because an earlier phase's write is not in flight yet when the skip is decided. - `runtime/d3d12/src/device/placement/queue_copies.rs`, `unchanged` and `note_gather`: the watches are made over the host pages `gpu_hosts` returns (`watch_pages`). On this machine XMem reports those ranges as not mapped, so the watch never reads clean or held and the texture is gathered again. - `runtime/d3d12/src/device/placement.rs`: `may_skip = !gpu_mappings.bindings_pending()`. This one is rarely the reason. ## Ideas, not a plan - For a later phase, gather only the textures whose pages an earlier phase of the same submission writes, as far as the phases' write sets say. - Watch the pages by an address XMem tracks, or have the page mapping stamp a texture when a mapping or a write reaches its pages, so that an unchanged texture reads clean. - Whatever the skip, the textures a batch only reaches through a heap and did not read lately could be left out of the gather, as read residency does for backing. I have not tried any of these. #668 looks at the neighbouring exclusivity gate and assumes reads are normally fresh, which they never are here, so the two may interact. ## Not covered - One machine, one title, two short runs of the tally. - Why the watch is never clean, read from the code and not yet confirmed by a run: with section backing, the page address the gather watches is the page's place in XMem's own GPU view of the section (`shared_pages.rs`, `chunk_view`), which `TuxBoxAcquireGpuTileBacking` returns. XMem's watch only resolves the title's own mappings (`tracking.rs`, `mappings.get(&at)`), so for that address it answers "not mapped" (cell 10, reason 1) every time. If that's right, the skip can't pass under section backing on any vendor, only with private backing. A run with `TUXBOX_XMEM_PRIVATE_VIEWS=1` is going now, and I'll add its result here. - @s3rius, #668 says reads are normally fresh on an RTX 5090. Which backing does that machine use (the `section-import=` value in the host profile line, and whether private views are on)? That may be the whole difference. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
NickStallman commented 2026-12-03 17:40:38 +00:00 (Migrated from github.com)
Author
Contributor

Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-12-03T17:40:38Z.


A control run for the mechanism above: the same build and settings as the 305 s tally run, plus TUXBOX_XMEM_PRIVATE_VIEWS=1.

It only covers loading and the intro. The run ended after 172 s on the title's own watchdog (exit 5), after about a minute without a presented frame, so there are no gameplay frame times to compare. I don't know yet whether that stall is the known cost of private views (#456) or something else.

For the part it did cover:

section backing (305 s run, all of it) private views (172 s run)
Texture reads reaching QueuedCopies::record 1,051,033 16,362
Skipped as unchanged 0 5,856 (36 %)
Watch not clean with cell 10, reason 1 (not mapped) 429,844 0
Watch not clean, other 0 1,341 (cell 5, reason 6)
Later phase of an ordered batch 610,725 7,479
Page-mapping bindings pending 472 1,398
A recorded GPU write over the range 0 26
No record of an earlier gather 9,992 262
XMem's class of the first host page under the texture not XMem's, every time held, every time

So with private views the watch is no longer refused as "not mapped", and about a third of the reads are skipped. That fits the reading that under section backing the watch is asked for an address XMem does not resolve. The later-phase rule is still the largest reason left (46 % of the reads in this run).

One run, loading only.

🤖 Generated with Claude Code

<!-- greyfinch-sync:brcly/TuxBox:comment:7386887904 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/issues/678#issuecomment-7386887904). Originally posted by [NickStallman](https://github.com/NickStallman) on 2026-12-03T17:40:38Z. --- A control run for the mechanism above: the same build and settings as the 305 s tally run, plus `TUXBOX_XMEM_PRIVATE_VIEWS=1`. It only covers loading and the intro. The run ended after 172 s on the title's own watchdog (exit 5), after about a minute without a presented frame, so there are no gameplay frame times to compare. I don't know yet whether that stall is the known cost of private views (#456) or something else. For the part it did cover: | | section backing (305 s run, all of it) | private views (172 s run) | |---|---|---| | Texture reads reaching `QueuedCopies::record` | 1,051,033 | 16,362 | | Skipped as unchanged | 0 | 5,856 (36 %) | | Watch not clean with cell 10, reason 1 (not mapped) | 429,844 | 0 | | Watch not clean, other | 0 | 1,341 (cell 5, reason 6) | | Later phase of an ordered batch | 610,725 | 7,479 | | Page-mapping bindings pending | 472 | 1,398 | | A recorded GPU write over the range | 0 | 26 | | No record of an earlier gather | 9,992 | 262 | | XMem's class of the first host page under the texture | not XMem's, every time | held, every time | So with private views the watch is no longer refused as "not mapped", and about a third of the reads are skipped. That fits the reading that under section backing the watch is asked for an address XMem does not resolve. The later-phase rule is still the largest reason left (46 % of the reads in this run). One run, loading only. 🤖 Generated with [Claude Code](https://claude.com/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
brcly/TuxBox#678
No description provided.