Recompiler: structured form for programs that needed the pc chain #172
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!172
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-172"
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?
@Foniass on GitHub · 2026-11-23 18:48 UTC · original
Foniass:t3/compile-time→main· +1034 −2 · 3 files · 1 commits · draftLane L6 of the compile-time handoff (emitter and DXC cost).
Update 19:35 UTC: measured again with
retail_translation_survey, the DXC gain is 6–8 %, and there is none on top of #174 (second table below).What was slow
3 325 of the retail pack's 26 698 programs fall back to the
while (pc …)dispatcher. On a 1-in-100 sample (4 memory windows) they are 13 % of the programs and about two thirds of DXC's time.-ftime-reporton the slowest one shows jump threading at 27 % and the loop passes (LCSSA, indvars, unroll, loop deletion) most of the rest: every value of the dispatcher loop is loop-carried.structurableworks on the layout: every backward jump is a loop to it. The common failing shape is not a loop at all: the console compiler puts blocks after the code they jump back into and enters them from before it (acyclic, the jumps only go backwards in memory). Loops with several heads or exits are the rest.What changed
gpu/recomp/structure.rsstructures any reducible program from its dominator tree (N. Ramsey, "Beyond Relooper", ICFP 2022):for (;;)(withLOOP_GUARD);do { … } while (false);xcl_br, and each construct passes it on.It runs only where
structurablefails, after a dry run: a program it rejects is emitted exactly as before. Unreachable blocks still go through the emitter (their text is dropped), so the registers, samplers and unsupported counts are those of the other forms. Left on the pc chain: 21 irreducible programs and the ES + GS pairs (58 programs in all, was 3 325).Measured (RTX 5070 Ti machine, 16 threads, DXC 1.9.2602.17, dxc.exe, 8 compiles at once, nothing else running)
DXC CPU time, 1-in-100 sample (253 programs, every 100th by name hash), translated with 4 windows. DXC got
-O1above 1 MB of HLSL, asdxc::compiledoes since956a476. Runs interleaved:956a476--precompile --limit 2650, cold cache, split wave64 form: main 276.1 s, this PR 284.2 s, 0 errors each. One run per side, so no spread. That slice holds only 5 of the 3 267 changed programs (11 s of their 21 326 s of DXC CPU), so it cannot show the change. An end-to-end run over a slice that holds them is not done yet.Measured again with
retail_translation_survey, alone and with #174 (19:05–19:32 UTC)Same machine, release build, the test's own DXC (4 threads):
XCL_SURVEY_EVERY=100,XCL_SURVEY_DXC=1,XCL_SURVEY_WINDOWS=4, two seeds. #174 was merged locally (it conflicts only at the end oftests.rs) and run with its linking off (XCL_LINK_MEM=0) and on. Runs interleaved; total DXC time the test prints:956a476So if #174 is merged, what this PR still gives is fewer programs on the dispatcher loop. Whether that helps the driver's compile time or the GPU's run time is not measured.
Output and correctness
main. The 3 267 that differ were all on the pc chain.XCL_RECOMP_CHECK=1turns it on elsewhere.gpu_general_structure_matches_the_pc_chainruns synthetic programs with the retail shapes (bottom entries, a jump out of two loops, a two-entry loop, a plain loop) as wave32 and wave64 (split on this GPU). It compares SGPRs and VGPRs with the pc chain for 6 inputs each.XCL_SAMPLE_RPFand withXCL_SPLIT_WAVE64=1: 571 passed, 0 failed, 39 ignored each.XCL_RECOMP_GENERAL=1(the general form for every program with branches) the GPU suite passes. Only the three tests that look for the first form's text fail.Not tested
amdxc64.Also measured, not in this PR
v_cmpx); dropped.-opt-disable gvnis slower; licm / sink: no change.Gate A passed at 2026-11-23 17:59 UTC on main
db5dc26; Gate B passed at 18:46 UTC on main956a476. PRs read: #113, #134, #138, #139, #155, #162, #166 and the bmjask/playability branch: none structures control flow. Written with an AI assistant (Claude); measured on the owner's machine. No game material in this PR: the tests use synthetic programs.🤖 Generated with Claude Code
`structurable` works on the layout: every backward jump is a loop to it. Code the console compiler placed after the blocks it jumps back into, entered from before them, and loops with several heads or exits made 3 325 of the retail pack's 26 698 programs fall back to the `pc` dispatcher, about two thirds of their DXC time (every value of the dispatcher loop is loop-carried; jump threading and the loop passes work on it). `structure.rs` builds structured code for any reducible program from its dominator tree (N. Ramsey, "Beyond Relooper"): a loop head becomes `for (;;)`, a merge is reached by leaving a `do { } while (false)`, other blocks go inline, a loop's dominated exits go after it, and a jump out of several constructs passes through `xcl_br`. It is used only where `structurable` fails, after a dry run (a program it rejects is emitted as before), so every other program's HLSL is unchanged. Left on the pc chain: 21 irreducible programs and ES + GS pairs. Checks: every structured program can be walked against its control flow graph with the same random branch decisions (`XCL_RECOMP_CHECK=1`, the retail survey and the new tests do); GPU tests compare the general form with the pc chain; `XCL_RECOMP_GENERAL=1` forces the general form for every program (the GPU suite passes with it). Co-Authored-By: Claude Opus 5.5 <[email protected]>@TheHoracio on GitHub · 2026-11-23 19:32 UTC · original
AMD run (no retail data, so not XDefiant / the retail game): RDNA3 Radeon RX 7800 XT (16 GB, native 64-lane waves,
amdxc64), driver 32.0.32015.7029, Windows 11 Pro 10.0.26300, Rust 1.100.0x86_64-pc-windows-msvc, DXC 1.9.2602.17, debug build, PR headca66c4a.cargo test -p xcl --lib:XCL_SPLIT_WAVE64=1XCL_RECOMP_GENERAL=1(gpu::tests)gpu_general_structure_matches_the_pc_chainpasses in all three runs, natively at 64 lanes and split. No driver crash, no TDR.gpu_wave64_ps_whole_wave_reductions. It fails the same way onmainon RDNA2/RDNA3 and is fixed by #155.XCL_RECOMP_GENERAL=1the failures are that test andhlsl_is_generated_for_straight_line_and_branches, which checks the first form's text. Only one text test failed here, not the three in the PR description.@Kalmarv on GitHub · 2026-11-23 21:50 UTC · original
With default settings this PR changes no existing program's HLSL. Every program main's synthetic recompiler tests translate (160 distinct bytecode/options pairs) gave byte-identical HLSL on
mainand on the merge. Only the PR's own four programs change. Carried tomain, they show the effect:The PR's GPU differential passes for wave32 and split wave64 over six inputs per program.
A small note:
XCL_RECOMP_GENERALis checked withvar_os(..).is_some()(gpu/recomp/mod.rs:1388), so=0also forces the general form, as mostXCL_*switches onmaindo. Under the forced form, 15 of 156 pairs change HLSL, among them main's scalar-loop and EXEC-divergence programs, and both GPU tests still pass. The recompiler run was 183 / 1 / 18; the one failure is the HLSL shape assertion, which expects the default form.Tested
gpu::recomp::ca66c4amain60565c460565c4(clean, local)Not tested
🤖 GPT-6.2 Astra, Claude Opus 5.5
@mariuslozo-boop on GitHub · 2026-11-23 22:00 UTC · original
Retail NVIDIA driver numbers for this PR. Kalmarv showed that with default settings this PR leaves the HLSL of main's synthetic test programs byte-for-byte the same, and listed retail packs and driver time as not tested. On a retail compute program, the default path (
XCL_RECOMP_GENERALnot set) removes the pc dispatcher and cuts driver time 5.7×.Setup: RTX 5070 Ti (16 GB), driver 616.92, Windows 11 26300, DXC from SDK 10.0.26100. The records come from the retail
shaders.rpf(1.0.2.1), passed in throughXCL_SAMPLE_RPF. The method is the same local bench as in my #156 comment:switchform), then compiles it with DXC.CreateComputePipelineState, on one thread, with a driver that has never seen the program.prop_batch_standard_fabric_dirt:CS_RaytracingResolve_b1139868:38b05b7(same recompiler as956a476, this PR's base)selects stripped (local experiment; changes what the program computes, so for timing only)ca66c4awhile (pc …)dispatcher loops with 92pc ==cases. With this PR it has none.rtdirectionalshadows:CS_RTShadowTrace32HQ_Tiled_bfd3b062goes from 17 loops with 377 cases to none.The larger compute programs:
956a476rtdirectionalshadows:CS_RTShadowTrace32HQ_Tiledrtdirectionalshadows:CS_RTShadowTrace32TemporalHQ_OneOver8RPP_Tiledcascadeshadows_rendering:CS_ShadowRenderTiledCascadesCBPPPCped_standard_garment_2lyr:CS_RaytracingResolve_ae7b7f3cThe run with this PR was stopped after its first two programs; I will add the other two. On main, the 5.3 MB
…TemporalHQ_OneOver2RPP_Tileddid not finish in 25 minutes.Not tested: whether the retail programs' output matches on the GPU (this is compile time only), AMD, DXC 1.9. Each time is a single run.
AI-assisted: Claude Code (Claude Opus 5.5) ran the measurements and wrote this comment. No game files attached.
@PHeitor1 on GitHub · 2026-11-23 22:34 UTC · original
Tested
ca66c4amerged ontomain9ab7d76on RTX 5060 Ti 8 GB (Blackwell, 32-lane waves), NVIDIA 621.24, Ryzen 5 5600X, Windows 11 Pro 26300 (native), rustc 1.100.0 MSVC, debug,cargo test --workspace --no-fail-fast -- --test-threads=4, noXCL_SAMPLE_*. Baselinemain9ab7d76: 651 passed, 0 failed, 40 ignored.Pass: 653 passed, 0 failed, 40 ignored. GPU skips: the same 2 as on
main(no wave64).Run and written with Claude Code (Claude Opus 5.5).
@xstraok on GitHub · 2026-11-24 02:47 UTC · original
Retail run on Linux (GTA VI 1.0.2.1): the general form fixes the compute program from #611, but its sibling now stalls dxil-spirv (vkd3d-proton's DXIL → SPIR-V) in a different pass.
Setup: PR head
ca66c4aapplied (without thetests.rshunk, which conflicts) on top of a local tree:maina6f5f7a+ #257 (Linux kit) + #458 + #496 + #484 + #610 (heap-index clamp), uncommitted. Release build,x86_64-pc-windows-gnu, rustc 1.92.0. RX 9060 XT (RDNA4, RADV, Mesa 26.2.6), Ryzen 5 7600, Arch Linux 7.2.15, Proton Experimental, vkd3d-proton 3.1 (4522cc1a) + local patches, dxil-spirv8b48f0e0. One 240 s run each,XCL_COHERENT_MB=512, compared with the same tree without this PR (run f).Offline: native
dxil-spirvCLI run on the DXBC that XCL cached indxil/translated/:2e0055c25f49848a_Compute(the #611 shader): without this PR (284 048 B, 3443 blocks, 381switch) it never finished and reached 20 GB in 60 s, insideCFGStructurizer::find_selection_merges. With this PR it is 225 416 B / 3238 blocks and converts in 0.18 s.62b584e061c05fc5_Compute(214 420 B, 3030 blocks, 323switch, loaded at the same moment as 2e0055): with this PR it does not finish in 120 s. Memory stays flat at 53 MB and stderr repeatsThere is no candidate for ladder merging.Stack under gdb:CFGStructurizer::split_merge_blocks_and_visit_orphan_preds → split_merge_blocks → build_ladder_block_for_escaping_edge_handling → CFGNode::recompute_immediate_post_dominator → find_common_post_dominator. Its translation without this PR was probably the second slow one in #611 (same block / switch / phi counts as the old 2e0055).In the title:
+0x23cf683, #505 / #534)find_selection_merges(RAM +500 MB/s)build_ladder_block_for_escaping_edge_handling(100 % CPU from ~178 s, no RAM growth)With #172 the loading screen rendered correctly. Part of the 24 s gain may only be retranslation, because this was the PR exe's first run: DXC threads were busy from 168 s.
So the PR helps here, but one program's structured output still sends dxil-spirv into a loop. Both stalls are inside dxil-spirv (#611).
Not tested: Windows / native D3D12 (dxil-spirv is not on that path),
cargo test(the PR's tests were not applied),smoke.ps1, other titles.Tested and written with Claude Code (Claude Opus 5.5); the run and the measurements are from this machine.
@QemmHD on GitHub · 2026-11-24 03:48 UTC · original
Thanks for this. I read
structure.rsand hunted for counter-examples atca66c4a(also merged ontomaindd2ae9a: clean merge, same results). I found no miscompile in the new form. The tests are in a test-only commit you can take:6e9c949on QemmHD/xclreview/172-structure(recomp/tests/structure_fuzz.rs).What held
pcchain, and none go the other way. The HLSL text, walked with 24 branch-decision sequences per program, runs the program's instructions in the program's order.s_and_saveexec,v_readfirstlane/v_readlane, DPP16,s_barrierand stores inside the loops. The general form matches a CPU reference run in every register and in memory.s_endpgminside loops, unreachable blocks (also an irreducible unreachable loop), loop heads with several latches, an untranslated branch, an indirects_setpc, a far jump as a latch, and 150 nested blocks (DXC compiles them; 200 fall back).1. A
LOOP_GUARDtrip can put the split-wave64 halves out of step (structure.rs:610,x64_masks.rs:160-181)x64_masksassumes a guard exit goes to the code after the loop in memory, or to the end of the program (as on thepcchain). Here thebreaklands on the block placed after thefor, which can be anywhere:This only happens after a trip, and I deliberately didn't run it on the GPU. Test:
split_wave64_halves_stay_in_step_after_a_loop_guard_trip(should_panicuntil fixed). One fix that keeps the analysis: make a trip a jump toLabel::Exit, which is what these programs did on thepcchain. Measured with a 100 000-iteration loop:pcchains0 = 65536, s3 = 0; this forms0 = 65536, s3 = 1. Otherwisedocs/wave64-on-wave32.md("to the code after it or … the end of the program") needs the new case.2. The GPU test's reference isn't the
pcchain alone (tests.rs:6859,mod.rs:1053)Options { structured: false }still emits the first structured form for single-entry stretches, and that form is wrong for two shapes. Both are onmain, not from this PR, and are now reported as #701. The general form gets both right (gpu_first_form_counter_examples_are_right_in_the_general_form). In the random run thepcchain and the default path differed from the reference in 13 of 1 200 programs, the general form in none. The expected values (the CPU run in the commit) would be a safer reference.3.
checkwalks the tree, not the text (structure.rs:678)refs, the elided tail jumps,falls_offandpass_on(497-659) are outside it: changingcontinuetobreakinpass_onstill passescheck. The text walk in the commit catches it.4. A failed check is silent (
structure.rs:466-471)It runs after the emitting build, so the fallback emits into the same
Emagain, andgpu_general_structure_matches_the_pc_chainthen compares thepcchain with itself.checkonly needs the dry run's tree; a failure could panic undercfg(test).5. Not covered here
A wave32 program in 64-lane hardware waves (VS / PS on AMD, where the halves branch differently) in this form. A forced-general variant of
gpu_wave32_program_in_wave64_hardware, with a loop the halves leave at different iterations, would cover it.6. Small
size()recounts aVec<bool>per comparison (structure.rs:191,207).MAX_DEPTH160 needs between 256 and 512 KB of stack in a debug build, which is fine on the 64 MB workers. Istranslateever called on a title thread?Options::structuredsays "always the guarded block chain" (mod.rs:491).7. CONTRIBUTING
structure.rsand its tests behindXCL_RECOMP_GENERAL, then turning it on, thenXCL_RECOMP_CHECK).smoke.ps1,mainagainst the head) yet.Reviewed and run on an RTX 4070 SUPER (NVIDIA 621.24, wave32); the commit's 14 tests were re-run before posting (14 passed, including the GPU ones).
AI-assisted review (Claude Code; Claude Opus 5.5 and Claude Fable 5.2).
Discord: bigpeppa.
mainreaches on Windows; the obstacle is replaced vtables — proposal: proxies #175@t4l03 on GitHub · 2026-11-24 15:29 UTC · original
ActivateRays coverage on the exact draft head
Tested clean
ca66c4aeb0def58bddf299c43557e3c5cb79c0fb, Windows 11 build 26300, RTX 4070 Ti driver 617.14, Ryzen 7 7800X3D and DXC 1.9.2609.5.On the 76,699-instruction
ActivateRayscompute program discussed in #1269, the general structurer declines withnesting too deep(reported withXCL_RECOMP_GENERAL=1 XCL_RECOMP_WHY=1). Four-window output from the default and PC control was byte-identical: 14,297,985 bytes of HLSL, 15,795pcguards. I timed the identical output once. DXC-O0finished in 58.09 s, yielding 13,015,412 bytes of DXIL. Pipeline creation reached a 75-second time cap with a fresh XCL cache. This documents the fallback on one large program; a smaller 15,577-instruction retail compute control produced HLSL without PC guards and built its pipeline in 26.47 s.Tested:
cargo build --locked --workspace -j 4followed bycargo test --locked --workspace -j 4 --no-fail-fast -- --test-threads=4 --show-output: 571 reported passed, 0 failed, 39 ignored. Two GPU tests were counted as passes but skipped for lack of native wave64:gpu_geometry_wave32_prefix_count_over_a_maskandgpu_wave32_program_in_wave64_hardware.Not tested: retail shader output, a new structuring form for this program, or native wave64.
AI use: Codex (
gpt-6.2-sol) ran the tests and wrote this report.@jessenic on GitHub · 2026-11-24 17:41 UTC · original
Driver compile time of
ca66c4aon today's tree: on the retail CS_RaytracingResolve programs it still moves off thepcdispatcher, NVIDIA's compile is the same or slower than without it. This is the driver-time question the description leaves open. It follows @mariuslozo-boop's 5.7× on956a476(comment); the base has changed since.Tested
mainb7aa9f3, both with #1288, #751, #684, #680, #1315/#1316 and #1321 (the stack that gets the retail title furthest here), one of them with this PR merged in:mod.rs: the general form is kept as the branch aftermain'sstructurable(&sctx…)path and #1321's size fallback.tests.rs: our side kept, so this PR's tests were not built.XCL_HEAP_WINDOWS=1, split wave64 (32-lane GPU), 4 windows, as the runtime translates.xcl shaders(not for a PR):console_translationand builds its DXIL withconsole_to_dxil_in.CreateComputePipelineState, one at a time, with no cached blob.Which programs change. Compute programs with 1 MB or more of HLSL in
shaders.rpf(1.0.2.1):pcform without this PR, 1 with it.CS_RaytracingResolve, the family whose ~1 MB DXIL compiles hold the world load up here.Driver time: four of them, picked across the size range; passes alternated (stack, PR, stack, PR).
emissivenight:CS_RaytracingResolve_b1139868ped_standard_muv_secmo:CS_RaytracingResolve_b1139868standard_2lyr_doublesided_secmo:CS_RaytracingResolve_18a17e12standard_2lyr_cutout_hbb_ground:CS_RaytracingResolve_c5cb017e956a476and 31 s with this PR. On today's base thepcform of these programs already builds in 8–20 s. So most of that gain seems to have reachedmainby other routes (b8b1f49, and #680's heap windows here), and on these four programs this PR adds nothing measurable to driver time.Not tested
mainwithout the rest of the stack, and withoutXCL_HEAP_WINDOWS.RTShadowTraceand cascade-shadow programs from the earlier comment (they are not on thepcform in our stack, so this PR does not change them there).AI use: Claude Code (Claude Opus 5.5) built the trees, wrote the local timing mode, ran the measurements and wrote this report. No game data is attached; program names are the pack's record names.
@DavidM1911 on GitHub · 2026-11-25 15:19 UTC · original
Verification on RTX 3060 Ti (Windows 11): merge conflict with current
main— needs a rebase before it can be tested.View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.