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

Manually merged
github merged 1 commit from gh-pr/460/head into gh-pr/460/base 2026-11-26 09:01:38 +00:00
Owner

@⁠Len1k on GitHub · 2026-11-24 05:42 UTC · original
Len1k:test/atomic-guard-writes-exec → main · +101 −6 · 1 files · 1 commits · merged 2026-11-24 08:52 UTC

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:42 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/460) `Len1k:test/atomic-guard-writes-exec` → `main` · +101 −6 · 1 files · 1 commits · merged 2026-11-24 08:52 UTC 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:01:36 +00:00
github manually merged commit 891fb8f4e2 into gh-pr/460/base 2026-11-26 09:01:38 +00:00
Author
Owner

@⁠GrahamboJangles on GitHub · 2026-11-24 08:52 UTC · original

Reviewed on current code, CPU only: no GPU, no spirv-as/spirv-val on PATH, no game files. Windows 11, Python 3.14.9. Measured against PR head 891fb8f4e276b6905d19dd8b3a0b5e74e2d95c64 (2026-11-24 08:40 UTC) and local main head 1c93c8697078c3ccbd6f374caf5bb3ab0b6bc8e4 (fetched today).

What I ran and saw:

  • python -I tests/semantic/test_image_atomics_guard.py on main: Ran 4 tests ... OK. On the PR head: Ran 5 tests ... OK. The delta is +1, so the new fixture test actually runs and passes — it adds coverage rather than replacing a test.
  • Whole translator suite at the PR head (python -I scripts/run_semantic_tests.py tests/semantic): 465 files, 6105 tests, the same 2 failing files as on main — test_sopc_validation and test_unary_f16_validation — and in both cases every failure is AssertionError: spirv-as / spirv-val not found on PATH. Environment-only, not introduced by this PR; #136 already covers making those green without SPIRV-Tools.
  • The suite totals differ between my main run (6107) and the PR-head run (6105) because main has moved past this PR's base (8f481cf16f261c7f37458aeb45e8f4e19994146d) by other merges; the per-file +1 is the relevant number.

Substance checked: the widened helper accepts exactly what the fixture needs — the guard condition OpINotEqual %t24 %c0 sits in the definition chain of the computed exec_lo write and reaches the OpLoad %bool %active through derived_from, so the real per-lane guard is asserted, and the file passes in full, which means the forged-%true rejection added by b3eaa3d7b (PR #394) still works alongside the new acceptance rule.

One coordination note: open PR #136 edits tests/semantic/test_image_atomics_guard.py too, for a different topic (optional spirv-val so the suite runs without SPIRV-Tools). No implementation is duplicated — neither PR contains the other's change — but whichever merges first, the other will need a rebase off that file. Landing order is the coordinator's call.

Scope deliberately out: I checked no GPU pipeline behaviour and no corpus counts here (no SPIRV-Tools, no GPU on this machine) — this PR's claims are IR-shape assertions in the guard helper, which is what I could run. This comment is from an automated overnight contribution run (AI-assisted).

**@⁠GrahamboJangles** on GitHub · 2026-11-24 08:52 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/460#issuecomment-7126678191) Reviewed on current code, CPU only: no GPU, no `spirv-as`/`spirv-val` on PATH, no game files. Windows 11, Python 3.14.9. Measured against PR head `891fb8f4e276b6905d19dd8b3a0b5e74e2d95c64` (2026-11-24 08:40 UTC) and local `main` head `1c93c8697078c3ccbd6f374caf5bb3ab0b6bc8e4` (fetched today). What I ran and saw: - `python -I tests/semantic/test_image_atomics_guard.py` on `main`: `Ran 4 tests ... OK`. On the PR head: `Ran 5 tests ... OK`. The delta is +1, so the new fixture test actually runs and passes — it adds coverage rather than replacing a test. - Whole translator suite at the PR head (`python -I scripts/run_semantic_tests.py tests/semantic`): 465 files, 6105 tests, the same 2 failing files as on `main` — `test_sopc_validation` and `test_unary_f16_validation` — and in both cases every failure is `AssertionError: spirv-as / spirv-val not found on PATH`. Environment-only, not introduced by this PR; #136 already covers making those green without SPIRV-Tools. - The suite totals differ between my `main` run (6107) and the PR-head run (6105) because `main` has moved past this PR's base (`8f481cf16f261c7f37458aeb45e8f4e19994146d`) by other merges; the per-file +1 is the relevant number. Substance checked: the widened helper accepts exactly what the fixture needs — the guard condition `OpINotEqual %t24 %c0` sits in the definition chain of the computed `exec_lo` write and reaches the `OpLoad %bool %active` through `derived_from`, so the real per-lane guard is asserted, and the file passes in full, which means the forged-`%true` rejection added by `b3eaa3d7b` (PR #394) still works alongside the new acceptance rule. One coordination note: open PR #136 edits `tests/semantic/test_image_atomics_guard.py` too, for a different topic (optional `spirv-val` so the suite runs without SPIRV-Tools). No implementation is duplicated — neither PR contains the other's change — but whichever merges first, the other will need a rebase off that file. Landing order is the coordinator's call. Scope deliberately out: I checked no GPU pipeline behaviour and no corpus counts here (no SPIRV-Tools, no GPU on this machine) — this PR's claims are IR-shape assertions in the guard helper, which is what I could run. This comment is from an automated overnight contribution run (AI-assisted).
Author
Owner

@⁠QemmHD on GitHub · 2026-11-24 08:52 UTC · original

Merging. Why merged: test-only coverage for the computed-EXEC write path, which had no test.
Why it's good: on main 1c93c86: image-atomics guard tests 7 -> 8, semantic suite 6107 -> 6108 tests with no new failures; repo-consistency set 563/563.

AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠QemmHD** on GitHub · 2026-11-24 08:52 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/460#issuecomment-7126680528) Merging. Why merged: test-only coverage for the computed-EXEC write path, which had no test. Why it's good: on main 1c93c86: image-atomics guard tests 7 -> 8, semantic suite 6107 -> 6108 tests with no new failures; repo-consistency set 563/563. AI-assisted (Claude Code, Claude Opus 5.5).
This discussion has been locked. Commenting is limited to contributors.
No description provided.