Skip to content

gfx2hlsl: extend the uniform compute load proof to multi-register loads - #2454

Merged
tedin7 merged 6 commits into
R0Y00:mainfrom
NiiRoZz:startup/gfx2hlsl-readfirstlane-multi-load
Nov 26, 2026
Merged

tedin7 merged 6 commits into
R0Y00:mainfrom
NiiRoZz:startup/gfx2hlsl-readfirstlane-multi-load

Conversation

@NiiRoZz

@NiiRoZz NiiRoZz commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Depends on #2446: this branch is stacked on it, so the diff shows that commit too until it merges; this pull request then holds one commit. Refs #2274.

What / Why

The entry-block rule for a compute buffer load with a uniform address (#2446) covers one destination register. Compilers also load pairs and quads (buffer_load_format_xy v[2:3], buffer_load_dwordx4 v[8:11]) and read one component with v_readfirstlane_b32.

Change

Accept buffer_load_dwordx2/x3/x4 and buffer_load_format_xy/xyz/xyzw under the same conditions (compute, entry block, exec known, uniform address). Each destination register is marked uniform, but the range must have exactly the length the opcode writes (otherwise a register the load leaves alone could be marked). No recompute expression is recorded.

Tests

python -B tests/startup_gfx2hlsl_readfirstlane_uniform_check.py: 0 failed. Positives: x2 first/second word, x4 last word, overwriting a varying register, formatted xy. Negatives: x2 into three registers, x2 into one register, varying offset, a register outside the loaded range. All tests/startup_gfx2hlsl_*.py and tests/startup_translator_check.py: exit 0.

Measured (256 compute requests)

First refusal v_readfirstlane_b32: 115 before, 95 after (20 move on; next: s_pack_ll_b32 42, v_mul_hi_u32 35, src_scc in s_add_u32 14, buffer store without offen 12, formatted load descriptor words 10).

Limits (why there is no "past the entry block" PR)

The remaining readfirstlane refusals past the entry block are about ten different shapes (loads past a join, exec narrowed between a recompute chain's parts, loaded vectors in later blocks, image_load, per-lane values), none above 8 requests. The one general idea, accepting a copy of a uniform VGPR when exec is known past the entry block, flips three existing refusal tests in startup_gfx2hlsl_readfirstlane_recompute_check.py (scalar rewritten or reloaded between definition and read). I did not change those tests; it is a maintainer decision whether copy semantics make them obsolete. Not touched: SGPR proofs across joins (#2274).

🤖 Generated with Claude Code

NiiRoZz and others added 2 commits November 25, 2026 17:58
v_readfirstlane_b32 needs a vector source with the same value in every
active lane. A buffer_load_dword or buffer_load_format_x in a compute
program reads a read-only descriptor (a descriptor used for a load and a
store is already refused), so with a uniform VGPR index or offset, a
uniform scalar offset and exec known in the entry block, every lane reads
the same dword. Mark the destination uniform there. The value has no
recomputable expression, so reads past the entry block still refuse.

Tests: positive cases plus negative controls for a varying VGPR offset, a
varying scalar offset, a graphics stage, no stage kind, unknown exec, a
read after the entry block and a varying overwrite.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The entry-block rule for a compute buffer load with a uniform address
covered one destination register. Accept buffer_load_dwordx2/x3/x4 and
buffer_load_format_xy/xyz/xyzw too: every destination register of such a
load holds the same dword in every lane. The destination range must be
exactly as long as the opcode writes, so no register the load leaves alone
is marked uniform. None of them records a recomputable expression.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

@tedin7 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of head a485968 (comment only, no Windows run on my side; the PR body lists no Windows results, so nothing here covers any SHA on Windows).

Checked against origin/main:

  • Logic in tools/startup/gfx2hlsl.py (UNIFORM_LOAD_WORDS, the loaded gate, loaded_regs): the destination range must have exactly the length the opcode writes, tfe/lds style modifiers are rejected by the modifier whitelist, and the recompute expression is dropped for every loaded register. I found no correctness problem.
  • Scope is small and additive: 2 files, no launcher/CI/hook changes. No other open or merged PR covers multi-register loads.
  • Dependency: this branch is stacked on #2446, which is still OPEN. It should not merge before #2446. The diff against main includes that commit.

Commands run locally:

  • python3 -B tests/startup_gfx2hlsl_readfirstlane_uniform_check.py -> 0 failed
  • git diff --check origin/main...HEAD -> clean
  • python3 tests/docs_links_check.py and python3 tests/bidi_controls_check.py -> OK
  • Mutation 1: relaxed the exact-length check (== count to >= count) -> the test fails (good, it guards the length rule).
  • Mutation 2: changed the buffer_load_dwordx3 word count from 3 to 4 -> the test still passes.

Finding (P2, non-blocking): the x3 opcodes (buffer_load_dwordx3, buffer_load_format_xyz) have no test, so a wrong word count there goes unnoticed (mutation 2). Suggest one positive (v[2:4]) and one negative (x3 into two or four registers) case next to the existing x2/x4 ones.

AI-assisted; commands listed were executed locally.

@ChazY11

ChazY11 commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Six mutations: three caught, three survive — and one survivor is load-bearing against a translator crash

Baseline: Readfirstlane uniformity checks: 0 failed, whole startup_gfx2hlsl_* family green.

mutation of the uniform-load condition result
the descriptor/source must be uniform caught
the destination-range width check (candidate[2] - candidate[1] + 1 == count) caught
the word count for buffer_load_dwordx2 (2 → 3) caught
the modifier whitelist widened (any modifier accepted) survived
len(ops) == 4 dropped survived
self.tracks_uniformity() requirement dropped survived

The len(ops) == 4 survivor is load-bearing, and the failure is a crash

This one is not cosmetic. With the conjunct removed, a short operand list reaches the new condition and reads ops[3] before anything else refuses it:

baseline:  buffer_load_dword v1, off, s[0:3]   ->  refused: buffer load with 3 operands, expected 4
mutant:    buffer_load_dword v1, off, s[0:3]   ->  IndexError at gfx2hlsl.py:1956 in one
                                                       (ops[1] == 'off' or self.uniform_source(ops[1])) and self.uniform_source(ops[3]))

buffer_load_dword v1, off (two operands) crashes the same way. The existing operand-count refusal lives in buffer_address, which this condition is evaluated before, so today the conjunct is the only thing standing between a short list and translator crash in buffer_load_dword: IndexError — the exact marker the refusal census reads as a translator defect rather than as text the translator does not lower.

That makes it the one I would pin first, and it is one case: a three-operand buffer_load_dword in a compute program, asserting the refusal text and not an exception. Cheap, and it turns an unstated ordering dependency into a tested property.

The other two survivors

  • modifier whitelist widened: ('idxen', 'offen', 'glc', 'slc', 'dlc') plus offset: is what keeps tfe / lds / swizzle forms out. Widening it to accept anything is invisible to the fixture, so no case exercises a modifier outside that set.
  • tracks_uniformity() dropped: the whole proof is about tracking, so dropping the gate should be visible somewhere; it is not. Worth a case where uniformity tracking is off (a barrier or a non-entry block) and the load must not be treated as uniform.

Neither of these two changes an output I could observe, so I am reporting them as unexercised rather than as defects.

What the three caught rows establish

The width check catching x2 mis-sized to 3 words is the interesting one: it means the fixture distinguishes a load's word count from its destination range, rather than asserting the expression text loosely. The uniform-descriptor rule and the width rule are the two that decide whether a value is really lane-invariant, and both are pinned.

AI-assisted; the six mutations and the crash probe were run locally on Windows 11 build 26300.9974.

@tedin7

tedin7 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

Merged origin/main into this branch (no conflicts, no rebase, no force-push); main's arity_check is fixed (#2659) so the earlier block is gone. New head: a84a6c8.

Commands executed locally:

  • git merge origin/main (clean; CMakeLists.txt foreach/endforeach balanced 370/370)
  • python3 tests/startup_gfx2hlsl_readfirstlane_uniform_check.py (0 failed), tests/docs_links_check.py, tests/bidi_controls_check.py, git diff --check origin/main...HEAD: all ok
  • Win2025 WARP dev + release via x2w_pipe.py win2025 2454 --patch <merge delta> --wait 7200: build and Python checks PASS (exit 0)

AI-assisted; commands listed were executed locally.

@tedin7
tedin7 enabled auto-merge (squash) November 26, 2026 02:39
# Conflicts:
#	tests/startup_gfx2hlsl_readfirstlane_uniform_check.py
@tedin7

tedin7 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

Merged current main into this branch again (merge commit 54f08ec85, no rebase, no force push). The PR had gone back into conflict after the wave-index uniformity work landed.

  • The only conflict was in tests/startup_gfx2hlsl_readfirstlane_uniform_check.py: this PR's multi-register load cases and main's wave-index and thread-id-base cases were added at the same spot. Both blocks are kept, and each loop keeps its own check(... refused ...) line.
  • tools/startup/gfx2hlsl.py merged without conflicts.
  • Linux, on 54f08ec85: python3 tests/startup_gfx2hlsl_readfirstlane_uniform_check.py (0 failed), python3 tests/startup_gfx2hlsl_compute_check.py ok, python3 tests/docs_links_check.py ok, python3 tests/bidi_controls_check.py ok, git diff --check clean.
  • Win2025 dev + release on the content passed before this merge (receipt above).

Squash merge is queued for when this head's CI is green.

AI-assisted; commands listed were executed locally.

@tedin7
tedin7 merged commit aa16aae into R0Y00:main Nov 26, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants