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

Open
Royalflamejlh wants to merge 1 commit from upstream-pr/3594 into main
Royalflamejlh commented 2026-12-01 17:37:00 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-01T17:37:00Z.


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, #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

  • Native Windows (unchanged there by construction), AMD, the whole suite. #3575 also adds a fast path to 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

  • Claude Code. Claude Opus 5.5 wrote the change, the test and this description, and ran the tests above.
<!-- greyfinch-sync:ivall/xcl:issue:5591060526 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3594). Originally posted by [Royalflamejlh](https://github.com/Royalflamejlh) on 2026-12-01T17:37:00Z. --- 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, #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** - Native Windows (unchanged there by construction), AMD, the whole suite. #3575 also adds a fast path to `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** - Claude Code. Claude Opus 5.5 wrote the change, the test and this description, and ran the tests above.
Foniass commented 2026-12-01 20:45:20 +00:00 (Migrated from github.com)

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):

  • 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 (#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.

<!-- greyfinch-sync:ivall/xcl:comment:7325218627 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3594#issuecomment-7325218627). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T20:45:20Z. --- Review (head a364ed71, 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 (#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.
Royalflamejlh commented 2026-12-01 21:37:09 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-01T21:37:09Z.


@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.

<!-- greyfinch-sync:ivall/xcl:comment:7326533202 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3594#issuecomment-7326533202). Originally posted by [Royalflamejlh](https://github.com/Royalflamejlh) on 2026-12-01T21:37:09Z. --- @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.
Foniass commented 2026-12-01 21:41:39 +00:00 (Migrated from github.com)

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


Follow-up review (head 26f43314, since a364ed71, 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.

<!-- greyfinch-sync:ivall/xcl:comment:7326645036 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3594#issuecomment-7326645036). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T21:41:39Z. --- Follow-up review (head 26f43314, since a364ed71, 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.
throny commented 2026-12-02 05:26:28 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by throny on 2026-12-02T05:26:28Z.


merge-check claim
head: 26f4331469

<!-- greyfinch-sync:ivall/xcl:comment:7335936607 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3594#issuecomment-7335936607). Originally posted by [throny](https://github.com/throny) on 2026-12-02T05:26:28Z. --- merge-check claim head: 26f4331469fb1a1709e77607612f5d6176e59dca
throny commented 2026-12-02 05:39:17 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by throny on 2026-12-02T05:39:17Z.


merge-check
base: main 1c8b55147
head: 26f4331469
merge: 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

<!-- greyfinch-sync:ivall/xcl:comment:7336155527 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3594#issuecomment-7336155527). Originally posted by [throny](https://github.com/throny) on 2026-12-02T05:39:17Z. --- merge-check base: main 1c8b55147 head: 26f4331469fb1a1709e77607612f5d6176e59dca merge: 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
Decodere commented 2026-12-02 10:47:15 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Decodere on 2026-12-02T10:47:15Z.


merge-check
base: 1c8b551475
head: 26f4331469
merge: 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 --nocapture passed 148/0 (20 ignored, including gpu_two_pass_cache_e2e), and cargo test -p xcl --lib -- --test-threads=2 passed 2762/0 (31 ignored; --test-threads=4 hit 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) and pages_readable as pub(crate) in gpu::shader, and extracts read_committed_into_as(at, out, wine) in title_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 after at.checked_add(len) and len == 0 checks) query pages_readable(at, limit) via K32QueryWorkingSetEx—which returns None without touching or probing any guard/no-access/non-resident page for small ranges—and copy in one pass via copy_committed_region when Some(true), falling back to the VirtualQuery loop otherwise. The new unit test verifies zero VirtualQuery calls for resident 32-byte and 16-page reads with wine = true and fallback for 32-page reads. Note: native Windows check; the Wine branch was verified via read_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 1c8b5514 baseline 1462 frames), 14795 MB peak commit (-7.8% vs 16043 MB baseline), 0 device removals, 0 crashes.

xcl-smoke v1
commit: c1ebdfc1425151e2f14091ba746fddcbb3006eaa
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1653 (PresentX 1653)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14795 MB

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)

<!-- greyfinch-sync:ivall/xcl:comment:7342979826 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3594#issuecomment-7342979826). Originally posted by [Decodere](https://github.com/Decodere) on 2026-12-02T10:47:15Z. --- merge-check base: 1c8b551475e1e7bfe48f94448492a4c3544a2e0f head: 26f4331469fb1a1709e77607612f5d6176e59dca merge: 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 --nocapture` passed 148/0 (20 ignored, including gpu_two_pass_cache_e2e), and `cargo test -p xcl --lib -- --test-threads=2` passed 2762/0 (31 ignored; `--test-threads=4` hit 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) and `pages_readable` as `pub(crate)` in `gpu::shader`, and extracts `read_committed_into_as(at, out, wine)` in `title_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 after `at.checked_add(len)` and `len == 0` checks) query `pages_readable(at, limit)` via `K32QueryWorkingSetEx`—which returns `None` without touching or probing any guard/no-access/non-resident page for small ranges—and copy in one pass via `copy_committed_region` when `Some(true)`, falling back to the `VirtualQuery` loop otherwise. The new unit test verifies zero `VirtualQuery` calls for resident 32-byte and 16-page reads with `wine = true` and fallback for 32-page reads. Note: native Windows check; the Wine branch was verified via `read_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 1c8b5514 baseline 1462 frames), 14795 MB peak commit (-7.8% vs 16043 MB baseline), 0 device removals, 0 crashes. ``` xcl-smoke v1 commit: c1ebdfc1425151e2f14091ba746fddcbb3006eaa gpu: NVIDIA GeForce RTX 4060 title: 29640639 seconds: 60 exit: 0x0 frames shown: 1653 (PresentX 1653) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14795 MB ``` 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)
bmjask commented 2026-12-02 15:33:47 +00:00 (Migrated from github.com)

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 3355

@@ -3337,12 +3342,17 @@ pub(super) unsafe fn read_committed_into(at: usize, out: &mut [u8]) {
     // of MiB – a 16 KiB texture cost ~120 µs at the start of a 64 MiB run, ~1.3 ms of 512 MiB.
     // `ReadProcessMemory` refuses a range with a page that is not committed, no-access or a guard
     // page (and leaves the guard in place: `title_bytes_leave_guard_pages_alone`). Under Wine
-    // that test fails with it (#2844), so there it is region by region.
+    // that test fails with it (#2844), so there it is one read of up to 16 pages the working set
+    // holds as readable (a guard page never is), else region by region.
     let mut read = 0usize;
     if len == 0 {
         return;
     }
-    if !crate::util::under_wine() && ReadProcessMemory(GetCurrentProcess(), at as *const c_void, out.as_mut_ptr() as *mut c_void, len, &mut read) != 0 {
+    if !wine && ReadProcessMemory(GetCurrentProcess(), at as *const c_void, out.as_mut_ptr() as *mut c_void, len, &mut read) != 0 {
+        return;
+    }
+    if wine && ((limit - 1) >> 12) - (at >> 12) < crate::gpu::shader::SMALL_RANGE_PAGES && crate::gpu::shader::pages_readable(at, limit) == Some(true) {
+        copy_committed_region(at, out.as_mut_ptr(), len);

Medium: 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 after pages_readable answers is still read with ReadProcessMemory. If thread A gets pages_readable(at, limit) == Some(true) and thread B then calls VirtualProtect(page, PAGE_READWRITE|PAGE_GUARD), A's copy_committed_region reads that page under Wine and consumes the guard (#2844). The comment in with_title_bytes says 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.

<!-- greyfinch-sync:ivall/xcl:review-comment:4772034716 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3594#discussion_r4772034716). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T15:33:47Z. **Code review location:** `crates/xcl/src/hle/d3d12x/title_textures.rs`; line 3355 ~~~~diff @@ -3337,12 +3342,17 @@ pub(super) unsafe fn read_committed_into(at: usize, out: &mut [u8]) { // of MiB – a 16 KiB texture cost ~120 µs at the start of a 64 MiB run, ~1.3 ms of 512 MiB. // `ReadProcessMemory` refuses a range with a page that is not committed, no-access or a guard // page (and leaves the guard in place: `title_bytes_leave_guard_pages_alone`). Under Wine - // that test fails with it (#2844), so there it is region by region. + // that test fails with it (#2844), so there it is one read of up to 16 pages the working set + // holds as readable (a guard page never is), else region by region. let mut read = 0usize; if len == 0 { return; } - if !crate::util::under_wine() && ReadProcessMemory(GetCurrentProcess(), at as *const c_void, out.as_mut_ptr() as *mut c_void, len, &mut read) != 0 { + if !wine && ReadProcessMemory(GetCurrentProcess(), at as *const c_void, out.as_mut_ptr() as *mut c_void, len, &mut read) != 0 { + return; + } + if wine && ((limit - 1) >> 12) - (at >> 12) < crate::gpu::shader::SMALL_RANGE_PAGES && crate::gpu::shader::pages_readable(at, limit) == Some(true) { + copy_committed_region(at, out.as_mut_ptr(), len); ~~~~ --- **Medium**: 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 after `pages_readable` answers is still read with ReadProcessMemory. If thread A gets `pages_readable(at, limit) == Some(true)` and thread B then calls `VirtualProtect(page, PAGE_READWRITE|PAGE_GUARD)`, A's `copy_committed_region` reads that page under Wine and consumes the guard (#2844). The comment in `with_title_bytes` says 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.
bmjask commented 2026-12-02 15:33:47 +00:00 (Migrated from github.com)

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 3354

@@ -3337,12 +3342,17 @@ pub(super) unsafe fn read_committed_into(at: usize, out: &mut [u8]) {
     // of MiB – a 16 KiB texture cost ~120 µs at the start of a 64 MiB run, ~1.3 ms of 512 MiB.
     // `ReadProcessMemory` refuses a range with a page that is not committed, no-access or a guard
     // page (and leaves the guard in place: `title_bytes_leave_guard_pages_alone`). Under Wine
-    // that test fails with it (#2844), so there it is region by region.
+    // that test fails with it (#2844), so there it is one read of up to 16 pages the working set
+    // holds as readable (a guard page never is), else region by region.
     let mut read = 0usize;
     if len == 0 {
         return;
     }
-    if !crate::util::under_wine() && ReadProcessMemory(GetCurrentProcess(), at as *const c_void, out.as_mut_ptr() as *mut c_void, len, &mut read) != 0 {
+    if !wine && ReadProcessMemory(GetCurrentProcess(), at as *const c_void, out.as_mut_ptr() as *mut c_void, len, &mut read) != 0 {
+        return;
+    }
+    if wine && ((limit - 1) >> 12) - (at >> 12) < crate::gpu::shader::SMALL_RANGE_PAGES && crate::gpu::shader::pages_readable(at, limit) == Some(true) {

Medium: The fast path and the region walk disagree on which pages are readable: the walk zero-fills PAGE_EXECUTE (0x10) pages (m.Protect & 0xEE), while pages_readable accepts 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.

<!-- greyfinch-sync:ivall/xcl:review-comment:4772034750 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3594#discussion_r4772034750). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T15:33:47Z. **Code review location:** `crates/xcl/src/hle/d3d12x/title_textures.rs`; line 3354 ~~~~diff @@ -3337,12 +3342,17 @@ pub(super) unsafe fn read_committed_into(at: usize, out: &mut [u8]) { // of MiB – a 16 KiB texture cost ~120 µs at the start of a 64 MiB run, ~1.3 ms of 512 MiB. // `ReadProcessMemory` refuses a range with a page that is not committed, no-access or a guard // page (and leaves the guard in place: `title_bytes_leave_guard_pages_alone`). Under Wine - // that test fails with it (#2844), so there it is region by region. + // that test fails with it (#2844), so there it is one read of up to 16 pages the working set + // holds as readable (a guard page never is), else region by region. let mut read = 0usize; if len == 0 { return; } - if !crate::util::under_wine() && ReadProcessMemory(GetCurrentProcess(), at as *const c_void, out.as_mut_ptr() as *mut c_void, len, &mut read) != 0 { + if !wine && ReadProcessMemory(GetCurrentProcess(), at as *const c_void, out.as_mut_ptr() as *mut c_void, len, &mut read) != 0 { + return; + } + if wine && ((limit - 1) >> 12) - (at >> 12) < crate::gpu::shader::SMALL_RANGE_PAGES && crate::gpu::shader::pages_readable(at, limit) == Some(true) { ~~~~ --- **Medium**: The fast path and the region walk disagree on which pages are readable: the walk zero-fills PAGE_EXECUTE (0x10) pages (`m.Protect & 0xEE`), while `pages_readable` accepts 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.
bmjask commented 2026-12-02 15:33:47 +00:00 (Migrated from github.com)

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.

  1. Medium crates/xcl/src/hle/d3d12x/title_textures.rs:3355: Not certain about this one: there's a race between the working-set check and copy_committed_region. (inline)
  2. Medium 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), while pages_readable accepts any Valid page that isn't NOACCESS or GUARD, PAGE_EXECUTE included. (inline)
  3. Medium crates/xcl/src/gpu/shader.rs:249: pages_readable is now pub(crate), but for ranges over 16 pages it still reads one byte of each non-resident page with ReadProcessMemory, so readable() 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.

<!-- greyfinch-sync:ivall/xcl:review:6153968524 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3594#pullrequestreview-6153968524). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T15:33:47Z. **Review:** COMMENTED --- Review of `26f43314`: 3 finding(s) (3 medium), most severe first. 1. **Medium** `crates/xcl/src/hle/d3d12x/title_textures.rs:3355`: Not certain about this one: there's a race between the working-set check and `copy_committed_region`. (inline) 2. **Medium** `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`), while `pages_readable` accepts any Valid page that isn't NOACCESS or GUARD, PAGE_EXECUTE included. (inline) 3. **Medium** `crates/xcl/src/gpu/shader.rs:249`: `pages_readable` is now `pub(crate)`, but for ranges over 16 pages it still reads one byte of each non-resident page with ReadProcessMemory, so `readable()` 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._
bmjask commented 2026-12-02 15:33:48 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T15:33:48Z.

Code review location: crates/xcl/src/gpu/shader.rs; line 249

@@ -243,15 +246,14 @@ pub fn readable(p: usize, len: usize) -> bool {
 /// out, guard, reserved, no access). In a longer range such a page is read by the kernel (a
 /// byte of it): a committed one is then resident, as the caller's reads would make it, any other
 /// is not readable.
-fn pages_readable(p: usize, end: usize) -> Option<bool> {
+pub(crate) fn pages_readable(p: usize, end: usize) -> Option<bool> {

Medium: pages_readable is now pub(crate), but for ranges over 16 pages it still reads one byte of each non-resident page with ReadProcessMemory, so readable() under Wine can consume a guard page in a range of 17 or more pages. For example, readable(p, 64<<12) from shader::capture on 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.

<!-- greyfinch-sync:ivall/xcl:review-comment:4772034764 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3594#discussion_r4772034764). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T15:33:48Z. **Code review location:** `crates/xcl/src/gpu/shader.rs`; line 249 ~~~~diff @@ -243,15 +246,14 @@ pub fn readable(p: usize, len: usize) -> bool { /// out, guard, reserved, no access). In a longer range such a page is read by the kernel (a /// byte of it): a committed one is then resident, as the caller's reads would make it, any other /// is not readable. -fn pages_readable(p: usize, end: usize) -> Option<bool> { +pub(crate) fn pages_readable(p: usize, end: usize) -> Option<bool> { ~~~~ --- **Medium**: `pages_readable` is now `pub(crate)`, but for ranges over 16 pages it still reads one byte of each non-resident page with ReadProcessMemory, so `readable()` under Wine can consume a guard page in a range of 17 or more pages. For example, `readable(p, 64<<12)` from `shader::capture` on 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.
bmjask commented 2026-12-02 15:33:54 +00:00 (Migrated from github.com)

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.

<!-- greyfinch-sync:ivall/xcl:comment:7350540041 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3594#issuecomment-7350540041). Originally posted by [bmjask](https://github.com/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.
ClosetPie107 commented 2026-12-02 17:13:20 +00:00 (Migrated from github.com)

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 26f4331

Merged onto main 5eaadb54 (clean merge) and compared with main run twice on the same machine.

Setup

  • AMD Radeon RX 9070 16 GB (RDNA4, RADV GFX1201, Mesa 26.3.1), Ryzen 5 9600X, 30 GiB RAM, CachyOS (kernel 7.3.7)
  • Wine 11.23 (system), stock vkd3d-proton v3.1-83-gcae8353ed and DXVK dxgi.dll from GE-Proton11-16, DXC 1.9.2609.5
  • Debug build, cross-compiled for x86_64-pc-windows-msvc with cargo-xwin; test binaries run under Wine

Tested: cargo xwin test --workspace --target x86_64-pc-windows-msvc --no-fail-fast -- --test-threads=4 --skip <31 tests>

passed failed ignored
main 5eaadb54 2769 177 52
this PR merged 2771 176 52
  • Tests that fail with this PR and pass on main: none.
  • Tests this PR adds: 1 of 1 pass (a_few_resident_pages_are_read_without_asking_their_regions).
  • Passing here and failing on main: gpu::recomp::tests::gpu_qsad_and_mqsad (flaky on main under Wine).
About the failures on main and the 31 skipped tests (same for every PR in this batch)
  • Most of 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 get E_INVALIDARG (0x80070057). Running vkd3d-proton master with its vtable check taken out, hle::d3d12x::sparse::tests goes from 106 passed / 38 failed to 144 / 0.
  • The 31 skipped tests make vkd3d-proton's dxil-spirv call 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 two gpu_mesh_mode_* tests, and console_wave64_compute_through_the_pso_hook_dispatch_and_read_back, plus serialize_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-spirv 93ab44c5).
  • main was run twice: same counts, same failure set. SKIPPED lines (same as main): 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 a merge-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.

<!-- greyfinch-sync:ivall/xcl:comment:7353066082 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3594#issuecomment-7353066082). Originally posted by [ClosetPie107](https://github.com/ClosetPie107) on 2026-12-02T17:13:20Z. --- **Linux / AMD RDNA4 (RADV, Wine + vkd3d-proton): full test suite on `26f4331`** Merged onto `main` `5eaadb54` (clean merge) and compared with `main` run twice on the same machine. **Setup** - AMD Radeon RX 9070 16 GB (RDNA4, RADV GFX1201, Mesa 26.3.1), Ryzen 5 9600X, 30 GiB RAM, CachyOS (kernel 7.3.7) - Wine 11.23 (system), stock vkd3d-proton `v3.1-83-gcae8353ed` and DXVK `dxgi.dll` from GE-Proton11-16, DXC 1.9.2609.5 - Debug build, cross-compiled for `x86_64-pc-windows-msvc` with `cargo-xwin`; test binaries run under Wine **Tested:** `cargo xwin test --workspace --target x86_64-pc-windows-msvc --no-fail-fast -- --test-threads=4 --skip <31 tests>` | | passed | failed | ignored | |---|---|---|---| | `main` `5eaadb54` | 2769 | 177 | 52 | | this PR merged | 2771 | 176 | 52 | - **Tests that fail with this PR and pass on `main`:** none. - **Tests this PR adds:** 1 of 1 pass (`a_few_resident_pages_are_read_without_asking_their_regions`). - Passing here and failing on `main`: `gpu::recomp::tests::gpu_qsad_and_mqsad` (flaky on `main` under Wine). <details><summary>About the failures on <code>main</code> and the 31 skipped tests (same for every PR in this batch)</summary> - Most of `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 get `E_INVALIDARG` (`0x80070057`). Running vkd3d-proton master with its vtable check taken out, `hle::d3d12x::sparse::tests` goes from 106 passed / 38 failed to 144 / 0. - The 31 skipped tests make vkd3d-proton's dxil-spirv call `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 two `gpu_mesh_mode_*` tests, and `console_wave64_compute_through_the_pso_hook_dispatch_and_read_back`, plus `serialize_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-spirv `93ab44c5`). - `main` was run twice: same counts, same failure set. `SKIPPED` lines (same as `main`): no heap windows (2), no D3D12 debug layer (2-3), driver cache control not implemented in vkd3d-proton (1). </details> **Not tested:** Windows, NVIDIA, a retail title / `scripts/smoke.ps1`, a review of the diff. This is a test report, not a `merge-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.
Royalflamejlh commented 2026-12-02 20:32:19 +00:00 (Migrated from github.com)

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 3355

@@ -3337,12 +3342,17 @@ pub(super) unsafe fn read_committed_into(at: usize, out: &mut [u8]) {
     // of MiB – a 16 KiB texture cost ~120 µs at the start of a 64 MiB run, ~1.3 ms of 512 MiB.
     // `ReadProcessMemory` refuses a range with a page that is not committed, no-access or a guard
     // page (and leaves the guard in place: `title_bytes_leave_guard_pages_alone`). Under Wine
-    // that test fails with it (#2844), so there it is region by region.
+    // that test fails with it (#2844), so there it is one read of up to 16 pages the working set
+    // holds as readable (a guard page never is), else region by region.
     let mut read = 0usize;
     if len == 0 {
         return;
     }
-    if !crate::util::under_wine() && ReadProcessMemory(GetCurrentProcess(), at as *const c_void, out.as_mut_ptr() as *mut c_void, len, &mut read) != 0 {
+    if !wine && ReadProcessMemory(GetCurrentProcess(), at as *const c_void, out.as_mut_ptr() as *mut c_void, len, &mut read) != 0 {
+        return;
+    }
+    if wine && ((limit - 1) >> 12) - (at >> 12) < crate::gpu::shader::SMALL_RANGE_PAGES && crate::gpu::shader::pages_readable(at, limit) == Some(true) {
+        copy_committed_region(at, out.as_mut_ptr(), len);

Not changed: this window is the one the region walk already has on main. It asks VirtualQuery (:3366) and then reads with copy_committed_region (:3375), and a page guarded in between is read the same way. This change replaces the question (the working set instead of VirtualQuery), not the gap between asking and reading. No lock of XCL's can close that gap, since the title can call VirtualProtect on its own memory from any thread.

AI use: Claude Code (Claude Opus 5.5) checked the code and wrote this reply.

<!-- greyfinch-sync:ivall/xcl:review-comment:4775618534 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3594#discussion_r4775618534). Originally posted by [Royalflamejlh](https://github.com/Royalflamejlh) on 2026-12-02T20:32:19Z. **Code review location:** `crates/xcl/src/hle/d3d12x/title_textures.rs`; line 3355 ~~~~diff @@ -3337,12 +3342,17 @@ pub(super) unsafe fn read_committed_into(at: usize, out: &mut [u8]) { // of MiB – a 16 KiB texture cost ~120 µs at the start of a 64 MiB run, ~1.3 ms of 512 MiB. // `ReadProcessMemory` refuses a range with a page that is not committed, no-access or a guard // page (and leaves the guard in place: `title_bytes_leave_guard_pages_alone`). Under Wine - // that test fails with it (#2844), so there it is region by region. + // that test fails with it (#2844), so there it is one read of up to 16 pages the working set + // holds as readable (a guard page never is), else region by region. let mut read = 0usize; if len == 0 { return; } - if !crate::util::under_wine() && ReadProcessMemory(GetCurrentProcess(), at as *const c_void, out.as_mut_ptr() as *mut c_void, len, &mut read) != 0 { + if !wine && ReadProcessMemory(GetCurrentProcess(), at as *const c_void, out.as_mut_ptr() as *mut c_void, len, &mut read) != 0 { + return; + } + if wine && ((limit - 1) >> 12) - (at >> 12) < crate::gpu::shader::SMALL_RANGE_PAGES && crate::gpu::shader::pages_readable(at, limit) == Some(true) { + copy_committed_region(at, out.as_mut_ptr(), len); ~~~~ --- Not changed: this window is the one the region walk already has on `main`. It asks `VirtualQuery` (:3366) and then reads with `copy_committed_region` (:3375), and a page guarded in between is read the same way. This change replaces the question (the working set instead of `VirtualQuery`), not the gap between asking and reading. No lock of XCL's can close that gap, since the title can call `VirtualProtect` on its own memory from any thread. AI use: Claude Code (Claude Opus 5.5) checked the code and wrote this reply.
Royalflamejlh commented 2026-12-02 20:32:22 +00:00 (Migrated from github.com)

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 3354

@@ -3337,12 +3342,17 @@ pub(super) unsafe fn read_committed_into(at: usize, out: &mut [u8]) {
     // of MiB – a 16 KiB texture cost ~120 µs at the start of a 64 MiB run, ~1.3 ms of 512 MiB.
     // `ReadProcessMemory` refuses a range with a page that is not committed, no-access or a guard
     // page (and leaves the guard in place: `title_bytes_leave_guard_pages_alone`). Under Wine
-    // that test fails with it (#2844), so there it is region by region.
+    // that test fails with it (#2844), so there it is one read of up to 16 pages the working set
+    // holds as readable (a guard page never is), else region by region.
     let mut read = 0usize;
     if len == 0 {
         return;
     }
-    if !crate::util::under_wine() && ReadProcessMemory(GetCurrentProcess(), at as *const c_void, out.as_mut_ptr() as *mut c_void, len, &mut read) != 0 {
+    if !wine && ReadProcessMemory(GetCurrentProcess(), at as *const c_void, out.as_mut_ptr() as *mut c_void, len, &mut read) != 0 {
+        return;
+    }
+    if wine && ((limit - 1) >> 12) - (at >> 12) < crate::gpu::shader::SMALL_RANGE_PAGES && crate::gpu::shader::pages_readable(at, limit) == Some(true) {

True that the two differ on an execute-only page (0x10). Not changed: pages_readable answers as readable (gpu/shader.rs:225) has on main, which also takes any committed page that is not no-access or guard; the walk's 0xEE mask 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.

<!-- greyfinch-sync:ivall/xcl:review-comment:4775619153 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3594#discussion_r4775619153). Originally posted by [Royalflamejlh](https://github.com/Royalflamejlh) on 2026-12-02T20:32:22Z. **Code review location:** `crates/xcl/src/hle/d3d12x/title_textures.rs`; line 3354 ~~~~diff @@ -3337,12 +3342,17 @@ pub(super) unsafe fn read_committed_into(at: usize, out: &mut [u8]) { // of MiB – a 16 KiB texture cost ~120 µs at the start of a 64 MiB run, ~1.3 ms of 512 MiB. // `ReadProcessMemory` refuses a range with a page that is not committed, no-access or a guard // page (and leaves the guard in place: `title_bytes_leave_guard_pages_alone`). Under Wine - // that test fails with it (#2844), so there it is region by region. + // that test fails with it (#2844), so there it is one read of up to 16 pages the working set + // holds as readable (a guard page never is), else region by region. let mut read = 0usize; if len == 0 { return; } - if !crate::util::under_wine() && ReadProcessMemory(GetCurrentProcess(), at as *const c_void, out.as_mut_ptr() as *mut c_void, len, &mut read) != 0 { + if !wine && ReadProcessMemory(GetCurrentProcess(), at as *const c_void, out.as_mut_ptr() as *mut c_void, len, &mut read) != 0 { + return; + } + if wine && ((limit - 1) >> 12) - (at >> 12) < crate::gpu::shader::SMALL_RANGE_PAGES && crate::gpu::shader::pages_readable(at, limit) == Some(true) { ~~~~ --- True that the two differ on an execute-only page (0x10). Not changed: `pages_readable` answers as `readable` (`gpu/shader.rs:225`) has on `main`, which also takes any committed page that is not no-access or guard; the walk's `0xEE` mask 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.
Royalflamejlh commented 2026-12-02 20:32:25 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T20:32:25Z.

Code review location: crates/xcl/src/gpu/shader.rs; line 249

@@ -243,15 +246,14 @@ pub fn readable(p: usize, len: usize) -> bool {
 /// out, guard, reserved, no access). In a longer range such a page is read by the kernel (a
 /// byte of it): a committed one is then resident, as the caller's reads would make it, any other
 /// is not readable.
-fn pages_readable(p: usize, end: usize) -> Option<bool> {
+pub(crate) fn pages_readable(p: usize, end: usize) -> Option<bool> {

Right that pages_readable reads 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 how readable behaves on main, 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 returns None instead of reading (gpu/shader.rs:276). readable under 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.

<!-- greyfinch-sync:ivall/xcl:review-comment:4775619846 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3594#discussion_r4775619846). Originally posted by [Royalflamejlh](https://github.com/Royalflamejlh) on 2026-12-02T20:32:25Z. **Code review location:** `crates/xcl/src/gpu/shader.rs`; line 249 ~~~~diff @@ -243,15 +246,14 @@ pub fn readable(p: usize, len: usize) -> bool { /// out, guard, reserved, no access). In a longer range such a page is read by the kernel (a /// byte of it): a committed one is then resident, as the caller's reads would make it, any other /// is not readable. -fn pages_readable(p: usize, end: usize) -> Option<bool> { +pub(crate) fn pages_readable(p: usize, end: usize) -> Option<bool> { ~~~~ --- Right that `pages_readable` reads 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 how `readable` behaves on `main`, 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 returns `None` instead of reading (`gpu/shader.rs:276`). `readable` under 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.
Royalflamejlh commented 2026-12-02 21:25:35 +00:00 (Migrated from github.com)

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.

<!-- greyfinch-sync:ivall/xcl:comment:7359262673 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3594#issuecomment-7359262673). Originally posted by [Royalflamejlh](https://github.com/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.
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/3594:upstream-pr/3594'
git switch 'upstream-pr/3594'

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