Repository navigation
D3D12.X: reduce retained texture upload staging - #2024
Conversation
Round large staging allocations in 16 MiB steps and release the completed buffer reference before allocating a replacement. Keep copy ordering and waits intact. Add a large mixed-format upload and readback regression. Assisted-by: OpenAI Codex (GPT-6)
|
Code review on
Remaining before merge: An independent AMD GPU test pass on exact head |
|
Independent AMD check completed on unchanged exact head Tested — Windows 10 Home 19045, Ryzen 7 7800X3D, AMD Radeon(TM) Graphics iGPU, driver 32.0.21030.2001, Rust 1.98.1 MSVC, debug. The fixture printed the AMD adapter name; this was not run on the RTX 3090. 2 passed / 0 failed / 0 ignored, zero GPU skips. The 132 MiB mixed RGBA/BC7 batch grew staging from 128 MiB to 144 MiB. Both growth and repeat uploads passed byte-exact readback; the repeat reused the same staging resource/capacity. Size-class boundaries and overflow rejection passed. All 311 source SHA256 hashes matched before/after and match the clean head worktree; XCL recompiled. No local source patch. Not tested — The debug-layer request failed with AI use — Codex (GPT-6) inspected the fixture, prepared and ran this native Windows check, verified logs/source hashes, and wrote this report. |
gefydev
left a comment
There was a problem hiding this comment.
Review of 24162c7 (read against main bf9eebd; I did not build or run it).
The change is correct. The cached uploader is only put back after its fence has passed (and is forget-ed on a timeout), so dropping the old buffer before buffer() is safe. If buffer() fails, upload_batch drops the uploader through ? as before. checked_next_multiple_of covers the overflow case and the boundary values in the test are right.
Points:
- More reallocations above 64 MiB. Growth goes from doubling to 16 MiB steps, so batches that grow slowly recreate the buffer at every step: about 12 times up to 256 MiB where it was 2 before. The
Uploaderdoc says each of these D3D12 calls cost 200–650 ms under VidMM pressure. Rounding to 16 MiB while growing by at least ~25 % (max(next 16 MiB multiple, cap * 5 / 4)) would keep most of the memory saving without that cost. - The release-before-replace ordering has no test. The size-class test fails without the change, but nothing fails if the old buffer is again dropped after the new one is created. Checking the old resource's refcount (or that it is released before
buffer()runs) would cover it. - Debug layer enabled mid-process. With
XCL_D3D12_DEBUGset, the GPU test callsEnableDebugLayer()after other tests in the same process (--test-threads=4) may already have created devices. Enabling the debug layer after a device exists removes that device. - The test picks its own adapter instead of using the module's
device()helper (texture.rs:668). On a hybrid laptop it can get a different adapter from the neighbouring test. BecauseUPLOADERSis keyed by the queue's address, it could then take a leftover uploader that belongs to another device. - The suite was run with
--test-threads=1, and CONTRIBUTING asks for 4. That matters for a test that allocates ~400 MiB of GPU memory. The "optimized test profile" in the description does not exist inCargo.toml. - The smoke pair is 22 s, and the long retail runs ended in device resets on both base and candidate, so the retail memory benefit is not shown yet.
Review written with Claude Code (Claude Opus 5.5); I checked each point against the code.
|
Independent post-merge hardware run on unmodified Your mixed RGBA/BC7 fixture printed a 138,412,032-byte request (132 MiB), with staging growing from 134,217,728 to 150,994,944 bytes (128 → 144 MiB). The repeated upload reused the staging resource and passed byte-exact GPU readback. The fixture printed the physical adapter name. Growth took 43.61 ms and reuse 23.27 ms in this single run. I ran AI use: Codex (GPT-6) ran the two existing tests and wrote this report. |
|
Verification on RTX 3060 Ti (Windows 11), branch merged with current
Thanks! |
Tighten the synchronous CPU texture uploader's large staging allocation classes and release the cached staging reference after its completed copy fence, before replacement. A retail ownership probe recorded a 132.3 MiB request growing staging from 128 MiB to 256 MiB. At that point the old and new staging resources and 131.5 MiB of detiled payload coexisted, for 515.5 MiB of tracked capacity and payload. The CPU fallback coordination was posted to the #1513 discussion for the #1513 and #455 authors. Coordination
What is in it
crates/xcl/src/gpu/texture.rskeeps the existing small allocation classes, rounds requests above 64 MiB to 16 MiB and releases the completed buffer's cached reference before creating its replacement. It uses the existing layout, barriers and fence.Tested
cargo build --locked --workspace --jobs 1followed bycargo test --locked --workspace --jobs 1 --no-fail-fast -- --test-threads=1 --nocapturereported 997 passed, 0 failed, 45 ignored. The passed count includes 24 capability skips covering wave64, unsupported direct-DXIL cases, driver cache control and heap windows.Regression run
Not tested
AI use