Skip to content

Recompiler: an access outside the heap windows takes a null view, no branch - #1669

Closed
milesah3ad wants to merge 1 commit into
xcl-dev:mainfrom
milesah3ad:heap-null-view
Closed

milesah3ad wants to merge 1 commit into
xcl-dev:mainfrom
milesah3ad:heap-null-view

Conversation

@milesah3ad

@milesah3ad milesah3ad commented Nov 24, 2026 •

Copy link
Copy Markdown

With heap windows (XCL_HEAP_WINDOWS=1, #680), every memory access was [branch] if (xcl_w >= windows) { … } around its descriptor-heap access. This replaces the branch with a select of the descriptor: xcl_w < windows ? MEM_HEAP_BASE + xcl_w : MEM_HEAP_NULL. MEM_HEAP_NULL is a new null raw UAV, placed after all MAX_WINDOWS window views. A null view's loads and atomics return 0 and its stores are dropped, the same as the switch form's default, so the out-of-UMA rule from f9e5ee9 stays as it is. The null slot comes after all four window slots, not at windows, so a program with fewer windows can't reach a live window's view through it. (min(xcl_w, windows) would land on descriptor 2 for a 2-window program.)

This is the form @brothernog proposed and measured on #680 with retail compute programs on an RTX 3050: less driver time (23.0 → 17.5 s on an 18.7k-instruction program), and no handle phi in the programs NVIDIA refused in #1269. Default runs (heap windows off) don't reach the new HLSL. Part of #1269.

What is in it (one commit)

  • gpu/recomp/emit.rs: the heap accessors index with the select and have no branch
  • gpu/recomp/mod.rs: MEM_HEAP_NULL = MEM_HEAP_BASE + MAX_WINDOWS
  • gpu/recomp/runner.rs: set_null_window_view; the two test heaps get one more descriptor and the null view
  • hle/d3d12x/console_heap.rs: the shared heap reserves the slot, and set_window_views writes the null view after the windows
  • tests: memory_windows_above_4_gib checks for the select and for no if (xcl_w >=; window_views_do_not_hold_global_during_device_calls expects one more device call, a null-resource view at MEM_HEAP_NULL

Tested

  • RTX 5080 16 GB, driver 621.24, wave32 (split wave64); Ryzen 7 9800X3D, 64 GB; Windows 11 Pro 26300; rustc 1.100.0 MSVC; DXC 1.9.2609.5; debug

  • On this head daaa354 (on main c160d86), cargo test --workspace --no-fail-fast -- --test-threads=4:

    • default: 858 passed, 0 failed, 42 ignored. SKIPPED: the two wave64-only tests, heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows)
    • XCL_HEAP_WINDOWS=1: 858 passed, 0 failed, 42 ignored. SKIPPED: the two wave64-only tests
  • The out-of-window semantics in the heap form go through the null view on the GPU in gpu_heap_windows_reject_out_of_uma_aliasing: out-of-UMA loads return 0, GLC atomics (add, buffer add) return 0, the global_atomic_inc CAS loop ends, and stores and atomics leave the canaries in both windows untouched.

  • Driver time, synthetic programs (the nv680 generator from Recompiler: memory windows from the descriptor heap (no per-access switch) #680: 4 windows, split wave64, 5 shapes × 2 sizes × 2 seeds; each program translated three ways, then a cold CreateComputePipelineState in its own process):

    shape switch form heap, branch (main) heap, null view (this PR)
    base (250 / 1000 rounds) 3.3 / 58.6 s 0.67 / 17.9 s 0.60 / 15.6 s
    loop 4.0 / 75.1 s 0.74 / 19.0 s 0.68 / 17.7 s
    wave (v_readlane) 5.5 / 91.6 s 1.97 / 44.9 s 1.83 / 38.6 s
    32-bit atomic 6.6 / 126.3 s 0.87 / 18.5 s 0.77 / 17.9 s
    64-bit atomics 7.7 / 149.9 s 0.88 / 21.1 s 0.99 / 24.6 s
    total, 20 programs 1057 s 253.0 s 238.4 s (−5.8 %)

    The null view is faster on 4 of the 5 shapes (−2 to −16 % per program). It is slower on the 64-bit-atomic shape (+12 to +19 %, DXIL +5 %), where every round has a returning UMAX_X2 and every second round a CMPSWAP_X2. Retail programs are the better measure here, and @brothernog's are faster in this form. If 64-bit atomics turn out to matter, keeping the branch only for the 64-bit accessors would be a small follow-up.

Regression run

  • None. I don't have a title, so I can't run scripts/smoke.ps1. Default runs don't reach the new HLSL (heap windows are opt-in), but the shared heap now reserves one more descriptor, so a run in both settings is still needed. @brothernog, or anyone running the newer title with XCL_HEAP_WINDOWS=1: a smoke pair would let this leave draft.

main:

PR:

Not tested

  • Any retail title or retail program (synthetic programs only); the smoke pair above
  • AMD, Intel, other NVIDIA generations; Wine / vkd3d-proton (a null raw UAV in a heap there)
  • The D3D12 debug layer on the null view (the test runner doesn't turn it on)
  • Whether the handle phi NVIDIA refused in [OFFICIAL] Looking for PRs with shaders optimization #1269 is gone for those programs (that's @brothernog's measurement, not mine)

AI use

  • Claude Code (Claude Opus 5.5) wrote the change, the test updates and this description, and ran the tests and measurements on the machine above. I read the diff.

🤖 Generated with Claude Code

https://claude.ai/code/session_01YPhfiWsdJcDBLYSS8edLyS

…branch

With heap windows every memory access was `[branch] if (xcl_w >= windows)
{ <the switch's default> }` around the descriptor-heap access. The index is
now a select instead: `xcl_w < windows ? MEM_HEAP_BASE + xcl_w :
MEM_HEAP_NULL`, and MEM_HEAP_NULL (the descriptor after the MAX_WINDOWS
window views) is a null raw UAV. A null view's loads and atomics return 0
and its stores are dropped, which is what the switch form's `default` does,
so the out-of-UMA rule is unchanged; the null slot sits after all
MAX_WINDOWS views, so a program with fewer windows cannot reach a live
window's view through it.

brothernog measured this form on xcl-dev#680 against retail compute programs on an
RTX 3050: less driver time, and no handle `phi` on the programs NVIDIA
refused in xcl-dev#1269.

- emit.rs: the select and no branch in the heap accessors
- mod.rs: MEM_HEAP_NULL
- runner.rs: set_null_window_view; the test heaps hold it
- console_heap.rs: the shared heap reserves it and set_window_views makes it
- tests: the HLSL check expects the select and no branch; the window-views
  test expects the null view after the windows

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YPhfiWsdJcDBLYSS8edLyS
@milesah3ad

Copy link
Copy Markdown
Author

Looking for a regression pair on the newer title. I don't have a title, so I can't make the xcl-smoke blocks this needs.

@brothernog (your proposal on #680), @imnicho, @Anon64, @tiagonleal: you've each run the title with XCL_HEAP_WINDOWS=1 since #680. If one of you has a few minutes, scripts/smoke.ps1 built from main c160d86 and from this head daaa354, both with XCL_HEAP_WINDOWS=1, would let this leave draft. A pair with it unset too would cover the extra reserved descriptor in default runs.

What would be most useful besides the blocks: whether any compute pipelines are refused (E_OUTOFMEMORY / the switch-form fallback) with this head, and the longest compute PSO build, compared with main.

AI use: Claude Code (Claude Opus 5.5) drafted this. I chose who to ask from the #680 test reports.

@WebIdentity1

Copy link
Copy Markdown
Contributor

RTX 3090 validation of exact head daaa354f2eb4bcd17cbe3ab41650edecc755ea36 against its parent/main c160d86ef2efe3a07e4dfb473e4fa72eafb413c0, with heap windows enabled. The focused out-of-UMA GPU oracle passes on both, and the full workspace has the same result on both revisions. This adds Ampere coverage to the RTX 5080 results in the description.

Tested

  • Windows 10 Home 19045, Ryzen 7 7800X3D, RTX 3090 driver 591.74, Rust 1.98.1 MSVC, Agility 1.620.2, DXC/DXIL 1.8.2502.11, debug. XCL_ADAPTER=3090, XCL_REQUIRE_GPU=mesh, XCL_HEAP_WINDOWS=1, XCL_DIRECT_DXIL unset; XCL_SAMPLE_* unset. Focused tests in fresh SSH Session 0 processes; full suite in interactive desktop Session 1, four threads.
  • cargo test --locked -p xcl --lib gpu_heap_windows_reject_out_of_uma_aliasing -- --test-threads=1 --show-output --nocapture: parent 1 passed / 0 failed / 0 ignored, head 1 / 0 / 0; no skip or timeout. It exercises the production heap path's out-of-UMA load/atomic/store behavior and checks the GPU canaries.
  • cargo build --locked --workspace: exit 0 on both revisions.
  • cargo test --locked --workspace --no-fail-fast -- --test-threads=4 --show-output: parent 857 passed / 1 failed / 42 ignored; head 857 / 1 / 42. Both exit 101 with the same known gpu_clamp_and_omod_per_instruction lane-0 v_pk_add_i16 clamp failure (Recompiler: complete remaining RDNA2 integer CLAMP=1 saturation (#105) #202). No timeout. Counts sum all 20 test targets.
  • Four explicit skips on each full run, counted inside the passes: the two native-wave64 reference tests (gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware), and the two debug-layer tests (test_title_draws_with_a_root_signature_under_the_debug_layer, uploads_start_from_each_subresources_state; system SDK Layers unavailable). They are not coverage. Some workspace fixtures select the default adapter themselves, so I do not claim that every full-suite test used the 3090.
  • All 292 tracked source hashes matched each Windows tree before and after the pair. No source changes or new PR.

Not tested: retail xcl-smoke pair, the newer title, actual large-program driver compile times, AMD/Intel, debug-layer behavior, Wine, release build, or every generated heap-accessor shape. This supports the null-view semantics on Ampere but does not satisfy the retail gate or establish merge readiness.

AI use: Codex (GPT-6) ran the native tests, checked the logs and source hashes, and prepared this report.

anoyarou added a commit to anoyarou/xcl that referenced this pull request Nov 24, 2026
…g, DirectStorage, and stream tracking

Cherry-picks upstream stabilization improvements across VRAM allocation,
pipeline caching, DirectStorage lifetime, descriptor heap indexing, Media
Foundation device bridging, and stream PSO tracking:

- D3D12.X: reclaim cooling and idle tiles on pool heap OOM (xcl-dev#1663,
  addressing xcl-dev#1585 and xcl-dev#1668). When CreateHeap returns 0x8007000E (E_OUTOFMEMORY),
  Pages::take_tile waits on Pages::fence up to 1000 ms to drain cooling tiles or
  force-evict idle pages rather than failing immediately. (by Nikita Romanovich)

- DirectStorage: close a queue when its last reference is released (xcl-dev#1675).
  Moves queue_close logic into QueueInner::close and invokes it when the final
  queue reference is released, preventing background workers from writing to freed
  caller buffers and marking pending entries complete with E_QUEUE_CLOSED. (by eizispark)

- D3D12.X: a pipeline the driver gave up on is not built again (xcl-dev#1665).
  Persists driver E_OUTOFMEMORY refusal state into used-pipelines.txt (!<key>)
  so giant compute pipelines that the host driver refuses to compile are skipped
  on subsequent runs. (by zorde23)

- Recompiler: access outside heap windows takes a null view without branching
  (xcl-dev#1669, xcl-dev#680). Replaces conditional branches in XCL_HEAP_WINDOWS=1
  (if (xcl_w >= windows)) with a branchless select pointing out-of-bounds accesses
  to a dedicated null UAV view (MEM_HEAP_NULL). (by milesah3ad)

- HLE: bridge ID3D12Device before direct ResetDevice and cache D3D11 companion
  (xcl-dev#1677). Fixes MFResetDXGIDeviceManagerX in mfplat.rs to bridge
  ID3D12Device COM pointers and caches multithreaded companion ID3D11Device
  instances per adapter LUID. (by eizispark)

- D3D12.X: route stream graphics PSOs through create_graphics_pso_tracked
  (xcl-dev#1661, finding XCL-BT-023 from xcl-dev#1489). Ensures stream-created
  graphics PSOs receive D3D12_PIPELINE_STATE_FLAG_DYNAMIC_DEPTH_BIAS and are
  tracked in device_x::note_base for CreateDerivedPipelineStateX and RSSetDepthBiasX.
  (by fixgep)

Assisted-by: Antigravity
@throny

throny commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

Two contributors checked independently and found that #1695 solves the same problem (for #1269) in a different way: #1607, group D44. You may want to compare them with the other author and agree on one, or say in the PR why both are needed.

This is a hint, not a request from the maintainers; nobody from the project has adopted #1607 so far.

AI use: Claude Code (Claude Opus 5.5), posted by a script from the #1607 table.

@srcamarda

Copy link
Copy Markdown
Contributor

Regression pair for daaa354 on AMD RDNA3 (RX 7800 XT), retail title, with and without XCL_HEAP_WINDOWS=1; also under the debug layer into the world load: no regression, and no new debug-layer messages from the null view

Setup

  • AMD Radeon RX 7800 XT 16 GB (RDNA3, native wave64), driver 32.0.32029.2010; Ryzen 5 5600G, 32 GB; Windows 11 Pro 26300 with Graphics Tools; rustc 1.100.0; debug for the tests, release for the title.
  • This head daaa354 and its parent main c160d86, each built clean, no local changes.

Tests on daaa354, cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4:

  • default: 858 passed, 0 failed, 42 ignored. SKIPPED: heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
  • XCL_HEAP_WINDOWS=1: 858 passed, 0 failed, 42 ignored, no SKIPPED. This includes gpu_heap_windows_reject_out_of_uma_aliasing with the null view on AMD, and the two wave64-only tests that skip on your card.

Regression run (retail title 1.0.2.1, scripts/smoke.ps1 -Seconds 60, no input, title screens; interleaved main / PR, two rounds per setting):

main c160d86 this PR daaa354
default: frames shown 1 558 · 1 542 1 554 · 1 579
default: peak commit 15 910 · 15 911 MB 15 916 · 15 905 MB
XCL_HEAP_WINDOWS=1: frames shown 1 579 · 1 573 1 493 · 1 575
XCL_HEAP_WINDOWS=1: peak commit 16 400 · 16 005 MB 16 364 · 16 213 MB

All eight runs: presents per 2 s (last 3) 60 60 60, no device removal, no crash. With heap windows the PR's run built its compute programs fresh, so the new HLSL was in use. Its DXIL sizes differ from main's, and the first round compiled every program cold in the driver. That first round's lower frame count is that compile, not a steady-state drop.

The blocks with XCL_HEAP_WINDOWS=1 (round 1):

main:

xcl-smoke v1
commit: c160d86ef2efe3a07e4dfb473e4fa72eafb413c0
gpu: AMD Radeon RX 7800 XT
title: RetailGame_Dump
seconds: 60
exit: 0x0
frames shown: 1579 (PresentX 1580)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16400 MB

PR:

xcl-smoke v1
commit: daaa354f2eb4bcd17cbe3ab41650edecc755ea36
gpu: AMD Radeon RX 7800 XT
title: RetailGame_Dump
seconds: 60
exit: 0x0
frames shown: 1493 (PresentX 1493)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16364 MB

Debug layer (XCL_D3D12_DEBUG=1 XCL_HEAP_WINDOWS=1 XCL_NETWORK=0 XCL_RUN_SECONDS=150, Enter (= A) at 30 / 40 / 50 s, into the world load; main, PR, PR, main):

  • The same message ids in all four runs, and none new with the null view: 538, 677, 679, 680, 745, 1047, 1422. XCL logs only the first 8 of each id, and these runs had no uncapped count, so this compares ids, not totals.
  • PR: 150 s twice, 3 034 and 3 082 frames shown, no device removal or crash.
  • main: crashed once at 130 s in the world load, 0xc0000005 in VCRUNTIME140.dll+0x1c11d (a read at 0xdc4871000, a memcpy), and ran 150 s the second time (2 834 frames). One crash in two runs on main and none on the PR says nothing about this change. I note it only because it is not the title's known +0x23cf683 crash (Retail title (Xbox Series 1.0.2.1) reaches actual gameplay on RDNA3 — then 0xC0000005 in the title (+0x23cf683) #534).

Not tested

  • Driver compile times on retail programs. The two builds did not reach the same programs in the same order, and some of main's heap-form programs came from my driver cache of earlier runs, so I have no comparable numbers.
  • Whether the handle phi NVIDIA refused in [OFFICIAL] Looking for PRs with shaders optimization #1269 is gone (no NVIDIA here); Wine / vkd3d-proton; Intel.
  • Gameplay past the first 150 s.

Claude Code (Claude Opus 5.5), from runs on the hardware above.

@milesah3ad

Copy link
Copy Markdown
Author

Closing in favour of #1695: the same null-view approach, from @brothernog, who proposed it on #680, plus the check for 64-bit atomics on heap views, and it already has its smoke pair and several test reports.

Thanks @srcamarda and @WebIdentity1. Your reports tested the null view itself, so they carry over to #1695: the AMD RX 7800 XT smoke pair with and without XCL_HEAP_WINDOWS=1, the debug-layer runs into the world load with no new message ids, and the RTX 3090 suite and out-of-UMA oracle. I've linked them there.

AI use: Claude Code (Claude Opus 5.5) drafted this.

@milesah3ad milesah3ad closed this Nov 24, 2026
@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~22 ignored.

Thanks!

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