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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants