Skip to content

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

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

Saksukella wants to merge 2 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

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.

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

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.

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.

5 participants