Repository navigation
D3D12.X: pool async upload command lists, raise staging item cap to 32 MiB, and lower parallel detile threshold - #2989
Saksukella wants to merge 270 commits into
Conversation
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>
…esent in flight)
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>
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)
…2 MiB, and lower parallel detile threshold
|
Independent Windows/NVIDIA check of #2989 head
One failure-path issue: after 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 Candidate correction and regression diffdiff --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. |
|
Updated RX 9070 / Wine check on 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 Tested
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. Original filters are under The two Not tested: actual native 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. |
|
Thanks @thehollowedone for the great catch and exact regression test! Pushed |
|
Tested Clean
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 ( |
|
Review of
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 |
|
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:
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:
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. |
|
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 Tested: at the PR head
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
left a comment
There was a problem hiding this comment.
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).
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>
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>
|
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. AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human. |
Pools async texture upload
(ID3D12CommandAllocator, ID3D12GraphicsCommandList)pairs per device, raisesSTAGING_POOL_MAX_ITEMfrom 8 MiB to 32 MiB to matchBATCH_BYTES, and lowersPARALLEL_BYTESfrom 1 MiB to 256 KiB.Root cause & summary of changes
Profiling 240 s world-streaming runs on AMD Radeon RX 9070 XT showed
texture uploadsconsuming6.4–7.1 stotal (3,200–3,500calls, peak765–886 ms / 2 swith single-batch spikes of543–725 ms):crates/xcl/src/gpu/texture.rs— Per-device async upload command list/allocator pool (CMD_POOLS):submit_batchpreviously created and destroyed a freshID3D12CommandAllocator+ID3D12GraphicsCommandListon every batch (~3,500 COM allocations per run).CmdPool(CMD_POOL_MAX_PER_DEV = 16) withXCL_UPLOAD_CMD_POOL=0kill-switch (default enabled).acquire_upload_cmdresets a pooled allocator + list with safe fresh-creation fallback;CmdSlotinsideInFlightonly recycles the pair onInFlight::drop(strictly after the queue fence completes intitle_textures::reclaim*) and trims idle entries onlow_commit.crates/xcl/src/gpu/texture.rs— RaiseSTAGING_POOL_MAX_ITEMfrom8 MiBto32 MiB:title_textures::BATCH_BYTES = 32 MiBso8–32 MiBstreaming bursts stay insideSTAGING_POOLSinstead of falling back to unpooledCreateCommittedResourceon anUPLOADheap (which caused200–725 msWDDM allocation hitches), while keepingSTAGING_POOL_DEFAULT_CAP = 256 MiB, 2 s / 30-frame idle reclamation, and immediatelow_commiteviction intact.crates/xcl/src/hle/d3d12x/title_textures.rs— LowerPARALLEL_BYTESfrom1 MiBto256 KiB:DetilePoolfor256 KiB–1 MiBmedium texture streaming bursts.Tested
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 failuretitle_bytes_are_used_in_place_when_all_are_readableonbf7c82eebase).cargo test -p xcl --release --lib gpu::texture::tests::bench_submit_batch_pooled_vs_legacy_12mib -- --ignored --nocapture --test-threads=1, 32x 12 MiB RGBA8submit_batchincluding full synchronous 384 MiB GPU DMA wait):124.68 ms(3.90 ms/op)77.05 ms(2.41 ms/op) ->1.62xend-to-end speedup (eliminating 100% of per-batchCreateCommandAllocator/CreateCommandListand unpooled 12 MiBCreateCommittedResourceWDDM stalls).Not tested
Regression run
Baseline (
main,b49be183):This PR (
7dece6b4onamd-devbf7c82ee):AI use