D3D12.X: under Wine read a few resident pages of the title's in one read #3594
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3594"
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 Royalflamejlh on 2026-12-01T17:37:00Z.
Under Wine,
title_textures::read_committed_intoskips its whole-rangeReadProcessMemory(a guard page would be consumed: #2844) and reads region by region, oneVirtualQueryper region, each under Wine's one virtual-memory lock. A read of up to 16 pages that the working set holds as readable is now one working-set question (gpu::shader::pages_readable, madepub(crate)) plus oneReadProcessMemory. A guard page is never in the working set, so a range with one still goes region by region and the guard survives. Windows is unchanged.What is in it
hle/d3d12x/title_textures.rs(read_committed_into): the Wine fast path for up to 16 resident pages; a test that such a read asks no region of the system (2 against 0 without the change).gpu/shader.rs:pages_readablevisible to the crate.Tested
x86_64-pc-windows-gnu, release, head26f433146(Foniass's review points fixed; the results below that namea364ed71bwere taken there):cargo test -p xcl --release --lib -- --test-threads=2 title_textures gpu::shader: 72 passed, 0 failed, 1 ignored in 5 of 11 runs; in the other 6,title_textures::tests::placed_title_textures_share_vram_and_preserve_pixelsfailed and threestream_recheck_*tests after it on its poisoned lock.main6bfb5c515fails the same four in 10 of 11 runs of the same command here: it fails whengpu_uploads_of_a_texture_on_two_queues_keep_their_orderruns before it in the same process (passes alone, 3 of 3), not because of this change.XCL_LOOK_STATS=2from another fork): theVirtualQuerycall site inread_committed_intomade 150,000 to 195,000 calls a second; with this change, #3592 and a third change together it was not in the top list and the title ran 3.70 frames a second in its world against 1.19. The gain from this change alone was not measured.Regression run
RTX 5070 Ti 16 GB (driver 621.24), Ryzen 7 9800X3D, Windows 11 Pro 26300, release builds by
scripts/smoke.ps1, the same retail title for 60 s each.main:this PR's head:
Not tested
read_committed_into(known_readable); they change different lines and this one is still taken first with #3575 in, on our test tree.AI use
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T20:45:20Z.
Review (head
a364ed71, diff read, not a merge-check; draft, checks red):a_few_resident_pages_are_read_without_asking_their_regions(title_textures.rs~7214), Windows returns fromread_committed_intothrough the whole-rangeReadProcessMemory(~3347) before the region walk, soREGION_QUERIESis the same with or without the change. CI is Windows-only, so nothing there covers the new branch; it only fails under Wine.SMALLinpages_readable. The((limit - 1) >> 12) - (at >> 12) < 16check (~3350) is what keeps this call away from the part ofpages_readable(gpu/shader.rs~272-292) that probes each non-resident page with a one-byteReadProcessMemoryon longer ranges, which under Wine uses up a guard page (#2844). IfSMALLchanges and this literal does not, the guard is lost silently; both should use one constant.crates/xcl/srcand Regression run has noxcl-smokeblocks, which is whyPR descriptionis red.Fine: on Windows behaviour is unchanged; under Wine a guard page, a non-resident page or a page the working-set query cannot answer for still goes region by region, and a page decommitted between the check and the copy is handled by
copy_committed_region.AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-01T21:37:09Z.
@Foniass thanks; both done at
26f433146.read_committed_into_as(.., true), so it takes the Wine path on any platform. With that branch removed it fails under Wine (2 regions asked, 0 expected); it has not run on Windows here.gpu::shader::SMALL_RANGE_PAGES, used bypages_readableand by this check.AI use: Claude Code (Claude Opus 5.5) made the change, ran the tests and drafted this reply.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T21:41:39Z.
Follow-up review (head
26f43314, sincea364ed71, diff read, not a merge-check; draft, checks red):a_few_resident_pages_are_read_without_asking_their_regions(title_textures.rs~7218) now callsread_committed_into_as(.., true), so it takes the Wine branch on any platform and would bumpREGION_QUERIES(~3364) without the new branch.SMALL: fixed. Bothread_committed_into_as(~3354) andpages_readable(gpu/shader.rs~256) usegpu::shader::SMALL_RANGE_PAGES(~234), and the test sizes its reads from it.xcl-smokeblocks are owed, which is whyPR descriptionis red.New: none.
Fine: Windows behaviour is unchanged; under Wine a range over 16 pages, or with a guard, non-resident or unanswerable page, still goes region by region; the fast path copies through
copy_committed_region.AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by throny on 2026-12-02T05:26:28Z.
merge-check claim
head:
26f4331469Imported from ivall/xcl. Originally posted by throny on 2026-12-02T05:39:17Z.
merge-check
base: main
1c8b55147head:
26f4331469merge: trial merge into base is clean (MERGEABLE)
build: cargo build --workspace on the merged tree: OK
tests: cargo test --workspace --no-fail-fast -- --test-threads=4: 2910 passed, 0 failed, 51 ignored; 25 SKIPPED lines (GPU tests that skip); 0 binaries ended abnormally
review: Diff read (+44 -5, scan clean). Under Wine a read of up to 16 resident pages is one copy instead of a region walk; Windows keeps the whole-range ReadProcessMemory. The earlier review points are fixed: the test now takes the Wine branch through read_committed_into_as on any platform, and the limit is the shared SMALL_RANGE_PAGES. The Wine path was not exercised on this Windows machine; the new test ran only through its forced-Wine entry here.
performance: not measured here; the PR's own smoke pair shows frames within a few percent of main and no removal
verdict: safe to merge (the description now carries both xcl-smoke blocks and its check is green; Wine paths not exercised here)
hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300; Claude Code, Claude Sonnet 5.5 ran the build and the suite and read the diff; Claude Opus 5.5 checked this report
Imported from ivall/xcl. Originally posted by Decodere on 2026-12-02T10:47:15Z.
merge-check
base:
1c8b551475head:
26f4331469merge: clean (trial-merge commit c1ebdfc1425151e2f14091ba746fddcbb3006eaa, git diff --check clean)
build: cargo build --workspace ok; cargo build --release -p xcl ok
tests: 43 targets combined: 2910 passed, 0 failed, 51 ignored (+1 new test vs main baseline). Specifically, all 42 non-lib workspace targets under
cargo test --workspace --no-fail-fast -- --test-threads=4 --nocapturepassed 148/0 (20 ignored, including gpu_two_pass_cache_e2e), andcargo test -p xcl --lib -- --test-threads=2passed 2762/0 (31 ignored;--test-threads=4hit the unrelated pre-existing ASLR collision on synthetic pointer 0x7c000041 in main's set_pipeline_state_goes_into_a_run_only_with_a_two_pass_pipeline -> real.rs:1237). Targeted hle::d3d12x::title_textures::tests::a_few_resident_pages_are_read_without_asking_their_regions and title_bytes_leave_guard_pages_alone both passed with 0 skips. 28 SKIPPED lines (host environment only: 22 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 2 no heap windows, 1 cannot disable the driver cache (Windows Developer Mode required)).review: Read the full merged diff (+44/-5 across crates/xcl/src/gpu/shader.rs and crates/xcl/src/hle/d3d12x/title_textures.rs). Exports
SMALL_RANGE_PAGES(16) andpages_readableaspub(crate)ingpu::shader, and extractsread_committed_into_as(at, out, wine)intitle_textures.rs. On native Windows (!wine), behavior is unchanged. Under Wine (wine == true), ranges spanning fewer than 16 pages (((limit - 1) >> 12) - (at >> 12) < SMALL_RANGE_PAGES, safe afterat.checked_add(len)andlen == 0checks) querypages_readable(at, limit)viaK32QueryWorkingSetEx—which returnsNonewithout touching or probing any guard/no-access/non-resident page for small ranges—and copy in one pass viacopy_committed_regionwhenSome(true), falling back to theVirtualQueryloop otherwise. The new unit test verifies zeroVirtualQuerycalls for resident 32-byte and 16-page reads withwine = trueand fallback for 32-page reads. Note: native Windows check; the Wine branch was verified viaread_committed_into_as(..., true)in the unit test rather than under Wine at runtime. No scope creep or UB.performance: 60 s retail smoke (title: 29640639, native Windows): 1653 frames (+13.1% vs
1c8b5514baseline 1462 frames), 14795 MB peak commit (-7.8% vs 16043 MB baseline), 0 device removals, 0 crashes.verdict: safe to merge
hardware / tool and model: NVIDIA GeForce RTX 4060 8 GB (driver 621.40), Intel Core i5-11400F, 32 GB RAM, Windows 11 Build 26200, Rust 1.100.1 MSVC, DXC 1.9.2602.17 / Antigravity (Gemini 4 Neon)
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T15:33:47Z.
Code review location:
crates/xcl/src/hle/d3d12x/title_textures.rs; line 3355Medium: Not certain about this one: there's a race between the working-set check and
copy_committed_region. Under Wine, a page the title re-protects as PAGE_GUARD (or decommits) on another thread afterpages_readableanswers is still read with ReadProcessMemory. If thread A getspages_readable(at, limit) == Some(true)and thread B then callsVirtualProtect(page, PAGE_READWRITE|PAGE_GUARD), A'scopy_committed_regionreads that page under Wine and consumes the guard (#2844). The comment inwith_title_bytessays the title can change its memory from another thread at any moment. The old region walk had a similar window, but this path is now taken for most small reads.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T15:33:47Z.
Code review location:
crates/xcl/src/hle/d3d12x/title_textures.rs; line 3354Medium: The fast path and the region walk disagree on which pages are readable: the walk zero-fills PAGE_EXECUTE (0x10) pages (
m.Protect & 0xEE), whilepages_readableaccepts any Valid page that isn't NOACCESS or GUARD, PAGE_EXECUTE included. Under Wine, an execute-only committed and resident page in a read of 16 pages or fewer is copied as real bytes, but the same page in a longer read, or on Windows, comes back as zeros. So the same title memory reads differently by length and platform, which affects texture hashes and cache keys. Applying the same protection mask in both paths would keep them consistent.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T15:33:47Z.
Review: COMMENTED
Review of
26f43314: 3 finding(s) (3 medium), most severe first.crates/xcl/src/hle/d3d12x/title_textures.rs:3355: Not certain about this one: there's a race between the working-set check andcopy_committed_region. (inline)crates/xcl/src/hle/d3d12x/title_textures.rs:3354: The fast path and the region walk disagree on which pages are readable: the walk zero-fills PAGE_EXECUTE (0x10) pages (m.Protect & 0xEE), whilepages_readableaccepts any Valid page that isn't NOACCESS or GUARD, PAGE_EXECUTE included. (inline)crates/xcl/src/gpu/shader.rs:249:pages_readableis nowpub(crate), but for ranges over 16 pages it still reads one byte of each non-resident page with ReadProcessMemory, soreadable()under Wine can consume a guard page in a range of 17 or more pages. (inline)These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T15:33:48Z.
Code review location:
crates/xcl/src/gpu/shader.rs; line 249Medium:
pages_readableis nowpub(crate), but for ranges over 16 pages it still reads one byte of each non-resident page with ReadProcessMemory, soreadable()under Wine can consume a guard page in a range of 17 or more pages. For example,readable(p, 64<<12)fromshader::captureon a blob next to a thread's stack guard finds the guard not Valid and, since the range isn't small, reads it, which consumes the title's stack-growth guard. This predates the PR, but the function the PR exports for Wine use carries it, and the caller is only safe because the 16-page check is copied by hand at title_textures.rs:3354. A non-touching mode (return false instead of reading) would make it safe for any length.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T15:33:54Z.
@Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any.
Imported from ivall/xcl. Originally posted by ClosetPie107 on 2026-12-02T17:13:20Z.
Linux / AMD RDNA4 (RADV, Wine + vkd3d-proton): full test suite on
26f4331Merged onto
main5eaadb54(clean merge) and compared withmainrun twice on the same machine.Setup
v3.1-83-gcae8353edand DXVKdxgi.dllfrom GE-Proton11-16, DXC 1.9.2609.5x86_64-pc-windows-msvcwithcargo-xwin; test binaries run under WineTested:
cargo xwin test --workspace --target x86_64-pc-windows-msvc --no-fail-fast -- --test-threads=4 --skip <31 tests>main5eaadb54main: none.a_few_resident_pages_are_read_without_asking_their_regions).main:gpu::recomp::tests::gpu_qsad_and_mqsad(flaky onmainunder Wine).About the failures on
mainand the 31 skipped tests (same for every PR in this batch)main's 177 failures under Wine come from #175: once a test has set up the real device, vkd3d-proton refuses the command allocators XCL adopts (d3d12_command_list_Reset: Invalid command allocator), and later tests getE_INVALIDARG(0x80070057). Running vkd3d-proton master with its vtable check taken out,hle::d3d12x::sparse::testsgoes from 106 passed / 38 failed to 144 / 0.std::terminate()(Cannot reliably convert LLVM pointer type, we cannot differentiate between Function and Private), which kills the whole test binary. They are the split-wave64, dispatch-chain and bridged-mask GPU tests,gpu_compute_mode_dispatch_abi,gpu_compute_thread_limits_leave_the_lanes_past_them_out, the twogpu_mesh_mode_*tests, andconsole_wave64_compute_through_the_pso_hook_dispatch_and_read_back, plusserialize_root_signature_strips_console_flags_and_preserves_pc_flags, whose null descriptor vkd3d-proton dereferences. The dxil-spirv ones crash the same way with vkd3d-proton master (f8c1cae8, dxil-spirv93ab44c5).mainwas run twice: same counts, same failure set.SKIPPEDlines (same asmain): no heap windows (2), no D3D12 debug layer (2-3), driver cache control not implemented in vkd3d-proton (1).Not tested: Windows, NVIDIA, a retail title /
scripts/smoke.ps1, a review of the diff. This is a test report, not amerge-check.AI use: omp (Claude Opus 5.5) merged, built and ran the suites on this machine, compared the results with
main, and drafted this report. The user asked for it to be posted.Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T20:32:19Z.
Code review location:
crates/xcl/src/hle/d3d12x/title_textures.rs; line 3355Not changed: this window is the one the region walk already has on
main. It asksVirtualQuery(:3366) and then reads withcopy_committed_region(:3375), and a page guarded in between is read the same way. This change replaces the question (the working set instead ofVirtualQuery), not the gap between asking and reading. No lock of XCL's can close that gap, since the title can callVirtualProtecton its own memory from any thread.AI use: Claude Code (Claude Opus 5.5) checked the code and wrote this reply.
Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T20:32:22Z.
Code review location:
crates/xcl/src/hle/d3d12x/title_textures.rs; line 3354True that the two differ on an execute-only page (0x10). Not changed:
pages_readableanswers asreadable(gpu/shader.rs:225) has onmain, which also takes any committed page that is not no-access or guard; the walk's0xEEmask at :3373 is the odd one. A given texture is read at the same address and length each time, so on one machine it takes the same path and hashes the same each time. If it should be one rule, it is better as a separate change to the walk than as this path zeroing bytes the title wrote.AI use: Claude Code (Claude Opus 5.5) checked the code and wrote this reply.
Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T20:32:25Z.
Code review location:
crates/xcl/src/gpu/shader.rs; line 249Right that
pages_readablereads one byte of each page that is not resident in a range over 16 pages, and that under Wine that uses up a guard page (#2844). That is howreadablebehaves onmain, and this PR does not change it: the only new caller (title_textures.rs:3354) passes at most 16 pages, and for those the function returnsNoneinstead of reading (gpu/shader.rs:276).readableunder Wine is worth its own issue; I'll look at it outside this PR.AI use: Claude Code (Claude Opus 5.5) checked the code and wrote this reply.
Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T21:25:35Z.
@ClosetPie107 thank you for the RDNA4 run under Wine: it is the first AMD result on this one. bmjask's three points are answered inline; the head is unchanged at
26f43314.AI use: Claude Code (Claude Opus 5.5) wrote this reply.
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.