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

Open
wayward-tail wants to merge 1 commit from upstream-pr/801 into main
wayward-tail commented 2026-11-24 05:37:01 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by wayward-tail on 2026-11-24T05:37:01Z.


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.
<!-- greyfinch-sync:ivall/xcl:issue:5466750607 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/801). Originally posted by [wayward-tail](https://github.com/wayward-tail) on 2026-11-24T05:37:01Z. --- 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.
futurepro62 commented 2026-11-24 07:06:57 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by futurepro62 on 2026-11-24T07:06:08Z.


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.
<!-- greyfinch-sync:ivall/xcl:comment:7124617282 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/801#issuecomment-7124617282). Originally posted by [futurepro62](https://github.com/futurepro62) on 2026-11-24T07:06:08Z. --- 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.
iggyvilla commented 2026-11-24 08:03:48 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by iggyvilla on 2026-11-24T07:34:37Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7125140920 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/801#issuecomment-7125140920). Originally posted by [iggyvilla](https://github.com/iggyvilla) on 2026-11-24T07:34:37Z. --- 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.
throny commented 2026-11-24 21:09:30 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by throny on 2026-11-24T20:29:55Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7143637594 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/801#issuecomment-7143637594). Originally posted by [throny](https://github.com/throny) on 2026-11-24T20:29:55Z. --- <!-- 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.
DavidM1911 commented 2026-11-25 11:09:40 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T10:58:39Z.


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

<!-- greyfinch-sync:ivall/xcl:comment:7160422857 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/801#issuecomment-7160422857). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-25T10:58:39Z. --- Verification on RTX 3060 Ti (Windows 11): **merge conflict with current `main`** — needs a rebase before it can be tested.
Foniass commented 2026-12-01 04:09:15 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T04:09:15Z.


Triage (#1607) – head cb08f9e

Same problem (#1359) as #1404 and #1527, solved differently. This PR runs the driver's Release with TEXTURES held. #1404 forgets early through refcount probes, and #1527 adds release_tracked with a counted fast path.
Main has moved on: res_release now does an AddRef/Release probe and calls title_textures::forget while the object is still alive (the last reference is kept by late_release or released after the cleanup). That covers the single-releaser case. Only two concurrent last-but-one releases can still free the object before forget.
This PR's base predates late_release: release_if_tracked calls the real Release directly, so on main it would bypass the late-release hold for tracked textures. It also holds the global TEXTURES lock across a driver call. The README line is not user-facing.
Recommendation: keep open.

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

<!-- greyfinch-sync:ivall/xcl:comment:7300434099 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/801#issuecomment-7300434099). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T04:09:15Z. --- **Triage (#1607)** – head cb08f9e Same problem (#1359) as #1404 and #1527, solved differently. This PR runs the driver's `Release` with `TEXTURES` held. #1404 forgets early through refcount probes, and #1527 adds `release_tracked` with a counted fast path. Main has moved on: `res_release` now does an `AddRef`/`Release` probe and calls `title_textures::forget` while the object is still alive (the last reference is kept by `late_release` or released after the cleanup). That covers the single-releaser case. Only two concurrent last-but-one releases can still free the object before `forget`. This PR's base predates `late_release`: `release_if_tracked` calls the real `Release` directly, so on main it would bypass the late-release hold for tracked textures. It also holds the global `TEXTURES` lock across a driver call. The README line is not user-facing. Recommendation: keep open. AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/801:upstream-pr/801'
git switch 'upstream-pr/801'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/801'
git switch 'upstream-pr/801'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/801'
git switch 'upstream-pr/801'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/801'
git switch 'main'
git merge --squash 'upstream-pr/801'
git switch 'main'
git merge --ff-only 'upstream-pr/801'
git switch 'main'
git merge 'upstream-pr/801'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!795
No description provided.