Skip to content

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

Open
BBareth wants to merge 1 commit into
xcl-dev:mainfrom
BBareth:d3d12x/skip-uncommitted-download-pages
Open

BBareth wants to merge 1 commit into
xcl-dev:mainfrom
BBareth:d3d12x/skip-uncommitted-download-pages

Conversation

@BBareth

@BBareth BBareth commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

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 reserved and free pages out of the copy, since the title cannot read them. One kind of reserved page is not left out: a mapped physical page that XCL keeps reserved until its first use (kernelx::lazy). The title can read it, so it is committed and written. Committed pages that are read-only or guarded still fail closed and retry, as before.

A texture over pages the title mapped (CopyPageMappingsBatchX) is a second case of the same refusal: its own address is a reserved GPU view and each page is kept elsewhere. Its download is now read and written where each page is kept, as uploads already read it. A page that shows nothing takes no bytes, and neither does a page mapped to another home since the download was prepared.

In GTA 6 (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, so 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.

What is in it

  • crates/xcl/src/hle/d3d12x/title_textures.rs: write_changed_pages (the coalesced runs from D3D12.X: coalesce contiguous WriteProcessMemory runs in write_changed_pages #3237) skips pages in MEM_RESERVE / MEM_FREE to the end of their region.
  • Unit test write_changed_pages_leaves_out_pages_the_title_has_not_committed: it fails without the fix.
  • write_changed_pages calls kernelx::lazy::ensure on a reserved run before it decides to skip (once per run), as cpu_writes and DirectStorage do before their writes. Unit test write_changed_pages_commits_a_lazy_page_and_writes_it: a committed page and a lazy page take the bytes, a plain reservation stays reserved. Found in triage (PR triage: duplicate PRs and batch-tested PRs, each checked by two contributors #1607).
  • publish_download / prepare_downloads: a paged texture carries the homes of its pages (mapped_homes, from kernelx::mirrors::resolve) from preparation to publication; write_changed_mapped_pages writes each 64 KiB page at its home and leaves out a page whose home changed in between. A page left out, for either reason, is logged (note_download_page_left_out: the first two, then at powers of two).
  • Unit test a_download_over_mapped_pages_is_written_where_they_are_kept: the pool page takes the bytes, a page never named goes to the CPU view, an unmapped page holds nothing back, and after a remap neither pool page is written.

Tested

Regression run

xcl-smoke v1
commit: 493dbd3dd0cd50b4c3e8d28f73ab9b504fcd8158
gpu: NVIDIA GeForce RTX 5070 Ti
title: 9cc6a39e
seconds: 120
exit: 0x0
frames shown: 3087 (PresentX 3087)
presents per 2 s (last 3): 49 46 47
device removals: 0
crashes: 0
peak commit: 30932 MB
xcl-smoke v1
commit: c3a91393d380d1f6b1741b6f740a02e1b2a53f36
gpu: NVIDIA GeForce RTX 5070 Ti
title: 9cc6a39e
seconds: 120
exit: 0x0
frames shown: 3066 (PresentX 3066)
presents per 2 s (last 3): 33 14 39
device removals: 0
crashes: 0
peak commit: 32653 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 GTA 6 runs that reach it were on an earlier tree with other PRs, not on this branch alone.
  • The mapped-page writes in a retail title: no world run was made with them, and there is no GPU test that drives a download of a paged texture through its fence. The unit test covers the write function only.
  • A page remapped between the GPU write and the preparation of its download is still written at its new home; only a remap after preparation is caught. A page remapped after preparation loses the GPU result at its old home too.
  • The memory cost of committing lazy pages for downloads in a retail title was not measured (only pages a download changes are committed); the 120 s smoke shows the peak commit below.
  • AMD GPUs.

AI use

  • Claude Code, Claude Opus 5.5: found the cause from logs and thread dumps, wrote the fix, the test and this description, and ran the GTA 6 runs above.
  • Claude Code, Claude Fable 5.2: rebased the branch, wrote the mapped-page writes, the lazy-page commit, their tests and the log line after review, ran the suite and the regression runs above and updated this description.

🤖 Generated with Claude Code

@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) labels Nov 30, 2026
@Gevroska

Gevroska commented Dec 1, 2026

Copy link
Copy Markdown

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

Copy link
Copy Markdown
Contributor

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.

@thehollowedone

Copy link
Copy Markdown
Contributor

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.

@BBareth
BBareth force-pushed the d3d12x/skip-uncommitted-download-pages branch from 3cf3ebb to 069739d Compare December 1, 2026 07:28
@BBareth

BBareth commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

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

  • 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 069739d: 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.

@github-actions github-actions Bot added the needs-pr-check Failing the PR description check (CONTRIBUTING.md) label Dec 1, 2026
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

merge-check
base: 7d86c5d
head: 069739d
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 069739d (one squashed commit, +86 since 3cf3ebb). 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 7d86c5d 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.

@github-actions github-actions Bot added needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU and removed needs-pr-check Failing the PR description check (CONTRIBUTING.md) labels Dec 1, 2026
@Gevroska

Gevroska commented Dec 1, 2026

Copy link
Copy Markdown

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

BBareth commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

Follow-up to the merge check above, head a615e1b: 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 a615e1b: 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.

@github-actions github-actions Bot removed needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU labels Dec 1, 2026
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Re-review (head a615e1b; the range-diff from 069739d, 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 069739d) still describes this head.

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

@Foniass

Foniass commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

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 (c3a9139), 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.

A GPU-written title texture is copied back into the title's memory when
its fence completes, and the fence value stays hidden until that copy
succeeds. write_changed_pages refused any changed page that was not
committed, so a destination whose pages are only reserved (a sparse home
not in use) failed on every retry and the fence never became visible.

In a retail game the frame-pacing wait on that fence then spun forever:
from 522 s every retry of two downloads (0x20000 and 0x10000 bytes) found
MEM_RESERVE pages, submits stopped at 528 s and the title's GPU watchdog
crashed it at 552 s. With reserved and free pages left out (the title
cannot read them), no download is held back and the game kept rendering
to 623 s in the same run.

A texture over pages the title mapped (CopyPageMappingsBatchX) is another
case of the same refusal: its own address is a reserved GPU view and each
page is kept elsewhere. Its download is now read and written where each
page is kept, as uploads read it. A page that shows nothing takes no
bytes, and neither does one mapped to another home since the download
was prepared, so the GPU's bytes cannot reach the wrong page.

Committed pages that are read-only or guarded still fail closed.
A page left out is logged (the first two, then at powers of two).

A mapped physical page that is reserved only until its first use
(kernelx::lazy) is not such a page: the title can read it, so it is
committed and written (found in triage, xcl-dev#1607).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@BBareth
BBareth force-pushed the d3d12x/skip-uncommitted-download-pages branch from a615e1b to c3a9139 Compare December 1, 2026 10:44
@BBareth

BBareth commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

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

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

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

merge-check
base: 493dbd3
head: c3a9139
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 a615e1b read; my merge-check of 069739d 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 493dbd3 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.

@github-actions github-actions Bot added needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU labels Dec 1, 2026

@gut0to gut0to left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@@ -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) };

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:d3d12 D3D12.X runtime, command lists, resources, sparse memory gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) needs:amd-test Needs a test report or merge-check on an AMD GPU needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants