Skip to content

D3D12.X: title texture uploads run on the submitting queue, without a CPU wait - #455

Open
Cattn wants to merge 1 commit into
ivall:mainfrom
Cattn:title-texture-uploads-on-title-queue
Open

Cattn wants to merge 1 commit into
ivall:mainfrom
Cattn:title-texture-uploads-on-title-queue

Conversation

@Cattn

@Cattn Cattn commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Part of #248; related to #262 (the same direction for sparse uploads, see #262 (comment)).

title_textures::refresh runs on the title's thread before each of its submits. It uploaded the CPU's writes to kept-in-step textures on XCL's own queue, then waited on the CPU until the GPU had run them (texture::upload_batch → wait). While a retail title streams its world with video memory past the card, those waits are long:

  • thread dumps every 30 s show its submit thread blocked in title_textures::refresh → texture::upload_batch → texture::wait → gpu::fence::wait;
  • presents drop to 0–8 per 20 s;
  • the title's watchdog ends it on the loading screen.

When the submitting queue is a DIRECT queue on the texture's device, the upload list now runs on that queue, ahead of the title's lists. The GPU orders the copies before the work that samples them, without a cross-queue wait (the deadlock #262 describes for waiting on title queues). A fence on that queue retires each batch's allocator, list and staging buffers at later submits; with over 512 MB in flight the oldest batches are waited for. Compute and copy queues, and a queue of another device, keep the upload queue and its wait.

What is in it

  • gpu/texture.rs: submit_batch = upload_batch without the wait, returning what has to stay alive (InFlight). upload_batch is submit_batch + wait, unchanged for its callers.

  • hle/d3d12x/title_textures.rs:

    • upload_all takes the submitting queue;
    • title_queue_for picks it when it is DIRECT on the same device;
    • submit_on_title_queue signals a per-queue fence;
    • reclaim releases finished batches and waits over the cap.
  • New GPU test gpu_uploads_on_the_title_queue_run_before_its_later_work_and_are_released:

    • two uploads, each read back on the same queue, give their bytes;
    • with the cap at 0 every batch is waited for and released;
    • compute queues and no queue are not used.

    read_r8 moves from the mirror test to the test module so both tests use it. The existing gpu_mirror_upload_follows_cpu_writes_and_later_mapping_changes calls refresh with a DIRECT queue, so it now runs through this path too and still reads the written bytes back.

Tested

  • RTX 4070 12 GB (driver 617.42), Ryzen 7 7800X3D, 32 GB RAM, Windows 11 26200, rustc 1.93.1.

  • cargo build --workspace, then cargo test --workspace --no-fail-fast -- --test-threads=4: 677 passed, 0 failed, 41 ignored, run alone on the GPU.

    • SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.
    • A first run hung in four recompiler GPU tests while another cargo test used the same GPU. The rerun alone passed.
  • cargo test --release -p xcl --lib title_textures: 8 passed.

  • Retail title, world streaming (guarded runs, XCL_NETWORK=0, frame-event, activity and thread-dump logging): with this change the title got past its loading screen for the first time on this machine, twice. Without it, every run ended on the loading screen (the title's watchdog, or a free-RAM guard). Both runs used larger local stacks:

    After loading the world draws black and the title stops, which is a separate problem.

Regression run

main:

xcl-smoke v1
commit: a6f5f7a74cc620c1f88a9e3669a633d10c3c8212
gpu: NVIDIA GeForce RTX 4070
title: GTA6.Xbox.v1.0.2
seconds: 60
exit: 0x0
frames shown: 404 (PresentX 404)
presents per 2 s (last 3): 8 6 8
device removals: 0
crashes: 0
peak commit: 15055 MB

PR:

xcl-smoke v1
commit: 07e6199d28283e9208f39364c0e6573a36c629ff
gpu: NVIDIA GeForce RTX 4070
title: GTA6.Xbox.v1.0.2
seconds: 60
exit: 0x0
frames shown: 496 (PresentX 497)
presents per 2 s (last 3): 8 9 9
device removals: 0
crashes: 0
peak commit: 15067 MB

(The 60 s run reaches the intro video, whose planes are uploaded through this path every frame.)

Not tested

  • AMD GPUs; titles that submit kept-in-step textures from COMPUTE or COPY queues (those keep the old path).
  • The world-streaming runs were not on plain main + this change alone.

AI use

  • Claude Code (Claude Opus 5.5): found the blocked thread in thread dumps, wrote the change, the test and this description. I ran the builds, tests, smoke runs and game runs above on the hardware named.

… CPU wait

title_textures::refresh runs on the title's thread before each of its
submits and uploaded the CPU's writes to its textures on XCL's own queue,
then waited on the CPU until the GPU had run them (texture::upload_batch).
While a retail title streams its world with video memory past the card,
those waits are long: thread dumps show its submit thread blocked in
fence::wait under refresh, presents drop to a few per 20 s, and the title's
watchdog ends it on the loading screen.

When the submitting queue is a DIRECT queue on the texture's device, the
upload list now runs on that queue, ahead of the title's lists, so the GPU
orders the copies before the work that samples them, with no cross-queue
wait. A fence on that queue retires each batch's allocator, list and staging
buffers at later submits; over 512 MB in flight the oldest batches are waited
for. Compute and copy queues, and a queue of another device, keep the upload
queue and its wait. texture::submit_batch is upload_batch without the wait.
@thehollowedone

Copy link
Copy Markdown

Tested

Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti (NVIDIA 621.35), Rust 1.99.1 MSVC, debug. The run confirmed XCL selected the real RTX 3080 Ti backend. Commit 07e6199d

cargo test --locked -p xcl --lib title_textures::tests -- --test-threads=1 --nocapture: 8 passed, 0 failed, 0 ignored, zero reported skips. The new queue test checked three 64×64 readbacks, confirmed that subsequent work on the direct queue saw the uploaded bytes, and verified that waiting at a zero staging cap retired all three uploads.

Not tested

Full workspace suite, AMD, retail titles, and frame-rate impact.

AI use

Codex with GPT-6.2 Sol ran the tests and drafted this report.

@PHeitor1

Copy link
Copy Markdown

Tested 07e6199 merged onto main 2997c9a.

RTX 5060 Ti 8 GB (Blackwell, 32-lane waves), NVIDIA 621.24, Ryzen 5 5600X, Windows 11 Pro 26300 (native, Graphics Tools + XGameRuntime installed, so the debug-layer tests run), rustc 1.100.0 MSVC, debug, cargo test --workspace --no-fail-fast -- --test-threads=4, no XCL_SAMPLE_*.

Pass: 677 passed, 0 failed, 41 ignored. SKIPPED: only the 2 no wave64 tests (gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware). Build clean.

Run and written with Claude Code (Claude Opus 5.5).

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.

3 participants