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
xcl-dev:mainfrom
Cattn:title-texture-uploads-on-title-queue
Open

Cattn wants to merge 1 commit into
xcl-dev: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.
  • A batch whose wait fails or times out stays in flight. New GPU test gpu_an_upload_still_running_is_kept_when_its_wait_times_out stalls the queue on a gate fence and checks that. It fails if the batch is released on a timeout.

  • 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

  • At 4a514ae, cargo build --release -p xcl passed. cargo test -p xcl --lib title_textures -- --nocapture on the RTX 4070 passed 11 tests, with 0 failed, 0 ignored and 0 skipped.

  • 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 at 90b45fb (rebased on main 7ebf1b8): 679 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: 10 passed, with D3D12.X: a title texture whose memory is as at its last upload is not uploaded again #486's test.

  • 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: 3db536ebe231418d76e8d6e52ccee0b47330a522
gpu: NVIDIA GeForce RTX 4070
title: 2615684f
seconds: 60
exit: 0x0
frames shown: 1600 (PresentX 1600)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16488 MB

PR:

xcl-smoke v1
commit: 4a514ae75a00336d0b461a72bc9650bc9f9a4510
gpu: NVIDIA GeForce RTX 4070
title: 2615684f
seconds: 60
exit: 0x0
frames shown: 1629 (PresentX 1629)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14930 MB

An earlier 60-second run on the same PR head showed 1,436 frames and peaked at 21,806 MB, above the 125% limit against this baseline. It also recorded zero device removals and crashes. The cause of the run-to-run variance is unknown.

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.
  • Codex (gpt-6.2-sol): resolved the rebase conflict, ran the focused tests and refreshed the regression runs.

@thehollowedone

thehollowedone commented Nov 24, 2026 •

Copy link
Copy Markdown

Error 921 localized on main

On 63cdc25, the serial texture suite stopped in placed_title_textures_share_vram_and_preserve_pixels. The single test reproduced the error after I initialized the debug layer explicitly. Naming its resources identified the reused texture in the overlap case. Fixture release site

A wait before the grouped release was insufficient. Releasing one alias can reactivate another and queue more mapping work. In a scratch change limited to the fixture, I waited for the mapping fence via vram::before_execute and texture::wait before releasing each placed resource individually. The full texture suite then passed 10/10 in each of three fresh processes, with no skips or D3D12 errors. This verifies the fixture change on main; runtime resource lifetime under #455 remains a separate question.

RTX 3080 Ti / 621.35, Windows 11 build 26300, Rust 1.99.1 MSVC, debug. cargo test --offline --locked -p xcl --lib hle::d3d12x::title_textures::tests -- --nocapture --test-threads=1. Synthetic input only. Codex with GPT-6.2 Sol instrumented the fixture, ran the tests, and drafted the update.

Current-baseline retest

With D3D12 validation enabled, the serial title-texture suite stopped with error 921 on both main at dd2ae9a and a scratch integration of 4a514ae onto that same revision. The debug layer reported a resource reaching final release while a queue still referenced it. This confirms the diagnostic from my earlier report also occurs on current main.

On the integrated tree, the stock queue-ordering and timeout-retention tests each passed in a fresh process with no reported validation errors or skips. The existing mirror-upload and placed-texture GPU readback tests also passed individually on both trees. These runs leave the resource involved in the suite failure unidentified.

RTX 3080 Ti / 621.35, Ryzen 7 9800X3D, Windows 11 build 26300, Rust 1.99.1 MSVC, debug. cargo test --offline --locked -p xcl --lib hle::d3d12x::title_textures::tests -- --nocapture --test-threads=1, then the individual test filters. Retail behavior remains untested. Codex with GPT-6.2 Sol ran the tests and drafted this update.

Results on earlier revisions

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.

Retest at 90b45fb

The focused title-texture suite passed on the same RTX 3080 Ti setup, with 10 passed, 0 failed, 0 ignored and no reported skips. This includes the current head’s queue-ordering and timeout-retention tests. I selected the hardware with XCL_ADAPTER=3080 Ti, set XCL_REQUIRE_GPU=1, and ran cargo test --offline --locked -p xcl --lib hle::d3d12x::title_textures::tests -- --test-threads=1 --nocapture. Tested revision

I tested the PR head in isolation. After the #451 merge, Git reports a conflict in crates/xcl/src/gpu/texture.rs against main at 9ce2070. The combined upload path and retail behavior remain untested here.

Codex with GPT-6.2 Sol ran the retest and drafted this update.

D3D12 debug-layer follow-up at 90b45fb

With Windows Graphics Tools installed, XCL confirmed the debug layer was active on the RTX 3080 Ti. The queue-ordering and timeout-retention tests both reported pass. The overall synthetic title-texture suite did not complete successfully. The debug callback reported message 921, a resource reaching final release while a queue still referenced it. This was a separate run from the earlier 10/10 result with validation off. I did not identify which resource was released.

One ownership check before rebasing: InFlight holds the allocator, command list, and staging resources, but the submitted copies also reference destination textures from the caller’s batch. Could the in-flight batch retain the destinations of successfully recorded copies through the same completion fence? This is a source-level follow-up, not an attribution of the diagnostic. In-flight batch and recording loop

Windows 11 build 26300, driver 621.35, Rust 1.99.1 MSVC, debug. Retail behavior and integration with latest main were outside this run. Codex with GPT-6.2 Sol ran the diagnostic pass, reviewed resource ownership, and drafted this update.

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

@TheHoracio

Copy link
Copy Markdown
Contributor

Test report on AMD RDNA3: RX 7800 XT (16 GB, wave32 and wave64), driver 32.0.32015.7029, Ryzen 7 9800X3D, Windows 11 Pro 10.0.26300, Rust 1.100.0 MSVC, DXC 1.9.2602.17, debug build. No retail data was used. The PR's own runs are all on NVIDIA, so this adds an AMD GPU with 64-lane waves.

Tested: the PR head 07e6199 as it is (on its base a6f5f7a).

  • cargo build --workspace, then cargo test --workspace --no-fail-fast -- --test-threads=4: 677 passed, 0 failed, 41 ignored, no SKIPPED tests (the two no wave64 tests run here).
  • The new gpu_uploads_on_the_title_queue_run_before_its_later_work_and_are_released passes. Nothing hung; the run was alone on the GPU.

Not tested: a regression run on a title, a release build, the head merged onto current main.

AI use: Claude Code ran the commands and drafted this comment; the runs are real runs on the hardware above.

@grahamster2

grahamster2 commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Tested on an RTX 3080 against main and the two other PRs for the same fix (#451, #465). On this machine #455 ended in a device removal (DEVICE_HUNG) in 2 of 3 runs, about 11–14 s in. The run that completed played the intro video at the same ~4.7 fps as main, and world streaming started at 134 s instead of 140 s.

Setup: RTX 3080 10 GB, driver 610.88, 32 GB RAM with ~15–17 GB used by other programs. Release builds of main 2997c9a (code-identical to a6f5f7a) and of #451 2cefc88, #455 07e6199 and #465 1152852. Each PR was tested on its own. The retail title ran 180 s per run with XCL_NETWORK=0 XCL_ACTIVITY=1 XCL_PRESS_A_AT=14,17,21 on a warm cache. Numbers are from the activity (2 s) lines; the earlier patch test on db1ddb2 is here.

main #451 #455 #465
Runs 2 2 3 (2 ended in a device removal) 2
Intro video, presents per 2 s 8–10 (≈4.5 fps) 37–43 (≈20 fps) 8–11 (≈4.7 fps) 8–10 (≈4.5 fps)
Intro video, start → end 20 → 119 / 121 s 20 → 41 / 41 s 20 → 113 s 20 → 118 / 117 s
World streaming starts 140 / 140 s 60 / 60 s 134 s 138 / 136 s
Max presents per 2 s after that 35 / 35 45 / 58 47 55 / 48
Commit at the end 23.7 / 24.0 GB 24.5 / 24.4 GB 24.1 GB 24.5 / 25.1 GB
  • Every completed run was stopped by my watchdog (it kills XCL when free RAM falls below 1.5 GB). That happened 15–25 s after world streaming started, at about 24 GB commit, in every build. It's this machine's RAM limit, so the "after that" row covers only those seconds.
  • D3D12.X: title texture uploads run on the submitting queue, without a CPU wait #455: 2 of 3 runs ended in a device removal. The removal was 0x887a0006 (DEVICE_HUNG), at 13.5 s and 11.0 s, before the intro video. The log line is D3D12 device removed: 0x887a0006 … – the title is stopped, and then the process ends with status 0x887a0006. main and the other PRs had no removals in their runs.
  • smoke.ps1, 60 s: it presses nothing, so every build stays on the menu, and all four look the same there.
smoke commit frames shown last 3 removals crashes peak commit
main 2997c9a 1532 60 60 60 0 0 14613 MB
#451 2cefc88 1590 60 61 60 0 0 14723 MB
#455 07e6199 1518 61 60 59 0 0 14589 MB
#465 1152852 1528 60 59 61 0 0 14663 MB

All smoke runs reported exit: 0x0 and gpu: NVIDIA GeForce RTX 3080. I left the title line out of the table.

Not tested:

  • Picture correctness: I can't see the screen.
  • Anything past ~20 s of world streaming, because of the RAM limit.
  • Combinations of the PRs.

The same numbers are posted on the other PRs: #451, #465.

Test runs and this report: Claude Code (Claude Opus 5.5).

@ryosen0

ryosen0 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Long-run data point on RTX 3060 Ti 8 GB (Ryzen 7 9800X3D, driver 32.0.16.1742, Windows 11): with this PR's direction plus the rest of the texture-upload work, a retail run survives its old crash point and reaches world streaming with the frame rate intact.

Build: main 2997c9a + #440 + this PR (#455) + #435, plus theaustinayers' build-10 fork commits (threaded detile of large levels, skip-unchanged texture uploads, 1 ms timer) merged locally; release, XCL_NETWORK=0 XCL_ACTIVITY=1 XCL_RUN_SECONDS=600.

Result: clean exit at the 600 s timer, 16434 frames. On this machine a 600 s run on the older stack died at ~395 s with 0xc0000005 during world loading (~26.6 GB commit). This run held 60 presents / 2 s from t≈26 s through t≈470 s - no intro dip at all (it used to be 4-8 fps for two minutes) - then streamed the world: a brief 20 presents / 2 s stretch around t≈480 s, back to 60, and at t≈598 s: 24.9 GB commit, 12.5 GB local + 4.6 GB non-local video on the 8 GB card, no device removal, no crash.

Not attributing the whole effect to this PR alone - it is the combined stack - but the CPU-wait removal is the piece that matches gw1337x's profiling in #283 (submit-thread stalls in texture::wait), and the run confirms the direction holds on a small-VRAM NVIDIA card for 10 minutes, not just 60 s.

Not tested: this PR in isolation on the retail title; no visual assessment (unattended run).

AI use: GPT-6.2 Astra (API model selector) in DSH ran the build and the run and wrote this comment; the human contributor reviewed it.

@Alpha325

Copy link
Copy Markdown

Independent AMD RDNA4 check on clean PR head 90b45fb83ff7eace999dc2f01d02d2369fa73258.

Tested on Radeon RX 9060 XT (driver 32.0.32029.2010), Windows 11 build 26200.9974, Rust 1.100.0 MSVC x64, release. Synthetic fixtures only.

cargo test --offline --locked --release -j 4 -p xcl --lib title_textures::tests -- --test-threads=1 --nocapture

10 passed, 0 failed, 0 ignored, no skips. XCL confirmed it used the hardware D3D12 backend. The same-queue readbacks matched the uploaded bytes. The timeout test kept the blocked upload in flight, then retired it after the fence was signaled and verified the texture contents. The existing CPU-write and remap test also passed.

The three focused GPU tests passed again on a separate run. The D3D12 debug layer was unavailable, so this run adds no debug-layer coverage. Full workspace tests and performance were outside this check.

AI use: OpenAI Codex (GPT-6.2 Sol) ran the tests and drafted this report.

… 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, and a batch whose wait fails or times out stays in flight. 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.
@upipibi

upipibi commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Lifetime question at head 4a514ae75a (code read, not built).

texture::InFlight (crates/xcl/src/gpu/texture.rs) keeps _alloc, _list and _staging alive until the queue passes the fence, but not the destination textures the list copies into. XCL's only strong references to them are the ID3D12Resource clones in the batch passed to submit_batch, which are dropped when submit_on_title_queue returns. TEXTURES holds raw addresses. On main those clones lived across the CPU wait, so it didn't matter.

Scenario: a texture kept in step is uploaded at the next DIRECT submit, and the title makes its final Release before the title queue reaches that upload list. res_release (real.rs:1547) passes the release straight through, so the resource is destroyed under a submitted list. That's D3D12 error 921, the same kind @thehollowedone localized above in placed_title_textures_share_vram_and_preserve_pixels. The window is the queue's backlog, which is longest in the streaming case this PR is for. upload_batch's comment in the same file already notes that "freeing them under the GPU removed the device".

Possible fix: keep the batch's ID3D12Resource clones in InFlight and release them when it's retired. Watch the lock order, since their final Release re-enters forget under ON_QUEUE/REFRESH.

I haven't shown that a title actually releases this early. This is from reading the code.

AI-assisted (Claude Code).

gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 24, 2026
…copy non-coherent reads safely

Integrates upstream PRs ivall#455 and ivall#751:
- Submit title texture upload batches directly on the title's direct
  queue without per-batch CPU fence waits, reclaiming staging buffers
  asynchronously and ordering vram tile updates before each submit
  (ivall#455).
- Copy title texture bytes outside the coherent UMA window through a
  reusable thread-local ReadProcessMemory buffer so concurrent page
  decommits cannot fault (ivall#751).
@mastrr9

mastrr9 commented Nov 24, 2026

Copy link
Copy Markdown

Independent NVIDIA RTX 5080 build/test run and code review at head 4a514ae75a00336d0b461a72bc9650bc9f9a4510.

Code Review Findings (in addition to @upipibi's destination-resource lifetime catch)

  1. Missing vram::before_execute(&tq) before uploading on the title queue (crates/xcl/src/hle/d3d12x/title_textures.rs, submit_on_title_queue + real.rs, q_execute_command_lists):
    • q_execute_command_lists calls title_textures::refresh(this) before vram::before_execute is called on the title's direct queue.
    • Inside refresh(), the fallback upload_queue path calls super::vram::before_execute(upload_queue) before submitting the upload list, whereas submit_on_title_queue(dev, &tq, &batch) submits the upload command list directly on tq without waiting on vram's mapping fence first.
    • For placed/reserved textures whose UpdateTileMappings work is still pending on XCL's mapping queue, the upload CopyTextureRegion on tq can race ahead of tile mapping completion. Adding super::vram::before_execute(&tq); at the start of submit_on_title_queue (before submit_batch) closes that gap.
  2. Minor (ON_QUEUE key lifetime): ON_QUEUE is keyed by queue.as_raw() as usize without an eviction hook on queue release (q_release). If a title destroys a direct queue and creates a new one on a different device at the same address, ON_QUEUE could inspect an entry from the old device's fence. Removing the entry in q_release (or retiring/cleaning up on drop) avoids address-reuse hazards.

Tested

  • Environment: NVIDIA GeForce RTX 5080 (16 GB, driver 617.42 / 32.0.16.1742), Windows 11 Pro 25H2 (26200.9974), rustc 1.100.0 (0ef1bc386 2026-11-09), debug build.
  • Command: cargo build --workspace && cargo test --workspace -- --test-threads=4
  • Result: 688 passed, 0 failed, 41 ignored (0 new warnings).
  • PR-specific tests (all ok):
    • hle::d3d12x::title_textures::tests::gpu_uploads_on_the_title_queue_run_before_its_later_work_and_are_released
    • hle::d3d12x::title_textures::tests::gpu_an_upload_still_running_is_kept_when_its_wait_times_out
    • Plus 9/9 existing hle::d3d12x::title_textures::tests::* tests.
  • SKIPPED (4):
    • gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask (no wave64)
    • gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware (no wave64)
    • test_title_draws_with_a_root_signature_under_the_debug_layer (no d3d12SDKLayers.dll)
    • uploads_start_from_each_subresources_state (no D3D12 debug layer (0x887A002D))

Not tested

  • D3D12 debug layer (d3d12SDKLayers.dll not installed on this host), AMD/wave64 hardware, and retail titles.

AI use: Antigravity (Gemini 4 Neon) performed the code review, ran the RTX 5080 workspace tests, and drafted this comment.

gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 24, 2026
…copy non-coherent reads safely

Integrates upstream PRs ivall#455 and ivall#751:
- Submit title texture upload batches directly on the title's direct
  queue without per-batch CPU fence waits, reclaiming staging buffers
  asynchronously and ordering vram tile updates before each submit
  (ivall#455).
- Copy title texture bytes outside the coherent UMA window through a
  reusable thread-local ReadProcessMemory buffer so concurrent page
  decommits cannot fault (ivall#751).
gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 24, 2026
…copy non-coherent reads safely

Integrates upstream PRs ivall#455 and ivall#751:
- Submit title texture upload batches directly on the title's direct
  queue without per-batch CPU fence waits, reclaiming staging buffers
  asynchronously and ordering vram tile updates before each submit
  (ivall#455).
- Copy title texture bytes outside the coherent UMA window through a
  reusable thread-local ReadProcessMemory buffer so concurrent page
  decommits cannot fault (ivall#751).
gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 24, 2026
…copy non-coherent reads safely

Integrates upstream PRs ivall#455 and ivall#751:
- Submit title texture upload batches directly on the title's direct
  queue without per-batch CPU fence waits, reclaiming staging buffers
  asynchronously and ordering vram tile updates before each submit
  (ivall#455).
- Copy title texture bytes outside the coherent UMA window through a
  reusable thread-local ReadProcessMemory buffer so concurrent page
  decommits cannot fault (ivall#751).
@iggyvilla

Copy link
Copy Markdown
Contributor

Code read of 4a514ae; nothing built or run. The before_execute gap and the ON_QUEUE lifetime are already in @ethandepstein-del's comment, the destination-resource lifetime in @upipibi's. Not yet mentioned:

  1. A failed wait drops the in-flight batch. title_textures.rs:859-860 and :869-870: texture::wait(dev, queue)? returns early on error, including its 10 s timeout, and the batch f (InFlight: allocator, list, staging) is dropped while the GPU may still run the copy. upload_batch does the opposite for this case (gpu/texture.rs:284-289, mem::forget: "freeing them under the GPU removed the device"). Keep f alive on those paths. They are rare (CreateFence/Signal failing), but they are the paths where the device is already in trouble.
  2. submit_batch makes new objects per batch. It calls CreateCommandAllocator, CreateCommandList and CreateCommittedResource (UPLOAD) each time (gpu/texture.rs:324-328), where upload_batch reuses the Uploader, whose comment (:204-208) says per-batch creation cost 200–650 ms per call under streaming. The PR may still win overall; a submit-thread time under streaming, before and after, would show it. Note also the doc comment above upload_all ("one list and one wait each") is now stale.

When this is stacked under #640/#782, refresh_once remaps evicted textures after its vram::before_execute(q) (:735), so the missing wait in submit_on_title_queue matters for that combination too.

AI use: Claude Code, Claude Sonnet 5.5, read the code at the head above and drafted this; a person checked it before posting.

@raylitebull

Copy link
Copy Markdown
Member

Holding off on merge until the three open review issues are resolved: (1) retaining destination ID3D12Resources in InFlight until GPU completion, (2) calling vram::before_execute before executing the upload, and (3) avoiding dropping InFlight on a failed wait — all likely contributors to the reported RTX 3080 DEVICE_HUNG.

gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 24, 2026
…copy non-coherent reads safely

Integrates upstream PRs xcl-dev#455 and xcl-dev#751:
- Submit title texture upload batches directly on the title's direct
  queue without per-batch CPU fence waits, reclaiming staging buffers
  asynchronously and ordering vram tile updates before each submit
  (xcl-dev#455).
- Copy title texture bytes outside the coherent UMA window through a
  reusable thread-local ReadProcessMemory buffer so concurrent page
  decommits cannot fault (xcl-dev#751).
@Krashgamer

Copy link
Copy Markdown

Measurement at 4a514ae (merged onto main c4d37be with #742, #1791, #1765, #1055; conflict in refresh_once resolved by hand), RTX 3080 10 GB, i7-10700K, retail title, world load, with local timers around title_textures::refresh and its parts. On this machine the CPU wait is not where the refresh time goes. With this PR the slow refreshes take about as long, because the CPU work before the submit dominates.

Time in refresh calls of 50 ms or more, first 150 s:

without (2 runs) with 4a514ae (4 runs)
total 7.6 s, 8.2 s 2.6 s, 8.4 s, 9.9 s, 8.4 s
longest 1.8 s, 1.8 s 0.2 s, 2.6 s, 2.3 s, 2.5 s

Where the time goes inside the uploads with this PR, in the longest refreshes (2 runs, every upload went to the title queue):

  • 1,363 textures / 1.5 GB: hash 579 ms, subresources_of_all 1,001 ms, submit_on_title_queue 606 ms.
  • 1,976 textures / 2.4 GB: hash 761 ms, subresources_of_all 519 ms, submit_on_title_queue 991 ms.
  • Only 9 to 20 textures per refresh were skipped as unchanged, so during the world load the hash mostly costs time: most of these are first uploads.

The write-watch look, the range rebuild, and sparse / vram::before_execute together stay under 30 ms in these refreshes.

So for the world-load stall on this card, the detile (#1512 / #1513) and the hash are the larger parts; this PR's change alone did not shorten it. No device removal in these 4 runs (grahamster2 saw two on an RTX 3080 at an earlier head).

Not tested: the review fixes asked for above; main + this PR alone.

AI use: Claude Code (Claude Opus 5.5) ran the runs, added the local timers and wrote this.

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.