shaders: shorten the DXC helper's optimizer for cs_6_6 #638

Merged
JeffreyBytes merged 1 commit from upstream-pr/638 into main 2026-12-02 21:30:48 +00:00
JeffreyBytes commented 2026-12-01 21:24:01 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by JeffreyBytes on 2026-12-01T21:24:01Z.


Summary

Refs #293.

The DXC helper (tools/dxc_worker.cpp) already runs DXC's optimizer through the API with the -Odump pass list. This replaces the general optimizer (the passes after -dxil-fix-array-init through -alignment-from-assumptions) with a shorter list, for cs_6_6 compiles that use -O1 with -fnew-inlining-behavior. The HLSL lowering before that range and the DXIL finalization after it stay as DXC arranges them. -O0 and every other profile are unchanged.

The list, with the runtime flags (-O1 -disable-lifetime-markers -fnew-inlining-behavior):

-targetlibinfo -tbaa -scoped-noalias -basicaa -globalopt
-inline,InlineThreshold=225,InsertLifetime=t -sroa -simplifycfg -gvn -loop-rotate
-instcombine,NoSink=0 -simplifycfg -dce

-instcombine runs once, after -gvn. Before -gvn it took 33 s of a 34 s compile on a program that keeps its registers in a local array. The list keeps a late -loop-rotate, since dxil-spirv crashed without one in Nick's tests on #293.

I'm doing the ps_6_6, ms_6_6 and cs_6_0 list as a separate PR once this one is in, as asked on #293. It needs a few more passes (DXC's own inline threshold, an earlier -instcombine, GVN hoisting and loop unrolling), and it needs pixel and mesh output checked, which this one doesn't.

Two new tests in tests/test_dxc_worker.py build the helper against the DXC release in DXC. One checks that its cs_6_6 output passes DXV with the runtime flags. The other compiles a small loop: DXC's stock -O1 list runs -indvars, which turns the exit test from icmp ult into icmp eq, and this list doesn't, so icmp ult stays. That one fails on the base's dxc_worker.cpp.

The helper's digest is part of the DXIL store's identity, so after this change a prefix starts a new store and the next prepare compiles everything once, as it did after #535.

Numbers

Re-timed on 9a19c767, since #523 changed the HLSL. 101 recorded ProjectScarlett cs_6_6 programs (the 40 largest plus a random sample, from the 4,000 largest requests), translated on the base, DXC 1.9.2609.5, stock helper against this one, 6 jobs, both sides interleaved per program:

programs DXC CPU slowest tenth median blocks instructions DXIL
cs_6_6 101 0.51 (1,159 s to 589 s) 0.43 0.52 1.020 1.015 1.005

All ratios are to the stock helper. Every compile succeeded and every output passes DXV. The three programs that took over 60 s on stock (6a42a3d9, 3f81993d, e8570a69) are all under 60 s now. At 3 jobs they went from 57 s to about 25 s each (0.45).

Main moved while I was measuring. At 2a850114, 32 of the 101 programs translate differently (mostly the group-memory size from #633 and the root constants from #619). Re-timed on their new HLSL, those 32 come out at 0.46 (0.41 for the slowest tenth), against 0.47 for the same 32 on 9a19c767, with blocks 1.030, instructions 1.019 and DXIL 1.007. All pass DXV. The branch is rebased onto 2a850114; the patch is unchanged.

Block count is 2.0% higher, and most of that comes from those three programs (66,919 to 70,391 blocks, +5.2%). The rest are within about 1.6%. It was +1% on the HLSL from before #523.

Where the time goes in the slowest program (6a42a3d9, perf, so the attribution is approximate): with this list the compile is about 31 s, of which DxilConditionalMem2Reg is ~21% (lowering, outside the replaced range, the same time as on stock), the LCSSA that -loop-rotate pulls in ~23%, GVN ~12% and instcombine ~6%. Stock spends about half its time in DXC's loop deletion and LCSSA, which this list drops.

Prep A/B

A cold --prepare-only of the same 4,000-request subset of my recorded requests as in my earlier #293 comment, on 9a19c767, scratch prefix for each side, no pipeline replay, default jobs, only the helper different:

base with the list
DXC pass 436.3 s 322.3 s (-26%)
total 535 s 419 s (-22%)
DXC helper CPU 6,081 s 4,400 s (0.72x)
compiled / unsupported / failed 3,866 / 134 / 0 3,866 / 134 / 0

Both sides had one slow shader and no DXV rejections.

GPU check

tools/execute_recorded_shaders.py on an RX 6700 XT with RADV, seed 293, 300 sampled requests, translated on 9a19c767, comparing the outputs of the stock helper and this one with the runtime flags. 96 ran on both sides (68 cs_6_6, and 28 cs_6_0, which this PR doesn't change). 94 were equivalent, 1 changed, 1 was unstable, 0 were lost. 192 were skipped for heap indexing, 11 were refused by the translator and 1 was a ray scene. No new kernel log lines during the run.

The changed one, 9268fb95, is not a miscompile. Only the x component of one 8x4 tile in one UAV differs, by 10 to 38 ULP. The DXIL for that read-modify-write is identical on both sides, and so are all its inputs. Stock gives seed*mx and the lean one gives seed*mx^2, as if the read-modify-write ran twice. The harness's seeds map every entry of both typed SRV seeds to tile (0,0), so all four groups of the 2x2 grid update the same texels, and the result depends on the order the groups run in. Stock compared with its own repeat gave the stock result, so it isn't flaky there, but I wouldn't expect the order to stay fixed. The unstable one (fa6c64bc) differs between stock and a second stock run, so it isn't tied to the change.

The harness only runs programs up to 4 MB of HLSL, and compute only, so the largest programs aren't in it. This list doesn't touch pixel or mesh compiles.

Tested

  • The checks relevant to this change passed: check --no-gpu and the helper tests passed. The full check has one failure that also happens on the base (below).
  • 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. Otherwise, say which vendor still needs to run them: NVIDIA. I don't have a card.

There's no Lanes scenario for this: it changes DXC's pass list, not what TuxBox does with the DXIL. The helper test and the GPU comparison above cover the output.

GPU, driver and backend: AMD Radeon RX 6700 XT, RADV, GE-Proton11-15, on a copy of the prefix.

python tuxbox.py check --no-gpu
13 passed, 0 failed, 0 not run

python tuxbox.py check (GPU, copied prefix, DXC given)
16 passed, 1 failed, 0 not run
FAIL lanes-selftest-texture-publication (lanes.exe exit code 5, no receipt)

DXC=<DXC 1.9.2609.5 release>/bin/dxc python -m unittest -v tests.test_dxc_worker
Ran 5 tests: OK

lanes-selftest-texture-publication fails the same way on 9a19c767 without this change (2 of 2 runs, and 3 of 3 with it). That's #625 (lazy publication), not this change. The D3D12 regression controls and the translator GPU checks passed.

Not run on NVIDIA.

<!-- greyfinch-sync:brcly/TuxBox:issue:5594809286 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/638). Originally posted by [JeffreyBytes](https://github.com/JeffreyBytes) on 2026-12-01T21:24:01Z. --- ## Summary Refs #293. The DXC helper (`tools/dxc_worker.cpp`) already runs DXC's optimizer through the API with the `-Odump` pass list. This replaces the general optimizer (the passes after `-dxil-fix-array-init` through `-alignment-from-assumptions`) with a shorter list, for `cs_6_6` compiles that use `-O1` with `-fnew-inlining-behavior`. The HLSL lowering before that range and the DXIL finalization after it stay as DXC arranges them. `-O0` and every other profile are unchanged. The list, with the runtime flags (`-O1 -disable-lifetime-markers -fnew-inlining-behavior`): ``` -targetlibinfo -tbaa -scoped-noalias -basicaa -globalopt -inline,InlineThreshold=225,InsertLifetime=t -sroa -simplifycfg -gvn -loop-rotate -instcombine,NoSink=0 -simplifycfg -dce ``` `-instcombine` runs once, after `-gvn`. Before `-gvn` it took 33 s of a 34 s compile on a program that keeps its registers in a local array. The list keeps a late `-loop-rotate`, since dxil-spirv crashed without one in Nick's tests on #293. I'm doing the `ps_6_6`, `ms_6_6` and `cs_6_0` list as a separate PR once this one is in, as asked on #293. It needs a few more passes (DXC's own inline threshold, an earlier `-instcombine`, GVN hoisting and loop unrolling), and it needs pixel and mesh output checked, which this one doesn't. Two new tests in `tests/test_dxc_worker.py` build the helper against the DXC release in `DXC`. One checks that its `cs_6_6` output passes DXV with the runtime flags. The other compiles a small loop: DXC's stock `-O1` list runs `-indvars`, which turns the exit test from `icmp ult` into `icmp eq`, and this list doesn't, so `icmp ult` stays. That one fails on the base's `dxc_worker.cpp`. The helper's digest is part of the DXIL store's identity, so after this change a prefix starts a new store and the next prepare compiles everything once, as it did after #535. ## Numbers Re-timed on 9a19c767, since #523 changed the HLSL. 101 recorded ProjectScarlett `cs_6_6` programs (the 40 largest plus a random sample, from the 4,000 largest requests), translated on the base, DXC 1.9.2609.5, stock helper against this one, 6 jobs, both sides interleaved per program: | | programs | DXC CPU | slowest tenth | median | blocks | instructions | DXIL | |---|---:|---:|---:|---:|---:|---:|---:| | `cs_6_6` | 101 | 0.51 (1,159 s to 589 s) | 0.43 | 0.52 | 1.020 | 1.015 | 1.005 | All ratios are to the stock helper. Every compile succeeded and every output passes DXV. The three programs that took over 60 s on stock (6a42a3d9, 3f81993d, e8570a69) are all under 60 s now. At 3 jobs they went from 57 s to about 25 s each (0.45). Main moved while I was measuring. At 2a850114, 32 of the 101 programs translate differently (mostly the group-memory size from #633 and the root constants from #619). Re-timed on their new HLSL, those 32 come out at 0.46 (0.41 for the slowest tenth), against 0.47 for the same 32 on 9a19c767, with blocks 1.030, instructions 1.019 and DXIL 1.007. All pass DXV. The branch is rebased onto 2a850114; the patch is unchanged. Block count is 2.0% higher, and most of that comes from those three programs (66,919 to 70,391 blocks, +5.2%). The rest are within about 1.6%. It was +1% on the HLSL from before #523. Where the time goes in the slowest program (6a42a3d9, perf, so the attribution is approximate): with this list the compile is about 31 s, of which DxilConditionalMem2Reg is ~21% (lowering, outside the replaced range, the same time as on stock), the LCSSA that `-loop-rotate` pulls in ~23%, GVN ~12% and instcombine ~6%. Stock spends about half its time in DXC's loop deletion and LCSSA, which this list drops. ### Prep A/B A cold `--prepare-only` of the same 4,000-request subset of my recorded requests as in my earlier #293 comment, on 9a19c767, scratch prefix for each side, no pipeline replay, default jobs, only the helper different: | | base | with the list | |---|---:|---:| | DXC pass | 436.3 s | 322.3 s (-26%) | | total | 535 s | 419 s (-22%) | | DXC helper CPU | 6,081 s | 4,400 s (0.72x) | | compiled / unsupported / failed | 3,866 / 134 / 0 | 3,866 / 134 / 0 | Both sides had one slow shader and no DXV rejections. ## GPU check `tools/execute_recorded_shaders.py` on an RX 6700 XT with RADV, seed 293, 300 sampled requests, translated on 9a19c767, comparing the outputs of the stock helper and this one with the runtime flags. 96 ran on both sides (68 `cs_6_6`, and 28 `cs_6_0`, which this PR doesn't change). 94 were equivalent, 1 changed, 1 was unstable, 0 were lost. 192 were skipped for heap indexing, 11 were refused by the translator and 1 was a ray scene. No new kernel log lines during the run. The changed one, 9268fb95, is not a miscompile. Only the x component of one 8x4 tile in one UAV differs, by 10 to 38 ULP. The DXIL for that read-modify-write is identical on both sides, and so are all its inputs. Stock gives `seed*mx` and the lean one gives `seed*mx^2`, as if the read-modify-write ran twice. The harness's seeds map every entry of both typed SRV seeds to tile (0,0), so all four groups of the 2x2 grid update the same texels, and the result depends on the order the groups run in. Stock compared with its own repeat gave the stock result, so it isn't flaky there, but I wouldn't expect the order to stay fixed. The unstable one (fa6c64bc) differs between stock and a second stock run, so it isn't tied to the change. The harness only runs programs up to 4 MB of HLSL, and compute only, so the largest programs aren't in it. This list doesn't touch pixel or mesh compiles. ## Tested - [x] The checks relevant to this change passed: `check --no-gpu` and the helper tests passed. The full check has one failure that also happens on the base (below). - [ ] 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. Otherwise, say which vendor still needs to run them: NVIDIA. I don't have a card. There's no Lanes scenario for this: it changes DXC's pass list, not what TuxBox does with the DXIL. The helper test and the GPU comparison above cover the output. GPU, driver and backend: AMD Radeon RX 6700 XT, RADV, GE-Proton11-15, on a copy of the prefix. ```text python tuxbox.py check --no-gpu 13 passed, 0 failed, 0 not run python tuxbox.py check (GPU, copied prefix, DXC given) 16 passed, 1 failed, 0 not run FAIL lanes-selftest-texture-publication (lanes.exe exit code 5, no receipt) DXC=<DXC 1.9.2609.5 release>/bin/dxc python -m unittest -v tests.test_dxc_worker Ran 5 tests: OK ``` `lanes-selftest-texture-publication` fails the same way on 9a19c767 without this change (2 of 2 runs, and 3 of 3 with it). That's #625 (lazy publication), not this change. The D3D12 regression controls and the translator GPU checks passed. Not run on NVIDIA.
brcly commented 2026-12-01 21:32:57 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by brcly on 2026-12-01T21:32:57Z.


Hey dude,

I see DXC is quicker, but what are the file sizes it spits out?

It's a tough balance between file size and speed with DXC.

DXC may be quicker, but if the file size is bigger, then it takes longer in the GPU driver, thus pretty much mitigating the DXC speed.

<!-- greyfinch-sync:brcly/TuxBox:comment:7326431140 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/638#issuecomment-7326431140). Originally posted by [brcly](https://github.com/brcly) on 2026-12-01T21:32:57Z. --- Hey dude, I see DXC is quicker, but what are the file sizes it spits out? It's a tough balance between file size and speed with DXC. DXC may be quicker, but if the file size is bigger, then it takes longer in the GPU driver, thus pretty much mitigating the DXC speed.
JeffreyBytes commented 2026-12-02 00:24:01 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by JeffreyBytes on 2026-12-02T00:24:01Z.


Fair point. That trade-off is why these programs compile at -O1 at all: unoptimised, their DXIL had about four times the blocks, and vkd3d-proton's control-flow pass took minutes on the largest.

Output size, on the same 101 cs_6_6 programs, this list against the stock one:

on 9a19c767 the 32 changed at 2a850114
DXIL bytes 1.005 1.007
instructions 1.015 1.019
basic blocks 1.020 1.030

Most of the block increase is in the three slowest programs, 66,919 to 70,391 blocks (+5.2%). The rest are within about 1.6%.

So the output is close to the same size, not a different class like -O0. What I haven't measured is driver time. Blocks are what vkd3d-proton's structurizer cares about, so +5% on the three biggest is where it would show, if anywhere. I'll run the prepare A/B again with pipeline replay on, and compile those programs through dxil-spirv and RADV on both sides, then post the numbers here.

<!-- greyfinch-sync:brcly/TuxBox:comment:7330501910 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/638#issuecomment-7330501910). Originally posted by [JeffreyBytes](https://github.com/JeffreyBytes) on 2026-12-02T00:24:01Z. --- Fair point. That trade-off is why these programs compile at `-O1` at all: unoptimised, their DXIL had about four times the blocks, and vkd3d-proton's control-flow pass took minutes on the largest. Output size, on the same 101 `cs_6_6` programs, this list against the stock one: | | on 9a19c767 | the 32 changed at 2a850114 | |---|---:|---:| | DXIL bytes | 1.005 | 1.007 | | instructions | 1.015 | 1.019 | | basic blocks | 1.020 | 1.030 | Most of the block increase is in the three slowest programs, 66,919 to 70,391 blocks (+5.2%). The rest are within about 1.6%. So the output is close to the same size, not a different class like `-O0`. What I haven't measured is driver time. Blocks are what vkd3d-proton's structurizer cares about, so +5% on the three biggest is where it would show, if anywhere. I'll run the prepare A/B again with pipeline replay on, and compile those programs through dxil-spirv and RADV on both sides, then post the numbers here.
JeffreyBytes commented 2026-12-02 11:08:11 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by JeffreyBytes on 2026-12-02T11:08:11Z.


Driver numbers, RX 6700 XT, RADV (Mesa 26.3.1), vkd3d-proton from GE-Proton11-15.

Per program. I built a compute pipeline from each program's DXIL through vkd3d-proton, with the vkd3d, Mesa and RADV caches off, median of 3 interleaved rounds. 42 of the 101 cs_6_6 programs build on both sides; the other 59 fail dxil-spirv conversion on both sides with the root signature my harness gives them (a synthetic one, not the runtime's), so they're unmeasured.

42 programs stock this list ratio
DXIL 61.6 MB 61.9 MB 1.006
SPIR-V 149.6 MB 152.9 MB 1.022
RADV code size 24.23 MB 24.14 MB 0.996
pipeline creation 436 s 454 s 1.042

Per program the median is 1.021 (0.94 to 1.08), with round-to-round noise around 1.3%. The three slowest go from about 13.9 s to 14.8 s each (+6%), with 6.8% more SPIR-V. So you're right that there is a driver cost. On the same 42 programs this list saves about 385 s of DXC CPU against those 18 s in the driver.

In a prepare. Cold --prepare-only of the same 4,000-request subset with pipeline replay on, two rounds (stock, this list, then reversed), ratios to the mean of the two stock runs:

stock this list
DXC helper CPU 6,222 s 0.71
preparation (before replay) 435 s 0.75
prepare wall 1,862 s 0.94
driver time, the 347 replayed records built from helper DXIL 474 s 0.98

Stock against stock varied 1.2% on that driver time, so call it unchanged here. It isn't the same set as the 42 above, and the replay times wall time per record across 8 threads with DXC running alongside, so it's a coarser measurement. Every side compiled the same 3,866 requests with no failures.

Short version: the output is a little bigger and the driver takes a few percent longer on the large compute programs, but that's tens of seconds against hundreds saved in DXC.

<!-- greyfinch-sync:brcly/TuxBox:comment:7343476411 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/638#issuecomment-7343476411). Originally posted by [JeffreyBytes](https://github.com/JeffreyBytes) on 2026-12-02T11:08:11Z. --- Driver numbers, RX 6700 XT, RADV (Mesa 26.3.1), vkd3d-proton from GE-Proton11-15. **Per program.** I built a compute pipeline from each program's DXIL through vkd3d-proton, with the vkd3d, Mesa and RADV caches off, median of 3 interleaved rounds. 42 of the 101 `cs_6_6` programs build on both sides; the other 59 fail dxil-spirv conversion on both sides with the root signature my harness gives them (a synthetic one, not the runtime's), so they're unmeasured. | 42 programs | stock | this list | ratio | |---|---:|---:|---:| | DXIL | 61.6 MB | 61.9 MB | 1.006 | | SPIR-V | 149.6 MB | 152.9 MB | 1.022 | | RADV code size | 24.23 MB | 24.14 MB | 0.996 | | pipeline creation | 436 s | 454 s | 1.042 | Per program the median is 1.021 (0.94 to 1.08), with round-to-round noise around 1.3%. The three slowest go from about 13.9 s to 14.8 s each (+6%), with 6.8% more SPIR-V. So you're right that there is a driver cost. On the same 42 programs this list saves about 385 s of DXC CPU against those 18 s in the driver. **In a prepare.** Cold `--prepare-only` of the same 4,000-request subset with pipeline replay on, two rounds (stock, this list, then reversed), ratios to the mean of the two stock runs: | | stock | this list | |---|---:|---:| | DXC helper CPU | 6,222 s | 0.71 | | preparation (before replay) | 435 s | 0.75 | | prepare wall | 1,862 s | 0.94 | | driver time, the 347 replayed records built from helper DXIL | 474 s | 0.98 | Stock against stock varied 1.2% on that driver time, so call it unchanged here. It isn't the same set as the 42 above, and the replay times wall time per record across 8 threads with DXC running alongside, so it's a coarser measurement. Every side compiled the same 3,866 requests with no failures. Short version: the output is a little bigger and the driver takes a few percent longer on the large compute programs, but that's tens of seconds against hundreds saved in DXC.
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!638
No description provided.