Repository navigation
D3D12.X: tighten write-watch merge gap to 4 MiB and add opt-in cold-chunk tiering - #2891
Saksukella wants to merge 260 commits into
Conversation
…s mapped at Without it XCL keeps a physical page at one address at a time and copies it when the title maps it elsewhere; the console shows the page at every address it is mapped at. A retail title maps its streamed pages into a pool, into the CPU view of a 24 GB reservation and into that reservation's GPU view (xcl-dev#1031). With `XCL_PAGE_ALIAS=1` (`kernelx::alias`): - a block of physical pages is a section (`kernelx::sections`) with a view of its own, through which XCL reads and writes pages by number (DirectStorage); the title never maps a page there; - the title's reservations of 64 KiB pages with no commit (its CPU view, GPU view and pool) are placeholders, and a page mapped there is a view of its slice, guarded (`kernelx::guards`) so that a write through one view is uploaded at all of them; `title_textures` adds those pages to what the write watch found; - a page mapped anywhere else (a placeholder region the title made in a sparse window) is moved there and back with its bytes, as before. Pages are committed on first use as before (`kernelx::lazy`); whether a page is committed is a bit per page: asking Windows walked the rest of a fresh block, and a title mapping 100 000 new pages one at a time took 20 s longer to its first frame. Measured in a traced run of a retail title: 3 blocks (11 360, 2 960 and 99 776 pages), 131 072 map calls in 150 s, nearly all single pages into its plain reservations, none at a page's home, no commit inside them.
…GPU-view page shows Queue method xcl-dev#31 (xcl-dev#29 of the older layout) maps pages of the title's memory into GPU views; it was a stub. Its batches are now decoded and checked against the batch count and the pool, and each 64 KiB page of a GPU view records the pool page it was given and the physical page the title had mapped there (kernelx::mirrors). A bad call records nothing; releasing a view drops its pages. XCL keeps a physical page's data where it was mapped last, and the title maps most streamed pages into the CPU view behind the GPU view too, so `mapped_source` answers where that page is now (`page_now`), else the pool page itself. Each title mapping is remembered per address (Away::title), written once the page is in place and forgotten when the reservation goes; a page freed while its allocation lives is no longer looked for (Away::freed). Nothing reads the record yet: textures are unchanged; the queue logs its counts. (xcl-dev#1031) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`mirrors::decode_batches` checks and decodes one call of the queue's CopyPageMappingsBatchX into (GPU-view page, pool page or unmapped) pairs; `apply_batches` records them as before. No change in behaviour: the next commit maps the decoded pages for real when physical pages alias.
The queue's CopyPageMappingsBatchX maps pool pages into GPU views; on the console a GPU-view page then shows the physical page mapped at its pool page at the time of the call. xcl-dev#1055 decodes the calls and keeps a record of them; with physical pages aliasing (`kernelx::alias`) the GPU view is a reservation of views, so the decoded mappings are made for real: each GPU-view page becomes a view of the physical page mapped at its pool page now, or is unmapped (kind 2, or nothing mapped at the pool page). Textures in the GPU view then read the page at their own address (`title_textures` prefers an address with a physical page mapped), and a write through any view of the page is uploaded at all of them. Without the switch nothing changes: the call is recorded as in xcl-dev#1055.
Each chained dispatch made a scratch buffer for all its groups and kept it until the allocator's reset. A retail title's 176 split programs need 187 KB a group (median), 3 GB for 960x540 pixels in groups of 8x4. At most XCL_SPLIT_SCRATCH_MB (256) of groups now run at once, each piece adding the slab's origin to the group ids, and the chains recorded on one list share the buffer.
In a pixel shader EXEC holds helper lanes (s_wqm), and on a primitive's edge the first lane of EXEC is often one. v_readfirstlane read that lane. An RDNA2 driver (RX 6700 XT, 32.0.21045) gives 0 for everything a helper lane holds once a WaveReadLaneAt ran inside a loop, quad reads included. A loop whose state the console's compiler carries in a vector register (v_mov v, s ... v_readfirstlane s, v) then read 0 back on each pass and ran to the loop budget: a retail title's volumetric light pass took seconds per draw at its world start and Windows reset the GPU (xcl-dev#675). v_readfirstlane now reads the first lane of EXEC that is live (ballot(true), per half in the wave32-in-64 form) when EXEC has one, and the first lane of EXEC as before when it has none. The value is the same: the console's compiler reads the first lane of a value equal in every lane, or of a lane it then removes from EXEC (a waterfall loop). The new GPU test draws that title's list-loop shape on two triangles sharing a diagonal. Without the change, on the RX 6700 XT, 69 of 1024 pixels run the loop 65 536 times (the budget) with wrong results; with it, none, and at most 16 passes. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…esent in flight)
A retail game unmaps addresses while it streams its world with
XMemMapPhysicalPagesScatter(addresses, n, NULL); it checks the result
and runs into its own int3 when the call fails (+0xb18de7, then its
crash reporter). XCL refused a NULL page array with
ERROR_INVALID_PARAMETER. Page 0 already means "unmap this address" in a
scatter, so no array is taken as page 0 for every address.
Test scatter_without_pages_unmaps: two pages mapped and written, unmapped
with no array (the call succeeds, the addresses are no longer committed),
mapped again they read what was written. It fails without the change
("refused").
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
I found a correctness gap on exact head I added a test-only schedule that cools one chunk over 16 clean looks, then asks for another look in the same frame after a simulated CPU write. On the unchanged PR logic, The 4 MiB merge-gap change is independently useful. For the default behavior, I suggest keeping cold-chunk skipping opt-in until it can detect the first write before any dependent submit (or otherwise prove the submitted lists do not read that range). A GPU regression should upload an existing texture, fence its first sampling, CPU-write its source, then resubmit and read back before Present. The benchmark here checks that the write is eventually seen at the following frame, which is weaker than that ordering requirement. Failing test-only diff@@ -4229,6 +4229,26 @@ mod tests {
+ #[test]
+ fn cold_watch_does_not_defer_a_required_same_frame_look() {
+ let chunk = (0x3000_0000, WATCH_CHUNK);
+ let mut tiers = WatchTierState::new();
+ for frame in 0..COLD_THRESHOLD as u64 {
+ tiers.scan_chunks(&[chunk], frame, true, 1, |_, _| false);
+ }
+ assert!(tiers.is_cold(chunk));
+
+ // A CPU write after a completed execution must be visible to a second
+ // execution of that list, even if no Present advanced the frame count.
+ let frame = COLD_THRESHOLD as u64 - 1;
+ let mut looked = false;
+ tiers.scan_chunks(&[chunk], frame, true, 1, |_, _| {
+ looked = true;
+ true
+ });
+ assert!(looked, "a required look must not defer a CPU write until Present");
+ }AI use: Codex (GPT-6.2 Sol) traced the execution path, wrote and ran the local test, and drafted this report. Codex (GPT-6.2 Astra) independently checked the source-level schedule. No game files or diagnostics were used. |
|
Follow-up to my same-head correctness report: I measured the 4 MiB merge gap alone, with Hot/Cold tiering disabled, using this PR's existing resident The fixture's 1.5 GiB arenas and 20 frames × 5 submits give 80 non-skipped looks, with 200 hot pages written per submit. Four separate Windows test-process runs: the 64 MiB gap scanned 1,104 MiB/look and took 42.47–43.10 ms total; the 4 MiB gap scanned 384 MiB/look and took 19.28–22.59 ms total, a 1.90–2.20× reduction in this synthetic scan time. Each run returned 1 passed, 0 failed, 0 ignored, 0 skipped for This supports retaining the independently useful gap change while the cold-tier ordering case is resolved. Hardware: Windows 11 build 26300, Ryzen 7 9800X3D; the RTX 3080 Ti was present but this fixture did not use it. Synthetic memory only. Test-only measurement diffdiff --git a/crates/xcl/src/hle/d3d12x/title_textures.rs b/crates/xcl/src/hle/d3d12x/title_textures.rs
index edb1e1e7..53655ef2 100644
--- a/crates/xcl/src/hle/d3d12x/title_textures.rs
+++ b/crates/xcl/src/hle/d3d12x/title_textures.rs
@@ -4315,6 +4315,32 @@ mod tests {
}
let base_ms = base_dur.as_secs_f64() * 1000.0;
+ // Isolate the 4 MiB gap from temperature tiering: scan every chunk
+ // on every non-skipped look, as the opt-out path would do.
+ dirty.clear();
+ for &(b, s) in ®ions {
+ take_written(b, s, &mut buf, &mut dirty, &mut page);
+ }
+ let mut gap_only_tiers = WatchTierState::new();
+ let mut gap_only_dur = std::time::Duration::ZERO;
+ for frame in 0..FRAMES {
+ for sub in 0..SUBMITS_PER_FRAME {
+ dirty_hot_pages(500 + frame * SUBMITS_PER_FRAME + sub);
+ if sub == 4 {
+ continue;
+ }
+ dirty.clear();
+ let t0 = std::time::Instant::now();
+ gap_only_tiers.scan_chunks(&fix_a_chunks, frame, false, 1, |b, s| {
+ let before = dirty.len();
+ take_written(b, s, &mut buf, &mut dirty, &mut page);
+ dirty.len() > before
+ });
+ gap_only_dur += t0.elapsed();
+ }
+ }
+ let gap_only_ms = gap_only_dur.as_secs_f64() * 1000.0;
// Drain any residual writes before Fix A measurement.
dirty.clear();
for &(b, s) in ®ions {
@@ -4415,6 +4441,12 @@ mod tests {
base_ms / total_submits,
base_ms / base_looks as f64,
);
+ println!(
+ " 4 MiB gap, tier=OFF : {:.2} ms total | {:.3} ms/submit | {:.3} ms/look",
+ gap_only_ms,
+ gap_only_ms / total_submits,
+ gap_only_ms / base_looks as f64,
+ );
println!(
" Fix A (4 MiB gap, stride=1) : {:.2} ms total | {:.3} ms/submit | {:.3} ms/look | speedup: {:.2}x",
fix_s1_ms,AI use: Codex (GPT-6.2 Sol) added and ran the measurement and drafted this report. |
…re messages) Upstream xcl-dev#2890 (c6c14a1, single-commit on upstream/main 8b957be): title_under_the_debug_layer prints the last TAIL=40 lines of xcl.log in its three assertion messages and tolerates a missing log file (unwrap_or_default), so a title that never finishes still shows why. Verbatim port of the whole fix (1 file, +24/-4): the TAIL const + tail() helper after the PathBuf import and the three rewritten asserts. Applies cleanly; the only context offset is the linux-only debug_layer_skip_line helper above the hunk. Windows-only siblings xcl-dev#2888 (perf-compare ps1 stack), xcl-dev#2889 (tiling_parity.rs host-driver test, no cfg(windows) gate), xcl-dev#2891 (title_textures.rs write-watch tiering on the 71b8e6e dev-stack) stay out per the step-139 sync entry.
…SKIP, probe past xcl-dev#2891)
|
I checked the existing write-watch timing counters in three runs of the retail game on Windows. Between sparse submits 4,096 and 8,192, the stock collection stage accumulated 7.641 s over 34.133 s in the first run, 7.932 s over 34.133 s in the second, and 36.766 s over 46.047 s in the third. I used the difference between consecutive cumulative samples in each run. The timer includes range and buffer preparation, dirty-page collection, and sorting. All three intervals ended before I confirmed loading. The last timing samples preceded the end of the first verified loading interval by 35, 65, and 78 seconds respectively. This puts substantial collection cost in the menu phase. The saved counters leave the cost during the later loading stall unknown. I did not run a base-versus-PR comparison, so these numbers do not measure the speedup from #2891. I used Codex GPT-6.2 Sol to analyze the saved counters and a separate GPT-6.2 Sol agent to verify the timings against the loading events. Codex GPT-6.2 Astra wrote this comment. |
|
Tested: Clean Not tested: Cold-source modification and resubmit before Present, full suite, retail smoke and performance. AI use: T3 Code / Codex ( |
|
On head I extended the existing
Each row was a fresh process using the same debug test binary, AI use: OpenAI Codex with GPT-6.2 Astra adapted the fixture, ran the paired checks, and prepared this report. |
|
Follow-up to my stale-read report: a local containment candidate makes cold write-watch tiering opt-in and leaves the 4 MiB merge-gap optimization enabled. Ordinary writes to an already registered cold texture have no separate notification before In three fresh synthetic processes on the same test fixture, unset/default and The setting is read once per process, matching existing initialization. Retail performance and GTA VI were not measured. AI use: OpenAI Codex with GPT-6.2 Astra implemented, tested and independently reviewed the local containment; Codex coordinated and prepared this follow-up. |
|
Full lib suite on AMD for this head (the reports above ran single tests and the benchmark). No new failure; the 4 new tiering / gap tests pass. This does not touch the cold-chunk ordering gap that @thehollowedone reported: no test here covers a resubmit before Present. Tested: AMD Radeon RX 6800 (RDNA2, driver 32.0.21045.5002), Windows 11 Pro 26200, Rust 1.100.0, debug. Head
Not tested: a title run (I am not running the title right now); AI use: Claude Code (Claude Opus 5.5) ran the suite through a local test runner, compared it with the base and wrote this comment. |
|
RX 7800 XT,
Write-watch time per submit fell by about 45 % (2.25 to 1.20 ms) and the whole submit by about 8 %. Dirty pages found, commit (about 19 GB) and presents per window were the same in both arms. No device removal, no crash in any of the four. This measures the default build of the PR, so the merge gap and the cold tier are not separated (no toggle on this head). I did not look at output (no readback), so I cannot confirm or rule out the stale-texture finding from @thehollowedone and @andrewDoing above; that bug is a correctness reason to hold the cold tier regardless of this timing. Not tested: the world, the cold-tier resubmit case, a full AI use: Claude Code (Claude Sonnet 5.5) ran the runs and wrote this. |
|
For the timing question in the latest report: head If the same warmed workload can be repeated, a base / head-with-0 / head-with-1 comparison could separate the merge-gap contribution from the incremental tiering contribution. My earlier synthetic same-frame cold-write readback found stale texels with tiering enabled, so please keep that correctness limitation in view; it did not measure the retail run or explain its timing. AI use: OpenAI Codex with GPT-6.2 Astra checked the switch and source; Codex coordinated and prepared this follow-up. |
|
Split of the #2891 write-watch gain on an RX 7800 XT: the cold tier, not the 4 MiB gap (answering @andrewDoing's switch above). Same machine, head
For reference, the plain Not tested: the world, output correctness (no readback), the cold-write resubmit case, other cards. Two runs per arm. AI use: Claude Code (Claude Sonnet 5.5) ran the runs and wrote this. |
|
Thanks @thehollowedone, @andrewDoing, and @oni-swr for the detailed testing, A/B splits, and readback repros! Pushed \�570a92e\ addressing the same-frame cold-write + closed-list resubmit / \KickoffX\ edge case:
|
|
On revised head
Queried bytes are summed logical address ranges; continuing after a full output buffer issues another OS call for the remaining suffix. The timing covers collection only. This fixture performed no texture staging and measures neither bytes read internally by Windows nor title performance. AI assistance: OpenAI Codex traced the code, constructed and ran the native controls, and drafted this report. Downstream staging control on the same head (native RTX 5070). I warmed a 128×128 RGBA8 texture with eight mip levels, then wrote one byte per look in its 90,112-byte tiled source. I passed the real GetWriteWatch page result into production
The 87,380 B is the sum of the actual mip payloads, excluding D3D12 row/placement padding. A changed page currently selects the whole texture for detiling and upload, while a same-value page is filtered before staging. This identifies separate counters for profiling a title: query extent, bytes hashed, and actual staging payload/regions. The test waited for the direct queue to finish; no pixel readback or timing comparison was performed. Current main comparison (
After each arm I fenced the queue, read all eight mips back, and compared every byte with the independent linear source pixels. All matched. This was a CPU-backed texture and checked the uploader after page selection; it did not measure GPU-owned aliases, automatic dirtiness discovery, or frame time. |
Port of what remains of #2891 by Saksukella (amd-dev commits 0246ae4 and b570a92) on main: its 4 MiB merge gap. They measured a 1.5 GiB resident write-watch benchmark at 2.28x faster with a 4 MiB gap than with amd-dev's 64 MiB; main had already gone to 8 MiB. Not ported: #2891's opt-in hot/cold 16 MiB chunk tiering and its cold sweep on resubmitted lists. Main has the tiering in another form (XCL_WATCH_HOT, on by default: a look takes the 2 MiB blocks written recently and a thread walks the rest), and #2891 forced the cold sweep only under its own opt-in switch; on main it would bring back the full look (4-7 ms) the walk replaced. With XCL_WATCH_HOT on, a look's calls use hot_gap (64 MiB); this gap shapes the watched ranges whose blocks the walk takes, and every look with XCL_WATCH_HOT=0. Main's comment puts the break-even of one call at 5-9 MiB of gap, so the effect is expected to be small either way: to be measured. Test: watch_ranges_merge_at_the_gap_limit_and_split_past_it (ranges 6 MiB apart are two scans; fails at 8 MiB). Co-authored-by: Saksukella <98151720+Saksukella@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Port of what remains of xcl-dev#2891 by Saksukella (amd-dev commits 0246ae4 and b570a92) on main: its 4 MiB merge gap. They measured a 1.5 GiB resident write-watch benchmark at 2.28x faster with a 4 MiB gap than with amd-dev's 64 MiB; main had already gone to 8 MiB. Not ported: xcl-dev#2891's opt-in hot/cold 16 MiB chunk tiering and its cold sweep on resubmitted lists. Main has the tiering in another form (XCL_WATCH_HOT, on by default: a look takes the 2 MiB blocks written recently and a thread walks the rest), and xcl-dev#2891 forced the cold sweep only under its own opt-in switch; on main it would bring back the full look (4-7 ms) the walk replaced. With XCL_WATCH_HOT on, a look's calls use hot_gap (64 MiB); this gap shapes the watched ranges whose blocks the walk takes, and every look with XCL_WATCH_HOT=0. Main's comment puts the break-even of one call at 5-9 MiB of gap, so the effect is expected to be small either way: to be measured. Test: watch_ranges_merge_at_the_gap_limit_and_split_past_it (ranges 6 MiB apart are two scans; fails at 8 MiB). Co-authored-by: Saksukella <98151720+Saksukella@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Triage note: this no longer merges with current Worth knowing before you spend time on a rebase: #3242 ports this and #2754 to current Flagging it so the choice is visible; I only need one of the routes to be buildable so the write-watch range change can be measured on current AI use: an agent posted this triage note. |
|
The 4 MiB AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human. |
Tightens
title_texturesMEM_WRITE_WATCHrange coalescing (WATCH_GAP) from 64 MiB to 4 MiB so sparse texture allocations no longer over-bridge huge unrelated address gaps, and adds an opt-in 16 MiB hot/cold chunk tiering mode (XCL_WRITE_WATCH_TIER=1) that moves clean cold chunks to frame boundaries while keeping default same-frame freshness identical toamd-dev.Summary of changes (
crates/xcl/src/hle/d3d12x/title_textures.rs)WATCH_GAP = 4 << 20):WATCH_GAPfrom 64 MiB to 4 MiB without skipping any watched range on any submit, reducingGetWriteWatchscan footprint (~2.28x faster in the 1.5 GiB resident microbenchmark) with zero stale-read risk.XCL_WRITE_WATCH_TIERis off (the default),cached_watch_ranges()skips 16 MiB chunk splitting so there is zero extra syscall overhead.XCL_WRITE_WATCH_TIER=1, default0;XCL_WRITE_WATCH_COLD_STRIDE, default1):SKIP_LOOK: Cell<bool>withLOOK_HINT: Cell<LookHint>(DirectFull,Skip,Normal,ForceFull) so even whenXCL_WRITE_WATCH_TIER=1is enabled, repeated closed-list resubmits (*submitted == true), untracked lists,XCL_LOOK_SKIP=0, and directrefresh()calls withoutdecide_look()(KickoffX) force a full cold sweep on the current submit.Tested
cargo test -p xcl --lib title_textures -- --test-threads=1):39 passed; 0 failedacross all write-watch, tiering, resubmit hint, and D3D12 GPU upload tests (title_bytes_are_used_in_place_when_all_are_readableis a pre-existing unrelated failure onamd-devbase).same_frame_cold_write_updates_before_present_by_default(verifies same-frame cold-page mutations beforePresentare caught immediately both in default mode and intier=1withforce_cold=true).decide_look_forces_full_sweep_on_resubmitted_list_and_direct_refresh(verifiesDirectFull,Skip,Normal, andForceFulltransitions).MEM_WRITE_WATCHmicrobenchmark (cargo test -p xcl --lib bench_write_watch_hot_cold_tiering -- --ignored --nocapture, 20 frames x 5 submits = 100 submits / 80 looks, 0 missed dirty pages):64 MiBgap,tier=OFF):47.89 ms(0.479 ms/submit,1.00x)4 MiBgap,tier=OFF):20.98 ms(0.210 ms/submit,2.28x)XCL_WRITE_WATCH_TIER=1,stride=1):8.19 ms(0.082 ms/submit,5.85x)XCL_WRITE_WATCH_TIER=1,stride=4):3.74 ms(0.037 ms/submit,12.82x)Not tested
b570a92e.XCL_WRITE_WATCH_TIER=1andXCL_WRITE_WATCH_COLD_STRIDE > 1.Regression run
Baseline (
main,b49be183):This PR (
b570a92e, default settings):AI use