xshader: optimize HLSL codegen without crashing DXC new inlining #523
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/523"
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 glovepost on 2026-11-29T19:50:29Z.
Rebased onto
origin/main(f360038d), split per review, and fixed the DXC 1.9 (1.9.2609.5)-fnew-inlining-behaviorSIGSEGV.Split PRs
page_wavesballots & double-buffered reads -> #555scc_from_maskscalar arithmetic/bitcount elision -> #558DXC 1.9 (
1.9.2609.5)-fnew-inlining-behaviorSegfault Root CauseUsing the exact runtime flags (
-disable-lifetime-markers -fnew-inlining-behavior, plus-O1forcs_6_6) across 258 recorded ProjectScarlett requests:origin/main:213compiled,0crashes (45xshaderunsupported).#523(3fdea412):143/213crashed with SIGSEGV (exit -11) (45 cs_6_6,20 ms_6_6,62 ps_6_6,3 ps_6_1,2 ps_6_0,9 vs_6_6,2 vs_6_0).compare.rsalone turned143/143crashing shaders into143/143passing.compare.rs's 64-bit integer XOR/andform and trivialpred == 0/pred == 15shortcuts while removingtb_f32_relation/tb_f32_relation_ftzturned30/30crashes into30/30passes.compare.rsalone ontoorigin/mainreproduced30/30DXCexit -11segfaults.CS_InterpolateStrands_94d04887_Wrapped, even rewritingtb_f32_relation_ftzfromselect(...)to ternary?:or earlyif (...) return ...;still segfaulted DXC under-fnew-inlining-behavior, sotb_f32_relation/tb_f32_relation_ftzhas been dropped from this PR (backed up onglovepost/TuxBox:backup/pr523-full).Remaining HLSL Codegen Summary
exec_hi/vcc_hizero initialization elision (setup.rs,output.rs) andOpnd::Nullwv/wswrite elision (state.rs).tb_sbw_*and power-of-2 / single-word shifts inoutput.rs,scalar_memory.rs,buffer.rs).v_mul_legacy_f32viatb_mullc, shifts,v_bfe_i32,v_cvt_pk_u8_f32), branchless 64-bit bit ops/shifts/readfirstlane/exec_grouphelpers (helper_code.rs,vector.rs,vector_wide.rs,scalar_bits.rs,operands.rs), redundant(uint)cast elision inexec_group::predicate, and 64-bit integer XOR/andcompares + trivialpred 0/15float shortcuts (compare.rs).Verification
python3 tuxbox.py check --no-gpupassed 9/9 on final commit HEAD:host_profiles.txtupdated for changed emission)1.9.2609.5)-disable-lifetime-markers -fnew-inlining-behaviorcheck across 258 recorded ProjectScarlett requests on final commit HEAD:213/213compiled,0DXC segfaults (45xshaderunsupported, identical toorigin/main).tools/stage_baseline.py cpuon the 58 locally recordedtools/reference/stage-baseline/sample.jsonrequests (89translations; measured on thecompare.rs-reverted pre-final build vsorigin/main):89/89compiled (0regressions),87/89changed DXIL.108,204,252 -> 104,244,946(-3.659%)35,797,836 -> 35,489,752(-0.861%)359.68s -> 354.13s(-1.54%), median4.199s -> 3.971s(-5.43%,-7.45%across changed DXIL)cpu_seconds): sum357.51s -> 351.66s(-1.64%), median4.188s -> 3.916s(-6.49%)tuxbox.py check) and ProjectScarlett were not run against this rebased commit.AI-assisted: bisected, split, rebased, and tested with LLM tooling.
Imported from brcly/TuxBox. Originally posted by brcly on 2026-11-29T21:41:54Z.
We measured this against
mainon the recorded ProjectScarlett requests before merging, and found a blocker.-fnew-inlining-behavior, which the runtime passes for game shaders (INLINING_FLAGinruntime_shaders.py). The same programs frommaincompile. Without the flag, or with the default flags only, they compile, so the translator GPU checks, which use their own flags, don't see it. In the game, every one of those compiles would crash and be retried without the flag, which is the slower path.To reproduce: translate any recorded request with this branch and run
dxc -T ps_6_6 -E main -HV 2021 -disable-lifetime-markers -fnew-inlining-behavioron the HLSL. The new helper forms (the branchlessselect(and(...))helpers and the specialised relation helpers) are where I'd look first, but I haven't bisected it.It also bundles three changes (codegen, 3-bank
page_waves, mesh SCC elision). If you split them, the parts that don't trigger the crash can be measured and land on their own.Imported from brcly/TuxBox. Originally posted by glovepost on 2026-11-29T23:25:41Z.
Thanks for catching that DXC crash! I reproduced and bisected it locally using
dxc 1.9.2609.5with the runtime flags (-disable-lifetime-markers -fnew-inlining-behavior, plus-O1forcs_6_6) across 258 recorded ProjectScarlett requests:Bisect result
tb_f32_relation/tb_f32_relation_ftzintools/shader-compiler/src/hlsl/compare.rsis the sole necessary and sufficient cause of all143/213DXCexit -11(SIGSEGV) crashes on3fdea412(45 cs_6_6,20 ms_6_6,62 ps_6_6,3 ps_6_1,2 ps_6_0,9 vs_6_6,2 vs_6_0):compare.rsalone turned143/143crashes into143/143passes (select(and(...))inhelper_code.rsandpredicate.rswere innocent).andcompare cleanup and trivialpred == 0/15shortcuts while droppingtb_f32_relation/tb_f32_relation_ftzstill passed30/30(and213/213on final HEAD).compare.rsalone ontoorigin/maincrashed30/30.CS_InterpolateStrands_94d04887_Wrapped, even rewritingtb_f32_relation_ftzfromselect(...)to?:or earlyif (...) return ...;still crashed DXC under-fnew-inlining-behavior.Splits & cleanup
page_wavesballots & double-buffered reads (9/9host checks,213/213DXC-fnew-inlining-behaviorok).scc_from_maskscalar arithmetic/bitcount elision (9/9host checks,213/213DXC-fnew-inlining-behaviorok).origin/main(f360038d) withtb_f32_relation*,page_waves, andabi.rsremoved/split out (full3fdea412backed up onglovepost/TuxBox:backup/pr523-full):tuxbox.py check --no-gpu: 9/9 passed (740Python tests,654+3+2xshader).-fnew-inlining-behaviorcheck across 258 requests:213/213ok,0crashes.stage_baseline.py cpu(58sample.jsonrequests / 89 translations, measured on thecompare.rs-reverted pre-final build):-3.659%HLSL bytes,-0.861%DXIL bytes,-6.49%median DXCcpu_seconds(0regressions).GPU checks (
tuxbox.py check) and ProjectScarlett were not run against this rebased commit.Imported from brcly/TuxBox. Originally posted by glovepost on 2026-11-30T00:35:38Z.
Rebased onto
main(f482572a, commitf1194f8b461c) with no functional changes from2bb24112, and ran the changed GPU checks on NVIDIA:TUXBOX_CHECK_JOBS=4 DXC=<dxc> python3 tuxbox.py check --changed --adapter 10de:1e84 --proton <proton> --prefix <prefix> --windows-dxc <windows-dxc>10de:1e84), driver620.73.04,GE-Proton11-14Lanes and fixtures on the GPU(lanes-bindless-compute,lanes-compute-root,lanes-compute-root-recovery,lanes-raster-tables,lanes-shader-cache) andShader translator on the GPUall passed (13 passed, 0 failed, 0 not run).Evidence: TuxBox check of f1194f8b461c, no uncommitted changes, GPU 10de:1e84: 13 passed, 0 failed, 0 not runImported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-30T01:20:31Z.
The AMD check you were missing, on
f1194f8b: AMD iGPU (1002:13c0, RADV, Mesa 26.0.8, GE-Proton11-14, Linux), fullpython tuxbox.py check: 199 pass, 0 fail. A game was running on the other card during part of it. ProjectScarlett was not run on this commit.Evidence: TuxBox check of
f1194f8b46, no uncommitted changes, GPU 1002:13c0: 14 passed, 0 failed, 0 not runImported from brcly/TuxBox. Originally posted by brcly on 2026-11-30T04:12:21Z.
Heads-up: main just landed a large cleanup (up to
e5d2e913), so this PR needs a rebase.rustfmt.toml).unwrap(), lossyascasts and undocumentedunsafeoutside tests.cargo fmt --check, rustdoc with warnings denied, and Miri on the providers' unit tests.The least painful way is to format your branch first, so the rebase only shows real changes:
Then run
python tuxbox.py check --no-gpu, which now includes the format step.If clippy flags something new:
Fromfor widening,TryFromfor narrowing, and a mask for bit fields.unwrap(): use?, orexpectwith the reason it can't fail.unsafeblock: it needs a// SAFETY:comment.CONTRIBUTING's "Code checks" section lists the commands. Thanks!