D3D12.X: defer pred_buf drops until GPU fence completion #2145
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!2145
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2145"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@Simon-CR on GitHub · 2026-11-25 06:14 UTC · original
Simon-CR:pr/defer-pred-buf-release→main· +307 −26 · 2 files · 1 commits · openWhen a console command list calls
SetPredicationBufferX, XCL creates a dedicated PC buffer (pred_buf) on the fly to hold the predicate value during recording. Previously, when that command list was released (on_release) or another command list was created at the same memory address (on_create), the old tracking entry and itspred_bufCOM reference were dropped synchronously on the CPU — even if earlier GPU submissions referencing that buffer were still in flight.This change defers dropping those PC-owned
pred_bufresources behind GPU completion fences usinglate_release, matching the lifetime guarantee already enforced for title-owned resources: once retired outside the command-list tracking lock,pred_bufstays alive until every known GPU queue has passed a signalled batch fence, and then drops outside theHELDlock (dropping immediately when no queues are active or whenXCL_LATE_RELEASE=0).What is in it
crates/xcl/src/hle/d3d12x/late_release.rs: extendHeld/Batchwithopen_pc/dead_pc(Vec<ID3D12Resource>), addHeld::drain_all(sealing immediately without waiting onSEAL_EVERYwhenqueues.is_empty()), extractensure_thread, addpub(super) unsafe fn hold_pc_resources, releasegone_pcoutsideHELDindrain_known, and add GPU/unit testsheld_pc_resources_wait_until_the_queue_is_past_their_batchandwithout_queues_held_pc_resources_go_at_oncecrates/xcl/src/hle/d3d12x/list_x.rs: addretire_pred_bufand passold.pred_buf.take()fromon_createandon_releaseoutside theLISTSlock, updateset_predication_buffer_state_transitions_and_lifecyclestep (h) to drainlate_releaseuntilfake_resreaches 0 (withAcqRel/Acquireordering and safe timeout handling under parallel queue tests), and add GPU teston_release_and_on_create_retire_pred_buf_until_queue_passesTested
rustc 1.100.0 (0ef1bc386 2026-11-09)--test-threads=1):hle::d3d12x::late_release::tests4 passed / 0 failed / 0 ignored;hle::d3d12x::list_x::tests35 passed / 0 failed / 0 ignoredcargo test -p xcl --lib hle::d3d12x -- --test-threads=4: 10/10 passed (220 passed, 0 failed, 2 ignored each, 0 aborts)cargo test --workspace --no-fail-fast -- --test-threads=4: 1266 passed, 2 failed (only pre-existinggpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1seed 722 andfuzz_validate_and_gpu_3seed 1599 reproduced on unmodifiedorigin/main06c9f550, tracked in #2115 / #1679), 46 ignored across 23 test result summaries (debug build)SKIPPEDtests: gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu: f16 arithmetic, wave32, per-lane form: refused (unsupported V_MUL_F16 (its #1426 semantics differ from the console's)); gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu: f16 arithmetic, wave64, per-lane form: refused (unsupported V_MUL_F16 (its #1426 semantics differ from the console's)); 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 #1426 semantics differ from the console's)); gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu: f16 packed, wave64, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its #1426 semantics differ from the console's)); gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 conversions, wave32, per-lane form: refused (unsupported V_CVT_F16_F32 (its #1426 semantics differ from the console's)); gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 conversions, wave64, per-lane form: refused (unsupported V_CVT_F16_F32 (its #1426 semantics differ from the console's)); shaders::tests::pso_measurement_compiles_an_exact_synthetic_record: cannot disable the driver cache (Windows Developer Mode is required): The application requested an operation that depends on an SDK component that is missing or mismatched. (0x887A002D); test_title_draws_with_a_root_signature_under_the_debug_layer: no d3d12SDKLayers.dll; heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows; uploads_start_from_each_subresources_state: no D3D12 debug layer (The application requested an operation that depends on an SDK component that is missing or mismatched. (0x887A002D))cargo build --release -p xcl) and 60 s retail title run (5ec87c56) completed cleanly with 0 device removals and 0 crashesRegression run
Not tested
SetPredicationBufferX, NVIDIA GPUs, Intel Arc GPUs, wave32-only GPUs, and Linux/WineAI use
late_releasefor owned PC resources, wiringlist_x::on_create/on_releaseretirement outside the lock, diagnosing and fixing the parallel-test drain/lifetime race, running the test suites and smoke runs, and drafting this description. All builds, tests, and regression runs were executed locally on the hardware above.@DavidM1911 on GitHub · 2026-11-25 06:50 UTC · original
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: 1038 passed, 1 failed in one parallel run; the failing test passes on a single-threaded rerun (1039/0). Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.Thanks!
@raylitebull on GitHub · 2026-11-25 10:46 UTC · original
Code review on
4fb33c7:ListState::pred_bufdrops throughlate_release::hold_pc_resourceson bothlist_x::on_releaseandon_createaddress reuse (dropping outsideLISTSandHELDlocks) cleanly prevents premature COMReleasewhile GPU fences are still pending.Remaining before merge:
Build and testfinishing green plus dual-vendor (AMD + NVIDIA) verification on4fb33c7.@Simon-CR on GitHub · 2026-11-25 14:39 UTC · original
Rebased onto current
main(06c9f550->1f8b821e) and fixed the CI / parallel-test failure! Thank you @raylitebull, @upipibi, and @tiagonleal for catching and pinpointing both causes:late_release::Held::drain_all): Whenqueues.is_empty()is true (such as on GPU-less CI),drain_allno longer waits on the 10 msSEAL_EVERYwindow, sohold_pc_resourcesseals and drops synchronously before returning.set_predication_buffer_state_transitions_and_lifecyclestep (h)): When parallel tests register live queues,on_releasedeferspred_bufthroughlate_releaseas intended. Step (h) now drainslate_release::drain_known(true)untilfake_res.refs == 0(usingAcqRel/AcquireonFakeComResand pinningfake_res+ boxedres_vton timeout soxcl-late-releasecan never hit freed memory).Re-tested on
1f8b821e(RX 9070 XT, Win10):cargo test -p xcl --lib hle::d3d12x -- --test-threads=4: 220 passed, 0 failed, 2 ignored each (0 aborts)--no-fail-fast -- --test-threads=4): 1266 passed, 2 pre-existing#2115fuzz failures, 46 ignored06c9f550: 1557 frames vs 1373 onmain, 0 device removals, 0 crashes.@pvfreis on GitHub · 2026-11-25 16:09 UTC · original
NVIDIA run of
1f8b821e(this PR's head) merged cleanly ontomain08294413, with the old head4fb33c7as a control. RTX 3060, one run per tree, so not a rate. The test @upipibi and @tiagonleal saw fail at the old head fails there here too and passes at the new one, and the new head has no failuremainlacks.set_predication_buffer_state_transitions_and_lifecyclemain082944131f8b821emerged onto it4fb33c7as is, on its own base6020a33b0xc0000005, no result line (1127 tests selected)held_pc_resources_wait_until_the_queue_is_past_their_batch,without_queues_held_pc_resources_go_at_once,on_release_and_on_create_retire_pred_buf_until_queue_passes. Test by test, nothing else differs frommain.presentsassertion (e2e.rs:249:frame_boundaries1,presents0):CreateSwapChainForHwndreturns0x887A0022in this session. The control fails the same assertion (e2e.rs:225there).--nocapture), so this run does not show where the access violation was; tiagonleal's runs above do. #1978 reports the same exit code onmain, so I count only the failed test, not the abort, as this run's evidence against the old head. The named test itself also changed between the heads (it now drainslate_releasebefore checking the count).Tested
cargo test --workspace --locked --offline --no-fail-fast -- --test-threads=4, as a separate sandbox user: non-interactive session, Low integrity, NVIDIA 32-lane waves only, no display, no audio device, network off (XCL_NETWORK=0).mainand the merge:set_predication_buffer_state_and_kickoff,test_title_draws_with_a_root_signature_under_the_debug_layer,uploads_start_from_each_subresources_state(the author's AMD run SKIPPED the last two).mainand the merge (21 "no wave64", 3 f16 / f32 per-lane forms the direct path refuses,heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows).Not tested
hle::d3d12xrun were not done.XCL_LATE_RELEASE=0, presentation and audio output.AI use: Claude Code. Claude Opus 5.5 staged and ran the three jobs, compared the logs and wrote this; a second Claude Opus 5.5 agent checked it against the logs and the live PR; Claude Fable 5.2 reviewed the text and spot-checked the counts against the logs.
@tiagonleal on GitHub · 2026-11-25 12:31 UTC · original · edited 2026-11-25 16:10 UTC
Verification on NVIDIA RTX 5070 Ti (Windows 11), head
1f8b821e4afdd28bd845888d4a5ac21a9dbf9201: the parallelhle::d3d12xabort I reported is goneThis replaces my earlier report on this PR. That report was for head
4fb33c7e37127a465645044e4c338aa98a022545, wherehle::d3d12xaborted with0xc0000005in 8 of 10 parallel runs. This one is for the rebased and fixed head1f8b821e4afdd28bd845888d4a5ac21a9dbf9201(pushed 14:39 UTC). Short answer: the failure no longer reproduces here.Tested
1f8b821e4afdd28bd845888d4a5ac21a9dbf9201(git rev-parse HEADof a clean worktree, no local changes; merge-base withmain06c9f5505f63f10c5ec49ef932d75b2c28177324). The PR was open and this was the latest head when I started and again before writing.cargo test -p xcl --lib hle::d3d12x -- --test-threads=4 --nocapture: 3 runs through cargo, all passed (220 passed, 0 failed, 2 ignored each).hle::d3d12x --test-threads=4): 10 runs, all passed (220 passed, 0 failed, 2 ignored each). No abort and noSTATUS_ACCESS_VIOLATION. Together that is 0 failures in 13 parallel runs, against 8 aborts in 10 at the old head.hle::d3d12x -- --test-threads=1: 220 passed, 0 failed, 2 ignored (8 s).held_pc_resources_wait_until_the_queue_is_past_their_batch,without_queues_held_pc_resources_go_at_once,on_release_and_on_create_retire_pred_buf_until_queue_passesandset_predication_buffer_state_transitions_and_lifecycle: 1 passed, 0 failed each.hle::d3d12xruns above.cargo test -p xcl --lib -- --test-threads=4, run through the test executable 3 times: the process now finishes every time (no abort, which is what @upipibi saw),1195 passed; 4 failed; 26 ignored, 24SKIPPEDlines (no wave64on this card). The same 4 tests fail in all 3 runs:gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_0to_3, withCreateComputePipelineState: Not enough memory resources are available to complete this operation. (0x8007000E). They fail the same way alone at 1 and 4 threads (gpu::dxil::fuzz_tests: 1 passed, 4 failed, 2 ignored). They are ingpu::dxil, not in code this PR touches, and I did not run them onmain, so I cannot say whethermainshows the same here.Not tested
cargo test --workspaceat this head; other test targets; release profile.gpu::dxil::fuzz_testsfailures also happen onmainon this machine.xcl-smokerun.Run and written with Claude Code (Claude Fable 5.2 and Claude Sonnet 5.5). No code was changed.
@upipibi on GitHub · 2026-11-25 12:30 UTC · original · edited 2026-11-25 16:33 UTC
NVIDIA half of the dual-vendor check, exact head
4fb33c7, tested as-is on its base6020a33b. It conflicts withmainnow, so this isn't a merged tree. RTX 3070 8 GB, driver 616.56, Windows 11, debug, full workspace build.The lib suite doesn't finish.
cargo test -p xcl --lib -- --test-threads=4:list_x::tests::set_predication_buffer_state_transitions_and_lifecyclefails.null::tests::device_queue_fence_resource_roundtrip ... ok.This PR's own CI run (Windows, no GPU) shows the same thing: that test fails, then the process exits without finishing.
main's CI passed at the base6020a33b. So the GPU isn't needed to hit it.A likely cause, from reading the code (not isolated yet): step (h) of that test calls
on_release(list_key)and then assertsfake_res.refs == 0. With this PR,on_releasehandspred_buftolate_release::hold_pc_resources. When late release is on and a known queue has work in flight, that keeps the resource (late_release.rs:133-137) instead of dropping it. In a parallel run, other tests (this PR's new one included) register real queues, so the reference count stays 1 and the assert fails. Then the test frees theFakeComResbox whileHELDstill points at it. The next drain wouldReleasefreed memory, which fits a segfault a few tests later. If so, the old test needs to wait for or drain the held list before asserting, and to keepfake_resalive until it's released. Alternatively,on_releasecould drop it at once when the queue has nothing in flight.Other runs on this head:
gpu_withXCL_DIRECT_DXIL=1, single-threadedgpu_image_get_resinfo_1d_array, which comes from the base; #2046 fixed it inmain(5ebaf3eb)cargo test -p xcl --test e2envlddmkm153 events(Edited: I've dropped the A/B I had queued here. tiagonleal's run on an RTX 5070 Ti covers it: 8 of 10 parallel runs abort at this head, 7 of 7 pass at
6020a33, and the test passes alone and single-threaded.)Update 16:33Z, new head
1f8b821e: repeat runs, which pvfreis's one-run RTX 3060 report below lists as not done. RTX 3070 (616.56), Windows 11, debug: the crash we reported at4fb33c7is gone. Both trees were built first, thenhle::d3d12x --test-threads=4ran 10 times on each, alternating the PR and its base06c9f550on an otherwise idle machine:06c9f550The one failing run is a test this PR doesn't add,
title_textures::tests::placed_title_textures_share_vram_and_preserve_pixels:The other two failures in that run (
transitions_apply_when_their_list_is_submitted,vram::tests::d32s8_targets_take_their_own_size_of_video_memory) arePoisonErrors that follow from it. I saw the same assertion once in an earlier set of 5 runs on this head, but those overlapped other work on the machine. Counting both sets: 2 of 15 runs with the PR, 0 of 15 on the base. If the failures were spread at random over the runs, the chance of both landing on the PR is about 24% (computed by script), so this doesn't show the PR causes it.My guess, not checked: the test counts active placements in shared state while other
hle::d3d12xtests run in parallel. This PR holdspred_bufreleases inlate_releaselonger, which could change when a superseded placement is retired. If you want to rule it out, run that test alone, or the module with--test-threads=1, a few times.AI-assisted (Claude Code, Claude Opus 5.5). Synthetic tests only.
@DavidM1911 on GitHub · 2026-11-26 08:15 UTC · original
Re-verification on RTX 3060 Ti (Windows 11): still a merge conflict with current
mainon the new head — needs another rebase before it can be tested.View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.