Skip to content

startup: gfx2hlsl accepts three compute programs whose descriptor or SCC state differs from program order #2302

Backlog

Description

@NiiRoZz

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.

  1. 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 to s[16:19] still
    translates and stores once per pass.
  2. 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 with uav 0 table 1 32.
  3. 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. Check s_cselect, s_cmov and s_cbranch_scc0/1 as 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: main at 0955199, llvm-mc 15.
  • 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.py still 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

  1. RavenCurseBurg commented on Nov 25, 2026

    @RavenCurseBurg
    Contributor

    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.

  2. RavenCurseBurg commented on Nov 25, 2026

    @RavenCurseBurg
    Contributor

    Item 3 landed in #2305. I also checked the two remaining items against #2292 at 78a1cd09 and main at 209938b0. 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.

    Source case main #2292
    Loop reload from table offset 32 after the store Publishes offset 16 Refuses the joined descriptor
    Loop modifies s17 in place after the store Publishes offset 16 Refuses the modified descriptor
    Same loop with no descriptor write Publishes offset 16 Publishes offset 16
    Forward branch skips the reload Publishes offset 32 Refuses the joined descriptor
    Reload before the forward branch Publishes offset 32 Publishes offset 32

    I also ran the committed #2292 binary, dispatch and control cases. 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.

  3. R0Y00 commented on Nov 25, 2026

    @R0Y00
    Owner

    #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.

  4. JVProg commented on Nov 25, 2026

    @JVProg
    Contributor

    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

    Totals

    a6d2c5e6 after #2305 after #2292
    Graphics with no recorded refusal (of 593) 67 67 68
    Compute with no recorded refusal (of 2,689) 8 8 8
    Newly refused requests 0 0
    Distinct requests Graphics Compute
    Gain an scc from descriptor data reason at #2305 147 112
    Gain a joined at a branch target reason at #2292 465 1,446
    First refusal changes at #2305 0 0
    First refusal changes at #2292 (of these, now a join reason) 3 (2) 5 (3)

    Reasons 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 ... Graphics ps Graphics vs Compute
    s_cbranch_scc0 132 1 62
    s_cbranch_scc1 19 48
    s_cselect_b32 55 6 82
    s_cselect_b64 10 30
    s_mov_b32 53 35
    s_or_b32 24
    s_add_u32 10
    s_and_b32 10
    s_addc_u32 2
    s_mul_i32 2

    Join reasons added at #2292

    Reason Graphics ps Graphics vs Compute
    numeric use of sN holding joined at a branch target 433 33 1,409
    descriptor operand s[N:N] holds ('joined at a branch target',) 368 4 953
    s_load through sN holding ('joined at a branch target',) 36 1 87
    buffer store through s[N:N] holding ('joined at a branch target',) 41
    s_addk_i32 on joined at a branch target data 4

    #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

    • Reasons after the first refusal are approximate, as the tool's caveat says: skipped instructions leave later state unmodelled. All three runs include follow-on internal error entries on already refused requests (no translator crash). The per-reason counts above are therefore less reliable than the totals.
    • Only 67 graphics and 8 compute requests had no recorded refusal at the start, so this cache has little room to show a newly refused one. It does not show that other caches would behave the same.
    • "No recorded refusal" does not mean the output compiles or is correct. I did not compare the emitted HLSL between revisions.
    • main has moved since 5074371f (28 later commits touch gfx2hlsl.py); these numbers do not describe current main.

    AI-assisted (Claude Code).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions