Repository navigation
Description
Problem
tools/startup/gfx2hlsl.py tracks descriptor words per scalar register in program order and emits nothing for
an in-place ALU instruction on a descriptor word. Three source-built gfx1013 compute programs translate without
a refusal on main (0955199) although the emitted HLSL does not do what the instructions do. Found while
working on #2274. Each program is assembled with llvm-mc 15 and translated with ComputePipeline through the
helpers of tests/startup_gfx2hlsl_compute_check.py (assemble, root_blob, case A's rsrc2, group size
2x3x4). Branch operands are dword offsets.
All three share this head: the table pointer in s[10:11], an eight-word load, a byte address and the data.
s_mov_b32 s10, s6
s_mov_b32 s11, 0
s_load_dwordx8 s[12:19], s[10:11], 0x0
s_waitcnt lgkmcnt(0)
v_lshlrev_b32 v4, 2, v0
v_mov_b32 v5, v0
Gap 1, CONFIRMED: a store at a loop head, with its descriptor registers written later in the loop body.
s_mov_b32 s24, 0
buffer_store_dword v5, v4, s[16:19], 0 offen ; loop head
s_load_dwordx4 s[16:19], s[10:11], 0x20
s_waitcnt lgkmcnt(0)
s_add_u32 s24, s24, 1
s_cmp_lt_u32 s24, 2
s_cbranch_scc1 65528 ; back to the store
s_endpgm
Result on main: no refusal. The loop block emits u0.Store(a, v5); for both passes and the manifest has the
single line uav 0 table 1 16. The second pass runs with the descriptor at table offset 0x20 in s[16:19],
so its store belongs to another buffer. The same holds when the loop body modifies a word in place instead
(s_and_b32 s17, s17, 0xffff, branch operand 65529): no refusal, both passes through u0.
Correct: refuse the store, since the registers at the loop head are not the same on every pass.
Gap 2, CONFIRMED: a reload of another descriptor that a branch skips.
s_cmp_lt_u32 s7, 4
s_cbranch_scc1 3 ; skips the load and the wait
s_load_dwordx4 s[16:19], s[10:11], 0x20
s_waitcnt lgkmcnt(0)
buffer_store_dword v5, v4, s[16:19], 0 offen
s_endpgm
Result on main: no refusal. The join block emits u0.Store(a, v5); and the manifest has the single line
uav 0 table 1 32. When s7 < 4 the load is skipped and the store runs through the descriptor at table
offset 0x10 that the head loaded, but the output always writes the buffer at offset 0x20.
Correct: refuse the store (two paths reach it with different descriptors), or emit both targets and select by
path.
Gap 3, CONFIRMED: an SCC read after an in-place ALU instruction on a descriptor word.
s_cmp_lt_u32 s7, 4
s_and_b32 s13, s13, 0xc000ffff ; sets SCC = (result != 0); nothing is emitted
s_cselect_b32 s20, 1, 0
v_mov_b32 v5, s20
buffer_store_dword v5, v4, s[16:19], 0 offen
s_endpgm
Result on main: no refusal. The output is scc = s7 < 0x00000004u; then
s20 = scc ? 0x00000001u : 0x00000000u;, so the stored word follows the compare. The instruction order makes it
follow the AND result of descriptor word 1, which the translator does not know.
Correct: refuse the SCC read (the existing scc from descriptor data refusal fits), or emit the SCC of the
masked word once descriptor words are available as values.
Observed where: all three are wrong in the emitted HLSL and manifest only, judged against the instruction
semantics. No wrong output was observed on a GPU read-back. The compute read-back runner binds its own buffers,
so a GPU run would only repeat what the HLSL says; console behaviour is not measured. No count of affected
real programs is claimed.
Proposal
One claimable item per gap, each inside gfx2hlsl.py plus a pure-Python control. Each control is the program
above: it must be refused after the fix, and it translates on main, so the control fails on main.
- Loop head. A register that is written inside a loop does not keep its descriptor symbol at the loop's
target. Acceptance: both gap 1 programs are refused; the same loop without a write tos[16:19]still
translates and stores once per pass. - Forward join. At a join, a register that a skipped path writes does not keep its descriptor symbol, in the
way startup: drop scalar constants at joins that another path writes in gfx2hlsl #2279 drops scalar constants that another path writes. Acceptance: the gap 2 program is refused; the
same program with the reload before the branch still translates withuav 0 table 1 32. - Stale SCC. After an in-place ALU instruction on a descriptor word, SCC is unknown until the next emitted
SCC write, and a read of it is refused. Acceptance: the gap 3 program is refused; the same program with the
compare after the AND still translates. Checks_cselect,s_cmovands_cbranch_scc0/1as readers.
Items 1 and 2 may turn out to be one join rule; whoever takes one should say so and take both.
Alternatives
- Refuse every buffer store past the entry block. Smaller, but it also refuses stores after a branch where no
path writes the descriptor registers, which translate correctly today. - Emit a per-path descriptor selection for gaps 1 and 2. Correct, but it needs per-path symbols and a second
manifest line per target; refusing first is the smaller step and loses nothing that is right today. - For gap 3, emit the real SCC. That needs descriptor words as run-time values, which the translator does not
have.
Verification
- Commit under test:
mainat 0955199,llvm-mc15. - Before a fix: assemble each program above with the head, translate it, and see no refusal and the quoted
lines. - After a fix: the three controls are refused, the three paired programs still translate, and
ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_compute_'and
python -B tests/startup_gfx2hlsl_compute_check.pystill pass. - A before/after refusal census over a local cache should list any request that newly refuses, as counts.
Checklist
- I checked for an existing issue or pull request for this change.
- I did not include game files, dumps, distribution links or credentials.
AI-assisted (Claude Code).
Activity
RavenCurseBurg commentedon Nov 25, 2026
I'll take item 3 (a stale SCC after scalar ALU on descriptor data). I'll use the reported compute program and paired source-built controls for conditional selects, conditional moves and both branch polarities, including a fresh comparison before the read. I'll check that a write reached on only one branch cannot clear the refusal for the other path. Items 1 and 2 remain with the descriptor-join work.
RavenCurseBurg commentedon Nov 25, 2026
Item 3 landed in #2305. I also checked the two remaining items against #2292 at
78a1cd09and main at209938b0. The programs below use the shared source prefix from this issue, compiled for gfx1013 with LLVM 15.0.7, and the normal case-A ComputePipeline entry point.I also ran the committed #2292
binary,dispatchandcontrolcases. The recorded words matched LLVM 15's integrated assembler. With DXC 1.9.2609.5, WARP 10.0.26100.9711 and desktop RTX 4060 driver 32.0.15.9579 both matched all 320 words of the same-slot loop, with values 1 and 2 for each of eight lanes. The OUTSIDE control returned 3 in all four channels on both. Both local adapters reported the debug layer unavailable.These are the reported source-built cases and their paired controls. With #2292 covering them, I see no need for a second implementation of items 1 and 2.
R0Y00 commentedon Nov 25, 2026
#2305 and #2292 are both on
main. The exact #2292 candidate tested in the report above is the one that merged, so the three source-built gaps now have coverage. The combined join, SCC and offline-cache checks passed locally, and the graphics and compute cache revisions advanced. Is anyone already collecting the remaining before/after refusal census requested here? For one matched cache, counts by newly refused reason are enough. Please keep the shader bytes and raw reports local.startup: accept a stride-cleared descriptor for compute buffer stores (…
JVProg commentedon Nov 25, 2026
I ran the before/after refusal census on one matched cache. In this cache neither #2305 nor #2292 turned a request with no recorded refusal into a refused one. The new reasons land on requests that were already refused.
Setup
a6d2c5e6(before),a7353044(shader: refuse stale SCC reads after descriptor arithmetic #2305),5074371f(startup: keep or refuse non-constant scalar symbols at joins in gfx2hlsl #2292). shader: refuse stale SCC reads after descriptor arithmetic #2305 and startup: keep or refuse non-constant scalar symbols at joins in gfx2hlsl #2292 are the only commits in this range that touchtools/startup/gfx2hlsl.py.refusals_report(the function behind--refusals) on a copy of a local cache: 593 graphics request keys and 2,689 compute requests. Slot 57 mesh requests are not examined.pipeline_keyandcompute_keyto 9. Lowering code is unchanged. No key-mismatch refusal in any run.X2W_*variables set. No fxc/DXC compile and no GPU read-back.Totals
a6d2c5e6scc from descriptor datareason at #2305joined at a branch targetreason at #2292Reasons added at #2305 (requests per reason; one request can count in several rows). No reason was removed at this step.
scc from descriptor data in ...psvss_cbranch_scc0s_cbranch_scc1s_cselect_b32s_cselect_b64s_mov_b32s_or_b32s_add_u32s_and_b32s_addc_u32s_mul_i32Join reasons added at #2292
psvsnumeric use of sN holding joined at a branch targetdescriptor operand s[N:N] holds ('joined at a branch target',)s_load through sN holding ('joined at a branch target',)buffer store through s[N:N] holding ('joined at a branch target',)s_addk_i32 on joined at a branch target data#2292 also adds some non-join reasons and removes others (the largest removal in compute is
numeric use of sN holding ptr, 219 requests).It also changes the SCC picture: of the requests that gained an SCC reason at #2305, 126 of 147 graphics and 11 of 112 compute show no SCC reason after #2292. All 126 graphics requests and 9 of the 11 compute requests gain a join reason at that step. I did not trace why.
Limits
internal errorentries on already refused requests (notranslator crash). The per-reason counts above are therefore less reliable than the totals.mainhas moved since5074371f(28 later commits touchgfx2hlsl.py); these numbers do not describe currentmain.AI-assisted (Claude Code).