D3D12.X: hash sparse uploads from a cached copy, not the staging ring #3164

Closed
tiagonleal wants to merge 1 commit from upstream-pr/3164 into main
tiagonleal commented 2026-11-28 14:43:52 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by tiagonleal on 2026-11-28T14:43:52Z.


On main since #2959, a retail title's menus run at about 12 presents per 2 s for roughly the first minute on an RTX 5070 Ti, where main f9a0cb80 (27 Nov) ran at 60 from about 8 s on. The "looks before submits" line shows why: the submitting thread spends nearly all its time in sparse uploads with the upload gate held, about 2 s of every 2 s for ~28 MB.

looks before submits (2 s): 35 looks did 2009 ms active work (100.5 % of the time) ... sparse queue wait/fence+state/scan/upload/ownership wait 0/6/0/1974/0 ms (115 runs, 27.8 MB zero/dirty bytes); ... upload gate submit wait/hold 0/1982 ms

Since 9d08eceb ("publish sparse upload hashes after queue receipt") every dirty upload hashes its bytes by reading them back from the mapped UPLOAD-heap staging ring (PreparedDirtyBatch::append_hashes on the staging pointer). That memory is write-combined, so reading it is uncached and slow. Before 9d08eceb the hashes came from title memory. I found no open PR or issue for this (searched "upload gate", "looks before submits", "write-combined", "sparse upload hash").

What is in it

  • sparse.rs: upload_dirty_with_timeout copies each chunk of title memory once into a reusable buffer on State (upload_scratch), hashes that buffer and copies it into the staging ring. The hashed bytes are still exactly the uploaded bytes, which is what 9d08eceb guarantees, and the staging ring is only written. +14/-5.
  • No new test: behaviour is unchanged and the staging pointer is a mapped D3D12 resource, so no unit test would fail without the change. The runs below are the evidence.

Tested

  • Windows 11 Pro 10.0.26300, NVIDIA GeForce RTX 5070 Ti 16 GB (driver 617.42), AMD Ryzen 7 9800X3D, 32 GB RAM, rustc 1.100.0
  • scripts/smoke.ps1 on the Newer Retail Game, release, XCL_PREPARE=0, same DXIL cache, main 309c3ec5 against this head: 322 against 1685 frames in 60 s, and 6723 against 8885 frames in 300 s (blocks below). With the change the same log line reads 180 looks did 178 ms active work (8.9 % of the time) and upload gate submit wait/hold 0/7 ms (from a run of this change on e429936c).
  • Earlier today, the same change on main e429936c, alternating, two runs each of 60 s: main 309 and 315 frames, the change 1677 and 1679.
  • cargo test --workspace --no-fail-fast -j 8 -- --test-threads=4, one run on head c9c57dba: 2138 passed, 4 failed, 48 ignored (25 SKIPPED lines). Failures: 4, the same 4 that fail on main 309c3ec5 here (fuzz_validate_and_gpu_0, fuzz_validate_and_gpu_1, fuzz_validate_and_gpu_2, fuzz_validate_and_gpu_3). main 309c3ec5 on this machine: 2138 passed, 4 failed, 48 ignored.
  • cargo test -p xcl --lib d3d12x::sparse -- --test-threads=4: 83 passed, 0 failed, 1 ignored.

Regression run
300 s each, release builds in clean trees, main first. I use 300 s and not 60 s here because in 60 s this change takes the title about five times further than main, so the 60 s pair compares two different points of the title: 322 against 1685 frames, and a peak commit of 11257 against 16655 MB, which is over the 125 % line of pr_check.py. After 300 s both have reached the same menus and commit the same.

main (309c3ec5), 300 s:

xcl-smoke v1
commit: 309c3ec5a25ea231ddbe01f76748ab8ed3d9d953
gpu: NVIDIA GeForce RTX 5070 Ti
title: 9cc6a39e
seconds: 300
exit: 0x0
frames shown: 6723 (PresentX 6723)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 18784 MB

This PR (c9c57dba), 300 s:

xcl-smoke v1
commit: c9c57dba3fba6e2c90823dbe04e3143513f9f600
gpu: NVIDIA GeForce RTX 5070 Ti
title: 9cc6a39e
seconds: 300
exit: 0x0
frames shown: 8885 (PresentX 8885)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 19006 MB

Not tested

  • AMD, Intel, Wine, other NVIDIA drivers. Write-combined memory is slow to read on any vendor, but that is not measured here.
  • World loading and anything past the menus.
  • The cost of the extra copy on its own: one cached copy per uploaded chunk (about 14 MB/s here). The totals above include it.
  • The buffer grows to the largest single copy (at most the 64 MiB staging size) and is not shrunk.

AI use

  • Claude Code with Claude Fable 5.2 and Anthropic subagents (Claude Opus 5.5, Claude Sonnet 5.5) helped developing.

🤖 Generated with Claude Code

<!-- greyfinch-sync:ivall/xcl:issue:5541273809 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3164). Originally posted by [tiagonleal](https://github.com/tiagonleal) on 2026-11-28T14:43:52Z. --- On `main` since #2959, a retail title's menus run at about 12 presents per 2 s for roughly the first minute on an RTX 5070 Ti, where `main` `f9a0cb80` (27 Nov) ran at 60 from about 8 s on. The "looks before submits" line shows why: the submitting thread spends nearly all its time in sparse uploads with the upload gate held, about 2 s of every 2 s for ~28 MB. ``` looks before submits (2 s): 35 looks did 2009 ms active work (100.5 % of the time) ... sparse queue wait/fence+state/scan/upload/ownership wait 0/6/0/1974/0 ms (115 runs, 27.8 MB zero/dirty bytes); ... upload gate submit wait/hold 0/1982 ms ``` Since 9d08eceb ("publish sparse upload hashes after queue receipt") every dirty upload hashes its bytes by reading them back from the mapped UPLOAD-heap staging ring (`PreparedDirtyBatch::append_hashes` on the staging pointer). That memory is write-combined, so reading it is uncached and slow. Before 9d08eceb the hashes came from title memory. I found no open PR or issue for this (searched "upload gate", "looks before submits", "write-combined", "sparse upload hash"). **What is in it** - `sparse.rs`: `upload_dirty_with_timeout` copies each chunk of title memory once into a reusable buffer on `State` (`upload_scratch`), hashes that buffer and copies it into the staging ring. The hashed bytes are still exactly the uploaded bytes, which is what 9d08eceb guarantees, and the staging ring is only written. +14/-5. - No new test: behaviour is unchanged and the staging pointer is a mapped D3D12 resource, so no unit test would fail without the change. The runs below are the evidence. **Tested** - Windows 11 Pro 10.0.26300, NVIDIA GeForce RTX 5070 Ti 16 GB (driver 617.42), AMD Ryzen 7 9800X3D, 32 GB RAM, rustc 1.100.0 - `scripts/smoke.ps1` on the Newer Retail Game, release, `XCL_PREPARE=0`, same DXIL cache, `main` `309c3ec5` against this head: 322 against 1685 frames in 60 s, and 6723 against 8885 frames in 300 s (blocks below). With the change the same log line reads `180 looks did 178 ms active work (8.9 % of the time)` and `upload gate submit wait/hold 0/7 ms` (from a run of this change on `e429936c`). - Earlier today, the same change on `main` `e429936c`, alternating, two runs each of 60 s: `main` 309 and 315 frames, the change 1677 and 1679. - `cargo test --workspace --no-fail-fast -j 8 -- --test-threads=4`, one run on head `c9c57dba`: 2138 passed, 4 failed, 48 ignored (25 `SKIPPED` lines). Failures: 4, the same 4 that fail on `main` `309c3ec5` here (`fuzz_validate_and_gpu_0`, `fuzz_validate_and_gpu_1`, `fuzz_validate_and_gpu_2`, `fuzz_validate_and_gpu_3`). `main` `309c3ec5` on this machine: 2138 passed, 4 failed, 48 ignored. - `cargo test -p xcl --lib d3d12x::sparse -- --test-threads=4`: 83 passed, 0 failed, 1 ignored. **Regression run** 300 s each, release builds in clean trees, `main` first. I use 300 s and not 60 s here because in 60 s this change takes the title about five times further than `main`, so the 60 s pair compares two different points of the title: 322 against 1685 frames, and a peak commit of 11257 against 16655 MB, which is over the 125 % line of `pr_check.py`. After 300 s both have reached the same menus and commit the same. `main` (`309c3ec5`), 300 s: ``` xcl-smoke v1 commit: 309c3ec5a25ea231ddbe01f76748ab8ed3d9d953 gpu: NVIDIA GeForce RTX 5070 Ti title: 9cc6a39e seconds: 300 exit: 0x0 frames shown: 6723 (PresentX 6723) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 18784 MB ``` This PR (`c9c57dba`), 300 s: ``` xcl-smoke v1 commit: c9c57dba3fba6e2c90823dbe04e3143513f9f600 gpu: NVIDIA GeForce RTX 5070 Ti title: 9cc6a39e seconds: 300 exit: 0x0 frames shown: 8885 (PresentX 8885) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 19006 MB ``` **Not tested** - AMD, Intel, Wine, other NVIDIA drivers. Write-combined memory is slow to read on any vendor, but that is not measured here. - World loading and anything past the menus. - The cost of the extra copy on its own: one cached copy per uploaded chunk (about 14 MB/s here). The totals above include it. - The buffer grows to the largest single copy (at most the 64 MiB staging size) and is not shrunk. **AI use** - Claude Code with Claude Fable 5.2 and Anthropic subagents (Claude Opus 5.5, Claude Sonnet 5.5) helped developing. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
tiagonleal commented 2026-11-29 11:05:51 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by tiagonleal on 2026-11-29T11:05:51Z.


Closing: main no longer has the readback this PR removed. Since the merge of nvidia-dev (f0e8fdd5), submit_upload in sparse.rs hashes each chunk from the title's memory and only then copies into the staging ring with run_copies, so the write-combined buffer is written and never read. I checked this by reading main at d8bd9a38; I have not measured frames on it.

  • Tiago
<!-- greyfinch-sync:ivall/xcl:comment:7254877332 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3164#issuecomment-7254877332). Originally posted by [tiagonleal](https://github.com/tiagonleal) on 2026-11-29T11:05:51Z. --- Closing: `main` no longer has the readback this PR removed. Since the merge of `nvidia-dev` (`f0e8fdd5`), `submit_upload` in `sparse.rs` hashes each chunk from the title's memory and only then copies into the staging ring with `run_copies`, so the write-combined buffer is written and never read. I checked this by reading `main` at `d8bd9a38`; I have not measured frames on it. - Tiago

Pull request closed

Sign in to join this conversation.
No reviewers
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
xcl-dev/xcl!3164
No description provided.