Skip to content

Recompiler: direct compact form stores a branch's target in the entry - #2076

Draft
Royalflamejlh wants to merge 2 commits into
xcl-dev:mainfrom
Royalflamejlh:shader/compact-third
Draft

Royalflamejlh wants to merge 2 commits into
xcl-dev:mainfrom
Royalflamejlh:shader/compact-third

Conversation

@Royalflamejlh

@Royalflamejlh Royalflamejlh commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

The third-largest compute program of a retail pack now takes the direct compact form of #2034: 3,916,120 B of direct DXIL become 1,249,504 B, and vkd3d-proton's dxil-spirv converts it in 0.6 s where its plain form took 496 s. The rule left this program out for the size of its tables. Part of #1269.

Draft: on an RTX 5070 Ti (native Windows, debug) the 7 compact_tests pass at f1b313f, the three card tests among them. Both regression blocks are below, and the driver took this program's table: 33 s for its compact form.

What is in it (two commits)

  • compact.rs, the tables: the program's branches go to 6,530 different pairs of offsets, so as an index into a table of pairs its tables were 23,913 words. In it, as in the other five of the six largest programs, a block's second successor is the next block or the same as its first. For such a program an entry now holds the taken successor itself when that makes the tables smaller: 11,287 words here, in one table. The limit for taking the form goes from 8,192 to 12,288 words.
  • compact.rs, the key (its own commit, from the review of Recompiler: direct DXIL lowers a repeating compute program's blocks once #2034): a flag for whether an instruction has a static sampler. Hardening only: the sampler follows from the moves before it in the block, which are in the key.
  • compact_tests.rs, two tests: a program of 1,000 early exits to one place needs under 500 words of tables (2,381 on main, where the test fails); gpu_compact_form_with_targets_in_the_entry_runs_as_the_plain_form runs 40 such exits in both forms and compares every register.

Tested

  • Linux through Wine, CPU only: Ryzen 9 9950X3D, 62 GB RAM, Fedora 44, Wine 11.21 Staging, DXC 1.9.2609.5 (its validator only), rustc 1.98.0, release, x86_64-pc-windows-gnu. main is cbc296a. The numbers were taken on a429968; the head, f1b313f, tightens one condition (a conditional branch's second successor must be the next block for the one-table form) and gives the six programs the same bytes (SHA-256).
  • The six largest compute programs of the pack, XCL_DIRECT_DXIL=1 xcl shaders <folder> --precompile --only cs --split 1 from an empty cache, 1 translation each:
console instructions DXIL on main with the change
76,699 3,916,120 B (plain) 1,249,504 B (−68.1 %)
88,863 484,508 B (compact) the same bytes
88,445 442,740 B (compact) the same bytes
46,741, 45,398, 44,430 2,514,272, 2,439,268 and 2,379,964 B (plain) the same bytes
sum 12,176,872 B 9,510,256 B (−21.9 %)

"The same bytes" is by SHA-256.

  • dxil-spirv as vkd3d-proton ships it (command-line tool, 8 GB limit, 1 conversion): the 76,699-instruction program in 0.6 s, 4,403,404 B of SPIR-V, which spirv-val --target-env vulkan1.3 accepts. Its plain form took 496.3 s and gave 20,705,832 B on main aa9ab8a (Recompiler: direct DXIL lowers a repeating compute program's blocks once #2034's description).

  • The whole pack, xcl shaders <pack> --direct --validate --only cs --split 1 --max-bytes 0 --sample 100000 (26,698 programs, 2,689 of them compute): with the rule deciding, 3 take the form (2 on main, by the six-program run) and DXC's validator accepts every program; with the form forced on every compute program it accepts every one too.

  • A 23,000-record slice of the pack (836 cached translations): 231,800,172 B on main, 229,133,556 B with the change, the difference being this one program.

  • cargo test --workspace --release --target x86_64-pc-windows-gnu --no-fail-fast -- --test-threads=8 under Wine, no card: 1,150 passed, 6 failed, 46 ignored; main: 1,148 passed, 6 failed, 46 ignored. The same six fail on both: disk_free_space_ex_reports_pls_quota, fence_and_command_queue_sync_timing_and_allocator_reset_match_host_and_console, 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: 296 (295 on main), no GPU or a missing wave size; the new card test is one of them.

  • The direct translator's own tests under Wine with XCL_DIRECT_DXIL=1 XCL_DIRECT_COMPACT=1: 123 passed, 1 failed (directed_reference_basics, which translates nothing and fails on main too), 3 ignored.

  • On the same RTX 5070 Ti (driver 621.24), alone on the machine, debug build of the head plus one local test that calls CreateComputePipelineState on a program's direct DXIL with XCL's root signature, split wave64 form, the driver's cache on, 1 run: the 76,699-instruction program in the compact form (1,249,504 B, one table of 11,287 words) took 33.16 s on the first call and 0.009 s on the second. The two programs main already compacts took 6.44 s and 5.22 s (484,508 and 442,740 B).

Regression run

Native Windows 11, RTX 5070 Ti 16 GB (driver 621.24), the retail title, 60 s, 1 run each. smoke.ps1 sets no XCL_DIRECT_DXIL, so neither run reaches this code.

main:

xcl-smoke v1
commit: cbc296ab65a2661a61e3e2da109134bcd5319f60
gpu: NVIDIA GeForce RTX 5070 Ti
title: 5330474d
seconds: 60
exit: 0x0
frames shown: 1632 (PresentX 1632)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15638 MB

PR:

xcl-smoke v1
commit: f1b313fb500f65645f50e653a8bf7abc497802b2
gpu: NVIDIA GeForce RTX 5070 Ti
title: 5330474d
seconds: 60
exit: 0x0
frames shown: 1637 (PresentX 1637)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 17163 MB

Not tested

  • The driver's time on this program's plain form on a quiet machine (in a 300 s title run on main it was at the driver for 209 s without finishing: [OFFICIAL] Looking for PRs with shaders optimization #1269), and any card but this one.
  • The suite, the two pack sweeps and the slice on the head f1b313f: they ran on a429968. On the head the six programs are the same bytes and the 7 compact tests pass.
  • What happens if a driver refuses the table: nothing falls back to the plain form then.
  • What the loop costs at run time, AMD, Intel, a native wave64 run, XCL_HEAP_WINDOWS=1.
  • With dxil: collapse forward s_cbranch_execz regions and make read-only loads branchless #1834: its collapse runs before the compact form's plan and would take the form away from these three programs unless the plan is made first (my comment there has the lines).

AI use

  • Claude Code (Claude Fable 5.2) wrote the change and the tests, ran the translations, the conversion and the suite, and wrote this description.

Hardening from the review of xcl-dev#2034. Whether an instruction has a static
sampler follows from the moves before it in its block, which are in the
key, so no two blocks share a key today; the flag makes the key's
sections delimit themselves. The six largest compute programs of a
retail pack come out byte for byte as before.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant