D3D12.X: drop CopyScratch resources outside COPY_SCRATCH lock and skip own-work reset hooks #3111

Closed
iggyvilla wants to merge 1 commit from upstream-pr/3111 into amd-dev
iggyvilla commented 2026-11-28 08:44:11 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by iggyvilla on 2026-11-28T08:44:11Z.


Fixes #3069.

Updated for amd-dev f33df5a7 (the first version was against 7c795f5e; the old head 6f37174c is replaced by a rebased commit).

CopyScratchCache still dropped ID3D12Resource wrappers (in collect_released and acquire) while holding the global COPY_SCRATCH mutex. ID3D12Resource::Release enters real::res_release -> vram::PAGES, so this inverts the lock order against threads that hold PAGES and wait for COPY_SCRATCH.

  • list_x.rs: collect_released, release and acquire hand evicted scratch to the caller in a Vec<CopyScratch>; every caller (on_queue_release, release_copy_scratch and its reaper thread, copy_scratch, acquire_scratch_for_copy, copy_scratch_submitted, the two tests) drops it after releasing COPY_SCRATCH.
  • real.rs: cl_reset skips list_x::on_pc_reset, dred::reset and dred::mark_pipeline when title_textures::is_own_work(), so XCL's own list resets never enter COPY_SCRATCH.

Tested

  • Hardware / OS / Rust: AMD Radeon RX 6650 XT (8 GB RDNA2, driver 32.0.21045.29003), Ryzen 7 5700X, Windows 11, rustc 1.100.0, debug test build on origin/amd-dev f33df5a7 + this commit.
  • cargo test --lib copy_scratch: 2 passed, 0 failed.
  • cargo test --lib hle::d3d12x:: -- --test-threads=1: the same 8 tests fail with and without this commit (in sparse, title_textures and real::release_tests); no new failures.
  • Retail soak: on the earlier base (a local branch on 7c795f5e) 4 runs of 254-600 s on this card without a hang. On f33df5a7 only the 60 s smoke below was run.

Regression run
Both 60 s runs with scripts/smoke.ps1 -Seconds 60, XCL_PREPARE=0, on the same retail title and RX 6650 XT, after xcl pso-precompile --used had warmed the compute pipeline cache (with a build that has all three ports of this series). First main d8bd9a38, then this PR's head.

xcl-smoke v1
commit: d8bd9a38204667f3ca7dd9eeffcc2f1c937b07b0
gpu: AMD Radeon RX 6650 XT
title: 1778c2d9
seconds: 60
exit: 0x0
frames shown: 1618 (PresentX 1618)
presents per 2 s (last 3): 60 61 60
device removals: 0
crashes: 0
peak commit: 15479 MB
xcl-smoke v1
commit: e2f500d1991a2c3f78feae35df576b1abdc4d374
gpu: AMD Radeon RX 6650 XT
title: 1778c2d9
seconds: 60
exit: 0x0
frames shown: 1410 (PresentX 1410)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 24093 MB

Peak commit is 1.56x main's, past the 1.25x rule, but that is amd-dev's, not this change's: the same 60 s run on amd-dev f33df5a7 without this commit peaks at 25,028 MB (1,429 frames). So every amd-dev PR will fail that one line of the check until amd-dev itself comes down.

Not tested

  • cargo test --workspace, so the PR description check stays red), NVIDIA, RDNA3/RDNA4.

AI use

  • The first version of this change (against amd-dev 7c795f5e) was written and tested by Antigravity with Gemini 4 Neon (High). Its port to f33df5a7 (the old patch no longer applied: the code moved) was done by Claude Code (Claude Sonnet 5.5, effort high), which also ran the tests below and wrote this text. The account owner did not write the code or this text.
<!-- greyfinch-sync:ivall/xcl:issue:5538418005 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3111). Originally posted by [iggyvilla](https://github.com/iggyvilla) on 2026-11-28T08:44:11Z. --- Fixes #3069. Updated for `amd-dev` `f33df5a7` (the first version was against `7c795f5e`; the old head `6f37174c` is replaced by a rebased commit). `CopyScratchCache` still dropped `ID3D12Resource` wrappers (in `collect_released` and `acquire`) while holding the global `COPY_SCRATCH` mutex. `ID3D12Resource::Release` enters `real::res_release` -> `vram::PAGES`, so this inverts the lock order against threads that hold `PAGES` and wait for `COPY_SCRATCH`. - `list_x.rs`: `collect_released`, `release` and `acquire` hand evicted scratch to the caller in a `Vec<CopyScratch>`; every caller (`on_queue_release`, `release_copy_scratch` and its reaper thread, `copy_scratch`, `acquire_scratch_for_copy`, `copy_scratch_submitted`, the two tests) drops it after releasing `COPY_SCRATCH`. - `real.rs`: `cl_reset` skips `list_x::on_pc_reset`, `dred::reset` and `dred::mark_pipeline` when `title_textures::is_own_work()`, so XCL's own list resets never enter `COPY_SCRATCH`. **Tested** - Hardware / OS / Rust: AMD Radeon RX 6650 XT (8 GB RDNA2, driver `32.0.21045.29003`), Ryzen 7 5700X, Windows 11, `rustc 1.100.0`, debug test build on `origin/amd-dev` `f33df5a7` + this commit. - `cargo test --lib copy_scratch`: 2 passed, 0 failed. - `cargo test --lib hle::d3d12x:: -- --test-threads=1`: the same 8 tests fail with and without this commit (in `sparse`, `title_textures` and `real::release_tests`); no new failures. - Retail soak: on the earlier base (a local branch on `7c795f5e`) 4 runs of 254-600 s on this card without a hang. On `f33df5a7` only the 60 s smoke below was run. **Regression run** Both 60 s runs with `scripts/smoke.ps1 -Seconds 60`, `XCL_PREPARE=0`, on the same retail title and RX 6650 XT, after `xcl pso-precompile --used` had warmed the compute pipeline cache (with a build that has all three ports of this series). First `main` `d8bd9a38`, then this PR's head. ``` xcl-smoke v1 commit: d8bd9a38204667f3ca7dd9eeffcc2f1c937b07b0 gpu: AMD Radeon RX 6650 XT title: 1778c2d9 seconds: 60 exit: 0x0 frames shown: 1618 (PresentX 1618) presents per 2 s (last 3): 60 61 60 device removals: 0 crashes: 0 peak commit: 15479 MB ``` ``` xcl-smoke v1 commit: e2f500d1991a2c3f78feae35df576b1abdc4d374 gpu: AMD Radeon RX 6650 XT title: 1778c2d9 seconds: 60 exit: 0x0 frames shown: 1410 (PresentX 1410) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 24093 MB ``` Peak commit is 1.56x main's, past the 1.25x rule, but that is `amd-dev`'s, not this change's: the same 60 s run on `amd-dev` `f33df5a7` without this commit peaks at 25,028 MB (1,429 frames). So every `amd-dev` PR will fail that one line of the check until `amd-dev` itself comes down. **Not tested** - `cargo test --workspace`, so the PR description check stays red), NVIDIA, RDNA3/RDNA4. **AI use** - The first version of this change (against `amd-dev` `7c795f5e`) was written and tested by Antigravity with Gemini 4 Neon (High). Its port to `f33df5a7` (the old patch no longer applied: the code moved) was done by Claude Code (Claude Sonnet 5.5, effort high), which also ran the tests below and wrote this text. The account owner did not write the code or this text.
JJAutoCompare commented 2026-11-28 10:37:58 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by JJAutoCompare on 2026-11-28T10:37:58Z.


Tested

Exact 6f37174c9d1c14ef914c716855e2346e4438a434 on the amd-dev PR, Windows 11 x64 build 26200.9974, Ryzen 7 3800X, and Rust 1.100.1 MSVC. I reran the pinned standalone CPU harness with copy_scratch.exe --test-threads=1 --nocapture. Its CopyScratchCache::collect_released and release methods matched the Git source byte-for-byte. The harness supplied stand-in owners, synthetic completion inputs, and a fixture mutex.

The busy entry stayed counted until completion. The sweep also visited the idle entry swapped into a vacated slot. Retained bytes went 238 → 149 → 82 → 59 → 0. Owners dropped exactly once in order 1, 3, 4, 6, 2, 5, and try_lock succeeded in each destructor.

1 passed, 0 failed, 0 ignored, 0 runtime skips. Native exit was 0, with no tests filtered out.

Not tested

Native COM or D3D12 behavior, GPU, acquire paths, production call sites, runtime reset hooks, the reported stall, retail soak, CI, and the workspace suite.

AI use

T3 Code through the Codex harness (gpt-6.2-sol) verified the source and executable, reran the standalone test, and wrote this report.

<!-- greyfinch-sync:ivall/xcl:comment:7238021724 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3111#issuecomment-7238021724). Originally posted by [JJAutoCompare](https://github.com/JJAutoCompare) on 2026-11-28T10:37:58Z. --- **Tested** Exact `6f37174c9d1c14ef914c716855e2346e4438a434` on the `amd-dev` PR, Windows 11 x64 build 26200.9974, Ryzen 7 3800X, and Rust 1.100.1 MSVC. I reran the pinned standalone CPU harness with `copy_scratch.exe --test-threads=1 --nocapture`. Its `CopyScratchCache::collect_released` and `release` methods matched the Git source byte-for-byte. The harness supplied stand-in owners, synthetic completion inputs, and a fixture mutex. The busy entry stayed counted until completion. The sweep also visited the idle entry swapped into a vacated slot. Retained bytes went **238 → 149 → 82 → 59 → 0**. Owners dropped exactly once in order `1, 3, 4, 6, 2, 5`, and `try_lock` succeeded in each destructor. **1 passed, 0 failed, 0 ignored, 0 runtime skips.** Native exit was 0, with no tests filtered out. **Not tested** Native COM or D3D12 behavior, GPU, acquire paths, production call sites, runtime reset hooks, the reported stall, retail soak, CI, and the workspace suite. **AI use** T3 Code through the Codex harness (`gpt-6.2-sol`) verified the source and executable, reran the standalone test, and wrote this report.
Foniass commented 2026-12-01 09:31:45 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T09:31:45Z.


Triage (#1607) – head e2f500d

This PR's commit is already on amd-dev as e46947d ("cherry picked from commit e2f500d1"), with the same changes to list_x.rs (CopyScratchCache hands evicted scratch back to drop outside COPY_SCRATCH) and real.rs (cl_reset skips own-work lists). Nothing in this PR is missing from the base branch.
Recommendation: close (superseded by amd-dev commit e46947d).

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:7306832124 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3111#issuecomment-7306832124). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T09:31:45Z. --- **Triage (#1607)** – head e2f500d This PR's commit is already on `amd-dev` as e46947d ("cherry picked from commit e2f500d1"), with the same changes to `list_x.rs` (`CopyScratchCache` hands evicted scratch back to drop outside `COPY_SCRATCH`) and `real.rs` (`cl_reset` skips own-work lists). Nothing in this PR is missing from the base branch. Recommendation: close (superseded by amd-dev commit e46947d). AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
throny commented 2026-12-01 16:01:24 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by throny on 2026-12-01T16:01:24Z.


Closing as superseded: this change is already on amd-dev (e46947d0). From Foniass's rechecked close list on #1607, checked again by script just now. If something here is still missing, say so and reopen it, or ask and I will.

AI use: Claude Code (Claude Opus 5.5).

<!-- greyfinch-sync:ivall/xcl:comment:7316906788 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3111#issuecomment-7316906788). Originally posted by [throny](https://github.com/throny) on 2026-12-01T16:01:24Z. --- Closing as superseded: this change is already on `amd-dev` (e46947d0). From Foniass's rechecked close list on #1607, checked again by script just now. If something here is still missing, say so and reopen it, or ask and I will. AI use: Claude Code (Claude Opus 5.5).

Pull request closed

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!3111
No description provided.