shaders: shorten the DXC helper's optimizer for cs_6_6 #638
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/638"
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?
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-Odumppass list. This replaces the general optimizer (the passes after-dxil-fix-array-initthrough-alignment-from-assumptions) with a shorter list, forcs_6_6compiles that use-O1with-fnew-inlining-behavior. The HLSL lowering before that range and the DXIL finalization after it stay as DXC arranges them.-O0and every other profile are unchanged.The list, with the runtime flags (
-O1 -disable-lifetime-markers -fnew-inlining-behavior):-instcombineruns once, after-gvn. Before-gvnit 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_6andcs_6_0list 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.pybuild the helper against the DXC release inDXC. One checks that itscs_6_6output passes DXV with the runtime flags. The other compiles a small loop: DXC's stock-O1list runs-indvars, which turns the exit test fromicmp ultintoicmp eq, and this list doesn't, soicmp ultstays. That one fails on the base'sdxc_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 ProjectScarlettcs_6_6programs (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:cs_6_6All 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 on9a19c767, with blocks 1.030, instructions 1.019 and DXIL 1.007. All pass DXV. The branch is rebased onto2a850114; 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-rotatepulls 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-onlyof the same 4,000-request subset of my recorded requests as in my earlier #293 comment, on9a19c767, scratch prefix for each side, no pipeline replay, default jobs, only the helper different:Both sides had one slow shader and no DXV rejections.
GPU check
tools/execute_recorded_shaders.pyon an RX 6700 XT with RADV, seed 293, 300 sampled requests, translated on9a19c767, comparing the outputs of the stock helper and this one with the runtime flags. 96 ran on both sides (68cs_6_6, and 28cs_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*mxand the lean one givesseed*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
check --no-gpuand the helper tests passed. The full check has one failure that also happens on the base (below).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.
lanes-selftest-texture-publicationfails the same way on9a19c767without 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.
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.
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
-O1at 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_6programs, this list against the stock one:9a19c7672a850114Most 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.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_6programs 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.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-onlyof 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 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.