startup: drop scalar constants at joins that another path writes in gfx2hlsl #2271
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2279"
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 R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-11-25T09:28:23Z.
Change
Fixes #2278.
At a branch target,
Stage.translatenow drops the('const', n)symbol of every SGPR that another path into the target can write:[target, branch];(branch, target);s_setpc_b64jumps from #2238 are included.Registers that no other path writes keep their constant.
set_salso assigns constants at run time, so a dropped register reads its real value. Non-constant symbols (pointers, descriptors) are unchanged.Before this change, a loop counter set to 0 before a loop was folded into the loop body (
s14 = 0x00000000u + 0x00000001u;), so the loop ran to the 65,536-iteration dispatcher guard and every value derived from the counter was frozen.Verification
tests/startup_gfx2hlsl_loop_constants_check.py(new, pure Python, registered in CMake, the Linux CI list and AGENTS.md):s14 = s14 + 0x00000001u;andfloat(int(s14))inside the loopMutations, each turning the check red: constants kept at every join (the old behavior), and forward branches handled without the loop body.
On
b55187e5(main07c1c20f+ this change), Windows 10 19045, Python 3.13:105 checks ok, including
startup_gfx2hlsl_loop_constants,startup_gfx2hlsl_calculated_target(#2238) and bothreadfirstlanechecks. Eight checks fail on this Windows host with and without this change, with the same exit codes, because they need the Linux environment:mesh_heap_sampler,mesh_dynamic_geometry,mesh_dynamic_aot,mesh_lane_spill,mesh_join_descriptor,pso_readinessandstartup_run_ps1exit 1, andstartup_build_revexits 77. The Linux CI job runs all of them.Local shader cache, same requests translated with
mainand with this change: 17 of 171 pipelines change, exactly the 17 that contain a loop. Every changed line replaces a folded constant with the register (R = R + K, conversions and shifts of the counter,reversebits).Evidence and follow-up
The measurements are in #2278: a local startup run, where three translated full-screen pixel passes with folded loop counters took ~99% of the GPU frame (330–440 ms per present). A rerun with the fixed translation has not reached the same load phase yet; I'll add the numbers there.
Checklist
AI-assisted (Claude Code).
🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T09:34:13Z.
Review: COMMENTED
Review of head
b55187e5c774d4768f72fb1bdea2936ccb35d69c(comment only).Summary: the change is correct for the cases it targets. I found no P1 and no P2. Title and body are neutral, the diff is small and clean-room, and the PR is mergeable.
What I checked
git diff --stat origin/main...HEAD: 5 files, +123. The change isStage.join_writesplus the drop of constants at joins intools/startup/gfx2hlsl.py. The rest is the new test and its CTest, CI and AGENTS.md wiring.[target, branch]for a backward branch, and the skipped range for a forward one. A trackedconstfor any of those registers is dropped, soset_sfalls back to the runtime value. That fixes a loop counter set before the loop and incremented inside it..github/workflows/windows.yml, AGENTS.md andCMakeLists.txtall list the new check.Commands run locally on the PR head
python3 -B tests/startup_gfx2hlsl_loop_constants_check.py: PASS (4 cases).tests/startup_gfx2hlsl_*_check.pyrun in a loop: no failures.python3 tests/docs_links_check.py: passed (18 files, 435 links).python3 tests/bidi_controls_check.py: passed.git diff --check origin/main...HEAD: clean.del self.sym[reg]withpass. The new test fails on the counter, loop offset and loop-offset-reads-counter cases, so the test kills it.s_movreldbranch (the "M0 picks the destination" rule). The test still passes, so that rule has no coverage (nit 1). The mutation was reverted.CI
Run platform-independent Python checks on LinuxandAssemble and translate gfx1013 fixturesjobs fail withTypeError: 'NoneType' object is not an iterator. The failing line isnext(steps)intools/mesh_entry_aot.py:882, reached fromtests/mesh_dynamic_aot_check.py.origin/mainand it fails the same way, so it is not caused by this PR. Please fix it separately or rebase on a fix before moving to Ready.Build and test on Windowspasses. I did not run the Win2025 VM: the change is Python-only lowering state. The GPU-readback rule for new shader math does not apply, because no new HLSL math is emitted.Findings
tools/startup/gfx2hlsl.py, injoin_writes): thes_movreldbranch that marks all 128 SGPRs as written has no test. Mutation 2 survives. One fixture withs_movreldinside a loop would cover it.destinations, used byjoin_writes): only the first destination, and the VOP3b SDST, are counted. A second implicit scalar destination, for example the link register ofs_swappc_b64, is not counted. A constant there could survive a join. This is rare. A comment or a follow-up is enough.regsmixes ints with the string'm0'. This is harmless, but a small comment would help.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T09:43:06Z.
Review: COMMENTED
Re-review of head
59a27f2ace55a7cfcb6ad1c5561b8f957626f60f(comment only).Summary: no P1 and no P2. The new head is a merge of main into the branch. The PR's own change is unchanged since my last review (
b55187e5).What changed since
b55187e5git diff --stat b55187e5 HEAD: README.md, docs/startup-runtime.md, src/startup_stubs/gameinput.cpp, tests/startup_gameinput_contracts_check.cpp, tools/mesh_entry_aot.py. These come from main, not from this PR.tools/startup/gfx2hlsl.pyandtests/startup_gfx2hlsl_loop_constants_check.pyare untouched by the merge.git diff --stat origin/main...HEAD: still 5 files, +123, the same as before.CI
mesh_dynamic_aot_check.pyfailure (a main regression) is gone. The Linux Python checks, the gfx1013 fixtures andBuild and test on Windowsall pass on this head. The skipped jobs are the /O2 build and the coverage chart.Commands run locally on this head
python3 -B tests/startup_gfx2hlsl_loop_constants_check.py: PASS.tests/startup_gfx2hlsl_*_check.py: no failures.python3 -B tests/mesh_dynamic_aot_check.py: passes.python3 tests/docs_links_check.py: 18 files, 435 links.python3 tests/bidi_controls_check.py: no bidirectional controls.git diff --check origin/main...HEAD: clean.del self.sym[reg]->passwas killed by the new test.Findings
s_movreldrule, a second implicit scalar destination is not counted injoin_writes, andregsmixes ints with'm0'. None block.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-11-25T09:30:29Z.
The Linux Python job fails in the
mesh_*andpso_readinesschecks (TypeErrorintools/mesh_entry_aot.pyrun_group).mainfails the same job at07c1c20f, this PR's base, and this change does not touch the mesh tools. The PR text's note that these need Linux is wrong: they fail onmainitself.AI-assisted (Claude Code).