Skip to content

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

Draft
raylitebull wants to merge 1 commit into
mainfrom
perf/superseded-set
Draft

raylitebull wants to merge 1 commit into
mainfrom
perf/superseded-set

Conversation

@raylitebull

@raylitebull raylitebull commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

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

@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) labels Dec 1, 2026
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Review (head b0fa4d6, 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 4d6d4a7 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.

placements::note_use runs for every barrier, copy and descriptor-table
texture of a draw while any target is superseded, and took the REGISTRY
mutex for each to learn whether that texture is one of them; almost
never is.

SUPERSEDED_IDS holds the superseded ones. Registry records each change
where it counts them (superseded_delta), and the callers that already
store SUPERSEDED under the registry's lock apply it (sync_superseded).
note_use returns early when the texture is not in the set, and
note_superseded_in_tables collects a draw's textures once and checks them
under one read lock (note_uses).

Ported from amd-dev 4d6d4a7, which measured this together with its other
lock changes on amd-dev; this part was not measured on its own or on
main.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
@github-actions github-actions Bot added the needs-pr-check Failing the PR description check (CONTRIBUTING.md) label Dec 1, 2026
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Follow-up (head ea033df; the diff from b0fa4d6 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.

@github-actions github-actions Bot removed the needs-pr-check Failing the PR description check (CONTRIBUTING.md) label Dec 1, 2026
@capy-ai

capy-ai Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

@Foniass thanks, both are in (ea033df), 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

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Test report (not a merge-check: draft, PR description red)
base: b2b1f10
head: ea033df
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 #3577 (comment), 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:d3d12 D3D12.X runtime, command lists, resources, sparse memory gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants