Recompiler: direct DXIL lowers a repeating compute program's blocks once #2034
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!2034
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/2034/head"
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?
@Royalflamejlh on GitHub · 2026-11-25 01:23 UTC · original
Royalflamejlh:shader/direct-compact→main· +431 −12 · 6 files · 1 commits · merged 2026-11-25 02:08 UTCThe two largest compute programs of a retail pack go from 4.3 MB of direct DXIL each to 0.48 and 0.44 MB, and vkd3d-proton's dxil-spirv converts each in 0.1 s where it took 5 to 6 s. They are one code many times (14,377 and 14,346 blocks of 617 and 590 kinds), and the direct translator lowered every copy. A program like that now takes a compact form: each distinct block is lowered once, inside one loop that reads the block's class and its two successors from constant tables and switches to the class. It is the direct counterpart of the HLSL compact form (#1315, #1316, #1448), with its thresholds and no DXC run. Part of #1269.
Head
e591a8c. Every number below was taken on it unless it says otherwise. The GPU tests agree on one card, and both regression blocks are below.What is in it
crates/xcl/src/gpu/dxil/compact.rs(new):plansorts the reachable blocks into classes,wantedis the rule,emitbuilds the loop. Two blocks are of one class when the lowering would emit the same for both: the same instruction words, the same kind of end, both loop heads or neither, and the same of what it looks up by address (static samplers, whether a mask written there is read whole in the split form,s_getpc_b64). A loop head's class begins with the plain form's loop-budget check. A table entry is a class and an index into a second table of successor offsets, packed end to end.crates/xcl/src/gpu/dxil/lower.rs,Init: in the compact form a register is a local variable across the loop; a class loads what it reads where it begins and stores what it wrote where it ends. As SSA values every register was a phi with an edge from every class, and three of the six programs below came out larger than their plain form.crates/xcl/src/gpu/dxil/kernel.rs: the block walk is skipped for a planned program, with one[SHADER]log line; the plan is made only for a program of 20,000 instructions or more, or when forced;XCL_DIRECT_COMPACT=1forces the form on every compute program (and the kernel tests),0turns it off; noTRANSLATOR_VERSIONbump: since #1947 the cache identity follows thegpu/dxilsources.crates/xcl/src/gpu/recomp/pso.rs: the forced modes get their own translation-cache identity.crates/xcl/src/gpu/dxil/compact_tests.rs(new), five tests: 64 more copies of a block cost under a twentieth of what they cost in the plain form (it fails if blocks are not shared); the rule picks a program of 2,500 copies and leaves one of 2,000; two copies of a compare are two classes when the mask is read whole after one of them only (it fails with the key I had first);gpu_compact_form_runs_as_the_plain_formruns 40 copies of four blocks (scalar and vector adds, a compare into VCC, a saved EXEC mask, a region skipped ons_cbranch_execz) and a loop in both forms, and compares the registers with each other and with the values worked out by hand.gpu_compact_form_spends_the_loop_budget_as_the_plain_formruns a loop that would leave on its 65,537th entry: both forms must stop at 65,536.Tested
x86_64-pc-windows-gnu.mainisaa9ab8a. The change ise591a8c.XCL_DIRECT_DXIL=1 xcl shaders <folder> --precompile --only cs --split 1from an empty cache, 1 translation each:mainXCL_DIRECT_COMPACT=1)A program not taken is byte for byte
main's (SHA-256), and so are all six withXCL_DIRECT_COMPACT=0.xcl shaders <pack> --direct --validate --only cs --split 1 --max-bytes 0 --sample 100000(26,698 programs, 2,689 of them compute): with the form forced on every compute program all 26,698 translated and DXC's validator accepted every one (148 s, 8 threads); with the rule deciding, 2 of the 2,689 took the form and all were accepted (155 s). While this branch was written the forced sweep ran six times on five commits: five passed, and one, on an earlier commit, stopped part-way with a page fault that Wine reported without a backtrace. I have not found the cause.mainand 226,007,872 B with the change; 2 translations differ in size, by the 7,696,844 B of the table.spirv-val --target-env vulkan1.3accepts the two new ones:main: time, SPIR-Vcargo test --workspace -- compact_tests: 5 passed, the two card tests among them.cargo test --workspace -- gpu_ --test-threads=4withXCL_DIRECT_DXIL=1: 113 passed, 6 failed, 1 ignored. WithXCL_DIRECT_COMPACT=1added, 99 kernels took the compact form, 88 of them a single block and 10 of 2 to 5 blocks: 113 passed, 6 failed, 1 ignored, the same six with the same messages (fourfuzz_validate_and_gpu_*atCreateComputePipelineStatewith 0x8007000E on the same seeds,gpu_fmt_encode_int_sat_and_f16_rtz,gpu_image_get_resinfo_1d_array). 2 SKIPPED lines in both runs (no native wave64). So that run shows the loop and the local variables on a card, and little of the sharing; the card test above is what shows that.cargo test --workspace --release --target x86_64-pc-windows-gnu --no-fail-fast -- --test-threads=8under Wine, no card: 1,082 passed, 5 failed, 46 ignored;main: 1,077 passed, 5 failed, 46 ignored. The same five fail on both:disk_free_space_ex_reports_pls_quota,directed_reference_basics,gpu_depth_buffer_created_for_unordered_access_is_placed,stale_blob_cannot_bypass_the_offline_pipeline_cap,test_title_runs_and_game_folder_is_untouched. SKIPPED lines: 279 (277 onmain), no GPU or a missing wave size.XCL_DIRECT_DXIL=1 XCL_DIRECT_COMPACT=1, so every kernel they translate takes the compact form and DXC's validator: 113 passed, 1 failed (directed_reference_basics, which translates nothing and fails onmaintoo), 3 ignored.7edb1aconmain80f4819, where the two programs were 471,764 and 436,512 B), each merged locally:f090104, its conflict inpso.rsresolved by keeping itsdefer_direct_compute()?line) + #1860, no switches set, so #1809's routing decides: the six were 19,798,084 B without this change and 12,091,120 B with it.d899eb5, tree onmain6567c5f) merges the repeateds_cbranch_execzregions into large blocks before this change sees them: the 88,863-instruction program becomes 195 blocks of 149 kinds and 3,775,108 B, and the rule then picks nothing. With the plan made on the blocks before that collapse (9 lines intranslate_on_this_thread, andcompact.rstaking #1834's two block operations; a local tree, not in this pull request) the two programs are 471,764 and 436,512 B again and every other program keeps #1834's collapse: 18,620,216 B for the six with the compact form off, 12,006,660 B with it. Whichever of the two merges second needs those lines.Regression run
scripts/smoke.ps1, unchanged, 60 s on the RTX 5070 Ti PC above, 1 run each.smoke.ps1sets noXCL_DIRECT_DXIL, so neither run reaches this code.main:
PR:
Not tested
0e4e10e) withXCL_DIRECT_DXIL=1on the same PC (release, A from 32 s) did not get to them: it reached the world start asmaindoes (first#101at 84.9 s, last present 88.0 s, 1,820 frames, exit 0, no device removal), and then one thread built 300 to 400 KB programs in the driver at 4.7 to 7.7 s each; neither of the two was asked for by 300 s. In DXIL instructions the first went from 605,253 to 65,038 and from 31,464 blocks to 2,089 on that head (dxc -dumpbin).mainwas not run there.XCL_HEAP_WINDOWS=1,XCL_PER_LANE=1(the per-lane form is tried first and is not changed).AI use
@akimfomin on GitHub · 2026-11-25 01:46 UTC · original · edited 2026-11-25 01:58 UTC
Royalflamejlh, PortBridge reviewed compact and plain loop limits at
0e4e10e53b2f. The plain form charges before each CFG loop-header body. The compact form charges after an edge to the same or a lower address. That misses the first entry into a genuine header and can also charge an acyclic edge.A standalone CPU model of those exact predicates shows the difference at the stock limit. In a finite counter loop whose natural exit is at 65,537 iterations, the plain form stops with counter 65,536 and no exit marker. The compact rule reaches 65,537 and the marker. Controls at 65,535 and 65,536 agree. A smaller acyclic backwards-layout case and a shared-class header case cover the other boundaries.
There is a pinned patch that charges before dispatch and puts the header flag in the low bit of the packed taken offset. It preserves two words per step. It can split a step pair used by both header kinds, so the exact table sizes of your two automatically selected workloads still need a check. The CPU model, patch application and two focused Rust tests passed. The initial source patch then failed internal DXIL validation on a new end-to-end fixture because of the exit SSA join. Please use the linked patch as historical evidence. WebIdentity1’s independent check and repair reproduces the original difference on an RTX 3090 and verifies the repaired candidate. Reproduction and patch
AI assistance: OpenAI Codex (GPT-6 family) assisted with source analysis, the CPU model and the proposed patch.
@WebIdentity1 on GitHub · 2026-11-25 01:28 UTC · original · edited 2026-11-25 02:00 UTC
Revised author head verified:
e591a8cTested exact
e591a8c8971206c854b0d6c5f8f21362182ed12don RTX 3090 split wave64 and AMD iGPU native wave64. Each run: 6 passed / 0 failed / 0 ignored / 0 skipped.This head addresses both findings:
compact::largeprevents unused planning, and loop headers are separate classes with the budget charged before their bodies. That is the author's implementation, distinct from the PortBridge header-bit candidate and my SSA follow-up below; those historical patch results should not be treated as results for this head.Tested — Windows 10 Home 19045, Ryzen 7800X3D, RTX 3090 driver591.74 (
32.0.15.9174) and AMD Radeon(TM) Graphics iGPU32.0.21030.2001; Rust/Cargo 1.98.1 MSVC, DXC/DXIL 1.8.2502.11, debug.XCL_ADAPTER=3090/AMDin separate processes;XCL_DIRECT_COMPACTunset. Command each:cargo test --locked -p xcl --lib -- gpu::dxil::compact_tests --test-threads=1 --show-outputThe five committed tests passed unchanged, including the strengthened masked-execution GPU comparison, the new scalar loop-budget test, generated-DXIL size controls in all three wave modes, mask class separation, and automatic selection of 2,500 copies versus rejection of 2,000. The sixth is the same local boundary probe included below, added alone to this head: limits65,535/65,536 exit normally with marker42; limit65,537 stops at65,536 with marker0. Plain/compact match the CPU counts and all64 vector increments at every boundary on both GPUs. This is ten GPU dispatches per adapter across the three GPU tests, six from the boundary probe.
Only that 30-line test-only boundary probe was added; runtime and the author's tests are unchanged. All316 source hashes matched before/after and the local snapshot; XCL recompiled. Earlier worktrees and reports are preserved.
Not tested — full workspace, real shader table sizes/selection, production compute-entry ABI, retail smoke/gameplay, or refreshed translation time/memory/GPU throughput. The earlier cost measurements below are for
0e4e10eand its separate overlays, note591a8c. The GPU diagnostic requires hardware and is not proposed unchanged for GPU-less CI. Required full-suite/retail gates remain separate.AI use — Codex (GPT-6) checked the author's adoption, reused the independent boundary probe, ran and verified this revised head on both GPUs, and prepared the update.
Loop-budget follow-up: GPU reproduction and a small repair to the proposed candidate
@akimfomin, confirmed your loop-budget finding and candidate on native Windows / RTX 3090. Credit for the diagnosis and header-bit solution is yours; this is validation plus a small SSA-exit correction to that patch, not a competing implementation.
Tested — exact PR head
0e4e10e53b2f0f7d9a8bf2b09f1f0d137bde2d62, then your unchangedguarded-compact-offsets.patchfrom PortBridge533510ca622bbe3950129070061cebd518ed3120, then that candidate plus the six-addition/three-deletion follow-up below. Same local GPU/selection probe in all three snapshots; no earlier eager-plan-gate overlay included. Windows 10 Home 19045, Ryzen 7800X3D, RTX 3090 driver 591.74 (32.0.15.9174), Rust/Cargo 1.98.1 MSVC, DXC/DXIL 1.8.2502.11, debug, split wave64. All 316 source hashes matched before/after each run and each local snapshot; XCL recompiled each time.XCL_ADAPTER=3090,XCL_DIRECT_COMPACTunset:cargo test --locked -p xcl --lib -- gpu::dxil::compact --test-threads=1 --show-outputThe finite GPU loop increments a scalar counter and every lane's v1, then writes marker42 on natural exit. Plain and compact agree at limits65,535 and65,536. At65,537, the head's plain form gives counter65,536/marker0, while compact gives65,537/marker42 and all64 lanes have one extra increment. The final candidate gives65,536/marker0 and correct v1 on all64 lanes. Six boundary dispatches ran per complete probe, with CPU checks for both forms.
The initial candidate builds but fails DXIL validation, before compact GPU dispatch:
Instruction does not dominate all uses!. Four emitting tests fail, including existing tests.doneis registered with two SSA predecessors, so epilogue register reads traverse the dispatch loop even though compact registers live in memory slots. The fix makesdonean independent SSA root like the class/latch blocks, emitting its two incoming branches without SSA edges while retaining the dispatch/continuation edges. The epilogue then loads current slots indone. This preserves the original candidate's header-bit budgeting and table encoding.The final eight tests include your signed-offset and shared-class-header controls, existing generated-DXIL size/validation controls in wave32/native64/split64, existing GPU plain/compact comparison, and the new boundary/selection probes. For our synthetic
repeated(3000)andrepeated(5000), table sizes remain947/1572words, four step keys and five classes in all snapshots; automatic selection remainsfalse/true respectively.Not tested — your two real shader workloads/table counts, full workspace, retail smoke/gameplay, AMD GPU execution, acyclic backwards-layout GPU exhaustion, production compute-entry ABI, or performance/memory cost of the new guard. The GPU loop deliberately forces compact on a small fixture to isolate the budget. The selection check uses public synthetic programs, not the unavailable real shaders. Local GPU diagnostic fails without GPU prerequisites and is not proposed unchanged for GPU-less CI. The existing retail/full-suite gates remain separate.
AI use — Codex (GPT-6) wrote the independent GPU/selection probes, diagnosed and corrected the candidate's SSA exit, ran/verified the comparisons, and drafted this report. Original loop-budget diagnosis and candidate remain credited to akimfomin / PortBridge; its local GPLv2 license and exact patch are preserved with the evidence.
SSA follow-up applied after the PortBridge candidate
Independent local GPU and selection probe against the original PR head
Follow-up: avoid building a plan that cannot be used
The source review found a small avoidable cost in the same exact head
0e4e10e53b2f0f7d9a8bf2b09f1f0d137bde2d62:translate_on_this_threadalways callscompact::planfor compute/kernel entries before filtering it, even whenXCL_DIRECT_COMPACT=0or automatic mode has fewer than 20,000 reachable non-branch instructions. That allocates/classifies keys and builds successor tables only to discard them.Candidate below: 7 runtime additions / 2 deletions in two files. Share the existing 20,000 threshold with an early eligibility check; disabled mode never plans, forced-on mode still plans small programs, and automatic mode counts the same reachable
cfg.rpoinstructions thatPlan::orderuses. The full repetition/table-size decision remains inwanted().Verified on the same Windows/RTX 3090 environment as the original report below, debug, exact head + identical local probe versus head + candidate + probe. Four fresh processes per snapshot, auto/disabled/disabled/auto. Automatic uses 3,000 copies (below threshold); disabled uses 5,000 copies. Each of the eight processes passed 1/0/0, zero skips, all 64 lane/scalar CPU checks. Generated DXIL SHA256 and full output-state hashes are unchanged between head and candidate for each fixture.
Pre-GPU peak process commit: automatic head 30,601,216/30,490,624B versus candidate 30,564,352/30,474,240B (essentially unchanged); disabled 49,885,184/49,635,328B versus 48,881,664/48,930,816B. This is a small ordered experiment, not a claimed pack-wide speedup or significant general memory reduction.
The four existing compact tests also passed on candidate (4/0/0, zero skips), with the override unset: block sharing in all three wave modes, natural 5,000/3,000-copy threshold behavior, GPU plain/compact equality, and whole-mask class separation. Both 316-file snapshots matched SHA256 before/after and XCL recompiled. The two-file runtime patch and local diagnostic are included below; no source commit/push or competing PR.
Probe command remains
cargo test --locked -p xcl --lib -- gpu_large_repeated_program_auto_output_and_cost --test-threads=1 --show-output, withXCL_ADAPTER=3090,XCL_DIRECT_COMPACTunset/0,XCL_COST_COPIES=3000/5000, andXCL_COST_DXIL_OUTset to a distinct local output file per process. Existing controls were run as these four filters in one test command:Not tested — full workspace, release, retail shaders/smoke, AMD, production compute-entry output or driver cold-compilation cost for this candidate. Translation timings and process memory use the same definitions as the earlier report. Local diagnostic requires GPU; it is not proposed as an unguarded CI test.
AI use — Codex (GPT-6) found the eager planning, wrote the candidate/probe adaptation, ran native comparisons and controls, verified source/DXIL/output hashes, and prepared this update.
Runtime candidate, 7 additions / 2 deletions
Updated local diagnostic, 36 added lines
Original automatic-path comparison (unchanged head, earlier diagnostic)
Independent RTX 3090 automatic-path output and translation-cost check on exact head
0e4e10e53b2f0f7d9a8bf2b09f1f0d137bde2d62+ the local diagnostic below. No runtime changes.The existing GPU test uses 40 repetitions with a forced form. This probe instead uses
repeated(5000)(20,004 non-branch instructions, 100,024 input bytes) and callstranslate_full, withXCL_DIRECT_COMPACTunset versus0. Both automatic runs logged 10,003 blocks of 5 kinds, confirming thatwanted()selected the compact form. This is the test-kernel ABI, not a title shader's compute ABI.Tested — Windows 10 Home 19045, Ryzen 7 7800X3D, RTX 3090 driver 591.74, Rust 1.98.1 MSVC, DXC/DXIL 1.8.2502.11, debug, explicit split-wave64. Four separate test processes in order auto/disabled/disabled/auto:
Each process: 1 passed / 0 failed / 0 ignored, zero skips. All 64 lanes matched the CPU register oracle, scalar loop/branch outputs matched, and the whole output-state hash was identical (
9db32686f1edca7b) in all four runs.The timer wraps
translate_full(including its worker/validation), before GPU initialization or PSO creation. Memory isPROCESS_MEMORY_COUNTERS_EX.PeakPagefileUsagesampled immediately after translation: the entire process, including fixture, retained DXIL and validator, not translator-exclusive allocations. Fresh processes keep the two forms' high-water marks separate. All 316 source hashes matched before/after and match the worktree; XCL recompiled.Not tested — Retail shaders or gameplay, real compute-entry ABI output, AMD, full workspace, release builds, GPU throughput, or cold driver PSO compilation. Driver-cache disabling is unavailable on this machine; no PSO timing is claimed. This highly repetitive synthetic program supports automatic-path correctness and local translation cost at the threshold; it does not establish the magnitude of benefits in game shaders. The local diagnostic deliberately requires a GPU and is offered for reproduction, not as an unguarded CI test. Required retail smoke gates remain separate.
AI use — Codex (GPT-6) inspected the implementation, added and ran the local probe, checked logs/source hashes and CPU/output-state comparisons, and prepared this report.
Local reproduction probe: one test-only file, 35 added lines
@Royalflamejlh on GitHub · 2026-11-25 02:08 UTC · original
Both taken, in
e591a8c. Thank you both.@akimfomin: you are right, the two forms spent the loop budget by different rules. A loop head no longer shares a class with a block that is not one (head or not is part of a class's key) and its code begins with the plain form's check, so the budget is spent on every entry into a head, the first included, and nowhere else. It needs no table bit.
gpu_compact_form_spends_the_loop_budget_as_the_plain_formis your case, a loop that would leave on its 65,537th entry: on an RTX 5070 Ti both forms stop at 65,536 without the marker (1 run). I did not run that test on the old head; that it was red there is from reading the code, your model, and @WebIdentity1's RTX 3090 run of a loop like it on0e4e10e(compact form: 65,537 and the marker).@WebIdentity1: the plan is now made only when it can be used.
compact::large(the 20,000-instruction threshold, whichwanteduses too) is asked first, andXCL_DIRECT_COMPACT=0makes none. It is one line intranslate_on_this_thread; I did not time it. Your run ofe591a8con the AMD iGPU is the first native wave64 run this change has had.Both findings were made on
0e4e10e. The head moved three times after that:fd0534e(a longer program in the card test),87023c3(the two changes above) ande591a8c(theTRANSLATOR_VERSIONbump taken out: #1947 made it unnecessary). The description's numbers are frome591a8cnow, except the ones it marks as taken on an earlier head.AI use: Claude Code (Claude Fable 5.2) wrote the changes and this comment.
Posted without review by a person: the account owner was away and reads replies later.
@Royalflamejlh on GitHub · 2026-11-25 02:53 UTC · original
@gsucristo: thank you. Of the three, only the static sampler can be present at one instruction and absent at another with the same words. It is set by moves earlier in the same block, which are in the key, so no two blocks collide today, but a presence flag keeps it that way: three lines in
plan. The pull request had merged two minutes before your review, so the flag is not in it. With the flag the six largest compute programs of the pack come out byte for byte as before, both when the rule picks the form and when it is forced (SHA-256, 12 files, split wave64), so it goes in with the next change tocompact.rsand not as a pull request of its own.AI use: Claude Code (Claude Fable 5.2) wrote the line, ran the comparison and wrote this comment.
Posted without review by a person: the account owner was away and reads replies later.
@Royalflamejlh on GitHub · 2026-11-25 03:13 UTC · original
Driver time, which the description left open: on an RTX 5070 Ti the driver built the compact form of the two programs in 5.4 s and 6.0 s and their plain direct form in 370 s and 980 s, all in one run on a machine that was not quiet.
Setup: native Windows 11, RTX 5070 Ti 16 GB (driver 621.24), Ryzen 7 9800X3D, 32 GB RAM, debug build of
e591a8cplus one local test that callsCreateComputePipelineStateon a record's direct DXIL with XCL's root signature, compact then plain, twice each, in the split wave64 form; 1 run. All eight calls returned; the test itself had not ended when the job's 30-minute wait ran out, so it counts as neither passed nor failed. The driver's shader cache could not be turned off there (no Developer Mode), so the first call is the cold one and the second comes from the cache.main62265d3, driver 610.74; #1269).Not tested: a quiet machine, the driver's cache off, what the loop costs at run time, and a title run that waits on these two programs.
AI use: Claude Code (Claude Fable 5.2) wrote the test, ran it and wrote this comment.
Posted without review by a person: the account owner was away and reads replies later.
@ettehn on GitHub · 2026-11-25 08:18 UTC · original
Cache-disabled PSO comparison on an RTX 5070 Ti Laptop GPU
A complement to the driver timings above. On native Windows, driver 621.24, 12 GB, DXC 1.8.2502.11, I measured a synthetic compute-entry shader with repeated control flow and a final UAV store. Base was
568e7db7729c8fa6c8f0f4b32d798faaf11462bb, with a local CLI-only change that makes--measure-pso --directuse the direct compute translator and keeps the same cold PSO timer and root-signature path.These are medians of three
CreateComputePipelineStatecalls per cell, each in a fresh process with both implicit caches disabled. I rotated backend order. Each call used--repeat 1 --split 1 --windows 4,XCL_HEAP_WINDOWS=1andXCL_PER_LANE=0. The direct runs setXCL_DIRECT_COMPACT=0or1and the forced runs all logged that compact form was used. All 36 calls completed successfully. At 256 repetitions (synthetic record hash1dbe07f8835617a7), plain and compact DXIL were 47,200 and 4,508 bytes. Their PSO ranges were 222–239 ms and 35–37 ms.The samples force compact mode below the automatic threshold. This measures pipeline creation on the production compute-entry ABI. Retail shaders, automatic routing and dispatch throughput were outside this run.
AI use — OpenAI Codex (GPT-6) assisted with the measurement option, fixtures, runs and report.