Skip to content

D3D12.X: forget released command queues from vram::Pages::waited - #1899

Open
emirduran707 wants to merge 1 commit into
xcl-dev:mainfrom
emirduran707:d3d12x-vram-forget-released-queue
Open

emirduran707 wants to merge 1 commit into
xcl-dev:mainfrom
emirduran707:d3d12x-vram-forget-released-queue

Conversation

@emirduran707

@emirduran707 emirduran707 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

vram::Pages::waited caches the last tile-mapping fence value each command queue waited on, keyed by the raw ID3D12CommandQueue COM pointer. real::q_release notified list_x::on_queue_release when a queue's refcount reached zero, but left its entry in vram::Pages::waited.

If a newly created command queue reuses a freed queue's COM pointer while pages.value has not advanced, vram::before_execute sees the stale entry and skips queue.Wait(&pages.fence, pages.value), allowing the new queue to execute against tiled resources before pending UpdateTileMappings complete (and leaking a map entry for every destroyed queue).

What is in it

  • crates/xcl/src/hle/d3d12x/vram.rs: extract the wait tracker into FenceWaits, add vram::forget_queue, and add unit test released_queue_address_rewaits_on_reuse.
  • crates/xcl/src/hle/d3d12x/real.rs: call super::vram::forget_queue(this as usize) in q_release when the queue's refcount reaches zero.

Tested

  • AMD Radeon RX 9060 XT (driver 32.0.31044.16), Ryzen 5 5600, Windows 11 Pro 26300, Rust 1.100.0; tests debug, smoke release
  • cargo build --workspace, then cargo test --workspace --no-fail-fast -- --test-threads=4 on 9c33650 (rebased onto main 2aa2d1a): 1136 passed, 2 failed, 46 ignored; 8 SKIPPED (6 in lower_dxil::tests::{f16,f32}_programs_on_the_gpu; heap_window_out_of_memory_falls_back_to_the_switch_form; pso_measurement_compiles_an_exact_synthetic_record)
    • The 2 failures (gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1, gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_3) fail identically on unmodified main 2aa2d1a on this GPU (seeds 722 and 1599).
  • cargo test -p xcl --lib released_queue_address_rewaits_on_reuse: 1 passed, 0 failed

Regression run

main:

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

this PR:

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

Not tested

  • A title that destroys and recreates a command queue at the exact same COM pointer while a tile mapping is in flight (the smoke title's run is a regression check only).
  • NVIDIA and Intel GPUs.

AI use

  • Antigravity with Gemini 4 Neon: found the bug, wrote the fix, unit test and this description, and ran the test suite and smoke runs above.
  • Claude Code with Claude Opus 5.5: rebased the change onto main 2aa2d1a (a conflict in crates/xcl/src/hle/d3d12x/vram.rs; main's new note_internal_wait call kept in the rewritten wait) and reran the suite and smoke runs above.

@upipibi

upipibi commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

An interaction to watch, from reading the diffs (not run). This PR, #1819 (cpu_writes::on_queue_release) and #1691 all change q_release in real.rs.

On main, a queue the title submitted to rarely reaches n == 0: present keeps a reference to every such queue (#1668). #1691 (head 81f6397) fixes that with a second path, n == 1 && present::forget_queue(this). That path drops the tracking reference and, when the count then reaches 0, calls list_x::on_queue_release again. With #1691 in, that second path is how a released queue normally goes.

This PR adds vram::forget_queue only in the first if n == 0 branch, and #1819 does the same for its hook. Whichever of them merges after #1691 would leave the stale vram::Pages::waited entry (or the FENCES worker) in place on that normal path. One way to keep the three independent: a single on_queue_gone(this) that calls every per-queue cleanup, used in both places n reaches 0.

AI-assisted (Claude Code).

gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 24, 2026

@Melow-code Melow-code left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The stale waited entry is a real bug — a reused COM pointer skipping a tile-mapping wait could corrupt GPU memory. Check how this interacts with #1691 and #1819 in q_release, since both touch the same cleanup path.

@frenziedcoder

Copy link
Copy Markdown

NVIDIA test report for 7b493f3: no new test failures (the 4 that fail also fail on 689f2db), its own test released_queue_address_rewaits_on_reuse passes, and a clean smoke pair on the retail title (1654 vs 1657 frames).

Tested

  • NVIDIA GeForce RTX 5080 16 GB (driver 617.14, 32-lane waves), AMD Ryzen 7 9800X3D, 64 GB, Windows 11 Pro 25H2 (26200.9974), rustc 1.100.0 stable-x86_64-pc-windows-msvc, DXC 1.8.2502.11 (SDK 10.0.26100.0). Exact head 7b493f354667e57b5cd765f7dda4795d48118b34, no local changes.
  • cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4 (debug): 972 passed, 4 failed, 45 ignored; the PR's own test released_queue_address_rewaits_on_reuse passes. SKIPPED: gpu::recomp::lower::tests::a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu (no wave64), gpu::recomp::lower::tests::coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu (no wave64), gpu::recomp::lower::tests::cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu (no wave64), gpu::recomp::lower::tests::the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu (no wave64), gpu::recomp::lower_dxil::tests::a_per_lane_2d_or_3d_group_runs_on_the_gpu (no wave64), gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu (f16 arithmetic, wave32, per-lane form: refused (unsupported V_MUL_F16 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu (f16 arithmetic, wave64: no wave64), gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu (f16 packed, wave32, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu (f16 packed, wave64: no wave64), gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu (f32 arithmetic, wave64: no wave64), gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu (f32 compares, wave64: no wave64), gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu (f32 conversions, wave32, per-lane form: refused (unsupported V_CVT_F16_F32 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu (f32 conversions, wave64: no wave64), gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu (f32 rounding, wave64: no wave64), gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu (f32 three-source, wave64: no wave64), gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu (f32 transcendentals, wave64: no wave64), gpu::recomp::lower_dxil::tests::f64_programs_on_the_gpu (f64, wave64: no wave64), gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu (integer arithmetic, wave64: no wave64), gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu (integer carries, wave64: no wave64), gpu_geometry_wave32_prefix_count_over_a_mask (no wave64), gpu_wave32_program_in_wave64_hardware (no wave64), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
  • The 4 failures are fuzz_validate_and_gpu_0, fuzz_validate_and_gpu_1, fuzz_validate_and_gpu_2, fuzz_validate_and_gpu_3 in gpu::dxil::fuzz_tests. They fail the same way on the base 689f2db here (0x8007000E from CreateComputePipelineState on seeds 70, 545, 1019 and 1507, the NVIDIA refusal @PHeitor1 reported on Direct DXIL: geometry mode, MSAA loads and directed f32 rounding #1679), so this PR adds no failure.
  • test_title_draws_with_a_root_signature_under_the_debug_layer reports ok, but this machine has no D3D12 debug layer (debug layer requested but unavailable … (0x887A002D)), so it ran without the layer and is no evidence either way.

Regression run (scripts/smoke.ps1 -Seconds 60, release, the retail title of #505 at its start screen; XCL_PSO_PRELOAD=0 for both builds, because this machine's preload list holds the program of #1307)

base (689f2db, this PR's merge base with main):

xcl-smoke v1
commit: 689f2db477c3c062cf162649781640ef8a977c18
gpu: NVIDIA GeForce RTX 5080
title: 16b5e5d4
seconds: 60
exit: 0x0
frames shown: 1657 (PresentX 1657)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14602 MB

this PR:

xcl-smoke v1
commit: 7b493f354667e57b5cd765f7dda4795d48118b34
gpu: NVIDIA GeForce RTX 5080
title: 16b5e5d4
seconds: 60
exit: 0x0
frames shown: 1654 (PresentX 1654)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14594 MB

Not tested: the world load (the smoke runs stop at the start screen, so code that only runs later is not exercised there); AMD.

AI use: Claude Code (Claude Opus 5.5) built and ran the tests and smoke runs on my machine and wrote this report; I checked it.

anoyarou pushed a commit to anoyarou/xcl that referenced this pull request Nov 24, 2026
…-dev#1899)

`vram::Pages::waited` caches the last tile-mapping fence value each command
queue waited on, keyed by the raw `ID3D12CommandQueue` COM pointer.
`real::q_release` notified `list_x::on_queue_release` when a queue's refcount
reached zero, but left its entry in `vram::Pages::waited`.

If a newly created command queue reuses a freed queue's COM pointer while
`pages.value` has not advanced, `vram::before_execute` sees the stale entry
and skips `queue.Wait(&pages.fence, pages.value)`, allowing the new queue to
execute against tiled resources before pending `UpdateTileMappings` complete
(and leaking map entries for every destroyed queue).

Extract the wait tracker into `FenceWaits`, add `vram::forget_queue`, and call
it from `real::q_release` when the queue's refcount reaches zero.

Assisted-by: Antigravity (Gemini 4 Neon)
`vram::Pages::waited` caches the last tile-mapping fence value each command
queue waited on, keyed by the raw `ID3D12CommandQueue` COM pointer.
`real::q_release` notified `list_x::on_queue_release` when a queue's refcount
reached zero, but left its entry in `vram::Pages::waited`.

If a newly created command queue reuses a freed queue's COM pointer while
`pages.value` has not advanced, `vram::before_execute` sees the stale entry
and skips `queue.Wait(&pages.fence, pages.value)`, allowing the new queue to
execute against tiled resources before pending `UpdateTileMappings` complete
(and leaking map entries for every destroyed queue).

Extract the wait tracker into `FenceWaits`, add `vram::forget_queue`, and call
it from `real::q_release` when the queue's refcount reaches zero.

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

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11): merge conflict with current main in crates/xcl/src/hle/d3d12x/vram.rs — needs a rebase before it can be tested.

@emirduran707
emirduran707 force-pushed the d3d12x-vram-forget-released-queue branch from 7b493f3 to 9c33650 Compare November 25, 2026 02:28
@JJAutoCompare

Copy link
Copy Markdown

XCL PR #1899 verification

Clean head 9c336500ee42c43197d6c7ec86cdeddaf169539d on STOR-WINLAB. Windows 11 Enterprise Evaluation x64 (build 26200), Ryzen 7 3800X, Intel Arc A770 (driver 32.0.101.9175), DXC 1.9.2609.5, rustc 1.100.0 (0ef1bc386, x86_64-pc-windows-msvc). Debug/test profiles with debug info and incremental compilation disabled.

Tested

  • cargo build --workspace and cargo test --workspace --no-run both succeeded outside the GPU mutex. Cargo built 19 test binaries.
  • cargo test -p xcl --lib hle::d3d12x::vram::tests::released_queue_address_rewaits_on_reuse -- --exact with XCL_ADAPTER=NONE_CPU_ONLY outside the mutex yielded 1 passed, 0 failed, 0 ignored, 0 skips. The unit test verifies that a duplicate fence wait is suppressed, forgetting a released queue lets the same address request that wait again, and an advancing fence requests a new wait. The diff touches only crates/xcl/src/hle/d3d12x/{real,vram}.rs.
  • cargo test --workspace --no-fail-fast -- --test-threads=4 ran once under Invoke-ArcTest.ps1 with XCL_ADAPTER=A770 and RUST_TEST_NOCAPTURE=1. Cargo exited 101. Summing all 20 test result: lines in pr1899-suite.log (19 binaries and one doc-test harness) yielded 1,110 reported passed, 28 failed and 46 ignored. The queue regression also passed in this run.

Workspace failures and skips

  • The xcl library had 27 GPU shader failures, including CreateComputePipelineState errors (0x80070057) and shader result mismatches. The e2e target had one failure in test_title_runs_and_game_folder_is_untouched. Its RSSetDepthBiasX check observed a blue pixel where it expected green.
  • The log contains 27 lines beginning with SKIPPED . They give no coverage for the skipped cases. Reasons include missing wave64 and D3D12 debug-layer support, per-lane forms refused by the recompiler, tiled-resource tier limits, unavailable heap windows, and inability to disable the driver cache.

Not tested

Matched main baseline, retail-title smoke run, other GPUs, sample-dependent paths (XCL_SAMPLE_* unset), and actual D3D12 queue address reuse.

AI use

T3 Code / Codex (gpt-6.2-sol, reasoningEffort: high) ran the build and verification. Coordinator #2 (T3 Code / Antigravity, gemini-4-neon) verified counts against pr1899-suite.log and published.

@throny throny added the goal:world-load Bears on the retail title getting past world loading label Nov 25, 2026
@thehollowedone

thehollowedone commented Nov 25, 2026 •

Copy link
Copy Markdown

Independent Windows run on 9c33650. Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti (621.35), Rust 1.99.1 MSVC, DXC 1.8.2502.11.

The clean cargo build --workspace --offline --locked -j 4 passed. cargo test --workspace --offline --locked --no-fail-fast -j 4 -- --nocapture --test-threads=4 finished with 1138 passed, 0 failed, 46 ignored. Cargo’s pass count includes 25 runtime skips (20 native wave64, three unsupported per-lane forms, one unavailable driver-cache control and one no heap windows). The stock address-reuse test passed.

A scratch test used two real D3D12 queues on the same device. Both completed native waits on the mapping fence. Dropping a nonfinal reference preserved both wait records. Final release removed only the matching record, leaving the other queue’s record intact until its own final release. Omitting only the new cleanup call left the first queue’s stale record and failed the test. The focused filter local_native_queue_final_release_forgets_only_its_own_wait passed with the D3D12 debug layer enabled and no skips.

The fixture covers native release without submission tracking. I also checked the exact #1691 and #1819 heads separately with git merge-tree. Each conflicts with this head in real.rs.

I combined the three exact heads locally on 568e7db by sending both final-release paths through the same cleanup block. The same workspace build and test commands passed on the integration with 1159 passed, 0 failed, 46 ignored, including 25 runtime skips in Cargo’s pass count.

With the D3D12 debug layer enabled, cargo test --offline --locked -j 4 -p xcl --lib local_combined_queue_cleanup_covers_both_final_release_paths -- --nocapture --test-threads=1 passed 1 of 1 without skips. Using three native queues, the fixture verified that both final-release paths remove the tile-mapping wait record and CPU write worker. Intermediate releases preserved both records, and the third queue kept its records until its own final release. When cleanup was omitted only on the path where the tracking reference is the last one, both records remained and the test failed at that assertion. The fixture registered the queue with submission tracking directly. Coverage was sequential and synthetic.

AI use: Codex (GPT-6, exact variant unspecified) prepared the scratch test, ran the checks and drafted this report.

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