Skip to content

D3D12.X: keep in-flight texture upload objects alive on Signal/wait failure - #1486

Open
b3IKK wants to merge 1 commit into
xcl-dev:mainfrom
b3IKK:gpu/texture-upload-signal-uaf
Open

b3IKK wants to merge 1 commit into
xcl-dev:mainfrom
b3IKK:gpu/texture-upload-signal-uaf

Conversation

@b3IKK

@b3IKK b3IKK commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

After ExecuteCommandLists, upload_batch called Signal and wait and then dropped the allocator, command list and staging buffer unconditionally. If Signal or the wait failed, the CPU freed memory the GPU could still be reading; the same applies to the uploader kept in UPLOADERS, which was keyed only by the queue pointer and could hand a device another device's staging buffer.

This keeps the in-flight objects alive when Signal or the wait fails (finish_gpu_wait forgets them instead of dropping them) and keys the uploader map by (device, queue).

What is in it

  • crates/xcl/src/gpu/texture.rs: finish_gpu_wait; upload_batch keeps (allocator, command list, staging) alive on error; UPLOADERS is keyed by (device, queue); unit test finish_gpu_wait_keeps_inflight_alive_on_error_and_returns_on_ok.
  • The test module's key construction was updated to the new (device, queue) key when rebasing.

Since the last push: rebased onto main 06c9f55. The conflict was in the test module, where main had added large_staging_uses_sixteen_mib_growth_steps / gpu_large_mixed_upload_keeps_tight_staging_and_exact_pixels at the same place; both sides are kept. main also changed the uploader key to (device, queue), so the branch's test now builds that key too.

Tested

  • hardware (GPU + driver, CPU), Windows build, Rust version, debug / release: NVIDIA GeForce RTX 5080 (driver 32.0.16.1088), AMD Ryzen 9 9950X3D, Windows 11 10.0.26300, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.9.2609.5, debug (scripts/test.ps1) and release (scripts/smoke.ps1)
  • .\\scripts\\test.ps1 (cargo build --workspace + cargo test --workspace -- --test-threads=4): 1266 passed, 0 failed, 46 ignored (SKIPPED: the wave64 / direct-DXIL per-lane tests that need 64-lane hardware or a semantics mode this adapter refuses, no heap windows, and cannot disable the driver cache (Windows Developer Mode is required))
  • cargo test -p xcl --lib -- gpu::texture: 15 passed, 0 failed
  • the new test with std::mem::forget(in_flight) put back to std::mem::drop(in_flight): 0 passed, 1 failed — assertion left == right failed: in-flight objects must stay alive on error (left: 1, right: 0)

Regression run

main (426a5a7, clean tree, no local changes):

xcl-smoke v1
commit: 426a5a745db4d5e4b037449ede0b70cb342f5192
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1642 (PresentX 1642)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15158 MB

PR (bd33797, clean tree, no local changes):

xcl-smoke v1
commit: bd33797d4255854b290515dd0c93757ccbf26c96
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1636 (PresentX 1636)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15939 MB

(The main block is 426a5a7, an ancestor of the current main 06c9f55, from the same machine and data folder.)

Not tested

  • a real Signal/wait failure while the GPU is still reading (the test drives finish_gpu_wait directly)
  • AMD GPUs and native wave64 hardware
  • other titles (Minecraft Preview, Unicorn Overlord, Fortnite, XDefiant) and Linux / Wine

AI use

  • OpenCode, Claude Fable 5.2: rebased onto 06c9f55, kept both tests at the conflict, adapted the test to main's (device, queue) key, confirmed the new test fails without the fix, ran the suite and the scripts/smoke.ps1 pair.

@dcastell1

Copy link
Copy Markdown

Verified on Windows 11 10.0.26300, NVIDIA GeForce RTX 5090 (driver 621.24), Rust 1.100.0 MSVC 14.44.35207, debug build, on main@b7aa9f3 (baseline 770 passed, 0 failed, 41 ignored on this box):

patch -p1 < this PR            # clean, no fuzz
cargo test --workspace -- --test-threads=4
771 passed; 0 failed; 41 ignored   (exit 0)

One more than the baseline; keeping in-flight texture upload objects alive is covered and green.

Tree restored afterwards (full diff against a clean checkout), hardware adapter, no Wine, no game data. AI-assisted (opencode): applied the patch to a built tree, ran the suite, reverted it.

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~21 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified main.)

Thanks!

@JJAutoCompare

Copy link
Copy Markdown

Empirical test report (8151725)

PR #1486 at 8151725a18ccc773b0cf23ef1732224c52adc7aa.

Hardware / environment

  • Windows x64 build 26200, AMD Ryzen 7 3800X, Intel Arc A770 with installed driver 32.0.101.9175. Windows also listed a Microsoft Basic Display Adapter.
  • rustc 1.100.0 (0ef1bc386 2026-11-09) and DXC 1.9.2609.5 (01b62ad47). The Cargo test profile was unoptimized, with incremental compilation and debug info disabled.
  • The focused run held the Arc test lock with XCL_ADAPTER=A770 and RUST_TEST_NOCAPTURE=1. The GPU fixture requested the default D3D12 adapter. Its output did not identify the adapter.

Commands and results

  • cargo test --workspace --no-run exited 0 outside Invoke-ArcTest.ps1.

  • Inside Invoke-ArcTest.ps1, ran the compiled library test executable xcl-77aca8ccb20e299f.exe with these exact arguments.

    --exact gpu::texture::tests::finish_gpu_wait_keeps_inflight_alive_on_error_and_returns_on_ok gpu::texture::tests::gpu_upload_batches_reuse_the_queues_upload_buffer
    
  • The focused run exited 0 and finished in 1.80 s. The log recorded 2 passed, 0 failed, 0 ignored, 0 skipped, and 742 filtered out. Both named tests reported ok. Skips were counted from case-sensitive SKIPPED lines.

Observed behavior

  • The drop-counter test passed both branches of finish_gpu_wait. A synthetic error left the in-flight object's drop count at zero. A successful wait returned ownership, and dropping the returned value increased the count to one.
  • Two successful D3D12 upload batches each uploaded three textures with patterned data. The fixture compared the readback subresources with their inputs and verified that both batches retained the same staging buffer and capacity under the (device, queue) cache key.

Not tested

The full GPU workspace suite and game smoke runs were omitted. The focused run did not inject a real D3D12 Signal or fence-wait failure or exercise cache reuse across devices.

AI use

Verified with T3 Code / Codex (gpt-6.2-sol, reasoningEffort: high). Coordinator #2 (T3 Code / Antigravity, gemini-4-neon) verified counts against pr1486-focused.log and published.

@throny throny added the goal:world-load Bears on the retail title getting past world loading label Nov 25, 2026
…ailure

In gpu/texture.rs:
- In upload_batch(), `queue.Signal(&up.fence, up.value)?` returned early
  after ExecuteCommandLists had already submitted `up.list`, dropping `up`
  (releasing its staging buffer, command list, allocator, and fence) while
  the GPU could still execute the list.
- In upload(), a failure from `wait(dev, queue)` dropped `staging`, `list`,
  and `alloc` while the GPU could still execute `list`.
- UPLOADERS was keyed solely by raw `queue` pointer; keying by `(dev, queue)`
  avoids cross-device reuse if a new device allocates a queue at a freed
  queue address.

Route post-submit waits in both upload() and upload_batch() through
finish_gpu_wait(), which leaks the in-flight objects via mem::forget on
any Signal or wait error, and key UPLOADERS by `(dev, queue)`.

Assisted-by: OpenCode (Gemini 4 Neon)
@b3IKK
b3IKK force-pushed the gpu/texture-upload-signal-uaf branch from 8151725 to bd33797 Compare November 25, 2026 16:01
@b3IKK

b3IKK commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto main 06c9f55; the conflict was main's two new staging tests in the same module, and both are kept. main had also changed the uploader key to (device, queue), so the branch's test builds that key now. Head bd33797: suite 1266 passed, 0 failed, 46 ignored; with std::mem::forget(in_flight) replaced by drop the new test fails (left: 1, right: 0); smoke 1636 frames, 0 crashes, 0 removals.

AI use: OpenCode, Claude Fable 5.2 rebased it, adapted the test, ran the suite and the smoke pair and wrote this.

@DavidM1911

Copy link
Copy Markdown
Contributor

Re-verification on RTX 3060 Ti (Windows 11), new head merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.

Thanks!

— Devin

@Decodere

Copy link
Copy Markdown
Contributor

Independent desktop NVIDIA verification of PR #1486 at head bd33797d4255854b290515dd0c93757ccbf26c96 (1 commit; exact parent & merge-base: 06c9f5505f63f10c5ec49ef932d75b2c28177324, pre-#2555 ancestor of main).

Environment

  • GPU: NVIDIA GeForce RTX 4060 (8 GB / 7956 MiB reported by D3D12, Wave32-only Ada), driver 32.0.16.2114 (NVIDIA 621.14, WDDM 3.2)
  • CPU / RAM / OS: Intel Core i5-11400F (6C / 12T), 32 GB RAM (31.9 GiB usable), Windows 11 Home 26200 (Developer Mode off)
  • Toolchain: rustc 1.100.0 (0ef1bc386 2026-11-09) MSVC, DXC 1.9.2609.5, --release

Targeted tests & build (bd33797d)

Command Result
cargo test --release -p xcl --lib -- --nocapture finish_gpu_wait_keeps_inflight_alive_on_error_and_returns_on_ok (3 consecutive runs) 1 passed; 0 failed; 0 ignored; 1222 filtered out × 3 (0.00s, 0.00s, 0.00s, 0 skipped)
cargo test --release -p xcl --lib -- --nocapture gpu::texture:: (3 consecutive runs) 15 passed; 0 failed; 0 ignored; 1208 filtered out × 3 (0.65s, 0.57s, 0.58s; 14 executed incl. 3 live RTX 4060 GPU upload tests with byte_exact=true + 1 self-skipped retail_ttpf_textures_detile_with_their_mip_chains because XCL_SAMPLE_TTPF is unset)
cargo build --release -p xcl Clean build (1m 29s, exit 0, 0 new warnings in gpu/texture.rs)

Paired quiet 60 s retail smoke (title: 29640639)

Exact parent & merge-base (06c9f5505f63f10c5ec49ef932d75b2c28177324, cached baseline on the same machine):

xcl-smoke v1
commit: 06c9f5505f63f10c5ec49ef932d75b2c28177324
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1588 (PresentX 1589)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14452 MB

PR #1486 (bd33797d4255854b290515dd0c93757ccbf26c96):

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

Limits of coverage

  • finish_gpu_wait_keeps_inflight_alive_on_error_and_returns_on_ok and all 14 executed gpu::texture:: tests (including live RTX 4060 gpu_upload_batches_reuse_the_queues_upload_buffer, gpu_console_textures_upload_every_mip_and_slice, and gpu_large_mixed_upload_keeps_tight_staging_and_exact_pixels) passed 3/3; retail_ttpf_textures_detile_with_their_mip_chains self-skipped because XCL_SAMPLE_TTPF was unset.
  • The Signal/fence-wait failure path is verified by the finish_gpu_wait unit test rather than by injecting a live D3D12 device removal during texture upload; the 60 s retail smoke confirms normal upload reuse and runtime stability (0 device removals, 0 crashes, steady 60 Hz), with single-run frame/commit delta vs. the cached parent reflecting normal startup variance.

AI disclosure: test execution and report drafting assisted by Google Antigravity (Gemini 4 Neon).

@ClosetPie107

Copy link
Copy Markdown

Tested on AMD / Linux: bd33797d (RX 9070 16 GB, RDNA4, Mesa 26.3.1 RADV; Ryzen 5 9600X, 32 GB; CachyOS; Proton Experimental experimental-11.0-20261112 with vkd3d-proton master ec207194 plus a local patch dropping the lpVtbl checks of command allocators and lists; DXC 1.9.2609.5; Rust 1.96.0, x86_64-pc-windows-gnu debug build, tests run under Wine)

The head as it is (not merged onto current main), with its base 06c9f550 as the baseline.

Tests (XCL_REQUIRE_GPU=wave64)

  • cargo test -p xcl --lib -- gpu::texture:: --test-threads=1: 15 passed, 0 failed, 0 ignored (includes finish_gpu_wait_keeps_inflight_alive_on_error_and_returns_on_ok).
  • cargo test --workspace --no-fail-fast -- --test-threads=4 with --skip compositor_blends_ui_plane_over_scene_plane --skip failed_restore_stops_before_importing_an_unbacked_window --skip grooming_leaves_a_window_under_1_gib_only_its_hole (here the first loses the RADV device, the other two run out of memory under Wine): lib 1181 passed, 16 failed, 26 ignored; base 06c9f550 (this PR's base) the same session: lib 1180 passed, 16 failed, 26 ignored. The failures are the same set as on the base. The other binaries fail the same 3 tests as on the base (e2e, pls_quota, predication_e2e).
  • d3d12_resource_and_sync: 3 passed, 0 failed on this head; on the base its fence and queue test ended the process (exit 1), which it does in most trees here, main included.

Not tested

  • Native Windows, NVIDIA / Intel
  • A retail title
  • The failure path itself (no Signal or fence-wait failure happened)

AI use

  • Claude Code (Claude Opus 5.5) wrote the test scripts, ran the builds and tests on my machine and wrote this report.

@throny

throny commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

merge-check claim
head: bd33797

@throny

throny commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

merge-check
base: 2c717a0
head: bd33797
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 1467 passed, 0 failed, 47 ignored (26 SKIPPED lines); base alone: 1466 passed, 0 failed, 47 ignored (26 SKIPPED lines)
review: no blocking finding. On main a failed Signal in upload_batch returns early and drops the uploader while its list may still run, and upload() drops allocator, list and staging after a failed wait; the PR keeps them alive in both cases (a deliberate leak on an error path), which is right. Outside the stated purpose: the uploader table's key changes from the queue to (device, queue). The test checks the helper's forget / drop only, not an upload error path. For whoever merges: textual conflicts with #2558 and #2678 in texture.rs, and one in meaning: #2558's new error path drops the in-flight objects when its wait fails, which is what this PR forbids; whichever lands second should route that path through this PR's helper.
performance: none by default (error paths only).
verdict: safe to merge
hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300, Rust 1.100.0, debug. Claude Code; merge, build and suite run by Claude Fable 5.2, diff review by Claude Opus 5.5 (every hunk read; nothing run on the GPU beyond the suite).

@KOLESNiii

Copy link
Copy Markdown
Contributor

merge-check
base: e429936
head: bd33797
merge: conflicts (crates/xcl/src/gpu/texture.rs)
build: not run (the PR does not merge into this base)
tests: not run
review: not done (the merge has conflicts)
performance: not assessed
verdict: not yet: conflicts with main (crates/xcl/src/gpu/texture.rs); rebase onto main
hardware / tool and model: Windows 11 build 26300.9974, NVIDIA GeForce RTX 2070 SUPER 8 GB (driver 621.40, wave32 only), AMD Ryzen 5 3600XT; rustc 1.100.1 (20ddd0171 2026-11-25) x86_64-pc-windows-msvc, debug test profile. Claude Code: Claude Opus 5.5 (coordination, draft).

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Triage (#1607) – head bd33797

Part of this is on main now: commit 5ee1547 (drop_after_wait) handles a failed Signal in upload_batch (fallback queue wait, objects forgotten only if that fails too), and the forget on a failed fence::wait was already there. The PR conflicts with that code and should be rebased onto it.
What main still lacks is the synchronous texture::upload: it still does drop(staging) after wait fails, so finish_gpu_wait((alloc, list, staging), ...) there is still useful.
The UPLOADERS key change to (device, queue) is not mentioned in the title and is a separate change; a queue pointer already identifies its device.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

goal:world-load Bears on the retail title getting past world loading

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants