D3D12.X: find superseded placements under a shared lock #3577

Open
raylitebull wants to merge 1 commit from upstream-pr/3577 into main
raylitebull commented 2026-12-01 14:44:35 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by raylitebull on 2026-12-01T14:44:35Z.


While any target is superseded, placements::note_use runs for every barrier, every copy and every texture in a draw's descriptor tables, and it took the REGISTRY mutex each time to learn whether that texture was superseded. It almost never is. Now the superseded placements are mirrored in a set that a shared read lock can check, and REGISTRY is taken only for the ones that are superseded.

What is in it

  • placements.rs: SUPERSEDED_IDS. Registry records each change where it counts superseded placements (superseded_delta), and sync_superseded applies those changes where SUPERSEDED was stored before. note_use returns early for a texture not in the set, and note_uses checks a batch under one read lock.
  • bind.rs: note_superseded_in_tables collects a draw's textures, sorts and deduplicates them, and calls note_uses.
  • In debug builds, sync_superseded checks that the set holds as many entries as Registry::unmapped counts.
  • Test: the_superseded_set_follows_the_registry.

Tested

  • No Windows machine or GPU here: a Linux x86_64 cloud machine (Ubuntu 24.04), rustc 1.99.0, debug build.
  • cargo check --workspace --all-targets --target x86_64-pc-windows-gnu: no errors, no new warnings.
  • The lib unit tests of the touched modules, built for x86_64-pc-windows-gnu and run under Wine 9.0 (no GPU) with --test-threads=4, next to the same filters on main b2b1f109:
    • hle::d3d12x::placements: 14 passed, 0 failed (main: 13 / 0)
    • hle::d3d12x::bind: 113 passed, 3 failed (main: 113 / 3)
      The failures are the same tests on both, ones that need a D3D12 device or Windows' working-set queries, which Wine lacks.

Regression run
Not run yet: there was no Windows machine or title here. scripts/smoke.ps1 still has to run on a title, built from main and from this head, so PR checks fails until those two blocks are added.

Not tested

  • The Windows (MSVC) build and the whole suite (cargo test --workspace -- --test-threads=4) on Windows, with or without a GPU; CI's no-GPU job is the first Windows run.
  • Any title on main, and any performance on main: the numbers above are from amd-dev.
  • This part was not measured on its own: on amd-dev it is part of 4d6d4a77, whose numbers cover all of its lock changes together.

AI use

  • Capy with Claude Opus 5.5 ported raylitebull's amd-dev commit 4d6d4a77 to main, split it into this PR and five others, and wrote the test, the commit message and this description. The amd-dev measurements are raylitebull's own runs.

Open in Capy

<!-- greyfinch-sync:ivall/xcl:issue:5588051167 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3577). Originally posted by [raylitebull](https://github.com/raylitebull) on 2026-12-01T14:44:35Z. --- While any target is superseded, `placements::note_use` runs for every barrier, every copy and every texture in a draw's descriptor tables, and it took the `REGISTRY` mutex each time to learn whether that texture was superseded. It almost never is. Now the superseded placements are mirrored in a set that a shared read lock can check, and `REGISTRY` is taken only for the ones that are superseded. **What is in it** - `placements.rs`: `SUPERSEDED_IDS`. `Registry` records each change where it counts superseded placements (`superseded_delta`), and `sync_superseded` applies those changes where `SUPERSEDED` was stored before. `note_use` returns early for a texture not in the set, and `note_uses` checks a batch under one read lock. - `bind.rs`: `note_superseded_in_tables` collects a draw's textures, sorts and deduplicates them, and calls `note_uses`. - In debug builds, `sync_superseded` checks that the set holds as many entries as `Registry::unmapped` counts. - Test: `the_superseded_set_follows_the_registry`. **Tested** - No Windows machine or GPU here: a Linux x86_64 cloud machine (Ubuntu 24.04), rustc 1.99.0, debug build. - `cargo check --workspace --all-targets --target x86_64-pc-windows-gnu`: no errors, no new warnings. - The lib unit tests of the touched modules, built for `x86_64-pc-windows-gnu` and run under Wine 9.0 (no GPU) with `--test-threads=4`, next to the same filters on `main` `b2b1f109`: - `hle::d3d12x::placements`: 14 passed, 0 failed (main: 13 / 0) - `hle::d3d12x::bind`: 113 passed, 3 failed (main: 113 / 3) The failures are the same tests on both, ones that need a D3D12 device or Windows' working-set queries, which Wine lacks. **Regression run** Not run yet: there was no Windows machine or title here. `scripts/smoke.ps1` still has to run on a title, built from `main` and from this head, so `PR checks` fails until those two blocks are added. **Not tested** - The Windows (MSVC) build and the whole suite (`cargo test --workspace -- --test-threads=4`) on Windows, with or without a GPU; CI's no-GPU job is the first Windows run. - Any title on `main`, and any performance on `main`: the numbers above are from `amd-dev`. - This part was not measured on its own: on `amd-dev` it is part of `4d6d4a77`, whose numbers cover all of its lock changes together. **AI use** - Capy with Claude Opus 5.5 ported raylitebull's `amd-dev` commit `4d6d4a77` to `main`, split it into this PR and five others, and wrote the test, the commit message and this description. The `amd-dev` measurements are raylitebull's own runs. <!-- capy-badge:start --> <a href="https://capy.ai/thread/jam_01M8RYX4CVNT8FXPPZSVVY1EFJ"><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 14:49:50 +00:00 (Migrated from github.com)

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


Review (head b0fa4d61, diff read, not a merge-check; draft):

  • The superseded set must mirror every change, and nothing checks it. note_use now returns early when a texture isn't in the set, so a superseded texture missing from it would never be mapped back when the title uses it again, and its reads would hit unmapped tiles without an error. All four current changes to mapped / released push a superseded_delta (placements.rs ~262, ~284, ~315, ~346). A debug_assert_eq!(set.len(), r.unmapped) in sync_superseded (~509) would keep future changes honest.
  • A per-draw cost on the default path. bind.rs ~1333 dedups the textures a draw's tables name with named.contains, a linear scan, so a draw with many tables naming up to 256 textures each pays O(n²). It runs while anything is superseded, which happens by default (XCL_PLACE_RETIRE is on). A small set or sorting would bound it.
  • The gain isn't measured on main. The only numbers are from amd-dev 4d6d4a77 with six lock changes together.

Fine: lookups only read the set, and the new lock is only ever taken last, under REGISTRY, so there's no lock-order cycle. No read lock is taken twice on one thread: the guards at ~584 and ~601 drop before note_use / REGISTRY. A stale read only looks like the use happened before or after the placement, which main already allows between threads, and the REGISTRY path rechecks through use_again. It conflicts with #3443 (note_superseded_in_tables).

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7314896988 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3577#issuecomment-7314896988). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T14:49:50Z. --- Review (head b0fa4d61, diff read, not a merge-check; draft): - **The superseded set must mirror every change, and nothing checks it.** `note_use` now returns early when a texture isn't in the set, so a superseded texture missing from it would never be mapped back when the title uses it again, and its reads would hit unmapped tiles without an error. All four current changes to `mapped` / `released` push a `superseded_delta` (`placements.rs` ~262, ~284, ~315, ~346). A `debug_assert_eq!(set.len(), r.unmapped)` in `sync_superseded` (~509) would keep future changes honest. - **A per-draw cost on the default path.** `bind.rs` ~1333 dedups the textures a draw's tables name with `named.contains`, a linear scan, so a draw with many tables naming up to 256 textures each pays O(n²). It runs while anything is superseded, which happens by default (`XCL_PLACE_RETIRE` is on). A small set or sorting would bound it. - **The gain isn't measured on main.** The only numbers are from `amd-dev` 4d6d4a77 with six lock changes together. Fine: lookups only read the set, and the new lock is only ever taken last, under `REGISTRY`, so there's no lock-order cycle. No read lock is taken twice on one thread: the guards at ~584 and ~601 drop before `note_use` / `REGISTRY`. A stale read only looks like the use happened before or after the placement, which main already allows between threads, and the `REGISTRY` path rechecks through `use_again`. It conflicts with #3443 (`note_superseded_in_tables`). AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Foniass commented 2026-12-01 14:59:05 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T14:59:05Z.


Follow-up (head ea033df7; the diff from b0fa4d61 read). Both points are addressed: sync_superseded now asserts that the set's size matches r.unmapped after the drain, so a missed registry change fails in debug builds; and the per-draw dedup is a sort_unstable + dedup after collecting instead of a linear contains per texture, so it's O(n log n). The set is checked under the write guard it's built with, so the assertion can't see a half-drained set. The gain on main is still unmeasured.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7315147590 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3577#issuecomment-7315147590). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T14:59:05Z. --- Follow-up (head ea033df7; the diff from b0fa4d61 read). Both points are addressed: `sync_superseded` now asserts that the set's size matches `r.unmapped` after the drain, so a missed registry change fails in debug builds; and the per-draw dedup is a `sort_unstable` + `dedup` after collecting instead of a linear `contains` per texture, so it's O(n log n). The set is checked under the write guard it's built with, so the assertion can't see a half-drained set. The gain on main is still unmeasured. AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
capy-ai[bot] commented 2026-12-01 15:06:18 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by capy-ai[bot] on 2026-12-01T15:06:18Z.


@Foniass thanks, both are in (ea033df7), as you confirmed. A measurement on main will come with the smoke runs. On #3443: whichever lands second will need a rebase of note_superseded_in_tables. I'll do it here if this one is second.

AI use: written by Capy (Claude Opus 5.5) and posted on raylitebull's behalf, with their go-ahead.

<!-- greyfinch-sync:ivall/xcl:comment:7315351389 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3577#issuecomment-7315351389). Originally posted by [capy-ai[bot]](https://github.com/apps/capy-ai) on 2026-12-01T15:06:18Z. --- @Foniass thanks, both are in (ea033df7), as you confirmed. A measurement on `main` will come with the smoke runs. On #3443: whichever lands second will need a rebase of `note_superseded_in_tables`. I'll do it here if this one is second. AI use: written by Capy (Claude Opus 5.5) and posted on raylitebull's behalf, with their go-ahead.
Foniass commented 2026-12-01 15:20:39 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T15:20:39Z.


Test report (not a merge-check: draft, PR description red)
base: b2b1f109d2
head: ea033df715
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2903 passed, 0 failed, 51 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 main); failing: none
review: not repeated here; my review of this same head is at https://github.com/xcl-dev/xcl/pull/3577#issuecomment-7315147590, and its findings stand. This run adds what reading couldn't: whether the change merges, builds and passes the whole suite on current main.
performance: no smoke run. A lock change whose cost a 60 s run capped at 60 presents per second can't show.
assessment: merges, builds and passes the whole suite on current main, including the new superseded-set check in the debug-build tests; still open: a measurement of the gain on main
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:7315752270 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3577#issuecomment-7315752270). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T15:20:39Z. --- Test report (not a merge-check: draft, `PR description` red) base: b2b1f109d27e746a62ec95b04dd1f9924452e682 head: ea033df715db7bf2f1ee1a266223ccf501478aa8 merge: clean build: cargo build --workspace -> ok tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2903 passed, 0 failed, 51 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 main); failing: none review: not repeated here; my review of this same head is at https://github.com/xcl-dev/xcl/pull/3577#issuecomment-7315147590, and its findings stand. This run adds what reading couldn't: whether the change merges, builds and passes the whole suite on current main. performance: no smoke run. A lock change whose cost a 60 s run capped at 60 presents per second can't show. assessment: merges, builds and passes the whole suite on current main, including the new superseded-set check in the debug-build tests; still open: a measurement of the gain on main 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.
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/3577:upstream-pr/3577'
git switch 'upstream-pr/3577'

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 'main'
git merge --no-ff 'upstream-pr/3577'
git switch 'upstream-pr/3577'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3577'
git switch 'upstream-pr/3577'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3577'
git switch 'main'
git merge --squash 'upstream-pr/3577'
git switch 'main'
git merge --ff-only 'upstream-pr/3577'
git switch 'main'
git merge 'upstream-pr/3577'
git push origin 'main'
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!3577
No description provided.