xshader: predicate guarded ALU blocks with select() and elide large-shader ISA comments #482

Merged
glovepost merged 1 commit from upstream-pr/482 into main 2026-11-29 15:07:57 +00:00
glovepost commented 2026-11-29 14:53:02 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by glovepost on 2026-11-29T14:53:02Z.


Summary

Shrink the HLSL control-flow graph emitted by xshader so DXC and dxil-spirv spend less time structurizing and optimizing per-lane EXEC branch diamonds:

  • Predicated exec_group blocks and pixel input coalescing: Split tools/shader-compiler/src/hlsl/exec_group.rs into tools/shader-compiler/src/hlsl/exec_group/{mod.rs,predicate.rs} (keeping all Rust files within the 1,200-line limit), allow pixel input reads (i.iN, i.iN.<xyzw>, and GetAttributeAtVertex(...)) inside pure ALU regions, guard both select_writes and predicate against speculating integer / and %, and wire exec_group::predicate() after exec_group::group() in tools/shader-compiler/src/hlsl/driver/pipeline.rs. Pure guarded VGPR and SDWA writes become non-branching select(..., (uint)(expr), dest) statements, sharing a single bool tb_p predicate when a block holds multiple writes or absorbed block-local temporaries.
  • Large-shader ISA comment elision: Emitter skips per-instruction // 0xXXXX <mnemonic> comments in emitter/instruction.rs and paired_wave64.rs when a shader exceeds 1,500 instructions (opt-in via TB_ISA_COMMENTS), trimming HLSL size on large shaders.
  • Branchless float64 helpers: Convert tb_f64_round, tb_f64_to_i32, and tb_i32_to_f64 in tools/shader-compiler/src/hlsl/float64.rs from short-circuit ?:/&&/|| chains to HLSL 2021 select/and/or with & 31u-masked shifts.
  • Profile table and GPU test harness updates:
    • Updated tools/shader-compiler/src/tests/hlsl/host_profiles.txt (TUXBOX_BLESS_PROFILES=1): only the 16-hex content hashes changed for single-lane-per-thread profiles because guarded ALU writes now emit select(); no target profiles or wave requirements changed.
    • Updated tools/check_packed_integer_gpu.py:load_input and tools/check_byte_sad_gpu.py:instrument to match both plain vN = 0x...u; and select()-predicated vN = select(..., (uint)(0x...u), vN); initial literal assignments when injecting GPU check inputs.
  • Benchmark & coverage: On a synthetic 1,806-instruction dynamic-exec_lo vertex shader (TuxBox-upstream vs this branch with DXC), if (exec_lo & guards dropped from 302 to 1, ISA comments from 1,804 to 0, DXIL -O3 br label branches from 300 to 1 (DXC -O3 compile time 0.056 s -> 0.029 s), and DXIL -O0 br label branches from 304 to 3, with dxv passing. Covered by new unit tests in tools/shader-compiler/src/tests/hlsl/exec_group.rs and tools/shader-compiler/src/tests/hlsl.rs, all 64 translator GPU checks (tools/check_translator_gpu.py), and all 39 scenarios across the five shader Lanes suites on both NVIDIA and AMD.

Drafted with AI assistance and verified with the CPU suite and dual-GPU checks listed below.

Tested

Run the checks relevant to this change.

  • The checks relevant to this change passed
  • Changed or new behaviour is covered by a Lanes scenario, or the reason it cannot be is stated below
  • Where the table calls for AMD and NVIDIA, they passed on both.

GPU, driver and backend:

  • NVIDIA GeForce RTX 2070 SUPER (10de:1e84), NVIDIA driver 620.73.04, GE-Proton11-14 + vkd3d-proton
  • AMD Ryzen 7 9800X3D integrated GPU (1002:13c0), Mesa 26.3.1-arch3.5 (RADV RAPHAEL_MENDOCINO), GE-Proton11-14 + vkd3d-proton

Commands run and their results:

DXC=<dxc> python3 tuxbox.py check --no-gpu
  7/7 checks passed (re-run after rebasing onto origin/main):
  - Python unit suite: 654 tests passed
  - tools/shader-compiler: 601 lib + 1 bin + 2 integration tests passed
  - crates/tuxbox-dxbc: 96 passed
  - crates/tuxbox-xg: 17 passed, 1 ignored
  - crates/tuxbox-storage: 18 passed
  - runtime/d3d12 Windows typecheck: passed
  - repository hygiene: passed

python3 tools/check_translator_gpu.py --adapter 10de:1e84 --provider build/d3d12-smoke/d3d12_xs.dll --proton <proton> --prefix <prefix> --compiler-dir <compiler-dir> --dxc <dxc> --work <work>
  64 PASS, 0 FAIL (NVIDIA)

python3 tuxbox.py verify --backend proton --proton <proton> --prefix <prefix> --adapter 10de:1e84 --only lanes-shader-cache --only lanes-raster-tables --only lanes-compute-root --only lanes-compute-root-recovery --only lanes-bindless-compute --output <output>
  39/39 scenarios passed (NVIDIA)

python3 tools/check_translator_gpu.py --adapter 1002:13c0 --provider build/d3d12-smoke/d3d12_xs.dll --proton <proton> --prefix <prefix> --compiler-dir <compiler-dir> --dxc <dxc> --work <work>
  64 PASS, 0 FAIL (AMD)

python3 tuxbox.py verify --backend proton --proton <proton> --prefix <prefix> --adapter 1002:13c0 --only lanes-shader-cache --only lanes-raster-tables --only lanes-compute-root --only lanes-compute-root-recovery --only lanes-bindless-compute --output <output>
  39/39 scenarios passed (AMD)

Checks

CI runs the Python unit tests, the shader compiler, DXBC, and XG layout tests, and a Windows typecheck of tuxbox-d3d12.

If this pull request changes evidence JSON, regenerate the results table and the progress map and include both files:

python tuxbox.py status > docs/RESULTS.md
python tuxbox.py status --svg docs/progress.svg
<!-- greyfinch-sync:brcly/TuxBox:issue:5551881686 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/482). Originally posted by [glovepost](https://github.com/glovepost) on 2026-11-29T14:53:02Z. --- ## Summary Shrink the HLSL control-flow graph emitted by `xshader` so DXC and `dxil-spirv` spend less time structurizing and optimizing per-lane EXEC branch diamonds: - **Predicated `exec_group` blocks and pixel input coalescing**: Split `tools/shader-compiler/src/hlsl/exec_group.rs` into `tools/shader-compiler/src/hlsl/exec_group/{mod.rs,predicate.rs}` (keeping all Rust files within the 1,200-line limit), allow pixel input reads (`i.iN`, `i.iN.<xyzw>`, and `GetAttributeAtVertex(...)`) inside pure ALU regions, guard both `select_writes` and `predicate` against speculating integer `/` and `%`, and wire `exec_group::predicate()` after `exec_group::group()` in `tools/shader-compiler/src/hlsl/driver/pipeline.rs`. Pure guarded VGPR and SDWA writes become non-branching `select(..., (uint)(expr), dest)` statements, sharing a single `bool tb_p` predicate when a block holds multiple writes or absorbed block-local temporaries. - **Large-shader ISA comment elision**: `Emitter` skips per-instruction `// 0xXXXX <mnemonic>` comments in `emitter/instruction.rs` and `paired_wave64.rs` when a shader exceeds 1,500 instructions (opt-in via `TB_ISA_COMMENTS`), trimming HLSL size on large shaders. - **Branchless `float64` helpers**: Convert `tb_f64_round`, `tb_f64_to_i32`, and `tb_i32_to_f64` in `tools/shader-compiler/src/hlsl/float64.rs` from short-circuit `?:`/`&&`/`||` chains to HLSL 2021 `select`/`and`/`or` with `& 31u`-masked shifts. - **Profile table and GPU test harness updates**: - Updated `tools/shader-compiler/src/tests/hlsl/host_profiles.txt` (`TUXBOX_BLESS_PROFILES=1`): only the 16-hex content hashes changed for single-lane-per-thread profiles because guarded ALU writes now emit `select()`; no target profiles or wave requirements changed. - Updated `tools/check_packed_integer_gpu.py:load_input` and `tools/check_byte_sad_gpu.py:instrument` to match both plain `vN = 0x...u;` and `select()`-predicated `vN = select(..., (uint)(0x...u), vN);` initial literal assignments when injecting GPU check inputs. - **Benchmark & coverage**: On a synthetic 1,806-instruction dynamic-`exec_lo` vertex shader (`TuxBox-upstream` vs this branch with DXC), `if (exec_lo &` guards dropped from `302` to `1`, ISA comments from `1,804` to `0`, DXIL `-O3` `br label` branches from `300` to `1` (DXC `-O3` compile time `0.056 s -> 0.029 s`), and DXIL `-O0` `br label` branches from `304` to `3`, with `dxv` passing. Covered by new unit tests in `tools/shader-compiler/src/tests/hlsl/exec_group.rs` and `tools/shader-compiler/src/tests/hlsl.rs`, all 64 translator GPU checks (`tools/check_translator_gpu.py`), and all 39 scenarios across the five shader Lanes suites on both NVIDIA and AMD. Drafted with AI assistance and verified with the CPU suite and dual-GPU checks listed below. ## Tested Run the [checks relevant to this change](../CONTRIBUTING.md#test-what-your-change-touches). - [x] The checks relevant to this change passed - [x] Changed or new behaviour is covered by a Lanes scenario, or the reason it cannot be is stated below - [x] Where the table calls for AMD and NVIDIA, they passed on both. GPU, driver and backend: - NVIDIA GeForce RTX 2070 SUPER (`10de:1e84`), NVIDIA driver `620.73.04`, GE-Proton11-14 + vkd3d-proton - AMD Ryzen 7 9800X3D integrated GPU (`1002:13c0`), Mesa `26.3.1-arch3.5` (RADV RAPHAEL_MENDOCINO), GE-Proton11-14 + vkd3d-proton Commands run and their results: ```text DXC=<dxc> python3 tuxbox.py check --no-gpu 7/7 checks passed (re-run after rebasing onto origin/main): - Python unit suite: 654 tests passed - tools/shader-compiler: 601 lib + 1 bin + 2 integration tests passed - crates/tuxbox-dxbc: 96 passed - crates/tuxbox-xg: 17 passed, 1 ignored - crates/tuxbox-storage: 18 passed - runtime/d3d12 Windows typecheck: passed - repository hygiene: passed python3 tools/check_translator_gpu.py --adapter 10de:1e84 --provider build/d3d12-smoke/d3d12_xs.dll --proton <proton> --prefix <prefix> --compiler-dir <compiler-dir> --dxc <dxc> --work <work> 64 PASS, 0 FAIL (NVIDIA) python3 tuxbox.py verify --backend proton --proton <proton> --prefix <prefix> --adapter 10de:1e84 --only lanes-shader-cache --only lanes-raster-tables --only lanes-compute-root --only lanes-compute-root-recovery --only lanes-bindless-compute --output <output> 39/39 scenarios passed (NVIDIA) python3 tools/check_translator_gpu.py --adapter 1002:13c0 --provider build/d3d12-smoke/d3d12_xs.dll --proton <proton> --prefix <prefix> --compiler-dir <compiler-dir> --dxc <dxc> --work <work> 64 PASS, 0 FAIL (AMD) python3 tuxbox.py verify --backend proton --proton <proton> --prefix <prefix> --adapter 1002:13c0 --only lanes-shader-cache --only lanes-raster-tables --only lanes-compute-root --only lanes-compute-root-recovery --only lanes-bindless-compute --output <output> 39/39 scenarios passed (AMD) ``` ## Checks CI runs the Python unit tests, the shader compiler, DXBC, and XG layout tests, and a Windows typecheck of `tuxbox-d3d12`. If this pull request changes evidence JSON, regenerate the results table and the progress map and include both files: ```sh python tuxbox.py status > docs/RESULTS.md python tuxbox.py status --svg docs/progress.svg ```
NickStallman commented 2026-11-29 16:23:55 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-29T16:23:55Z.


Two checks of this on current main, both cards, by running the translated programs themselves:

  • Mesh programs: 148 random voting ones (fixed seed) plus three that failed before #473, as mesh against their compute form, RTX 5090 (620.70.10) and an AMD iGPU (RADV): right in every one that runs (150 of 151; one root is refused) with the tree before and after this change. It removes selects from mesh programs rather than adding them (writes with a division keep their guard), and no line that votes, skips or uses the lane changes.
  • Compute: 100 changed programs, 35 could run (most index the descriptor heap): the RTX 5090 12 the same, 23 equivalent (float rounding), none changed. AMD 34 equivalent and one counter that differed by 1. Either translation gives either value from run to run, so I don't count it as this change. (Corrected: I first called it a float tie. The number of comparisons executed also varies between builds, which looks more like an uninitialised or racing input; I don't know which.)

Not covered: pixel, vertex and geometry programs, which this changes most (17,381 pixel programs in the recorded set); our tools only execute compute and mesh.

<!-- greyfinch-sync:brcly/TuxBox:comment:7258871678 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/482#issuecomment-7258871678). Originally posted by [NickStallman](https://github.com/NickStallman) on 2026-11-29T16:23:55Z. --- Two checks of this on current `main`, both cards, by running the translated programs themselves: - **Mesh programs:** 148 random voting ones (fixed seed) plus three that failed before #473, as mesh against their compute form, RTX 5090 (620.70.10) and an AMD iGPU (RADV): right in every one that runs (150 of 151; one root is refused) with the tree before and after this change. It removes selects from mesh programs rather than adding them (writes with a division keep their guard), and no line that votes, skips or uses the lane changes. - **Compute:** 100 changed programs, 35 could run (most index the descriptor heap): the RTX 5090 12 the same, 23 equivalent (float rounding), none changed. AMD 34 equivalent and one counter that differed by 1. Either translation gives either value from run to run, so I don't count it as this change. (Corrected: I first called it a float tie. The number of comparisons executed also varies between builds, which looks more like an uninitialised or racing input; I don't know which.) **Not covered:** pixel, vertex and geometry programs, which this changes most (17,381 pixel programs in the recorded set); our tools only execute compute and mesh.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
brcly/TuxBox!482
No description provided.