D3D12.X: shard the command list state map by list address #3603
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3603"
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?
Imported from ivall/xcl. Originally posted by raylitebull on 2026-12-01T19:03:12Z.
Every recorded call XCL tracks on a command list (barriers, depth bias and bounds, predication, queries, memory waits and writes, the list type
indirect_guard::checkasks for) and every submit locked one process-wideLISTSmutex inlist_x.rs. A title recording on many threads waits there for itself:sharded.rsmeasured one shared map lock at 5.7 µs against 0.6 µs for a dispatch with 8 recording threads, andbind.rsalready movedDEFERRINGontosharded::Shardedfor that. On AMD, xcl is limited by its submitting thread (amd-devb54c6d9b,9f9a9bce), which takes the same lock.The idea comes from ReVIctory (https://github.com/ReTerryDavis/ReVIctory, GPL-3.0-or-later), commit 3e5cb1d, which took its global locks off the hot paths ("shadow BUFFERS lock waits 7.48 ms/frame -> 0.00"). No code was ported.
What is in it
list_x.rs:LISTSis asharded::Sharded<ListState>. Each single-list site locks its list's part (LISTS.shard(key)) for the same lookup as before; the guard keeps theOption<HashMap>shape, so the critical sections are unchanged.every_list(queue retirement and forgetting, allocator release),any_recording_poisoned,SubmissionPlan::capture,on_execute_bundle(copies the bundle's pins, poison and shared-view use, then updates the parent;propagate_bundle_shared_view_usetakes the parent and the bundle's flag),move_list_state.split_recordingno longer reserves in the map: the segments' entries are made when they are reserved (note_reserved_closed, in their own parts), and the commit writes over them in place (Sharded::replace), so it does not grow a map.sharded.rs:shardis public; newfor_each_mutandreplace, and test-onlyheldandlock_all.LISTS.insert/remove. New:a_list_is_reachable_while_another_lists_part_is_held(times out with one lock),sharded::tests::every_value_can_change,sharded::tests::replace_does_not_grow_a_full_part(fails withreplacewritten asinsert).LISTSwhile taking it again (it would deadlock), so the only lock edges are the ones that existed (LISTS → alloc_pool inon_create_with_backing, LISTS → title_list in KickoffX); no part is held across a driver call.LISTS.lock().unwrap()→LISTS.shard(key)swap.Tested
cargo check --workspace --all-targets --target x86_64-pc-windows-gnu: clean, same warnings as amd-dev6bfb5c51(lib 50, lib test 25), none in the changed code.sharded.rsalone in a scratch crate,cargo test --lib: 3 passed; withreplacewritten as a plaininsert,replace_does_not_grow_a_full_partfails ("the full part grew").0f4c3b20merged onto amd-dev41aa60ce; RTX 5070 Ti, driver 621.14):cargo test --workspace --no-fail-fast -- --test-threads=42963 passed, 9 failed, 49 ignored, the same 9 failing on amd-dev alone on that card; 60 s smoke of a retail title 1671 → 1653 frames shown.Not tested
xcl-smokeblocks under Regression run follow after a Windows run.--features pipeline-resolution-benchdoes not build on amd-dev before this change either (pso_async.rs:11957, missingPendingfields), so the bench's edits were only checked as far as that build gets.Regression run
AI use
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T19:48:08Z.
Test report (not a merge-check: draft,
PR descriptionred; merged ontoamd-dev, the PR's base)base:
41aa60ce84head:
0f4c3b20c1merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2963 passed, 9 failed, 49 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on amd-dev); failing: gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu, gpu::recomp::tests::gpu_fract_f32_edges, hle::d3d12x::sparse::tests::private_physical_pages_reach_the_gpu_on_mapping, hle::d3d12x::title_textures::tests::placed_title_textures_share_vram_and_preserve_pixels, hle::d3d12x::title_textures::tests::remapped_pages_are_compared_with_what_they_held, hle::d3d12x::title_textures::tests::stream_recheck_keeps_the_whole_upload_baseline_over_partial_uploads, hle::d3d12x::title_textures::tests::stream_recheck_partial_upload_without_an_entry_queues_a_whole_upload, hle::d3d12x::title_textures::tests::stream_recheck_schedule_catches_late_writes_and_resets_milestones (the same tests fail on amd-dev
41aa60cealone on this card, so none is from this PR)review: read the whole diff (+275/-258) against amd-dev. It replaces the single
LISTSmutex inlist_x.rswith a 64-partsharded::Sharded<ListState>keyed by list address, makes multi-list sites take one part at a time, and addsfor_each_mut/try_reserve/ test helpers tosharded.rs. Findings: (1) No measurement. The description reports only a Linuxcargo check, and nothing shows thatLISTScontention costs frame time on amd-dev, so the gain is unverified (this run covers the build, the suite and a smoke pair on NVIDIA, below). (2) Every split now sweeps all 64 parts.split_recording(list_x.rs~4725) callsLISTS.try_reserve(extra_segments), which locks every part one after another (sharded.rstry_reserve). Every deferred-dispatch or wait split on a recording thread therefore touches every other thread's lock, the cross-thread contact the PR is meant to remove. It also leaves room for 1-2 extraListStates (~40 fields) in all 64 maps for good, since the maps never shrink. Reserving only in the parts ofnext_pcand the deferred segment once their keys are known would keep the "all allocation done before commit" guarantee. (3) Effects and traces are no longer captured together.SubmissionPlan::capture(~1582-1610) now locks each list's part once foreffectsand again fortraces, so thetracesdoc ("Exact recording tokens captured witheffects") holds only if nothing re-records the list between the two passes. This only matters with sync-state tracing on and a concurrent re-record; one lock per list capturing both would keep it exact. (4) Narrower release probe in the test.generation_release(~7746) now checks only the parent's part instead of the whole map, so a regression that drops the final generation reference under another list's part (for example the bundle's) would no longer failbundle_generations_propagate_and_final_release_runs_outside_lists; it still covers the realistic path (clear_segment_state(parent)). Fine: no formerLISTS.lock()is left and no code outside the file used the map. No site holds two parts (the bundle guard inon_execute_bundleis dropped before the parent's part is taken;any_recording_poisoned,capture,move_list_stateandfor_each_muttake one part at a time), and the single-list critical sections are unchanged, so lock edges and the D3D calls made outside them stay as before. The whole-map sweeps (stop_queue_submissions,forget_queue,on_allocator_release) are no longer atomic across parts, but no caller relies on that beyond races a title would already have. The shard key uses the samepart()/spreadasDEFERRING, whose existing test checks the spread. The new tests cover cross-part reachability,for_each_mutandtry_reserve, and the existing multi-list plan tests now use keys in different parts.performance: 60 s smoke of a retail title, amd-dev
41aa60cevs this merge (0f4c3b20): 1671 -> 1653 frames shown (98 %; last presents per 2 s: 60 60 60), peak commit 16722 -> 16661 MB, 0 device removals, 0 crashes.assessment: merges cleanly into amd-dev, builds, adds no test failure (the failing ones fail on amd-dev alone on this NVIDIA card), and a 60 s smoke run shows no change (98-99 % of amd-dev's frames, about the same peak commit). That's NVIDIA only and doesn't show the AMD gain the PR is after; the review findings stand, mainly that
try_reserveon every split sweeps all 64 partshardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5
AI-written and posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T20:04:50Z.
Test report (not a merge-check: draft,
PR descriptionred; merged ontoamd-dev, the PR's base)base:
41aa60ce84head:
f585977364merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2963 passed, 9 failed, 49 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on amd-dev); failing: gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu, gpu::recomp::tests::gpu_fract_f32_edges, hle::d3d12x::sparse::tests::private_physical_pages_reach_the_gpu_on_mapping, hle::d3d12x::title_textures::tests::placed_title_textures_share_vram_and_preserve_pixels, hle::d3d12x::title_textures::tests::remapped_pages_are_compared_with_what_they_held, hle::d3d12x::title_textures::tests::stream_recheck_keeps_the_whole_upload_baseline_over_partial_uploads, hle::d3d12x::title_textures::tests::stream_recheck_partial_upload_without_an_entry_queues_a_whole_upload, hle::d3d12x::title_textures::tests::stream_recheck_schedule_catches_late_writes_and_resets_milestones (the same tests fail on amd-dev
41aa60cealone on this card, so none is from this PR)review: follow-up on
f5859773(+9/-23 since0f4c3b20, the head of my test report above). The commit removesSharded::try_reserveand its call insplit_recording, so a split no longer locks all 64 parts or leaves reserved room in them, andSubmissionPlan::capturenow reads each list'seffectsandwrite64_traceunder one shard guard. (2) Fixed as to locking and leftover capacity, but by removing the reservation rather than reserving only in the target parts, so the commit section can now grow a map.reserve_closed_segment->note_reserved_closed(list_x.rs~4955) creates the entries fornext_pc,standandsegbefore the commit, and that insert can use up a part's last free slot. After the "Commit starts here: all allocation is complete" comment (~4765), the code writes those existing keys back withm.remove+m.insert(~4829-4845),insert(seg, state)(~4902) andLISTS.insert(stand, …)throughmove_list_state(~4794, the failed-Close path). hashbrown'sinsertcallsreserve(1)before it looks up the key, and aremovethat leaves a tombstone doesn't give backgrowth_left, so when the part is at its load limit these writes rehash or reallocate inside the commit, and an allocation failure there aborts the process instead of refusing the split. (0f4c3b20's reservation didn't fully cover this either, sincenote_reserved_closed's own inserts and other threads' inserts could use the room up.) Writing throughget_mut/mem::replaceon the entriesnote_reserved_closedalready made, withinsertonly as a fallback, would keep the guarantee; otherwise the comment should change. (3) Fixed: one guard per list covers both theSegmentEffectsclone and thetracespush, andtraceskeeps one entry per list when tracing is on. (4) Still open:generation_release(~7736) still probes only the parent's part. Fine:tracesstays empty when tracing is off, and the removed test lines only covered the removed method.performance: 60 s smoke of a retail title, amd-dev
41aa60cevs this merge (f5859773): 1671 -> 1668 frames shown (99 %; last presents per 2 s: 60 60 60), peak commit 16722 -> 17036 MB, 0 device removals, 0 crashes.assessment: on the new head, merges cleanly into amd-dev, builds, adds no test failure and the smoke run is unchanged (1668 vs 1671 frames). (2) and (3) from my first review are fixed; the new point is that the commit section can now grow a map, so an allocation failure there would abort instead of refusing the split
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5
AI-written and posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T20:43:01Z.
Test report (not a merge-check: draft,
PR descriptionred; merged ontoamd-dev, the PR's base)base:
41aa60ce84head:
7653b97dd4merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2963 passed, 9 failed, 49 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on amd-dev); failing: gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu, gpu::recomp::tests::gpu_fract_f32_edges, hle::d3d12x::sparse::tests::private_physical_pages_reach_the_gpu_on_mapping, hle::d3d12x::title_textures::tests::placed_title_textures_share_vram_and_preserve_pixels, hle::d3d12x::title_textures::tests::remapped_pages_are_compared_with_what_they_held, hle::d3d12x::title_textures::tests::stream_recheck_keeps_the_whole_upload_baseline_over_partial_uploads, hle::d3d12x::title_textures::tests::stream_recheck_partial_upload_without_an_entry_queues_a_whole_upload, hle::d3d12x::title_textures::tests::stream_recheck_schedule_catches_late_writes_and_resets_milestones (the same tests fail on amd-dev
41aa60cealone on this card, so none is from this PR)review: follow-up on
7653b97d(+26/-22 sincef5859773, the head of my test report above). The commit addsSharded::replace(sharded.rs~79), which writes over an existing value throughget_mut+mem::replaceand callsinsertonly when the key is missing, and uses it for the three writes insplit_recording's commit section:next_pc(list_x.rs~4829, replacing the oldremove+insert), the put-offseg(~4891) and the stand-in inmove_list_state(~4992). The allocation finding is fixed:reserve_closed_segmentmakes all three entries throughnote_reserved_closedbefore the commit (forsegthroughprepare_deferred_segment), and nothing removes them in between (record_empty/alloc_pool::reset_listdon't touchLISTS; outside tests onlyon_release,on_createand the benchDropremove entries), so every write lands on an existing entry and can't callreserve(1).LISTS.remove(from)on the failed-Close path doesn't allocate. If an entry were ever missing,replacefalls back to a plaininsert: the state is still written and nothing panics, but that write could allocate again. (4) Still open:generation_release(~7724) still probes onlyLISTS.held(parent). New: (5) The new capacity check doesn't test the fix. The check added toevery_value_can_change(sharded.rs~166) passes with plaininserttoo: the part holdingkeys[0]has 8 of the 500 keys, so it sits at 16 buckets with capacity 14 and 6 slots free, andinserton an existing key wouldn't grow it either. Filling that part untillen() == capacity()before callingreplacewould catch a regression; nothing inlist_x.rstests that the commit doesn't grow a part. Fine: the final map contents and theSPARSE_WRITE_LISTS/WRITE64_SIGNAL_LISTSdecrements are unchanged. The only behaviour change is that the replacedsegstate is now dropped after its part's lock is released, and that state has already had its native generations taken byclear_segment_state.replacetakes one part's lock, andmove_list_statetakes its two parts one after the other, never both.performance: 60 s smoke of a retail title, amd-dev
41aa60cevs this merge (7653b97d): 1671 -> 1677 frames shown (100 %; last presents per 2 s: 60 60 60), peak commit 16722 -> 17058 MB, 0 device removals, 0 crashes.assessment: on the new head, merges cleanly into amd-dev, builds, adds no test failure and the smoke run is unchanged (1677 vs 1671 frames). The allocation-in-commit finding is fixed; still open are the narrow release probe (4) and the new capacity check that would pass without the fix (5)
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5
AI-written and posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T21:08:42Z.
Follow-up (head
6139e667, since7653b97d; merged ontoamd-dev41aa60ce, not a merge-check: draft):replace_does_not_grow_a_full_part(sharded.rs~177) fills one part untillen() == capacity()and then checks thatreplaceon an existing key leaves the capacity unchanged, which a plaininsert(with itsreserve(1)) would fail. It passes here, and the old capacity assert inevery_value_can_changeis gone. (4), the narrow release probe ingeneration_release, is still open.amd-dev41aa60cehas alone on this card (RTX 5070 Ti, driver 621.14), so none is from this PR.hle::d3d12x::list_x::tests::wait64_satisfied_counter_keeps_submission_together_and_wait32_keeps_its_maskpanicked with "misaligned pointer dereference: address must be a multiple of 0x8 but is 0x18137b93512" inwindows-coreinterface.rs:41(a COM interface pointer read from a bad address), exit 0xc0000409. The rerun passed it, and so did this PR's three earlier runs and everyamd-devrun here, so it's intermittent and I can't tie it to the sharding. Since it's alist_xtest and this PR changes howlist_xstate is stored and found, it may be worth checking whether twolist_xtests can meet on the same list address inLISTSwhen they run in parallel.AI-written and posted by Foniass without a human check of each point. Tool and model: Claude Code with Claude Opus 5.5.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.