Skip to content

D3D12.X: a pipeline is forgotten before its address is free - #2422

Open
veyn-sudo wants to merge 1 commit into
xcl-dev:mainfrom
veyn-sudo:pr/forget-pso-first
Open

veyn-sudo wants to merge 1 commit into
xcl-dev:mainfrom
veyn-sudo:pr/forget-pso-first

Conversation

@veyn-sudo

@veyn-sudo veyn-sudo commented Nov 25, 2026 •

Copy link
Copy Markdown

pso_release drops what XCL keeps of a pipeline by its address (forget_pso) after the driver has freed it. A pipeline that another thread makes in between can get the same address, register itself, and lose its own entries: a translated compute program then counts as untranslated (is_translated_compute) and its dispatches are skipped. Background workers make pipelines while titles release them, so nothing keeps the two apart.

Found by reading the code while looking into #2403. I have not seen it happen in a title. res_release has the same question, see #1404 and #1527; the stand-ins of standin.rs already forget first. #2417 changes pso_release too, as part of a larger change; with XCL_LATE_RELEASE=0 it still forgets after the release.

What is in it

  • crates/xcl/src/hle/d3d12x/real.rs: on the last reference (AddRef says 2) pso_release forgets before it releases. Two threads that release the last two references at once can both miss being the last: then it is forgotten after the release, as before.
  • The same file, test: a pipeline is forgotten when its last reference goes, and not while there are others. It fails on main (left: Some(true), right: Some(false)).

Tested

  • RTX 2070 SUPER (driver 617.14), i7-9700K, 32 GB, Windows 11 26300, Rust 1.99.0, debug for the tests, release for the title.
  • cargo test --workspace --no-fail-fast -- --test-threads=4 on 349970c: 1364 passed, 0 failed, 46 ignored.
  • 25 SKIPPED lines: 21 no wave64, 3 f16 forms refused, 1 no heap windows.

Regression run

main:

xcl-smoke v1
commit: 2898511af1c038a2ef809719e9b6f89e5675c422
gpu: NVIDIA GeForce RTX 2070 SUPER
title: 404998dc
seconds: 60
exit: 0x0
frames shown: 1552 (PresentX 1553)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14701 MB

this PR:

xcl-smoke v1
commit: 349970c0a7ad9d336675e3ea2a93263294c09511
gpu: NVIDIA GeForce RTX 2070 SUPER
title: 404998dc
seconds: 60
exit: 0x0
frames shown: 1557 (PresentX 1557)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14630 MB

Not tested

  • AMD and Intel; the race itself in a title (how many pipelines the smoke run releases is not counted).

AI use

  • Claude Code with Claude Opus 5.5 found this, wrote the fix and the test, ran everything on my PC and wrote this description.

🤖 Generated with Claude Code

https://claude.ai/code/session_01WStEFektfHt5AEbK6Wupac

@emirduran707

Copy link
Copy Markdown
Contributor

Independent AMD RDNA4 (native wave64) test report on exact head 836ddedac40e3ef43164a17df941c950c26a3df4 (clean detached checkout, no local changes).

Tested

  • AMD Radeon RX 9060 XT 16 GB (RDNA4, native wave64, driver 32.0.31044.16), Ryzen 5 5600, 32 GB RAM, Windows 11 Pro 26300, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.9.2602.17; tests debug, smoke release.
  • cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4: 1288 passed, 3 failed, 46 ignored; 8 SKIPPED (6 in lower_dxil::tests::{f16,f32}_programs_on_the_gpu refused by per-lane form; heap_window_out_of_memory_falls_back_to_the_switch_form; pso_measurement_compiles_an_exact_synthetic_record). All native wave64 GPU tests ran and passed.
    • The PR's test passed: hle::d3d12x::real::pso_release_tests::a_pipeline_is_forgotten_before_its_address_is_free.
    • The 3 failures are pre-existing on unmodified main 68a284a: gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 (seed 722) and fuzz_validate_and_gpu_3 (seed 1599) on this GPU, plus gpu::recomp::lower_dxil::tests::a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier (from 50a9fde / Recompiler: a bridged mask write in the split form meets no barrier #2074).

Regression run (60 s retail-title smoke, XCL_NETWORK=0, release)

xcl-smoke v1
commit: 836ddedac40e3ef43164a17df941c950c26a3df4
gpu: AMD Radeon RX 9060 XT
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1572 (PresentX 1572)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 13924 MB

(Matched main 68a284a baseline on the same machine today: 1573 frames, 14420 MB peak, 0 device removals, 0 crashes.)

Not tested

  • D3D12 debug layer; Intel GPUs.

AI use

  • Antigravity with Gemini 4 Neon ran the build, test suite, and smoke run and drafted this report.

pso_release dropped what XCL keeps of a pipeline after the driver had freed it. A pipeline made by
another thread in between could get the same address and lose its own entries: a translated compute
program then counts as untranslated and its dispatches are skipped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WStEFektfHt5AEbK6Wupac
@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: 1 real failure, deterministic (also fails --test-threads=1, 1219/1):
gpu::recomp::lower_dxil::tests::a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier
  assertion failed: group barriers in the program (lower_dxil.rs:1155)

The lowered program is missing an expected group barrier (or emits one where none is expected). Needs a fix before merge.

— Devin

@bmjask bmjask left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: pso_release calls the original Release twice: f(this); then let n = f(this). Every caller Release therefore drops two COM references, risking premature pipeline destruction/use-after-free. The new test masks this by starting from two refs; after its first pso_release it sees one rather than proving the expected one-reference decrement. Remove the stray first call and assert exact one-release/one-ref behavior.

@veyn-sudo

Copy link
Copy Markdown
Author

That test was failing on main itself then (#2074's, fixed since). On this head (349970c, rebased) the suite is 1364 passed, 0 failed.

AI use: Claude Code (Claude Opus 5.5) wrote this.

@veyn-sudo

Copy link
Copy Markdown
Author

The first Release balances the AddRef (add(this)) above it, which is how the count is read. So a call takes off one reference: the test starts with two and sees one after the first pso_release; two taken off would leave zero.

AI use: Claude Code (Claude Opus 5.5) wrote this.

@oni-swr

oni-swr commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Independent AMD report for 349970c0a7ad9d336675e3ea2a93263294c09511.

Tested

  • AMD Radeon RX 7800 XT (driver 32.0.31035.1003), Ryzen 7 5700X3D, Windows 11 build 26200, rustc 1.100.0, debug profile, DXC from Windows SDK 10.0.26100.0, XCL_ADAPTER=radeon. Exact PR head (not a local merge onto main); main at the time was 6d12f58a.
  • cargo test --workspace --no-fail-fast -j 4 -- --test-threads=4: 1363 passed, 1 failed, 46 ignored. The one failure is gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 (seed 722: res[30] = 0x1, CPU 0x7fffffff); it fails identically on main 6d12f58a on this adapter (cargo test -p xcl --lib fuzz_validate_and_gpu_1), so it is not caused by this PR.
  • 7 SKIPPED lines: 6 f16_programs_on_the_gpu / f32_programs_on_the_gpu per-lane cases refused for V_MUL_F16, V_PK_MUL_F16 or V_CVT_F16_F32, and heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
  • The new real::pso_release_tests::a_pipeline_is_forgotten_before_its_address_is_free passed.

Not tested

  • scripts/smoke.ps1 / a retail title (no regression run), other adapters, NVIDIA. No game data was used.

AI use

Claude Code (Claude Sonnet 5.5) ran the tests and wrote this report. No game files, dumps or shader names are included.

gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 26, 2026
Integrates split-segment alloc_pool unpin + title_list ABA guard (xcl-dev#1453),
allocator-put-aside memory retention (xcl-dev#1422), and forget-PSO-before-free
(xcl-dev#2422). Preserves UnadoptGuard in list_x reset paths and xcl-dev#2320 kickoff
target switching.

Assisted-by: Antigravity (Gemini 4 Neon)
@DavidM1911

Copy link
Copy Markdown
Contributor

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

@itsSio

itsSio commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Independent dual-PC NVIDIA full-workspace test report on clean head 349970c0a7ad9d336675e3ea2a93263294c09511.

Tested

  • Machine 1: NVIDIA GeForce RTX 5080 (driver 32.0.16.1088), AMD Ryzen 7 9800X3D, 32 GB RAM, Windows 11 Pro build 26200, rustc 1.97.0 (stable-x86_64-pc-windows-msvc), DXC 1.9.2609.5, debug build (XCL_ADAPTER=NVIDIA)
    • cargo build --workspace: exit 0
    • cargo test --workspace --no-fail-fast -- --test-threads=4 --nocapture: 1364 passed, 0 failed, 46 ignored (real::pso_release_tests::a_pipeline_is_forgotten_before_its_address_is_free passed)
    • SKIPPED: 26 (wave64-only GPU tests, #1426 wave32 f16/cvt refusals, heap_window_out_of_memory_falls_back_to_the_switch_form, pso_measurement_compiles_an_exact_synthetic_record)
  • Machine 2: NVIDIA GeForce RTX 2080 SUPER (driver 32.0.16.1088), AMD Ryzen 5 5600X, 16 GB RAM, Windows 11 Pro build 26200, rustc 1.99.1 (stable-x86_64-pc-windows-msvc), Windows SDK 10.0.26100 DXC 1.8.2502.11, debug build (XCL_ADAPTER=NVIDIA)
    • cargo build --workspace: exit 0
    • cargo test --workspace --no-fail-fast -- --test-threads=4 --nocapture: 1363 passed, 1 failed, 46 ignored (real::pso_release_tests::a_pipeline_is_forgotten_before_its_address_is_free passed; the sole failure was unrelated intermittent xgameruntime::gamesave::tests::atomic_writes_preserve_xcltmp_blobs_and_skip_leftover_temps at gamesave.rs:958, which passed 2/3 standalone reruns and 11/11 in the gamesave module)
    • SKIPPED: 29 (same 26 as Machine 1 plus 3 requiring d3d12SDKLayers.dll)

Not tested

  • Retail title / scripts/smoke.ps1 runs
  • Release builds (--release)
  • AMD / Intel GPUs, native wave64, Linux / Wine / vkd3d-proton

AI use
Ran via Samaritan:

  • Google Antigravity CLI (Claude Opus 5.5 (High)): built the branch and ran the workspace test suite on both NVIDIA machines.
  • Google Antigravity CLI (Gemini 4 Neon (High)): coordinated the runs and wrote this test report.

@ClosetPie107

Copy link
Copy Markdown

AMD RDNA4 / Linux (Proton Experimental) test report on head 349970c0 (merged cleanly onto main b49be183):

Hardware & environment

  • AMD Radeon RX 9070 16 GB (RDNA4, RADV GFX1201, Mesa 26.3.1, native wave64), Ryzen 5 9600X, 30 GiB RAM, CachyOS Linux
  • Proton Experimental (experimental-11.0-20261112), vkd3d-proton master ec207194 (3.2.0) + dxil-spirv b540c8a2 + relaxed-vtable patch (-Db_ndebug=true), DXVK v3.1.1-209, DXC 1.9.2609.5, Rust x86_64-pc-windows-gnu

Isolated unit / GPU tests (main b49be183 + #2422 349970c0, debug, --test-threads=1, WINEDLLOVERRIDES="d3d12,d3d12core=n"):

  • xcl.exe hle::d3d12x::real:: -- --test-threads=1: 61 passed, 0 failed, 0 ignored (0 skipped).

Combined 300 s retail sanity run (release, main b49be183 + #1540 + #1675 + #1844 + #1899 + #2123 + #2369 + #2422, retail 1.0.2.1 pressing A past menus):

  • Completed full 300 s (exit=0), 0 crashes, 0 device removals, 2,014 PresentX frames, 131,072 translated draws, 660,943 dispatches (44,546 chained split-compute dispatches), 102,631 Opus packets (0 errors).

Not tested

AI use

sage-sage added a commit to sage-sage/xcl that referenced this pull request Nov 26, 2026
…ease

`heap_release`, `mem_heap_release`, `q_release` and `alloc_release`
called the driver's Release first and, when it returned 0, removed what
XCL keeps by the object's address. Once the driver has freed the object,
another thread can create a new one at the same address and record its
own entries; the cleanup then removes those. For an ID3D12Heap that is
worse than lost bookkeeping: `mem_heap_release` takes the new heap's
`HEAP_UMA` entry and frees its block of unified memory while the new
heap's buffers live in it. A descriptor heap loses its console slots, a
queue or an allocator its list_x / alloc_pool entries.

`release_taking_first` takes a reference first; when AddRef returns 2
the caller holds the last one, so the entries are removed while the
address is still this object's, and what must outlive the object (the
heap's memory block, a descriptor heap's slots and shadow) is freed
after the last Release, as before. `console_heap::unregister` is split
into `take` and `free` for that.

The command list and pipeline releases have the same order; xcl-dev#2691,
xcl-dev#1453 and xcl-dev#2422 change those (xcl-dev#2690).

Assisted-by: Claude Code (Claude Opus 5.5)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
sage-sage added a commit to sage-sage/xcl that referenced this pull request Nov 26, 2026
…ease

`heap_release`, `mem_heap_release`, `q_release` and `alloc_release`
called the driver's Release first and, when it returned 0, removed what
XCL keeps by the object's address. Once the driver has freed the object,
another thread can create a new one at the same address and record its
own entries; the cleanup then removes those. For an ID3D12Heap that is
worse than lost bookkeeping: `mem_heap_release` takes the new heap's
`HEAP_UMA` entry and frees its block of unified memory while the new
heap's buffers live in it. A descriptor heap loses its console slots, a
queue or an allocator its list_x / alloc_pool entries.

`release_taking_first` takes a reference first; when AddRef returns 2
the caller holds the last one, so the entries are removed while the
address is still this object's, and what must outlive the object (the
heap's memory block, a descriptor heap's slots and shadow) is freed
after the last Release, as before. Two last-but-one releases at once
both miss `AddRef == 2`; the one whose Release ends at 0 then takes the
entries after the object is gone, as before this change, so nothing is
left behind. `console_heap::unregister` is split into `take` and `free`.

The command list and pipeline releases have the same order; xcl-dev#2691,
xcl-dev#1453 and xcl-dev#2422 change those (xcl-dev#2690).

Assisted-by: Claude Code (Claude Opus 5.5)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
rootw0rm pushed a commit to rootw0rm/xcl that referenced this pull request Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

goal:world-load Bears on the retail title getting past world loading

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants