D3D12.X: leave uncommitted pages out when publishing a texture download #3549

Open
BBareth wants to merge 1 commit from upstream-pr/3549 into main
BBareth commented 2026-11-30 22:48:05 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by BBareth on 2026-11-30T22:48:05Z.


A GPU-written title texture is copied back into the title's memory when its fence completes, and the fence value stays hidden from the title until that copy succeeds. write_changed_pages refused every changed page that was not committed. So a download into memory the title has only reserved (a sparse home not in use) failed on every retry, and its fence never became visible. This change leaves out pages that are reserved and settled, and free pages, since the title cannot read them. Committed pages that are read-only or guarded still fail closed and retry, as before.

A reserved page is left out only when it is settled. MapTitlePhysicalPages unmaps what an address holds before it commits the new page, under kernelx's AWAY lock. So a page is skipped only when that lock is free, no physical page is kept there, and the page is still not committed (kernelx::settled_uncommitted, which never blocks). Otherwise the download retries as before, and a page committed in between is written. A mapped physical page that XCL keeps reserved until its first use (kernelx::lazy) is readable by the title, so it is committed and written.

In a retail title (part of #505) this hung the game when the world loaded. From 522 s, every retry of two downloads (0x20000 and 0x10000 bytes) found MEM_RESERVE pages. The title's frame-pacing wait on that fence spun, submits stopped at 528 s, and the title's own GPU watchdog crashed it at 552 s. #3550 hits the same refusal sooner (crash at ~161 s) and depends on this PR: https://github.com/xcl-dev/xcl/pull/3550#issuecomment-7364038479

The writes for textures over pages the title mapped (CopyPageMappingsBatchX, the mapped_homes part of the earlier revision) are taken out of this PR. They come back in a separate PR that addresses the review points on them.

What is in it

  • crates/xcl/src/hle/d3d12x/title_textures.rs, write_changed_pages:
    • calls kernelx::lazy::ensure on a reserved run, as cpu_writes and DirectStorage do before their writes;
    • then leaves out reserved or free pages up to the next 64 KiB boundary when kernelx::settled_uncommitted says they are settled, and retries otherwise;
    • a page left out is logged (note_download_page_left_out: the first two, then at powers of two).
  • crates/xcl/src/hle/kernelx.rs: settled_uncommitted (a try_lock of AWAY; a page kept in Away::at is never "uncommitted").
  • Unit tests:
    • write_changed_pages_leaves_out_pages_the_title_has_not_committed
    • write_changed_pages_commits_a_lazy_page_and_writes_it
    • write_changed_pages_waits_for_a_mapping_call_in_progress (a call holding AWAY holds the download back until it ends)
    • write_changed_pages_writes_a_page_committed_while_it_looked (a page committed between the query and the skip takes the bytes)

Tested

  • RTX 5070 Ti, driver 32.0.16.2124; i7-12700K; Windows 11 Pro 26200; rustc 1.95.0; debug suite, release smoke.
  • cargo build --workspace, then cargo test --workspace --no-fail-fast -- --test-threads=4 on fc7abe51 (on main 078358a0): 3010 passed, 0 failed, 52 ignored.
  • SKIPPED on this adapter, 28 in all:
    • 22 no wave64
    • 2 no heap windows
    • 2 no d3d12SDKLayers.dll
    • 1 no D3D12 debug layer
    • 1 cannot disable the driver cache (no Developer Mode)
  • The first test fails with the skip disabled (reserved pages must not hold the download back) and passes with it.
  • A retail title, 420 s world runs, XCL_RESIDENCY_PRIORITY=1:
    • main 078358a0 + #3550 + this fix: 3 of 3 runs without a crash (3510, 3649 and 3956 frames); 64 to 128 pages left out per run, the first at 136 s.
    • main c53e9696 + #3550 alone: 3 of 3 crashed at 161 to 163 s.
    • Earlier, on an older tree with the first form of this fix plus other PRs: without it the game froze at 528 s and crashed at 552 s; with it, it kept rendering in three runs (to 623, 770 and 792 s).

Regression run

xcl-smoke v1
commit: 078358a058f7ba5d16690dba8dc4e55d2c88ae0a
gpu: NVIDIA GeForce RTX 5070 Ti
title: 9cc6a39e
seconds: 120
exit: 0x0
frames shown: 3046 (PresentX 3046)
presents per 2 s (last 3): 15 27 19
device removals: 0
crashes: 0
peak commit: 32465 MB
xcl-smoke v1
commit: fc7abe5178e4c2e73f3388ccf24fdb061a1f14a1
gpu: NVIDIA GeForce RTX 5070 Ti
title: 9cc6a39e
seconds: 120
exit: 0x0
frames shown: 3077 (PresentX 3077)
presents per 2 s (last 3): 31 27 25
device removals: 0
crashes: 0
peak commit: 32458 MB

Each run follows one warm-up run of the same build; the A button is pressed once at 70 s.

Not tested

  • The 120 s smoke runs end before the 528 s path this fixes; the runs that reach it are listed under Tested.
  • A texture over pages the title mapped (CopyPageMappingsBatchX) still has its download written at its own address, a reserved GPU view. Its reserved pages are now left out, so its fence becomes visible without the GPU's bytes reaching the pages the title reads. On main, that download never completed and its fence stayed hidden. Writing those pages where they are kept is the follow-up PR.
  • The memory cost of committing lazy pages for downloads in a retail title was not measured (only pages a download changes are committed); the smoke run shows the peak commit.
  • AMD GPUs.

AI use

  • Claude Code, Claude Opus 5.5: found the cause from logs and thread dumps, wrote the fix, the AWAY check, its tests and this description, and ran the suite, the smoke runs and the retail-title runs above.
  • Claude Code, Claude Fable 5.2: rebased the earlier revision, wrote the lazy-page commit and its test after review.

🤖 Generated with Claude Code

<!-- greyfinch-sync:ivall/xcl:issue:5575173748 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3549). Originally posted by [BBareth](https://github.com/BBareth) on 2026-11-30T22:48:05Z. --- A GPU-written title texture is copied back into the title's memory when its fence completes, and the fence value stays hidden from the title until that copy succeeds. `write_changed_pages` refused every changed page that was not committed. So a download into memory the title has only reserved (a sparse home not in use) failed on every retry, and its fence never became visible. This change leaves out pages that are reserved and settled, and free pages, since the title cannot read them. Committed pages that are read-only or guarded still fail closed and retry, as before. A reserved page is left out only when it is settled. `MapTitlePhysicalPages` unmaps what an address holds before it commits the new page, under kernelx's `AWAY` lock. So a page is skipped only when that lock is free, no physical page is kept there, and the page is still not committed (`kernelx::settled_uncommitted`, which never blocks). Otherwise the download retries as before, and a page committed in between is written. A mapped physical page that XCL keeps reserved until its first use (`kernelx::lazy`) is readable by the title, so it is committed and written. In a retail title (part of #505) this hung the game when the world loaded. From 522 s, every retry of two downloads (0x20000 and 0x10000 bytes) found `MEM_RESERVE` pages. The title's frame-pacing wait on that fence spun, submits stopped at 528 s, and the title's own GPU watchdog crashed it at 552 s. #3550 hits the same refusal sooner (crash at ~161 s) and depends on this PR: https://github.com/xcl-dev/xcl/pull/3550#issuecomment-7364038479 The writes for textures over pages the title mapped (`CopyPageMappingsBatchX`, the `mapped_homes` part of the earlier revision) are taken out of this PR. They come back in a separate PR that addresses the review points on them. **What is in it** - `crates/xcl/src/hle/d3d12x/title_textures.rs`, `write_changed_pages`: - calls `kernelx::lazy::ensure` on a reserved run, as `cpu_writes` and DirectStorage do before their writes; - then leaves out reserved or free pages up to the next 64 KiB boundary when `kernelx::settled_uncommitted` says they are settled, and retries otherwise; - a page left out is logged (`note_download_page_left_out`: the first two, then at powers of two). - `crates/xcl/src/hle/kernelx.rs`: `settled_uncommitted` (a `try_lock` of `AWAY`; a page kept in `Away::at` is never "uncommitted"). - Unit tests: - `write_changed_pages_leaves_out_pages_the_title_has_not_committed` - `write_changed_pages_commits_a_lazy_page_and_writes_it` - `write_changed_pages_waits_for_a_mapping_call_in_progress` (a call holding `AWAY` holds the download back until it ends) - `write_changed_pages_writes_a_page_committed_while_it_looked` (a page committed between the query and the skip takes the bytes) **Tested** - RTX 5070 Ti, driver 32.0.16.2124; i7-12700K; Windows 11 Pro 26200; rustc 1.95.0; debug suite, release smoke. - `cargo build --workspace`, then `cargo test --workspace --no-fail-fast -- --test-threads=4` on fc7abe51 (on main 078358a0): 3010 passed, 0 failed, 52 ignored. - `SKIPPED` on this adapter, 28 in all: - 22 `no wave64` - 2 `no heap windows` - 2 `no d3d12SDKLayers.dll` - 1 `no D3D12 debug layer` - 1 cannot disable the driver cache (no Developer Mode) - The first test fails with the skip disabled (`reserved pages must not hold the download back`) and passes with it. - A retail title, 420 s world runs, `XCL_RESIDENCY_PRIORITY=1`: - main 078358a0 + #3550 + this fix: 3 of 3 runs without a crash (3510, 3649 and 3956 frames); 64 to 128 pages left out per run, the first at 136 s. - main c53e9696 + #3550 alone: 3 of 3 crashed at 161 to 163 s. - Earlier, on an older tree with the first form of this fix plus other PRs: without it the game froze at 528 s and crashed at 552 s; with it, it kept rendering in three runs (to 623, 770 and 792 s). **Regression run** ``` xcl-smoke v1 commit: 078358a058f7ba5d16690dba8dc4e55d2c88ae0a gpu: NVIDIA GeForce RTX 5070 Ti title: 9cc6a39e seconds: 120 exit: 0x0 frames shown: 3046 (PresentX 3046) presents per 2 s (last 3): 15 27 19 device removals: 0 crashes: 0 peak commit: 32465 MB ``` ``` xcl-smoke v1 commit: fc7abe5178e4c2e73f3388ccf24fdb061a1f14a1 gpu: NVIDIA GeForce RTX 5070 Ti title: 9cc6a39e seconds: 120 exit: 0x0 frames shown: 3077 (PresentX 3077) presents per 2 s (last 3): 31 27 25 device removals: 0 crashes: 0 peak commit: 32458 MB ``` Each run follows one warm-up run of the same build; the A button is pressed once at 70 s. **Not tested** - The 120 s smoke runs end before the 528 s path this fixes; the runs that reach it are listed under **Tested**. - A texture over pages the title mapped (`CopyPageMappingsBatchX`) still has its download written at its own address, a reserved GPU view. Its reserved pages are now left out, so its fence becomes visible without the GPU's bytes reaching the pages the title reads. On `main`, that download never completed and its fence stayed hidden. Writing those pages where they are kept is the follow-up PR. - The memory cost of committing lazy pages for downloads in a retail title was not measured (only pages a download changes are committed); the smoke run shows the peak commit. - AMD GPUs. **AI use** - Claude Code, Claude Opus 5.5: found the cause from logs and thread dumps, wrote the fix, the `AWAY` check, its tests and this description, and ran the suite, the smoke runs and the retail-title runs above. - Claude Code, Claude Fable 5.2: rebased the earlier revision, wrote the lazy-page commit and its test after review. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Gevroska commented 2026-12-01 01:50:27 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Gevroska on 2026-12-01T01:50:27Z.


I reproduced the reserved-page behavior on a pre-fix diagnostic build with Windows WARP. Once the texture readback completed, the native fence was at 11, but the fence visible to the title stayed at 10 while the destination was reserved. After I committed that memory and retried, the title saw 11 and all 4,096 texels matched the expected value.

I also checked whether that pattern appeared during the RTX 3080 loading stall I reported in #505. On driver 32.0.16.1692, the instrumented build recorded six successful texture publications and zero refusals for reserved or free pages across 448 samples. The retail game still reached a black screen. That gives me a reproduction of the fence behavior in WARP, but no evidence tying it to this particular retail run.

Next I’ll run the same mixed-page download on the PR’s parent and head 3cf3ebb4. I’ll keep one page reserved throughout and check two things after readback completes: whether the title sees fence 11, and whether the committed page contains the expected bytes. I’ll also run a fully committed control on both revisions.

AI disclosure — Codex GPT-6.2 Sol ran the initial diagnostics. GPT-6.2 Astra drafted this comment.

I reviewed and approved this comment before posting.

<!-- greyfinch-sync:ivall/xcl:comment:7297953108 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3549#issuecomment-7297953108). Originally posted by [Gevroska](https://github.com/Gevroska) on 2026-12-01T01:50:27Z. --- I reproduced the reserved-page behavior on a pre-fix diagnostic build with Windows WARP. Once the texture readback completed, the native fence was at `11`, but the fence visible to the title stayed at `10` while the destination was reserved. After I committed that memory and retried, the title saw `11` and all 4,096 texels matched the expected value. I also checked whether that pattern appeared during the RTX 3080 loading stall I reported in #505. On driver `32.0.16.1692`, the instrumented build recorded six successful texture publications and zero refusals for reserved or free pages across 448 samples. The retail game still reached a black screen. That gives me a reproduction of the fence behavior in WARP, but no evidence tying it to this particular retail run. Next I’ll run the same mixed-page download on the PR’s parent and head `3cf3ebb4`. I’ll keep one page reserved throughout and check two things after readback completes: whether the title sees fence `11`, and whether the committed page contains the expected bytes. I’ll also run a fully committed control on both revisions. AI disclosure — Codex GPT-6.2 Sol ran the initial diagnostics. GPT-6.2 Astra drafted this comment. I reviewed and approved this comment before posting.
thehollowedone commented 2026-12-01 04:24:33 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by thehollowedone on 2026-12-01T04:24:33Z.


Source review on head 3cf3ebb4: the new reserved-page skip can make a download appear complete while a mapped physical page still has its old bytes.

This is distinct from an unused reservation. XCL's existing page-mapping fixture reserves a GPU-view VA, maps one of its pages to a committed physical pool page, and reads the pool's 0x5a bytes through mirrors::resolve. source_of keeps the GPU-view VA and marks it paged. But prepare_downloads uses that raw VA as the destination, and publish_download calls write_changed_pages on it. The new MEM_RESERVE branch skips that VA, returns success, and clears the GPU writer; the committed pool page is never updated. The title can read stale pool bytes after its fence becomes visible, without any later commit or remap.

The publication path needs to distinguish a genuine unmapped hole from a reserved view with a mapped physical home. For a paged texture, resolve each destination page as uploads do, write changed bytes to the committed backing page, and skip only holes. Tie that resolution to the queue's mapping order so a remap cannot silently send the result to the wrong home before the writer is retired. A focused regression can extend the existing mapped-pool fixture with a GPU write and fence, then assert the pool bytes match the GPU result when the title sees completion. Keep the direct-reservation test too. This is a source trace; I did not run that new GPU regression.

AI use: Codex (GPT-6.2 Sol) checked the publication path; Codex (GPT-6.2 Astra) independently traced the mapped-page case and regression.

<!-- greyfinch-sync:ivall/xcl:comment:7300704248 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3549#issuecomment-7300704248). Originally posted by [thehollowedone](https://github.com/thehollowedone) on 2026-12-01T04:24:33Z. --- Source review on [head `3cf3ebb4`](https://github.com/xcl-dev/xcl/commit/3cf3ebb4cc27f82e5499835427c8229dda988cdb): the new reserved-page skip can make a download **appear complete while a mapped physical page still has its old bytes**. This is distinct from an unused reservation. XCL's [existing page-mapping fixture](https://github.com/xcl-dev/xcl/blob/3cf3ebb4cc27f82e5499835427c8229dda988cdb/crates/xcl/src/hle/d3d12x/title_textures.rs#L4885-L4945) reserves a GPU-view VA, maps one of its pages to a committed physical pool page, and reads the pool's `0x5a` bytes through [`mirrors::resolve`](https://github.com/xcl-dev/xcl/blob/3cf3ebb4cc27f82e5499835427c8229dda988cdb/crates/xcl/src/hle/kernelx.rs#L607-L650). [`source_of` keeps the GPU-view VA and marks it paged](https://github.com/xcl-dev/xcl/blob/3cf3ebb4cc27f82e5499835427c8229dda988cdb/crates/xcl/src/hle/d3d12x/title_textures.rs#L714-L720). But [`prepare_downloads` uses that raw VA as the destination](https://github.com/xcl-dev/xcl/blob/3cf3ebb4cc27f82e5499835427c8229dda988cdb/crates/xcl/src/hle/d3d12x/title_textures.rs#L3883-L3897), and [`publish_download` calls `write_changed_pages` on it](https://github.com/xcl-dev/xcl/blob/3cf3ebb4cc27f82e5499835427c8229dda988cdb/crates/xcl/src/hle/d3d12x/title_textures.rs#L3986-L4013). The new `MEM_RESERVE` branch skips that VA, returns success, and clears the GPU writer; the committed pool page is never updated. The title can read stale pool bytes after its fence becomes visible, without any later commit or remap. The publication path needs to distinguish a genuine unmapped hole from a reserved **view** with a mapped physical home. For a paged texture, resolve each destination page as uploads do, write changed bytes to the committed backing page, and skip only holes. Tie that resolution to the queue's mapping order so a remap cannot silently send the result to the wrong home before the writer is retired. A focused regression can extend the existing mapped-pool fixture with a GPU write and fence, then assert the pool bytes match the GPU result when the title sees completion. Keep the direct-reservation test too. This is a source trace; I did not run that new GPU regression. AI use: Codex (GPT-6.2 Sol) checked the publication path; Codex (GPT-6.2 Astra) independently traced the mapped-page case and regression.
thehollowedone commented 2026-12-01 04:31:42 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by thehollowedone on 2026-12-01T04:31:42Z.


Follow-up to the mapped-page finding, on head 3cf3ebb4: a repair that resolves the physical destination only when the readback is published also needs to reject a later page mapping.

The source permits this sequence: a queue submits a GPU write while a GPU-view page shows physical page A; a later CopyPageMappingsBatchX makes the same view page show B; then the earlier readback completes. mapping_changed clears gpu_written when the mapping call is newer, but leaves gpu_writers intact. download_writes and download_current still accept that writer: the resource generation and raw entry.src have not changed. Resolving the destination at publication would therefore write A's GPU result into B's backing page.

The publication invariant should include page identity at the writer's queue position, not just resource generation and address. A later A→B remap must not send A's GPU result into B. If A remains live, its earlier write still needs publication to A; that may require taking the readback before the remap changes the resource's tiles. If A merely moves, publication should follow A to its current home. A focused regression should check both physical pages after A→B before fence publication, plus a move of A's backing address without a remap. This is a source-derived schedule; I have not run the new GPU regression.

AI use: Codex (GPT-6.2 Sol) traced the mapping and download lifecycle.

<!-- greyfinch-sync:ivall/xcl:comment:7300824791 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3549#issuecomment-7300824791). Originally posted by [thehollowedone](https://github.com/thehollowedone) on 2026-12-01T04:31:42Z. --- Follow-up to [the mapped-page finding](https://github.com/xcl-dev/xcl/pull/3549#issuecomment-7300704248), on head [`3cf3ebb4`](https://github.com/xcl-dev/xcl/commit/3cf3ebb4cc27f82e5499835427c8229dda988cdb): a repair that resolves the physical destination only when the readback is published also needs to reject a **later page mapping**. The source permits this sequence: a queue submits a GPU write while a GPU-view page shows physical page A; a later `CopyPageMappingsBatchX` makes the same view page show B; then the earlier readback completes. [`mapping_changed`](https://github.com/xcl-dev/xcl/blob/3cf3ebb4cc27f82e5499835427c8229dda988cdb/crates/xcl/src/hle/d3d12x/title_textures.rs#L872-L887) clears `gpu_written` when the mapping call is newer, but leaves `gpu_writers` intact. [`download_writes` and `download_current`](https://github.com/xcl-dev/xcl/blob/3cf3ebb4cc27f82e5499835427c8229dda988cdb/crates/xcl/src/hle/d3d12x/title_textures.rs#L3854-L3880) still accept that writer: the resource generation and raw `entry.src` have not changed. Resolving the destination at publication would therefore write A's GPU result into B's backing page. The publication invariant should include page identity at the writer's queue position, not just resource generation and address. A later A→B remap must not send A's GPU result into B. If A remains live, its earlier write still needs publication to A; that may require taking the readback before the remap changes the resource's tiles. If A merely moves, publication should follow A to its current home. A focused regression should check both physical pages after A→B before fence publication, plus a move of A's backing address without a remap. This is a source-derived schedule; I have not run the new GPU regression. AI use: Codex (GPT-6.2 Sol) traced the mapping and download lifecycle.
BBareth commented 2026-12-01 07:28:42 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by BBareth on 2026-12-01T07:28:42Z.


Thanks for both findings; I checked them against the source and they hold. Head is now 069739d3.

  • Mapped pages: a paged texture's own address is a reserved GPU view, so the skip published the download without writing anything, and current was read from the wrong place too. A paged texture now carries the homes of its pages (kernelx::mirrors::resolve) from prepare_downloads to publish_download; the current bytes are read through them and write_changed_mapped_pages writes each 64 KiB page where it is kept. A page that shows nothing takes no bytes. A page never named goes to the CPU view, where the reserved-page skip still applies.
  • Later mapping: the homes are resolved again at publication, under the TEXTURES lock, and a page whose home differs from the one at preparation is not written. So A's result cannot reach B.

Limits, also under Not tested in the description:

  • A remap between the GPU write and the preparation of its download is not caught: the homes are taken at preparation, not at the writer's queue position.
  • A page remapped after preparation loses the GPU result at its old home as well; publication does not follow A.
  • The new test a_download_over_mapped_pages_is_written_where_they_are_kept covers the write function on the existing mapped-pool fixture (pool page written, unmapped page skipped, remapped page left alone). There is no GPU test that drives a paged download through its fence, and no retail run with this part.

Suite on 069739d3: 2891 passed, 0 failed, 51 ignored, 28 SKIPPED lines (as before). The smoke blocks in the description are rerun on this head.

AI use: Claude Code, Claude Fable 5.2 checked both points against the source, wrote the change and this reply, and ran the tests.

<!-- greyfinch-sync:ivall/xcl:comment:7304104167 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3549#issuecomment-7304104167). Originally posted by [BBareth](https://github.com/BBareth) on 2026-12-01T07:28:42Z. --- Thanks for both findings; I checked them against the source and they hold. Head is now 069739d3. - **Mapped pages:** a paged texture's own address is a reserved GPU view, so the skip published the download without writing anything, and `current` was read from the wrong place too. A paged texture now carries the homes of its pages (`kernelx::mirrors::resolve`) from `prepare_downloads` to `publish_download`; the current bytes are read through them and `write_changed_mapped_pages` writes each 64 KiB page where it is kept. A page that shows nothing takes no bytes. A page never named goes to the CPU view, where the reserved-page skip still applies. - **Later mapping:** the homes are resolved again at publication, under the `TEXTURES` lock, and a page whose home differs from the one at preparation is not written. So A's result cannot reach B. Limits, also under **Not tested** in the description: - A remap between the GPU write and the preparation of its download is not caught: the homes are taken at preparation, not at the writer's queue position. - A page remapped after preparation loses the GPU result at its old home as well; publication does not follow A. - The new test `a_download_over_mapped_pages_is_written_where_they_are_kept` covers the write function on the existing mapped-pool fixture (pool page written, unmapped page skipped, remapped page left alone). There is no GPU test that drives a paged download through its fence, and no retail run with this part. Suite on 069739d3: 2891 passed, 0 failed, 51 ignored, 28 SKIPPED lines (as before). The smoke blocks in the description are rerun on this head. AI use: Claude Code, Claude Fable 5.2 checked both points against the source, wrote the change and this reply, and ran the tests.
Foniass commented 2026-12-01 08:14:28 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T08:14:28Z.


merge-check
base: 7d86c5d2b7
head: 069739d3b7
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2898 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: re-reviewed at 069739d3 (one squashed commit, +86 since 3cf3ebb4). A paged texture now records where each of its pages is kept (mapped_homes) when the download is prepared (prepare_downloads ~3895), and on publish reads through that page table and writes with the new write_changed_mapped_pages (~4118), skipping pages that are unmapped or mapped elsewhere since preparation; this fixes my earlier point about paged targets falling back to the GPU-view address. Findings: (1) a page remapped after preparation loses the GPU's bytes at its old page too, and the fence is still published (~4010, ~4129); the PR lists this under Not tested. (2) Skipped and remapped pages are still dropped without a log line. (3) The comment at ~4052 still says every changed page must be committed. Fine: paged downloads are read and written through the same page table uploads use, bit-0 entries (pages the title never mapped) go to the CPU view, the page lookups under TEXTURES take locks in the order the upload code already uses, a skipped region can't loop, read-only and guard pages still fail closed, and the new tests follow the existing patterns.
performance: 60 s smoke of a retail title, main 7d86c5d2 vs this merge (d7c56bde): 1663 -> 1684 frames shown (101 %; last presents per 2 s: 60 60 61), peak commit 17153 -> 17213 MB, 0 device removals, 0 crashes.
verdict: safe to merge (a one-time log for skipped or remapped pages, and fixing the stale comment, would make it easier to follow)
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.

<!-- greyfinch-sync:ivall/xcl:comment:7305057242 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3549#issuecomment-7305057242). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T08:14:28Z. --- merge-check base: 7d86c5d2b7845695031eeea1327aa81b6c439323 head: 069739d3b730cbc493329432c2dea3b76038cf2c merge: clean build: cargo build --workspace -> ok tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2898 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: re-reviewed at 069739d3 (one squashed commit, +86 since 3cf3ebb4). A paged texture now records where each of its pages is kept (`mapped_homes`) when the download is prepared (`prepare_downloads` ~3895), and on publish reads through that page table and writes with the new `write_changed_mapped_pages` (~4118), skipping pages that are unmapped or mapped elsewhere since preparation; this fixes my earlier point about paged targets falling back to the GPU-view address. Findings: (1) a page remapped after preparation loses the GPU's bytes at its old page too, and the fence is still published (~4010, ~4129); the PR lists this under Not tested. (2) Skipped and remapped pages are still dropped without a log line. (3) The comment at ~4052 still says every changed page must be committed. Fine: paged downloads are read and written through the same page table uploads use, bit-0 entries (pages the title never mapped) go to the CPU view, the page lookups under `TEXTURES` take locks in the order the upload code already uses, a skipped region can't loop, read-only and guard pages still fail closed, and the new tests follow the existing patterns. performance: 60 s smoke of a retail title, main 7d86c5d2 vs this merge (d7c56bde): 1663 -> 1684 frames shown (101 %; last presents per 2 s: 60 60 61), peak commit 17153 -> 17213 MB, 0 device removals, 0 crashes. verdict: safe to merge (a one-time log for skipped or remapped pages, and fixing the stale comment, would make it easier to follow) 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.
Gevroska commented 2026-12-01 08:27:51 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Gevroska on 2026-12-01T08:27:51Z.


I finished the Windows WARP comparison I mentioned above, using the same two-page texture download on parent ff0c364b and PR revision 3cf3ebb4. I kept the first page writable and the second page reserved throughout the test.

While readback was pending, the native fence was 11 and the title-facing fence stayed at 10 on both revisions. Once readback completed, all 4,096 bytes on the writable page matched on both. The difference was the title-facing fence: it stayed at 10 on the parent and advanced to 11 on 3cf3ebb4 while the second page was still reserved. In the fully committed control, both revisions copied all 8,192 bytes correctly and advanced the fence to 11.

This verifies the mixed-page fix in the synchronous fence-refresh path on WARP. The PR has since advanced to 069739d3, which I haven’t tested.

AI disclosure — Codex GPT-6.2 Sol ran the comparison. A separate GPT-6.2 Sol agent verified the test source and original run logs. GPT-6.2 Astra drafted this comment.

I reviewed and approved this comment before posting.

<!-- greyfinch-sync:ivall/xcl:comment:7305351082 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3549#issuecomment-7305351082). Originally posted by [Gevroska](https://github.com/Gevroska) on 2026-12-01T08:27:51Z. --- I finished the Windows WARP comparison I mentioned above, using the same two-page texture download on parent `ff0c364b` and PR revision `3cf3ebb4`. I kept the first page writable and the second page reserved throughout the test. While readback was pending, the native fence was `11` and the title-facing fence stayed at `10` on both revisions. Once readback completed, all 4,096 bytes on the writable page matched on both. The difference was the title-facing fence: **it stayed at `10` on the parent and advanced to `11` on `3cf3ebb4` while the second page was still reserved.** In the fully committed control, both revisions copied all 8,192 bytes correctly and advanced the fence to `11`. This verifies the mixed-page fix in the synchronous fence-refresh path on WARP. The PR has since advanced to `069739d3`, which I haven’t tested. AI disclosure — Codex GPT-6.2 Sol ran the comparison. A separate GPT-6.2 Sol agent verified the test source and original run logs. GPT-6.2 Astra drafted this comment. I reviewed and approved this comment before posting.
BBareth commented 2026-12-01 09:39:35 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by BBareth on 2026-12-01T09:39:35Z.


Follow-up to the merge check above, head a615e1b1: the two optional points are in.

  • A page a download leaves out is logged now (D3D12.X: a texture download left out a page at ... (not committed | mapped elsewhere since; N so far)), for the first two and then at powers of two.
  • The comment on write_changed_pages no longer says every changed page must be committed.

No other change. Suite on a615e1b1: 2891 passed, 0 failed, 51 ignored, 28 SKIPPED lines. The smoke blocks in the description are rerun on this head (the 120 s run logged no such line).

AI use: Claude Code, Claude Fable 5.2 wrote the change and this comment and ran the tests.

<!-- greyfinch-sync:ivall/xcl:comment:7307019421 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3549#issuecomment-7307019421). Originally posted by [BBareth](https://github.com/BBareth) on 2026-12-01T09:39:35Z. --- Follow-up to the merge check above, head a615e1b1: the two optional points are in. - A page a download leaves out is logged now (`D3D12.X: a texture download left out a page at ... (not committed | mapped elsewhere since; N so far)`), for the first two and then at powers of two. - The comment on `write_changed_pages` no longer says every changed page must be committed. No other change. Suite on a615e1b1: 2891 passed, 0 failed, 51 ignored, 28 SKIPPED lines. The smoke blocks in the description are rerun on this head (the 120 s run logged no such line). AI use: Claude Code, Claude Fable 5.2 wrote the change and this comment and ran the tests.
Foniass commented 2026-12-01 09:41:35 +00:00 (Migrated from github.com)

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


Re-review (head a615e1b1; the range-diff from 069739d3, which I merge-checked, read). Both suggestions are in. A page left out is now logged, the first two and then at powers of two (note_download_page_left_out), for "not committed" and "mapped elsewhere since". The doc comment of write_changed_pages now says only committed pages must be writable. The branch restructuring in the mirror loop is equivalent to before apart from the log call, so my earlier merge-check (suite and smoke on 069739d3) still describes this head.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7307067342 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3549#issuecomment-7307067342). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T09:41:35Z. --- Re-review (head a615e1b1; the range-diff from 069739d3, which I merge-checked, read). Both suggestions are in. A page left out is now logged, the first two and then at powers of two (`note_download_page_left_out`), for "not committed" and "mapped elsewhere since". The doc comment of `write_changed_pages` now says only committed pages must be writable. The branch restructuring in the mirror loop is equivalent to before apart from the log call, so my earlier merge-check (suite and smoke on 069739d3) still describes this head. AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Foniass commented 2026-12-01 10:12:26 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T10:12:26Z.


Triage (#1607) – head c3a9139

No open or merged PR makes the same change.
write_changed_pages now skips only plain reservations: a reserved page marked by kernelx::lazy is committed with lazy::ensure and then written (c3a91393), and write_changed_pages_commits_a_lazy_page_and_writes_it covers it.
The PR also does two things (the reserved-page skip and the paged-texture download), and #3550's new test builds a ReadyDownload without the pages field this adds, so whichever lands second needs an update.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

<!-- greyfinch-sync:ivall/xcl:comment:7307833130 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3549#issuecomment-7307833130). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T10:12:26Z. --- **Triage (#1607)** – head c3a9139 No open or merged PR makes the same change. `write_changed_pages` now skips only plain reservations: a reserved page marked by `kernelx::lazy` is committed with `lazy::ensure` and then written (c3a91393), and `write_changed_pages_commits_a_lazy_page_and_writes_it` covers it. The PR also does two things (the reserved-page skip and the paged-texture download), and #3550's new test builds a `ReadyDownload` without the `pages` field this adds, so whichever lands second needs an update. Recommendation: keep open. AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
BBareth commented 2026-12-01 10:44:58 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by BBareth on 2026-12-01T10:44:58Z.


On the triage note above (lazy pages): confirmed in the source, and fixed in c3a91393.

A mapped physical page that is still zero stays MEM_RESERVE until its first use (kernelx::lazy), and the title can read it, so the skip dropped the GPU's bytes for it. write_changed_pages now calls kernelx::lazy::ensure on a reserved run before it decides to skip, as cpu_writes and DirectStorage do before their writes: a lazy page is committed and written, a plain reservation is still left out. New test write_changed_pages_commits_a_lazy_page_and_writes_it.

On the two other points: the PR does carry two things since the review (the reserved-page skip and the paged-texture download); they are the same refusal in publish_download and I kept them together, but I can split them if the maintainer prefers. And yes, whichever of this and #3550 merges second needs the pages field in that test's ReadyDownload; I will rebase the second one.

Suite on c3a91393: 2892 passed, 0 failed, 51 ignored, 28 SKIPPED lines. The smoke blocks in the description are rerun on this head.

AI use: Claude Code, Claude Fable 5.2 checked the point against the source, wrote the change and this comment and ran the tests.

<!-- greyfinch-sync:ivall/xcl:comment:7308657302 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3549#issuecomment-7308657302). Originally posted by [BBareth](https://github.com/BBareth) on 2026-12-01T10:44:58Z. --- On the triage note above (lazy pages): confirmed in the source, and fixed in c3a91393. A mapped physical page that is still zero stays `MEM_RESERVE` until its first use (`kernelx::lazy`), and the title can read it, so the skip dropped the GPU's bytes for it. `write_changed_pages` now calls `kernelx::lazy::ensure` on a reserved run before it decides to skip, as `cpu_writes` and DirectStorage do before their writes: a lazy page is committed and written, a plain reservation is still left out. New test `write_changed_pages_commits_a_lazy_page_and_writes_it`. On the two other points: the PR does carry two things since the review (the reserved-page skip and the paged-texture download); they are the same refusal in `publish_download` and I kept them together, but I can split them if the maintainer prefers. And yes, whichever of this and #3550 merges second needs the `pages` field in that test's `ReadyDownload`; I will rebase the second one. Suite on c3a91393: 2892 passed, 0 failed, 51 ignored, 28 SKIPPED lines. The smoke blocks in the description are rerun on this head. AI use: Claude Code, Claude Fable 5.2 checked the point against the source, wrote the change and this comment and ran the tests.
Foniass commented 2026-12-01 11:52:36 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T11:52:36Z.


merge-check
base: 493dbd3dd0
head: c3a91393d3
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: re-check of the new head (the 34-line diff from a615e1b1 read; my merge-check of 069739d3 covers the rest). A page VirtualQuery reports as reserved is now first offered to kernelx::lazy::ensure for the rest of its changed run, then queried again (title_textures.rs ~4076-4081). A mapped physical page that is only reserved until its first use is committed and written, and a plain reservation is still left out. Findings: none blocking. The address >= ensured guard means ensure runs at most once per run, so a reservation that ensure doesn't commit falls through to the skip branch rather than looping. Minor: it costs one more VirtualQuery per lazy run on the download path. Fine: the new test builds a committed, a lazy and a plain-reserved page side by side and checks that the first two get the GPU's bytes while the third stays reserved; it fails without the change (the lazy page was skipped).
performance: 60 s smoke of a retail title, main 493dbd3d vs this merge (41403968): 1670 -> 1679 frames shown (100 %; last presents per 2 s: 60 60 60), peak commit 17083 -> 17313 MB, 0 device removals, 0 crashes.
verdict: safe to merge
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.

<!-- greyfinch-sync:ivall/xcl:comment:7310282955 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3549#issuecomment-7310282955). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T11:52:36Z. --- merge-check base: 493dbd3dd0cd50b4c3e8d28f73ab9b504fcd8158 head: c3a91393d380d1f6b1741b6f740a02e1b2a53f36 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: re-check of the new head (the 34-line diff from a615e1b1 read; my merge-check of 069739d3 covers the rest). A page `VirtualQuery` reports as reserved is now first offered to `kernelx::lazy::ensure` for the rest of its changed run, then queried again (`title_textures.rs` ~4076-4081). A mapped physical page that is only reserved until its first use is committed and written, and a plain reservation is still left out. Findings: none blocking. The `address >= ensured` guard means `ensure` runs at most once per run, so a reservation that `ensure` doesn't commit falls through to the skip branch rather than looping. Minor: it costs one more `VirtualQuery` per lazy run on the download path. Fine: the new test builds a committed, a lazy and a plain-reserved page side by side and checks that the first two get the GPU's bytes while the third stays reserved; it fails without the change (the lazy page was skipped). performance: 60 s smoke of a retail title, main 493dbd3d vs this merge (41403968): 1670 -> 1679 frames shown (100 %; last presents per 2 s: 60 60 60), peak commit 17083 -> 17313 MB, 0 device removals, 0 crashes. verdict: safe to merge 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.
gut0to commented 2026-12-01 15:03:14 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by gut0to on 2026-12-01T15:03:14Z.

Code review location: crates/xcl/src/hle/d3d12x/title_textures.rs; line 4007

@@ -3997,7 +4006,11 @@ fn publish_download(download: &ReadyDownload) -> Result<bool, String> {
     let mut table = TEXTURES.lock().unwrap();
     let Some(entry) = table.by_res.get_mut(&download.res) else { return Ok(true) };

Could the mapping identity stay protected through these writes, or be revalidated under the same synchronization immediately before each write? mapped_homes() calls mirrors::resolve(), which returns a snapshot after releasing the page-map locks; apply_batches() can change the mappings afterward. If it remaps a GPU-view page after now is collected but before this loop writes the captured homes address, the stale download can write into a physical page whose mapping/ownership has since changed. Comparing against now closes changes that happened before the snapshot but leaves this check-to-write window. Please serialize the write with mapping updates or add a per-page revalidation that cannot race.

<!-- greyfinch-sync:ivall/xcl:review-comment:4756136311 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3549#discussion_r4756136311). Originally posted by [gut0to](https://github.com/gut0to) on 2026-12-01T15:03:14Z. **Code review location:** `crates/xcl/src/hle/d3d12x/title_textures.rs`; line 4007 ~~~~diff @@ -3997,7 +4006,11 @@ fn publish_download(download: &ReadyDownload) -> Result<bool, String> { let mut table = TEXTURES.lock().unwrap(); let Some(entry) = table.by_res.get_mut(&download.res) else { return Ok(true) }; ~~~~ --- Could the mapping identity stay protected through these writes, or be revalidated under the same synchronization immediately before each write? `mapped_homes()` calls `mirrors::resolve()`, which returns a snapshot after releasing the page-map locks; `apply_batches()` can change the mappings afterward. If it remaps a GPU-view page after `now` is collected but before this loop writes the captured `homes` address, the stale download can write into a physical page whose mapping/ownership has since changed. Comparing against `now` closes changes that happened before the snapshot but leaves this check-to-write window. Please serialize the write with mapping updates or add a per-page revalidation that cannot race.
gut0to commented 2026-12-01 15:03:14 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by gut0to on 2026-12-01T15:03:14Z.

Review: COMMENTED


AI-assisted review: I traced the texture-download publication path and the page-mapping update path in the current head. I used AI assistance; I did not run a concurrency test.

<!-- greyfinch-sync:ivall/xcl:review:6133917015 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3549#pullrequestreview-6133917015). Originally posted by [gut0to](https://github.com/gut0to) on 2026-12-01T15:03:14Z. **Review:** COMMENTED --- AI-assisted review: I traced the texture-download publication path and the page-mapping update path in the current head. I used AI assistance; I did not run a concurrency test.
bmjask commented 2026-12-02 13:14:25 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T13:14:25Z.

Code review location: crates/xcl/src/hle/d3d12x/title_textures.rs; line 4010

@@ -3997,7 +4006,11 @@ fn publish_download(download: &ReadyDownload) -> Result<bool, String> {
     let mut table = TEXTURES.lock().unwrap();
     let Some(entry) = table.by_res.get_mut(&download.res) else { return Ok(true) };
     if !download_current(entry, download.generation, download.target, &download.writes) { return Ok(true) }
-    if !unsafe { write_changed_pages(download.target, &current, &console) } { return Ok(false) }
+    let written = match &download.pages {
+        Some(homes) => unsafe { write_changed_mapped_pages(download.target, homes, &mapped_homes(download.target, size).unwrap_or_default(), &current, &console) },

High: mapped_homes(...).unwrap_or_default() turns "no table now" into an empty now, so write_changed_mapped_pages treats every page as "mapped elsewhere since", including never-named (bit 0) pages that still go to the CPU view. It skips them all and returns true. Suppose the download is prepared while the entry is paged, and before publish resolve returns None for the range (e.g. recheck_source flipped the entry to paged=false with src unchanged because mirror_source(va)==va, or the record's pages went). download_current only checks generation/src/writers, so it passes, now is [], and the result is Ok(true). The title's fence is published with none of the GPU's bytes written anywhere. Before this PR this case failed and retried. Treating a missing table as "not current" (retry) would keep it failing closed.

<!-- greyfinch-sync:ivall/xcl:review-comment:4770076002 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3549#discussion_r4770076002). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T13:14:25Z. **Code review location:** `crates/xcl/src/hle/d3d12x/title_textures.rs`; line 4010 ~~~~diff @@ -3997,7 +4006,11 @@ fn publish_download(download: &ReadyDownload) -> Result<bool, String> { let mut table = TEXTURES.lock().unwrap(); let Some(entry) = table.by_res.get_mut(&download.res) else { return Ok(true) }; if !download_current(entry, download.generation, download.target, &download.writes) { return Ok(true) } - if !unsafe { write_changed_pages(download.target, &current, &console) } { return Ok(false) } + let written = match &download.pages { + Some(homes) => unsafe { write_changed_mapped_pages(download.target, homes, &mapped_homes(download.target, size).unwrap_or_default(), &current, &console) }, ~~~~ --- **High**: `mapped_homes(...).unwrap_or_default()` turns "no table now" into an empty `now`, so `write_changed_mapped_pages` treats every page as "mapped elsewhere since", including never-named (bit 0) pages that still go to the CPU view. It skips them all and returns true. Suppose the download is prepared while the entry is paged, and before publish `resolve` returns None for the range (e.g. `recheck_source` flipped the entry to `paged=false` with `src` unchanged because `mirror_source(va)==va`, or the record's pages went). `download_current` only checks generation/src/writers, so it passes, `now` is `[]`, and the result is Ok(true). The title's fence is published with none of the GPU's bytes written anywhere. Before this PR this case failed and retried. Treating a missing table as "not current" (retry) would keep it failing closed.
bmjask commented 2026-12-02 13:14:25 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T13:14:25Z.

Code review location: crates/xcl/src/hle/d3d12x/title_textures.rs; line 4151

@@ -4079,6 +4114,48 @@ unsafe fn write_changed_pages(at: usize, old: &[u8], new: &[u8]) -> bool {
     true
 }
 
+/// A download left bytes out at `at` (`why`): logged for the first two and then at powers of two.
+fn note_download_page_left_out(why: &str, at: usize) {
+    static N: AtomicU64 = AtomicU64::new(0);
+    let n = N.fetch_add(1, Ordering::Relaxed) + 1;
+    if n <= 2 || n.is_power_of_two() {
+        crate::xlog_info!("D3D12.X: a texture download left out a page at {at:#x} ({why}; {n} so far)");
+    }
+}
+
+/// Where each 64 KiB page of `[va, va + size)` is kept (`kernelx::mirrors::resolve`); None when
+/// the title mapped none of them.
+fn mapped_homes(va: usize, size: usize) -> Option<Vec<usize>> {
+    let mut at = Vec::new();
+    crate::hle::kernelx::mirrors::resolve(va, size, &mut at)?;
+    Some(at)
+}
+
+/// `write_changed_pages` for a texture at `at` over pages the title mapped: each 64 KiB page is
+/// written where it is kept (`was`, the homes when the download was prepared). A page that shows
+/// nothing takes no bytes, and neither does one whose home is another by `now`: the GPU wrote
+/// what the earlier mapping showed, and those bytes must not reach the page mapped since.
+unsafe fn write_changed_mapped_pages(at: usize, was: &[usize], now: &[usize], old: &[u8], new: &[u8]) -> bool {
+    const PAGE: usize = crate::hle::kernelx::mirrors::PAGE;
+    if old.len() != new.len() { return false }
+    let first = at & !(PAGE - 1);
+    let mut done = 0;
+    while done < new.len() {
+        let a = at + done;
+        let (k, off) = ((a - first) / PAGE, a & (PAGE - 1));
+        let n = (PAGE - off).min(new.len() - done);
+        let home = was.get(k).copied().unwrap_or(0);
+        // (bit 0: a page never named, kept at the CPU view's same offset)
+        if home != 0 && now.get(k) != Some(&home) {
+            note_download_page_left_out("mapped elsewhere since", a);
+        } else if home != 0 && !write_changed_pages((home & !1) + off, &old[done..done + n], &new[done..done + n]) {

High: When several GPU-view pages share one home (range kind 1: pool page start at each of count pages), each is written from its own stale old slice, and only bytes that differ from that stale copy are written, so the pool page ends up mixing several pages' GPU data. If view pages 0 and 1 both map pool page P, current read P for both before any write. Page 0's write changes P. For page 1, the bytes where new1 == old (P as it was before page 0's write) are left as page 0's bytes, so P holds neither page's result. Writing each home once, from the last view page that maps it (or comparing against the live bytes), would avoid the mix.

<!-- greyfinch-sync:ivall/xcl:review-comment:4770076017 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3549#discussion_r4770076017). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T13:14:25Z. **Code review location:** `crates/xcl/src/hle/d3d12x/title_textures.rs`; line 4151 ~~~~diff @@ -4079,6 +4114,48 @@ unsafe fn write_changed_pages(at: usize, old: &[u8], new: &[u8]) -> bool { true } +/// A download left bytes out at `at` (`why`): logged for the first two and then at powers of two. +fn note_download_page_left_out(why: &str, at: usize) { + static N: AtomicU64 = AtomicU64::new(0); + let n = N.fetch_add(1, Ordering::Relaxed) + 1; + if n <= 2 || n.is_power_of_two() { + crate::xlog_info!("D3D12.X: a texture download left out a page at {at:#x} ({why}; {n} so far)"); + } +} + +/// Where each 64 KiB page of `[va, va + size)` is kept (`kernelx::mirrors::resolve`); None when +/// the title mapped none of them. +fn mapped_homes(va: usize, size: usize) -> Option<Vec<usize>> { + let mut at = Vec::new(); + crate::hle::kernelx::mirrors::resolve(va, size, &mut at)?; + Some(at) +} + +/// `write_changed_pages` for a texture at `at` over pages the title mapped: each 64 KiB page is +/// written where it is kept (`was`, the homes when the download was prepared). A page that shows +/// nothing takes no bytes, and neither does one whose home is another by `now`: the GPU wrote +/// what the earlier mapping showed, and those bytes must not reach the page mapped since. +unsafe fn write_changed_mapped_pages(at: usize, was: &[usize], now: &[usize], old: &[u8], new: &[u8]) -> bool { + const PAGE: usize = crate::hle::kernelx::mirrors::PAGE; + if old.len() != new.len() { return false } + let first = at & !(PAGE - 1); + let mut done = 0; + while done < new.len() { + let a = at + done; + let (k, off) = ((a - first) / PAGE, a & (PAGE - 1)); + let n = (PAGE - off).min(new.len() - done); + let home = was.get(k).copied().unwrap_or(0); + // (bit 0: a page never named, kept at the CPU view's same offset) + if home != 0 && now.get(k) != Some(&home) { + note_download_page_left_out("mapped elsewhere since", a); + } else if home != 0 && !write_changed_pages((home & !1) + off, &old[done..done + n], &new[done..done + n]) { ~~~~ --- **High**: When several GPU-view pages share one home (range kind 1: pool page `start` at each of `count` pages), each is written from its own stale `old` slice, and only bytes that differ from that stale copy are written, so the pool page ends up mixing several pages' GPU data. If view pages 0 and 1 both map pool page P, `current` read P for both before any write. Page 0's write changes P. For page 1, the bytes where new1 == old (P as it was before page 0's write) are left as page 0's bytes, so P holds neither page's result. Writing each home once, from the last view page that maps it (or comparing against the live bytes), would avoid the mix.
bmjask commented 2026-12-02 13:14:25 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T13:14:25Z.

Code review location: crates/xcl/src/hle/d3d12x/title_textures.rs; line 4082

@@ -4036,24 +4049,46 @@ fn changed_page_runs(at: usize, old: &[u8], new: &[u8]) -> Vec<(usize, usize)> {
     runs
 }
 
-/// Write changed 4 KiB pages without faulting if the title concurrently unmaps one. Every
-/// changed page must be committed and writable; otherwise its fence remains hidden and retries.
+/// Write changed 4 KiB pages without faulting if the title concurrently unmaps one. A changed
+/// page that is committed must be writable; otherwise its fence remains hidden and retries.
+/// A page the title has not committed (reserved or free) is left out: the title cannot read it, and
+/// waiting for it held the fence back for good (a retail game's frame-pacing wait then never ended).
+/// A mapped physical page that is only reserved until its first use (`kernelx::lazy`) is one the
+/// title can read: it is committed first and written.
 /// Contiguous changed pages within a VM region are coalesced into one `WriteProcessMemory` call
 /// so publishing large GPU-written textures does not pay a per-4 KiB syscall and instruction-cache
 /// flush while holding `TEXTURES`.
 unsafe fn write_changed_pages(at: usize, old: &[u8], new: &[u8]) -> bool {
     use windows_sys::Win32::System::Diagnostics::Debug::WriteProcessMemory;
-    use windows_sys::Win32::System::Memory::{VirtualQuery, MEMORY_BASIC_INFORMATION, MEM_COMMIT, PAGE_GUARD};
+    use windows_sys::Win32::System::Memory::{VirtualQuery, MEMORY_BASIC_INFORMATION, MEM_COMMIT, MEM_FREE, MEM_RESERVE, PAGE_GUARD};
     use windows_sys::Win32::System::Threading::GetCurrentProcess;
     if old.len() != new.len() { return false }
     let proc = GetCurrentProcess();
     let mut region_end = 0usize;
+    // the end of the addresses whose lazy pages were committed already
+    let mut ensured = 0usize;
     for (mut offset, run_end) in changed_page_runs(at, old, new) {
         while offset < run_end {
             let Some(address) = at.checked_add(offset) else { return false };
             if address >= region_end {
                 let mut info: MEMORY_BASIC_INFORMATION = std::mem::zeroed();
-                if VirtualQuery(address as *const c_void, &mut info, std::mem::size_of_val(&info)) == 0
+                let queried = VirtualQuery(address as *const c_void, &mut info, std::mem::size_of_val(&info)) != 0;
+                if queried && info.State == MEM_RESERVE && address >= ensured {
+                    // (a kernel call does not fault a lazy page in: commit those of the run, ask again)
+                    ensured = at.saturating_add(run_end);
+                    crate::hle::kernelx::lazy::ensure(address, ensured - address);
+                    continue;
+                }
+                if queried && (info.State == MEM_RESERVE || info.State == MEM_FREE) {

Medium: Pages in MEM_RESERVE/MEM_FREE are now skipped for good where they used to fail and retry, so a page the title is committing at that moment loses the GPU result permanently. If the title thread is in VirtualAlloc(MEM_COMMIT) on a texture page the GPU just wrote, the poller's VirtualQuery sees MEM_RESERVE, skips the page and publishes the fence, and the title then reads the newly committed page as zeros instead of the GPU output. Before, the next retry would have written it.

<!-- greyfinch-sync:ivall/xcl:review-comment:4770076032 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3549#discussion_r4770076032). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T13:14:25Z. **Code review location:** `crates/xcl/src/hle/d3d12x/title_textures.rs`; line 4082 ~~~~diff @@ -4036,24 +4049,46 @@ fn changed_page_runs(at: usize, old: &[u8], new: &[u8]) -> Vec<(usize, usize)> { runs } -/// Write changed 4 KiB pages without faulting if the title concurrently unmaps one. Every -/// changed page must be committed and writable; otherwise its fence remains hidden and retries. +/// Write changed 4 KiB pages without faulting if the title concurrently unmaps one. A changed +/// page that is committed must be writable; otherwise its fence remains hidden and retries. +/// A page the title has not committed (reserved or free) is left out: the title cannot read it, and +/// waiting for it held the fence back for good (a retail game's frame-pacing wait then never ended). +/// A mapped physical page that is only reserved until its first use (`kernelx::lazy`) is one the +/// title can read: it is committed first and written. /// Contiguous changed pages within a VM region are coalesced into one `WriteProcessMemory` call /// so publishing large GPU-written textures does not pay a per-4 KiB syscall and instruction-cache /// flush while holding `TEXTURES`. unsafe fn write_changed_pages(at: usize, old: &[u8], new: &[u8]) -> bool { use windows_sys::Win32::System::Diagnostics::Debug::WriteProcessMemory; - use windows_sys::Win32::System::Memory::{VirtualQuery, MEMORY_BASIC_INFORMATION, MEM_COMMIT, PAGE_GUARD}; + use windows_sys::Win32::System::Memory::{VirtualQuery, MEMORY_BASIC_INFORMATION, MEM_COMMIT, MEM_FREE, MEM_RESERVE, PAGE_GUARD}; use windows_sys::Win32::System::Threading::GetCurrentProcess; if old.len() != new.len() { return false } let proc = GetCurrentProcess(); let mut region_end = 0usize; + // the end of the addresses whose lazy pages were committed already + let mut ensured = 0usize; for (mut offset, run_end) in changed_page_runs(at, old, new) { while offset < run_end { let Some(address) = at.checked_add(offset) else { return false }; if address >= region_end { let mut info: MEMORY_BASIC_INFORMATION = std::mem::zeroed(); - if VirtualQuery(address as *const c_void, &mut info, std::mem::size_of_val(&info)) == 0 + let queried = VirtualQuery(address as *const c_void, &mut info, std::mem::size_of_val(&info)) != 0; + if queried && info.State == MEM_RESERVE && address >= ensured { + // (a kernel call does not fault a lazy page in: commit those of the run, ask again) + ensured = at.saturating_add(run_end); + crate::hle::kernelx::lazy::ensure(address, ensured - address); + continue; + } + if queried && (info.State == MEM_RESERVE || info.State == MEM_FREE) { ~~~~ --- **Medium**: Pages in MEM_RESERVE/MEM_FREE are now skipped for good where they used to fail and retry, so a page the title is committing at that moment loses the GPU result permanently. If the title thread is in `VirtualAlloc(MEM_COMMIT)` on a texture page the GPU just wrote, the poller's `VirtualQuery` sees MEM_RESERVE, skips the page and publishes the fence, and the title then reads the newly committed page as zeros instead of the GPU output. Before, the next retry would have written it.
bmjask commented 2026-12-02 13:14:25 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T13:14:25Z.

Code review location: crates/xcl/src/hle/d3d12x/title_textures.rs; line 3895

@@ -3892,7 +3892,7 @@ pub(super) unsafe fn prepare_downloads(queue: *mut c_void) -> PreparedDownloads
             if writes.is_empty() { return None }
             let source = ID3D12Resource::from_raw_borrowed(&(res as *mut c_void))?.clone();
             let device = ID3D12Device::from_raw_borrowed(&(entry.device as *mut c_void))?.clone();
-            Some(DownloadSnapshot { res, generation: entry.generation, target: entry.src, format: source.GetDesc().Format.0 as u32,
+            Some(DownloadSnapshot { res, generation: entry.generation, target: entry.src, pages: if entry.paged { mapped_homes(entry.src, entry.tex.size() as usize) } else { None }, format: source.GetDesc().Format.0 as u32,

Medium: Not certain about this one: for a paged entry where mapped_homes returns None at prepare (e.g. the view's pages were released between touched and resolve), pages falls back to None, so publish reads and writes the GPU-view reservation (NOACCESS/MEM_RESERVE) directly. With the new reserved-page skip, current reads zeros, every changed page is skipped, Ok(true) is returned, and the fence goes up with the download lost, where before it failed closed.

<!-- greyfinch-sync:ivall/xcl:review-comment:4770076047 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3549#discussion_r4770076047). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T13:14:25Z. **Code review location:** `crates/xcl/src/hle/d3d12x/title_textures.rs`; line 3895 ~~~~diff @@ -3892,7 +3892,7 @@ pub(super) unsafe fn prepare_downloads(queue: *mut c_void) -> PreparedDownloads if writes.is_empty() { return None } let source = ID3D12Resource::from_raw_borrowed(&(res as *mut c_void))?.clone(); let device = ID3D12Device::from_raw_borrowed(&(entry.device as *mut c_void))?.clone(); - Some(DownloadSnapshot { res, generation: entry.generation, target: entry.src, format: source.GetDesc().Format.0 as u32, + Some(DownloadSnapshot { res, generation: entry.generation, target: entry.src, pages: if entry.paged { mapped_homes(entry.src, entry.tex.size() as usize) } else { None }, format: source.GetDesc().Format.0 as u32, ~~~~ --- **Medium**: Not certain about this one: for a paged entry where `mapped_homes` returns None at prepare (e.g. the view's pages were released between `touched` and `resolve`), `pages` falls back to None, so publish reads and writes the GPU-view reservation (NOACCESS/MEM_RESERVE) directly. With the new reserved-page skip, `current` reads zeros, every changed page is skipped, Ok(true) is returned, and the fence goes up with the download lost, where before it failed closed.
bmjask commented 2026-12-02 13:14:25 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T13:14:25Z.

Code review location: crates/xcl/src/hle/d3d12x/title_textures.rs; line 4152

@@ -4079,6 +4114,48 @@ unsafe fn write_changed_pages(at: usize, old: &[u8], new: &[u8]) -> bool {
     true
 }
 
+/// A download left bytes out at `at` (`why`): logged for the first two and then at powers of two.
+fn note_download_page_left_out(why: &str, at: usize) {
+    static N: AtomicU64 = AtomicU64::new(0);
+    let n = N.fetch_add(1, Ordering::Relaxed) + 1;
+    if n <= 2 || n.is_power_of_two() {
+        crate::xlog_info!("D3D12.X: a texture download left out a page at {at:#x} ({why}; {n} so far)");
+    }
+}
+
+/// Where each 64 KiB page of `[va, va + size)` is kept (`kernelx::mirrors::resolve`); None when
+/// the title mapped none of them.
+fn mapped_homes(va: usize, size: usize) -> Option<Vec<usize>> {
+    let mut at = Vec::new();
+    crate::hle::kernelx::mirrors::resolve(va, size, &mut at)?;
+    Some(at)
+}
+
+/// `write_changed_pages` for a texture at `at` over pages the title mapped: each 64 KiB page is
+/// written where it is kept (`was`, the homes when the download was prepared). A page that shows
+/// nothing takes no bytes, and neither does one whose home is another by `now`: the GPU wrote
+/// what the earlier mapping showed, and those bytes must not reach the page mapped since.
+unsafe fn write_changed_mapped_pages(at: usize, was: &[usize], now: &[usize], old: &[u8], new: &[u8]) -> bool {
+    const PAGE: usize = crate::hle::kernelx::mirrors::PAGE;
+    if old.len() != new.len() { return false }
+    let first = at & !(PAGE - 1);
+    let mut done = 0;
+    while done < new.len() {
+        let a = at + done;
+        let (k, off) = ((a - first) / PAGE, a & (PAGE - 1));
+        let n = (PAGE - off).min(new.len() - done);
+        let home = was.get(k).copied().unwrap_or(0);
+        // (bit 0: a page never named, kept at the CPU view's same offset)
+        if home != 0 && now.get(k) != Some(&home) {
+            note_download_page_left_out("mapped elsewhere since", a);
+        } else if home != 0 && !write_changed_pages((home & !1) + off, &old[done..done + n], &new[done..done + n]) {
+            return false;

Medium: Not certain about this one: the "mapped elsewhere since" check is a TOCTOU race. now is computed once, then the writes run without holding the mirrors/pages lock. If publish computes now == was for page k and another thread's CopyPageMappingsBatchX then remaps pool page P to a different GPU-view page, write_changed_pages(P+off) writes the old texture's GPU bytes into P, which now backs another resource. That's the corruption the function's doc says it prevents.

<!-- greyfinch-sync:ivall/xcl:review-comment:4770076063 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3549#discussion_r4770076063). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T13:14:25Z. **Code review location:** `crates/xcl/src/hle/d3d12x/title_textures.rs`; line 4152 ~~~~diff @@ -4079,6 +4114,48 @@ unsafe fn write_changed_pages(at: usize, old: &[u8], new: &[u8]) -> bool { true } +/// A download left bytes out at `at` (`why`): logged for the first two and then at powers of two. +fn note_download_page_left_out(why: &str, at: usize) { + static N: AtomicU64 = AtomicU64::new(0); + let n = N.fetch_add(1, Ordering::Relaxed) + 1; + if n <= 2 || n.is_power_of_two() { + crate::xlog_info!("D3D12.X: a texture download left out a page at {at:#x} ({why}; {n} so far)"); + } +} + +/// Where each 64 KiB page of `[va, va + size)` is kept (`kernelx::mirrors::resolve`); None when +/// the title mapped none of them. +fn mapped_homes(va: usize, size: usize) -> Option<Vec<usize>> { + let mut at = Vec::new(); + crate::hle::kernelx::mirrors::resolve(va, size, &mut at)?; + Some(at) +} + +/// `write_changed_pages` for a texture at `at` over pages the title mapped: each 64 KiB page is +/// written where it is kept (`was`, the homes when the download was prepared). A page that shows +/// nothing takes no bytes, and neither does one whose home is another by `now`: the GPU wrote +/// what the earlier mapping showed, and those bytes must not reach the page mapped since. +unsafe fn write_changed_mapped_pages(at: usize, was: &[usize], now: &[usize], old: &[u8], new: &[u8]) -> bool { + const PAGE: usize = crate::hle::kernelx::mirrors::PAGE; + if old.len() != new.len() { return false } + let first = at & !(PAGE - 1); + let mut done = 0; + while done < new.len() { + let a = at + done; + let (k, off) = ((a - first) / PAGE, a & (PAGE - 1)); + let n = (PAGE - off).min(new.len() - done); + let home = was.get(k).copied().unwrap_or(0); + // (bit 0: a page never named, kept at the CPU view's same offset) + if home != 0 && now.get(k) != Some(&home) { + note_download_page_left_out("mapped elsewhere since", a); + } else if home != 0 && !write_changed_pages((home & !1) + off, &old[done..done + n], &new[done..done + n]) { + return false; ~~~~ --- **Medium**: Not certain about this one: the "mapped elsewhere since" check is a TOCTOU race. `now` is computed once, then the writes run without holding the mirrors/pages lock. If publish computes `now == was` for page k and another thread's `CopyPageMappingsBatchX` then remaps pool page P to a different GPU-view page, `write_changed_pages(P+off)` writes the old texture's GPU bytes into P, which now backs another resource. That's the corruption the function's doc says it prevents.
bmjask commented 2026-12-02 13:14:25 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T13:14:25Z.

Review: COMMENTED


Review of c3a91393: 6 finding(s) (3 high, 3 medium), most severe first.

  1. High crates/xcl/src/hle/d3d12x/title_textures.rs:4010: mapped_homes(...).unwrap_or_default() turns "no table now" into an empty now, so write_changed_mapped_pages treats every page as "mapped elsewhere since", including never-named (bit 0) pages that still go to the CPU view. (inline)
  2. High crates/xcl/src/hle/d3d12x/title_textures.rs:4151: When several GPU-view pages share one home (range kind 1: pool page start at each of count pages), each is written from its own stale old slice, and only bytes that differ from that stale copy are written, so the pool page ends up mixing several pages' GPU data. (inline)
  3. High crates/xcl/src/hle/d3d12x/title_textures.rs:3877: see below.
  4. Medium crates/xcl/src/hle/d3d12x/title_textures.rs:4082: Pages in MEM_RESERVE/MEM_FREE are now skipped for good where they used to fail and retry, so a page the title is committing at that moment loses the GPU result permanently. (inline)
  5. Medium crates/xcl/src/hle/d3d12x/title_textures.rs:3895: Not certain about this one: for a paged entry where mapped_homes returns None at prepare (e.g. (inline)
  6. Medium crates/xcl/src/hle/d3d12x/title_textures.rs:4152: Not certain about this one: the "mapped elsewhere since" check is a TOCTOU race. (inline)

On lines outside the diff:

  1. High crates/xcl/src/hle/d3d12x/title_textures.rs:3877: Not certain about this one: download_current and the submit_prepared_downloads check never compare entry.paged or the page table with the snapshot, so a download prepared with one way of reaching the pages can be published with the other. Prepare runs with paged=false (pages=None). Then CopyPageMappingsBatchX touches the view and recheck_source sets paged=true without bumping the generation (src stays va). Publish writes through write_changed_pages(va): reserved GPU-view pages are now silently skipped instead of failing, the pool pages the texture really reads never get the GPU result, and the fence is released.

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:6151444046 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3549#pullrequestreview-6151444046). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T13:14:25Z. **Review:** COMMENTED --- Review of `c3a91393`: 6 finding(s) (3 high, 3 medium), most severe first. 1. **High** `crates/xcl/src/hle/d3d12x/title_textures.rs:4010`: `mapped_homes(...).unwrap_or_default()` turns "no table now" into an empty `now`, so `write_changed_mapped_pages` treats every page as "mapped elsewhere since", including never-named (bit 0) pages that still go to the CPU view. (inline) 2. **High** `crates/xcl/src/hle/d3d12x/title_textures.rs:4151`: When several GPU-view pages share one home (range kind 1: pool page `start` at each of `count` pages), each is written from its own stale `old` slice, and only bytes that differ from that stale copy are written, so the pool page ends up mixing several pages' GPU data. (inline) 3. **High** `crates/xcl/src/hle/d3d12x/title_textures.rs:3877`: see below. 4. **Medium** `crates/xcl/src/hle/d3d12x/title_textures.rs:4082`: Pages in MEM_RESERVE/MEM_FREE are now skipped for good where they used to fail and retry, so a page the title is committing at that moment loses the GPU result permanently. (inline) 5. **Medium** `crates/xcl/src/hle/d3d12x/title_textures.rs:3895`: Not certain about this one: for a paged entry where `mapped_homes` returns None at prepare (e.g. (inline) 6. **Medium** `crates/xcl/src/hle/d3d12x/title_textures.rs:4152`: Not certain about this one: the "mapped elsewhere since" check is a TOCTOU race. (inline) **On lines outside the diff:** 3. **High** `crates/xcl/src/hle/d3d12x/title_textures.rs:3877`: Not certain about this one: `download_current` and the `submit_prepared_downloads` check never compare `entry.paged` or the page table with the snapshot, so a download prepared with one way of reaching the pages can be published with the other. Prepare runs with `paged=false` (`pages=None`). Then `CopyPageMappingsBatchX` touches the view and `recheck_source` sets `paged=true` without bumping the generation (src stays va). Publish writes through `write_changed_pages(va)`: reserved GPU-view pages are now silently skipped instead of failing, the pool pages the texture really reads never get the GPU result, and the fence is released. --- _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 14:11:28 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T14:11:28Z.


@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:7348135972 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3549#issuecomment-7348135972). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T14:11:28Z. --- @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:18 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by ClosetPie107 on 2026-12-02T17:13:18Z.


Linux / AMD RDNA4 (RADV, Wine + vkd3d-proton): full test suite on c3a9139

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 2774 175 52
  • Tests that fail with this PR and pass on main: none.
  • Tests this PR adds: 3 of 3 pass (write_changed_pages_leaves_out_pages_the_title_has_not_committed, write_changed_pages_commits_a_lazy_page_and_writes_it, a_download_over_mapped_pages_is_written_where_they_are_kept).
  • Passing here and failing on main: gpu::recomp::tests::gpu_qsad_and_mqsad, gpu::recomp::tests::gpu_split_wave64_cross_half_operations (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:7353065354 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3549#issuecomment-7353065354). Originally posted by [ClosetPie107](https://github.com/ClosetPie107) on 2026-12-02T17:13:18Z. --- **Linux / AMD RDNA4 (RADV, Wine + vkd3d-proton): full test suite on `c3a9139`** 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 | 2774 | 175 | 52 | - **Tests that fail with this PR and pass on `main`:** none. - **Tests this PR adds:** 3 of 3 pass (`write_changed_pages_leaves_out_pages_the_title_has_not_committed`, `write_changed_pages_commits_a_lazy_page_and_writes_it`, `a_download_over_mapped_pages_is_written_where_they_are_kept`). - Passing here and failing on `main`: `gpu::recomp::tests::gpu_qsad_and_mqsad`, `gpu::recomp::tests::gpu_split_wave64_cross_half_operations` (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.
throny commented 2026-12-03 01:24:06 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by throny on 2026-12-03T01:24:06Z.


Test report (not a merge check): with #3550 on top, main 078358a05 + this PR (c3a91393) ran a 300 s world run of the retail title on an RTX 4080 with no crash, no device removal and no Aftermath dump, 2.90 presents/s. Without this PR, #3550 crashes here about 100 s in. Details on #3550. AI use: Claude Code (Claude Opus 5.5).

<!-- greyfinch-sync:ivall/xcl:comment:7364300836 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3549#issuecomment-7364300836). Originally posted by [throny](https://github.com/throny) on 2026-12-03T01:24:06Z. --- Test report (not a merge check): with #3550 on top, main `078358a05` + this PR (`c3a91393`) ran a 300 s world run of the retail title on an RTX 4080 with no crash, no device removal and no Aftermath dump, 2.90 presents/s. Without this PR, #3550 crashes here about 100 s in. Details on #3550. *AI use: Claude Code (Claude Opus 5.5).*
BBareth commented 2026-12-03 01:35:35 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by BBareth on 2026-12-03T01:35:35Z.

Code review location: crates/xcl/src/hle/d3d12x/title_textures.rs; line 4010

@@ -3997,7 +4006,11 @@ fn publish_download(download: &ReadyDownload) -> Result<bool, String> {
     let mut table = TEXTURES.lock().unwrap();
     let Some(entry) = table.by_res.get_mut(&download.res) else { return Ok(true) };
     if !download_current(entry, download.generation, download.target, &download.writes) { return Ok(true) }
-    if !unsafe { write_changed_pages(download.target, &current, &console) } { return Ok(false) }
+    let written = match &download.pages {
+        Some(homes) => unsafe { write_changed_mapped_pages(download.target, homes, &mapped_homes(download.target, size).unwrap_or_default(), &current, &console) },

The mapped-page writes (mapped_homes, write_changed_mapped_pages) are no longer in this PR as of fc7abe51; they come back in a separate PR. There a missing table at publication will count as "not current" and retry, as you suggest, instead of treating every page as moved.

<!-- greyfinch-sync:ivall/xcl:review-comment:4778667982 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3549#discussion_r4778667982). Originally posted by [BBareth](https://github.com/BBareth) on 2026-12-03T01:35:35Z. **Code review location:** `crates/xcl/src/hle/d3d12x/title_textures.rs`; line 4010 ~~~~diff @@ -3997,7 +4006,11 @@ fn publish_download(download: &ReadyDownload) -> Result<bool, String> { let mut table = TEXTURES.lock().unwrap(); let Some(entry) = table.by_res.get_mut(&download.res) else { return Ok(true) }; if !download_current(entry, download.generation, download.target, &download.writes) { return Ok(true) } - if !unsafe { write_changed_pages(download.target, &current, &console) } { return Ok(false) } + let written = match &download.pages { + Some(homes) => unsafe { write_changed_mapped_pages(download.target, homes, &mapped_homes(download.target, size).unwrap_or_default(), &current, &console) }, ~~~~ --- The mapped-page writes (`mapped_homes`, `write_changed_mapped_pages`) are no longer in this PR as of fc7abe51; they come back in a separate PR. There a missing table at publication will count as "not current" and retry, as you suggest, instead of treating every page as moved.
BBareth commented 2026-12-03 01:35:37 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by BBareth on 2026-12-03T01:35:37Z.

Code review location: crates/xcl/src/hle/d3d12x/title_textures.rs; line 4151

@@ -4079,6 +4114,48 @@ unsafe fn write_changed_pages(at: usize, old: &[u8], new: &[u8]) -> bool {
     true
 }
 
+/// A download left bytes out at `at` (`why`): logged for the first two and then at powers of two.
+fn note_download_page_left_out(why: &str, at: usize) {
+    static N: AtomicU64 = AtomicU64::new(0);
+    let n = N.fetch_add(1, Ordering::Relaxed) + 1;
+    if n <= 2 || n.is_power_of_two() {
+        crate::xlog_info!("D3D12.X: a texture download left out a page at {at:#x} ({why}; {n} so far)");
+    }
+}
+
+/// Where each 64 KiB page of `[va, va + size)` is kept (`kernelx::mirrors::resolve`); None when
+/// the title mapped none of them.
+fn mapped_homes(va: usize, size: usize) -> Option<Vec<usize>> {
+    let mut at = Vec::new();
+    crate::hle::kernelx::mirrors::resolve(va, size, &mut at)?;
+    Some(at)
+}
+
+/// `write_changed_pages` for a texture at `at` over pages the title mapped: each 64 KiB page is
+/// written where it is kept (`was`, the homes when the download was prepared). A page that shows
+/// nothing takes no bytes, and neither does one whose home is another by `now`: the GPU wrote
+/// what the earlier mapping showed, and those bytes must not reach the page mapped since.
+unsafe fn write_changed_mapped_pages(at: usize, was: &[usize], now: &[usize], old: &[u8], new: &[u8]) -> bool {
+    const PAGE: usize = crate::hle::kernelx::mirrors::PAGE;
+    if old.len() != new.len() { return false }
+    let first = at & !(PAGE - 1);
+    let mut done = 0;
+    while done < new.len() {
+        let a = at + done;
+        let (k, off) = ((a - first) / PAGE, a & (PAGE - 1));
+        let n = (PAGE - off).min(new.len() - done);
+        let home = was.get(k).copied().unwrap_or(0);
+        // (bit 0: a page never named, kept at the CPU view's same offset)
+        if home != 0 && now.get(k) != Some(&home) {
+            note_download_page_left_out("mapped elsewhere since", a);
+        } else if home != 0 && !write_changed_pages((home & !1) + off, &old[done..done + n], &new[done..done + n]) {

The mapped-page writes (mapped_homes, write_changed_mapped_pages) are no longer in this PR as of fc7abe51; they come back in a separate PR. There each home is written once, from the last view page that maps it, compared against its live bytes.

<!-- greyfinch-sync:ivall/xcl:review-comment:4778668189 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3549#discussion_r4778668189). Originally posted by [BBareth](https://github.com/BBareth) on 2026-12-03T01:35:37Z. **Code review location:** `crates/xcl/src/hle/d3d12x/title_textures.rs`; line 4151 ~~~~diff @@ -4079,6 +4114,48 @@ unsafe fn write_changed_pages(at: usize, old: &[u8], new: &[u8]) -> bool { true } +/// A download left bytes out at `at` (`why`): logged for the first two and then at powers of two. +fn note_download_page_left_out(why: &str, at: usize) { + static N: AtomicU64 = AtomicU64::new(0); + let n = N.fetch_add(1, Ordering::Relaxed) + 1; + if n <= 2 || n.is_power_of_two() { + crate::xlog_info!("D3D12.X: a texture download left out a page at {at:#x} ({why}; {n} so far)"); + } +} + +/// Where each 64 KiB page of `[va, va + size)` is kept (`kernelx::mirrors::resolve`); None when +/// the title mapped none of them. +fn mapped_homes(va: usize, size: usize) -> Option<Vec<usize>> { + let mut at = Vec::new(); + crate::hle::kernelx::mirrors::resolve(va, size, &mut at)?; + Some(at) +} + +/// `write_changed_pages` for a texture at `at` over pages the title mapped: each 64 KiB page is +/// written where it is kept (`was`, the homes when the download was prepared). A page that shows +/// nothing takes no bytes, and neither does one whose home is another by `now`: the GPU wrote +/// what the earlier mapping showed, and those bytes must not reach the page mapped since. +unsafe fn write_changed_mapped_pages(at: usize, was: &[usize], now: &[usize], old: &[u8], new: &[u8]) -> bool { + const PAGE: usize = crate::hle::kernelx::mirrors::PAGE; + if old.len() != new.len() { return false } + let first = at & !(PAGE - 1); + let mut done = 0; + while done < new.len() { + let a = at + done; + let (k, off) = ((a - first) / PAGE, a & (PAGE - 1)); + let n = (PAGE - off).min(new.len() - done); + let home = was.get(k).copied().unwrap_or(0); + // (bit 0: a page never named, kept at the CPU view's same offset) + if home != 0 && now.get(k) != Some(&home) { + note_download_page_left_out("mapped elsewhere since", a); + } else if home != 0 && !write_changed_pages((home & !1) + off, &old[done..done + n], &new[done..done + n]) { ~~~~ --- The mapped-page writes (`mapped_homes`, `write_changed_mapped_pages`) are no longer in this PR as of fc7abe51; they come back in a separate PR. There each home is written once, from the last view page that maps it, compared against its live bytes.
BBareth commented 2026-12-03 01:35:39 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by BBareth on 2026-12-03T01:35:39Z.

Code review location: crates/xcl/src/hle/d3d12x/title_textures.rs; line 4152

@@ -4079,6 +4114,48 @@ unsafe fn write_changed_pages(at: usize, old: &[u8], new: &[u8]) -> bool {
     true
 }
 
+/// A download left bytes out at `at` (`why`): logged for the first two and then at powers of two.
+fn note_download_page_left_out(why: &str, at: usize) {
+    static N: AtomicU64 = AtomicU64::new(0);
+    let n = N.fetch_add(1, Ordering::Relaxed) + 1;
+    if n <= 2 || n.is_power_of_two() {
+        crate::xlog_info!("D3D12.X: a texture download left out a page at {at:#x} ({why}; {n} so far)");
+    }
+}
+
+/// Where each 64 KiB page of `[va, va + size)` is kept (`kernelx::mirrors::resolve`); None when
+/// the title mapped none of them.
+fn mapped_homes(va: usize, size: usize) -> Option<Vec<usize>> {
+    let mut at = Vec::new();
+    crate::hle::kernelx::mirrors::resolve(va, size, &mut at)?;
+    Some(at)
+}
+
+/// `write_changed_pages` for a texture at `at` over pages the title mapped: each 64 KiB page is
+/// written where it is kept (`was`, the homes when the download was prepared). A page that shows
+/// nothing takes no bytes, and neither does one whose home is another by `now`: the GPU wrote
+/// what the earlier mapping showed, and those bytes must not reach the page mapped since.
+unsafe fn write_changed_mapped_pages(at: usize, was: &[usize], now: &[usize], old: &[u8], new: &[u8]) -> bool {
+    const PAGE: usize = crate::hle::kernelx::mirrors::PAGE;
+    if old.len() != new.len() { return false }
+    let first = at & !(PAGE - 1);
+    let mut done = 0;
+    while done < new.len() {
+        let a = at + done;
+        let (k, off) = ((a - first) / PAGE, a & (PAGE - 1));
+        let n = (PAGE - off).min(new.len() - done);
+        let home = was.get(k).copied().unwrap_or(0);
+        // (bit 0: a page never named, kept at the CPU view's same offset)
+        if home != 0 && now.get(k) != Some(&home) {
+            note_download_page_left_out("mapped elsewhere since", a);
+        } else if home != 0 && !write_changed_pages((home & !1) + off, &old[done..done + n], &new[done..done + n]) {
+            return false;

The mapped-page writes (mapped_homes, write_changed_mapped_pages) are no longer in this PR as of fc7abe51; they come back in a separate PR. The follow-up has to revalidate each page's home under the mapping lock right before its write, not against a snapshot taken earlier.

<!-- greyfinch-sync:ivall/xcl:review-comment:4778668397 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3549#discussion_r4778668397). Originally posted by [BBareth](https://github.com/BBareth) on 2026-12-03T01:35:39Z. **Code review location:** `crates/xcl/src/hle/d3d12x/title_textures.rs`; line 4152 ~~~~diff @@ -4079,6 +4114,48 @@ unsafe fn write_changed_pages(at: usize, old: &[u8], new: &[u8]) -> bool { true } +/// A download left bytes out at `at` (`why`): logged for the first two and then at powers of two. +fn note_download_page_left_out(why: &str, at: usize) { + static N: AtomicU64 = AtomicU64::new(0); + let n = N.fetch_add(1, Ordering::Relaxed) + 1; + if n <= 2 || n.is_power_of_two() { + crate::xlog_info!("D3D12.X: a texture download left out a page at {at:#x} ({why}; {n} so far)"); + } +} + +/// Where each 64 KiB page of `[va, va + size)` is kept (`kernelx::mirrors::resolve`); None when +/// the title mapped none of them. +fn mapped_homes(va: usize, size: usize) -> Option<Vec<usize>> { + let mut at = Vec::new(); + crate::hle::kernelx::mirrors::resolve(va, size, &mut at)?; + Some(at) +} + +/// `write_changed_pages` for a texture at `at` over pages the title mapped: each 64 KiB page is +/// written where it is kept (`was`, the homes when the download was prepared). A page that shows +/// nothing takes no bytes, and neither does one whose home is another by `now`: the GPU wrote +/// what the earlier mapping showed, and those bytes must not reach the page mapped since. +unsafe fn write_changed_mapped_pages(at: usize, was: &[usize], now: &[usize], old: &[u8], new: &[u8]) -> bool { + const PAGE: usize = crate::hle::kernelx::mirrors::PAGE; + if old.len() != new.len() { return false } + let first = at & !(PAGE - 1); + let mut done = 0; + while done < new.len() { + let a = at + done; + let (k, off) = ((a - first) / PAGE, a & (PAGE - 1)); + let n = (PAGE - off).min(new.len() - done); + let home = was.get(k).copied().unwrap_or(0); + // (bit 0: a page never named, kept at the CPU view's same offset) + if home != 0 && now.get(k) != Some(&home) { + note_download_page_left_out("mapped elsewhere since", a); + } else if home != 0 && !write_changed_pages((home & !1) + off, &old[done..done + n], &new[done..done + n]) { + return false; ~~~~ --- The mapped-page writes (`mapped_homes`, `write_changed_mapped_pages`) are no longer in this PR as of fc7abe51; they come back in a separate PR. The follow-up has to revalidate each page's home under the mapping lock right before its write, not against a snapshot taken earlier.
BBareth commented 2026-12-03 01:35:41 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by BBareth on 2026-12-03T01:35:41Z.

Code review location: crates/xcl/src/hle/d3d12x/title_textures.rs; line 4007

@@ -3997,7 +4006,11 @@ fn publish_download(download: &ReadyDownload) -> Result<bool, String> {
     let mut table = TEXTURES.lock().unwrap();
     let Some(entry) = table.by_res.get_mut(&download.res) else { return Ok(true) };

The mapped-page writes (mapped_homes, write_changed_mapped_pages) are no longer in this PR as of fc7abe51; they come back in a separate PR. Agreed on the window between the snapshot and the write. In the follow-up each page's home is checked under the same lock apply_batches takes, immediately before its write.

<!-- greyfinch-sync:ivall/xcl:review-comment:4778668609 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3549#discussion_r4778668609). Originally posted by [BBareth](https://github.com/BBareth) on 2026-12-03T01:35:41Z. **Code review location:** `crates/xcl/src/hle/d3d12x/title_textures.rs`; line 4007 ~~~~diff @@ -3997,7 +4006,11 @@ fn publish_download(download: &ReadyDownload) -> Result<bool, String> { let mut table = TEXTURES.lock().unwrap(); let Some(entry) = table.by_res.get_mut(&download.res) else { return Ok(true) }; ~~~~ --- The mapped-page writes (`mapped_homes`, `write_changed_mapped_pages`) are no longer in this PR as of fc7abe51; they come back in a separate PR. Agreed on the window between the snapshot and the write. In the follow-up each page's home is checked under the same lock `apply_batches` takes, immediately before its write.
BBareth commented 2026-12-03 01:35:43 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by BBareth on 2026-12-03T01:35:43Z.

Code review location: crates/xcl/src/hle/d3d12x/title_textures.rs; line 3895

@@ -3892,7 +3892,7 @@ pub(super) unsafe fn prepare_downloads(queue: *mut c_void) -> PreparedDownloads
             if writes.is_empty() { return None }
             let source = ID3D12Resource::from_raw_borrowed(&(res as *mut c_void))?.clone();
             let device = ID3D12Device::from_raw_borrowed(&(entry.device as *mut c_void))?.clone();
-            Some(DownloadSnapshot { res, generation: entry.generation, target: entry.src, format: source.GetDesc().Format.0 as u32,
+            Some(DownloadSnapshot { res, generation: entry.generation, target: entry.src, pages: if entry.paged { mapped_homes(entry.src, entry.tex.size() as usize) } else { None }, format: source.GetDesc().Format.0 as u32,

The mapped-page writes (mapped_homes, write_changed_mapped_pages) are no longer in this PR as of fc7abe51; they come back in a separate PR. What is left of this case: a paged texture's download is written at its own address (the reserved GPU view), as on main. Its reserved pages are now left out, so the fence becomes visible without the GPU's bytes reaching the pool pages. On main that download failed on every retry and the fence stayed hidden. This is listed under Not tested in the description; writing those pages where they are kept is the follow-up.

<!-- greyfinch-sync:ivall/xcl:review-comment:4778668884 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3549#discussion_r4778668884). Originally posted by [BBareth](https://github.com/BBareth) on 2026-12-03T01:35:43Z. **Code review location:** `crates/xcl/src/hle/d3d12x/title_textures.rs`; line 3895 ~~~~diff @@ -3892,7 +3892,7 @@ pub(super) unsafe fn prepare_downloads(queue: *mut c_void) -> PreparedDownloads if writes.is_empty() { return None } let source = ID3D12Resource::from_raw_borrowed(&(res as *mut c_void))?.clone(); let device = ID3D12Device::from_raw_borrowed(&(entry.device as *mut c_void))?.clone(); - Some(DownloadSnapshot { res, generation: entry.generation, target: entry.src, format: source.GetDesc().Format.0 as u32, + Some(DownloadSnapshot { res, generation: entry.generation, target: entry.src, pages: if entry.paged { mapped_homes(entry.src, entry.tex.size() as usize) } else { None }, format: source.GetDesc().Format.0 as u32, ~~~~ --- The mapped-page writes (`mapped_homes`, `write_changed_mapped_pages`) are no longer in this PR as of fc7abe51; they come back in a separate PR. What is left of this case: a paged texture's download is written at its own address (the reserved GPU view), as on `main`. Its reserved pages are now left out, so the fence becomes visible without the GPU's bytes reaching the pool pages. On `main` that download failed on every retry and the fence stayed hidden. This is listed under **Not tested** in the description; writing those pages where they are kept is the follow-up.
BBareth commented 2026-12-03 01:35:44 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by BBareth on 2026-12-03T01:35:44Z.

Code review location: crates/xcl/src/hle/d3d12x/title_textures.rs; line 4082

@@ -4036,24 +4049,46 @@ fn changed_page_runs(at: usize, old: &[u8], new: &[u8]) -> Vec<(usize, usize)> {
     runs
 }
 
-/// Write changed 4 KiB pages without faulting if the title concurrently unmaps one. Every
-/// changed page must be committed and writable; otherwise its fence remains hidden and retries.
+/// Write changed 4 KiB pages without faulting if the title concurrently unmaps one. A changed
+/// page that is committed must be writable; otherwise its fence remains hidden and retries.
+/// A page the title has not committed (reserved or free) is left out: the title cannot read it, and
+/// waiting for it held the fence back for good (a retail game's frame-pacing wait then never ended).
+/// A mapped physical page that is only reserved until its first use (`kernelx::lazy`) is one the
+/// title can read: it is committed first and written.
 /// Contiguous changed pages within a VM region are coalesced into one `WriteProcessMemory` call
 /// so publishing large GPU-written textures does not pay a per-4 KiB syscall and instruction-cache
 /// flush while holding `TEXTURES`.
 unsafe fn write_changed_pages(at: usize, old: &[u8], new: &[u8]) -> bool {
     use windows_sys::Win32::System::Diagnostics::Debug::WriteProcessMemory;
-    use windows_sys::Win32::System::Memory::{VirtualQuery, MEMORY_BASIC_INFORMATION, MEM_COMMIT, PAGE_GUARD};
+    use windows_sys::Win32::System::Memory::{VirtualQuery, MEMORY_BASIC_INFORMATION, MEM_COMMIT, MEM_FREE, MEM_RESERVE, PAGE_GUARD};
     use windows_sys::Win32::System::Threading::GetCurrentProcess;
     if old.len() != new.len() { return false }
     let proc = GetCurrentProcess();
     let mut region_end = 0usize;
+    // the end of the addresses whose lazy pages were committed already
+    let mut ensured = 0usize;
     for (mut offset, run_end) in changed_page_runs(at, old, new) {
         while offset < run_end {
             let Some(address) = at.checked_add(offset) else { return false };
             if address >= region_end {
                 let mut info: MEMORY_BASIC_INFORMATION = std::mem::zeroed();
-                if VirtualQuery(address as *const c_void, &mut info, std::mem::size_of_val(&info)) == 0
+                let queried = VirtualQuery(address as *const c_void, &mut info, std::mem::size_of_val(&info)) != 0;
+                if queried && info.State == MEM_RESERVE && address >= ensured {
+                    // (a kernel call does not fault a lazy page in: commit those of the run, ask again)
+                    ensured = at.saturating_add(run_end);
+                    crate::hle::kernelx::lazy::ensure(address, ensured - address);
+                    continue;
+                }
+                if queried && (info.State == MEM_RESERVE || info.State == MEM_FREE) {

Addressed in fc7abe51. A reserved page is left out only when it is settled: kernelx::settled_uncommitted takes AWAY with try_lock (the lock MapTitlePhysicalPages holds while it unmaps and commits). If a mapping call is in progress, the download retries. If a physical page is kept for the address (Away::at), it is not treated as uncommitted. Otherwise the page is queried again under the lock, and a page committed in between is written. Tests: write_changed_pages_waits_for_a_mapping_call_in_progress and write_changed_pages_writes_a_page_committed_while_it_looked. A page the title commits after the skip is a new physical page; on the console it does not hold what the GPU wrote while it was unmapped either.

<!-- greyfinch-sync:ivall/xcl:review-comment:4778669101 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3549#discussion_r4778669101). Originally posted by [BBareth](https://github.com/BBareth) on 2026-12-03T01:35:44Z. **Code review location:** `crates/xcl/src/hle/d3d12x/title_textures.rs`; line 4082 ~~~~diff @@ -4036,24 +4049,46 @@ fn changed_page_runs(at: usize, old: &[u8], new: &[u8]) -> Vec<(usize, usize)> { runs } -/// Write changed 4 KiB pages without faulting if the title concurrently unmaps one. Every -/// changed page must be committed and writable; otherwise its fence remains hidden and retries. +/// Write changed 4 KiB pages without faulting if the title concurrently unmaps one. A changed +/// page that is committed must be writable; otherwise its fence remains hidden and retries. +/// A page the title has not committed (reserved or free) is left out: the title cannot read it, and +/// waiting for it held the fence back for good (a retail game's frame-pacing wait then never ended). +/// A mapped physical page that is only reserved until its first use (`kernelx::lazy`) is one the +/// title can read: it is committed first and written. /// Contiguous changed pages within a VM region are coalesced into one `WriteProcessMemory` call /// so publishing large GPU-written textures does not pay a per-4 KiB syscall and instruction-cache /// flush while holding `TEXTURES`. unsafe fn write_changed_pages(at: usize, old: &[u8], new: &[u8]) -> bool { use windows_sys::Win32::System::Diagnostics::Debug::WriteProcessMemory; - use windows_sys::Win32::System::Memory::{VirtualQuery, MEMORY_BASIC_INFORMATION, MEM_COMMIT, PAGE_GUARD}; + use windows_sys::Win32::System::Memory::{VirtualQuery, MEMORY_BASIC_INFORMATION, MEM_COMMIT, MEM_FREE, MEM_RESERVE, PAGE_GUARD}; use windows_sys::Win32::System::Threading::GetCurrentProcess; if old.len() != new.len() { return false } let proc = GetCurrentProcess(); let mut region_end = 0usize; + // the end of the addresses whose lazy pages were committed already + let mut ensured = 0usize; for (mut offset, run_end) in changed_page_runs(at, old, new) { while offset < run_end { let Some(address) = at.checked_add(offset) else { return false }; if address >= region_end { let mut info: MEMORY_BASIC_INFORMATION = std::mem::zeroed(); - if VirtualQuery(address as *const c_void, &mut info, std::mem::size_of_val(&info)) == 0 + let queried = VirtualQuery(address as *const c_void, &mut info, std::mem::size_of_val(&info)) != 0; + if queried && info.State == MEM_RESERVE && address >= ensured { + // (a kernel call does not fault a lazy page in: commit those of the run, ask again) + ensured = at.saturating_add(run_end); + crate::hle::kernelx::lazy::ensure(address, ensured - address); + continue; + } + if queried && (info.State == MEM_RESERVE || info.State == MEM_FREE) { ~~~~ --- Addressed in fc7abe51. A reserved page is left out only when it is settled: `kernelx::settled_uncommitted` takes `AWAY` with `try_lock` (the lock `MapTitlePhysicalPages` holds while it unmaps and commits). If a mapping call is in progress, the download retries. If a physical page is kept for the address (`Away::at`), it is not treated as uncommitted. Otherwise the page is queried again under the lock, and a page committed in between is written. Tests: `write_changed_pages_waits_for_a_mapping_call_in_progress` and `write_changed_pages_writes_a_page_committed_while_it_looked`. A page the title commits after the skip is a new physical page; on the console it does not hold what the GPU wrote while it was unmapped either.
BBareth commented 2026-12-03 01:36:05 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by BBareth on 2026-12-03T01:36:05Z.


Updated to fc7abe51 (rebased on main 078358a0). Suite, smoke blocks and GTA 6 runs are in the description. Thanks @throny for the 4080 run with #3550 on top. It matches mine: 3 of 3 runs clean here with the updated fix.

@bmjask, on point 3 (outside the diff): this PR no longer has a paged path. download_current doesn't need to compare paged, because a download is always written at entry.src as on main. What remains is the case you describe at the end: a paged texture's reserved GPU-view pages are now left out, so its fence goes up without the GPU's bytes reaching the pool pages. On main that download failed on every retry and its fence stayed hidden. I've listed it under Not tested. The follow-up PR that writes those pages where they are kept will also check paged and the page table against the snapshot.

Points 1, 2, 5 and 6, and the point from @gut0to, were on the mapped-page writes, which are taken out of this PR. Point 4 is addressed by the AWAY check; replies are in the threads.

AI use: Claude Code (Claude Opus 5.5) wrote the change, ran the tests and runs, and wrote these replies.

<!-- greyfinch-sync:ivall/xcl:comment:7364526461 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3549#issuecomment-7364526461). Originally posted by [BBareth](https://github.com/BBareth) on 2026-12-03T01:36:05Z. --- Updated to fc7abe51 (rebased on main 078358a0). Suite, smoke blocks and GTA 6 runs are in the description. Thanks @throny for the 4080 run with #3550 on top. It matches mine: 3 of 3 runs clean here with the updated fix. @bmjask, on point 3 (outside the diff): this PR no longer has a paged path. `download_current` doesn't need to compare `paged`, because a download is always written at `entry.src` as on `main`. What remains is the case you describe at the end: a paged texture's reserved GPU-view pages are now left out, so its fence goes up without the GPU's bytes reaching the pool pages. On `main` that download failed on every retry and its fence stayed hidden. I've listed it under **Not tested**. The follow-up PR that writes those pages where they are kept will also check `paged` and the page table against the snapshot. Points 1, 2, 5 and 6, and the point from @gut0to, were on the mapped-page writes, which are taken out of this PR. Point 4 is addressed by the `AWAY` check; replies are in the threads. AI use: Claude Code (Claude Opus 5.5) wrote the change, ran the tests and runs, and wrote these replies.
Foniass commented 2026-12-03 01:39:20 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-03T01:39:20Z.


Follow-up review of fc7abe51, since a615e1b (code reading only, not a merge-check) · 2 medium

In short: Since a615e1b1 (merge-checked at c3a91393), the PR no longer does the download for textures over mapped pages: mapped_homes, write_changed_mapped_pages and ReadyDownload.pages are gone. The description says that part will come back in a separate PR, not open yet. What remains is the reserved-page skip, now bounded to the end of the 64 KiB page and gated on kernelx::settled_uncommitted, plus the lazy::ensure step, a test hook and two new tests. Nothing blocks it. Dropping the mapped-page part changes what happens to paged textures, though, and the new 64 KiB bound has no test.

Medium

  1. Paged textures now publish without the GPU's bytes and are no longer treated as GPU-written.

    • For a texture over pages the title mapped, target is entry.src, the reserved GPU view (title_textures.rs ~3925, source_of ~716). Every changed page there is left out, so publish_download succeeds. Not tested says so.
    • It does not say that the publish also clears gpu_writers and sets gpu_written = false (~4036-4042). After that the texture can be uploaded again from title memory, for example pending on uncover (~425). Those pages never got the GPU's output, so such an upload can put stale bytes over the GPU's result in the PC texture.
    • On main the texture stayed GPU-owned.

    Fix: until the follow-up lands, keep gpu_written set when a paged entry's download wrote nothing, or say in the description that this can happen.

  2. The 64 KiB bound on the skip has no test. skip_to is capped at the end of the 64 KiB page (~4102), so the next page is checked again on its own. In all four tests the reserved region already ends at or before a 64 KiB boundary, so removing .min((address & !(PAGE - 1)) + PAGE) fails none of them. Fix: reserve two 64 KiB pages, use the BEFORE_LEAVING_OUT hook on the first left-out page to commit base + PAGE, and check the second page takes the GPU's bytes.

Checked and fine
  • Earlier finding fixed: a page left out is logged (note_download_page_left_out, the first two then at powers of two, ~4149).
  • Earlier finding fixed: the doc comment of write_changed_pages says only committed pages must be writable, and describes the lazy-page case (~4069-4074).
  • Earlier finding no longer applies: the loss of a page remapped after preparation was in the mapped_homes path, which is gone. So is the pages field that conflicted with #3550's test.
  • MapTitlePhysicalPages, XMemMapPhysicalPagesScatter and FreeTitlePhysicalPages hold AWAY for the whole call, so uncommitted is asked while no mapping call is between its unmap and its commit.
  • settled_uncommitted returning None (any AWAY holder) makes write_changed_pages return false. The fence stays hidden and the publish is tried again on the next query. It uses try_lock, so it cannot deadlock under TEXTURES.
  • A page found in Away::at that is still reserved (a lazy commit in progress on another thread) returns Some(false), then is written or retried, never skipped.
  • ensured makes lazy::ensure run at most once per run. skip_to is always past address, so the loop cannot spin. Committed read-only or guarded pages still fail closed.
  • BEFORE_LEAVING_OUT and with_mapping_call are #[cfg(test)] only. The two new tests check the None path and the re-query after Some(false).
  • 175+/4-, about half of it tests. #3550 depends on this PR.

Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7364586038 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3549#issuecomment-7364586038). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-03T01:39:20Z. --- **Follow-up review** of `fc7abe51`, since `a615e1b` (code reading only, not a merge-check) · 2 medium **In short:** Since `a615e1b1` (merge-checked at `c3a91393`), the PR no longer does the download for textures over mapped pages: `mapped_homes`, `write_changed_mapped_pages` and `ReadyDownload.pages` are gone. The description says that part will come back in a separate PR, not open yet. What remains is the reserved-page skip, now bounded to the end of the 64 KiB page and gated on `kernelx::settled_uncommitted`, plus the `lazy::ensure` step, a test hook and two new tests. Nothing blocks it. Dropping the mapped-page part changes what happens to paged textures, though, and the new 64 KiB bound has no test. #### Medium 1. **Paged textures now publish without the GPU's bytes and are no longer treated as GPU-written.** - For a texture over pages the title mapped, `target` is `entry.src`, the reserved GPU view (`title_textures.rs` ~3925, `source_of` ~716). Every changed page there is left out, so `publish_download` succeeds. **Not tested** says so. - It does not say that the publish also clears `gpu_writers` and sets `gpu_written = false` (~4036-4042). After that the texture can be uploaded again from title memory, for example `pending` on uncover (~425). Those pages never got the GPU's output, so such an upload can put stale bytes over the GPU's result in the PC texture. - On `main` the texture stayed GPU-owned. Fix: until the follow-up lands, keep `gpu_written` set when a paged entry's download wrote nothing, or say in the description that this can happen. 2. **The 64 KiB bound on the skip has no test.** `skip_to` is capped at the end of the 64 KiB page (~4102), so the next page is checked again on its own. In all four tests the reserved region already ends at or before a 64 KiB boundary, so removing `.min((address & !(PAGE - 1)) + PAGE)` fails none of them. Fix: reserve two 64 KiB pages, use the `BEFORE_LEAVING_OUT` hook on the first left-out page to commit `base + PAGE`, and check the second page takes the GPU's bytes. <details><summary>Checked and fine</summary> - Earlier finding fixed: a page left out is logged (`note_download_page_left_out`, the first two then at powers of two, ~4149). - Earlier finding fixed: the doc comment of `write_changed_pages` says only committed pages must be writable, and describes the lazy-page case (~4069-4074). - Earlier finding no longer applies: the loss of a page remapped after preparation was in the `mapped_homes` path, which is gone. So is the `pages` field that conflicted with #3550's test. - `MapTitlePhysicalPages`, `XMemMapPhysicalPagesScatter` and `FreeTitlePhysicalPages` hold `AWAY` for the whole call, so `uncommitted` is asked while no mapping call is between its unmap and its commit. - `settled_uncommitted` returning `None` (any `AWAY` holder) makes `write_changed_pages` return false. The fence stays hidden and the publish is tried again on the next query. It uses `try_lock`, so it cannot deadlock under `TEXTURES`. - A page found in `Away::at` that is still reserved (a lazy commit in progress on another thread) returns `Some(false)`, then is written or retried, never skipped. - `ensured` makes `lazy::ensure` run at most once per run. `skip_to` is always past `address`, so the loop cannot spin. Committed read-only or guarded pages still fail closed. - `BEFORE_LEAVING_OUT` and `with_mapping_call` are `#[cfg(test)]` only. The two new tests check the `None` path and the re-query after `Some(false)`. - 175+/4-, about half of it tests. #3550 depends on this PR. </details> <sub>Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.</sub>
throny commented 2026-12-03 02:35:39 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by throny on 2026-12-03T02:35:39Z.


merge-check
base: 078358a05
head: fc7abe517
merge: clean (trial merge into main 078358a05)
build: cargo build --workspace -> ok
tests: cargo test --workspace -- --test-threads=4 -> 3010 passed, 0 failed, 52 ignored; 25 SKIPPED (no wave64 and similar); failing: none
title run: retail title, RTX 4080, main 078358a05 + this head + #3550 on top, 300 s in the world (run 517), no crash, no device removal, no Aftermath dump, 2.93 presents/s
review: whole diff read (title_textures.rs write_changed_pages, kernelx.rs settled_uncommitted). Uncommitted (reserved or free) pages are left out to the end of their 64 KiB page at most. A lazy page is committed and written. While a mapping call is in progress (AWAY lock held), the write retries instead of leaving the page out, and a page that becomes committed meanwhile is written. The logging is bounded (first two, then powers of two). Tests cover leaving out, the lazy commit and the in-progress wait. Nothing found.
performance: no measurable cost (2.93 presents/s, as main on this machine)
verdict: safe to merge
hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300 / Claude Code with Claude Opus 5.5 (trial suite, world run, diff review)

<!-- greyfinch-sync:ivall/xcl:comment:7365640309 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3549#issuecomment-7365640309). Originally posted by [throny](https://github.com/throny) on 2026-12-03T02:35:39Z. --- merge-check base: 078358a05 head: fc7abe517 merge: clean (trial merge into main 078358a05) build: cargo build --workspace -> ok tests: cargo test --workspace -- --test-threads=4 -> 3010 passed, 0 failed, 52 ignored; 25 SKIPPED (no wave64 and similar); failing: none title run: retail title, RTX 4080, main 078358a05 + this head + #3550 on top, 300 s in the world (run 517), no crash, no device removal, no Aftermath dump, 2.93 presents/s review: whole diff read (title_textures.rs write_changed_pages, kernelx.rs settled_uncommitted). Uncommitted (reserved or free) pages are left out to the end of their 64 KiB page at most. A lazy page is committed and written. While a mapping call is in progress (AWAY lock held), the write retries instead of leaving the page out, and a page that becomes committed meanwhile is written. The logging is bounded (first two, then powers of two). Tests cover leaving out, the lazy commit and the in-progress wait. Nothing found. performance: no measurable cost (2.93 presents/s, as main on this machine) verdict: safe to merge hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300 / Claude Code with Claude Opus 5.5 (trial suite, world run, diff review)
BBareth commented 2026-12-03 03:09:53 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by BBareth on 2026-12-03T03:09:53Z.


The mapped-page part taken out of this PR is now #3759, stacked on this one. It writes a paged texture's download where each page is kept, and it addresses the points raised on its first form:

  • a missing table is not current;
  • a shared home is written once, from its last page;
  • paged and the homes are compared with the prepare-time snapshot;
  • each page is rechecked under AWAY.

It also includes the suite and smoke blocks for its head commit.

<!-- greyfinch-sync:ivall/xcl:comment:7366270040 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3549#issuecomment-7366270040). Originally posted by [BBareth](https://github.com/BBareth) on 2026-12-03T03:09:53Z. --- The mapped-page part taken out of this PR is now #3759, stacked on this one. It writes a paged texture's download where each page is kept, and it addresses the points raised on its first form: - a missing table is not current; - a shared home is written once, from its last page; - `paged` and the homes are compared with the prepare-time snapshot; - each page is rechecked under `AWAY`. It also includes the suite and smoke blocks for its head commit.
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/3549:upstream-pr/3549'
git switch 'upstream-pr/3549'

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