Skip to content

D3D12.X: pool async upload command lists, raise staging item cap to 32 MiB, and lower parallel detile threshold - #2989

Closed
Saksukella wants to merge 270 commits into
xcl-dev:amd-devfrom
Saksukella:perf/texture-upload-pool
Closed

Saksukella wants to merge 270 commits into
xcl-dev:amd-devfrom
Saksukella:perf/texture-upload-pool

Conversation

@Saksukella

Copy link
Copy Markdown
Contributor

Pools async texture upload (ID3D12CommandAllocator, ID3D12GraphicsCommandList) pairs per device, raises STAGING_POOL_MAX_ITEM from 8 MiB to 32 MiB to match BATCH_BYTES, and lowers PARALLEL_BYTES from 1 MiB to 256 KiB.

Root cause & summary of changes

Profiling 240 s world-streaming runs on AMD Radeon RX 9070 XT showed texture uploads consuming 6.4–7.1 s total (3,200–3,500 calls, peak 765–886 ms / 2 s with single-batch spikes of 543–725 ms):

  1. crates/xcl/src/gpu/texture.rs — Per-device async upload command list/allocator pool (CMD_POOLS):
    • submit_batch previously created and destroyed a fresh ID3D12CommandAllocator + ID3D12GraphicsCommandList on every batch (~3,500 COM allocations per run).
    • Adds bounded LIFO CmdPool (CMD_POOL_MAX_PER_DEV = 16) with XCL_UPLOAD_CMD_POOL=0 kill-switch (default enabled). acquire_upload_cmd resets a pooled allocator + list with safe fresh-creation fallback; CmdSlot inside InFlight only recycles the pair on InFlight::drop (strictly after the queue fence completes in title_textures::reclaim*) and trims idle entries on low_commit.
  2. crates/xcl/src/gpu/texture.rs — Raise STAGING_POOL_MAX_ITEM from 8 MiB to 32 MiB:
    • Matches title_textures::BATCH_BYTES = 32 MiB so 8–32 MiB streaming bursts stay inside STAGING_POOLS instead of falling back to unpooled CreateCommittedResource on an UPLOAD heap (which caused 200–725 ms WDDM allocation hitches), while keeping STAGING_POOL_DEFAULT_CAP = 256 MiB, 2 s / 30-frame idle reclamation, and immediate low_commit eviction intact.
  3. crates/xcl/src/hle/d3d12x/title_textures.rs — Lower PARALLEL_BYTES from 1 MiB to 256 KiB:
    • Engages the persistent DetilePool for 256 KiB–1 MiB medium texture streaming bursts.

Tested

  • Unit & live D3D12 GPU tests on amd-dev (bf7c82ee + 7dece6b4, --test-threads=1, 0 new warnings):
    • cargo test -p xcl --lib gpu::texture -- --test-threads=1: 18 passed; 0 failed; 1 ignored, including:
      • cmd_pool_reuses_lifo_enforces_cap_and_handles_disabled (pure-CPU)
      • staging_pool_buckets_caps_reuses_and_reclaims_idle (updated for 16/32 MiB buckets)
      • gpu_submit_batch_reuses_cmd_list_and_16mib_staging_pixel_exact (live D3D12 GPU test verifying exact COM pointer reuse, 16 MiB staging bucket reuse, and bit-exact readback)
    • cargo test -p xcl --lib hle::d3d12x::title_textures -- --test-threads=1: 33 passed (1 pre-existing unrelated failure title_bytes_are_used_in_place_when_all_are_readable on bf7c82ee base).
  • Offline D3D12 hardware microbenchmark on AMD Radeon RX 9070 XT (cargo test -p xcl --release --lib gpu::texture::tests::bench_submit_batch_pooled_vs_legacy_12mib -- --ignored --nocapture --test-threads=1, 32x 12 MiB RGBA8 submit_batch including full synchronous 384 MiB GPU DMA wait):
    • Legacy (unpooled allocator/list + 8 MiB staging cap): 124.68 ms (3.90 ms/op)
    • Pooled (reused allocator/list + 32 MiB staging cap): 77.05 ms (2.41 ms/op) -> 1.62x end-to-end speedup (eliminating 100% of per-batch CreateCommandAllocator/CreateCommandList and unpooled 12 MiB CreateCommittedResource WDDM stalls).

Not tested

  • Non-AMD GPUs (NVIDIA / Intel).
  • Multi-hour soak runs beyond 60 s smoke.

Regression run
Baseline (main, b49be183):

xcl-smoke v1
commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7
gpu: AMD Radeon RX 9070 XT
title: b8db18c2
seconds: 60
exit: 0x0
frames shown: 1624 (PresentX 1624)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 19700 MB

This PR (7dece6b4 on amd-dev bf7c82ee):

xcl-smoke v1
commit: 7dece6b41d353e4ab7d6cf1e25837a87f331479e
gpu: AMD Radeon RX 9070 XT
title: b8db18c2
seconds: 60
exit: 0x0
frames shown: 1667 (PresentX 1667)
presents per 2 s (last 3): 63 60 60
device removals: 0
crashes: 0
peak commit: 13100 MB

AI use

  • Profiling analysis, implementation, unit/GPU tests, and microbenchmark harness were assisted by AI; all tests, hardware benchmarks, and the 60 s smoke run were executed and verified locally on AMD Radeon RX 9070 XT.

madaraXor and others added 30 commits November 25, 2026 14:14
In a pixel shader EXEC holds helper lanes (s_wqm), and on a primitive's
edge the first lane of EXEC is often one. v_readfirstlane read that lane.
An RDNA2 driver (RX 6700 XT, 32.0.21045) gives 0 for everything a helper
lane holds once a WaveReadLaneAt ran inside a loop, quad reads included.
A loop whose state the console's compiler carries in a vector register
(v_mov v, s ... v_readfirstlane s, v) then read 0 back on each pass and
ran to the loop budget: a retail title's volumetric light pass took
seconds per draw at its world start and Windows reset the GPU (xcl-dev#675).

v_readfirstlane now reads the first lane of EXEC that is live
(ballot(true), per half in the wave32-in-64 form) when EXEC has one, and
the first lane of EXEC as before when it has none. The value is the same:
the console's compiler reads the first lane of a value equal in every
lane, or of a lane it then removes from EXEC (a waterfall loop).

The new GPU test draws that title's list-loop shape on two triangles
sharing a diagonal. Without the change, on the RX 6700 XT, 69 of 1024
pixels run the loop 65 536 times (the budget) with wrong results; with
it, none, and at most 16 passes.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A retail game unmaps addresses while it streams its world with
XMemMapPhysicalPagesScatter(addresses, n, NULL); it checks the result
and runs into its own int3 when the call fails (+0xb18de7, then its
crash reporter). XCL refused a NULL page array with
ERROR_INVALID_PARAMETER. Page 0 already means "unmap this address" in a
scatter, so no array is taken as page 0 for every address.

Test scatter_without_pages_unmaps: two pages mapped and written, unmapped
with no array (the call succeeds, the addresses are no longer committed),
mapped again they read what was written. It fails without the change
("refused").

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A retail title keeps its destination page lists in slots of its own
table and writes a slot's pages after EnqueueRequest. At enqueue such a
slot can still name the pages of the slot's previous request, and the
snapshot taken then is what execute() wrote to (xcl-dev#289 rereads only the
entries that are 0). Over 16 000 requests a run were written into pages
the title had since reused: its objects got garbage pointers and it
crashed about 20 s into world loading; when the old pages were freed,
the request failed with E_ACCESS_VIOLATION.

The console reads the list when it runs the request. execute() now
reads it again (through read_own, as the snapshot) and takes it when it
differs and every page in it is allocated (kernelx::physical_pages_live).
A list that was on the enqueuing thread's stack keeps the snapshot: that
memory is reused once the call returns, and a page ID written there
since can belong to another live allocation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…heir pages with their texels

A retail title places its streamed textures at full size and has memory behind
their levels only as it loads them, the small ones first. vram::place_pages
gives a sampled texture a 64 KiB page of video memory for every tile at once:
when that title's world is set up about 92 % of those pages have nothing behind
them (80 690 pages, 6 809 committed, on one card).

With the switch (off by default) a sampled 2D texture of one slice is placed
with no tile mapped. Its tiling is kept as groups of tiles, one for each level
with tiles of its own and one for the packed levels, and a group gets its pages
before the first upload that has texels for it - the same pages by address as
before, so textures placed at one address still share them. A texture the GPU
writes gets all its pages.

Part of xcl-dev#1773.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… done

When the GPU-wait watchdog releases a wait (xcl-dev#505), its lines say which
queues wait on which, but not what the GPU is running. With
XCL_GPU_CULPRIT=1 every dispatch XCL records (title lists,
console-recorded lists, ExecuteIndirect of a translated compute
pipeline) is wrapped in WriteBufferImmediate markers, in before and out
after, one pair of words per PC list in a readback buffer. At a release
the lists whose marker in is above their marker out are logged with the
dispatches between the two: console CS (fnv64 of the title's bytecode),
PC pipeline and groups.

On the retail title of xcl-dev#505 (RTX 5080) this named, at each stall, one
list with a run of 1-D dispatches of one CS whose first never finished;
not the same CS from run to run. DRED breadcrumbs were tried first: they
change the driver's pipeline cache keys, so every pipeline was built
again and the title never got past its start.

Off by default; without the variable nothing is recorded.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ivall and others added 8 commits November 26, 2026 23:28
Port xcl-dev#2859. Keep a readable dword beyond the logical blob length for the driver.

Assisted-by: Claude (exact model unknown), Codex (GPT-6 family, exact model unknown)
Port xcl-dev#2842. Check the fence after each event wake-up and keep a timed-out staging job alive while the GPU can still write to it.

Assisted-by: Claude (exact model unknown), Codex (GPT-6 family, exact model unknown)
A shared fence could move backward as separate title queues completed out of order. Signal a separate fence on each source queue.

Assisted-by: Claude (exact model unknown), Codex (GPT-6 family, exact model unknown)
Port xcl-dev#2630. Smaller pools let more video memory return when a title frees runs of tiles and keeps the tiles between them.

Assisted-by: Claude (exact model unknown), Codex (GPT-6 family, exact model unknown)
Keep full read-write sparse pages GPU-only until the title touches them on the CPU. Preserve title-facing query and protection behavior for lazy pages.

Assisted-by: Claude (exact model unknown), Codex (GPT-6 family, exact model unknown)
Record the compute, graphics or mesh pipeline in the driver when compilation stops the process. Skip the recorded pipeline on later launches and retain the available shader diagnostics.

Assisted-by: Claude (exact model unknown), Codex (GPT-6 family, exact model unknown)
Track active profiling spans, queue waits and submissions, and report the dispatch associated with a device removal.

Assisted-by: Claude (exact model unknown), Codex (GPT-6 family, exact model unknown)
@thehollowedone

Copy link
Copy Markdown
Contributor

Independent Windows/NVIDIA check of #2989 head 7dece6b4: Windows 11 build 26300, RTX 3080 Ti (621.35), Ryzen 7 9800X3D, Rust 1.99.1 MSVC.

  • With XCL_REQUIRE_GPU=1, cargo test --offline --locked -j 4 -p xcl --lib gpu::texture -- --test-threads=1 --nocapture: 18 passed, 0 failed, 1 ignored, no GPU skip. The native gpu_submit_batch_reuses_cmd_list_and_16mib_staging_pixel_exact ran and passed.
  • On the local candidate below, cargo test --offline --locked -j 4 -p xcl --lib gpu_an_upload_still_running_is_kept_when_its_wait_times_out -- --nocapture --test-threads=1: 1 passed, 0 failed, 0 ignored, no GPU skip.

One failure-path issue: after submit_batch has submitted the command list, submit_on_title_queue calls texture::wait(...)? if creating or signaling its tracking fence fails. If that fallback wait also fails or times out, ? drops InFlight without proof of completion. This PR's new CmdSlot::drop returns the submitted allocator/list to the pool; a later upload can reset the allocator while its GPU commands may still be running. Staging reuse on this path predates this PR. #1486 treats an analogous failed-wait lifetime problem elsewhere.

The candidate retains the entire submitted batch when the fallback wait cannot establish completion, while preserving normal release after a successful wait. A focused drop-probe test failed with the old wait()?; drop(batch) behavior (0 passed, 1 failed) and passed with the candidate (1 passed, 0 failed). This injects a wait-result failure into the ownership helper; I did not force a real D3D12 CreateFence or Signal failure. Repeated ambiguous failures would retain one batch each until process exit; a larger recovery path could quarantine them against a later proven fence or stop further submits.

Candidate correction and regression diff
diff --git a/crates/xcl/src/hle/d3d12x/title_textures.rs b/crates/xcl/src/hle/d3d12x/title_textures.rs
index c16ef6cb..e8c3e10d 100644
--- a/crates/xcl/src/hle/d3d12x/title_textures.rs
+++ b/crates/xcl/src/hle/d3d12x/title_textures.rs
@@ -1617,6 +1617,15 @@ unsafe fn reclaim(dev: &ID3D12Device, q: &mut QueueUploads, cap: u64, wait_ms: u
     }
 }
 
+/// A submitted batch may be released only when the fallback wait proves GPU completion.
+/// If waiting fails, retain its command allocator and staging bytes for this process.
+fn release_after_upload_wait<T>(batch: T, wait: impl FnOnce() -> Result<(), String>) -> Result<(), String> {
+    let batch = std::mem::ManuallyDrop::new(batch);
+    wait()?;
+    drop(std::mem::ManuallyDrop::into_inner(batch));
+    Ok(())
+}
+
 unsafe fn submit_on_title_queue(dev: &ID3D12Device, queue: &ID3D12CommandQueue, batch: &[(ID3D12Resource, Vec<Subresource>, Vec<D3D12_RESOURCE_STATES>)]) -> Result<Vec<(usize, String)>, String> {
     // Wait for any tile mappings queued since `queue` last waited (from another thread or from
     // `map_levels_with_texels` above) so copy-engine writes never hit unmapped tiles.
@@ -1631,8 +1640,7 @@ unsafe fn submit_on_title_queue(dev: &ID3D12Device, queue: &ID3D12CommandQueue,
                 g.insert(key, QueueUploads { fence, value: 0, in_flight: std::collections::VecDeque::new(), bytes: 0 });
             }
             Err(e) => {
-                texture::wait(dev, queue)?;
-                drop(f);
+                release_after_upload_wait(f, || texture::wait(dev, queue))?;
                 return Err(e.to_string());
             }
         }
@@ -1641,8 +1649,7 @@ unsafe fn submit_on_title_queue(dev: &ID3D12Device, queue: &ID3D12CommandQueue,
     q.value += 1;
     if let Err(e) = queue.Signal(&q.fence, q.value) {
         q.value -= 1;
-        texture::wait(dev, queue)?;
-        drop(f);
+        release_after_upload_wait(f, || texture::wait(dev, queue))?;
         return Err(e.to_string());
     }
     super::flight::signaled("texture uploads", key, &q.fence, q.value);
@@ -2222,6 +2229,24 @@ unsafe fn subresources(va: usize, tex: &xg::Texture) -> Vec<Subresource> {
 mod tests {
     use super::*;
 
+    #[test]
+    fn failed_upload_wait_retains_submitted_resources() {
+        use std::sync::atomic::{AtomicUsize, Ordering};
+
+        struct Probe<'a>(&'a AtomicUsize);
+        impl Drop for Probe<'_> {
+            fn drop(&mut self) {
+                self.0.fetch_add(1, Ordering::SeqCst);
+            }
+        }
+
+        let drops = AtomicUsize::new(0);
+        assert_eq!(release_after_upload_wait(Probe(&drops), || Err("wait failed".into())), Err("wait failed".into()));
+        assert_eq!(drops.load(Ordering::SeqCst), 0, "completion unknown: batch must not be recycled");
+        assert_eq!(release_after_upload_wait(Probe(&drops), || Ok(())), Ok(()));
+        assert_eq!(drops.load(Ordering::SeqCst), 1, "completed batch can be recycled");
+    }
+
     #[test]
     fn content_hash_avx2_zero_fast_path_matches_scalar() {
         let mut page = vec![0u8; 4096];

Not tested: full workspace suite, Intel/AMD hardware, or a paired title smoke run on this machine. No game files were used. AI use: Codex (GPT-6.2 Sol) ran the tests and wrote the candidate; Codex (GPT-6.2 Astra) reviewed the submitted-resource lifetime and candidate.

@SzczepanGrela

SzczepanGrela commented Nov 27, 2026 •

Copy link
Copy Markdown

Updated RX 9070 / Wine check on d1167f8d373547fa1c85e36fa8c9a8e550d8c551, including the failed-wait correction following the earlier lifetime report. The control for this update is its actual parent/previous head 7dece6b41d353e4ab7d6cf1e25837a87f331479e; the PR targets amd-dev bf7c82ee1b2685bb40417e09c4128177aa68d719.

RX 9070 16 GB (RADV GFX1201), Ryzen 7 7700, CachyOS kernel 7.3.6-1-cachyos, Mesa 26.3.1-5, GE-Proton11-12 / Wine 11.0 Staging, ntsync. Native vkd3d-proton 8293130ebe370b1+, local asserts-disabled build; Rust 1.97.1, Windows-GNU release. Private enabled caches per process. Copied source trees with appended tests; production functions and original assertions unchanged.

Tested

  • The original staging-growth/pool tests, command-pool CPU test and gpu_submit_batch_reuses_cmd_list_and_16mib_staging_pixel_exact, plus the new head's failed_upload_wait_retains_submitted_resources: at both --test-threads=1 and 4, head 5 passed / 0 failed; previous head 4 passed / 0 failed; 0 ignored or skipped.
  • A local native probe submits a real InFlight containing a command allocator/list and pooled staging, while its queue is blocked on a CPU-controlled fence. It calls the real new release_after_upload_wait with an injected failed wait result. At helper return the queue fence is still 0, and neither command pair nor staging is in the idle pools. The previous-head control uses the former wait()?; drop(batch) sequence at the same ownership boundary: both resources are already cached while the fence is 0. Three fresh processes per source: the pool-retention assertion fails on the previous control (0 passed / 1 failed each) and passes on the new head (1 passed / 0 failed each), 0 ignored/skipped.
  • A successful-wait control in the same probe first establishes real GPU completion: both sources then cache one command pair and its 64 KiB staging. Both texture payloads read back correctly on both sources. The fixture always releases/drains the queue before pool cleanup or CPU assertions, and never resets/reuses an allocator while its GPU work is pending. The new failed-wait batch remains retained for the process lifetime, as this correction intends.
  • Repeated the normal native submit_batch matrix three fresh times per source with XCL_UPLOAD_CMD_POOL=1 and 0: 18 held upload batches, cap 16 with two overflow entries uncached, 16 LIFO command-pair reacquisitions, full small-texture contents, low-commit idle-pool clearing, and large textures at 8 MiB + one row, 12 MiB, exactly 32 MiB and 32 MiB + one row. Both sources retain the same 16/32 MiB staging reuse and command-pool off behavior. All 14 normal fixture invocations, including two pilots, passed (1 passed / 0 failed / 0 ignored / 0 skipped each).

In this update: 24 processes, 504 full texture readbacks, 1,668,153,344 bytes independently checked with a separate row/column CPU oracle. All payloads agree; 0 new-head test failures, 0 device removals, 0 hidden skips. The three expected previous-control failures concern early pool return, not corrupted readback data.

cargo test --offline --locked --release --target x86_64-pc-windows-gnu -p xcl --lib --no-run
wine <test-exe> <original-test-filters> --exact --nocapture --test-threads=1
wine <test-exe> <original-test-filters> --exact --nocapture --test-threads=4
wine <test-exe> hle::d3d12x::title_textures::workflow_failed_wait::workflow_actual_batch_failed_wait_retains_resources --exact --nocapture --test-threads=1
wine <test-exe> gpu::texture::workflow_upload_native::workflow_upload_pool_lifetime_cap_and_full_pixels --exact --nocapture --test-threads=1

Original filters are under gpu::texture::tests::: large_staging_uses_sixteen_mib_growth_steps, staging_pool_buckets_caps_reuses_and_reclaims_idle, cmd_pool_reuses_lifo_enforces_cap_and_handles_disabled, and gpu_submit_batch_reuses_cmd_list_and_16mib_staging_pixel_exact; the new-head-only filter is hle::d3d12x::title_textures::tests::failed_upload_wait_retains_submitted_resources.

The two workflow_* tests are local fixtures, not upstream tests. My earlier normal-path comparison of 7dece6b4 against bf7c82ee remains a separate archived result: 15 processes, 372 full readbacks, 1,263,583,232 verified bytes. It is not a measurement of the new head.

Not tested: actual native CreateFence/Signal failures or a real 10 s timeout, the complete submit_on_title_queue caller, repeated-error recovery/memory bounds, concurrent CPU submitters, reset-failure injection, parallel detile threshold, whole suite, retail/title/smoke or performance. Both fallback call sites were checked in source. Automatic integration into current main 83b0081 still conflicts in both changed files and was not built.

AI use: OpenAI Codex (GPT-6; exact serving variant not exposed) reviewed both public revisions, wrote the appended fixtures/checker, ran the controls and full readback verification, and updated this report. Publication authorized by the account owner.

@Saksukella

Copy link
Copy Markdown
Contributor Author

Thanks @thehollowedone for the great catch and exact regression test!

Pushed
elease_after_upload_wait\ on both fallback wait error paths in \submit_on_title_queue\ (\CreateFence\ and \queue.Signal\ failures) so an \InFlight\ batch (its \CmdSlot\ allocator/list and staging buffer) is never recycled without proof of GPU completion, plus \ ailed_upload_wait_retains_submitted_resources\ (\18/18\ \gpu::texture\ + \1/1\ new test passed).

@JJAutoCompare

Copy link
Copy Markdown

Tested

Clean d1167f8d373547fa1c85e36fa8c9a8e550d8c551 on Windows 11 build 26200.9974, Ryzen 7 3800X, Rust 1.100.0 MSVC, Intel Arc A770 driver 32.0.101.9175. Built with cargo build --offline --locked -j 2 -p xcl --lib --message-format=json and cargo test --offline --locked -j 2 -p xcl --lib --no-run --message-format=json.

  • The exact CPU filters hle::d3d12x::title_textures::tests::detile_pool_reuses_workers_across_multiple_batches and hle::d3d12x::title_textures::tests::a_batch_detiled_on_several_threads_matches_one_thread both passed with --exact --nocapture --test-threads=1.
  • detile-probe.exe detile_threshold_and_ordered_readback --exact --nocapture --test-threads=1 passed on Arc. The exact-head extracted detile routines used the unmodified exact-head submit/wait path. Worker generation stayed flat at 240 KiB and for a single item at 256 KiB. It advanced for multi-item batches at 256 and 272 KiB and for a repeated 256 KiB batch. All 20 textures and 1,310,720 bytes matched on readback. Each fence remained at 0 during the CPU gate and reached 2 after drain.

Three passed, zero failed, ignored, or skipped. The probe pinned its executable and used the shared Arc mutex.

Not tested

Production high-level caller coverage, title smoke, performance, stress and full workspace suite.

AI use

T3 Code / Codex (gpt-6.2-sol) ran the original verification, independently reproduced the cases reported here, and wrote this report.

@iggyvilla

Copy link
Copy Markdown
Collaborator

Review of #2989, diff only; I did not build or run it.

  1. Possible allocator reuse while in flight. real::q_release calls title_textures::on_queue_release, which just removes ON_QUEUE[key] without waiting on q.fence (checked, title_textures.rs 1623-1628, real.rs ~9303). With this PR's CmdSlot::drop returning (alloc, list) to CMD_POOLS, dropping a not-yet-completed InFlight lets another queue's acquire_upload_cmd Reset() an allocator the released queue may still be executing. The fix would be to wait on (or hold) q.fence before dropping. (The pool-return half is in the PR diff, the on_queue_release half checked on amd-dev; the race itself is inferred.)
  2. Rebase conflict at the end of title_textures.rs mod tests with 706d0ce0 + 47cbd3aa on amd-dev 7c795f5e.
  3. Tests: failed_upload_wait_retains_submitted_resources tests release_after_upload_wait alone and would pass if submit_on_title_queue dropped the resources directly; nothing checks PARALLEL_BYTES = 256 << 10. gpu_submit_batch_... clears CMD_POOLS/STAGING_POOLS for the device at exit, which may disturb concurrent tests on the shared device.
  4. Minor: CmdSlot::recyclable is always true (dead field).

The title and description (32 MiB staging cap, pooled command lists, 256 KiB detile threshold) match the diff.

AI use: Gemini 4 Hydrogen High (agy2 for #2981, agy3 for #2985 and #2989; Antigravity) read the PR diff, its comments and the touched code and wrote the report; Claude Code (Claude Sonnet 5.5, coordinator) spot-checked the points marked "checked" against amd-dev 7c795f5e and wrote this text. Everything else is the agent's reading and was not re-verified. Nothing was built or run. The comment was posted without the account owner reading it first.

@pickles976

Copy link
Copy Markdown

Verified production head d1167f8 on Linux 6.17 / Wine 11 / i7-13620H / 16 GiB RAM / RTX 4060 Laptop 8 GiB / NVIDIA 590.48.1. Local changes are test-only strengthening in texture.rs and title_textures.rs. Diagnostic-relaxed-vtable vkd3d-proton 2576c0b4adfae4a+, not stock compatibility certification; NVIDIA masking disabled.

Results:

  • Six CPU policy/ownership checks pass: staging growth/overflow, bucket/cap/reuse/idle/low-commit behavior, command-pool LIFO/cap/disabled behavior, parallel detile parity, persistent detile workers, and failed-wait retention.
  • One strict NVIDIA upload test passes: three complete 2048x1536 RGBA8 (12 MiB) patterned readbacks, every byte checked; the same allocator/list/16 MiB staging tuple is reused after real queue completion. Idle pools remain empty while InFlight owns the batch. No silent adapter skip or deliberately stalled GPU.
  • Release benchmark, one fixed-order pair of 32 uploads per leg: legacy 231.26 ms total / 7.23 ms per upload; pooled 114.22 ms / 3.57 ms per upload (2.02x). This combines command allocation, staging allocation/reuse, CPU copies, GPU copies and completion waits. It is a directional microbenchmark, not a matched title-loading/frame-time result or an isolated allocator-only effect.

Commands used cargo-xcl-wine.sh test --locked --target x86_64-pc-windows-msvc -p xcl --lib with one test thread. GPU gates used XCL_UPLOAD_CMD_POOL=1 and XCL_STAGING_POOL_MB=256; the release benchmark additionally used XCL_ADAPTER=NVIDIA and --release --exact --ignored for gpu::texture::tests::bench_submit_batch_pooled_vs_legacy_12mib. Fresh intended-worktree compilation was confirmed: 32.17 s debug and 183 s release.

Local evidence:

  • .compat-runtime/logs/verify-xcl2989-upload-policy-20261127T180902Z-20261127T180902Z/
  • .compat-runtime/logs/verify-xcl2989-nvidia-upload-20261127T180902Z-20261127T180935Z/
  • .compat-runtime/logs/verify-xcl2989-nvidia-upload-bench-20261127T181114Z/

Limits: failed-wait coverage injects an error around a synthetic tracked holder; it is not a real native queue/device failure. Retention deliberately avoids recycling pending resources but does not provide bounded recovery after repeated failures. No pending cross-queue/queue-release lifetime certification, matched-parent comparison, retail run, measured loading-RAM saving, or gameplay claim. Guards remained 9 GiB scope / 512 MiB swap, GPU 6000 MiB, available RAM 2048 MiB and available disk 10 GiB; the release-build-inclusive minimum available RAM was 7952 MiB and disk 11.324 GiB.

Useful next owner gate: exercise fallback-wait failure together with queue teardown and subsequent recovery, proving staging/command resources remain owned until completion without unbounded retained batches. For performance, add alternating benchmark order and a matched loading trace before claiming reduced title stutter.

@DarkPanda69

Copy link
Copy Markdown

Run on an RX 9070 XT and an RTX 3060 in the same PC: the three new tests pass on both. There's also a note on title_textures tests that are already flaky on the base.

Tested: at the PR head d1167f8 against its merge-base with amd-dev, bf7c82e (the diff does not apply on today's amd-dev). Debug, Rust 1.100.0, Windows 11 Pro 26200, Ryzen 7 5800X, card picked with XCL_ADAPTER (log: backend 'real' – AMD Radeon RX 9070 XT / – NVIDIA GeForce RTX 3060).

  • cargo test -p xcl --lib -- title_textures gpu::texture cmd_pool --test-threads=4 --nocapture on the RX 9070 XT (32.0.32029.2010) and the RTX 3060 (32.0.16.1088). Merge-base → PR head: RX 9070 XT 48 passed, 2 failed → 50 passed, 3 failed, 1 ignored; RTX 3060 49 passed, 1 failed → 52 passed, 1 failed, 1 ignored (the ignored one is the new bench_submit_batch_pooled_vs_legacy_12mib). The failures are the title_textures ones below. New and ok on both: gpu_submit_batch_reuses_cmd_list_and_16mib_staging_pixel_exact, cmd_pool_reuses_lifo_enforces_cap_and_handles_disabled, failed_upload_wait_retains_submitted_resources.

title_textures on the RX 9070 XT (cargo test -p xcl --lib -- title_textures, 5 runs at --test-threads=4 and 2 at --test-threads=1 per stage):

  • title_bytes_are_used_in_place_when_all_are_readable fails in every run, with and without the PR: all 7 + 7 on the RX 9070 XT and the single run per stage on the RTX 3060 (a committed page is not copied).
  • gpu_uploads_on_the_title_queue_run_before_its_later_work_and_are_released and placed_title_textures_share_vram_and_preserve_pixels fail now and then on the RX 9070 XT: merge-base 7 of 7 runs, PR head 3 of 7. The same merge-base gave 3 of 7 in the runs for D3D12.X: pool small fallback placements in placed heaps and deduplicate xg::Texture #2985, so these counts are mostly noise; I wouldn't read them as the PR fixing anything. They didn't fail in the single RTX 3060 run per stage (I didn't repeat runs on it).

Not tested: the whole suite, a title, Intel.

AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.

@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.

The command allocator/list recycling appears fence-safe: ownership remains in InFlight, recycling happens on drop after completion, and failed waits deliberately retain the resources. I found no concrete pooling defect.

This PR nevertheless contains three independently reversible performance changes: command pooling, raising the staging item cap, and lowering the parallel-detile threshold. Please split them, or provide separate A/B measurements and kill switches for each. The detile threshold in particular is not validated by the command/staging microbenchmark. Rebase the current conflict and rerun exact-head smoke/tests.

Reviewed at d1167f8 with Codex (GPT-5).

raylitebull added a commit that referenced this pull request Nov 29, 2026
Ports the command-list pooling of upstream PR #2989 (7dece6b) to the upload path of this branch.

Upstream's submit_batch made a new allocator and list for every batch and kept staging buffers of
at most 8 MiB. Here 73fc616 had already replaced that path: an upload job (allocator, list and
mapped buffer) is kept in FREE and used again once its fence has passed. But a job was kept or let
go as a whole: a batch that none of the kept buffers fits made a new allocator and list along with
its buffer, and a job let go for XCL_UPLOAD_KEEP_MB took its list with it.

Now a job let go leaves its list and allocator in SPARE (at most 16 a device, upstream's
CMD_POOL_MAX_PER_DEV), and a new job takes one of those before it makes one. Only give_back feeds
SPARE, and it is called only once the GPU is done with the job (reclaim's fence, upload_and_wait's
wait), so a spare list is never reset while the GPU runs it. The buffers let go are released out of
FREE's lock.

Measured on an RX 9070 XT (debug test build, three runs): making an allocator and list took
0.09-0.35 ms, resetting a kept one 3-11 us; making and mapping an upload buffer took 0.3-0.6 ms at
1 MiB, 1.2-5 ms at 16 MiB, 2-10 ms at 32 MiB, and releasing one 0.1-4.6 ms. A job made anew costs
mostly its buffer; this takes the list's part off it. Not measured in a title.

Not ported:
- STAGING_POOL_MAX_ITEM 8 -> 32 MiB: there is no per-buffer limit here. Buffers of up to 64 MiB
  (powers of two) are kept, XCL_UPLOAD_KEEP_MB (64 MB) of them in all, which stays as it is.
- PARALLEL_BYTES 1 MiB -> 256 KiB: hash_and_detile_all is not in this branch. Uploads of 192 KiB
  and more (SHARE_FROM) are compared and detiled by the standing workers in 64 KiB pieces, already
  below upstream's new threshold. Uploads detile with detile_blocks' runs (73fc616); 27e9562 sped
  up detile_level, which uploads do not use, so nothing asks for a lower threshold.
- Clearing the lists on low commit (trim_idle_staging): FREE has no such trim here, and the spare
  lists are small next to its buffers.
- The XCL_UPLOAD_CMD_POOL switch and the #[ignore] benchmark.

Tests: upstream's pool test as spares_are_kept_by_device_newest_first_up_to_the_most, and its GPU
test as gpu_a_list_whose_buffer_went_goes_on_with_a_new_one (a job let go leaves its list, a job
made next takes it with a bigger buffer, read back texel for texel); it keys its job to a device of
its own so the other tests' uploads cannot take its spare.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
raylitebull added a commit that referenced this pull request Nov 29, 2026
Ports upstream PR #2989's d1167f8. A job given back is reset and written by the next batch, and a
job dropped releases a buffer the GPU may still read: neither may happen until a wait has said the
GPU is done with it.

submit_on already kept the job (std::mem::forget) when the wait after a failed Signal failed; it
now goes through release_after_upload_wait, as upstream's submit_on_title_queue does, with the same
behaviour. upload_and_wait returned on a failed wait and so dropped the job: it now keeps it. In
this branch the fence is made before the batch is submitted, so upstream's other site (a failed
CreateFence after the submit) does not exist here. Unlike upstream's, the helper takes what to do
with the job, since a job here is given back explicitly (give_back) rather than on drop.

Test: upstream's failed_upload_wait_retains_submitted_resources, which also checks that the job is
not given back when the wait fails.

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

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Triage (#1607) – head d1167f8

Only the top two commits (7dece6b, d1167f8) are this PR's own. The other ~285 commits are the old amd-dev base shared with #2912, #2913, #2981, #2988 and the other large amd-dev PRs.
Both were ported to current amd-dev. 1be2221 ("texture uploads keep their lists when their buffers go") carries the command-list pooling, with 16 spare lists per device as in CMD_POOL_MAX_PER_DEV. 512b0bb ("retain a texture upload job whose fallback wait fails") carries release_after_upload_wait and its test.
The staging-cap and detile-threshold parts no longer apply. amd-dev's texture_upload.rs (73fc616) replaced the staging pool with kept upload jobs whose buffers go up to 64 MiB, and PARALLEL_BYTES / the parallel detile path is gone.
Recommendation: close (superseded by amd-dev commits 1be2221 and 512b0bb).

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

@throny

throny commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Closing as superseded: this change is already on amd-dev (1be2221, 512b0bb). From Foniass's rechecked close list on #1607, checked again by script just now. If something here is still missing, say so and reopen it, or ask and I will.

AI use: Claude Code (Claude Opus 5.5).

@throny throny added the duplicate This issue or pull request already exists label Dec 1, 2026
@throny throny closed this Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

duplicate This issue or pull request already exists

Projects

None yet

Development

Successfully merging this pull request may close these issues.