Skip to content

D3D12.X / XG: async texture upload, detiling, VRAM, XG ABI, and PSO scheduling improvements - #539

Closed
JGonzalezRodriguez wants to merge 16 commits into
xcl-dev:mainfrom
JGonzalezRodriguez:feat/d3d12x-perf-and-xg-fixes
Closed

JGonzalezRodriguez wants to merge 16 commits into
xcl-dev:mainfrom
JGonzalezRodriguez:feat/d3d12x-perf-and-xg-fixes

Conversation

@JGonzalezRodriguez

@JGonzalezRodriguez JGonzalezRodriguez commented Nov 24, 2026 •

Copy link
Copy Markdown

Draft rollup PR for Windows testing — opened so another contributor can pull and test these changes on native Windows across retail titles / D3D12.X workloads. Once validated, this rollup will be split into individual focused PRs.

This branch bundles D3D12.X performance, scheduling, and XG ABI/correctness fixes targeting heavy streaming and shader-compilation workloads (no Linux/Wine-specific workarounds are included).

What is in it

  • Async texture upload staging & command-list reuse (crates/xcl/src/gpu/texture.rs, crates/xcl/src/hle/d3d12x/title_textures.rs, crates/xcl/src/hle/d3d12x/vram.rs, crates/xcl/src/hle/d3d12x/real.rs): per-device async Uploader with fence-ordered consuming-queue waits, reusable mapped staging chunks and allocators, and tracked in-flight destination refs for safe texture release and vram::Pages ordering.
  • xg::CopyFromSubresource 7-argument ABI fix & destination span guard (crates/xcl/src/hle/xg.rs, crates/xcl/tests/xg_oracle.rs): handle the extra u32 argument before src, bounds-check the destination span, and log invalid arguments.
  • Texture detiling & layout table optimizations (crates/xcl/src/gpu/tiling.rs, crates/xcl/src/hle/d3d12x/title_textures.rs): copy linear mip levels row-by-row, hoist tiled detiling with parallel batch detiling, and cache Layout offset tables via Arc slices while trimming unused high-bit tables.
  • vram::Pages overhead reduction (crates/xcl/src/hle/d3d12x/vram.rs): coalesce page-queue fence signals and throttle idle-page sweeps.
  • Sorted VirtualQuery span cache (crates/xcl/src/hle/d3d12x/title_textures.rs): cache VirtualQuery memory region spans across sorted entries in recheck_gpu_view_sources.
  • Asynchronous PSO compilation & scheduling (crates/xcl/src/hle/d3d12x/pso_async.rs, crates/xcl/src/hle/d3d12x/bind.rs, crates/xcl/src/hle/d3d12x/real.rs):
    • pre-compile compute PSOs in the background while keeping graphics PSOs lazy;
    • route large compute driver compiles to a dedicated worker pool so small PSOs are not starved;
    • run background PSO worker threads at BELOW_NORMAL priority;
    • give bound lazy graphics PSOs a dedicated urgent worker pool;
    • skip draws using pending graphics PSOs instead of blocking the render thread;
    • add opt-in XCL_ASYNC_COMPUTE=1 non-blocking compute PSO mode.
  • Cross-queue Wait64BitValueX GPU fence bridge, cycle-breaking, and GPU-completion watchdog (crates/xcl/src/hle/d3d12x/list_x.rs, crates/xcl/src/hle/d3d12x/real.rs):
    • What: bridge monotonic 64-bit Write64BitValue{Bottom,Top}OfPipeX → Wait64BitValueX (GREATER_EQUAL, full 64-bit mask) onto per-address ID3D12Fence queue.Signal / queue.Wait calls, bypass redundant waits when the producer already submitted earlier on the same queue (D3D12 FIFO order), detect and break cross-queue fork-join wait cycles before hoisting queue.Wait, and monitor armed GPU waits with a bounded GPU-completion watchdog (falling back to bounded CPU polling for non-monotonic or ineligible waits).
    • Why: workloads that submit a consumer list with Wait64BitValueX ahead of the producer list on another queue previously stalled the CPU submission thread until timeout or risked cross-queue/unsubmitted-producer deadlocks; moving eligible waits to GPU fences preserves ordering without blocking command submission.

Tested

  • Cross-compile check (rustc 1.98.1, debug): cargo check -p xcl --target x86_64-pc-windows-msvc --tests passed (0 errors, 0 warnings).
  • Targeted unit & GPU tests run under Wine/Proton + vkd3d-proton on NVIDIA RTX 4090:
    • list_x::tests: 19/19 passed (including write_buffer_immediate_on_open_existing_heap_visible_to_cpu, cross_queue_wait64_before_signal_does_not_deadlock_submit_thread, cross_queue_cycle_and_same_queue_fifo_do_not_deadlock)
    • vram: 6/6 passed
    • title_textures: 9/9 passed
    • gpu::texture: 15/15 passed
    • gpu::tiling: 11/11 passed
    • hle::xg: 4/4 passed
    • bind: 4/4 passed

Regression run

  • Pending native Windows 11 scripts/smoke.ps1 runs (draft PR for contributor testing; will be split and include main + PR xcl-smoke blocks before review).

Not tested

  • Native Windows 11 scripts/test.ps1 (full workspace suite) and scripts/smoke.ps1 regression runs (opening as draft for a Windows contributor to test).
  • AMD and Intel GPUs.

AI use

  • Antigravity with Gemini neon (wrote code, tests, and PR description; reviewed and compiled by author).

…ure uploads

Avoid per-batch CPU stalls, upload-buffer churn, and command list
allocation in title texture uploads by reusing a per-device async
Uploader (fence-ordered GPU waits on consuming queues, dynamic 4-64 MiB
staging chunks mapped once per chunk, capped idle pool/allocator
recycling, and dedicated pinning on queue.Signal failure).

Track Uploader's in-flight destination COM references so res_release
detaches title-dropped textures from title_textures immediately (while
deferring vram::forget until the GPU copy completes), order vram::Pages
unmap/remap tile updates after the async upload fence without
UPLOADERS/PAGES lock inversion, drop retired COM objects outside
UPLOADERS, and clear queue wait tracking on both queue creation and
release.
@grahamster2

Copy link
Copy Markdown
Collaborator

Evidence for the cross-queue Wait64BitValueX problem this PR targets, from the retail title that trips #232. Setup: RTX 3080 10 GB, Windows 11, release builds, XCL_NETWORK=0. Counters are given as offsets from one 256-byte block of title memory (base B).

main 9ce2070 + #435, with a local env-gated trace of writes, waits and submits on that block (once the shader cache is warm enough to reach the world, ~80 s):

  • 79.62 s: Write64BitValueBottomOfPipeX(B+0x58, 0x613) is recorded on a direct list D1. Wait64BitValueX(B+0x58 >= 0x613) is recorded on a compute list C1. The same pattern repeats for B+0x10, +0x18, +0x68, +0xe8: four more counters, all used for the first time at world start (memory 0). Writers and waiters are on both queue types.
  • 80.445 s: the submit thread submits C1. execute_with_waits → wait_all blocks that thread on the CPU.
  • 82.447 / 84.459 / 86.460 s: three 2 s timeouts (B+0x58, +0x10, +0xe8; memory still 0).
  • 86.468 s: only now does the same thread submit D1, the writer of B+0x58, then D2 (writer of +0x10/+0xe8). The producer is queued behind its own consumer on one thread.
  • The compute lists then run on unready data. The next frame dump is fully black (0 of 518,400 samples lit); presents stop and the Retail title: null write at +0x2215c35 (#159) still hits on NVIDIA RTX 4070 Ti, with and without XCL_NETWORK=0 #232 watchdog fires at 109 s. In another run the same sequence ended in a read at -1 with -inf values in the registers.

This PR (head 4ff33f0, on its own base): the bridge does what it says. At 91.5 s three waits (B+0x58, +0x10, +0xe8 >= 0x6d5, compute waiting on direct producers) became GPU queue.Wait calls and the submit thread was not blocked. 1 s later:
GPU queue.Wait at B+0x58 >= 0x6d5 did not complete within 1000 ms (waiter_ty=2, prod_ty=Some(0), recorded=0x6d5, submitted=0x6d5, completed=0x0) – released on CPU. The same happened for B+0x68 (producer on the compute queue). The title then crashed at 93 s with the same garbage-data read. A local run with the watchdog raised to 10 s didn't reach this point: the new binary had to retranslate, and the compile backlog tripped #232 first. So that run is inconclusive.

Question for you and the maintainer (design): XCL checks every Wait*BitValueX of a list before the whole list is submitted, but on the console the wait sits where it was recorded. In the trace, one compute list records wait +0x10, write +0x18, wait +0x68 / +0xe8, write +0xf0, and a direct list waits on +0x18. With the waits moved to the front of the list, +0x18 can't be written until +0x68 is ready, though on the console it is written before that wait. That can turn a valid console chain into a cycle. It may also explain completed=0x0 (the other explanation: the GPU really is that slow here, with 12.8 GB of video memory in use on a 10 GB card). Would splitting a list at each recorded wait (close the PC list, continue in a new one, queue.Wait between the parts) be the intended direction?

Test report written with Claude Code (Claude Opus 5.5) from my own runs; the trace patch is local only.

@alpz1000

alpz1000 commented Nov 24, 2026 •

Copy link
Copy Markdown

Native Windows/NVIDIA test of the draft on RTX 3060 12 GB (driver 610.88 / 32.0.16.1088), Core i5-8400, Windows 11 Home 26200.9974, Rust 1.100.0 x86_64-pc-windows-msvc, MSVC 14.44.35230, debug. Tested the exact PR head as-is against the then-current upstream main (no local merge).

Check main 3db536ebe231418d76e8d6e52ccee0b47330a522 PR 4ff33f02789f6f6b9748567e45366568f60f13c9
cargo build --locked --workspace exit 0 exit 0
cargo test --locked -p xcl --lib -- --test-threads=1 --nocapture gpu_mirror_upload_follows_cpu_writes_and_later_mapping_changes placed_title_textures_share_vram_and_preserve_pixels 2 passed 2 passed
cargo test --locked -p xcl --test e2e test_title_runs_and_game_folder_is_untouched -- --exact --nocapture 1 passed 1 passed

No skip messages in these runs. The bundled title reported zero failures and the real RTX 3060 backend on both revisions.

Not tested: full workspace suite, opt-in async compute, retail gameplay/loading, or other adapters.

AI use: OpenAI Codex (GPT-6) ran the local checks and drafted the report.

Follow-up: compute checks with the opt-in flag off and on. Same PR head 4ff33f0 and RTX 3060 setup. I ran cargo test --locked -p xcl --test gpu_compute_e2e -- --test-threads=1 --nocapture and cargo test --locked -p xcl --lib async_compute_pso_success_and_failure_in_dispatch_and_execute_indirect -- --nocapture in separate processes with XCL_ASYNC_PSO=1 and XCL_ASYNC_COMPUTE=0 then 1. Both configurations had 2 GPU tests and 1 bind test pass, with zero failures or skips. The GPU integration tests used the real RTX 3060 device and covered cold pipeline resolution and translated compute dispatch/readback. This is compatibility coverage with the setting enabled, with no measurement of pending-dispatch latency or retail loading.

@JGonzalezRodriguez
JGonzalezRodriguez marked this pull request as ready for review November 24, 2026 02:41
@ddm-j

ddm-j commented Nov 24, 2026

Copy link
Copy Markdown

Tested the two xg commits on Linux (Wine, NVIDIA): the 7-argument ABI fix is right; split out, it would also cover #477.

Tested: ivall/main 9ce2070 + #257 (26fdda6) + only this PR's 7d1c466 (guard dst span) and 9c4c3e6 (7-argument ABI), cherry-picked without conflict, plus a local log line in copy_from (logging only). Compared with the same base without them, same protocol (300 s, Series X, one A press).

Tested

Not tested

  • The other 14 commits of this PR. Windows, AMD. The test suite and scripts/smoke.sh.

The two xg commits apply cleanly on their own; as a separate PR they would be small and easy to check.

AI use

  • Claude Code (Claude Opus 5.5) built and ran each version and wrote this comment from the logs; checked by me.

forbesfields added a commit to forbesfields/xcl that referenced this pull request Nov 24, 2026
Accept the extra argument before the tiled source pointer in
CopyFromSubresource so the source and pitches are read from the
right slots. Validate the destination span, preserve row padding,
and report unavailable title memory through HRESULT.

Exercise the console vtable with pitched output and an unmapped
destination page. All 4 XG and 14 DirectStorage tests passed on
Windows, and the XG oracle test target compiled.

Related upstream work: xcl-dev#539
Assisted-by: Codex (gpt-6.2-sol)
@JGonzalezRodriguez

Copy link
Copy Markdown
Author

Closing this rollup PR and replacing it with a clean, single-purpose PR against current main: #684 (XG: fix CopyFromSubresource 7-argument ABI and guard destination span, fixing #477 and the first crash in #662 — thanks @ddm-j for verifying the xg fix independently).

Summary of what was dropped from #539:

@crosettiremi

Copy link
Copy Markdown

RX 7900 XT comparison for the two Wait64 commits (d419af8d11bc and 4ff33f02789f). Windows 11 build 26100, AMD driver 32.0.32029.2010, retail 1.0.2.1, same saved profile, networking off. Both runs used a local stack with #267, #533 and #574, with a 1 ms graphics wait and 4,000 ms compute wait. The comparison adds only the two fence commits to that stack.

  • Before the bridge, one submission thread logged 29 Wait64 timeouts of 2 s each. For 22 of those, the observed counter was exactly one behind the requested value. The title watchdog fired at 192.718 s. No device removal was logged.
  • With the bridge, the log showed eight wait-before-signal messages (the log is rate-limited), 11 cycle skips and 34 GPU waits released by the CPU timeout. For one release, the requested value was 0x755, the highest recorded value was 0x756, and both the submitted and completed values were still 0x754. The last interval with a present ended at 148.219 s. At 149.365 s D3D12 reported DXGI_ERROR_DEVICE_HUNG (0x887a0006), and the game hit a breakpoint. Windows recorded LiveKernelEvent 141. I stopped the unresponsive game process after collecting the log.
  • The bridge stack passed 715 workspace tests with 41 ignored. The retail run reached loading artwork. Playable world rendering remains unverified on this machine.

This confirms the bridge executes on RDNA3. I could not determine which GPU command caused the hang or establish that a particular CPU fence release caused it.

AI disclosure: Codex ran the tests and prepared this report.

@artor410

Copy link
Copy Markdown
Contributor

Native Windows test of 4ff33f0 (this PR's head, as checked out; not rebased, so this is not the conflict-resolved tree)

Tested

  • NVIDIA RTX 3070 Ti 8 GB (32-lane waves), Ryzen 5 5600, Windows 11 10.0.26300, rustc 1.100.0, DXC 1.9.2602.17, debug.
  • cargo build --workspace then cargo test --workspace --no-fail-fast -- --test-threads=4: 688 passed, 1 failed, 41 ignored. SKIPPED (no wave64): gpu_wave32_program_in_wave64_hardware, gpu_geometry_wave32_prefix_count_over_a_mask.
  • The one failure, e2e::test_title_draws_with_a_root_signature_under_the_debug_layer, comes from my environment, not from this PR: the checkout's path is long, and the test title's overlay and PLS steps fail with os error 3 / 206 (path too long). main at the merge base 508a0c7 fails the same test with the same three [FAIL] lines in the same location.
  • All list_x, vram, title_textures, gpu::texture, gpu::tiling, hle::xg and bind tests pass natively here, including the new cross-queue Wait64 ones.

Not tested

  • scripts/smoke.ps1 / any retail title (I have none); AMD and Intel; release build; the tree after resolving this PR's current conflicts with main.

AI use: Claude Code (Claude Opus 5.5) ran the commands above and wrote this report.

grahamster2 added a commit to grahamster2/xcl that referenced this pull request Nov 24, 2026
On the console a Wait*BitValueX holds the GPU where it was recorded.
XCL checks a list's waits before the whole list is submitted, so a list
[wait A][write B][wait C][write D] cannot write B until C holds. A list
on another queue that waits on B before it writes C then waits forever,
or (with the Wait64 fence bridge) has its wait skipped as a cycle. A
retail title records exactly this on its compute and direct lists at
world start (xcl-dev#539).

A title list object (title_list) now closes its PC list at a wait that
follows other commands and goes on recording in another PC list: reset
onto the title's allocator, with the recording's state (list_x state,
bind's root state) moved over and the bindings set again as KickoffX
does after its Reset. ExecuteCommandLists and KickoffX submit the parts
in order through execute_with_waits_on, so each part's waits come right
before it and its Write64 signals before the next part's waits.

The forwarding thunks count calls, so a wait that comes first in a part
does not split. QueryInterface, AddRef and Release stay on the PC list
the object was made for. The PC lists XCL makes are reused after Reset
and released with the object. Only direct and compute lists are split,
and not while a query other than occlusion is open;
XCL_SPLIT_WAITS=0 turns it off.
wondercrash pushed a commit to wondercrash/xcl that referenced this pull request Nov 24, 2026
Split supported recording segments before waits; open the queue gate only when its progress value is visible. Verify the original stale read and patched result with a two-queue GPU fixture.
Queue-local completion workers adapted from xcl-dev#562. Recorded-order trace and motivation: xcl-dev#539.
Assisted-by: omp (amd-openai/gpt-6.2-sol)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants