Repository navigation
Recompiler: compact form that emits every distinct block text once - #1315
CowboyBingus wants to merge 3 commits into
Conversation
|
AMD run with 64-lane waves, where Tested: pass, head
Not tested: the whole workspace suite; #1316 on top of this; a title; compile time of the big program. AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report. |
|
Test report for this PR on an adapter with native 64-lane waves, which covers the test listed as skipped above. Commit: Hardware: AMD Radeon(TM) Graphics (integrated, Ryzen 9 7900X3D; driver 31.0.24002.92) and NVIDIA RTX 5070 Ti (driver 32.0.16.2124), 64 GB RAM, Windows 11 26300, Rust 1.100.0, DXC 1.9.2602.17. Tested
Not tested
AI use: Claude Code (Claude Fable 5.2) ran the tests and wrote this report. |
|
Verification on RTX 3060 Ti (Windows 11), branch merged with current
Thanks! |
|
Edited: rerun on the current head Test report for this PR's head Tested
Not tested
AI use
|
7118972 to
d58677a
Compare
d58677a to
732f2ff
Compare
|
Rebased onto AI use: Claude Code (Claude Opus 5.5) wrote this comment. |
732f2ff to
a45ac0c
Compare
a45ac0c to
a940184
Compare
8174658 to
c195f07
Compare
The third-largest compute program of a retail pack repeats itself as the two largest do (13,890 blocks of 2,643 kinds), but its branches go to 6,530 different pairs of offsets. As an index into a table of pairs its tables were about 24,000 words, over the limit, and it kept the plain form: 3.9 MB of DXIL. In it, as in the other large programs, a block's second successor is the next block or the same as its first. When every conditional branch of a program falls through to the next block, a table entry now holds the taken successor itself if that makes the tables smaller: 11,287 words here, in one table. The limit goes from 8,192 to 12,288 words, the size xcl-dev#1315 measured an RTX 5070 Ti accepting in the HLSL form, and the program takes the form. Part of xcl-dev#1269. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…nslate No behaviour change: the decoding, block leaders and emitter set-up at the start of translate() move into prepare(), so a second form of the program (the compact form) is built from exactly the same decoded program and emitter state. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
DXC inlines every helper of a cs_6_x target, so a retail compute shader with thousands of equal blocks (ActivateProbes 56c0cd3b82a00c6e: 88,863 instructions, 3,281 buffer_load_format_x) becomes 29.75 MB of DXIL that the driver needs minutes for. translate_compact() cuts the program into blocks (leaders, plus every instruction whose HLSL exceeds 600 B on its own), emits each instruction with emit::Em as translate() does, temporaries numbered from t1 per instruction, and shares equal block texts as cases of one dispatch loop. Branches go to a block at an offset from their own (part of the text), so a static table only holds every block's case, packed. The table is capped at 8,192 words: on an RTX 5070 Ti, CreateComputePipelineState of this program's compact form with an added 12,288-word static array succeeded; with 15,360 words it failed with E_OUTOFMEMORY. Back edges spend the loop budget (65,536 per lane); once it is spent the program ends, where the structured form leaves the loop and runs what follows. compact_wanted() picks programs of 20,000+ instructions whose distinct blocks hold under 30 % of them. Not called yet. Measured on 56c0cd3b82a00c6e (4 memory windows, split wave64, RTX 5070 Ti, a local merge, 31be310): 723,453 B HLSL, DXIL 1,053,264 B in 12.5 s, CreateComputePipelineState 9.7 s from a new exe with no cached blob. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tests_compact translates each program with translate and with compact::translate_compact and runs both on the same inputs. The kernel programs assert byte-identical SGPRs, SCC, VGPRs of all lanes, exports and the split form's upper-half SGPRs, plus flat memory or the first 64 KiB of each memory window; the compute dispatch compares memory. Programs: nested execz regions, divergent and scalar backward loops, one block repeated at five addresses, far jumps (s_getpc_b64, add or sub, s_setpc_b64) forward and backward, v_mul_lo_u32, buffer_load_format_x in twelve formats and repeated as a block of its own, a cross-lane block (ballot, readfirstlane, readlane) repeated under four exec masks, s_endpgm before the last block, a loop through four memory windows with loads, stores and per-lane atomics, a compute dispatch, and 200 forward jumps that xcl-dev#1307's bound sends to pc blocks in translate (gpu_compact_against_the_pc_block_fallback). The kernel programs run in each form forms() lists for the adapter (wave64 split or native, wave32; with branches also unstructured), and in the wave64 forms with mem_windows: 4; the compute dispatch runs in wave64 (split where the adapter needs it) and wave32. Every program here except one has a branch, and the tests assert that translate_compact gives it the compact form: they read its dispatch loop back from the HLSL. translate_compact keeps translate's form for a program without branches, so the two straight-line programs start with a branch to the next instruction. For the repeated blocks, the exchange block, the buffer loads, the window loop, the far jumps and s_endpgm they also assert the shape: fewer cases than blocks, one case for the four copies of the exchange block and one for the block after the load, the load a case of its own, the far jumps' block offsets, two program ends before the last block. The exception is the memory-window program of gpu_memory_windows_above_4_gib (no branch): it gets translate's form from both, so its test compares translate with itself; the window loop runs the compact form through the windows. The atomics in the memory-window programs add to a dword per lane. On an RTX 5070 Ti (split wave64, 4 windows), with all 64 lanes adding to one dword, 40 runs of the same DXIL returned two different lane 0 values (5 and 35 runs): the split halves' atomics land in either order. gpu_compact_sample_big_cs (XCL_SAMPLE_BIG_CS=<code file>) runs a retail program both ways. A program translate_compact refuses (e.g. its table limit) is SKIPPED; when the driver cannot create translate's pipeline (e.g. E_OUTOFMEMORY), the A/B comparison is SKIPPED and the compact form must still compile and run. Needs the compact backend (compact.rs and `pub mod compact`). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
c195f07 to
0d7907b
Compare
A compact translation for very large compute programs whose basic blocks repeat: each distinct block text is emitted once, as a case of one dispatch loop, and a static table gives every block's case and branch offset. Part of #1269 and #505 (the 29.75 MB
ActivateProbesprogram, see this comment).This PR adds the form and its tests; nothing calls it yet. #1316, stacked on this one, routes compute programs to it.
Measured on an RTX 5070 Ti (driver 621.24),
indirect_diffuse_lighting:CS_ScreenProbes_ActivateProbes(56c0cd3b82a00c6e, 88,863 instructions), 4 memory windows, split wave64, through XCL's own DXC path and level rule;CreateComputePipelineStatewith XCL's ABI root signature, no cached blob, from a new exe:translatetranslate_compact-O0)CreateComputePipelineStateThe
translatecolumn was measured on47efa2eplus one local commit outsidegpu/(bc394e3). The 600 s run was the same DXIL (sha256e45bc693…) on another local tree. Thetranslate_compactcolumn was measured on a local merge (31be310) whosecompact.rsdiffers from this PR's in two comments.The program has 14,378 basic blocks, and 594 distinct block bodies when branch targets are set aside.
compact_wantedtakes programs of 20,000 instructions or more whose distinct blocks hold under 30 % of the instructions. By a survey of the retail pack's 2,689 compute-program records (2,682 distinct programs) that applies the same rule, these are56c0cd3b82a00c6e,958400d2caf07244(ActivateProbesTarget) and95cc13288a27a96e(ActivateRays).ActivateRaysneeds a 9,975-word table. The table is capped at 8,192 words: a static array is constant data for the driver, and on this GPUCreateComputePipelineStateof this program's compact form with an added 12,288-word static array succeeded, and with 15,360 words failed withE_OUTOFMEMORY. Sotranslate_compactreturns an error forActivateRays, and the caller keepstranslate.Related: #1278 and #1279 change how programs of 4 MB of DXIL or more are scheduled. This PR adds a form for two of them, and the stacked PR routes them to it.
What is in it
Recompiler: decode and set up the emitter in prepare(), shared by translate–gpu/recomp/mod.rs, no behaviour change.preparealso takes theHEAP_WINDOWSflag out ofmem_windows, astranslatedid since Recompiler: memory windows from the descriptor heap (no per-access switch) #680, so the compact form gets the same options.Recompiler: compact form that emits every distinct block text once:gpu/recomp/compact.rs(new).gpu/recomp/emit.rs:reset_temps, so temporaries are numbered from t1 for each instruction.emit::Emproduces for each instruction, as intranslate; the A/B tests below compare the results.Tests: A/B tests of translate_compact against translate on the GPU–gpu/recomp/tests_compact.rs.buffer_load_format_xas its own block at several addresses, and in 12 formats;s_setpc_b64forward and backward;s_endpgmbefore the last block;v_mul_lo_u32;pcblocks intranslate;XCL_SAMPLE_BIG_CS=<code file>adds a retail program; a programtranslate_compactreturns an error for (e.g. its table limit) is SKIPPED, and whenCreateComputePipelineStatefails fortranslate's form the A/B comparison is SKIPPED and the compact form must still compile and run.translatedoes; the runtime code is about 380 lines.Tested
0d7907b(onmain6e1e2be):cargo build --workspaceandcargo build --releasesucceeded;cargo test -p xcl --lib compact -- --test-threads=4: 25 passed, 0 failed, 0 ignored, withgpu_compact_native_wave64_formSKIPPED (no wave64);cargo test -p xcl --lib pso:: -- --test-threads=4: 16 passed, 0 failed, 1 ignored (compile_time_bench::repeated_pso_shader_compile). The full suite was not run on this head.cargo build --workspace, thencargo test --workspace --no-fail-fast -- --test-threads=4(debug) on an earlier head of this PR,c195f07(onmain266b845): 976 passed, 1 failed, 42 ignored (lib tests 927 / 1 / 22). The failure ishle::kernelx::tests::xmem_virtual_query_marks_cpu_readable_memory(kernelx.rs:2070), which fails the same way onmain930e8b4. SKIPPED (no wave64):gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware,gpu_compact_native_wave64_form, and 16 lines ofmain'slower/lower_dxiltests. SKIPPED (per-lane form refused): 3 lines oflower_dxil's f16 / f32-conversion tests. SKIPPED (no heap windows):heap_window_out_of_memory_falls_back_to_the_switch_form.Regression run
scripts/smoke.ps1 -Game <game folder> -Seconds 60 -Title retail(release builds, menus, no input):main:
this PR:
Not tested
translateform did not finish in the driver within 600 s on this GPU.XCL_HEAP_WINDOWS=1): the A/B tests use the switch form.AI use
🤖 Generated with Claude Code