tests: cover the computed-EXEC write path #24 left without a test #448

Closed
github-bot wants to merge 1 commit from gh-pr/448/head into gh-pr/448/base
Owner

@⁠Len1k on GitHub · 2026-11-24 05:37 UTC · original
Len1k:test/atomic-guard-writes-exec → main · +142 −6 · 1 files · 1 commits · closed without merging

Claimed in the coordination issue as: TEST-ATOMIC-GUARD — see the note at the end, this turned out to be a follow-up rather than that item.

What this actually adds

b3eaa3d7b ("tests: image atomics guard keeps a dynamic EXEC case", 04:20 UTC) already restored the case @⁠Okamizs asked for in the coordination issue, so the folded-constant gap is closed on main before this PR. That commit's own comment names what it left out:

Both EXEC writes come from a per-lane compare (VCC), not from a computed SGPR value, which is SHADER-1264's path.

SHADER-1264 is fixed — #24, "a computed value written to EXEC sets the lanes of its bits" — and that PR changed tools/rdna2spirv.py and docs/design.md with no test. So the lowering #24 introduced is the one shape the guard suite cannot express today, and nothing would catch a regression in it.

This PR adds that case, and the helper change needed to write it.

Why the helper has to change

With a computed mask, the branch condition is a value derived from the load, not the load:

s_mov_b32 s4, 1
s_and_b32 exec_lo, exec_lo, s4
image_atomic_add v0, v[1:2], s[4:11] dmask:0x1 dim:SQ_RSRC_IMG_2D unorm

lowers to (trimmed):

%t6  = OpLoad %bool %active
%t5  = OpSelect %uint %t6 %cffffffff %c0
...
%t20 = OpSelect %uint %t21 %cffffffff %c0
%t4  = OpBitwiseAnd %uint %t5 %t20
%t23 = OpShiftRightLogical %uint %t4 %t22
%t24 = OpBitwiseAnd %uint %t23 %c1
%t34 = OpINotEqual %bool %t24 %c0
      OpStore %active %t34
      OpBranchConditional %t34 %t123_do %t124_end

%t34 is the lane's bit of the new mask, which is the correct guard, but find_guarded_texel_block accepted only ids produced by OpLoad %bool %active (plus the folded %true). Against main the new fixture fails with AssertionError: OpImageTexelPointer in unguarded block %t123_do.

Widening the helper to accept any condition would have been worse — a guard that never consults the lane mask would pass. Instead:

  • derived_from(spv, cond) walks the definition chain of a value and answers whether it reaches an OpLoad %bool %active. defs_of(spv) builds the id-to-operand map.
  • find_guarded_texel_block accepts a condition when it is the folded %true (still only for a module with no OpStore %active) or when derived_from reaches a load. Everything else is still rejected, so the forged-%true assertion b3eaa3d7b added keeps working.
  • texel_guard_condition(spv) returns the condition of the selection entering the block that holds the OpImageTexelPointer, so a test can assert on it.
  • test_a_shader_that_writes_exec_guards_on_the_load_not_the_folded_constant: the fixture above, asserting OpStore %active is present, the condition is not %true, derived_from(spv, condition) is true, derived_from(spv, "%true") is false, and the guarded block still holds OpAccessChain, OpImageTexelPointer and OpAtomicIAdd.

Verified

  • python -m unittest discover -s tests/semantic -p test_image_atomics_guard.py — Ran 5 tests ... OK (4 on main; the new one fails there with the assertion above).
  • python -I scripts/run_semantic_tests.py tests/semantic — 465 files, 6105 tests, 2 files failed in 485 s with 16 jobs: test_sopc_validation and test_unary_f16_validation, both AssertionError: spirv-as / spirv-val not found on PATH inside their own validate_spirv. This machine has no SPIR-V tools, so those two cannot run here; nothing else failed and test_image_atomics_guard passed inside that run.
  • python -I scripts/check_no_game_data.py tests/semantic/test_image_atomics_guard.py — exit 0.
  • One file, +101/−6, LF preserved.

No translator change, so the translated and spirv-val-valid counts are unchanged by construction. The fixture is hand-written; no game file was read and no GPU was involved.

Note on the coordination issue

TEST-ATOMIC-GUARD's reported gap was closed at 04:20 UTC, six minutes before the finding was posted at 04:26 — so the board entry is stale rather than pending. I have said so in the coordination issue; this PR should be read as "the computed-EXEC path #24 left without a test", not as that item.

Depends on: none. AI-assisted (OpenCode) on Windows 11, Python 3.12, RX 5700 XT (used for nothing here).

**@⁠Len1k** on GitHub · 2026-11-24 05:37 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/448) `Len1k:test/atomic-guard-writes-exec` → `main` · +142 −6 · 1 files · 1 commits · closed without merging Claimed in the coordination issue as: `TEST-ATOMIC-GUARD` — see the note at the end, this turned out to be a follow-up rather than that item. ## What this actually adds `b3eaa3d7b` ("tests: image atomics guard keeps a dynamic EXEC case", 04:20 UTC) already restored the case @⁠Okamizs asked for in the coordination issue, so the folded-constant gap is closed on `main` before this PR. That commit's own comment names what it left out: > Both EXEC writes come from a per-lane compare (VCC), not from a computed SGPR value, which is SHADER-1264's path. SHADER-1264 is fixed — #24, "a computed value written to EXEC sets the lanes of its bits" — and that PR changed `tools/rdna2spirv.py` and `docs/design.md` with **no test**. So the lowering #24 introduced is the one shape the guard suite cannot express today, and nothing would catch a regression in it. This PR adds that case, and the helper change needed to write it. ## Why the helper has to change With a computed mask, the branch condition is a value derived from the load, not the load: ```asm s_mov_b32 s4, 1 s_and_b32 exec_lo, exec_lo, s4 image_atomic_add v0, v[1:2], s[4:11] dmask:0x1 dim:SQ_RSRC_IMG_2D unorm ``` lowers to (trimmed): ```text %t6 = OpLoad %bool %active %t5 = OpSelect %uint %t6 %cffffffff %c0 ... %t20 = OpSelect %uint %t21 %cffffffff %c0 %t4 = OpBitwiseAnd %uint %t5 %t20 %t23 = OpShiftRightLogical %uint %t4 %t22 %t24 = OpBitwiseAnd %uint %t23 %c1 %t34 = OpINotEqual %bool %t24 %c0 OpStore %active %t34 OpBranchConditional %t34 %t123_do %t124_end ``` `%t34` is the lane's bit of the new mask, which is the correct guard, but `find_guarded_texel_block` accepted only ids produced by `OpLoad %bool %active` (plus the folded `%true`). Against `main` the new fixture fails with `AssertionError: OpImageTexelPointer in unguarded block %t123_do`. Widening the helper to accept any condition would have been worse — a guard that never consults the lane mask would pass. Instead: - `derived_from(spv, cond)` walks the definition chain of a value and answers whether it reaches an `OpLoad %bool %active`. `defs_of(spv)` builds the id-to-operand map. - `find_guarded_texel_block` accepts a condition when it is the folded `%true` (still only for a module with no `OpStore %active`) **or** when `derived_from` reaches a load. Everything else is still rejected, so the forged-`%true` assertion `b3eaa3d7b` added keeps working. - `texel_guard_condition(spv)` returns the condition of the selection entering the block that holds the `OpImageTexelPointer`, so a test can assert on it. - `test_a_shader_that_writes_exec_guards_on_the_load_not_the_folded_constant`: the fixture above, asserting `OpStore %active` is present, the condition is not `%true`, `derived_from(spv, condition)` is true, `derived_from(spv, "%true")` is false, and the guarded block still holds `OpAccessChain`, `OpImageTexelPointer` and `OpAtomicIAdd`. ## Verified - `python -m unittest discover -s tests/semantic -p test_image_atomics_guard.py` — `Ran 5 tests ... OK` (4 on `main`; the new one fails there with the assertion above). - `python -I scripts/run_semantic_tests.py tests/semantic` — 465 files, 6105 tests, 2 files failed in 485 s with 16 jobs: `test_sopc_validation` and `test_unary_f16_validation`, both `AssertionError: spirv-as / spirv-val not found on PATH` inside their own `validate_spirv`. This machine has no SPIR-V tools, so those two cannot run here; nothing else failed and `test_image_atomics_guard` passed inside that run. - `python -I scripts/check_no_game_data.py tests/semantic/test_image_atomics_guard.py` — exit 0. - One file, +101/−6, LF preserved. No translator change, so the translated and spirv-val-valid counts are unchanged by construction. The fixture is hand-written; no game file was read and no GPU was involved. ## Note on the coordination issue `TEST-ATOMIC-GUARD`'s reported gap was closed at 04:20 UTC, six minutes before the finding was posted at 04:26 — so the board entry is stale rather than pending. I have said so in the coordination issue; this PR should be read as "the computed-EXEC path #24 left without a test", not as that item. `Depends on:` none. AI-assisted (OpenCode) on Windows 11, Python 3.12, RX 5700 XT (used for nothing here).
`find_guarded_texel_block` accepted only an `OpLoad %bool %active` result as
the branch condition (or the folded `%true` for a shader that never writes
EXEC). After the folded-constant path was added, every case in the file left
EXEC untouched and took that path, so the assertion the file exists for - a
lane whose EXEC bit is off skips the image atomic - was not checked by
anything.

Widening the helper alone would have been wrong: a guard that never consulted
the lane mask would then pass. Instead the helper now walks the definition
chain of the branch condition and accepts it only when it reaches an
`OpLoad %bool %active`, which is the shape the translator actually emits for
an EXEC-writing shader. `s_and_b32 exec_lo, exec_lo, s4` becomes
`OpSelect`/`OpBitwiseAnd`/`OpShiftRightLogical`/`OpINotEqual` over the loaded
boolean and the branch tests the last comparison, so the condition is a value
computed from the load, not the load.

The new case writes EXEC (`s_mov_b32 s4, 1` + `s_and_b32 exec_lo, exec_lo, s4`)
before `image_atomic_add`, asserts the module really contains an
`OpStore %active`, and asserts the guard is not the folded constant and does
reach the load. A shader with an `OpStore %active` that branched on `%true`
would now fail.

No GPU, no game data, no translator change: the fixture is hand-written and the
file stays standard-library only.

Tested with `python -m unittest discover -s tests/semantic -p
test_image_atomics_guard.py` (5 tests, OK before and after the change; the new
test fails against the old helper with "OpImageTexelPointer in unguarded block
%t123_do", which is the gap reported in the coordination issue).

AI-assisted (OpenCode). Windows 11, Python 3.12, no GPU involved.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:00:44 +00:00
github-bot closed this pull request 2026-11-26 09:00:44 +00:00
Author
Owner

@⁠Len1k on GitHub · 2026-11-24 05:43 UTC · original

Closed and re-opened as #460: recreating the branch after fast-forwarding the fork broke this PR's state (state cannot be changed. The test/atomic-guard-writes-exec branch was force-pushed or recreated). #460 is the same change, one file, based on current main.

**@⁠Len1k** on GitHub · 2026-11-24 05:43 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/448#issuecomment-7123212643) Closed and re-opened as #460: recreating the branch after fast-forwarding the fork broke this PR's state (state cannot be changed. The test/atomic-guard-writes-exec branch was force-pushed or recreated). #460 is the same change, one file, based on current main.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.