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

Open
github-bot wants to merge 1 commit from github-bot/gh-1486 into main AGit
Owner

@⁠b3IKK on GitHub · 2026-11-24 16:50 UTC · original
b3IKK:gpu/texture-upload-signal-uaf → main · +52 −18 · 1 files · 1 commits · open

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.
**@⁠b3IKK** on GitHub · 2026-11-24 16:50 UTC · [original](https://github.com/xcl-dev/xcl/pull/1486) `b3IKK:gpu/texture-upload-signal-uaf` → `main` · +52 −18 · 1 files · 1 commits · open 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.
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)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:55:22 +00:00
Author
Owner

@⁠dcastell1 on GitHub · 2026-11-24 16:55 UTC · original

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.

**@⁠dcastell1** on GitHub · 2026-11-24 16:55 UTC · [original](https://github.com/xcl-dev/xcl/pull/1486#issuecomment-7138417662) 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.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-24 18:53 UTC · original

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!

**@⁠DavidM1911** on GitHub · 2026-11-24 18:53 UTC · [original](https://github.com/xcl-dev/xcl/pull/1486#issuecomment-7141296103) 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!
Author
Owner

@⁠JJAutoCompare on GitHub · 2026-11-25 05:26 UTC · original

Empirical test report (8151725a)

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.

**@⁠JJAutoCompare** on GitHub · 2026-11-25 05:26 UTC · [original](https://github.com/xcl-dev/xcl/pull/1486#issuecomment-7153771418) ### Empirical test report (8151725a) 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. ```text --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.
Author
Owner

@⁠b3IKK on GitHub · 2026-11-25 16:04 UTC · original

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.

**@⁠b3IKK** on GitHub · 2026-11-25 16:04 UTC · [original](https://github.com/xcl-dev/xcl/pull/1486#issuecomment-7167566431) 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.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-26 05:27 UTC · original

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

**@⁠DavidM1911** on GitHub · 2026-11-26 05:27 UTC · [original](https://github.com/xcl-dev/xcl/pull/1486#issuecomment-7183504529) 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
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1486/head:github-bot/gh-1486'
git switch 'github-bot/gh-1486'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1486'
git switch 'github-bot/gh-1486'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1486'
git switch 'github-bot/gh-1486'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1486'
git switch 'main'
git merge --squash 'github-bot/gh-1486'
git switch 'main'
git merge --ff-only 'github-bot/gh-1486'
git switch 'main'
git merge 'github-bot/gh-1486'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.