Repository navigation
Recompiler: pick root-UAV memory windows with bit tests, not a switch - #2191
ezamelczyk wants to merge 1 commit into
Conversation
The accessors that pick a memory window (`xcl_mLoad`, `xcl_mStore`, the atomics, `xcl_loadx4`) branched with `[branch] switch (xcl_w)` over the root UAVs. Mesa's SPIR-V front end (vtn) lowers OpSwitch into a chain of ifs with a path on which no case runs. In a loop, every accessor result then becomes a loop-carried value that is undefined on entry, and RADV has to keep all of them live around the loop. On a 1.28 MB-DXIL CS_RaytracingResolve program (console 84eee477d68b6fdf), NIR had 4 624 loop-header phis where the SPIR-V had 204. ACO needed about 3 800 SGPRs, and its spiller grew past 20 GB in 100-140 s (the out-of-memory builds reported in xcl-dev#1269). Each window is now one `[branch] if` on a value that is set before the first one, so nothing is carried round the loop. The ifs test bits of a one-hot mask, `wm = select(xcl_w < windows, 1u << xcl_w, 0u)`, not `xcl_w == k`: with equality tests DXC's jump threading took 31 of 47 s of the same program's compile. An `xcl_w` outside the windows sets no bit and keeps the default, as the switch's `default` did. The heap form (`XCL_HEAP_WINDOWS=1`) is unchanged. That program on an RX 9070 XT, Mesa 26.3.1 RADV, vkd3d-proton (VKD3D_SHADER_CACHE_PATH=0), one cold build: - switch: 103-140 s, 20.5 GB peak, 3 840 SGPRs - bit tests: 39 s (DXC about 20 s of it), 1.26 GB peak, 301 SGPRs, 192 VGPRs; 644 loop-header phis in NIR Part of xcl-dev#1269. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Independent native Windows compiler measurement on exact PR head Environment: Windows 11 build 26200, Ryzen 9 5980HX, RX 6800M driver I compiled each exported HLSL file using
All six DXC processes exited 0. On this Windows DXC path, the PR's median was 6.109 s / 17.9% longer and its DXIL was 221,060 bytes / 17.2% larger for this record. The sampled RSS is an approximate process measure, not total system commit. This differs from the Linux/RADV end-to-end improvement in the PR description; it does not measure or contradict the RADV driver result. Scope: Exact-record HLSL generation and standalone native DXC compilation only. I did not run AI use: OpenAI Codex identified the record in the locally owned pack, built the PR, exported both HLSL variants, wrote and ran the bounded DXC measurement script, checked the exact revisions and numbers, and prepared this report. |
|
AMD Windows driver data for #2191: on the RX 9070 XT, the bit-test form makes the DXIL 15 % larger and AMD's Setup
Method
24 programs (means of 2 rounds; all 96 builds succeeded, 0 refused)
The DXIL sizes match luckyteagirl's (+17 %). Both builds were still working, at 9–11 GB private, when they were killed. So on AMD Windows the bit tests don't remove whatever stalls this program in the driver. The direct route (53 s whole, 7.8 s with #2107's split; data) remains the way through here. Read / inference
Not tested
AI use: Claude Code (Claude Opus 5.5) ran the measurements and drafted this. The account owner is away; counts and timings only, no game data. |
The memory-window accessors (
xcl_mLoad,xcl_mStore, the atomics,xcl_loadx4) now choose a root UAV with one[branch] ifper window, testing a bit of a one-hot mask, instead of[branch] switch (xcl_w). Part of #1269.Why: Mesa's SPIR-V front end lowers an
OpSwitchinto a chain of ifs with a path on which no case runs. Inside a loop, every accessor result then becomes a loop-carried value that is undefined on entry, and RADV keeps all of them live. This is the cause of theCS_RaytracingResolvebuilds that @Fran-co-F and @lucsoft saw ACO's spiller run out of memory on in #1269. In those builds the windows are root UAVs, which is the default because heap windows are opt-in. With per-window ifs the values are defined before the first test, so nothing is carried round the loop. The bits are tested as(wm & (1u << k)) != 0u, withwm = select(xcl_w < windows, 1u << xcl_w, 0u), notxcl_w == k: with equality tests, DXC's jump threading took 31 of 47 s of the compile. Anxcl_woutside the windows sets no bit and keeps the default, as the switch'sdefaultdid. The heap form (XCL_HEAP_WINDOWS=1) is unchanged.What is in it
crates/xcl/src/gpu/recomp/emit.rs(mem_accessors): the switch form is replaced by per-window bit tests.crates/xcl/src/gpu/recomp/tests.rs: the two checks that looked forswitch (xcl_w)look for the new form.Tested
RX 9070 XT (RDNA4), Mesa 26.3.1 RADV (ACO), Ryzen 5 8400F, 30 GB RAM, CachyOS kernel 7.3.6. Wine 11.0 Staging (GE-Proton), vkd3d-proton 3.1 with Linux: docs/linux.md, scripts/linux and Wine start-up checks for vkd3d-proton and DXVK (#154, #241) #257's patch and dxil-spirv
53aac418. DXC 1.9.2609. rustc 1.99.1, release, cross-built forx86_64-pc-windows-msvc. Not Windows.One retail program,
CS_RaytracingResolve(console84eee477d68b6fdf, 1.28 MB of DXIL in the switch form), one cold pipeline build (VKD3D_SHADER_CACHE_PATH=0, empty caches):main(switch)xcl_w == k(The register and phi counts come from a locally instrumented Mesa build. The times and memory are with the system Mesa.)
The retail pack's 2 689 compute programs,
xcl shaders shaders.rpf --precompile --only cs --pipelines: 2 689 compiled, 0 errors, 2 689 pipelines made, 0 refused. This was on a local tree with this change on top of Recompiler: route compute programs through a compact backend (XCL_COMPACT_CS) #1316, Recompiler: compact cases share code whose branch targets differ #1448 and kernelx: Sleep does not count the time a bind waits for a pipeline build #1288, not on this branch alone. In the switch form, the same pass ran out of memory on RADV in theCS_RaytracingResolvestretch for @lucsoft ([OFFICIAL] Looking for PRs with shaders optimization #1269).cargo test --workspace -- --test-threads=4(release, Wine): 1 083 passed, 15 failed, 26 ignored. SKIPPED:f16_programs_on_the_gpu/f32_programs_on_the_gpu(per-lane form refusesV_MUL_F16,V_PK_MUL_F16,V_CVT_F16_F32) andpso_measurement_compiles_an_exact_synthetic_record(no Developer Mode under Wine).main568e7dband on this branch, with identical results on both. 6 fail on both:fuzz_validate_and_gpu_2,f64_programs_on_the_gpu,f32_programs_on_the_gpu,gpu_nonfused_mad_and_mac_prevent_fma_contraction,gpu_depth_buffer_created_for_unordered_access_is_placed,xma2_source_voice_decodes_and_manages_lifetime. The other 9 pass alone on both; in the full run they failed because a device removal from another test took them out.gpu_memory_windows_reject_out_of_uma_aliasing,gpu_mesh_mode_reads_memory_windows,gpu_memory_windows_above_4_gibandgpu_bvh64_intersect_ray_across_memory_windows_and_grazing.Regression run
scripts/linux/smoke.shfrom #257 (it prints the blocksmoke.ps1prints), retail title, 300 s, the same button script. Each run had an empty DXIL cache, Mesa's shader cache off andVKD3D_SHADER_CACHE_PATH=0.In both runs presents had stopped before the end (
presents per 2 s (last 3): 0 0 0). I have not checked where each run stopped.main:
this PR:
Not tested
XCL_DIRECT_DXIL), which picks its windows separately.AI use
🤖 Generated with Claude Code