Skip to content

D3D12.X: streamed textures read through their pages are rechecked there - #3725

Open
Lakanya wants to merge 1 commit into
xcl-dev:mainfrom
Lakanya:pr-ready/paged-stream-recheck
Open

Lakanya wants to merge 1 commit into
xcl-dev:mainfrom
Lakanya:pr-ready/paged-stream-recheck

Conversation

@Lakanya

@Lakanya Lakanya commented Dec 2, 2026 •

Copy link
Copy Markdown

Textures read through physical pages mapped under a GPU view (CopyPageMappingsBatchX, Entry::paged) were skipped in seed_stream_recheck and pruned in recheck_streamed_unwatched_at. When the title moves a physical page, its texels are kept away from the view's address, and texels written there after the initial zeroed upload without a write the dirty path saw were never re-uploaded.

Paged textures are now seeded and rechecked on the milestone schedule through their resolved page table (sample_fingerprint_in), sampling three 128-byte probes per 64 KiB page (up to 256 evenly spaced pages, at most 96 KiB read) so late-arriving interior pages are caught. Entries with no mapped pages leave the schedule until a new mapping arrives.

Updated after review (head ad7c0a89, squashed; 91304b35 with the commit author corrected and the budget test on a view size no other test uses): a partial upload of a paged texture no longer makes an entry without a baseline (which brought a whole upload 4 frames after each partial one of a streaming texture), and at most 32 paged textures are fingerprinted per frame (up to 3 MiB read); the others stay due for the next frames.

What is in it

  • d3d12x::title_textures: sample_fingerprint_in per-64 KiB page probing through PageMap, seeding (whole uploads only) and milestone recheck for Entry::paged textures in seed_stream_recheck and recheck_streamed_unwatched_at, with PAGED_CHECKS_PER_FRAME (32) paged checks per frame at most.
  • Unit tests: stream_recheck_catches_a_late_write_under_a_paged_texture, a_paged_fingerprint_sees_a_late_page_inside_the_texture, paged_rechecks_keep_to_the_frame_budget, and a paged case in stream_recheck_partial_upload_without_an_entry_queues_a_whole_upload.

Regression run
(both made with scripts/smoke.ps1 run on a hidden desktop, CreateDesktopW, so that no window shows)

xcl-smoke v1
commit: 5ad98adbc360225ac8a57ad9661e16fe8df9d8dd
gpu: NVIDIA GeForce RTX 5070 Laptop GPU
title: 861a59ab
seconds: 60
exit: 0x0
frames shown: 1624 (PresentX 1624)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15870 MB
xcl-smoke v1
commit: ad7c0a897110adad4fa038f7051f6020c8f018ef
gpu: NVIDIA GeForce RTX 5070 Laptop GPU
title: 861a59ab
seconds: 60
exit: 0x0
frames shown: 1673 (PresentX 1673)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 15875 MB

Tested

  • Hardware: NVIDIA GeForce RTX 5070 Laptop GPU (7891 MiB VRAM), Windows 11 x64, debug test build.
  • Retail title (C:\gta6), on a local stack (the first version of this change, before the partial-upload rule and the per-frame budget, on top of other local commits over an older main, not this commit alone): 64–4,096 paged textures re-queued per run (none before); the look before submits took the same share of time (26 %). As the review points out, that count may include whole uploads brought by partial ones, which this version no longer makes.
  • The 4 tests above on 91304b35: 4 passed. paged_rechecks_keep_to_the_frame_budget fails without the budget ((33, 33) checked against (32, 33)), and the paged case fails without the partial-upload rule. cargo test -p xcl --lib -- hle::d3d12x::title_textures:: --test-threads=4 --skip placed_title_textures_share_vram_and_preserve_pixels: 67 passed, 0 failed, 1 ignored.
  • .\scripts\test.ps1 (cargo test --workspace -- --test-threads=4) on 91304b35: the xcl lib test process exits with 0x80004005 partway ("sparse upload preparation still failed after bounded retries", the stop Tests: on an AMD RDNA2 iGPU the xcl lib test binary stops itself partway ("sparse upload preparation still failed after bounded retries") since #2959 #3488 reports on an AMD iGPU); 817eb1fc exits the same way. Remaining binaries (--no-fail-fast): 152 passed, 0 failed, 20 ignored.
  • xcl lib tests run one module group at a time (cargo test -p xcl --lib -- <module>:: --test-threads=4, 199 groups, all 2,887 tests): 2,852 passed, 3 failed, 32 ignored. Failed:
    • title_textures::tests::placed_title_textures_share_vram_and_preserve_pixels, then two stream_recheck_* tests through the TEST_LOCK it poisons; all pass alone, the whole title_textures group passes without the first (above), and they fail the same way on 817eb1fc.
    • Not seen this time: bind::tests::records_for_falls_back_to_whole_before_shrinking_halves, intermittent (on the first head the bind:: group failed it 1 of 4 runs, and 2 of 3 on 817eb1fc).
  • On the head ad7c0a89 (only the budget test's view size differs from 91304b35): cargo test -p xcl --lib -- paged_rechecks_keep_to_the_frame_budget: 1 passed; cargo test -p xcl --lib -- hle::kernelx:: hle::d3d12x::title_textures:: --test-threads=4 --skip placed_title_textures_share_vram_and_preserve_pixels (the test that used the same size runs next to it): 136 passed, 0 failed, 2 ignored.
  • SKIPPED: 22 wave64 tests (no wave64), 2 heap-window tests (no heap windows), 1 driver-cache test (Developer Mode not enabled).

Not tested

  • AMD / RDNA GPUs, wave64.
  • The retail-title measurements above on this commit alone (the 60 s smoke run does not reach the world), including frame time at milestone frames during world load.
  • macOS / Linux (not built / not tested).

AI use

  • Claude Code, Claude Opus 5.5: implementation, unit tests, and initial retail-title measurements.
  • Antigravity, Gemini 4 Carbon: standalone rebase adaptation and compile verification onto 817eb1fc.
  • Claude Code, Claude Opus 5.5: review changes and their tests, full test suite, scripts/smoke.ps1 regression runs, and PR preparation.

🤖 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) needs-1st-check Passes gates; needs first independent merge-check (#3041) labels Dec 2, 2026
@Foniass

Foniass commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

Review of 85b53380 (code reading only, not a merge-check) · 2 medium, 1 nit

In short: The PR keeps textures read through their pages (Entry::paged) on the stream-recheck schedule and fingerprints them through their page table. Before, they were skipped at seeding and pruned at the first milestone. The logic and both tests match the description. The change does schedule every paged texture, including those whose pages are write-watched, and its per-check cost on the default path is unmeasured; the 60 s smoke run does not reach that path.

Medium

  1. Paged textures are scheduled even when their pages are write-watched.

    • In seed_stream_recheck (title_textures.rs ~2425), the range_is_fully_watched skip now applies only when d.pages.is_none(). In recheck_streamed_unwatched_at (~2491), e.paged never prunes.
    • Writes at a page's kept place already reach the GPU view through the dirty path (mirrors::views_of_written, ~2075), so a watched paged texture gains nothing from the schedule.
    • Each partial upload of a paged texture now goes through unsent (~2434) and gets a last_fp: None entry. The first milestone always queues a whole upload for such an entry, so a streaming texture gets an extra whole upload 4 frames after each partial one.
    • For the same reason, the "64-4,096 re-queued per run" figure cannot tell missed writes from these re-uploads.

    Fix: skip a paged texture when every place its PageMap resolves to is watched, or at least add no None-baseline entries for paged partial uploads.

  2. The per-check cost has no bound and was not measured on this commit.

    • sample_fingerprint_in (~2396-2400) makes three reads per 64 KiB page, up to 768 per texture. Each read of a page kept elsewhere is one ReadProcessMemory call.
    • Each due paged texture also costs a page_map → mirrors::resolve at every milestone (~2525).
    • There is no per-frame budget, and textures seeded by one large load-time submit all come due in the same frame.

    Please measure frame time at milestone frames during world load on this commit, or cap the paged checks per frame.

Nit

  1. Wrong references in a comment and the doc.
    • The comment at ~2423 and the description say a moved page is kept "at a home no write watch sees, cpu_writes". d3d12x::cpu_writes is the bottom-of-pipe write worker and has nothing to do with page homes.
    • The doc of sample_fingerprint_in (~2376) says "the same slices", but the function uses its own 128-byte probes per page.
Checked and fine
  • The arithmetic in sample_fingerprint_in: probe and step are never 0, the offsets stay inside [start, end), and nothing overflows at realistic sizes.
  • Seed and recheck fingerprint the same address: for a paged entry e.src == e.va.
  • The recheck calls page_map after TEXTURES is dropped, so there is no new lock-order edge.
  • An entry with no mapped pages left is dropped from STREAM_RECHECK and seeded again by the next whole upload.
  • stream_recheck_catches_a_late_write_under_a_paged_texture fails without the change and cleans up its tables. The second test's write falls outside the old start, mid and end slices.
  • Size (131+/10-), scope and the description outline meet the rules. XCL_TEXTURE_STREAM_RECHECK=0 still turns the recheck off.
  • Not a duplicate: D3D12.X: keep re-checking small textures in the unwatched upload range #3617 also changes the stream recheck, for textures that are not paged and behind a switch. It touches the same code and will probably conflict.

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

@Lakanya
Lakanya force-pushed the pr-ready/paged-stream-recheck branch from 85b5338 to 91304b3 Compare December 2, 2026 21:01
@Lakanya

Lakanya commented Dec 2, 2026

Copy link
Copy Markdown
Author

Thanks, @Foniass. Checked against 85b53380, and addressed in 91304b35 (squashed, description updated):

  1. Medium, confirmed: a partial upload of a paged texture went through unsent and got a last_fp: None entry, so a streaming texture got a whole upload 4 frames after each partial one. Paged textures now get no entry from a partial upload; their schedule starts at whole uploads. The paged case added to stream_recheck_partial_upload_without_an_entry_queues_a_whole_upload fails without it. I did not add the "every resolved place is watched" skip: a texture that keeps no entry from partial uploads only rechecks after whole uploads, which is the case the change is for.
  2. Medium, agreed: at most PAGED_CHECKS_PER_FRAME (32) paged textures are fingerprinted per frame (up to 3 MiB read); the others stay due and are checked in the next frames, since a checked one leaves the due set until its next milestone. paged_rechecks_keep_to_the_frame_budget checks 33 due textures: 32, then 33. Frame time at milestone frames during world load is still not measured on this commit (listed under Not tested).
  3. Nit, right: the cpu_writes reference is gone from the comment, the commit message and the description, and the doc of sample_fingerprint_in now describes its own probes.

The retail count (64–4,096 re-queued) came from the first version and may include the whole uploads of point 1; the description now says so.

AI use: Claude Code, Claude Opus 5.5 (checked the points, wrote the changes, tests and this reply; tests and smoke run on an RTX 5070 Laptop GPU).

@github-actions github-actions Bot removed the needs-1st-check Passes gates; needs first independent merge-check (#3041) label Dec 2, 2026
@Foniass

Foniass commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

Follow-up review of 91304b35, since 85b53380 (code reading only, not a merge-check; Build and test (Windows, no GPU) red) · 1 medium

In short: Since 85b53380 the PR is squashed into one commit with three changes:

  • a partial upload of a paged texture no longer creates an entry without a baseline;
  • paged checks are capped at PAGED_CHECKS_PER_FRAME (32) per frame, with a test;
  • the comment and doc wording is corrected.

That fixes all three earlier points. The one new problem is that the budget test uses a view size another test already uses, so the two can pair with each other's views when they run at the same time.

Medium

  1. The new budget test reuses a view size from a kernelx test.

    • paged_rechecks_keep_to_the_frame_budget (title_textures.rs ~6793) calls paged_views(199 * PAGE, n), and gpu_view_pages_record_the_physical_page_mapped_into_them (kernelx.rs ~4558) uses 199 * PAGE for its cpu_view.
    • mirrors::reserved pairs a GPU view with the newest unpaired CPU view of the same size (unpaired_cpu, kernelx.rs ~200). That is why both helpers' docs ask for a size no other test uses. The two tests share no lock.
    • On parallel test threads, either GPU view can pair with the other test's CPU view, and one of the two tests fails at random.

    Fix: use a size no other test passes to mirrors::reserved / cpu_view / paged_views.

Checked and fine
  • Earlier finding fixed: partial uploads of paged textures no longer create last_fp: None entries, so no whole upload follows 4 frames later (seed_stream_recheck ~2439). The paged case added to stream_recheck_partial_upload_without_an_entry_queues_a_whole_upload covers it. Write-watched paged textures are still scheduled, but now under the per-frame cap.
  • Earlier finding fixed: paged checks are capped at 32 per frame, about 3 MiB read (~2501). Textures over the budget stay due, because the due test is >= against the milestone (~2481). The test checks 32 textures, then the 33rd one frame later.
  • Earlier finding fixed: the comment at ~2426 and the doc of sample_fingerprint_in (~2376) no longer name cpu_writes or "the same slices", and the description no longer does either.
  • The description now says the retail re-queue figure predates these changes, and that frame time at milestone frames was not measured.
  • The cap applies only to paged entries, and pending paged entries use no budget.
  • 190+/12- in one file. D3D12.X: keep re-checking small textures in the unwatched upload range #3617 touches the same recheck code for non-paged textures and will probably conflict.

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

@Lakanya
Lakanya force-pushed the pr-ready/paged-stream-recheck branch from 91304b3 to 7a59f45 Compare December 2, 2026 21:33
@Foniass

Foniass commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

Follow-up review of 7a59f45e, since 91304b35 (code reading only, not a merge-check) · 1 medium

In short: This push only changes the commit's author; the code is the same as at 91304b35 (git range-diff). The test point from my last review is still open.

Medium

  1. The budget test reuses a view size from a kernelx test (still open). paged_rechecks_keep_to_the_frame_budget (title_textures.rs ~6793) uses paged_views(199 * PAGE, n), the size gpu_view_pages_record_the_physical_page_mapped_into_them (kernelx.rs ~4558) uses for its cpu_view. mirrors::reserved pairs views by size, and the two tests share no lock, so on parallel test threads one can pair with the other's view and fail at random. Use a size no other test uses.
Checked and fine
  • No code change since the last review; the fixes listed there (no baseline-less entries for paged partial uploads, the per-frame cap, the corrected comments) still hold.

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

A texture read through the pages the title mapped under a GPU view
(CopyPageMappingsBatchX, `Entry::paged`) was left out of STREAM_RECHECK:
`seed_stream_recheck` skipped it and `recheck_streamed_unwatched_at`
pruned it, on the grounds that its pages are found written where they are
kept. A page the title moved is kept away from the view's address, and
texels that arrived there after the first (zeroed) upload without a write
the dirty path saw never reached the PC texture.

Such a texture is now seeded and rechecked like the others, fingerprinted
through its page table (`sample_fingerprint_in`): three 128-byte probes in
every 64 KiB page (an even subset past 256 pages, at most 96 KiB read), so a
single late page in the middle of a big texture is seen. A texture with no
page mapped any more leaves the schedule; a new mapping reads it again.

A partial upload of such a texture makes no entry without a baseline (that
would bring a whole upload 4 frames after each partial one of a streaming
texture): its schedule starts at whole uploads. At most 32 of them are
fingerprinted in a frame (up to 3 MiB read); the others stay due for the
next frames.

GTA VI (before the two changes above): 64-4,096 paged textures re-queued
per run, none before; the look
before submits took the same share of time (26 %).

Tests: stream_recheck_catches_a_late_write_under_a_paged_texture and
a_paged_fingerprint_sees_a_late_page_inside_the_texture fail without the
change (the first is pruned, the second's start/middle/end sample misses
the page) and pass with it; paged_rechecks_keep_to_the_frame_budget and
the paged case added to
stream_recheck_partial_upload_without_an_entry_queues_a_whole_upload fail
without the budget and the partial-upload rule.

Assisted-by: Claude Code (Claude Opus 5.5)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the needs-1st-check Passes gates; needs first independent merge-check (#3041) label Dec 2, 2026
@Lakanya
Lakanya force-pushed the pr-ready/paged-stream-recheck branch from 7a59f45 to ad7c0a8 Compare December 2, 2026 22:00
@Lakanya

Lakanya commented Dec 2, 2026

Copy link
Copy Markdown
Author

Thanks, @Foniass, right: kernelx.rs uses 199 * PAGE for gpu_view_pages_record_the_physical_page_mapped_into_them. In ad7c0a89 the budget test uses 233 * PAGE, which no other test passes to paged_views / cpu_view / mirrors::reserved (checked with git grep over crates/xcl/src and crates/xcl/tests). hle::kernelx:: and hle::d3d12x::title_textures:: run together on 4 threads: 136 passed, 0 failed, 2 ignored. The regression blocks are rerun on the new head (description updated).

AI use: Claude Code, Claude Opus 5.5 (the change, the runs and this reply).

@Foniass

Foniass commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

Follow-up review of ad7c0a89, since 7a59f45e (code reading only, not a merge-check) · no new findings

In short: This push fixes the test point from my last review. paged_rechecks_keep_to_the_frame_budget now uses views of 233 * PAGE, which no other test uses, so it can no longer pair with kernelx's views. Nothing else changed, and nothing blocks it.

Checked and fine
  • Earlier finding fixed: the budget test reused 199 * PAGE from gpu_view_pages_record_the_physical_page_mapped_into_them. 233 * PAGE appears nowhere else in the crate's tests. The other paged_views sizes (179, 181, 191, 193, 197) are unchanged and also unique.
  • The earlier fixes (no baseline-less entries for paged partial uploads, the 32-per-frame cap, the corrected comments) are unchanged.

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

@fromthemoonx

fromthemoonx commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

merge-check
base: 395405e
head: ad7c0a8
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 3015 passed, 0 failed, 56 ignored (base: 3012 passed, 0 failed, 56 ignored); SKIPPED: 25, the same as base (22 no wave64, 2 no heap windows, 1 no GPU_UPLOAD heaps); failing: none
review: read the whole diff (1 file, +190 -12). The fix works, but it also uploads whole textures again when nothing was missed.

  1. Medium: a paged texture whose writes are seen goes up whole again at the next milestone. A partial upload leaves the baseline of the last whole upload in place. At the next milestone the fingerprint differs because of the bytes that partial upload already sent, so the texture is queued whole and its schedule starts again. Main does not do this, because it keeps paged textures out of the schedule.
    Measured with a scratch test: a 1 MiB paged texture on a real device, going through refresh, with the frame number set by the test. Same numbers in 3 of 3 runs:
case main this PR this PR + the change below
a write the watch does not report (I reset the watch after it) never arrives arrives arrives
one 4 KiB page written each frame, new bytes every other frame, 400 frames 12.5 MiB, 0 whole 111.5 MiB, 99 whole 12.5 MiB, 0 whole
the same page written every 30th frame, 400 frames 0.9 MiB, 0 whole 13.9 MiB, 13 whole 0.9 MiB, 0 whole

A change that fixes it: when a paged texture's fingerprint differs, do not set pending. Add its 4 KiB pages to this look's dirty pages instead. texture_upload::changed then compares them with what was last sent (known) and sends only what differs. I ran only the scratch test above with it, and stream_recheck_catches_a_late_write_under_a_paged_texture asserts pending, so it would need a change.
2) GPU-written paged textures are safe: the recheck drops them from the schedule, and checks again before it queues one.
3) title_textures tests at 8 threads: no failure in 4 runs (base: 4). The tests with paged in their name: no failure in 20 runs.
4) Not tested: a retail title (none on this machine), AMD. So I do not know how often a title writes paged textures this way.
performance: more upload traffic by default for paged textures that are written after their first upload, see 1). The cost of the fingerprints themselves was not measured; it is capped at 32 textures a frame.
verdict: not yet: whole re-uploads of paged textures whose writes were already sent (point 1)
hardware / tool and model: RTX 3060 12 GB (610.88), Ryzen 7 5700X, Windows 11 Pro 26300 / Claude Code (Claude Opus 5.5)

@Lakanya point 1 needs a change; the rest is fine.

The change I tried (scratch code, not polished)
// recheck_streamed_unwatched_at, where a changed entry is queued:
if e.paged && !e.gpu_written && !e.pending {
    let end = e.src + e.tex.size() as usize;
    FOUND.lock().unwrap().extend((e.src & !0xFFF..end).step_by(0x1000));
    queued += 1;
} else if !e.gpu_written && !e.pending { /* as now */ }

// refresh, right after recheck_streamed_unwatched(&ranges, recheck_frame):
let found = std::mem::take(&mut *FOUND.lock().unwrap());
let dirty_len = if found.is_empty() { dirty_len } else {
    DIRTY_BUF.with(|c| { let mut d = c.borrow_mut(); d.extend(found); d.sort_unstable(); d.dedup(); d.len() })
};

@github-actions github-actions Bot removed the needs-1st-check Passes gates; needs first independent merge-check (#3041) label Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:d3d12 D3D12.X runtime, command lists, resources, sparse memory gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants