Skip to content

Recompiler: NVIDIA compute programs take flat heap windows by default - #2428

Draft
Kalmarv wants to merge 2 commits into
xcl-dev:mainfrom
Kalmarv:heap-windows-default
Draft

Kalmarv wants to merge 2 commits into
xcl-dev:mainfrom
Kalmarv:heap-windows-default

Conversation

@Kalmarv

@Kalmarv Kalmarv commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Part of #2088. Stacked on #2427; only the top commit belongs here.

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

On NVIDIA, the driver builds direct-DXIL compute programs 1.1–3.8 times as fast with #2427's flat heap windows as with the switch over root UAVs, and their native code is 11–25 % smaller (table in #2427). This PR turns that form on by default there, for compute programs only. Graphics stages, mesh, GS, other vendors and the HLSL path keep the switch, as they do today.

How it decides:

Why only compute, and not the HLSL path:

XCL_HEAP_WINDOWS was opt-in because two NVIDIA setups failed with it in #187's review:

  • The failures: the driver's compiler ended the process, and the device was removed when the views were made on an 8 GB card.
  • Fixed since: pipelines the driver refuses with E_OUTOFMEMORY now fall back to the switch form (927adcc). A view that some D3D12 runtimes refused, removing the device, is now capped (deb4b92).
  • Not confirmed: that those fixes cover the two failures. Neither setup was re-run.

What is in it

  • gpu/recomp/pso.rs:
    • heap_windows with the vendor default, set_adapter_vendor, heap_windows_everywhere, compute_mem_windows / compute_windows and hlsl_windows.
    • console_to_dxil_for takes the compute windows for a compute program.
    • XCL_HEAP_FLAT is on by default.
    • Tests: the default rule per vendor and env, and the windows each form takes.
  • hle/d3d12x/real.rs: the device's adapter vendor is noted before the UMA opens. driver_pso looks at the compute windows for the switch-form fallback.
  • shaders.rs, gpu/adapter.rs: the --precompile / --export-hlsl / --measure-pso keys follow the runtime's for the bench's adapter. The precompile key was missing HEAP_FLAT before.
  • gpu/uma.rs: XCL_UMA_WINDOWS=8|16 still needs XCL_HEAP_WINDOWS=1, since graphics need the heap for more than 4 windows.
  • tests/gpu_compute_e2e.rs: the switch-form fallback test checks the compute windows.

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 this head: 1292 passed, 1 failed, 46 ignored.
    • The failure, a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier, also fails on main 68a284a5.
    • 24 SKIPPED notices: 8 for no wave64 and 16 for the per-op wave64 forms.
    • heap_window_out_of_memory_falls_back_to_the_switch_form used to be skipped here. It now runs, because heap windows are on by default on this NVIDIA card, and it passes: a refused heap-window pipeline is rebuilt in the switch form and runs correctly.

Regression run

  • pending (main 68a284a5 vs this head, default settings, XCL_DIRECT_DXIL=1)

Not tested

AI use

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

🤖 Generated with Claude Code

Kalmarv and others added 2 commits November 25, 2026 13:18
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>
On NVIDIA the driver builds a direct-DXIL compute program 1.1-3.8 times as
fast with flat heap windows (HEAP_FLAT) as with the switch over root
UAVs, and its native code is 11-25 % smaller. Turn that form on by
default there, for compute programs only.

- pso::heap_windows: XCL_HEAP_WINDOWS=1 every stage (as before), =0 none,
  unset: on when the title's adapter is NVIDIA (set_adapter_vendor, from
  the device's DXGI adapter). XCL_HEAP_FLAT=0 turns the flat form off.
- compute_mem_windows: the windows of a compute program, with the heap
  by default; mem_windows (graphics, mesh, GS) takes the heap only with
  XCL_HEAP_WINDOWS=1. The HLSL path keeps the switch unless
  XCL_HEAP_WINDOWS=1 (hlsl_windows): its heap form is not measured.
- A pipeline the driver refuses with heap windows is still built in the
  switch form (with_switch_fallback); driver_pso looks at the compute
  windows for that now.
- xcl shaders --precompile / --export-hlsl / --measure-pso: the keys of
  the runtime, from the bench's adapter (HEAP_FLAT was missing from the
  precompile key).
- XCL_UMA_WINDOWS=8|16 still needs XCL_HEAP_WINDOWS=1.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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.

1 participant