Recompiler: direct DXIL reads heap memory windows without a branch #2427
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!2427
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2427"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@Kalmarv on GitHub · 2026-11-25 18:37 UTC · original
Kalmarv:heap-flat-loads→main· +180 −12 · 7 files · 1 commits · openPart of #2088.
With heap memory windows (
XCL_HEAP_WINDOWS=1), every read in a direct-DXIL compute program is a branch onw < 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:w's heap view. It uses window 0 instead whenwis 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.HEAP_FLATflag is in the windows count, so the caches keep the forms apart.kernel::reads_heap_flat). Vertex, pixel, mesh and GS programs keep the guarded form, and the HLSL path is unchanged. Before, mesh and GS programs read flat too (@pvfreis's review). Only reads change: raw, SMEM, unaligned, format and BVH node loads (all thewith_mem_i32scallers). Stores and atomics keep their branch.Result, on native Windows and NVIDIA: this form builds these five large programs 34–64 % faster than the guarded heap form. Its native code is 2.4 % smaller than the guarded form's in total (1.5–4.8 % per program).
The table was measured on 0f045140, this PR before its rebase onto
6d12f58a. Its switch column is the form from before #2368;mainnow reads compute memory through #2368's select instead.Cold pipeline builds on an RTX 5070 Ti (NVIDIA 610.74), shader cache disabled (
ShaderCacheControl), 4 windows, split wave64:main's root UAVs.GetCachedBlob) is 2.4 % smaller than the guarded form's here (1.5–4.8 % per program), and 0.974 times its size over 60 records on @pvfreis's RTX 3060, where 12 of the 60 are larger. Against root UAVs, the gap is larger; #2428, which turns this form on by default, has those numbers.What is in it
gpu/dxil/lower_mem.rs: the one-path read inwith_mem_i32s.gpu/dxil/kernel.rs,gpu/dxil/lower.rs:heap_flatinLw.kernel::reads_heap_flatsets it for kernel and CS entries withHEAP_FLATand heap windows. Test:only_compute_programs_read_heap_windows_flat.gpu/recomp/mod.rs,gpu/recomp/pso.rs: theHEAP_FLATflag andXCL_HEAP_FLAT=1. The HLSL path strips the flag the way it stripsHEAP_WINDOWS.pso::windows_forgives the windows ofnfor this run;mem_windowstakes it.shaders.rs:xcl shaders(--precompile,--export-hlsl,--measure-pso) takes its windows frompso::windows_fortoo, instead of its own copy of the rule, which had noHEAP_FLAT. WithXCL_HEAP_FLAT=1, the precompile made the guarded form's entries, not the ones the runtime looks up (found by @bielfreedom). Test:precompile_windows_are_the_runtimesruns withXCL_HEAP_WINDOWS=1andXCL_HEAP_FLAT=1or0in a new process and compares the windows with the runtime's. It fails with the old copy (260 against 772).gpu/recomp/tests.rs:gpu_heap_flat_reads_match_the_switch_form.s_buffer_load_dwordx4from window 3, abuffer_loadfrom window 1, and per-laneglobal_loads spread over all four windows.v_cmpx), and there is a SADDRglobal_load_dwordx2.Tested
cargo test --workspace --no-fail-fast -- --test-threads=4on this head,c8c2b7a6(onmain6d12f58a): 1426 passed, 0 failed, 46 ignored.V_MUL_F16,V_PK_MUL_F16,V_CVT_F16_F32), and 1 for no heap windows (the switch-form fallback test, since heap windows are opt-in here).gpu_heap_flat_reads_match_the_switch_form,only_compute_programs_read_heap_windows_flatandprecompile_windows_are_the_runtimespass.XCL_DIRECT_DXIL=1 XCL_HEAP_WINDOWS=1 XCL_HEAP_FLAT=1, 60 s, release, one run beside other jobs on the same machine. There was no device removal and no crash. It showed 1474 frames and was still presenting at the end (52, 38 and 50 frames per 2 s), with a peak commit of 17993 MB. Its log shows the memory windows coming from the shared descriptor heap. There is nomainrun of the same length to compare with.Tested by others
@pvfreis (#2428, comment 7177531683): RTX 3060, NVIDIA 617.14, on #2428's ab2855f, which contains this PR.
@Eterst (#2496, comment 7176075746): RTX 4070 SUPER 12 GB, NVIDIA 616.92, Windows 10 19045, release.
6d12f58with #249678bba5cand this PR's d356a74.XCL_DIRECT_DXIL=1 XCL_HEAP_WINDOWS=1, split off, a full precompile with the same switches, then a title run withXCL_WINDOW_NO_CARRY=1 XCL_HEAP_FLAT=1.main06055a7): four runs lost the device (0x887a0005) at 261–303 s.@bielfreedom (comment 7180279957): RX 9070 XT 16 GB (RDNA4), AMD driver 32.0.32029.2010, Ryzen 7 7700, 32 GB, Windows 11, release.
main08db802. It had their one-line fix of the precompile windows, now in this PR, and a local patch that logs each program's DXIL size andCreateComputePipelineStatetime.xcl shaders --precompile --only cs --pipelineswithXCL_DIRECT_DXIL=1 XCL_HEAP_WINDOWS=1 XCL_PSO_DISK_CACHE=0, one driver thread, every build cold. The flat and guarded arms come from one binary.c8c2b7a, with no local change (comment 7181043742), merged ontomainb49be18with only their timing patch:XCL_HEAP_WINDOWS=1 XCL_HEAP_FLAT=1 xcl shaders --precompilenow makes the flat form. Its DXIL is 728.9 → 702.1 MB (−3.7 %, 2,639 changed), the same bytes, program for program, as their run with the hand-added fix.Regression run
scripts/smoke.ps1through our run script, 120 s, release builds,XCL_DIRECT_DXIL=1, in one queue job:mainb49be18, then this head. Both sides use the same data root and XCL cache, warmed by earlier runs, and start from the same learned coherent-window state.xcl shaders --precompilecount, through both sides), and another agent's GPU test suite ran beside themainside only (about 60 of its 120 s).main's frames (1522 against 1738) and 101.7 % of its peak commit (28999 against 28514 MB). The run uses this PR's defaults, where the flat form is off.mainb49be18:This PR (
c8c2b7a6):Not tested
mainover the same time.AI use
🤖 Generated with Claude Code
@FIJI1299 on GitHub · 2026-11-25 18:49 UTC · original
Tested commit
717fec5on Windows:Environment
621.40,wave32)1.8.2502.11(Windows SDK10.0.26100.0)Results
cargo test -p xcl --lib -- --skip fuzz_validate_and_gpu): 1216 passed, 1 failed, 26 ignored, 4 filtered out (14.73s).XCL_HEAP_FLAT/XCL_HEAP_WINDOWSGPU tests: Passed cleanly on nativewave32NVIDIA hardware.main:gpu::recomp::lower_dxil::tests::a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier(assertion left == right failed: group barriers in the program: left: 3, right: 1).gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_0..3(filtered out; known RTX 5000 driverE_OUTOFMEMORY0x8007000Eon non-constantgroupsharedatomic subtract tracked in #1905 / #1919).@SlopTart on GitHub · 2026-11-25 19:18 UTC · original
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 targetx86_64-pc-windows-gnurun 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 newgpu_promoted_uav_clear_values_pass_create_committed_resourcefailure 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.
@DavidM1911 on GitHub · 2026-11-25 20:04 UTC · original
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: 1038 passed, 1 failed in one parallel run; the failing test passes on a single-threaded rerun (1039/0). Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.Thanks!
@pvfreis on GitHub · 2026-11-25 22:24 UTC · original
By reading only, at
d356a74and #2428ab2855f:68a284a) predates #2368 (merged 19:59, now in both heads' base). #2368 replaced the switch on compute raw loads with selects and reports builds up to 3.5 times as fast for that form. So the switch column, and #2428's 1.1–3.8 times (body andheap_windowscomment) and 11–25 %, are not against the form #2428's default replaces now. Rerunning the five programs on the current base would settle it.heap_flatis off only forEntry::Vertex | Entry::Pixel, so withXCL_HEAP_WINDOWS=1and direct DXIL the mesh and GS compute passes read flat too (by default after #2428). The new test runs a kernel program only.AI use: Claude Code (Claude Opus 5.5) found this; a second Claude Opus 5.5 re-derived it; Claude Fable 5.2 reviewed the text; checked by a person before posting.
@bielfreedom on GitHub · 2026-11-26 01:55 UTC · original
AMD Windows driver timing for #2427: on an RX 9070 XT with heap windows,
XCL_HEAP_FLAT=1makes AMD'sCreateComputePipelineStateabout 11 % faster over 26 large retail compute programs and lowers peak memory. One catch first:xcl shaders --precompilenever setsHEAP_FLAT, so offline the switch does nothing.The offline tool:
pso::mem_windowsaddsHEAP_FLAT, butshaders.rs'sruntime_windowsbuilds its own count (windows | HEAP_WINDOWS). With this PR as is,XCL_HEAP_WINDOWS=1 XCL_HEAP_FLAT=1 xcl shaders --precompilegives the same bytes as without the switch for all 2,689 programs. So with the switch on, what the offline precompile caches would not be what the runtime looks for. For the numbers below I added| if recomp::pso::heap_flat() { recomp::HEAP_FLAT } else { 0 }toruntime_windowslocally.Setup
main08db802, plus the one-line hookup above and a local timing patch that writes each program's DXIL size and eachCreateComputePipelineStatetime to a file. Measured atd356a74and again at the current headf8b3191; the numbers below are fromf8b3191(d356a74gave the same sizes and a 10.5 % driver gain). One binary for both arms; only the switch differs.xcl shaders <retail shaders.rpf> --precompile --only cs --pipelineswithXCL_DIRECT_DXIL=1,XCL_HEAP_WINDOWS=1,XCL_PSO_DISK_CACHE=0, one driver thread, a fresh translation cache and a fresh executable name for every run (the AMD driver keys its own cache on the exe name, so every build is cold).DXIL size, all 2,689 compute programs, heap windows (translation only)
XCL_HEAP_FLAT=1main)Driver time, 26 large programs, 2 interleaved rounds (off, on, then on, off)
XCL_HEAP_FLAT=1Mean 73.5 → 65.2 s (−11 %), and no pipeline failed. The gain is much larger than the 3.7 % size cut, which fits the description: AMD also seems to pay for the blocks, not the bytes. Largest programs:
620491641aa9bad66d1e4583f81297717c08ec6429245b8e6f3a2502a8d6b12983a3df882bebfdabNot measured:
95cc13288a27a96e(ActivateRays, 17.6 GB with heap windows on #2375), GPU output, and a title run.AI use: Claude Code (Claude Opus 5.5) built the binaries, ran the measurements and wrote this report; I posted it.
@Kalmarv on GitHub · 2026-11-26 01:55 UTC · original
@pvfreis thank you for both: the reading on #2427 and the RTX 3060 run on #2428.
1. Baseline. You're right: the table predated #2368. A same-job rerun of the five programs on
main6d12f58ais queued: RTX 5070 Ti (610.74), cold, A B B A, in four forms (the old switch, #2368's select form, the guarded heap form and the flat heap form). Until it lands, the bodies state each claim against the form it was measured against:heap_windowscomment.2. Scope. Also right: with
XCL_HEAP_WINDOWS=1, the mesh and GS compute passes read flat too, and that form was never timed or GPU-tested. I narrowed the code rather than the claim. Flat reads are now for kernel and CS entries only (kernel::reads_heap_flat), and mesh, GS, VS and PS keep the guarded form. A test,only_compute_programs_read_heap_windows_flat, covers it. It is in #2427's commit, now f8b31918.Your other results. Your suite (1429 passed, 1 failed, 46 ignored; only e2e
presentsfails, and it fails onmaintoo) and the native sizes are in the bodies under Tested by others, with a link to your comment. On the repeat check: I haven't looked into why blob contents differ between runs either. The sizes were equal 60/60, and the size claims use only sizes.AI use: Claude Code (Claude Opus 5.5) made the changes and the measurements and wrote this reply.
@Kalmarv on GitHub · 2026-11-26 02:20 UTC · original
@bielfreedom thank you, that is a real bug, and the AMD timing is very useful.
The fix, in this PR's commit, now
c8c2b7a6:xcl shaders(--precompile,--export-hlsl,--measure-pso) no longer has its own copy of the window rule. It takes its windows frompso::windows_for, the same functionpso::mem_windowsuses at run time. WithXCL_HEAP_WINDOWS=1 XCL_HEAP_FLAT=1, the precompile now makes the entries the runtime looks up.shaders::tests::precompile_windows_are_the_runtimes, runs withXCL_HEAP_WINDOWS=1andXCL_HEAP_FLAT=1or0in a new process, since both switches are read once. It checks that the precompile's windows are the runtime's. With the old copy it fails: 260 (noHEAP_FLAT) against 772.HEAP_FLAT. It is rebased onto the fix and keeps one shared function (pso::compute_windows) for the precompile and the runtime. The same test runs there.This corrects what I wrote to @bmjask above: precompiled entries for this form are found with the flag on.
Your setup and numbers are in the description under Tested by others, credited to you: 3.7 % less DXIL over 2,689 programs, and 11 % less AMD
CreateComputePipelineStatetime over 26 large programs, with lower peak memory and no failures.AI use: Claude Code (Claude Opus 5.5) made the fix and the test and wrote this reply.
@DavidM1911 on GitHub · 2026-11-26 02:22 UTC · original
Re-verification on RTX 3060 Ti (Windows 11), new head merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.Thanks!
— Devin
@bielfreedom on GitHub · 2026-11-26 02:42 UTC · original
@Kalmarv confirmed on the RX 9070 XT: at
c8c2b7a, with no local change,XCL_HEAP_WINDOWS=1 XCL_HEAP_FLAT=1 xcl shaders --precompilenow makes the flat form.mainb49be18. Only my timing patch is added: it writes eachCreateComputePipelineStatetime to a file.AI use: Claude Code (Claude Opus 5.5) built the binary, ran the measurements and wrote this; I posted it.
@pvfreis on GitHub · 2026-11-26 03:01 UTC · original
Follow-up, by reading only, not run, at
c8c2b7a6and #2428970823e4. Both points are addressed.heap_windowscomment. Each remaining build-time figure names the form it was measured against (the guarded heap form, or the switch from before #2368). Still open, as both bodies say: build time against #2368's form.heap_flatis set in one place (kernel.rs:537), fromreads_heap_flat, which is true only for kernel and CS entries, andwith_mem_i32sis its only reader. Mesh and GS passes are translated asEntry::Mesh/Entry::Geometry, so they keep the guarded form withXCL_HEAP_WINDOWS=1 XCL_HEAP_FLAT=1. In #2428 they take heap windows only withXCL_HEAP_WINDOWS=1(pso::mem_windows).AI use: Claude Code (Claude Opus 5.5) checked this; Claude Fable 5.2 reviewed it; checked by a person before posting.
@Kalmarv on GitHub · 2026-11-26 03:02 UTC · original
@pvfreis thank you for reading both heads again.
On point 2: the scope is stated under Scope in this PR's description (compute programs only,
kernel::reads_heap_flat), andonly_compute_programs_read_heap_windows_flattests it. #2428's description says so under How it decides: graphics, mesh and GS take heap windows only withXCL_HEAP_WINDOWS=1, throughpso::mem_windows. On the open item, build time against #2368's form, the same-job rerun of the five programs is still queued.AI use: Claude Code (Claude Opus 5.5) wrote this reply.
@Kalmarv on GitHub · 2026-11-26 01:55 UTC · original · edited 2026-11-26 04:13 UTC
@bmjask thanks for the review.
Rebased. This PR is now
c8c2b7a6, onmain6d12f58a, so #2368 is in its base. The suite on that head: 1426 passed, 0 failed, 46 ignored.The table. It was measured before the rebase, and its switch column is the form from before #2368. The body now says so and states the claim against the guarded heap form, which this opt-in flag replaces. Against that form, the flat form built the five large programs 34–64 % faster, and its native code was 2.4 % smaller in total. On @pvfreis's RTX 3060 it was 0.974 times the guarded form's size over 60 records, with 12 of them larger. Those five programs are all the compile-time evidence there is, and the body says the gain is shown only for them. A same-job rerun on the new base, with #2368's form as a fourth column, is queued.
Scope. Flat reads are now for compute programs only (kernel and CS entries,
kernel::reads_heap_flat). Mesh and GS passes read flat before withXCL_HEAP_WINDOWS=1; now they keep the guarded form.only_compute_programs_read_heap_windows_flatcovers it (@pvfreis's point).Regression pair (in the body), on
c8c2b7a6againstmainb49be18, 120 s,XCL_DIRECT_DXIL=1: no removal or crash, 87.6 % ofmain's frames (1522 against 1738) and 101.7 % of its peak commit.XCL_HEAP_FLATtitle run: this head withXCL_DIRECT_DXIL=1 XCL_HEAP_WINDOWS=1 XCL_HEAP_FLAT=1, 60 s, one run. There was no device removal and no crash, 1474 frames, still presenting at the end, and a peak commit of 17993 MB. @Eterst ran a title with this PR and #2496 together on an RTX 4070 SUPER (#2496, comment 7176075746): no device removal up to 395 s, wheremain06055a7lost the device at 261–303 s in four runs. That run is not separated from #2496, and it is one run.AMD / Intel. I have neither. @bielfreedom timed the form on an RX 9070 XT (comment 7180279957), and found and confirmed a precompile-key fix (comment 7181043742):
xcl shaders --precompilenow keys this form as the runtime does.AI use: Claude Code (Claude Opus 5.5) made the changes and measurements and wrote this reply.
github-bot referenced this pull request2026-11-26 06:18:31 +00:00
@bmjask on GitHub · 2026-11-25 21:03 UTC · original · reviewed
No concrete source-level defect found. Flat path clamping/select behavior, cache identity, and GPU parity coverage look sound. This draft is not merge-ready: merge state is unstable, required main/head regression pair is pending, and there is no XCL_HEAP_FLAT title run or AMD/Intel validation. The documented precompiled-cache misses are acceptable only while opt-in measurement remains the scope; rebase and provide current evidence before merge.
xcl nvprofileputs xcl.exe in an NVIDIA profile with a bigger shader heap (#2403) #2590github-bot referenced this pull request2026-11-26 07:52:45 +00:00
github-bot referenced this pull request2026-11-26 12:40:17 +00:00
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.