Skip to content

D3D12.X: abort failed device batches and restore pending in title_textures::upload_all - #2224

Open
Decodere wants to merge 1 commit into
xcl-dev:mainfrom
Decodere:fix-2109-upload-all-abort-restore
Open

Decodere wants to merge 1 commit into
xcl-dev:mainfrom
Decodere:fix-2109-upload-all-abort-restore

Conversation

@Decodere

@Decodere Decodere commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

What is in it

Part of #2109.

When upload_queue or texture::upload_batch fails in title_textures::upload_all() (for example after a 10 s GPU wait timeout on a stalled queue), upload_all() previously kept submitting every remaining batch in todo for the same device, turning one stalled queue into an N × 10 s freeze while leaving failed and skipped textures stuck with pending = false and stale LAST_CONTENT hashes.

This change extracts pure-CPU batch-control (run_upload_batches) and pending-restoration (restore_pending) helpers in crates/xcl/src/hle/d3d12x/title_textures.rs without changing texture.rs or any other file:

  • Track failed_devices: Vec<usize> across batches (zero allocations on the happy path). Once upload_queue or texture::upload_batch returns Err(e) for a device, log via warn(&e) and mark that device failed so all remaining todo items for that device are drained without running content_hash / same_as_last_upload / subresources_of_all / upload_batch, while unaffected devices continue uploading normally.
  • Clear LAST_CONTENT for every resource in a failed Err batch (so retries cannot false-skip as unchanged) and for each failed index in a partial Ok(failed) result. On Ok(failed), count only (batch.len() - failed_keys.len()) toward UPLOADS and do not restore pending (avoiding infinite retry loops on permanently failing textures).
  • Retain the ID3D12Resource handles of failed and skipped same-device items until after the loop, lock TEXTURES once to restore pending = true (and increment PENDING by the exact restored count) only on active by_res entries where !e.pending && !e.gpu_written, and drop the retained ID3D12Resource handles after releasing TEXTURES so raw pointers stay pinned during lookup and COM Release -> forget() cannot re-enter TEXTURES.
  • Scoped strictly to stopping the cascading timeout storm and restoring pending after batch failures (Part of #2109); does not claim to fix the upstream RTX 3090 GPU queue stall itself.

(Rebased onto origin/main 50a9fdef to integrate #2306's vram::level_pages() -> map_levels_with_texels(&r, &subs) call cleanly inside upload_all's batch submit closure.)

Tested

  • Failing-first verification before the fix: running the three new pure-CPU unit tests against pre-fix batch-loop/restore behavior failed all three (upload_all_*: 0 passed / 2 failed — device 1 submitted all 4 batches instead of aborting after batch 1 and left retry empty; restore_pending_*: 0 passed / 1 failed — returned 0 instead of 1).
  • Targeted unit tests (cargo test --release -p xcl --lib hle::d3d12x::title_textures::tests:: -- --test-threads=1 --nocapture on 85d79bf6 atop 50a9fdef): 22 passed, 0 failed, 0 ignored (0.93 s, 0 skipped — includes all existing GPU upload tests, D3D12.X: XCL_TEXTURE_LEVEL_PAGES=1 gives a sampled texture's levels their pages with their texels #2306's a_placed_texture_gets_the_pages_of_a_level_with_its_texels, and all 3 new tests: upload_all_aborts_failed_device_batches_while_other_devices_continue, upload_all_clears_last_content_on_batch_err_and_partial_ok_without_poisoning_skipped, and restore_pending_requeues_only_active_non_pending_non_gpu_written_entries).
  • Full workspace release build and test suite (cargo build --release --workspace and cargo test --release --workspace --no-fail-fast -- --test-threads=4 --nocapture on Windows 11, Intel Core i5-11400F, NVIDIA GeForce RTX 4060 driver 621.14, DXC 1.9.2609.5): 23 test binaries, 1291 passed, 1 failed, 46 ignored, where the sole failure is origin/main 50a9fdef's pre-existing gpu::recomp::lower_dxil::tests::a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier (left: 3, right: 1, failing on main CI run 45656870453 after Recompiler: a bridged mask write in the split form meets no barrier #2074), plus 28 runtime SKIPPED lines (21 no wave64 on RTX 4060, 3 wave32 per-lane form refused by driver, 2 missing d3d12SDKLayers.dll / D3D12 debug layer, 1 driver shader cache toggle unavailable, 1 no heap windows).

Regression run

Baseline (origin/main 50a9fdef81cb796b8756a31defb0648301d002ce):

xcl-smoke v1
commit: 50a9fdef81cb796b8756a31defb0648301d002ce
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1544 (PresentX 1544)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 13995 MB

PR head (85d79bf639d42a0c7149c3efcadf6bb0cd3abb1a):

xcl-smoke v1
commit: 85d79bf639d42a0c7149c3efcadf6bb0cd3abb1a
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1565 (PresentX 1565)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 13986 MB

Not tested

  • Did not reproduce a real RTX 3090 / hardware GPU queue stall or 10 s texture::upload_batch timeout on live D3D12 hardware; failure-path batch abort, LAST_CONTENT invalidation, and restore_pending state transitions are covered by the new pure-CPU unit tests, while the happy path ran under the RTX 4060 GPU unit tests and 60 s smoke test above.
  • The 28 runtime-skipped tests (wave64 hardware, driver-refused wave32 per-lane forms, D3D12 debug layer, driver shader cache toggle, and heap windows) and 46 #[ignore] tests did not execute on this machine.
  • Did not test multi-GPU / multi-ID3D12Device hardware scenarios live (covered by pure-CPU unit test).

AI use

Implemented and verified with Google Antigravity (Gemini 4 Neon). All code changes, failing-first and post-fix unit tests, full workspace release tests, and paired 60 s RTX 4060 smoke runs were reviewed and executed locally.

@raylitebull

Copy link
Copy Markdown
Member

Code review on 3a60f54:

  • run_upload_batches + restore_pending in crates/xcl/src/hle/d3d12x/title_textures.rs cleanly stops submitting subsequent batches for a failed device, preserves LAST_CONTENT for unchanged/skipped entries while clearing failed keys, and re-marks pending only for active !pending && !gpu_written entries (dropping COM handles outside TEXTURES to prevent lock re-entry).
  • Build and test and PR description are both green (CLEAN).

Remaining before merge: Dual-vendor (AMD + NVIDIA) verification on 3a60f54.

@tiagonleal

Copy link
Copy Markdown
Contributor

Verification on NVIDIA RTX 5070 Ti (Windows 11), head 3a60f54e96c01ea9600744ba69ce3d2d39cf91b3

Tested

  • Head 3a60f54e96c01ea9600744ba69ce3d2d39cf91b3 (git rev-parse HEAD of a clean worktree, no local changes, built as is; merge-base with main 568e7db7729c8fa6c8f0f4b32d798faaf11462bb). The PR was open and the head unchanged when I started and again before writing this.
  • Windows 11 Pro 10.0.26300 (Developer Mode off), NVIDIA GeForce RTX 5070 Ti 16 GB (driver 32.0.16.1742), AMD Ryzen 7 9800X3D, 32 GB RAM, rustc 1.100.0 (0ef1bc386 2026-11-09), cargo 1.100.0, debug profile (the cargo test default), DXC from the Windows SDK 10.0.26100.0 (dxcompiler/dxil 1.8.2502.11).
  • cargo test -p xcl --lib title_textures -- --test-threads=4 --nocapture: 17 passed, 0 failed, 0 ignored (9 s). This includes the three new tests (upload_all_aborts_failed_device_batches_while_other_devices_continue, upload_all_clears_last_content_on_batch_err_and_partial_ok_without_poisoning_skipped, restore_pending_requeues_only_active_non_pending_non_gpu_written_entries).
  • cargo test -p xcl --lib hle::d3d12x -- --test-threads=4 --nocapture: 180 passed, 0 failed, 2 ignored (11 s).
  • cargo test -p xcl --lib -- --test-threads=4 --nocapture (whole lib): 1097 passed, 4 failed, 26 ignored. The 4 failures are gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_0 to _3, each with CreateComputePipelineState: Not enough memory resources are available to complete this operation. (0x8007000E). They are not from this PR: the same four tests fail with the same message on its merge-base 568e7db (same command: 1094 passed, 4 failed, 26 ignored; the 3 extra passes here are this PR's new tests). Running gpu::dxil::fuzz_tests alone at this head, twice, gave 4 failed both times (and fuzz_validate_and_gpu_0 alone with --test-threads=1 failed too), and gpu::dxil::fuzz_tests on the merge-base gave 4 failed again.
  • SKIPPED lines in the whole-lib run: 23 GPU tests with no wave64 or refused (unsupported V_MUL_F16 / V_PK_MUL_F16 / V_CVT_F16_F32 ...) on this wave32-only GPU, and shaders::tests::pso_measurement_compiles_an_exact_synthetic_record: cannot disable the driver cache (Windows Developer Mode is required), 0x887A002D.

Not tested

  • AMD (the other half of the requested dual-vendor check).
  • Developer Mode on (it is off here), symlink behaviour.
  • The retail game and any xcl-smoke run; this is a unit-test run only.
  • cargo test --workspace and the other test targets under crates/xcl/tests; release profile.
  • A separate game job was using the same machine in bursts. I started each run when no game process above 2 GB was running, but the whole-lib run happened close to such a burst.

AI use

  • Claude Code created the clean worktree, built and ran the tests above, compared the failing tests with the merge-base, and wrote this report. No code was changed.

Run and written with Claude Code (Claude Fable 5.2 and Claude Sonnet 5.5).

…tures::upload_all

When `upload_queue` or `texture::upload_batch` fails (for example, a 10 s GPU
wait timeout), `title_textures::upload_all()` previously kept submitting every
remaining batch in `todo` for the same device, turning a single stalled queue
into an `N x 10 s` freeze and leaking failed/skipped textures with `pending = false`
and stale `LAST_CONTENT` hashes.

Track failed devices across batches via `run_upload_batches` and `restore_pending`:
- Once a device returns `Err` from `upload_queue` or `texture::upload_batch`, skip
  remaining `todo` items for that device (avoiding `content_hash`, detiling, and
  further submits) while still allowing unaffected devices to upload normally.
- Clear `LAST_CONTENT` for every resource in a failed `Err` batch and for each
  failed item in a partial `Ok(failed)` result (counting only succeeded uploads
  toward `UPLOADS`, without requeuing permanently failing `Ok(failed)` items).
- Keep the `ID3D12Resource` handles for failed/skipped batch items alive across a
  single `TEXTURES` lock after the loop to restore `pending = true` (and increment
  `PENDING`) only on active `!pending && !gpu_written` entries, dropping the
  handles after releasing `TEXTURES` so COM release cannot re-enter the lock.

Part of xcl-dev#2109
Assisted-by: Google Antigravity (Gemini 4 Neon)
@Decodere
Decodere force-pushed the fix-2109-upload-all-abort-restore branch from 3a60f54 to 85d79bf Compare November 25, 2026 17:14
@Decodere

Copy link
Copy Markdown
Contributor Author

Rebased onto 50a9fdef (85d79bf6, preserving #2306's vram::level_pages() / map_levels_with_texels and vram::before_execute inside upload_all). Re-verified title_textures::tests (22/0), paired 60 s RTX 4060 smoke (1544 -> 1565, 0 device removals/crashes), and workspace (1291 passed, 1 failed solely on 50a9fdef's #2074 test).

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