D3D12.X: remove tracked textures before final COM release #1527

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

@⁠OtavioTadeu on GitHub · 2026-11-24 17:17 UTC · original
OtavioTadeu:fix/d3d12x-tracked-release-1359 → main · +244 −27 · 2 files · 1 commits · open

Synchronizes real::res_release with title_textures::TEXTURES so tracked resources are removed before their COM refcount can drop to 0 (under XCL_LATE_RELEASE=0 or a concurrent refcount-2 race), preventing refresh_once and clone_resources from calling AddRef on freed memory. Fixes #1359.

What is in it

  • crates/xcl/src/hle/d3d12x/title_textures.rs: add TRACKED_COUNT, ReleaseOutcome, release_tracked, and unit + concurrent refcount-2 race tests
  • crates/xcl/src/hle/d3d12x/real.rs: route res_release through title_textures::release_tracked before final release and cleanup

Tested

  • NVIDIA GeForce GTX 1660 SUPER (driver 32.0.16.1088), AMD Ryzen 5 5600G, Windows 11 build 26200, DXC 1.9.2602.17 (Windows SDK 10.0.26100.0), rustc 1.100.0 (stable-x86_64-pc-windows-msvc), debug build
  • cargo test --workspace -- --test-threads=4: 777 passed, 0 failed, 41 ignored (SKIPPED GPU tests: gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask [no wave64], gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware [no wave64], heap_window_out_of_memory_falls_back_to_the_switch_form [no heap windows])
  • cargo test -p xcl --lib title_textures: 14 passed, 0 failed
  • cargo test -p xcl --lib d3d12x: 144 passed, 0 failed, 1 ignored

Regression run

  • scripts/smoke.ps1 -Game retail_title -Seconds 60 (main baseline vs PR head on NVIDIA GeForce GTX 1660 SUPER):

xcl-smoke v1

commit: 9e3831e1f570d3646e53ab753b19ec07eb8f1485

gpu: NVIDIA GeForce GTX 1660 SUPER

title: retail_title

seconds: 60

exit: 0x0

frames shown: 631 (PresentX 631)

presents per 2 s (last 3): 47 47 49

device removals: 0

crashes: 0

peak commit: 15199 MB


xcl-smoke v1

commit: 25fe06723d867defb80671d309a002f30a17475f

gpu: NVIDIA GeForce GTX 1660 SUPER

title: retail_title

seconds: 60

exit: 0x0

frames shown: 644 (PresentX 644)

presents per 2 s (last 3): 44 46 44

device removals: 0

crashes: 0

peak commit: 15211 MB

Not tested

  • AMD / native wave64 GPUs, Linux/Wine, and extended gameplay past the 60 s smoke window

AI use

  • Antigravity with Gemini 4 Neon: analyzed the issue, wrote the fix, tests, and PR description; reviewed by author.
**@⁠OtavioTadeu** on GitHub · 2026-11-24 17:17 UTC · [original](https://github.com/xcl-dev/xcl/pull/1527) `OtavioTadeu:fix/d3d12x-tracked-release-1359` → `main` · +244 −27 · 2 files · 1 commits · open Synchronizes `real::res_release` with `title_textures::TEXTURES` so tracked resources are removed before their COM refcount can drop to 0 (under `XCL_LATE_RELEASE=0` or a concurrent refcount-2 race), preventing `refresh_once` and `clone_resources` from calling `AddRef` on freed memory. Fixes #1359. **What is in it** - `crates/xcl/src/hle/d3d12x/title_textures.rs`: add `TRACKED_COUNT`, `ReleaseOutcome`, `release_tracked`, and unit + concurrent refcount-2 race tests - `crates/xcl/src/hle/d3d12x/real.rs`: route `res_release` through `title_textures::release_tracked` before final release and cleanup **Tested** - NVIDIA GeForce GTX 1660 SUPER (driver 32.0.16.1088), AMD Ryzen 5 5600G, Windows 11 build 26200, DXC 1.9.2602.17 (Windows SDK 10.0.26100.0), rustc 1.100.0 (`stable-x86_64-pc-windows-msvc`), debug build - `cargo test --workspace -- --test-threads=4`: 777 passed, 0 failed, 41 ignored (SKIPPED GPU tests: `gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask` [no wave64], `gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware` [no wave64], `heap_window_out_of_memory_falls_back_to_the_switch_form` [no heap windows]) - `cargo test -p xcl --lib title_textures`: 14 passed, 0 failed - `cargo test -p xcl --lib d3d12x`: 144 passed, 0 failed, 1 ignored **Regression run** - `scripts/smoke.ps1 -Game retail_title -Seconds 60` (`main` baseline vs PR head on NVIDIA GeForce GTX 1660 SUPER): ``` xcl-smoke v1 commit: 9e3831e1f570d3646e53ab753b19ec07eb8f1485 gpu: NVIDIA GeForce GTX 1660 SUPER title: retail_title seconds: 60 exit: 0x0 frames shown: 631 (PresentX 631) presents per 2 s (last 3): 47 47 49 device removals: 0 crashes: 0 peak commit: 15199 MB ``` ``` xcl-smoke v1 commit: 25fe06723d867defb80671d309a002f30a17475f gpu: NVIDIA GeForce GTX 1660 SUPER title: retail_title seconds: 60 exit: 0x0 frames shown: 644 (PresentX 644) presents per 2 s (last 3): 44 46 44 device removals: 0 crashes: 0 peak commit: 15211 MB ``` **Not tested** - AMD / native wave64 GPUs, Linux/Wine, and extended gameplay past the 60 s smoke window **AI use** - Antigravity with Gemini 4 Neon: analyzed the issue, wrote the fix, tests, and PR description; reviewed by author.
Synchronizes res_release with title_textures::TEXTURES via release_tracked so tracked resources are removed before their refcount drops to 0 (including under XCL_LATE_RELEASE=0 or a refcount-2 race), preventing refresh_once/clone_resources from calling AddRef on a freed ID3D12Resource.

Fixes #1359.
Verified with cargo test -p xcl --lib title_textures (14 passed) and d3d12x (144 passed, 1 ignored).

Assisted-by: Antigravity (Gemini 4 Neon)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:56:32 +00:00
Author
Owner

@⁠upipibi on GitHub · 2026-11-24 17:47 UTC · original

Duplicate note: #1404 (opened earlier, not a draft, 3 comments) also fixes #1359 in real::res_release. The approaches differ:

  • #1404: +15/−2 in real.rs. It calls title_textures::forget from the reference count Release returns, and around an extra AddRef.
  • This PR: routes the release through a new title_textures::release_tracked (+202 in title_textures.rs), with unit tests and a concurrent refcount-2 race test.

Both edit res_release, so only one can land. Comparison only: I haven't run either.

AI use: Claude Code (Claude Opus 5.5) compared the diffs and wrote this.

**@⁠upipibi** on GitHub · 2026-11-24 17:47 UTC · [original](https://github.com/xcl-dev/xcl/pull/1527#issuecomment-7139719631) Duplicate note: #1404 (opened earlier, not a draft, 3 comments) also fixes #1359 in `real::res_release`. The approaches differ: - #1404: +15/−2 in `real.rs`. It calls `title_textures::forget` from the reference count `Release` returns, and around an extra `AddRef`. - This PR: routes the release through a new `title_textures::release_tracked` (+202 in `title_textures.rs`), with unit tests and a concurrent refcount-2 race test. Both edit `res_release`, so only one can land. Comparison only: I haven't run either. AI use: Claude Code (Claude Opus 5.5) compared the diffs and wrote this.
Author
Owner

@⁠Belox17 on GitHub · 2026-11-24 18:48 UTC · original

Test report for 0789e88b / 7c748c8b on NVIDIA (RTX 3060 Ti): the whole suite passes, but the new test is flaky and takes two other tests down with it

Tested

  • NVIDIA GeForce RTX 3060 Ti 8 GB, driver 32.0.16.2124; Ryzen 5 5600X; Windows 11 build 26300; rustc 1.98.1 MSVC; debug build. Head 0789e88b as is, clean tree. The current head 7c748c8b is the same patch rebased onto 9e3831e (git range-diff); its tree is identical to my merge of 0789e88b into 9e3831e, and the test is unchanged.
  • cargo test --workspace -- --test-threads=4: 771 passed, 0 failed, 41 ignored (base b7aa9f3: 770). Merged into 9e3831e: 777 passed, 0 failed, 41 ignored.
  • cargo test -p xcl --lib tracked_release_removes_entry, alone, 20 runs: 13 passed, 7 failed, always object not freed on iteration N (title_textures.rs:2181; N = 2, 14, 70, 85, 115, 208, 460).
  • cargo test -p xcl --lib title_textures -- --test-threads=4, 10 runs: 5 passed, 5 failed. Each failed run has 3 failures: this test, plus placed_title_textures_share_vram_and_preserve_pixels and transitions_apply_when_their_list_is_submitted with PoisonError, because the panic happens while TEST_LOCK is held.

Likely cause, from reading the test (I did not instrument it): the reader thread AddRefs every tracked key under the TEXTURES lock and releases it later through release_tracked. When the reader holds the last reference in an iteration, the final mock_release runs on the reader thread, possibly after t2.join(), so obj.freed can still be false at the assertion. Waiting until the reader has dropped its references to the current object (or keeping the reader away from the object under test) before asserting would make the check deterministic.

Not tested

  • res_release with a title (late release on and XCL_LATE_RELEASE=0); AMD; any retail title (no smoke run).

AI use: Claude Code (Claude Opus 5.5) ran the commands and wrote this report; I checked it before posting.

**@⁠Belox17** on GitHub · 2026-11-24 18:48 UTC · [original](https://github.com/xcl-dev/xcl/pull/1527#issuecomment-7141187587) **Test report for `0789e88b` / `7c748c8b` on NVIDIA (RTX 3060 Ti): the whole suite passes, but the new test is flaky and takes two other tests down with it** **Tested** - NVIDIA GeForce RTX 3060 Ti 8 GB, driver 32.0.16.2124; Ryzen 5 5600X; Windows 11 build 26300; rustc 1.98.1 MSVC; debug build. Head `0789e88b` as is, clean tree. The current head `7c748c8b` is the same patch rebased onto `9e3831e` (`git range-diff`); its tree is identical to my merge of `0789e88b` into `9e3831e`, and the test is unchanged. - `cargo test --workspace -- --test-threads=4`: 771 passed, 0 failed, 41 ignored (base `b7aa9f3`: 770). Merged into `9e3831e`: 777 passed, 0 failed, 41 ignored. - `cargo test -p xcl --lib tracked_release_removes_entry`, alone, 20 runs: **13 passed, 7 failed**, always `object not freed on iteration N` (`title_textures.rs:2181`; N = 2, 14, 70, 85, 115, 208, 460). - `cargo test -p xcl --lib title_textures -- --test-threads=4`, 10 runs: **5 passed, 5 failed**. Each failed run has 3 failures: this test, plus `placed_title_textures_share_vram_and_preserve_pixels` and `transitions_apply_when_their_list_is_submitted` with `PoisonError`, because the panic happens while `TEST_LOCK` is held. Likely cause, from reading the test (I did not instrument it): the `reader` thread AddRefs every tracked key under the `TEXTURES` lock and releases it later through `release_tracked`. When the reader holds the last reference in an iteration, the final `mock_release` runs on the reader thread, possibly after `t2.join()`, so `obj.freed` can still be false at the assertion. Waiting until the reader has dropped its references to the current object (or keeping the reader away from the object under test) before asserting would make the check deterministic. **Not tested** - `res_release` with a title (late release on and `XCL_LATE_RELEASE=0`); AMD; any retail title (no smoke run). **AI use:** Claude Code (Claude Opus 5.5) ran the commands and wrote this report; I checked it before posting.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-24 18:58 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.

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-24 18:58 UTC · [original](https://github.com/xcl-dev/xcl/pull/1527#issuecomment-7141417033) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~21 ignored. Thanks!
Author
Owner

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

Two contributors checked independently and found that #801 #1404 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/1527#issuecomment-7143638659) <!-- xcl-1607-hint:D38 --> Two contributors checked independently and found that #801 #1404 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

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

Empirical test report (25fe0672)

PR #1527, tested at 25fe06723d867defb80671d309a002f30a17475f.

Hardware / environment

  • Windows x64, build 26200, on an AMD64 host (family 23, model 113, stepping 0). The focused fixture ran on the CPU and did not initialize a D3D12 device.
  • rustc 1.100.0 (0ef1bc386 2026-11-09)
  • dxcompiler.dll: 1.9(5512-01b62ad4)(1.9.2609.5) - 1.9.2609.5 (01b62ad47)
  • Cargo test profile, unoptimized, with debug info and incremental compilation disabled.

Commands and results

  • cargo test --workspace --no-run exited 0. This compiled the workspace test binaries.
  • cargo test -p xcl --lib tracked_release_removes_entry_before_final_drop_and_survives_refcount_2_race ran outside Invoke-ArcTest.ps1 with XCL_ADAPTER=NONE_CPU_ONLY and RUST_TEST_NOCAPTURE=1. It exited 0 with 1 passed, 0 failed, 0 ignored, 0 skipped, and 748 filtered out.

Observed behavior

The mock COM fixture confirmed that the single-reference resource left the texture table while the final reference was still held. Its concurrent case ran 500 iterations with two releasing threads and a reader that attempted to retain the resource under the table lock. Every iteration reached mock destruction, removed the table entry, and completed without the mock recording an AddRef after destruction.

Not tested

The full GPU workspace suite and game smoke runs were omitted. This fixture exercises the release helper with mock reference counts. It provides no coverage of the real D3D12 release hook, GPU queue behavior, or a title running with XCL_LATE_RELEASE=0.

AI use

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

**@⁠JJAutoCompare** on GitHub · 2026-11-25 05:20 UTC · [original](https://github.com/xcl-dev/xcl/pull/1527#issuecomment-7153675376) ### Empirical test report (25fe0672) PR #1527, tested at `25fe06723d867defb80671d309a002f30a17475f`. **Hardware / environment** - Windows x64, build 26200, on an AMD64 host (family 23, model 113, stepping 0). The focused fixture ran on the CPU and did not initialize a D3D12 device. - `rustc 1.100.0 (0ef1bc386 2026-11-09)` - `dxcompiler.dll: 1.9(5512-01b62ad4)(1.9.2609.5) - 1.9.2609.5 (01b62ad47)` - Cargo test profile, unoptimized, with debug info and incremental compilation disabled. **Commands and results** - `cargo test --workspace --no-run` exited 0. This compiled the workspace test binaries. - `cargo test -p xcl --lib tracked_release_removes_entry_before_final_drop_and_survives_refcount_2_race` ran outside `Invoke-ArcTest.ps1` with `XCL_ADAPTER=NONE_CPU_ONLY` and `RUST_TEST_NOCAPTURE=1`. It exited 0 with **1 passed, 0 failed, 0 ignored, 0 skipped**, and 748 filtered out. **Observed behavior** The mock COM fixture confirmed that the single-reference resource left the texture table while the final reference was still held. Its concurrent case ran 500 iterations with two releasing threads and a reader that attempted to retain the resource under the table lock. Every iteration reached mock destruction, removed the table entry, and completed without the mock recording an AddRef after destruction. **Not tested** The full GPU workspace suite and game smoke runs were omitted. This fixture exercises the release helper with mock reference counts. It provides no coverage of the real D3D12 release hook, GPU queue behavior, or a title running with `XCL_LATE_RELEASE=0`. **AI use** Verified with T3 Code / Codex (gpt-6.2-sol, reasoningEffort: high). Coordinator #2 (T3 Code / Antigravity, gemini-4-neon) verified counts against `pr1527-focused.log` and published.
Author
Owner

@⁠ettehn on GitHub · 2026-11-25 07:01 UTC · original

I repeated the mock COM test after the earlier flaky result. I applied the 25fe067 diff by itself to main at 568e7db and verified that the added and removed lines match the upstream diff.

On Windows 11 25H2 (26200.9974), Ryzen 9 8945HX, Rust 1.97.1 MSVC (debug), I ran cargo test --locked --offline -j 2 -p xcl --lib hle::d3d12x::title_textures::tests::tracked_release_removes_entry_before_final_drop_and_survives_refcount_2_race -- --exact --test-threads=1 with XCL_ADAPTER=NONE_CPU_ONLY. 20 of 20 invocations passed, with 500 concurrent iterations per invocation and zero failures or ignored tests. I tested the updated fixture on this machine. This run did not exercise the actual D3D12 release hook, the GPU, or a retail title.

Verification assisted by OpenAI Codex (GPT-6).

**@⁠ettehn** on GitHub · 2026-11-25 07:01 UTC · [original](https://github.com/xcl-dev/xcl/pull/1527#issuecomment-7155402226) I repeated the mock COM test after the earlier flaky result. I applied the `25fe067` diff by itself to `main` at `568e7db` and verified that the added and removed lines match the upstream diff. On Windows 11 25H2 (`26200.9974`), Ryzen 9 8945HX, Rust 1.97.1 MSVC (debug), I ran `cargo test --locked --offline -j 2 -p xcl --lib hle::d3d12x::title_textures::tests::tracked_release_removes_entry_before_final_drop_and_survives_refcount_2_race -- --exact --test-threads=1` with `XCL_ADAPTER=NONE_CPU_ONLY`. **20 of 20 invocations passed**, with 500 concurrent iterations per invocation and zero failures or ignored tests. I tested the updated fixture on this machine. This run did not exercise the actual D3D12 release hook, the GPU, or a retail title. Verification assisted by OpenAI Codex (GPT-6).
Author
Owner

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

Re-verification on RTX 3060 Ti (Windows 11): still a merge conflict with current main on the new head — needs another rebase before it can be tested.

**@⁠DavidM1911** on GitHub · 2026-11-26 05:40 UTC · [original](https://github.com/xcl-dev/xcl/pull/1527#issuecomment-7183703104) Re-verification on RTX 3060 Ti (Windows 11): still a **merge conflict with current `main`** on the new head — needs another rebase before it can be tested.
This pull request has changes conflicting with the target branch.
  • crates/xcl/src/hle/d3d12x/title_textures.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/1527/head:github-bot/gh-1527'
git switch 'github-bot/gh-1527'

Merge

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