Skip to content

D3D12.X: omit VRAM-only sparse tiles and GPU-written textures from write-watch ranges - #2754

Closed
Saksukella wants to merge 203 commits into
xcl-dev:amd-devfrom
Saksukella:fix/write-watch-skip-vram-and-gpu-textures
Closed

Saksukella wants to merge 203 commits into
xcl-dev:amd-devfrom
Saksukella:fix/write-watch-skip-vram-and-gpu-textures

Conversation

@Saksukella

@Saksukella Saksukella commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

What is in it

  • crates/xcl/src/hle/d3d12x/sparse.rs:
    • Extract watchable_tile_runs(mapped) and exclude VRAM-only tiles (holes == 0xFFFF, never CPU-committed) from mapped_ranges() so GetWriteWatch skips purely GPU-resident sparse tiles.
    • In drain_lazy_commits(), invalidate self.runs and bump MAPPED_GEN when a lazily CPU-committed tile transitions off holes == 0xFFFF.
    • Add drain_lazy_commits_if_pending() (zero-lock Acquire fast path when no lazy commits are pending) so refresh_once() reflects newly CPU-committed tiles on the very first submit without a 1-submit delay.
    • Add CPU unit test watchable_tile_runs_omits_vram_only_holes_until_unmasked.
  • crates/xcl/src/hle/d3d12x/title_textures.rs:
    • Add Table::watchable_ranges(&self) excluding e.gpu_written render targets / UAV textures from cached_watch_ranges(), bump TEXTURES_GEN in note_gpu_write() when a texture becomes GPU-written, and call sparse::drain_lazy_commits_if_pending() before cached_watch_ranges(u) in refresh_once().
    • Add CPU unit test watchable_ranges_excludes_gpu_written_textures.
  • Target branch: amd-dev (where alloc_vram_only / drain_lazy_commits live).

Tested

  • Hardware: AMD Radeon RX 9070 XT (driver 32.0.32029.2010), 24-thread x86_64 CPU, 32 GB RAM, Windows; rustc 1.100.0 (0ef1bc386 2026-11-09); debug (tests) and release (xcl.exe).
  • cargo test -p xcl --lib watchable_tile_runs_omits_vram_only_holes_until_unmasked: 1 passed, 0 failed (0.00s).
  • cargo test -p xcl --lib watchable_ranges_excludes_gpu_written_textures: 1 passed, 0 failed (0.00s).

Regression run

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
xcl-smoke v1
commit: 891c97a572505514237fe6424416e4ff8be341b4
gpu: AMD Radeon RX 9070 XT
title: b8db18c2
seconds: 60
exit: 0x0
frames shown: 1671 (PresentX 1671)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15086 MB

Not tested

  • NVIDIA and Intel GPU adapters (tested on AMD Radeon RX 9070 XT only).

AI use

  • Antigravity (Google Gemini): assisted with auditing GetWriteWatch range collection, catching the first-submit drain_lazy_commits ordering hazard, writing the patch and unit tests, and running local tests and smoke verification. All diffs and measurements were verified locally on hardware.

isaacwingate and others added 30 commits November 25, 2026 07:22
pso_async means a graphics pipeline still being built to go on with its
stand-in, which draws nothing, while a worker builds it; only compute
pipelines are waited for (a skipped dispatch would leave its outputs
unwritten). But graphics_bound and ExecuteIndirect called resolve_wait,
which waits for the build - and builds it on the title's thread when no
worker has started it. With lazy pipelines that is every graphics
pipeline's first draw.

On an NVIDIA GPU the retail title of xcl-dev#505 had its threads held 1 - 5 s
per draw in the driver's compiler as its world loaded: 25 graphics binds,
33.2 s in all within 25 s (counted with xcl-dev#899's log), and its hang
watchdog ended the run. A test report on xcl-dev#889 (RTX 4080) found a title
thread held in bind::execute_indirect -> resolve_wait at the abort.

Draws and ExecuteIndirect now take their pipeline with resolve_for_bind:
a graphics one still being built goes to the workers and the draw uses
its stand-in (ExecuteIndirect skips, as it already did for a pending
one); a compute one is waited for as before. With this, the same world
load logged no graphics wait.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…addresses

On the console a physical page mapped at several addresses is one page. XCL
keeps a page at one address at a time and copies it when the title maps it
elsewhere (`move_away`), so the other addresses go stale; 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).

`kernelx::sections` is the base for real aliasing: a block of physical pages
is one pagefile-backed SEC_RESERVE section, and a page is mapped as a view of
its 64 KiB slice into a placeholder (MapViewOfFile3 with
MEM_REPLACE_PLACEHOLDER). Every view of a slice is the same memory and a page
takes commit once, when it is committed through any view. Unmapping leaves a
placeholder for the next view. Ordinary reserved memory (write-watched if
asked) can replace part of a placeholder and go back to one.

Nothing calls it yet. Measured in a standalone program on Windows 11 26200
over 200 000 pages: map 2.2 us, unmap 2.75 us, commit 0.9 us a page.
GetWriteWatch refuses a range that holds a view (error 87), and one call
cannot span two neighbouring reservations either.
The upload of title memory to video memory (`d3d12x::sparse`) and the
textures kept in step with title memory learn what the CPU wrote from the
write watch, and a view of a section (`kernelx::sections`) cannot be
write-watched: GetWriteWatch refuses any range that holds one.

`kernelx::guards` keeps the views of a physical page read-only. The first
write through any of them faults; a vectored handler makes that view
writable, notes the page and lets the write go on. `take_dirty` hands over
the pages of every view of each page written – a write through one view is
a write to all of them – and guards those views again before their bytes are
read, so a later write is caught again and an earlier one is in what is read.

Kernel calls do not fault into the handler, they fail: `lazy::ensure`, which
XCL already calls before a kernel call or its own code writes title memory,
opens the guards there first and counts the write. A view committed by the
lazy handler is writable and counts as written. Both take no lock until a
view has been watched.

Nothing watches a view yet.
… fault

A guarded view of a physical page (`kernelx::guards`) is read-only until it
is written. Code of XCL's own that writes there faults into the guard and
goes on, but a kernel call does not fault: ReadFile into such a view fails.
`lazy::ensure` opened the views first, yet the submit thread's `take_dirty`
could guard them again before the write – between DirectStorage's check of
its destination and the copy, or before the kernel wrote a ReadFile buffer.

`guards::open` now returns `Opened`, which keeps its views writable until it
is dropped; `take_dirty` uploads a pinned view but does not guard it again,
and the end of the write counts as a write. `lazy::ensure` returns it and its
callers hold it across their write: the routed ReadFile for a synchronous
read, and the destination checks of DirectStorage and the CPU-side
bottom-of-pipe writes. An overlapped ReadFile writes after the call returns:
its views stay open until its OVERLAPPED is no longer STATUS_PENDING, which
`take_dirty` reads without faulting (the title may free it once done). A
retail title reads 271 MB that way into the CPU view of its 24 GB
reservation 8.5 s after start.

`guards::written` counts a page as written through all its views when XCL
writes it by page number.

Nothing watches a view yet, so nothing changes without views.
…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>
raylitebull and others added 6 commits November 26, 2026 02:03
placed_srv_resource and placed_uav_resource returned uncounted raw ID3D12Resource pointers after dropping TABLE.lock(), and on a concurrent cache-miss race entry(key).or_insert(res) dropped the losing resource inside TABLE.lock() (risking res_release -> format_alias::forget deadlock) while still returning the dropped loser pointer. Furthermore, concurrent eviction via evict_stale_internal_at -> defer_drop_resources -> late_release::hold could synchronously run drain_known(true) and release the PC COM object while dev_create_srv_x was mid-call before r.GetDesc() (crashing inside amdxc64.dll).

Fix all three lifetime bugs:

- Return owned Option<ID3D12Resource> cloned inside TABLE.lock() from placed_srv_resource and placed_uav_resource (via cache_insert_or_clone), dropping any race loser outside TABLE.lock(), and hold the owned reference across dev_create_srv_x / dev_create_uav_x.

- Pin internal PlacedUav/PlacedSrv resources across sync_pair in on_uav_barrier and sync_title_writers.

- Drop adopted evicted resources normally in defer_drop_resources (outside TABLE.lock()) so real::res_release cleans up title_textures/vram/format_alias maps on the final ref before deferring the PC Release via late_release::hold.

- Reuse a single r.GetDesc() call across dev_create_srv_x.

Verified with cargo check -p xcl --lib and cargo test -p xcl --lib -- hle::d3d12x::format_alias::tests --test-threads=1 (5 passed, 0 failed).

Assisted-by: Antigravity (Gemini 4 Neon High)
…patch

In live world runs ambient.rs tracked TemporalResolve / ReflectionHistory PSOs and captured the 128x128 sky dome, yet ambient_fill_cs and reflect_clamp_cs never dispatched because find_dispatch_views missed the output UAV:

- SM 6.6 directly-indexed bindless heaps bind the view heap via SetDescriptorHeaps (s.heaps[0]) rather than Param::Table, leaving tables empty.

- ExecuteIndirect compute dispatches (both chained split and direct) never called ambient::after_compute_dispatch, and matches_dispatch_target rejected indirect/1D dispatches.

- matches_dispatch_target checked the resource format (often R16G16B16A16_TYPELESS) instead of the concrete UAV view format (R16G16B16A16_FLOAT / R11G11B10_FLOAT / R32G32B32A32_FLOAT).

- VIEW_SLOTS was keyed only by slot.index, colliding across CPU-only view heaps before CopyDescriptors copied them to the >1.24M-slot shader-visible heap, while the 1<<20 index cap and 256-byte CBV scan truncated high slots and larger pass CBVs.

Pass s.heaps[0] into find_dispatch_views, hook ExecuteIndirect compute dispatches, index ViewSlots by both unique slot.at and hosted GLOBAL index, raise the slot cap to 2_000_000 and CBV scan to 2048 B, match by concrete UAV view format with DepthOrArraySize == 1 guard, rank candidates by dispatch grid match, and log first-4 diagnostic misses.

Verified with cargo check -p xcl --lib and hle::d3d12x::ambient::tests (5 passed, 0 failed).

Assisted-by: Antigravity (Gemini 4 Neon High)
…adbacks

Two defensive memory/resource-lifetime fixes:

- kernelx.rs / uma.rs: clean up AWAY physical-page mappings, mirrors, and
  title mapping records on coherent UMA VirtualFree (MEM_DECOMMIT and
  MEM_RELEASE), matching sparse and plain VirtualFree so freed/reused
  coherent blocks never retain dangling AWAY entries. Add Uma::allocation_at
  and extend virtual_free_unmaps_away_pages_in_plain_and_sparse_reservations
  to cover coherent UMA MEM_DECOMMIT and MEM_RELEASE.
- real.rs: call cpu_writes::unregister_water_readback in res_release so
  released or recycled placed textures never retain stale water-readback
  entries.

Assisted-by: Antigravity (Gemini 4 Neon High)
…raphics once, and guard unbuilt ExecuteIndirect

- Keep non-spared memory-writing producer compute pipelines (`!spared && !bvh_traversal`)
  exempt from the per-frame `XCL_PSO_FRAME_BUDGET_MS` skip cutoff so world-entry dispatches
  never leave title memory/tables uninitialized; prioritize wanted producer compute ahead of
  wanted graphics in `PsoQueue::pop`, and run non-deprioritized producer compute inline when
  no worker has started it yet.
- Restrict `XCL_PSO_FRAME_BUDGET_MS` skipping to graphics pipelines and stamp `waited_frame`
  on `Pending` so an unready slow graphics PSO stalls at most one frame while workers finish
  compiling it in the background.
- Skip `list_x::defer` for `spared`/`bvh_traversal` compute PSOs and make `FrameDeferCap`
  slot reservation atomic (`try_reserve`/`release`) so concurrent threads cannot overshoot
  the per-frame deferred segment cap (producer dispatches past the cap fall through to
  `resolve_wait` instead of being dropped).
- Add `pso_async::bound_unbuilt(raw_pso, pso)` for `execute_indirect` and `dispatch_mesh`
  so a pipeline that finishes building right after `resolve_for_bind` returned the stand-in
  cannot slip into the raw PC call with a mismatched root signature.

Assisted-by: Antigravity (Gemini 4 Neon High)
…8x4 grids in ambient

Wave 16e diagnostics showed both TemporalResolve ([320, 360, 1]) and ReflectionHistory ([0, 0, 0]) reached ambient::after_compute_dispatch with tables=3, view_heap=0x4c610000, indices=16 (meaning zero root constants/CBVs and all bindings inside the two Param::Table descriptor tables).

Fix all four remaining lookup gaps:

- Decode CBV V# buffer descriptors (w3 >> 28 < 8, dst_sel 0xFAC) in slots 0..32 of every bound Param::Table and scan their readable constant-buffer bytes (up to 2048 B) for bindless view-heap indices.

- Probe direct image T# descriptors across slots 0..64 of every bound Param::Table (previously capped at 0..16).

- Resolve DXGI_FORMAT_UNKNOWN (0) in dev_create_uav_x and dev_create_srv_x to rd.Format.0 before calling ambient::note_descriptor so views that inherit the resource format are never dropped.

- Score Wave32 [8, 4, 1] and [4, 2, 1] dispatch grids alongside [8, 8, 1] and lower min_w/min_h to (groups/2).max(64) so [320, 360, 1] matches 2560x1440, 1280x720, and half-res probe targets.

Verified with cargo check -p xcl --lib and hle::d3d12x::ambient::tests (5 passed, 0 failed).

Assisted-by: Antigravity (Gemini 4 Neon High)

@luckyteagirl luckyteagirl 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.

On 60bc047f, mapped_ranges() now excludes an existing tile while entry.holes == 0xFFFF and caches that empty result in s.runs. The new invalidation in drain_lazy_commits() covers VEH commits, but the ordinary committed() → commit_range() path can also clear a hole bit on a tile that is already in s.mapped. In that case ensure_mapped() has no new entry to map, and commit_range() changes entry.holes without clearing s.runs or incrementing MAPPED_GEN. title_textures::cached_watch_ranges() can therefore keep omitting the newly CPU-backed tile on later submits, missing its CPU dirty pages until some unrelated mapping changes.

I reproduced the cache transition with a small CPU harness that compiles the exact commit_range, mapped_ranges, and new watchable_tile_runs functions from this head, with minimal state/ensure_mapped stubs for one already-mapped tile. After priming an all-holes tile and committing one 4 KiB page, the base b5c0275 still returned its watch range (exit 0); this head returned [] with holes=0xfffe and generation unchanged (assertion failure, exit 101). This isolates the cache behavior; it does not reproduce a D3D12 title failure.

Could the explicit commit path invalidate both the cached runs and generation when a tile becomes watchable? A regression test should prime mapped_ranges() before committing part of a VRAM-only tile, then assert the next range and generation include it. Codex (GPT-6.2 Sol and GPT-6.2 Astra) reviewed this exact head and CPU differential.

@oni-swr

oni-swr commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Independent test report: PR #2754 at head 60bc047f5bc418dc68563e3c9f8c9aeb56632ae2 (base amd-dev @ b5c0275f)

Hardware / toolchain

  • AMD Radeon RX 7800 XT, driver 32.0.31035.1003; Windows 11 Pro 26200; rustc 1.100.0 (0ef1bc386 2026-11-09); DXC 1.9.0.5512; debug build, -j 4.

Tested (cargo test -p xcl --lib -j 4 ..., separate target dir)

  • The PR's two new tests, each run by name: watchable_tile_runs_omits_vram_only_holes_until_unmasked and watchable_ranges_excludes_gpu_written_textures: 1 passed each (lazy_commit_clears_vram_only_holes_without_clobbering_to_zero, an existing sparse test, also passes).
  • hle::d3d12x::sparse: 26 passed, 0 failed, 1 ignored.
  • hle::d3d12x::title_textures: 31 passed, 1 failed (title_bytes_are_used_in_place_when_all_are_readable, "a committed page is not copied").
  • Full --no-fail-fast -- --test-threads=4 on the PR head: the process aborts (STATUS_STACK_BUFFER_OVERRUN, "non-unwinding panic") in title_textures::tests::placed_title_textures_share_vram_and_preserve_pixels when run in parallel; that test passes alone (1 passed). Re-running with --skip for that one test: 1534 passed, 11 failed, 27 ignored, 1 filtered out.
  • Failures on the PR head: gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 (known, DXIL fuzz tests: fuzz_validate_and_gpu_1 fails on AMD (seed 722 and others, RDNA2-4), so the default suite is red there #2115), gpu::dxil::kernel::dispatch_chain_native_wave64_builds_whole, gpu::recomp::lower_dxil::tests::{a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier, f32_programs_on_the_gpu}, hle::d3d12x::bind::tests::two_pass_binds_set_the_shared_view_heap, hle::d3d12x::list_x::tests::{a_dispatch_with_a_pipeline_still_building_waits_at_the_submit, a_put_off_dispatch_runs_at_the_submit_when_its_build_outlasts_the_wait_budget, bitset_runs_emit_exact_contiguous_page_ranges}, hle::d3d12x::real::big_compile_tests::giant_driver_compiles_have_their_own_lane, hle::d3d12x::title_textures::tests::title_bytes_are_used_in_place_when_all_are_readable, hle::kernelx::tests::physical_home_without_sparse_windows_uses_coherent_window.
  • Same run on the PR's base b5c0275f (same --skip): 1532 passed, 11 failed, 27 ignored. The failing set is identical, and the full run without --skip aborts the same way. So these failures and the abort exist on amd-dev before this PR; the PR adds 2 passing tests and no failures. (title_bytes_are_used_in_place..., giant_driver_compiles... and physical_home_without_sparse... were also checked alone on both commits: they fail on both.)
  • For reference, origin/main @ b49be183 full lib run: 1308 passed, 1 failed (fuzz_validate_and_gpu_1), 27 ignored. The extra failures above come from the amd-dev line, not from this PR.
  • SKIPPED lines (4): lower_dxil::tests::f16_programs_on_the_gpu: f16 arithmetic and f16 packed, each wave32 and wave64, "refused (unsupported V_MUL_F16 / V_PK_MUL_F16 ... gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's)".
  • The hle::d3d12x filter run on the PR head: 409 passed, 5 failed, 2 ignored (all five are in the list above).

Regression run

  • Not run (no title / scripts/smoke.ps1 run).

Not tested

  • No retail title, no smoke run, no release build, no tests/ integration or e2e suites (only -p xcl --lib), no other GPU vendors. Whether the PR changes GetWriteWatch behaviour on a real title is not covered.

AI use

  • Claude Code (Claude Sonnet 5.5) ran the commands and wrote this report. Results come from real runs on the hardware above.

@Saksukella

Copy link
Copy Markdown
Contributor Author

Good catch @luckyteagirl — fixed in 891c97a5. State::commit_range() now tracks transitions off holes == 0xFFFF via unmask_committed_holes and invalidates self.runs + increments MAPPED_GEN whenever an explicit commit makes a VRAM-only tile watchable. Added commit_range_unmasking_vram_only_tile_invalidates_runs_and_gen and re-ran 60s RX 9070 XT smoke (1671 frames, 15086 MB, 0 removals, 0 crashes).

@thehollowedone

Copy link
Copy Markdown
Contributor

Independent Windows/NVIDIA check of PR #2754 head 891c97a against its amd-dev base b5c0275. The head was unchanged when checked before posting. RTX 3080 Ti 12 GiB, NVIDIA 621.35, Windows 11 build 26300, rustc 1.99.1 MSVC; synthetic tests, no game files.

  • cargo build --offline --locked --workspace: passed.
  • cargo test --offline --locked -p xcl --lib watchable_ -- --nocapture --test-threads=1: both new watch-range tests passed (2 passed, 0 failed, 0 ignored, 0 GPU skips).
  • cargo test --offline --locked -p xcl --lib commit_range_unmasking_vram_only_tile_invalidates_runs_and_gen -- --nocapture --test-threads=1: the new explicit-commit regression passed (1/0/0, 0 skips).
  • cargo test --offline --locked -p xcl --lib hle::d3d12x::sparse::tests:: -- --test-threads=1: 22 passed, 0 failed, 1 ignored, 0 skips.
  • cargo test --offline --locked -p xcl --lib hle::d3d12x::title_textures::tests:: -- --test-threads=1: 31 passed, 1 failed, 0 ignored, 0 skips. The failing title_bytes_are_used_in_place_when_all_are_readable says “a committed page is not copied.” I restored both changed files from the exact b5c0275 base, rebuilt, and ran that test alone with --nocapture --test-threads=1: it failed with the same assertion (0/1/0). I then restored the PR files.

I also attempted cargo test --offline --locked --workspace --no-fail-fast -- --test-threads=4. The library process aborted with Windows 0xc0000409 after a worker dereferenced the sentinel 0xffffffffffffffff in windows-core::interface; there is no complete library count. Twenty GPU SKIPPED notices appeared before the abort and are not coverage. Other completed targets included d3d12_mesh_stream (2 passed, 1 failed: expected AS-slot refusal but got MS: no NGG hardware variant) and gpu_compute_e2e (4 passed, 2 failed: offline second-process cache paths). I have not established those integration failures as changes from the base. This run is not a whole-suite pass.

Not tested: paired clean-commit retail smoke, the time saved by GetWriteWatch, a title phase with GPU-written textures, visual output, or AMD/Intel hardware. The focused results confirm the new range-selection and explicit-commit tests on this NVIDIA machine; they do not measure the PR's runtime benefit.

AI use: Codex (GPT-6.2 Sol) ran the Windows checks, compared the focused failure with the base, and drafted this report.

@relativespace2K

Copy link
Copy Markdown

Tested - retail title on native Windows AMD RDNA2, PR head 891c97a572505514237fe6424416e4ff8be341b4 on amd-dev b5c0275f

Tool: OpenCode with DeepSeek V4.1 Flash 1017

  • AMD Radeon RX 6800 XT (16338 MiB), driver 32.0.21045.29003; Ryzen 5 5600, 31.9 GB;
    Windows 11 IoT Enterprise LTSC 26100; release build; DXC 1.9.2602.17.
  • cargo test --release -p xcl --lib -- watchable_: 2 passed, 0 failed, 0 ignored, 0 skipped.
  • cargo test --release -p xcl --lib -- commit_range_unmasking: 1 passed, 0 failed, 0 ignored, 0 skipped.
  • Game: retail title 1.0.2.1, 180 s runs, XCL_INLINE_GUARD_BATCH=0 on both sides,
    XCL_NETWORK=0 XCL_ACTIVITY=1 XCL_FRAME_DUMP=1 XCL_RUN_SECONDS=180; warm caches.
run draws last present write-watch dirty pages MS compiles result
b5c0275f #1 8.5k 106.2 s 6,224 ms 1,871,985 42 no crash
b5c0275f #2 8.6k 102.0 s 6,191 ms 1,927,890 84 no crash
PR 891c97a5 16.0k 125.8 s 7,110 ms 1,927,967 3 no crash

The target does not move on this title: the ~1.9M dirty pages are in tiles with CPU-committed
pages, not the VRAM-only (holes == 0xFFFF) tiles this change excludes, so write-watch time
and page count stay the same (6.2-7.1 s, 1.87-1.93M pages). The PR is safe in this window (tests
pass, no crash, no device removal), but I do not attribute the draw-count difference to it: the
baseline runs spent 42 and 84 MS PSO driver compiles against 3 on the PR, which is pipeline-library
state, not this diff.

Note: the PR is DIRTY against the current amd-dev c32c91a3; git merge-tree reports one
conflict in crates/xcl/src/hle/d3d12x/sparse.rs. It needs a rebase before it can merge.

Not tested: world/FPS (not reached), NVIDIA/Intel GPUs, full workspace, debug build.

AI use: OpenCode with DeepSeek V4.1 Flash 1017 ran the tests and the game runs, read the logs and wrote this comment; the counts, write-watch lines and merge check were verified against the logs and git.

raylitebull added a commit that referenced this pull request Nov 29, 2026
…nges

Ports the sparse half of upstream PR #2754: 60bc047 ("omit VRAM-only
sparse tiles and GPU-written textures from write-watch ranges") and its
follow-up 891c97a ("invalidate sparse watch ranges when commit_range
unmasks a VRAM-only tile").

A tile of a sparse window whose 16 pages are all holes (holes == 0xFFFF)
has no page the CPU can write: the title has not committed one there.
The upload before a submit already skips hole pages, so watching such a
tile only had the looks for CPU writes walk memory nothing could have
written. In this tree such tiles stay in `mapped` for a buffer placed
over reserved memory (`buffer_tiles` maps its tiles with the holes
Windows reports), and for a moment in each commit (`ensure_listed`, a
tile over a CPU view committed at its own address).

`State::runs` (what `mapped_ranges` returns for the window's own tiles)
now holds only tiles with a page committed: `ensure_mapped` and
`ensure_listed` leave an all-holes tile out, and `commit_range` clears
holes through `unmask_committed_holes`, which puts a tile that had none
committed into `runs` and bumps MAPPED_GEN, so the next submit makes its
watched ranges again (`watch_key`). Write-watch bits outside the watched
ranges are never reset, so what the CPU writes after the commit is found
by the next look; `committed` also makes the blocks hot (`mark_hot`). A
tile that becomes all holes on a decommit already left `mapped` and
`runs` (`decommit_tiles`).

Adapted, not cherry-picked: upstream rebuilds its runs from all of
`mapped` when they are asked for and filters there; this tree keeps
`runs` up to date incrementally (a retail title has ~150,000 tiles), so
the filter sits where tiles are listed and committed. The two upstream
commits are one here: with only the first, a commit on an all-holes tile
would never be watched. Upstream's lazy VEH commit queue
(`drain_lazy_commits`, `alloc_vram_only`) does not exist in this tree,
so that part does not apply: holes are only cleared by `commit_range`.

Ranges under WATCH_GAP (64 MiB) apart are still scanned as one, so this
shrinks the looks only where the tiles left out open such a gap.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
raylitebull added a commit that referenced this pull request Nov 29, 2026
Ports the texture half of upstream PR #2754 (60bc047, "omit VRAM-only
sparse tiles and GPU-written textures from write-watch ranges"). A
texture the title's GPU work wrote (`gpu_written`) is never uploaded for
a CPU write again, so watching its source only cost the looks for CPU
writes.

Upstream builds the textures' part of the watched ranges from every
texture that is not GPU-written (`watchable_ranges`). Here that part is
`Table::coarse`, 16 MiB blocks -> how many linked textures cover them,
so the count now leaves GPU-written textures out: `link_src` and
`unlink_src` are told whether the texture counts, `Table::mark_gpu_written`
(from `note_gpu_write` and `submitted`) takes a linked one out, and one
that `mapping_changed` gives back to the CPU counts again. A block whose
count reaches 0 bumps COARSE_GEN, which is in `watch_key`, so the ranges
are made again at the next submit; upstream's TEXTURES_GEN bump has no
reader here. `src_pieces` is unchanged: a GPU-written texture is still
found by its written pages and skipped there, as before.

In this tree GPU-written textures were already skipped before the
compare, so the saving is in the looks, not in the texture compare and
upload. A block stays watched while a texture there that is not
GPU-written, a sparse tile with a committed page, or a shown page lies
in it, and ranges under WATCH_GAP apart are still one scan.

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 xcl-dev#2754 by Saksukella (amd-dev commits 60bc047 and 891c97a) to
main, re-implemented for main's sparse runs and coarse texture blocks;
the idea and the rules are theirs.

Sparse windows: a window's own tile with video memory and no CPU page
(holes == 0xFFFF) takes no CPU write, yet main added it to State::runs
at ensure_listed (XCL_SPARSE_LAZY), ensure_mapped (a placed buffer over
uncommitted pages) and the CPU-view unlink, so write-watch scanned it.
Such a tile now enters the runs at its first CPU page
(commit_range_with_protection, with a MAPPED_GEN bump). Tiles over a CPU
view (src != 0) are tracked by src_runs and unchanged.

Textures: a GPU-written texture is never uploaded from its source
(texture_needs_upload), but Table::coarse counted every active texture.
It now counts only those that are not gpu_written, and a texture moves
in or out where that flips: a published GPU write, a mapping change that
undoes one (recheck_gpu_view_sources), and a download that makes the
CPU's copy current. GPU-owned textures (gpu_written from the start) are
no longer watched at all. Shadowed entries never count.

Risk: a CPU commit XCL never sees leaves its tile unwatched, where main
watched it from the GPU mapping. A block that comes back into the
watched ranges may report pages written while it was out; that costs at
most one extra upload of a texture there, as main's always-watched block
would.

Tests: a_tile_with_no_cpu_page_is_not_watched,
a_tile_with_no_cpu_page_is_watched_from_its_first_commit (GPU),
gpu_written_textures_leave_the_watched_blocks_until_they_are_current_again;
the runs_of helper follows the new invariant.

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 is a port of this and #2891 to current main, and it is mergeable but currently blocked. So the change is represented there — the question is whether to keep this one alive in parallel or defer to the port.

Flagging it so the choice is yours; I have no stake in which route is used, only that one of them can be built and tested.

AI use: an agent posted this triage note.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Triage (#1607) – head 891c97a

This PR targets amd-dev. Only the top two commits (60bc047, 891c97a) are its own. The other ~217 commits (+35k lines) come from the old base b5c0275, which is shared with #2755, #2756, #2727, #2726, #2738 and #2710. That is where the shared added lines come from.
Both parts of the change are now on amd-dev, ported from this PR. The sparse half is f2f02bd: all-holes tiles are kept out of State::runs, and unmask_committed_holes adds them back and bumps MAPPED_GEN. The texture half is fe5260b: mark_gpu_written unwatches the texture's coarse blocks. The lazy VEH commit drain does not exist on amd-dev.
Recommendation: close (superseded by amd-dev commits f2f02bd and fe5260b).

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

@throny

throny commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Closing as superseded: this change is already on amd-dev (f2f02bd, fe5260b). From Foniass's rechecked close list on #1607, checked again by script just now. If something here is still missing, say so and reopen it, or ask and I will.

AI use: Claude Code (Claude Opus 5.5).

@throny throny added the duplicate This issue or pull request already exists label Dec 1, 2026
@throny throny closed this Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

duplicate This issue or pull request already exists

Projects

None yet

Development

Successfully merging this pull request may close these issues.