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
Contributor

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
Collaborator

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
Contributor

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
Collaborator

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
Collaborator

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
Collaborator

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.

@bmjask bmjask left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

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) },

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

// (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]) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

crate::hle::kernelx::lazy::ensure(address, ensured - address);
continue;
}
if queried && (info.State == MEM_RESERVE || info.State == MEM_FREE) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

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,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

bmjask commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

@Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any.

@ClosetPie107

Copy link
Copy Markdown

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 Linux (Wine + vkd3d-proton): a retail game reaches what main reaches on Windows; the obstacle is replaced vtables — proposal: proxies #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.

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.

7 participants