Skip to content

D3D12.X: tighten write-watch merge gap to 4 MiB and add opt-in cold-chunk tiering - #2891

Open
Saksukella wants to merge 260 commits into
xcl-dev:amd-devfrom
Saksukella:perf/write-watch-hot-cold-tiering
Open

Saksukella wants to merge 260 commits into
xcl-dev:amd-devfrom
Saksukella:perf/write-watch-hot-cold-tiering

Conversation

@Saksukella

@Saksukella Saksukella commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Tightens title_textures MEM_WRITE_WATCH range 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 to amd-dev.

Summary of changes (crates/xcl/src/hle/d3d12x/title_textures.rs)

  1. Always-on 4 MiB merge gap (WATCH_GAP = 4 << 20):
    • Tightens WATCH_GAP from 64 MiB to 4 MiB without skipping any watched range on any submit, reducing GetWriteWatch scan footprint (~2.28x faster in the 1.5 GiB resident microbenchmark) with zero stale-read risk.
    • When XCL_WRITE_WATCH_TIER is off (the default), cached_watch_ranges() skips 16 MiB chunk splitting so there is zero extra syscall overhead.
  2. Opt-in hot/cold 16 MiB chunk tiering (XCL_WRITE_WATCH_TIER=1, default 0; XCL_WRITE_WATCH_COLD_STRIDE, default 1):
    • Chunks start hot and demote to cold after 16 consecutive clean looks; any dirty page immediately promotes a chunk back to hot.
    • Replaces thread-local SKIP_LOOK: Cell<bool> with LOOK_HINT: Cell<LookHint> (DirectFull, Skip, Normal, ForceFull) so even when XCL_WRITE_WATCH_TIER=1 is enabled, repeated closed-list resubmits (*submitted == true), untracked lists, XCL_LOOK_SKIP=0, and direct refresh() calls without decide_look() (KickoffX) force a full cold sweep on the current submit.

Tested

  • Unit tests (cargo test -p xcl --lib title_textures -- --test-threads=1): 39 passed; 0 failed across all write-watch, tiering, resubmit hint, and D3D12 GPU upload tests (title_bytes_are_used_in_place_when_all_are_readable is a pre-existing unrelated failure on amd-dev base).
    • New regression tests:
      • same_frame_cold_write_updates_before_present_by_default (verifies same-frame cold-page mutations before Present are caught immediately both in default mode and in tier=1 with force_cold=true).
      • decide_look_forces_full_sweep_on_resubmitted_list_and_direct_refresh (verifies DirectFull, Skip, Normal, and ForceFull transitions).
  • Offline 1.5 GiB resident MEM_WRITE_WATCH microbenchmark (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):
    • Baseline (64 MiB gap, tier=OFF): 47.89 ms (0.479 ms/submit, 1.00x)
    • Default (4 MiB gap, tier=OFF): 20.98 ms (0.210 ms/submit, 2.28x)
    • Opt-in (XCL_WRITE_WATCH_TIER=1, stride=1): 8.19 ms (0.082 ms/submit, 5.85x)
    • Opt-in (XCL_WRITE_WATCH_TIER=1, stride=4): 3.74 ms (0.037 ms/submit, 12.82x)

Not tested

  • Non-AMD GPUs (NVIDIA / Intel) on the updated commit b570a92e.
  • Multi-hour soak runs with XCL_WRITE_WATCH_TIER=1 and XCL_WRITE_WATCH_COLD_STRIDE > 1.

Regression run
Baseline (main, b49be183):

xcl-smoke v1
commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7
gpu: AMD Radeon RX 9070 XT
title: b8db18c2
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: 19700 MB

This PR (b570a92e, default settings):

xcl-smoke v1
commit: b570a92e1896104b8754d97fd5feab0793399713
gpu: AMD Radeon RX 9070 XT
title: b8db18c2
seconds: 60
exit: 0x0
frames shown: 1613 (PresentX 1613)
presents per 2 s (last 3): 63 61 60
device removals: 0
crashes: 0
peak commit: 13089 MB

AI use

  • Drafted and reviewed the implementation, unit tests, and benchmark harness with AI assistance; all tests, benchmarks, and hardware smoke runs were executed and verified locally on AMD Radeon RX 9070 XT.

ivall and others added 30 commits November 25, 2026 13:03
…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>
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>
@thehollowedone

Copy link
Copy Markdown
Contributor

I found a correctness gap on exact head 0246ae436afd1397a0672ca5ee6a4b7eabaca847. After a watched texture's chunk cools, a CPU write to its existing source can be deferred until a shown frame advances. That is not necessarily the next GPU execution: a title can submit the same closed list again before Present, and decide_look explicitly requests a fresh look on that resubmission. scan_chunks still skips the cold chunk because present::presents() has not changed; with no other dirty pages or pending uploads, refresh_once returns before updating the texture. Repeated submits before the first shown frame could keep using the old pixels. This is a source-level execution path; I did not confirm pixel output in a retail run.

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, cargo test -p xcl --lib cold_watch_does_not_defer_a_required_same_frame_look -- --test-threads=1 --nocapture fails as expected: 0 passed, 1 failed, 0 ignored, 0 skipped (a required look must not defer a CPU write until Present). The PR's existing hot_cold_tiering filter passed 3/0/0/0, and watch_gap_4mib_does_not_overbridge_64mib_hole passed 1/0/0/0. These are local Windows CPU tests on a Ryzen 7 9800X3D / RTX 3080 Ti machine; they do not exercise the GPU upload/readback path.

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.

@thehollowedone

Copy link
Copy Markdown
Contributor

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 MEM_WRITE_WATCH fixture at 0246ae436afd1397a0672ca5ee6a4b7eabaca847.

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 cargo test -p xcl --lib bench_write_watch_hot_cold_tiering -- --test-threads=1 --nocapture. The comparison includes the PR's chunk iteration with tier_on=false, so every chunk is still scanned on each non-skipped look. It does not measure a title run, GPU output, or end-to-end FPS.

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 diff
diff --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 &regions {
+                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 &regions {
@@ -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.

rootw0rm pushed a commit to rootw0rm/xcl that referenced this pull request Nov 26, 2026
…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.
rootw0rm pushed a commit to rootw0rm/xcl that referenced this pull request Nov 26, 2026
rootw0rm pushed a commit to rootw0rm/xcl that referenced this pull request Nov 26, 2026
rootw0rm pushed a commit to rootw0rm/xcl that referenced this pull request Nov 26, 2026
@Gevroska

Gevroska commented Nov 27, 2026 •

Copy link
Copy Markdown

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.

@JJAutoCompare

Copy link
Copy Markdown

Tested: Clean 0246ae436afd1397a0672ca5ee6a4b7eabaca847, Windows 11 build 26200.9974, Ryzen 7 3800X, Intel Arc A770 driver 32.0.101.9175, Rust 1.100.0 MSVC debug. Built cargo test --locked -j 2 -p xcl --lib --no-run and ran hle::d3d12x::title_textures::tests::gpu_mirror_upload_follows_cpu_writes_and_later_mapping_changes --exact --test-threads=1 --nocapture with tiering enabled, cold stride 1, and XCL_ADAPTER=A770. One passed, zero failed, ignored or skipped. The hot-source R8 readback matched the CPU writes, the later physical mapping and the restored CPU view after unmapping.

Not tested: Cold-source modification and resubmit before Present, full suite, retail smoke and performance.

AI use: T3 Code / Codex (gpt-6.2-sol) ran and reran the checks and wrote this report.

@andrewDoing

Copy link
Copy Markdown
Contributor

On head 0246ae436afd1397a0672ca5ee6a4b7eabaca847, I confirmed the earlier same-frame scheduling finding with a native RTX 5070 texture readback. With the default write-watch tier enabled, all 4,096 texels retained their old value after the CPU modified a cold source and the same closed command list was resubmitted before Present. Earlier scheduling test

I extended the existing gpu_mirror_upload_follows_cpu_writes_and_later_mapping_changes test in an isolated checkout. The test registered a synthetic 64 × 64 R8 texture backed by write-watched CPU memory and verified two hot uploads. It then closed a real empty direct command list and resubmitted it 18 times, calling the production look decision and refresh functions and waiting for a GPU readback after each submit. The test confirmed the source chunk was cold. I changed all source bytes from 0x9A to 0xC7, confirmed the resubmitted list required a look, and read the texture back after its fence. The shown-frame counter stayed at zero throughout.

Setting Old texels (0x9A) Updated texels (0xC7) Expected-content assertion
XCL_WRITE_WATCH_TIER=1 4,096 0 Failed
XCL_WRITE_WATCH_TIER=0 0 4,096 Passed

Each row was a fresh process using the same debug test binary, XCL_LOOK_SKIP=1, and XCL_COLD_WATCH_STRIDE=1. Neither run skipped. This exercises native GPU texture visibility through the production refresh helpers with a test-controlled submission schedule. No retail title, frame timing, or post-Present recovery was tested.

AI use: OpenAI Codex with GPT-6.2 Astra adapted the fixture, ran the paired checks, and prepared this report.

@andrewDoing

Copy link
Copy Markdown
Contributor

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 GetWriteWatch, and required looks also occur on paths beyond repeated-list tracking, including direct KickoffX refreshes.

In three fresh synthetic processes on the same test fixture, unset/default and XCL_WRITE_WATCH_TIER=0 each updated all 4,096 texels before Present and passed the existing mapping/restoration checks. Explicit =1 retained all 4,096 stale texels and failed the expected-content assertion. Thus this contains the problem by default; it does not repair the experimental tier. The explicit-tier negative run must not be counted as a passing suite.

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.

@vibryxcx

Copy link
Copy Markdown

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 0246ae43 on its base amd-dev bf7c82ee. Command: cargo test -p xcl --lib -- --test-threads=1, skipping tests that hang or abort only inside the full amd-dev run (listed in #42).

  • Result: 1639 passed, 11 failed, 27 ignored, 7 filtered out.
  • Against base bf7c82ee run the same way: the 11 failures are all ones the base has. The base's 12th, gpu_uploads_on_the_title_queue_run_before_its_later_work_and_are_released, passed here, and it is the known flaky one on this card (D3D12.X: amd-dev readback waits: no stale wake-up, no buffer freed under a queued copy #2842).
  • bench_write_watch_hot_cold_tiering, hot_cold_tiering_promotes_on_dirty_and_catches_cold_writes_at_frame_boundary, hot_cold_tiering_starts_new_ranges_hot and watch_gap_4mib_does_not_overbridge_64mib_hole pass. So do the existing write-watch tests (write_watched_memory_lives_beside_views_in_one_placeholder, gpu_visible_fallback_memory_is_write_watched).

Not tested: a title run (I am not running the title right now); cold_watch_does_not_defer_a_required_same_frame_look from the comment above (not in this head).

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.

@oni-swr

oni-swr commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

RX 7800 XT, amd-dev bf7c82ee against the same plus #2891 head 0246ae43 (merged locally, clean): write-watch time per submit, menu and loading phase only.

  • RX 7800 XT (RDNA3), driver 32.0.31035.1003, Windows 11 build 26200, AMD Ryzen 7 5700X3D, 64 GB, release builds. Retail title, same copy of a warm shader cache and of the profile for every run (fresh copy each time). XCL_NETWORK=0 XCL_ACTIVITY=1 XCL_PREPARE=0 XCL_GFX_PSO_WAIT_MS=200, scripted A presses every 8 s from 16 s, 300 s runs, nothing else running. Two runs per arm, interleaved base, head, base, head.
  • Window: the windows with presents before the title stalled, about 90-100 s in each run (42-47 windows of 2 s, about 7,200-8,100 submits). The title did not reach the world in these runs, so this is the menu and loading phase, not in-world frame time.
run write-watch ms per submit submit ms per submit write-watch ms per 2 s
base 1 2.28 6.89 375
head 1 1.25 6.27 204
base 2 2.23 6.46 386
head 2 1.15 5.89 202

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 cargo test run (only the 4 tiering/gap tests passed on CPU), NVIDIA, other AMD parts.

AI use: Claude Code (Claude Sonnet 5.5) ran the runs and wrote this.

@andrewDoing

Copy link
Copy Markdown
Contributor

For the timing question in the latest report: head 0246ae436afd1397a0672ca5ee6a4b7eabaca847 does have a tier switch. XCL_WRITE_WATCH_TIER=0 disables cold-chunk tiering, while the 4 MiB WATCH_GAP change remains active. XCL_WRITE_WATCH_TIER=1 enables tiering (also the current default when unset). The setting is read once per process.

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.

@oni-swr

oni-swr commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

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 0246ae43 merged on amd-dev bf7c82ee (RX 7800 XT, driver 32.0.31035.1003, Windows 11 build 26200, Ryzen 7 5700X3D, release), same warm cache copy and profile per run, XCL_NETWORK=0 XCL_ACTIVITY=1 XCL_PREPARE=0 XCL_GFX_PSO_WAIT_MS=200, scripted A presses, 150 s runs, order tier 1, tier 0, tier 1, tier 0. Windows with presents before the title stalled (41-43 windows of 2 s, about 7,300-7,500 submits per run). Menu and loading phase only; the title did not reach the world.

XCL_WRITE_WATCH_TIER run write-watch ms per submit submit ms per submit
1 (default: gap and cold tier) a 1.37 5.82
0 (4 MiB gap only) a 2.45 6.86
1 b 1.20 5.56
0 b 2.40 6.88

For reference, the plain amd-dev base in my earlier comment was 2.28 and 2.23 ms per submit. So on this card the 4 MiB gap alone did not change write-watch time (2.4 against 2.25, within the run-to-run spread I see), and the whole saving, about 1.1 ms per submit (45 %), comes with the cold tier on. That is the part with the same-frame stale-write finding from @thehollowedone and @andrewDoing. If the tier becomes opt-in as proposed, the gain on RDNA3 in this phase goes with it.

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.

@Saksukella Saksukella changed the title D3D12.X: tighten write-watch merge gap to 4 MiB and tier cold 16 MiB chunks to frame boundaries D3D12.X: tighten write-watch merge gap to 4 MiB and add opt-in cold-chunk tiering Nov 27, 2026
@Saksukella

Copy link
Copy Markdown
Contributor Author

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:

  1. \WATCH_GAP = 4 MiB\ stays always enabled (default mode gives ~2.28x speedup in the 1.5 GiB resident microbenchmark with identical same-frame freshness to \�md-dev\ and skips 16 MiB chunk splitting when tiering is off).
  2. \XCL_WRITE_WATCH_TIER\ is now opt-in (\default 0, enable via \XCL_WRITE_WATCH_TIER=1) so setups that want the extra cold-chunk win @oni-swr measured on RX 7800 XT can opt in explicitly.
  3. *Forced full cold sweep on resubmits and \KickoffX* even when \XCL_WRITE_WATCH_TIER=1\ is enabled, via thread-local \LookHint\ (\DirectFull\ / \ForceFull\ / \Normal\ / \Skip).
  4. New regression tests (\same_frame_cold_write_updates_before_present_by_default\ and \decide_look_forces_full_sweep_on_resubmitted_list_and_direct_refresh) + fresh 60 s smoke on RX 9070 XT (\1613\ frames, \63 61 60, \

@andrewDoing

andrewDoing commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

On revised head b570a92e, an unchunked default write-watch range larger than the 16,384-entry output buffer still returned every dirty page. I exercised the actual take_written and range-selection helpers against Windows MEM_WRITE_WATCH on a Ryzen 7 5700X3D. Seven runs per layout, tiering disabled for the parent/head comparison.

  • 68 MiB span: one byte written in each of 17,408 pages. The immediate parent (0246ae43) queried aligned chunks; the revision queried one logical span and continued past the full output buffer. Both returned 17,408 distinct pages in every run. Median collection times: 486 µs parent, 427 µs head.
  • Scattered writes: three wanted 4 KiB ranges, starting 16 MiB apart. I wrote one byte in each and one byte in each of two intervening pages. The original 64 MiB merge policy queried 32 MiB + 4 KiB and returned five pages (median 23 µs). The parent's and head's 4 MiB policy queried 12 KiB and returned exactly the three wanted pages (10 and 9 µs respectively).

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 upload_all and counted payload bytes at the staging row copies and regions at CopyTextureRegion. The unchanged-skip policy was at its default.

One-byte store Logical query Dirty pages Bytes hashed Bytes copied into staging Copy regions
0 → 0 90,112 B 1 4,096 B 0 0
0 → 1 90,112 B 1 4,096 B 87,380 B 8
1 → 1 90,112 B 1 4,096 B 0 0

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 (92985481): the 87,380-byte whole-chain measurement above is specific to this PR branch. Main already defaults to selective uploads via texture_upload. On the same RTX 5070 and 128×128 eight-mip RGBA8 layout, I fed the production uploader the 4 KiB source-page range containing one changed byte and compared with a whole upload to a second resource:

Change Subresources copied Texel payload Staging footprint
Mip 0, outside tail 0 4,096 B 8,192 B
Mip 7, shared tail page 3–7 1,364 B 7,936 B
Whole upload control 0–7 87,380 B 98,304 B

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.

raylitebull pushed a commit that referenced this pull request Nov 29, 2026
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>
KOLESNiii added a commit to KOLESNiii/xcl that referenced this pull request Nov 29, 2026
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>
@brainhay5

Copy link
Copy Markdown

Triage note: this no longer merges with current main (mergeable=false, DIRTY).

Worth knowing before you spend time on a rebase: #3242 ports this and #2754 to current main and is mergeable, though currently blocked. So the change is represented there — whether to keep this one alive in parallel or defer to the port is your call.

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 main.

AI use: an agent posted this triage note.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Triage (#1607) – head b570a92

The 4 MiB WATCH_GAP part is already on amd-dev: 3bb095a ("D3D12.X: write-watch ranges merge across gaps of up to 4 MiB, not 8") cites this PR's benchmark. The opt-in XCL_WRITE_WATCH_TIER tiering (LookHint, WatchTierState) is not on amd-dev and not in any other open PR.
The branch carries about 210 other commits that are not on amd-dev, including local: experiment commits by other authors. That is why it shares about 2600 added lines with #2859, #2912, #2913, #2981, #2988, #2989, #3023 and others. Only the top two commits (0246ae4, b570a92) are this PR's own; it needs a rebase onto amd-dev with only those two.
In title_textures.rs, the stride is read from XCL_COLD_WATCH_STRIDE, but the description says XCL_WRITE_WATCH_COLD_STRIDE. With the tier off, refresh_once still locks WATCH_TIERS and updates a HashMap for every range on every look.
Recommendation: keep open.

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

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.