D3D12.X: reduce retained texture upload staging #2014

Merged
ZekkJJ merged 1 commit from upstream-pr/2024 into main 2026-11-25 01:23:26 +00:00
ZekkJJ commented 2026-11-25 01:05:34 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by ZekkJJ on 2026-11-25T01:05:34Z.


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.rs keeps 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.
  • Size-class boundary tests and a 132 MiB mixed RGBA and BC7 fixture cover growth, staging reuse and byte-exact GPU readback after both uploads.

Tested

  • Windows 11 build 26200, AMD Ryzen 7 8845HS, NVIDIA GeForce RTX 4060 Laptop GPU, NVIDIA driver 616.56 and Rust 1.98.1. Workspace tests use the optimized test profile. Retail binaries are release builds.
  • cargo build --locked --workspace --jobs 1 followed by cargo test --locked --workspace --jobs 1 --no-fail-fast -- --test-threads=1 --nocapture reported 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.
  • Two alternating GPU pairs cut retained staging from 256 to 144 MiB and peak private commit by 110.8 and 111.7 MiB. All four fixtures passed byte-exact readback with zero D3D12 debug errors. The candidate also completed both orderings under a 950 MiB synthetic process commit limit. The baseline hit the same 128 MiB allocation failure in both constrained runs.
  • Four guarded retail runs reached loading activity. One baseline was stopped by the concurrent-XCL guard. The other baseline and both candidate runs ended with device resets during loading. At comparable texture-page milestones the process-commit difference varied. The latest captured candidate frame still showed loading artwork.

Regression run

xcl-smoke v1
commit: 8c4a46a3c2d50498691cbda79cbbf4fadb45fbe8
gpu: NVIDIA GeForce RTX 4060 Laptop GPU
title: retail-loading
seconds: 22
exit: 0x0
frames shown: 383 (PresentX 383)
presents per 2 s (last 3): 22 60 60
device removals: 0
crashes: 0
peak commit: 14704 MB
xcl-smoke v1
commit: 24162c76f4a2c5d2e673bc05fbfdba71c3426668
gpu: NVIDIA GeForce RTX 4060 Laptop GPU
title: retail-loading
seconds: 22
exit: 0x0
frames shown: 404 (PresentX 404)
presents per 2 s (last 3): 37 32 59
device removals: 0
crashes: 0
peak commit: 14641 MB

Not tested

  • AMD GPUs, completed world rendering and the memory effect after the full retail loading sequence. The 22-second smoke pair covers early launch only. The long retail comparisons preserve the existing Safe-Runner limits.

AI use

  • Codex with GPT-6 performed the allocation audit, wrote the local staging experiment and fixture, and ran the workspace, GPU and guarded retail checks.
<!-- greyfinch-sync:ivall/xcl:issue:6594736791 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2024). Originally posted by [ZekkJJ](https://github.com/ZekkJJ) on 2026-11-25T01:05:34Z. --- 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](https://github.com/xcl-dev/xcl/pull/1513#issuecomment-7148450201) **What is in it** - `crates/xcl/src/gpu/texture.rs` keeps 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. - Size-class boundary tests and a 132 MiB mixed RGBA and BC7 fixture cover growth, staging reuse and byte-exact GPU readback after both uploads. **Tested** - Windows 11 build 26200, AMD Ryzen 7 8845HS, NVIDIA GeForce RTX 4060 Laptop GPU, NVIDIA driver 616.56 and Rust 1.98.1. Workspace tests use the optimized test profile. Retail binaries are release builds. - `cargo build --locked --workspace --jobs 1` followed by `cargo test --locked --workspace --jobs 1 --no-fail-fast -- --test-threads=1 --nocapture` reported 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. - Two alternating GPU pairs cut retained staging from 256 to 144 MiB and peak private commit by 110.8 and 111.7 MiB. All four fixtures passed byte-exact readback with zero D3D12 debug errors. The candidate also completed both orderings under a 950 MiB synthetic process commit limit. The baseline hit the same 128 MiB allocation failure in both constrained runs. - Four guarded retail runs reached loading activity. One baseline was stopped by the concurrent-XCL guard. The other baseline and both candidate runs ended with device resets during loading. At comparable texture-page milestones the process-commit difference varied. The latest captured candidate frame still showed loading artwork. **Regression run** ``` xcl-smoke v1 commit: 8c4a46a3c2d50498691cbda79cbbf4fadb45fbe8 gpu: NVIDIA GeForce RTX 4060 Laptop GPU title: retail-loading seconds: 22 exit: 0x0 frames shown: 383 (PresentX 383) presents per 2 s (last 3): 22 60 60 device removals: 0 crashes: 0 peak commit: 14704 MB ``` ``` xcl-smoke v1 commit: 24162c76f4a2c5d2e673bc05fbfdba71c3426668 gpu: NVIDIA GeForce RTX 4060 Laptop GPU title: retail-loading seconds: 22 exit: 0x0 frames shown: 404 (PresentX 404) presents per 2 s (last 3): 37 32 59 device removals: 0 crashes: 0 peak commit: 14641 MB ``` **Not tested** - AMD GPUs, completed world rendering and the memory effect after the full retail loading sequence. The 22-second smoke pair covers early launch only. The long retail comparisons preserve the existing Safe-Runner limits. **AI use** - Codex with GPT-6 performed the allocation audit, wrote the local staging experiment and fixture, and ran the workspace, GPU and guarded retail checks.
upstream-sync closed this pull request 2026-11-25 02:08:25 +00:00
gefydev commented 2026-11-25 02:08:26 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by gefydev on 2026-11-25T01:37:31Z.

Review: COMMENTED


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:

  1. 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 Uploader doc 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.
  2. 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.
  3. Debug layer enabled mid-process. With XCL_D3D12_DEBUG set, the GPU test calls EnableDebugLayer() 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.
  4. 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. Because UPLOADERS is keyed by the queue's address, it could then take a leftover uploader that belongs to another device.
  5. 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 in Cargo.toml.
  6. 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.

<!-- greyfinch-sync:ivall/xcl:review:6050261253 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2024#pullrequestreview-6050261253). Originally posted by [gefydev](https://github.com/gefydev) on 2026-11-25T01:37:31Z. **Review:** COMMENTED --- 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: 1. **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 `Uploader` doc 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. 2. **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. 3. **Debug layer enabled mid-process.** With `XCL_D3D12_DEBUG` set, the GPU test calls `EnableDebugLayer()` 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. 4. **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. Because `UPLOADERS` is keyed by the queue's address, it could then take a leftover uploader that belongs to another device. 5. **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 in `Cargo.toml`. 6. **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.
raylitebull commented 2026-11-25 02:08:40 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by raylitebull on 2026-11-25T01:12:49Z.


Code review on 24162c7:

  • staging_capacity in crates/xcl/src/gpu/texture.rs keeps the existing power-of-two growth (>= STAGING_MIN) up to 64 MiB (STAGING_MAX_POW2) and switches to checked_next_multiple_of(16 MiB) (STAGING_LARGE_STEP) above 64 MiB, avoiding 128 -> 256 MiB overshoots on ~132 MiB uploads.
  • Uploader::staging calls drop(self.staging.take()) before allocating the replacement upload buffer, so the old and new staging buffers do not coexist. Because upload_batch waits on up.fence (fence::wait, or std::mem::forget(up) on timeout) before returning the Uploader via put_back, the previous staging buffer is GPU-idle when dropped.
  • large_staging_uses_sixteen_mib_growth_steps and gpu_large_mixed_upload_keeps_tight_staging_and_exact_pixels cleanly cover the size classes, reuse, and byte-exact GPU readback.
  • Build and test (Windows, no GPU) and PR description are both green (CLEAN).

Remaining before merge: An independent AMD GPU test pass on exact head 24162c7.

<!-- greyfinch-sync:ivall/xcl:comment:7149319615 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2024#issuecomment-7149319615). Originally posted by [raylitebull](https://github.com/raylitebull) on 2026-11-25T01:12:49Z. --- Code review on `24162c7`: - `staging_capacity` in `crates/xcl/src/gpu/texture.rs` keeps the existing power-of-two growth (`>= STAGING_MIN`) up to `64 MiB` (`STAGING_MAX_POW2`) and switches to `checked_next_multiple_of(16 MiB)` (`STAGING_LARGE_STEP`) above `64 MiB`, avoiding `128 -> 256 MiB` overshoots on ~132 MiB uploads. - `Uploader::staging` calls `drop(self.staging.take())` before allocating the replacement upload buffer, so the old and new staging buffers do not coexist. Because `upload_batch` waits on `up.fence` (`fence::wait`, or `std::mem::forget(up)` on timeout) before returning the `Uploader` via `put_back`, the previous staging buffer is GPU-idle when dropped. - `large_staging_uses_sixteen_mib_growth_steps` and `gpu_large_mixed_upload_keeps_tight_staging_and_exact_pixels` cleanly cover the size classes, reuse, and byte-exact GPU readback. - `Build and test (Windows, no GPU)` and `PR description` are both green (`CLEAN`). **Remaining before merge:** An independent **AMD GPU** test pass on exact head `24162c7`.
WebIdentity1 commented 2026-11-25 02:08:44 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by WebIdentity1 on 2026-11-25T01:17:21Z.


Independent AMD check completed on unchanged exact head 24162c76f4a2c5d2e673bc05fbfdba71c3426668.

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.

XCL_ADAPTER=AMD XCL_D3D12_DEBUG=1
cargo test --locked -p xcl --lib -- gpu::texture::tests::large_staging_uses_sixteen_mib_growth_steps gpu::texture::tests::gpu_large_mixed_upload_keeps_tight_staging_and_exact_pixels --test-threads=1 --show-output

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 0x887A002D (missing/mismatched SDK component), so this is not a zero-debug-errors result. No discrete AMD GPU, full suite, retail smoke, constrained-process memory experiment, peak-memory comparison, or controlled timing comparison in this check. The printed capacity is retained staging, not measured process-memory savings. This supplies the requested independent AMD iGPU readback evidence; it does not replace the project's other merge gates.

AI use — Codex (GPT-6) inspected the fixture, prepared and ran this native Windows check, verified logs/source hashes, and wrote this report.

<!-- greyfinch-sync:ivall/xcl:comment:7149395175 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2024#issuecomment-7149395175). Originally posted by [WebIdentity1](https://github.com/WebIdentity1) on 2026-11-25T01:17:21Z. --- Independent AMD check completed on unchanged exact head `24162c76f4a2c5d2e673bc05fbfdba71c3426668`. **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. ```text XCL_ADAPTER=AMD XCL_D3D12_DEBUG=1 cargo test --locked -p xcl --lib -- gpu::texture::tests::large_staging_uses_sixteen_mib_growth_steps gpu::texture::tests::gpu_large_mixed_upload_keeps_tight_staging_and_exact_pixels --test-threads=1 --show-output ``` **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 `0x887A002D` (missing/mismatched SDK component), so this is **not** a zero-debug-errors result. No discrete AMD GPU, full suite, retail smoke, constrained-process memory experiment, peak-memory comparison, or controlled timing comparison in this check. The printed capacity is retained staging, not measured process-memory savings. This supplies the requested independent AMD iGPU readback evidence; it does not replace the project's other merge gates. **AI use** — Codex (GPT-6) inspected the fixture, prepared and ran this native Windows check, verified logs/source hashes, and wrote this report.
tyr0nsur commented 2026-11-25 02:09:00 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by tyr0nsur on 2026-11-25T01:53:49Z.


Independent post-merge hardware run on unmodified main@3da2abb81606. Windows 11 Pro 26300, Ryzen 7 5800X, desktop GeForce RTX 4060, NVIDIA driver 32.0.16.2114, Rust 1.98.1 MSVC, default test profile.

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 cargo test --locked -p xcl --lib <filter> -- --nocapture --test-threads=1 once each for large_staging_uses_sixteen_mib_growth_steps and gpu_large_mixed_upload_keeps_tight_staging_and_exact_pixels. Both passed, with zero failures, ignores or capability skips. This run measures staging capacity and pixel correctness only.

AI use: Codex (GPT-6) ran the two existing tests and wrote this report.

<!-- greyfinch-sync:ivall/xcl:comment:7150085392 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2024#issuecomment-7150085392). Originally posted by [tyr0nsur](https://github.com/tyr0nsur) on 2026-11-25T01:53:49Z. --- Independent post-merge hardware run on unmodified `main@3da2abb81606`. Windows 11 Pro 26300, Ryzen 7 5800X, desktop GeForce RTX 4060, NVIDIA driver 32.0.16.2114, Rust 1.98.1 MSVC, default test profile. 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 `cargo test --locked -p xcl --lib <filter> -- --nocapture --test-threads=1` once each for `large_staging_uses_sixteen_mib_growth_steps` and `gpu_large_mixed_upload_keeps_tight_staging_and_exact_pixels`. Both passed, with zero failures, ignores or capability skips. This run measures staging capacity and pixel correctness only. AI use: Codex (GPT-6) ran the two existing tests and wrote this report.
DavidM1911 commented 2026-11-25 05:08:11 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T04:12:13Z.


Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)

Thanks!

<!-- greyfinch-sync:ivall/xcl:comment:7152625401 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2024#issuecomment-7152625401). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-25T04:12:13Z. --- Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.) Thanks!
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!2014
No description provided.