Skip to content

D3D12.X: release alloc_pool queue fence on queue release - #1967

Open
n-romanovich wants to merge 1 commit into
xcl-dev:mainfrom
n-romanovich:d3d12x/alloc-pool-release-queue-fence
Open

n-romanovich wants to merge 1 commit into
xcl-dev:mainfrom
n-romanovich:d3d12x/alloc-pool-release-queue-fence

Conversation

@n-romanovich

@n-romanovich n-romanovich commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1909.

alloc_pool::State.fences previously retained (ID3D12Fence, u64) per command queue indefinitely with no cleanup when real::q_release released the queue at refcount 0.

This PR adds alloc_pool::on_queue_release(queue), called from real::q_release when n == 0, to drop the queue's retained fence from State.fences and clear any already-completed Backing.marks entries for that queue (while leaving in-flight marks alive until completion/reset).

What is in it

  • crates/xcl/src/hle/d3d12x/alloc_pool.rs: add on_queue_release(queue) and unit test released_queue_drops_retained_fence_from_state.
  • crates/xcl/src/hle/d3d12x/real.rs: call super::alloc_pool::on_queue_release(this as usize) in q_release when n == 0.

Tested
Hardware: Windows 11 x64, NVIDIA GeForce RTX 5060 Ti.

  • cargo test -p xcl --lib alloc_pool -- --test-threads=4: 4 passed, 0 failed, 0 ignored (961 filtered out)
  • cargo test --workspace -- --test-threads=4: 989 passed, 0 failed, 45 ignored
    • SKIPPED: 22 gpu::recomp wave64 / refused per-lane f16 tests (no wave64 / refused per-lane f16), shaders::tests::pso_measurement_compiles_an_exact_synthetic_record (Windows Developer Mode is required, 0x887A002D), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows)

Regression run
Main (5478c4a7c1ae5adba127c8d27018d7fdbf3a8725):

xcl-smoke v1
commit: 5478c4a7c1ae5adba127c8d27018d7fdbf3a8725
gpu: NVIDIA GeForce RTX 5060 Ti
title: FILES
seconds: 60
exit: 0x0
frames shown: 1541 (PresentX 1541)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15701 MB

PR (4fffef38d1edb0be45b3c51859b0f711e7f85098):

xcl-smoke v1
commit: 4fffef38d1edb0be45b3c51859b0f711e7f85098
gpu: NVIDIA GeForce RTX 5060 Ti
title: FILES
seconds: 60
exit: 0x0
frames shown: 1533 (PresentX 1534)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14706 MB

Not tested

  • macOS / Linux (crate targets Windows only).
  • AMD / wave64-capable GPU.

AI use

  • Antigravity (model name not provided): implemented the fix and unit test, ran the test suite and smoke.ps1 runs.

@futurepro62

futurepro62 commented Nov 25, 2026 •

Copy link
Copy Markdown

Full-suite run, since this PR has no test report yet. Tested exact head 61db31a (on its base fc14fab).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, DXC + dxil.dll 1.9.2602.17 (Windows SDK 10.0.26100), debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4 --skip heap_window_out_of_memory_falls_back_to_the_switch_form --skip gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f64_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::const_and_null_mask_operands_agree_with_hlsl_on_the_gpu --skip gpu::dxil::fuzz_tests: 978 passed, 0 failed, 43 ignored. SKIPPED (no wave64): a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu, a_per_lane_2d_or_3d_group_runs_on_the_gpu, coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu, cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu, gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware, the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu.
  • The new tests ran and passed: released_queue_drops_retained_fence_from_state.
  • Same head on the AMD Radeon integrated GPU (iGPU) of the Ryzen 7 9800X3D (RDNA2, XCL_ADAPTER=radeon), cargo test --workspace -- --test-threads=4 --skip gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1: 988 passed, 0 failed, 45 ignored. SKIPPED: 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))), f16_programs_on_the_gpu (f16 arithmetic, wave64, 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))), 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))), f16_programs_on_the_gpu (f16 packed, wave64, 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))), 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))), f32_programs_on_the_gpu (f32 conversions, wave64, 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))), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
  • --skip leaves out tests that fail on main 80f4819 too, not because of this PR. On NVIDIA: heap_window_out_of_memory_falls_back_to_the_switch_form (Tests: heap_window_out_of_memory_falls_back_to_the_switch_form fails under XCL_REQUIRE_GPU=mesh (opt-in skip counted as missing coverage) #1651), the four gpu::recomp::lower_dxil::tests::*_programs_on_the_gpu tests and const_and_null_mask_operands_agree_with_hlsl_on_the_gpu (follow-up on #1651) fail because runner::skip_test turns their skips into failures under XCL_REQUIRE_GPU=mesh, and gpu::dxil::fuzz_tests seeds 70, 545, 1019 and 1507 fail CreateComputePipelineState with E_OUTOFMEMORY on this card (drivers 616.64 and 621.40). On AMD: fuzz_validate_and_gpu_1 fails on seed 540 (res[833] 0x7 vs CPU 0x6). The AMD run does not set XCL_REQUIRE_GPU.

Not tested

  • a release build, a game (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.

@raylitebull

Copy link
Copy Markdown
Member

Code review on 61db31a:

  • Diff audited (crates/xcl/src/hle/d3d12x/alloc_pool.rs, real.rs) and CI workflow approved (running).
  • Note the overlap with #1945 (alloc_pool.rs + q_release): #1945 additionally moves still-pending queue marks into Backing.retired on forget_queue (so a new queue reusing the same address cannot overwrite an in-flight mark) and uses create_pc_fence to bypass real::FENCES. If #1967 moves forward instead, it still needs Build and test green plus AMD verification.

@JJAutoCompare

Copy link
Copy Markdown

PR #1967 compatibility verification

Tested 61db31aacab5bcc912eb8426f180ba6881d12d2f on STOR-WINLAB. The allocator-pool regression test passed in both runs. The workspace suite exited 101 with 25 failures.

Environment

Windows 11 Enterprise Evaluation build 26200.9974, Ryzen 7 3800X, Intel Arc A770 16 GiB with driver 32.0.101.9175. Wave range 8–32, DoublePrecisionFloatShaderOps=0, and no d3d12SDKLayers.dll. Rust 1.100.0 (0ef1bc386, 2026-11-09), DXC/DXIL 1.9.2609.5, unoptimized builds with debug info and incremental compilation disabled, XCL_ADAPTER=A770.

Tested

  • cargo build --workspace and cargo test --workspace --no-run succeeded.
  • cargo test -p xcl hle::d3d12x::alloc_pool::tests -- --nocapture reported 4 passed, 0 failed, 0 ignored, and 0 skip markers. released_queue_drops_retained_fence_from_state submitted a D3D12 list, waited for completion, then called the cleanup directly and verified removal of the retained fence and completed backing mark. Source inspection confirmed that q_release calls the cleanup when the native reference count reaches zero.
  • cargo test --workspace --no-fail-fast -- --test-threads=4 ran once under the shared Arc lock. Across 20 result summaries, Cargo reported 964 passed, 25 failed, 45 ignored. The log contained 23 SKIPPED lines. Some tests emit multiple markers, and skipped paths contribute no coverage.

Of the 25 failures, 20 library tests reported CreateComputePipelineState error 0x80070057, and four library tests had result mismatches in fused FMA, implicit-LOD sampling, f16 VALU, and wave reductions. The test-title e2e case failed its RSSetDepthBiasX check (blue pixel, expected green). Skip markers covered 18 wave64 cases, three refused wave32 lowering cases, one driver-cache prerequisite, and one heap-window case.

Not tested

Baseline on main, retail-title smoke, other GPUs, the D3D12 debug layer, or optional XCL_SAMPLE_* data. The focused test did not exercise the release hook directly, an in-flight mark at release, or 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 pr1967-suite.log and published this report.

@DavidM1911

Copy link
Copy Markdown
Contributor

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

Thanks!

@throny throny added the goal:world-load Bears on the retail title getting past world loading label Nov 25, 2026
Fixes xcl-dev#1909.

alloc_pool::State.fences retained (ID3D12Fence, u64) per command queue
with no cleanup when real::q_release released the queue (refcount 0).
Add alloc_pool::on_queue_release(queue), called from real::q_release
when n == 0, to remove the queue's retained fence and any already
completed backing marks for that queue.

Tested: cargo test --workspace -- --test-threads=4.

Assisted-by: Antigravity (model name not provided)
@n-romanovich
n-romanovich force-pushed the d3d12x/alloc-pool-release-queue-fence branch from 61db31a to 4fffef3 Compare November 25, 2026 10:54
@thehollowedone

Copy link
Copy Markdown

Independent Windows check on 4fffef3. Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti (621.35), Rust 1.99.1 MSVC, debug.

The stock allocator-pool tests passed 5/0/0 with zero skips (cargo test --offline --locked -p xcl --lib hle::d3d12x::alloc_pool::tests -- --test-threads=1 --nocapture).

I also tested simulated queue-key reuse with native D3D12 fences. An unsignaled fence represented the old queue. The backing stayed busy after the release callback. After a new native submission under the same key completed, the backing reported free while the old fence was still unsignaled. The same fixture on #1945’s f581057 kept the backing busy until I signaled the old fence.

The scratch check used cargo test --offline --locked -p xcl --lib released_queue_key_reuse_keeps_the_older_pending_fence -- --test-threads=1 --nocapture (with -j 4 on #1945). It failed the busy-state assertion on #1967 and passed 1/0/0 on #1945, with zero skips in both runs. The fixture only queried eligibility. It never reset a busy allocator or blocked live GPU work. AI-assisted. Codex (GPT-6, exact variant unavailable) wrote the fixture, ran the checks, and drafted this report.

@thiagocalile

Copy link
Copy Markdown

Independent test report for head 4fffef38d1edb0be45b3c51859b0f711e7f85098 on an AMD Radeon RX 6600 (8 GB VRAM, RDNA2, native wave64).

Tested

  • Hardware: AMD Radeon RX 6600 (8146 MiB VRAM, RDNA2, native wave64 + mesh shaders, driver 32.0.21045.29003, XCL_ADAPTER=radeon), AMD Ryzen 7 5700X3D, 47.9 GB RAM, Windows 11 (10.0.26200.0), Rust 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.8.2502.11.
  • XCL_ADAPTER=radeon cargo test --no-fail-fast -p xcl --lib -- alloc_pool --test-threads=4: 5 passed, 0 failed, 0 ignored (0 skipped).

Regression run (scripts/smoke.ps1 -Seconds 60, release builds, XCL_ADAPTER=radeon)

main (06c9f55):

xcl-smoke v1
commit: 06c9f5505f63f10c5ec49ef932d75b2c28177324
gpu: AMD Radeon RX 6600
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1469 (PresentX 1469)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 13436 MB

PR #1967 (4fffef3):

xcl-smoke v1
commit: 4fffef38d1edb0be45b3c51859b0f711e7f85098
gpu: AMD Radeon RX 6600
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1530 (PresentX 1530)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 17360 MB

Not tested: full workspace test suite on this head, NVIDIA/Intel GPUs, Linux/Wine, or world load past the 60 s smoke window.

AI use: Antigravity (Gemini 4 Neon) ran the builds, tests, and smoke runs and drafted this report; the account owner reviewed and approved posting.

@oni-swr

oni-swr commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

AMD RX 7800 XT run of 4fffef38d1edb0be45b3c51859b0f711e7f85098 (PR head, as-is).

Tested

  • AMD Radeon RX 7800 XT 16 GB (RDNA3, native 64-lane waves), driver 32.0.31035.1003; Ryzen 7 5700X3D; Windows 11 Pro 26200; Rust 1.100.0 MSVC; Windows SDK DXC; debug build
  • cargo test --workspace --no-fail-fast -- --test-threads=4 on the head: lib 1161 passed, 4 failed, 26 ignored; every other test binary passed. The new alloc_pool::tests::released_queue_drops_retained_fence_from_state passed.
  • The 4 failures: gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 fails (seed 722: res[30] = 0x1, CPU 0x7fffffff); it fails the same way on main in my run, so it is not caused by this PR. The other three (pso::shader_cache_tests::rerouted_disk_entries_follow_the_direct_translator, recomp::tests::gpu_image_get_resinfo_past_last_level, d3d12x::device_x::tests::pc_resource_desc_strips_uav_on_unsupported_formats_and_msaa) pass on current main, so I think they come from the old base (5478c4a): the branch is behind main.
  • To check that, I merged the head onto origin/main 68a284a596bd558b6bd9db6eedda6d6aa178c360 locally (clean merge, cargo test -p xcl --lib): 1219 passed, 2 failed, 26 ignored. The 2 failures are the fuzz test above and lower_dxil::tests::a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier; plain main gives the same 2 (1218 passed). So no regression from this change on this card.

Not tested

  • scripts/smoke.ps1 regression run on a real title (no title I can use for a posted smoke block), so the runtime-change requirement is not met by this report.
  • NVIDIA, Intel, other AMD generations.

AI use

  • Test report written and run by Claude Code (Claude Sonnet 5.5); no code changed.

@upipibi

upipibi commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

NVIDIA test report for 4fffef3. RTX 3070 8 GB (Ampere, 32-lane waves), driver 616.56, Windows 11, debug, after cargo build --workspace, cargo test --workspace --no-fail-fast -- --test-threads=4 --skip hle::xaudio2:

  • As is (base 5478c4a): 1217 passed, 2 failed, 46 ignored. The two are gpu::recomp::pso::shader_cache_tests::rerouted_disk_entries_follow_the_direct_translator and hle::d3d12x::device_x::tests::pc_resource_desc_strips_uav_on_unsupported_formats_and_msaa. Both are stale test expectations that main fixed in 0d13b071, which this PR's base doesn't have. The PR only touches alloc_pool.rs and real.rs, so a rebase onto main fixes both.
  • Merged onto main at 569f0fc: 1320 passed, 1 failed, 46 ignored. The one failure is gpu::recomp::lower_dxil::tests::a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier.
  • main at 569f0fc alone, same machine and command: 1319 passed, 1 failed, 46 ignored, the same test. Tests: check divergent block barriers in a_bridged_mask_write #2420 (merged 18:45Z) fixed that test on main; main at 2898511 is green. So the merge adds one passing test and no failure.
  • Skipped hle::xaudio2, because its tests fail or hang on this machine on main too. SKIPPED lines: 26 in the merged run, the same as on main.

AI-assisted (Claude Code, Claude Opus 5.5). Synthetic tests only; no title run.

@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 queue-address reuse: on_queue_release removes State.fences[queue] but leaves incomplete backing marks keyed by raw queue address. If new queue reuses address before old work completes, executed() creates new fence and b.marks.insert overwrites old incomplete mark, allowing backing reuse while old queue still uses it. Key marks by queue generation/fence identity or retain multiple marks; add release-with-incomplete-submit then same-address-reuse regression. Current test waits completion before release and misses this.

@CalvyPZ CalvyPZ added the duplicate This issue or pull request already exists label Nov 25, 2026
@CalvyPZ CalvyPZ closed this Nov 25, 2026
@CalvyPZ CalvyPZ reopened this Nov 25, 2026
@CalvyPZ CalvyPZ removed the duplicate This issue or pull request already exists label Nov 25, 2026
@n-romanovich
n-romanovich force-pushed the d3d12x/alloc-pool-release-queue-fence branch 2 times, most recently from 21fae63 to 4fffef3 Compare November 25, 2026 23:21
@LocranKing

Copy link
Copy Markdown

Independent NVIDIA test report on exact head 4fffef38d1edb0be45b3c51859b0f711e7f85098 (clean detached checkout, no local changes).

Tested

  • Hardware: NVIDIA GeForce RTX 3060 Ti 8 GB (Ampere, wave32, driver 32.0.16.2140 / 621.40), AMD Ryzen 5 5500, 32 GB RAM, Windows 11 Home (build 26300), Rust 1.100.0 (stable-x86_64-pc-windows-msvc), Windows SDK 10.0.26100.0.
  • cargo build --workspace + cargo test --workspace --no-fail-fast -- --test-threads=4 (debug): 1226 passed, 2 failed, 46 ignored (xcl --lib: 1163 passed, 2 failed, 26 ignored).
    • Both failures are pre-existing on the PR's older main base (08db802) and pass on current main (b49be18):
      • gpu::recomp::pso::shader_cache_tests::rerouted_disk_entries_follow_the_direct_translator (left: 68, right: 1)
      • hle::d3d12x::device_x::tests::pc_resource_desc_strips_uav_on_unsupported_formats_and_msaa (left: 28, right: 85)
    • All alloc_pool, integration, and e2e tests passed.
  • 26 SKIPPED GPU tests on this adapter: 20 wave64-only (no wave64), 3 wave32 per-lane f16/f32 semantics, 1 no heap windows, 1 no d3d12SDKLayers.dll, 1 cannot disable driver cache without Developer Mode (0x887A002D).

Regression run
scripts/smoke.ps1 -Seconds 60, release builds of origin/main (b49be18) and this PR's head (4fffef38):

main:

xcl-smoke v1
commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7
gpu: NVIDIA GeForce RTX 3060 Ti
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1409 (PresentX 1409)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14032 MB

PR:

xcl-smoke v1
commit: 4fffef38d1edb0be45b3c51859b0f711e7f85098
gpu: NVIDIA GeForce RTX 3060 Ti
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1569 (PresentX 1569)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14489 MB

Not tested

  • AMD / Intel / Linux GPUs; XCL_SAMPLE_* tests; the 60 s smoke run covers boot/intro/menus and does not enter the 3D world.

AI use

  • Antigravity (Gemini 4 Hydrogen) ran the builds, test suite, and smoke.ps1 commands on this machine and drafted this report from the captured outputs.

@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

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.

D3D12.X: allocator pool retains internal fences after command queue release