D3D12.X: mapped ranges asked again at the same generation need no lock #3476
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3476"
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 Foniass on 2026-11-29T23:34:41Z.
Port of raylitebull's amd-dev commit
707123ad.sparse::mapped_rangestooksparse::STATEevery time the watched ranges were rebuilt. In a retail title's world on amd-dev (RX 9070 XT), a submit waited 0.08–0.29 ms for that lock there. The ranges only change under that lock, and every change movesMAPPED_GEN. So the last answer is now kept with the generation it was made at, and given again without the lock while the generation stands.initmoves the generation when it puts in a new state.What is in it
crates/xcl/src/hle/d3d12x/sparse.rs:LAST_MAPPED_RANGES(amd-dev'sRANGES, renamed: main has aconst RANGES),initmoving the generation under main'sSTATEguard, theXCL_LOOK_STATS=2count of answers made with and without the lock (main's split line has no CPU-reads part, so only this count is added), and the testmapped_ranges_made_at_this_generation_need_no_lockReview of the port:
State::runs/src_runson main is followed by aMAPPED_GENbump underSTATE:shadow_window,ensure_listed,commit_range, decommit, unmirror,link_mirror,unlink_kept.STATEheld, so its generation always matches its ranges.forget_released, so buffers waiting inFORGOTTENare handled by the next lock holder. That only delays a release.Tested
cargo test -p xcl --lib hle::d3d12x::sparse: 141 passed, 0 failed, 1 ignored. The new test fails with the lock-free path taken out.cargo test --workspace --no-fail-fast -- --test-threads=4onb47d0eb8, rebased on main86e86fcb(5070 Ti): 2890 passed, 0 failed, 51 ignored. SKIPPED: 28 notices, almost allno wave64(the others: no D3D12 debug layer, heap windows off, driver cache needs Developer Mode). The narrower runs listed here are from before the rebase.Regression run
main:
this PR:
Not tested
AI use
init, the split line), reviewed every change of the ranges for the generation bump, ran the tests and the smoke runs, wrote this description.707123ad.🤖 Generated with Claude Code
Imported from ivall/xcl. Originally posted by fromthemoonx on 2026-12-01T17:42:35Z.
merge-check
base:
6bfb5c5153head:
b47d0eb817merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2905 passed, 0 failed, 51 ignored (base: 2904 passed, 0 failed, 51 ignored); SKIPPED: 25 (22 no wave64, 2 no heap windows, 1 no GPU_UPLOAD heaps), the same set as base; failing: none from this PR. The counts are the lib binary's clean run (2757 passed, 0 failed, 31 ignored) plus the other binaries (148 passed, 0 failed, 20 ignored). How the runs went:
eh::tests::thread_dumps_while_threads_run_and_exit. That is #3586, which happens on main too.title_textures::tests::placed_title_textures_share_vram_and_preserve_pixels, with the same "superseded unaligned extra_pages ... (22609920 -> 22609920)" message I saw today on #1852's merge, which has nosparse.rschange; #2591 is its open fix. Three tests of that module are poisoned after it.xaudio2::tests::xma2_source_voice_decodes_and_manages_lifetime, which #3551 fixes.review: read the whole diff (
sparse.rs, +71 -2). No correctness problem found.watched_rangesreads onlyrunsandsrc_runs. Every change to them is followed by aMAPPED_GENbump underSTATE:early_add/early_removeatsparse.rs3390, 3780, 3864/3873 (bumped whennew || unparked), 5790, 5873, 6519, 6545.init(new in this PR).STATEback toNone.STATEheld, with the generation read under it. So a lock-free answer is at worst the one from just before a writer's bump.mapped_ranges_made_at_this_generation_need_no_lock: 30 of 30 alone, 30 of 30 withhle::d3d12x::sparse::tests::at--test-threads=8.if false && *gen == ...) fails the new test with "answered with the state's lock held elsewhere: Timeout". Good.MAPPED_GENbump ininitremoved, all 1212hle::d3d12x::tests still pass. No test makes a second state and asks for its ranges, so that line, which keeps an old device's ranges from being answered, has no test.performance: not measured here. The lock-free answer clones the cached
Vec, as the locked path's result already did.verdict: safe to merge
hardware / tool and model: RTX 3060 12 GB (610.88), Ryzen 7 5700X, Windows 11 Pro 26300 / Claude Code (Claude Opus 5.5)
Imported from ivall/xcl. Originally posted by vasanex on 2026-12-02T01:09:25Z.
merge-check claim
head:
b47d0eb817Imported from ivall/xcl. Originally posted by vasanex on 2026-12-02T01:22:46Z.
merge-check
base:
1c8b551475head:
b47d0eb817merge: clean (merged tree 42485b91,
git diff --checkclean)build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2910 passed, 0 failed, 51 ignored; SKIPPED: 25 (22 no wave64, 2 no heap windows, 1 cannot disable the driver cache), the same set as on the base; failing: none. Base alone, same machine: 2909 passed, 0 failed, 51 ignored. The new test
mapped_ranges_made_at_this_generation_need_no_lockpasses.review: whole diff read (one file, sparse.rs, +71/-2), in the merge result. No finding. The claim the change rests on holds on current main:
watched_rangesis made ofrunsandsrc_runsonly, and every place that changes either (the tile mapping and unmapping paths, the shadow window, the mirror sources) movesMAPPED_GENwhile still holdingSTATE;initnow moves it too when it puts in a new state. The answer is stored with the generation read under the lock, so a stored answer is never newer than its generation. A caller that asks while another thread is inside the lock between a change and itsfetch_addgets the answer from before that change, which is what it would have got by asking a moment earlier.LAST_MAPPED_RANGESis taken alone or insideSTATE, never around it. The extra text on theXCL_LOOK_STATS=2line only appears with that switch.performance: 60 s smoke of the same title, release, default settings, same machine, one run each. Base
1c8b5514: 1608 frames shown, presents per 2 s (last 3) 60 60 61, 0 device removals, 0 crashes, peak commit 19911 MB. Merge result (local merge commit): 1624 frames shown, 60 60 60, 0 device removals, 0 crashes, peak commit 20004 MB. No difference outside the spread; the start and menu phase of this title does not have the lock contention the change is for, so the gain in a world is not shown here. Cost by default, reasoned: one short mutex and a clone of the ranges per call, where main tookSTATEand built the same vector.verdict: safe to merge
hardware / tool and model: NVIDIA GeForce RTX 3080 10 GB (driver 621.40), AMD Ryzen 9 7950X, Windows 11 Pro 26200, rustc 1.100.0, debug suite and release smoke / Claude Code with Claude Fable 5.2. Run and posted without a human check of each point.
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T14:13:13Z.
@Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any.
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.