Repository navigation
gfx2hlsl: extend the uniform compute load proof to multi-register loads - #2454
Conversation
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
left a comment
There was a problem hiding this comment.
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, theloadedgate,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 failedgit diff --check origin/main...HEAD-> cleanpython3 tests/docs_links_check.pyandpython3 tests/bidi_controls_check.py-> OK- Mutation 1: relaxed the exact-length check (
== countto>= count) -> the test fails (good, it guards the length rule). - Mutation 2: changed the
buffer_load_dwordx3word 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.
Six mutations: three caught, three survive — and one survivor is load-bearing against a translator crashBaseline:
The
|
|
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:
AI-assisted; commands listed were executed locally. |
# Conflicts: # tests/startup_gfx2hlsl_readfirstlane_uniform_check.py
|
Merged current
Squash merge is queued for when this head's CI is green. AI-assisted; commands listed were executed locally. |
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 withv_readfirstlane_b32.Change
Accept
buffer_load_dwordx2/x3/x4andbuffer_load_format_xy/xyz/xyzwunder 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. Alltests/startup_gfx2hlsl_*.pyandtests/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