D3D12.X: shard the command list state map by list address #3603

Open
raylitebull wants to merge 4 commits from upstream-pr/3603 into amd-dev
raylitebull commented 2026-12-01 19:03:12 +00:00 (Migrated from github.com)

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::check asks for) and every submit locked one process-wide LISTS mutex in list_x.rs. A title recording on many threads waits there for itself: sharded.rs measured one shared map lock at 5.7 µs against 0.6 µs for a dispatch with 8 recording threads, and bind.rs already moved DEFERRING onto sharded::Sharded for that. On AMD, xcl is limited by its submitting thread (amd-dev b54c6d9b, 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: LISTS is a sharded::Sharded<ListState>. Each single-list site locks its list's part (LISTS.shard(key)) for the same lookup as before; the guard keeps the Option<HashMap> shape, so the critical sections are unchanged.
  • Sites over several lists take one list at a time, so no thread holds two parts: 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_use takes the parent and the bundle's flag), move_list_state. split_recording no 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: shard is public; new for_each_mut and replace, and test-only held and lock_all.
  • Tests: the generation-release probe checks the parent's part instead of the whole lock; the empty-plan fast-path test holds every part; multi-list setup uses 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 with replace written as insert).
  • Lock order: no path held LISTS while taking it again (it would deadlock), so the only lock edges are the ones that existed (LISTS → alloc_pool in on_create_with_backing, LISTS → title_list in KickoffX); no part is held across a driver call.
  • Size: +305/−285, of which ~205 lines are the one-line LISTS.lock().unwrap() → LISTS.shard(key) swap.

Tested

  • Linux, cargo check --workspace --all-targets --target x86_64-pc-windows-gnu: clean, same warnings as amd-dev 6bfb5c51 (lib 50, lib test 25), none in the changed code.
  • Linux, sharded.rs alone in a scratch crate, cargo test --lib: 3 passed; with replace written as a plain insert, replace_does_not_grow_a_full_part fails ("the full part grew").
  • Foniass's run (their report on this PR, at 0f4c3b20 merged onto amd-dev 41aa60ce; RTX 5070 Ti, driver 621.14): cargo test --workspace --no-fail-fast -- --test-threads=4 2963 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

  • We did not build for Windows, run the tests or run a game ourselves, and there is no AMD measurement yet. The xcl-smoke blocks under Regression run follow after a Windows run.
  • --features pipeline-resolution-bench does not build on amd-dev before this change either (pso_async.rs:11957, missing Pending fields), so the bench's edits were only checked as far as that build gets.

Regression run

  • To follow after a Windows run.

AI use

  • Capy (Claude Opus 5.5) audited the LISTS sites (iteration, lock order, re-entry, tests that depend on the single lock), wrote the change, the tests and this description, and ran the type check above.

Open in Capy

<!-- greyfinch-sync:ivall/xcl:issue:5592516680 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3603). Originally posted by [raylitebull](https://github.com/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::check` asks for) and every submit locked one process-wide `LISTS` mutex in `list_x.rs`. A title recording on many threads waits there for itself: `sharded.rs` measured one shared map lock at 5.7 µs against 0.6 µs for a dispatch with 8 recording threads, and `bind.rs` already moved `DEFERRING` onto `sharded::Sharded` for that. On AMD, xcl is limited by its submitting thread (amd-dev b54c6d9b, 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`: `LISTS` is a `sharded::Sharded<ListState>`. Each single-list site locks its list's part (`LISTS.shard(key)`) for the same lookup as before; the guard keeps the `Option<HashMap>` shape, so the critical sections are unchanged. - Sites over several lists take one list at a time, so no thread holds two parts: `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_use` takes the parent and the bundle's flag), `move_list_state`. `split_recording` no 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`: `shard` is public; new `for_each_mut` and `replace`, and test-only `held` and `lock_all`. - Tests: the generation-release probe checks the parent's part instead of the whole lock; the empty-plan fast-path test holds every part; multi-list setup uses `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 with `replace` written as `insert`). - Lock order: no path held `LISTS` while taking it again (it would deadlock), so the only lock edges are the ones that existed (LISTS → alloc_pool in `on_create_with_backing`, LISTS → title_list in KickoffX); no part is held across a driver call. - Size: +305/−285, of which ~205 lines are the one-line `LISTS.lock().unwrap()` → `LISTS.shard(key)` swap. **Tested** - Linux, `cargo check --workspace --all-targets --target x86_64-pc-windows-gnu`: clean, same warnings as amd-dev 6bfb5c51 (lib 50, lib test 25), none in the changed code. - Linux, `sharded.rs` alone in a scratch crate, `cargo test --lib`: 3 passed; with `replace` written as a plain `insert`, `replace_does_not_grow_a_full_part` fails ("the full part grew"). - Foniass's run (their report on this PR, at 0f4c3b20 merged onto amd-dev 41aa60ce; RTX 5070 Ti, driver 621.14): `cargo test --workspace --no-fail-fast -- --test-threads=4` 2963 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** - We did not build for Windows, run the tests or run a game ourselves, and there is no AMD measurement yet. The `xcl-smoke` blocks under **Regression run** follow after a Windows run. - `--features pipeline-resolution-bench` does not build on amd-dev before this change either (pso_async.rs:11957, missing `Pending` fields), so the bench's edits were only checked as far as that build gets. **Regression run** - To follow after a Windows run. **AI use** - Capy (Claude Opus 5.5) audited the LISTS sites (iteration, lock order, re-entry, tests that depend on the single lock), wrote the change, the tests and this description, and ran the type check above. <!-- capy-badge:start --> <a href="https://capy.ai/thread/jam_01M8SC32421HJHXZ6G8RCDZD8X"><picture><source media="(prefers-color-scheme: dark)" srcset="https://capy.ai/badge/accent-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://capy.ai/badge/accent-light.svg"><img alt="Open in Capy" src="https://capy.ai/badge/accent-light.svg"></picture></a> <!-- capy-badge:end -->
Foniass commented 2026-12-01 19:48:08 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T19:48:08Z.


Test report (not a merge-check: draft, PR description red; merged onto amd-dev, the PR's base)
base: 41aa60ce84
head: 0f4c3b20c1
merge: 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 41aa60ce alone on this card, so none is from this PR)
review: read the whole diff (+275/-258) against amd-dev. It replaces the single LISTS mutex in list_x.rs with a 64-part sharded::Sharded<ListState> keyed by list address, makes multi-list sites take one part at a time, and adds for_each_mut / try_reserve / test helpers to sharded.rs. Findings: (1) No measurement. The description reports only a Linux cargo check, and nothing shows that LISTS contention 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) calls LISTS.try_reserve(extra_segments), which locks every part one after another (sharded.rs try_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 extra ListStates (~40 fields) in all 64 maps for good, since the maps never shrink. Reserving only in the parts of next_pc and 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 for effects and again for traces, so the traces doc ("Exact recording tokens captured with effects") 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 fail bundle_generations_propagate_and_final_release_runs_outside_lists; it still covers the realistic path (clear_segment_state(parent)). Fine: no former LISTS.lock() is left and no code outside the file used the map. No site holds two parts (the bundle guard in on_execute_bundle is dropped before the parent's part is taken; any_recording_poisoned, capture, move_list_state and for_each_mut take 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 same part() / spread as DEFERRING, whose existing test checks the spread. The new tests cover cross-part reachability, for_each_mut and try_reserve, and the existing multi-list plan tests now use keys in different parts.
performance: 60 s smoke of a retail title, amd-dev 41aa60ce vs 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_reserve on every split sweeps all 64 parts
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.

<!-- greyfinch-sync:ivall/xcl:comment:7323460038 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3603#issuecomment-7323460038). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T19:48:08Z. --- Test report (not a merge-check: draft, `PR description` red; merged onto `amd-dev`, the PR's base) base: 41aa60ce842060a597b7e8724896f7bf6a031af5 head: 0f4c3b20c104c4cefe5a1df6c1d0c76769ae1633 merge: 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 41aa60ce alone on this card, so none is from this PR) review: read the whole diff (+275/-258) against amd-dev. It replaces the single `LISTS` mutex in `list_x.rs` with a 64-part `sharded::Sharded<ListState>` keyed by list address, makes multi-list sites take one part at a time, and adds `for_each_mut` / `try_reserve` / test helpers to `sharded.rs`. Findings: (1) **No measurement.** The description reports only a Linux `cargo check`, and nothing shows that `LISTS` contention 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) calls `LISTS.try_reserve(extra_segments)`, which locks every part one after another (`sharded.rs` `try_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 extra `ListState`s (~40 fields) in all 64 maps for good, since the maps never shrink. Reserving only in the parts of `next_pc` and 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 for `effects` and again for `traces`, so the `traces` doc ("Exact recording tokens captured with `effects`") 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 fail `bundle_generations_propagate_and_final_release_runs_outside_lists`; it still covers the realistic path (`clear_segment_state(parent)`). Fine: no former `LISTS.lock()` is left and no code outside the file used the map. No site holds two parts (the bundle guard in `on_execute_bundle` is dropped before the parent's part is taken; `any_recording_poisoned`, `capture`, `move_list_state` and `for_each_mut` take 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 same `part()` / `spread` as `DEFERRING`, whose existing test checks the spread. The new tests cover cross-part reachability, `for_each_mut` and `try_reserve`, and the existing multi-list plan tests now use keys in different parts. performance: 60 s smoke of a retail title, amd-dev 41aa60ce vs 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_reserve` on every split sweeps all 64 parts 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.
Foniass commented 2026-12-01 20:04:50 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T20:04:50Z.


Test report (not a merge-check: draft, PR description red; merged onto amd-dev, the PR's base)
base: 41aa60ce84
head: f585977364
merge: 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 41aa60ce alone on this card, so none is from this PR)
review: follow-up on f5859773 (+9/-23 since 0f4c3b20, the head of my test report above). The commit removes Sharded::try_reserve and its call in split_recording, so a split no longer locks all 64 parts or leaves reserved room in them, and SubmissionPlan::capture now reads each list's effects and write64_trace under 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 for next_pc, stand and seg before 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 with m.remove + m.insert (~4829-4845), insert(seg, state) (~4902) and LISTS.insert(stand, …) through move_list_state (~4794, the failed-Close path). hashbrown's insert calls reserve(1) before it looks up the key, and a remove that leaves a tombstone doesn't give back growth_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, since note_reserved_closed's own inserts and other threads' inserts could use the room up.) Writing through get_mut / mem::replace on the entries note_reserved_closed already made, with insert only as a fallback, would keep the guarantee; otherwise the comment should change. (3) Fixed: one guard per list covers both the SegmentEffects clone and the traces push, and traces keeps one entry per list when tracing is on. (4) Still open: generation_release (~7736) still probes only the parent's part. Fine: traces stays 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 41aa60ce vs 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.

<!-- greyfinch-sync:ivall/xcl:comment:7324001916 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3603#issuecomment-7324001916). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T20:04:50Z. --- Test report (not a merge-check: draft, `PR description` red; merged onto `amd-dev`, the PR's base) base: 41aa60ce842060a597b7e8724896f7bf6a031af5 head: f585977364eb0bb05f69b6e6406b462632b672dd merge: 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 41aa60ce alone on this card, so none is from this PR) review: follow-up on f5859773 (+9/-23 since 0f4c3b20, the head of my test report above). The commit removes `Sharded::try_reserve` and its call in `split_recording`, so a split no longer locks all 64 parts or leaves reserved room in them, and `SubmissionPlan::capture` now reads each list's `effects` and `write64_trace` under 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 for `next_pc`, `stand` and `seg` before 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 with `m.remove` + `m.insert` (~4829-4845), `insert(seg, state)` (~4902) and `LISTS.insert(stand, …)` through `move_list_state` (~4794, the failed-Close path). hashbrown's `insert` calls `reserve(1)` before it looks up the key, and a `remove` that leaves a tombstone doesn't give back `growth_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, since `note_reserved_closed`'s own inserts and other threads' inserts could use the room up.) Writing through `get_mut` / `mem::replace` on the entries `note_reserved_closed` already made, with `insert` only as a fallback, would keep the guarantee; otherwise the comment should change. (3) Fixed: one guard per list covers both the `SegmentEffects` clone and the `traces` push, and `traces` keeps one entry per list when tracing is on. (4) Still open: `generation_release` (~7736) still probes only the parent's part. Fine: `traces` stays 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 41aa60ce vs 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.
Foniass commented 2026-12-01 20:43:01 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T20:43:01Z.


Test report (not a merge-check: draft, PR description red; merged onto amd-dev, the PR's base)
base: 41aa60ce84
head: 7653b97dd4
merge: 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 41aa60ce alone on this card, so none is from this PR)
review: follow-up on 7653b97d (+26/-22 since f5859773, the head of my test report above). The commit adds Sharded::replace (sharded.rs ~79), which writes over an existing value through get_mut + mem::replace and calls insert only when the key is missing, and uses it for the three writes in split_recording's commit section: next_pc (list_x.rs ~4829, replacing the old remove + insert), the put-off seg (~4891) and the stand-in in move_list_state (~4992). The allocation finding is fixed: reserve_closed_segment makes all three entries through note_reserved_closed before the commit (for seg through prepare_deferred_segment), and nothing removes them in between (record_empty / alloc_pool::reset_list don't touch LISTS; outside tests only on_release, on_create and the bench Drop remove entries), so every write lands on an existing entry and can't call reserve(1). LISTS.remove(from) on the failed-Close path doesn't allocate. If an entry were ever missing, replace falls back to a plain insert: the state is still written and nothing panics, but that write could allocate again. (4) Still open: generation_release (~7724) still probes only LISTS.held(parent). New: (5) The new capacity check doesn't test the fix. The check added to every_value_can_change (sharded.rs ~166) passes with plain insert too: the part holding keys[0] has 8 of the 500 keys, so it sits at 16 buckets with capacity 14 and 6 slots free, and insert on an existing key wouldn't grow it either. Filling that part until len() == capacity() before calling replace would catch a regression; nothing in list_x.rs tests that the commit doesn't grow a part. Fine: the final map contents and the SPARSE_WRITE_LISTS / WRITE64_SIGNAL_LISTS decrements are unchanged. The only behaviour change is that the replaced seg state is now dropped after its part's lock is released, and that state has already had its native generations taken by clear_segment_state. replace takes one part's lock, and move_list_state takes its two parts one after the other, never both.
performance: 60 s smoke of a retail title, amd-dev 41aa60ce vs 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.

<!-- greyfinch-sync:ivall/xcl:comment:7325155205 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3603#issuecomment-7325155205). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T20:43:01Z. --- Test report (not a merge-check: draft, `PR description` red; merged onto `amd-dev`, the PR's base) base: 41aa60ce842060a597b7e8724896f7bf6a031af5 head: 7653b97dd4442ed66a3118b17a0fd25d118b244c merge: 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 41aa60ce alone on this card, so none is from this PR) review: follow-up on 7653b97d (+26/-22 since f5859773, the head of my test report above). The commit adds `Sharded::replace` (`sharded.rs` ~79), which writes over an existing value through `get_mut` + `mem::replace` and calls `insert` only when the key is missing, and uses it for the three writes in `split_recording`'s commit section: `next_pc` (`list_x.rs` ~4829, replacing the old `remove` + `insert`), the put-off `seg` (~4891) and the stand-in in `move_list_state` (~4992). The allocation finding is fixed: `reserve_closed_segment` makes all three entries through `note_reserved_closed` before the commit (for `seg` through `prepare_deferred_segment`), and nothing removes them in between (`record_empty` / `alloc_pool::reset_list` don't touch `LISTS`; outside tests only `on_release`, `on_create` and the bench `Drop` remove entries), so every write lands on an existing entry and can't call `reserve(1)`. `LISTS.remove(from)` on the failed-Close path doesn't allocate. If an entry were ever missing, `replace` falls back to a plain `insert`: the state is still written and nothing panics, but that write could allocate again. (4) Still open: `generation_release` (~7724) still probes only `LISTS.held(parent)`. New: (5) **The new capacity check doesn't test the fix.** The check added to `every_value_can_change` (`sharded.rs` ~166) passes with plain `insert` too: the part holding `keys[0]` has 8 of the 500 keys, so it sits at 16 buckets with capacity 14 and 6 slots free, and `insert` on an existing key wouldn't grow it either. Filling that part until `len() == capacity()` before calling `replace` would catch a regression; nothing in `list_x.rs` tests that the commit doesn't grow a part. Fine: the final map contents and the `SPARSE_WRITE_LISTS` / `WRITE64_SIGNAL_LISTS` decrements are unchanged. The only behaviour change is that the replaced `seg` state is now dropped after its part's lock is released, and that state has already had its native generations taken by `clear_segment_state`. `replace` takes one part's lock, and `move_list_state` takes its two parts one after the other, never both. performance: 60 s smoke of a retail title, amd-dev 41aa60ce vs 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.
Foniass commented 2026-12-01 21:08:42 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T21:08:42Z.


Follow-up (head 6139e667, since 7653b97d; merged onto amd-dev 41aa60ce, not a merge-check: draft):

  • The new test answers (5). replace_does_not_grow_a_full_part (sharded.rs ~177) fills one part until len() == capacity() and then checks that replace on an existing key leaves the capacity unchanged, which a plain insert (with its reserve(1)) would fail. It passes here, and the old capacity assert in every_value_can_change is gone. (4), the narrow release probe in generation_release, is still open.
  • Suite: 2964 passed, 9 failed, 49 ignored; the 9 failures are the ones amd-dev 41aa60ce has alone on this card (RTX 5070 Ti, driver 621.14), so none is from this PR.
  • One crash to note. The first run of this head lost the lib test binary: hle::d3d12x::list_x::tests::wait64_satisfied_counter_keeps_submission_together_and_wait32_keeps_its_mask panicked with "misaligned pointer dereference: address must be a multiple of 0x8 but is 0x18137b93512" in windows-core interface.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 every amd-dev run here, so it's intermittent and I can't tie it to the sharding. Since it's a list_x test and this PR changes how list_x state is stored and found, it may be worth checking whether two list_x tests can meet on the same list address in LISTS when 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.

<!-- greyfinch-sync:ivall/xcl:comment:7325812470 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3603#issuecomment-7325812470). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T21:08:42Z. --- Follow-up (head 6139e667, since 7653b97d; merged onto `amd-dev` 41aa60ce, not a merge-check: draft): - **The new test answers (5).** `replace_does_not_grow_a_full_part` (`sharded.rs` ~177) fills one part until `len() == capacity()` and then checks that `replace` on an existing key leaves the capacity unchanged, which a plain `insert` (with its `reserve(1)`) would fail. It passes here, and the old capacity assert in `every_value_can_change` is gone. (4), the narrow release probe in `generation_release`, is still open. - **Suite:** 2964 passed, 9 failed, 49 ignored; the 9 failures are the ones `amd-dev` 41aa60ce has alone on this card (RTX 5070 Ti, driver 621.14), so none is from this PR. - **One crash to note.** The first run of this head lost the lib test binary: `hle::d3d12x::list_x::tests::wait64_satisfied_counter_keeps_submission_together_and_wait32_keeps_its_mask` panicked with "misaligned pointer dereference: address must be a multiple of 0x8 but is 0x18137b93512" in `windows-core` `interface.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 every `amd-dev` run here, so it's intermittent and I can't tie it to the sharding. Since it's a `list_x` test and this PR changes how `list_x` state is stored and found, it may be worth checking whether two `list_x` tests can meet on the same list address in `LISTS` when 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.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3603:upstream-pr/3603'
git switch 'upstream-pr/3603'

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.

git switch 'amd-dev'
git merge --no-ff 'upstream-pr/3603'
git switch 'upstream-pr/3603'
git rebase 'amd-dev'
git switch 'amd-dev'
git merge --ff-only 'upstream-pr/3603'
git switch 'upstream-pr/3603'
git rebase 'amd-dev'
git switch 'amd-dev'
git merge --no-ff 'upstream-pr/3603'
git switch 'amd-dev'
git merge --squash 'upstream-pr/3603'
git switch 'amd-dev'
git merge --ff-only 'upstream-pr/3603'
git switch 'amd-dev'
git merge 'upstream-pr/3603'
git push origin 'amd-dev'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!3603
No description provided.