Skip to content

D3D12.X: XCL_UPLOAD_KEEP_MB sets the idle texture upload buffers kept - #3050

Draft
Prime1997 wants to merge 1 commit into
xcl-dev:mainfrom
Prime1997:contrib/nv-upload-keep
Draft

Prime1997 wants to merge 1 commit into
xcl-dev:mainfrom
Prime1997:contrib/nv-upload-keep

Conversation

@Prime1997

@Prime1997 Prime1997 commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

XCL_UPLOAD_KEEP_MB bounds completed texture-upload buffers retained for reuse (0–4096 MiB, default 512). Active buffers remain owned until completion. The activity log separates idle upload memory from submitted buffers awaiting reclaim. This addresses retained system-memory upload heaps; it does not cap live textures, VRAM or total process commit.

Part of #2688; related to #2912's in-flight upload reclamation. This refreshes the existing proposal on nvidia-dev 54225f5884a94cd23b7aab3f703a7c975070aa77 rather than opening another PR. Current main e429936c10a5b8aa09470ff99dfc8c8d3d8c56fd uses a different uploader and does not contain this idle-pool switch.

What is in it

  • Preserve the existing configurable cap and upload diagnostics, resolve the activity-loop rebase, and document the switch.
  • Add a functional test using isolated WARP processes: allocate 6 MiB, exercise zero and 2 MiB idle caps, preserve checked-out contents, discard the largest idle buffer, and reuse retained buffers. No command queue or GPU submission is used.

Tested

  • Clean head cbb909c08ca786b4ddfeaf95b686aa105bec43e4; Windows x64, debug Rust tests, software WARP device. Commands below use the actual arguments with only the private build-cache path abbreviated as <target>.
  • cargo test --locked -p xcl --lib --target-dir <target> hle::d3d12x::texture_upload::tests::the_idle_upload_buffers_kept_follow_the_switch -- --exact --nocapture --test-threads=1: 1 passed, 0 failed, 0 ignored, 0 explicit skips.
  • cargo test --locked -p xcl --lib --target-dir <target> hle::d3d12x::texture_upload::tests::idle_upload_limit_releases_buffers_and_keeps_reusable_ones -- --exact --nocapture --test-threads=1: 1 top-level test passed, 0 failed, 0 ignored, 0 explicit skips; two child cases each passed separately. Nested summaries are not added to the top-level count.

Regression run
Pending for this head. Previous-head smoke blocks and whole-suite results are historical and do not establish validation of this revision. Keep this PR a draft.

Not tested

  • Current-head full workspace suite, hardware GPU behavior, paired current-main/title regression, and release gameplay.
  • Frame-time cost of low retention limits, overall process-memory reduction, and AMD hardware.

AI use
Original implementation by Claude Code (Claude Opus 5.5), as recorded in the previous revision. Codex (GPT-6) rebased it, added the functional fixture/documentation, reviewed current-main overlap, and ran the focused checks above. Earlier contributors' results are not presented as new runs.

Optional temporary contributor/testing coordination: https://discord.gg/6B4TykyC4W

@Prime1997 Prime1997 self-assigned this Nov 27, 2026
@Gevroska

Gevroska commented Nov 27, 2026 •

Copy link
Copy Markdown

I tested the idle upload-buffer cap at d6d529c2 on Windows 11 with Microsoft WARP. I ran the same test binary in three fresh processes. Each run submitted two RGBA8 upload jobs, waited for their completion fences, then returned the 1 MiB buffer to the idle pool followed by the 2 MiB buffer.

Configured cap Idle after first return Idle after both returns
Default (512 MiB) 1 MiB 3 MiB
0 MiB 0 MiB 0 MiB
1 MiB 1 MiB 1 MiB

With the 1 MiB cap, the next small upload reused the same buffer. Idle capacity dropped to zero while it was checked out and returned to 1 MiB after its fence completed. All three runs passed byte-for-byte readback checks for both textures and the subsequent refresh, with zero skips. These measurements cover idle buffer capacity on WARP. I didn’t measure process memory, physical GPU performance, or loading in the retail game.

I used OpenAI Codex with GPT-6.2 Sol to write and run the test. A separate GPT-6.2 Sol agent verified the artifact and logs. GPT-6.2 Astra drafted this comment.

I reviewed and approved this comment before posting.

@pickles976

Copy link
Copy Markdown

Exact production d6d529c verified on RTX 4060 Laptop/Wine 11, with only a local test fixture added to texture_upload.rs.

cargo test --locked --target x86_64-pc-windows-msvc -p xcl --lib idle_upload -- --nocapture --test-threads=1: 2/2 pass, 0 ignored, 2.53 s after fresh intended-worktree compile32.86 s. Includes the owner's parser/policy test and a new three-child real-GPU consumer fixture. Each child independently initializes the once-read setting and requires NVIDIA vendor0x10de/non-software through the actual D3D12 device's adapter LUID.

A 64x64 R8 upload plus 1024x1024 RGBA8 burst allocate 1 MiB and4 MiB staging jobs, neither counted idle while checked out. Both jobs are returned only after real queue-fence completion:

XCL_UPLOAD_KEEP_MB Completed idle buffer capacity
0 0 MiB
2 1 MiB
8 5 MiB

All GPU texels remain correct after trimming. A second differently patterned small upload reuses the original smallest-fitting buffer when retained; with zero retention it still returns every correct byte. The large texture remains intact after this subsequent upload. Device remains healthy in all three fresh processes. No fake fence completion or shader dispatch.

This verifies the actual allocated idle-pool cap and data correctness, not OS resident-RAM reduction, in-flight retirement under a stalled GPU, native Windows, title memory peaks, or improved frame times. Lowering the cap can increase allocation churn/stutter; no new default recommended without matched real loading measurements. The fixture's retained-capacity figures are not RSS.

Linux6.17/i7-13620H/16 GiB RAM/8 GiB VRAM, NVIDIA590.48.1, masking disabled; diagnostic-relaxed-vtable vkd3d2576c0b4adfae4a+, not stock certification. All guards unchanged. GPUpeak238 MiB, availableRAM minimum9120.3 MiB. Evidence .compat-runtime/logs/verify-xcl3050-idle-pool-texels-20261127T184950Z/.

Next useful owner measurement: matched burst/reuse workload or loading trace with allocation count and frame-time tails at a smaller retention cap, separating idle capacity from pending uploads and actual resident memory.

@andrewDoing

Copy link
Copy Markdown
Contributor

I checked the activity-line wording on RTX 5070 / NVIDIA 616.92 at head d6d529c2f7d725f12b157aeb25fe59513dc390f4 with a test-only fixture using the production upload queue and upload_line.

A queue fence held the upload until released. While its upload fence was incomplete, the line reported 0 MB idle / 1 MB the GPU has not read yet. After signaling the gate and waiting for the actual upload fence to complete, but before another upload or reclamation, the line was unchanged. The texture readback matched all 4,096 expected bytes. After invoking the production reclaim function, the line changed to 1 MB idle / 0 MB the GPU has not read yet.

The focused test passed with no skips. The queued count therefore includes completed staging buffers awaiting reclamation; it is not an exact measure of bytes the GPU still has to read. Wording such as “submitted upload buffers awaiting reclamation” would distinguish that accounting from fence progress. This is an activity-reporting observation, not an upload corruption or process-memory measurement.

AI use: OpenAI Codex with GPT-6.2 Astra built and ran the fixture; Codex reviewed and prepared this report.

Prime1997 added a commit to Prime1997/xcl that referenced this pull request Nov 27, 2026
The line said its second number was what the GPU had not read yet, but the
count includes buffers whose upload finished and that wait for the next
reclaim (andrewDoing's fixture on xcl-dev#3050: unchanged after the fence until
reclaim ran). It now says what it counts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Prime1997

Copy link
Copy Markdown
Collaborator Author

Thanks to all three of you. @Gevroska and @pickles976: agreed, the default stays at 512 MiB until a loading run with a smaller cap measures allocation churn and frame-time tails. The run in the description only measured what's kept idle (378 MB at 277 s).

@andrewDoing: right, the second number includes finished uploads that are waiting for the next reclaim. 94b7a07 now words it as "submitted and not taken back yet". The new head's suite and smoke are in the description.

AI use: Claude Code (Claude Opus 5.5) wrote this reply; Prime posted it.

Refresh the existing PR xcl-dev#3050 on nvidia-dev. Preserve its configurable idle cap and submitted-versus-idle diagnostics, and cover actual allocation, trimming and reuse in isolated WARP processes without submitting GPU work. Keep active buffers alive and document that this limits system-memory upload heaps, not live textures or total process commit.

Original implementation: d6d529c and 94b7a07 (Prime / Claude Code). Refreshed and tested with Codex (GPT-6).
@Prime1997
Prime1997 force-pushed the contrib/nv-upload-keep branch from 94b7a07 to cbb909c Compare November 28, 2026 08:38
@JJAutoCompare

Copy link
Copy Markdown

Tested

Exact cbb909c08ca786b4ddfeaf95b686aa105bec43e4 on native Windows 11 x64 build 26200.9974, Ryzen 7 3800X, and Rust 1.100.1 MSVC debug. I reran the pinned libtest after verifying all 386 original Git blobs and reconstructing the private test insertion in memory.

I ran <libtest.exe> hle::d3d12x::title_textures::tests::warp_upload_accounting_until_reclaim --exact --nocapture --test-threads=1 in two fresh processes with XCL_ADAPTER=warp, XCL_NETWORK=0, and XCL_UPLOAD_KEEP_MB=0 then 2. Both processes identified Microsoft Basic Render Driver (1414:008c) with the DXGI software flag and matching adapter and D3D12 device LUIDs.

  • On one DIRECT queue, the gated reclaim poll and the completed fence before explicit reclaim both left 1,048,576 bytes submitted and zero idle. The activity line reported 0 MB idle, 1 MB submitted and not taken back yet.
  • Explicit reclaim reduced submitted bytes to zero in both runs. Idle stayed at zero with cap 0 and rose to 1,048,576 bytes with cap 2. Both readbacks matched all 4,096 bytes against 0x77, and both device health checks returned S_OK.

2 passed, 0 failed, 0 ignored, 0 runtime skips. Both native processes exited 0, with 1,808 tests filtered out each.

Not tested

Physical GPUs, cross-queue or queue-release behavior, pool reuse, process memory, timing, retail smoke, or the full suite.

AI use

T3 Code through the Codex harness (gpt-6.2-sol) verified the source and executable, reran the two tests, and wrote this report.

@Gevroska

Copy link
Copy Markdown

Thanks, Prime. On my RTX 3080, lowering the cap from 512 to 128 MiB reduced peak sampled idle upload capacity from 504 to 124 MiB and increased staging-buffer allocations from 15 to 64 during loading. I’d keep the 512 MiB default. The allocation trade-off showed up clearly, but the two runs didn’t isolate the cap’s effect on frame times.

I used the same instrumented build based on 94b7a070, identical starting DXIL caches, and a 20-minute window after Confirm in each run. The PR has since advanced to cbb909c0. The timing samples below are intervals between host presents during loading.

After Confirm 512 MiB 128 MiB
Staging allocations / idle-buffer reuses 15 / 1,270 64 / 1,320
Cap evictions 3 59
Peak sampled idle upload capacity 504 MiB 124 MiB
Host-present intervals measured 766 672
p95 / p99 interval 172.7 / 1,116.4 ms 290.1 / 2,198.5 ms
Time from last host present to end of window 1,109.4 s 1,054.0 s

All 59 evictions at 128 MiB occurred about 60–140 seconds after Confirm. Present intervals were already longer in that run during the first 45 seconds, before its first eviction. The p99 ordering also changed with the observation window: over the first 90 seconds, p99 was 657.1 ms at 128 MiB and 1,116.4 ms at 512 MiB. I wouldn’t attribute the higher full-window p99 to the smaller cap from this pair alone.

An initial 512 MiB attempt hit DXGI_ERROR_DEVICE_HUNG about 48 seconds after Confirm. The completed pair was the 128 MiB run followed by a fresh 512 MiB repeat. Both completed runs exited on schedule without a crash or device removal. Both stopped presenting during loading, and neither showed gameplay.

I used OpenAI Codex with GPT-6.2 Sol to implement and calibrate the measurement and run the comparison. A separate GPT-6.2 Sol agent verified the saved evidence. GPT-6.2 Astra drafted this comment.

I reviewed and approved this comment before posting.

@thehollowedone

thehollowedone commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Current-main integration check for #3050 head cbb909c0 against main fa204595: Git merged without a text conflict, but cargo check -p xcl --all-targets fails with E0609 at upload_line(). Main changed ON_QUEUE values to Arc<Mutex<Option<QueueUploads>>>; the PR still reads q.bytes directly.

I revised my earlier suggested adaptation after checking its lock behavior. Cloning queue handles under the registry lock fixes compilation, but blocking on each queue state can pause the shared activity/PSO-pressure sampler while upload reclamation waits on the GPU, for up to 10 seconds in that path. The uncommitted candidate below uses try_lock. If any queue is busy, it reports the submitted total as unavailable for that sample instead of silently undercounting it. The upload cap and PSO-pressure inputs are unchanged. This is a source-proven contention path, not a measured frame-rate claim. The sampled total is approximate across queues.

The new upload_line_does_not_wait_for_a_busy_queue regression failed with my earlier blocking-lock adaptation (0 passed, 1 failed, timeout), then passed with the candidate. On the combined, uncommitted tree, cargo check --offline --locked -j 4 -p xcl --all-targets passed; cargo test --offline --locked -j 4 -p xcl --lib hle::d3d12x::title_textures::tests:: -- --test-threads=4 recorded 64 passed, 0 failed, 1 ignored; cargo test --offline --locked -j 4 -p xcl --lib idle_upload -- --test-threads=1 recorded 2 passed, 0 failed, 0 ignored. Windows 11 build 26300, RTX 3080 Ti / 621.35, Ryzen 7 9800X3D. The candidate also corrects the README wording: a submitted buffer may be GPU-complete yet still await reclamation.

I have not run the full workspace suite or paired clean-commit title smoke for this uncommitted integration. The author should rebase, apply or adapt the diff, and run those gates on the clean new head.

Current-main integration and nonblocking diagnostic diff
diff --git a/README.md b/README.md
index e5b02cfa..994e1530 100644
--- a/README.md
+++ b/README.md
@@ -337,7 +337,7 @@ Fill the reusable DXIL cache ahead of a run with the read-only package wrapper.
   - `XCL_UPLOAD_KEEP_MB`: the most completed texture-upload buffers to keep for reuse, in MiB
     (default 512, range 0–4096; `0` releases them all). This limits idle system-memory upload
     heaps; buffers still in use and textures in video memory are unaffected. The activity log
-    reports idle upload memory separately from uploads waiting for completion.
+    reports idle upload memory separately from submitted buffers awaiting reclamation.
   - `XCL_SKIP_BINK`: skips the Bink 2 movies of a title that ships a `bink2*.dll` (its logos and
     intros), by taking them straight to their last frame without decoding. Off when unset or `0`,
     `off`, `false` or `no`; `all` also skips looping movies; any other value (`1`, `intro` …)
diff --git a/crates/xcl/src/hle/d3d12x/title_textures.rs b/crates/xcl/src/hle/d3d12x/title_textures.rs
index 6371a317..050fe24b 100644
--- a/crates/xcl/src/hle/d3d12x/title_textures.rs
+++ b/crates/xcl/src/hle/d3d12x/title_textures.rs
@@ -2584,8 +2584,13 @@ pub(super) fn forget_queue(id: super::present::QueueId) {
 /// The memory line of the texture upload buffers (`XCL_ACTIVITY`): system memory the process holds
 /// for them, idle, and submitted but not yet taken back (`reclaim`: done on the GPU or not).
 pub fn upload_line() -> String {
-    let in_flight: u64 = ON_QUEUE.lock().unwrap().values().map(|q| q.bytes).sum();
-    format!("texture upload buffers: {} MB idle, {} MB submitted and not taken back yet", texture_upload::idle_bytes() >> 20, in_flight >> 20)
+    let queues: Vec<_> = ON_QUEUE.lock().unwrap().values().cloned().collect();
+    let in_flight: Option<u64> = queues.iter().map(|q| q.try_lock().ok().map(|s| s.as_ref().map_or(0, |u| u.bytes))).sum();
+    let idle = texture_upload::idle_bytes() >> 20;
+    match in_flight {
+        Some(bytes) => format!("texture upload buffers: {idle} MB idle, {} MB submitted and not taken back yet", bytes >> 20),
+        None => format!("texture upload buffers: {idle} MB idle, submitted amount unavailable"),
+    }
 }
 
 /// upload buffers the GPU has not read yet, before a submit waits for it: a moment past the first,
@@ -4229,6 +4234,22 @@ pub(super) unsafe fn prepare_texture_download(
 pub(super) mod tests {
     use super::*;
 
+    #[test]
+    fn upload_line_does_not_wait_for_a_busy_queue() {
+        let state = Arc::new(Mutex::new(None));
+        let key = Arc::as_ptr(&state) as usize;
+        ON_QUEUE.lock().unwrap().insert(key, Arc::clone(&state));
+        let held = state.lock().unwrap();
+        let (tx, rx) = std::sync::mpsc::channel();
+        let worker = std::thread::spawn(move || tx.send(upload_line()).unwrap());
+        let sampled = rx.recv_timeout(std::time::Duration::from_secs(2));
+        drop(held);
+        worker.join().unwrap();
+        ON_QUEUE.lock().unwrap().remove(&key);
+        let line = sampled.expect("the activity sampler must not wait for upload reclamation");
+        assert!(line.contains("submitted amount unavailable"), "{line}");
+    }
+
     /// A 64x64 R8 texture's upload from memory full of `value`, with that memory.
     fn r8_item(texture: &ID3D12Resource, value: u8) -> (texture_upload::Item, Vec<u8>) {
         let tex = Arc::new(xg::Texture::new(&console_desc(3, 64, 64, 1, 1, 61, 1)).unwrap());

AI use: Codex (GPT-6.2 Sol) reproduced the compile and lock-wait failures, wrote the candidate and regression, and ran the checks; Codex (GPT-6.2 Astra) reviewed the queue-state and sampling invariants.

@Kalmarv

Kalmarv commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

merge-check
base: beeb81b (merges cleanly as text, but fails to compile on main)
head: cbb909c
merge: clean as text, fails to build on main
build: fails as posted — title_textures.rs upload_line sums q.bytes over ON_QUEUE, whose values on main are per-queue Arc<Mutex<Option>> (QueueUploadState). Adapted locally to read each queue under its own lock after releasing ON_QUEUE; then builds ok.
tests: with local adaptation, non-GPU lib tests of touched modules (texture_upload 5 passed, title_textures 7 passed / 1 ignored). Full workspace suite and WARP child-process test not run.
review: needs rebase onto main for per-queue QueueUploadState. Otherwise diff looks clean: default keep limit unchanged (512 MiB), XCL_UPLOAD_KEEP_MB capped at 4096.
performance: default unchanged (512 MiB); one activity line every 20 s. Tested in a combined 600 s retail run on main beeb81b + 13 PRs (warm cache, defaults) vs baseline: presents/2 s 3.27 vs 3.29, peak commit 35,016 vs 35,767 MB, local video memory 14.19-14.76 vs 14.32-14.95 GB, 0 pipeline waits >= 1 s vs 5, 0 device removals, 0 crashes. Combined result across all 13 PRs, not isolated to this PR.
verdict: not yet: does not compile on current main (needs rebase for QueueUploadState); full suite not run.
hardware / tool and model: NVIDIA GeForce RTX 5070 Ti, driver 32.0.16.1074, AMD Ryzen 9 9950X, Windows 11 Pro 26200 / Claude Code (claude-opus-5-5)

@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:docs-ci Documentation, scripts, workflows, repo governance gpu:nvidia Code is specific to NVIDIA / wave32 GPUs (scope tag; see needs:nvidia-test) needs-pr-check Failing the PR description check (CONTRIBUTING.md) labels Nov 29, 2026

@bmjask bmjask left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Critical review of current head cbb909c0. Current-main build blocker despite a text-clean merge: upload_line sums q.bytes over ON_QUEUE, but main changed its values to per-queue Arc<Mutex<Option<QueueUploads>>>; the merged tree fails with E0609. See the current-main integration report. Please rebase and read queue upload state through its lock after releasing the outer map lock, then rerun all-targets check and the WARP upload test. The configurable idle limit is otherwise scoped correctly; it does not bound active allocations. No local Windows run.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Review (head cbb909c, diff read, not a merge-check; draft with PR description red, so not built or run):

  • It doesn't compile on current main. The textual merge is clean, but upload_line reads q.bytes from ON_QUEUE, which on main holds Arc<Mutex<Option<QueueUploads>>> (title_textures.rs ~2551-2555). CI passed only against nvidia-dev 54225f5, before the base changed to main. A fix that locks each queue's state would block the log thread while submit_on holds it (up to 10 s in reclaim); a try-lock or a separate counter avoids that.
  • An invalid XCL_UPLOAD_KEEP_MB (64MB, -1) silently falls back to 512; worth a log line.
  • The description says main "uses a different uploader", but main's live path is submit_on -> give_back with the fixed FREE_BYTES = 512 MiB (texture_upload.rs ~795), exactly what this makes configurable (and the right place for the trimming D3D12.X: release large texture upload buffers after idle #3194 attempted). No smoke blocks.

Fine: only buffers whose fences completed reach the pool, so trimming is safe; the default stays 512 MiB; parsing and the 4096 cap are right; the tests run in separate WARP processes and fail without the switch.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Test report (not a merge-check: draft, PR description red)
base: b2b1f10
head: cbb909c
merge: clean (no textual conflict)
build: cargo build --workspace -> failed: error[E0609] at crates/xcl/src/hle/d3d12x/title_textures.rs ~2587, ON_QUEUE.lock().unwrap().values().map(|q| q.bytes): on main each ON_QUEUE value is now an Arc<Mutex<Option<QueueUploads>>> (per-queue upload state), so there's no bytes field to read without locking each queue's entry. The upload bookkeeping changed on main since this PR's base, so it needs a rebase onto the per-queue state.
tests: not run (no build).
review: not repeated here; my review of this same head is at #3050 (comment), and its findings stand. This run adds what reading couldn't: whether the change merges, builds and passes the whole suite on current main.
performance: not measured.
assessment: needs a rebase onto current main's per-queue upload state; the findings in my review stand
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5

AI-written and posted by Foniass without a human check of each point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:docs-ci Documentation, scripts, workflows, repo governance gpu:nvidia Code is specific to NVIDIA / wave32 GPUs (scope tag; see needs:nvidia-test) needs-pr-check Failing the PR description check (CONTRIBUTING.md)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants