D3D12.X: remove tracked textures atomically on final Release #801

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

@⁠wayward-tail on GitHub · 2026-11-24 05:37 UTC · original
wayward-tail:pr/tracked-texture-release → main · +75 −2 · 3 files · 1 commits · draft

A tracked resource could be destroyed by its final COM Release before it was removed from the texture table. A concurrent refresh could then AddRef the stale pointer. Hold TEXTURES across the real Release and remove the entry before unlocking when its refcount reaches zero.

What is in it

  • real.rs / title_textures.rs: perform tracked Release and table removal atomically, finish remapping after unlocking, and test tracked/nontracked and final/nonfinal releases.
  • README note describing the behavior.

Tested

  • Commit cb08f9e464d09060850734e9b0962b80d31b2740; Windows 11 Home build 26200, AMD Ryzen 7 8845HS, NVIDIA RTX 4060 Laptop GPU (driver 32.0.15.9282), Rust 1.100.0 MSVC, DXC 1.9.2609.5. Tests debug; title smoke release with symbols. XCL_ADAPTER=rtx 4060.
  • cargo build --workspace and cargo build --release -p xcl: succeeded.
  • cargo test --workspace --no-fail-fast -- --test-threads=4: 701 passed, 1 failed, 41 ignored. The two wave64 skips below are included in Cargo's passed count.
  • Baseline 64b3f35: 700 passed, 1 failed, 41 ignored. gpu_clamp_and_omod_per_instruction fails at v_pk_add_i16 clamp on unmodified main on this GPU.
  • Branch failures: gpu::recomp::tests::gpu_clamp_and_omod_per_instruction.
  • GPU skips: SKIPPED gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask: no wave64; SKIPPED gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware: no wave64.

Regression run
Main:

xcl-smoke v1
commit: 64b3f35599bb7102f55d640e1a791e7d6dd3b175
gpu: NVIDIA GeForce RTX 4060 Laptop GPU
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 989 (PresentX 990)
presents per 2 s (last 3): 50 49 53
device removals: 0
crashes: 0
peak commit: 15068 MB

This branch:

xcl-smoke v1
commit: cb08f9e464d09060850734e9b0962b80d31b2740
gpu: NVIDIA GeForce RTX 4060 Laptop GPU
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1099 (PresentX 1100)
presents per 2 s (last 3): 39 10 47
device removals: 0
crashes: 0
peak commit: 16286 MB

Not tested

  • AMD / Intel GPU behavior, wave64, gameplay and sustained streaming. The smoke runs exercise startup without menu input.
  • Tests requiring XCL_SAMPLE_* game-data variables: unset, so those bodies were not exercised.
  • Not merge-ready while the full suite has failures; retained as a draft with the upstream baseline failure disclosed.

AI use

  • OpenAI Codex (GPT-6) reconciled the existing local fix with upstream, adjusted the regression test where needed, ran validation, and prepared this description. The existing local commit's original model provenance is unknown.
**@⁠wayward-tail** on GitHub · 2026-11-24 05:37 UTC · [original](https://github.com/xcl-dev/xcl/pull/801) `wayward-tail:pr/tracked-texture-release` → `main` · +75 −2 · 3 files · 1 commits · draft A tracked resource could be destroyed by its final COM Release before it was removed from the texture table. A concurrent refresh could then AddRef the stale pointer. Hold TEXTURES across the real Release and remove the entry before unlocking when its refcount reaches zero. **What is in it** - real.rs / title_textures.rs: perform tracked Release and table removal atomically, finish remapping after unlocking, and test tracked/nontracked and final/nonfinal releases. - README note describing the behavior. **Tested** - Commit `cb08f9e464d09060850734e9b0962b80d31b2740`; Windows 11 Home build 26200, AMD Ryzen 7 8845HS, NVIDIA RTX 4060 Laptop GPU (driver 32.0.15.9282), Rust 1.100.0 MSVC, DXC 1.9.2609.5. Tests debug; title smoke release with symbols. `XCL_ADAPTER=rtx 4060`. - `cargo build --workspace` and `cargo build --release -p xcl`: succeeded. - `cargo test --workspace --no-fail-fast -- --test-threads=4`: 701 passed, 1 failed, 41 ignored. The two wave64 skips below are included in Cargo's passed count. - Baseline `64b3f35`: 700 passed, 1 failed, 41 ignored. `gpu_clamp_and_omod_per_instruction` fails at `v_pk_add_i16 clamp` on unmodified main on this GPU. - Branch failures: gpu::recomp::tests::gpu_clamp_and_omod_per_instruction. - GPU skips: SKIPPED gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask: no wave64; SKIPPED gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware: no wave64. **Regression run** Main: ``` xcl-smoke v1 commit: 64b3f35599bb7102f55d640e1a791e7d6dd3b175 gpu: NVIDIA GeForce RTX 4060 Laptop GPU title: 3c290c16 seconds: 60 exit: 0x0 frames shown: 989 (PresentX 990) presents per 2 s (last 3): 50 49 53 device removals: 0 crashes: 0 peak commit: 15068 MB ``` This branch: ``` xcl-smoke v1 commit: cb08f9e464d09060850734e9b0962b80d31b2740 gpu: NVIDIA GeForce RTX 4060 Laptop GPU title: 3c290c16 seconds: 60 exit: 0x0 frames shown: 1099 (PresentX 1100) presents per 2 s (last 3): 39 10 47 device removals: 0 crashes: 0 peak commit: 16286 MB ``` **Not tested** - AMD / Intel GPU behavior, wave64, gameplay and sustained streaming. The smoke runs exercise startup without menu input. - Tests requiring `XCL_SAMPLE_*` game-data variables: unset, so those bodies were not exercised. - Not merge-ready while the full suite has failures; retained as a draft with the upstream baseline failure disclosed. **AI use** - OpenAI Codex (GPT-6) reconciled the existing local fix with upstream, adjusted the regression test where needed, ran validation, and prepared this description. The existing local commit's original model provenance is unknown.
res_release() previously called the underlying COM Release() before calling title_textures::forget(). When refcount dropped to zero, D3D12Core tore down the driver resource handle while the raw pointer remained in TEXTURES, allowing a concurrent title_textures::refresh() to AddRef a dead ID3D12Resource and crash inside the driver's ResourceBarrier path (0xC0000005 null read).

Run Release() for tracked textures under TEXTURES.lock() and remove the entry before releasing the lock whenever refcount reaches zero.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:33:07 +00:00
Author
Owner

@⁠futurepro62 on GitHub · 2026-11-24 07:06 UTC · original

Full-suite run, since this PR has no test report yet. Tested exact head cb08f9e (on its base 64b3f35).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4: 702 passed, 0 failed, 41 ignored. SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.
  • The new tests ran and passed: release_if_tracked_removes_atomically_under_textures_lock.

Not tested

  • AMD, a release build, a game (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
**@⁠futurepro62** on GitHub · 2026-11-24 07:06 UTC · [original](https://github.com/xcl-dev/xcl/pull/801#issuecomment-7124617282) Full-suite run, since this PR has no test report yet. Tested exact head `cb08f9e` (on its base `64b3f35`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, debug, D3D12 debug layer installed. - `cargo build --workspace`, then `XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4`: **702 passed, 0 failed, 41 ignored**. SKIPPED (no wave64): `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware`. - The new tests ran and passed: `release_if_tracked_removes_atomically_under_textures_lock`. **Not tested** - AMD, a release build, a game (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
Author
Owner

@⁠iggyvilla on GitHub · 2026-11-24 07:34 UTC · original

Code read of head cb08f9e (static read only; nothing built or run). The race is real: refresh_once clones tracked resources under TEXTURES, and removing the entry in the same critical section as the final Release closes the window between Release() == 0 and forget(). I looked for a self-deadlock (a Release of an XCL-held clone while TEXTURES is held) and did not find one: every clone made under the lock (title_textures.rs:298 clone_resources) is returned out of the lock before it is dropped.

One concern: cost on the hot path. res_release (real.rs:1547) is the patched Release of every resource XCL hands out, buffers included. It now calls release_if_tracked, which takes the global TEXTURES mutex first (title_textures.rs:506) to find out whether the resource is tracked, and for a tracked one runs the driver's Release under that lock (:510). Before, the fast path was a plain f(this). So every Release in the title (per-frame buffers, XCL's own clone drops after an upload) now contends with refresh, submitted and note_transitions, which hold the same mutex. I did not measure it, so it may be nothing; can you say what the 60 s smoke shows for frames and for refresh time against main? If it matters, a check that does not take the lock for untracked resources (a marker on the object, or an atomic count of tracked textures as a first gate) would leave the lock to the ones that need it.

The test proves Release runs under TEXTURES; it does not run a second thread doing what refresh does (lock, clone) during the final release, so it would still pass if the removal moved back outside the lock.

AI use: Claude Code, Claude Sonnet 5.5, read the diff and the code around it at the head named above and drafted this comment; I checked each line reference.

**@⁠iggyvilla** on GitHub · 2026-11-24 07:34 UTC · [original](https://github.com/xcl-dev/xcl/pull/801#issuecomment-7125140920) Code read of head `cb08f9e` (static read only; nothing built or run). The race is real: `refresh_once` clones tracked resources under `TEXTURES`, and removing the entry in the same critical section as the final `Release` closes the window between `Release() == 0` and `forget()`. I looked for a self-deadlock (a `Release` of an XCL-held clone while `TEXTURES` is held) and did not find one: every clone made under the lock (`title_textures.rs:298` `clone_resources`) is returned out of the lock before it is dropped. One concern: **cost on the hot path.** `res_release` (`real.rs:1547`) is the patched `Release` of every resource XCL hands out, buffers included. It now calls `release_if_tracked`, which takes the global `TEXTURES` mutex first (`title_textures.rs:506`) to find out whether the resource is tracked, and for a tracked one runs the driver's `Release` under that lock (`:510`). Before, the fast path was a plain `f(this)`. So every `Release` in the title (per-frame buffers, XCL's own clone drops after an upload) now contends with `refresh`, `submitted` and `note_transitions`, which hold the same mutex. I did not measure it, so it may be nothing; can you say what the 60 s smoke shows for frames and for `refresh` time against `main`? If it matters, a check that does not take the lock for untracked resources (a marker on the object, or an atomic count of tracked textures as a first gate) would leave the lock to the ones that need it. The test proves `Release` runs under `TEXTURES`; it does not run a second thread doing what `refresh` does (lock, `clone`) during the final release, so it would still pass if the removal moved back outside the lock. AI use: Claude Code, Claude Sonnet 5.5, read the diff and the code around it at the head named above and drafted this comment; I checked each line reference.
Author
Owner

@⁠throny on GitHub · 2026-11-24 20:29 UTC · original

Two contributors checked independently and found that #1404 #1527 solves the same problem (for #1359) in a different way: #1607, group D38. You may want to compare them with the other author and agree on one, or say in the PR why both are needed.

This is a hint, not a request from the maintainers; nobody from the project has adopted #1607 so far.

AI use: Claude Code (Claude Opus 5.5), posted by a script from the #1607 table.

**@⁠throny** on GitHub · 2026-11-24 20:29 UTC · [original](https://github.com/xcl-dev/xcl/pull/801#issuecomment-7143637594) <!-- xcl-1607-hint:D38 --> Two contributors checked independently and found that #1404 #1527 solves the same problem (for #1359) in a different way: #1607, group D38. You may want to compare them with the other author and agree on one, or say in the PR why both are needed. This is a hint, not a request from the maintainers; nobody from the project has adopted #1607 so far. AI use: Claude Code (Claude Opus 5.5), posted by a script from the #1607 table.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 10:58 UTC · original

Verification on RTX 3060 Ti (Windows 11): merge conflict with current main — needs a rebase before it can be tested.

**@⁠DavidM1911** on GitHub · 2026-11-25 10:58 UTC · [original](https://github.com/xcl-dev/xcl/pull/801#issuecomment-7160422857) Verification on RTX 3060 Ti (Windows 11): **merge conflict with current `main`** — needs a rebase before it can be tested.
This pull request has changes conflicting with the target branch.
  • README.md
  • crates/xcl/src/hle/d3d12x/real.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

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