Skip to content

Recompiler: direct DXIL reads heap memory windows without a branch - #2427

Draft
Kalmarv wants to merge 1 commit into
xcl-dev:mainfrom
Kalmarv:heap-flat-loads
Draft

Kalmarv wants to merge 1 commit into
xcl-dev:mainfrom
Kalmarv:heap-flat-loads

Conversation

@Kalmarv

@Kalmarv Kalmarv commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Part of #2088.

Draft: the regression pair is still to run. I'll fill in Regression run and mark this ready when it finishes.

With heap memory windows (XCL_HEAP_WINDOWS=1), every read in a direct-DXIL compute program is a branch on w < windows (and the lane guard) around the heap lookup, with a phi per value where the paths join. NVIDIA's compile time follows the block count, not the byte count, and the reads in a large compute program make thousands of blocks.

This PR adds a one-path form behind XCL_HEAP_FLAT=1. It applies only with heap windows on:

  • The read: each lane reads from window w's heap view. It uses window 0 instead when w is outside the windows or the lane is inactive, and those lanes then take 0. The guarded form and the switch over root UAVs give the same results.
  • Credit: the one-path idea (a clamped index instead of a branch) is the one @brothernog brings to the HLSL heap form in Recompiler: heap memory windows without a guard (min + null view), and the 64-bit atomics check #1695. Reading through a select instead of a branch is the same direction as @coolpersonnn's Recompiler: flatten direct DXIL root-UAV loads for compute #2368 for root UAVs. This PR applies it to the direct translator's heap form.
  • Cache keys: the new HEAP_FLAT flag is in the windows count, so the caches keep the forms apart.
  • Scope: only reads change: raw, SMEM, unaligned, format and BVH node loads (all the with_mem_i32s callers). Stores and atomics keep their branch. Vertex, pixel, mesh and GS programs and the HLSL path are unchanged.

Cold pipeline builds, RTX 5070 Ti (NVIDIA 610.74), shader cache disabled (ShaderCacheControl), 4 windows, split wave64. Five large compute programs from title: ea3b5e4d, one run each, all in one job:

program switch over root UAVs heap, guarded (earlier job) heap, this PR native code, switch → this PR
RT resolve A 31.0 s 14.0 s 8.1 s 1276 → 964 KB
RT resolve B 32.5 s 36.1 s 8.7 s 1400 → 1052 KB
local lights 6.7 s 3.9 s 3.4 s 472 → 365 KB
cascade shadows A 60.7 s 138.0 s 28.6 s 2476 → 2142 KB
cascade shadows B 12.6 s 23.9 s 11.8 s 1285 → 1144 KB
  • Native code: the driver's blob (GetCachedBlob) is 11–25 % smaller. That is less shader code for the driver to hold (cf. NVIDIA: the device is removed when the pipelines in use need more than 512 MB of shader code (0x887a0005) #2403's device removal with a shader-code heap above 512 MB), but I have not checked whether it is enough there.
  • Noise: the guarded column comes from an earlier job. Between jobs, times varied by up to about 25 %.
  • The cascade shadows programs: they are wave64 groups of several waves. Most of their remaining time is the split form's spin exchange, which this PR does not touch.

What is in it

  • gpu/dxil/lower_mem.rs: the one-path read in with_mem_i32s.
  • gpu/dxil/kernel.rs, gpu/dxil/lower.rs: heap_flat in Lw, set for compute stages with HEAP_FLAT and heap windows.
  • gpu/recomp/mod.rs, gpu/recomp/pso.rs: the HEAP_FLAT flag and XCL_HEAP_FLAT=1. The HLSL path strips the flag the way it strips HEAP_WINDOWS.
  • gpu/recomp/tests.rs: gpu_heap_flat_reads_match_the_switch_form. It runs one program in all three forms (switch, guarded heap, flat heap) over a 4-window arena and compares SGPRs and VGPRs. The program has SMEM loads into window 2 and outside the UMA, an s_buffer_load_dwordx4 from window 3, a buffer_load from window 1, and per-lane global_loads spread over all four windows. Every eighth lane reads outside the UMA, lanes 0–32 are inactive (v_cmpx), and there is a SADDR global_load_dwordx2.

Tested

  • Ryzen 9 9950X, RTX 5070 Ti (NVIDIA 610.74), Windows 11 build 26200, DXC 1.9.2609, debug.
  • cargo test --workspace --no-fail-fast -- --test-threads=4 on 717fec50: 1290 passed, 1 failed, 46 ignored.
    • The failure, a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier, also fails on main 68a284a5.
    • 25 SKIPPED notices: 8 for no wave64, 16 for the per-op wave64 forms, and 1 for no heap windows (the switch-form fallback test, since heap windows are opt-in).
  • Window filter (window), default and with XCL_DIRECT_DXIL=1: 31 passed, 0 failed.
  • gpu_heap_flat_reads_match_the_switch_form passes in the suite run.

Regression run

  • pending (main 68a284a5 vs this head)

Not tested

  • A title run with XCL_HEAP_FLAT=1.
  • AMD, Intel and Linux.
  • Graphics stages: they keep the switch. Recompiler: flatten direct DXIL root-UAV loads for compute #2368 measured a select-flattened form as slower for NVIDIA pixel shaders, so extending this form to them needs its own timing.
  • xcl shaders --precompile keys this form only in the follow-up PR, which turns it on by default. With XCL_HEAP_FLAT=1 alone, precompiled entries are not found and the programs are translated at run time.

AI use

  • Claude Code (Claude Opus 5.5) wrote the change, the test and this description, made the measurements and ran the tests.

🤖 Generated with Claude Code

With heap windows (XCL_HEAP_WINDOWS=1), every read of the direct DXIL
translator was a branch on `w < windows` (and the lane guard) around the
heap lookup, and a phi per value at the join. On NVIDIA the driver's
compile time follows the block count, and the reads of a large compute
program make thousands of blocks.

XCL_HEAP_FLAT=1 (with heap windows; new flag HEAP_FLAT in the windows
count, so the caches keep the forms apart) reads in one path: the lane
loads from window `w`, or window 0 when `w` is outside the windows or
the lane is not active, and those lanes take 0, as the guarded form and
the switch over root UAVs give. All with_mem_i32s callers only load
(raw, SMEM, unaligned, format and BVH node reads). Stores and atomics
keep their branch. Compute stages only: vertex and pixel shaders are
unchanged. The HLSL path ignores the flag. The one-path form is the
idea xcl-dev#1695 brings to the HLSL heap form.

Measured cold on an RTX 5070 Ti (610.74), shader cache disabled, 4
windows, split wave64, five large compute programs: the driver took
6.7-60.7 s with the switch over root UAVs and 3.4-28.6 s with this form;
its native code was 11-25 % smaller.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@alexmircea1299

Copy link
Copy Markdown

Tested commit 717fec5 on Windows:

Environment

  • OS: Windows 11 (Build 26100)
  • CPU: AMD Ryzen 5 9600X 6-Core Processor
  • RAM: 32 GB
  • GPU: NVIDIA GeForce RTX 5070 (12 GB VRAM, driver 621.40, wave32)
  • DXC: 1.8.2502.11 (Windows SDK 10.0.26100.0)

Results

@ivall ivall added the goal:world-load Bears on the retail title getting past world loading label Nov 25, 2026
raylitebull added a commit that referenced this pull request Nov 25, 2026
Port #2427 (XCL_HEAP_FLAT=1, HEAP_FLAT=0x200) for compute stages using
XCL_HEAP_WINDOWS=1 so every heap-window read in Lw::with_mem_i32s() lowers
to a single clamped ResourceDescriptorHeap[NonUniformResourceIndex(4 + w)]
load and select instead of a per-read branch, merge block, and PHI set.

Large compute shaders (including 95cc13288a27a96e with 1,316 heap-window
reads and a74706fb8f96ade9 with 1,012 reads) eliminate thousands of basic
blocks and PHIs on AMD RDNA4 as well as NVIDIA; heap_raw_buffer_uav already
sets NonUniformResourceIndex=true and out-of-range/inactive lanes read
harmlessly from window 0 and select 0.

Includes gpu_heap_flat_reads_match_the_switch_form regression test.

Assisted-by: Antigravity (Gemini 4 Neon High)
@SlopTart

Copy link
Copy Markdown

Tested: current PR head merged onto current origin/main (clean), Linux (Arch, kernel 7.2.15), Mesa 26.2.5 RADV, Radeon RX 7900 XT (NAVI31), cargo target x86_64-pc-windows-gnu run under wine-11.0 (Proton), rustc 1.94.0, vkd3d-proton 3.1 with the XCL patch, official MS DXC (binaries 2026-09-29).

gpu_ suite, cold cache: 161 passed / 4 failed. Three are the known baseline trio on this lane; the fourth is the new gpu_promoted_uav_clear_values_pass_create_committed_resource failure that current main carries (reported here), not caused by this PR. Everything else is green.

Not tested: retail titles (no title data on this lane, counts only).

AI use: Hermes agent (local Qwen-class) ran both machines and drafted this; I checked it before posting.

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

Labels

goal:world-load Bears on the retail title getting past world loading

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants