Skip to content

D3D12.X: under Wine read a few resident pages of the title's in one read - #3594

Draft
Royalflamejlh wants to merge 1 commit into
xcl-dev:mainfrom
Royalflamejlh:d3d12x/wine-resident-read
Draft

Royalflamejlh wants to merge 1 commit into
xcl-dev:mainfrom
Royalflamejlh:d3d12x/wine-resident-read

Conversation

@Royalflamejlh

@Royalflamejlh Royalflamejlh commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Under Wine, title_textures::read_committed_into skips its whole-range ReadProcessMemory (a guard page would be consumed: #2844) and reads region by region, one VirtualQuery per 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, made pub(crate)) plus one ReadProcessMemory. 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_readable visible to the crate.

Tested

  • RTX 4060 Ti 16 GB, NVIDIA 615.71.09, AMD Ryzen 9 9950X3D, Linux, Wine 11.21 Staging, Rust 1.98.0, x86_64-pc-windows-gnu, release, head 26f433146 (Foniass's review points fixed; the results below that name a364ed71b were 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_pixels failed and three stream_recheck_* tests after it on its poisoned lock. main 6bfb5c515 fails the same four in 10 of 11 runs of the same command here: it fails when gpu_uploads_of_a_texture_on_two_queues_keep_their_order runs before it in the same process (passes alone, 3 of 3), not because of this change.
  • In a retail title on a tree with other unmerged pull requests (1 run each, 900 s, XCL's memory-call counters XCL_LOOK_STATS=2 from another fork): the VirtualQuery call site in read_committed_into made 150,000 to 195,000 calls a second; with this change, D3D12.X: read a view heap's slots in place when scanning for superseded targets #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:

xcl-smoke v1
commit: 1c8b551475e1e7bfe48f94448492a4c3544a2e0f
gpu: NVIDIA GeForce RTX 5070 Ti
title: 5330474d
seconds: 60
exit: 0x0
frames shown: 1620 (PresentX 1621)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 15476 MB

this PR's head:

xcl-smoke v1
commit: 26f4331469fb1a1709e77607612f5d6176e59dca
gpu: NVIDIA GeForce RTX 5070 Ti
title: 5330474d
seconds: 60
exit: 0x0
frames shown: 1662 (PresentX 1662)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15671 MB

Not tested

AI use

  • Claude Code. Claude Opus 5.5 wrote the change, the test and this description, and ran the tests above.

@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:shaders Shader cache, PSO compilation, pipeline libraries, precompilation gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) labels Dec 1, 2026
Royalflamejlh added a commit to Royalflamejlh/xcl that referenced this pull request Dec 1, 2026
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Review (head a364ed7, diff read, not a merge-check; draft, checks red):

  • The test cannot fail on Windows. In a_few_resident_pages_are_read_without_asking_their_regions (title_textures.rs ~7214), Windows returns from read_committed_into through the whole-range ReadProcessMemory (~3347) before the region walk, so REGION_QUERIES is the same with or without the change. CI is Windows-only, so nothing there covers the new branch; it only fails under Wine.
  • The 16-page limit is a copy of SMALL in pages_readable. The ((limit - 1) >> 12) - (at >> 12) < 16 check (~3350) is what keeps this call away from the part of pages_readable (gpu/shader.rs ~272-292) that probes each non-resident page with a one-byte ReadProcessMemory on longer ranges, which under Wine uses up a guard page (D3D12.X: UMA windows in a driver heap on NVIDIA, 4.9x FPS (0.62 -> 3.03) #2844). If SMALL changes and this literal does not, the guard is lost silently; both should use one constant.
  • No regression run. The change is in crates/xcl/src and Regression run has no xcl-smoke blocks, which is why PR description is 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.

read_committed_into reads the title's bytes with one ReadProcessMemory on
Windows. Under Wine that read uses up a guard page in the range (xcl-dev#2844:
title_bytes_leave_guard_pages_alone fails with it), so there every read
asked VirtualQuery about each region first, even a 32-byte one. In a run
in the title's world those queries were the first call site of all,
about 17 µs each, mostly for 32-byte descriptor slots. Under Wine 11.21,
with no other thread, a VirtualQuery in a 300 MB committed run took
2.5 µs and a working-set question about 1, 4 or 16 pages 0.33, 0.38 and
0.61 µs, both under Wine's virtual-memory lock.

Under Wine a range of up to 16 pages that the working set holds as
readable (gpu::shader::pages_readable, now crate-visible) is read in one
copy_committed_region, which survives a concurrent decommit. A guard page
is never in the working set, so a range with one is read region by region
as before, and its guard stays. Windows is unchanged.

Measured with two other changes (the superseded-target scan reading view
heap slots in place, and the memory report reusing its commit sum) on a
tree carrying other unmerged work, RTX 4060 Ti, Wine 11.21, 1 run each
with the same options, the title in its world: 1.19 -> 3.70 frames a
second, and this VirtualQuery call site went from 1,120 ms of thread time
a second on average to out of the top list. What each change gives on
its own was not measured.

The 16 is pages_readable's own limit (SMALL_RANGE_PAGES, now shared): past
it that function reads a byte of each page that is not resident, which
under Wine would use up a guard page.

Test: read the Wine way on any platform, a 32-byte read and a 16-page
read of resident memory ask no region (red without the change, on Windows
too); a 32-page read reads the same bytes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Royalflamejlh
Royalflamejlh force-pushed the d3d12x/wine-resident-read branch from a364ed7 to 26f4331 Compare December 1, 2026 21:36
@Royalflamejlh

Copy link
Copy Markdown
Contributor Author

@Foniass thanks; both done at 26f433146.

  • The test now reads through 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.
  • The 16-page limit is now gpu::shader::SMALL_RANGE_PAGES, used by pages_readable and by this check.
  • The smoke pair is still owed.

AI use: Claude Code (Claude Opus 5.5) made the change, ran the tests and drafted this reply.

@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 review (head 26f4331, since a364ed7, diff read, not a merge-check; draft, checks red):

  • The test cannot fail on Windows: fixed. a_few_resident_pages_are_read_without_asking_their_regions (title_textures.rs ~7218) now calls read_committed_into_as(.., true), so it takes the Wine branch on any platform and would bump REGION_QUERIES (~3364) without the new branch.
  • The 16-page limit is a copy of SMALL: fixed. Both read_committed_into_as (~3354) and pages_readable (gpu/shader.rs ~256) use gpu::shader::SMALL_RANGE_PAGES (~234), and the test sizes its reads from it.
  • No regression run: still open. Regression run still says the xcl-smoke blocks are owed, which is why PR description is 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.

@github-actions github-actions Bot removed the needs-pr-check Failing the PR description check (CONTRIBUTING.md) label Dec 2, 2026
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 area:shaders Shader cache, PSO compilation, pipeline libraries, precompilation 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