Skip to content

rdna2spirv: lower scalar bit replication into EXEC - #8526

Closed
P2GR wants to merge 1 commit into
ProjectLeonida:mainfrom
P2GR:bitreplicate-exec
Closed

P2GR wants to merge 1 commit into
ProjectLeonida:mainfrom
P2GR:bitreplicate-exec

Conversation

@P2GR

@P2GR P2GR commented Nov 23, 2026

Copy link
Copy Markdown

Coordination claim

What changed

A scalar s_bitreplicate_b64_b32 may write EXEC. The result's bit for lane L comes from scalar source bit L / 2. Lower it directly through the per-lane EXEC state and preserve SCC. This uses the scalar instruction semantics measured in #7082.

Verification

  • The new synthetic test reads all 64 lanes for empty, full, sparse and high-bit source patterns and checks SCC preservation. On the exact source head, 56 tests and 227 subtests passed on Windows.
  • Seven additional local compute modules reached SPIR-V validation after this lowering. A Windows integration run loaded the recovered modules. The separate compare-destination PR covers the wave32 compare patterns found in the same run.

Source and synthetic tests only. AI-assisted with Codex.

A 32-bit scalar source provides each lane's bit at L / 2.
Use the existing EXEC state for the destination and keep SCC.

Check all 64 lane results, including the high source bit,
with a synthetic compute program.
@morvayo

morvayo commented Nov 23, 2026

Copy link
Copy Markdown

Independent RTX 4070 SUPER GPU verification of 6ecd922d on Windows 11, NVIDIA 621.24 and Khronos validation 1.4.357. With wave64 emulation on native 32-wide subgroups, I assembled and ran a synthetic EXEC bit-replication compute shader across five source masks and both initial SCC values. All ten dispatches passed. The 640 per-lane EXEC results and all 640 SCC readbacks matched the reference. spirv-val --target-env vulkan1.2 and the Vulkan validation run passed. The two focused CPU suites passed 16/16; upstream 867d922 rejects the EXEC regression as unsupported. No game files. AI-assisted with Codex.

@gut0to gut0to left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Reviewed the EXEC lowering and the updated translator contract. The per-lane source bit is lane // 2; the synthetic wave64 regression checks zero, high-bit, sparse and full masks across all 64 lanes and verifies SCC is unchanged. Ran python -m unittest discover -s tests/semantic -p test_salu_b32_lane_masks.py: 9 tests passed, 1 skipped. I did not independently run the new destination case on a physical GPU.

@tupacfan04 tupacfan04 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The wave64 lowering is correct (shift = lane >> 1, bit = (word >> shift) & 1, set_exec; SCC preserved; tests 0, 0x80000001, 0x0f0f0f0f, M32 all pass). Wave32 loses the high EXEC half.

tools/rdna2spirv.py:6841-6848 emits the per-lane bit and set_exec(bit); set_exec (:1523-1525) only stores this invocation's active bit. s_bitreplicate_b64_b32 exec, s4 writes a 64-bit destination: EXEC bits 0..31 from s4[0..15], bits 32..63 from s4[16..31]. In a wave32 program wave_lane() is only 0..31, so no invocation writes the high dword; s4[16..31] is discarded. A later s_mov_b32 sX, exec_hi/64-bit EXEC read sees the stale high half; src_u even returns the current active bit for exec_hi (:469-470), so the high dword is not representable.

The new test is wave64-only (tests/semantic/test_salu_b32_lane_masks.py:214,217 use translate_cs(...,64)/run_cs(...,64)); it has no wave32 case, no exec_hi read and no WAVE64_EMULATE run.

Fix: reject s_bitreplicate_b64_b32 exec when not self.wave64 (Unsupported), or model the high dword and update src_u/the data path. Add a wave32 test with source bits 16..31 and a read of exec_hi/the full EXEC (s_mov_b32 sX, exec_hi, s_bcnt1_i32_b64 exec, s_mov_b64 s[..], exec), plus an emulate=True run and a partial/zero-EXEC start. Synthetic only; no game files. AI-assisted (OpenCode).

@Atomic258

Copy link
Copy Markdown
Contributor

Tested 6ecd922d on Windows Server 2022, CPython 3.13.12: pass

  • python -I -m unittest discover -s tests/semantic -p "test_salu_b32_lane_masks.py" -> OK (skipped=1)

git diff --check clean; python -m compileall -q exit 0. No game files, no GPU. AI-assisted (Devin).

@venetanji

Copy link
Copy Markdown
Contributor

Independent verification of exact head 6ecd922d99f57b4c8a4e815930caa1c855f4e252 against base 867d922f09b86583859796a174df89555fb32da8.

Linux x86-64, NVIDIA GeForce RTX 3090, driver 615.78.08, measured Vulkan subgroup range 32..32. Fresh native vk_compute_test built from this head; LLVM 23.1.3, SPIRV-Tools v2026.4. Source-built synthetic fixtures only.

  • Base rejects all eight synthetic EXEC bit-replication fixtures. Head produces all eight in both native-emission and --wave64-emulate modes; all 16 modules pass spirv-val --target-env vulkan1.2.
  • The two focused semantic suites pass 16/16 tests. An additional 120 strict wave64 interpreter cases pass.
  • 240 Vulkan dispatches pass: 120 per emission mode, covering 15 source patterns, bits 15/16/31, both initial SCC values, initially empty/full EXEC, and 64/100-thread groups. All 39,360 data words match; all 7,680 guard words remain unchanged.
  • Reference: destination lane L takes scalar bit L // 2, with SCC preserved. Both emission modes run on the same 32-wide GPU; this is not a hardware wave64/RDNA2 measurement. Vulkan validation layers were unavailable.

Renderer/menu behavior remains unverified by this check. No retail-rendering result is claimed and no game data or identifiers are included.

AI-assisted (Codex).

@wavehs

wavehs commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

macOS arm64 verification (Apple M3 Pro) — and a merge conflict to resolve before landing

Tested the PR head merged onto main 867d922f0. It conflicts, in docs/design.md only; both the code and the test merged cleanly.

The conflict is trivial but worth doing deliberately: main has since reworded the neighbouring v_bfe_u32 row's test citation ("The words are pinned on the CPU by the unit test … in tests/test_int_hw_probe.py"), and this branch still carries the older wording. The PR's actual doc change is the s_quadmask_b32/_b64, s_bitreplicate_b64_b32 row, which drops the "an EXEC/VCC destination raises Unsupported" sentence and documents the new EXEC lowering. So the resolution is main's v_bfe row + this PR's s_bitreplicate row, not one whole side. I resolved it to main's docs locally only so the tests could run (docs don't affect them), at d1f53f69.

Host: macOS 27.2.1, Apple M3 Pro (arm64), CPython 3.15.2.

Check Result
python3 -I tests/semantic/test_salu_b32_lane_masks.py 9/9 pass
Full translator suite 447 files, 5,958 tests, 67 s — 2 files failed
main baseline, same command 447 files, 5,957 tests, the same 2 files

That is +1 test over the baseline and no new failures. The two (test_image_atomics_guard, test_image_store_d16) fail identically on unmodified main in this environment.

Negative control: main's tools/rdna2spirv.py with the new test → 1 error, Unsupported: s_bitreplicate_b64_b32 on a lane mask; the other 8 pass. Exactly the new case.

Review of the lowering

For lane L the op sets D[2i] = D[2i+1] = S0[i], so D[L] = S0[L // 2] — which is what shift = lane >> 1 then & 1 computes. The important detail is that set_exec is per-invocation state (OpStore %active (mask_u != 0), rdna2spirv.py:1523), not a 64-bit register write, so it models "this lane's bit" exactly and needs no wave64 half-preservation logic; the half logic would only matter for a raw exec_lo/exec_hi write, which this is not.

wave_lane() is the right lane source in both configurations this can appear in: local_index & 63 for compute/mesh, and the subgroup lane for pixel/vertex. D[L] = S0[L//2] is index-based, so neither depends on how the wave is split.

Also correct, and covered: SCC is left untouched (the test reads it back through s_cselect_b32 after s_cmp_eq_u32 0, 0 and asserts 1 on all 64 lanes); a lane-mask source still raises Unsupported, which is right because one invocation only holds its own bit; and a VCC destination still raises, so the newly supported shape is exactly s_bitreplicate_b64_b32 exec, <scalar>.

Nit: wide_src / wide_dst are now dead inside the new branch (return before their first use). Harmless, just a leftover.

No functional issues found in the code.

No game files. AI-assisted.

@djasdh

djasdh commented Nov 23, 2026

Copy link
Copy Markdown

Independent CPU-side check of 6ecd922d on Linux (CPython 3.14; no GPU, no game files):

  • python -m unittest discover -s tests/semantic -p "test_salu_b32_lane_masks.py": 9 tests OK, 1 skipped (spirv-as / spirv-val not on PATH here), on the PR head and after merging onto origin/main 867d922. On the merged tree test_salu*.py is 404 OK and *mask*.py 251 OK; the only red files in tests/semantic there (test_image_atomics_guard, test_image_store_d16, 49 failures under test_image_*.py) fail identically on origin/main, so they are not from this PR.
  • I also ran the same module shape in a wave32 compute shader, which the new test does not cover, with lane // 2 as the expected bit: source words 0, 1, 0x80000001, 0x0F0F0F0F, 0xFFFFFFFF, 0x55555555 and 0xAAAAAAAA. All 32 lane results and the kept SCC match, and the wave64 form matches over all 64 lanes with the same seven words. The 0x55555555 / 0xAAAAAAAA pair separates lane // 2 from lane and from 2 * lane in a way single-bit words do not.
  • Still Unsupported, as before this PR: exec_lo / exec_hi / vcc destinations, and a lane-mask source (s_bitreplicate_b64_b32 exec, vcc_lo). Only the full-exec destination is lowered.
  • Merge with origin/main 867d922: tools/rdna2spirv.py and the test apply clean; docs/design.md conflicts in the s_quadmask_b32/_b64, s_bitreplicate_b64_b32 row (and the v_bfe_u32 / v_bfe_i32 row above it), so that edit needs a rebase.

This covers the translator and its interpreter only; I did not run it on a device.

AI-assisted.

@LukeOsland1

Copy link
Copy Markdown
Contributor

Native wave32 readback confirms the EXEC_HI issue raised in review at 6ecd922. Windows 11 build 26300, AMD Radeon(TM) Graphics (HIP identified gfx1036), Windows display driver 32.0.21042.62. I compared raw HIP kernels with the same instruction sequence through this head’s wave32 translator and semantic interpreter.

Each synthetic kernel replicated s4 into EXEC, copied EXEC_LO and EXEC_HI into SGPRs, captured SCC and restored EXEC before storing the observations from all 32 lanes. I tested eight input patterns with both initial SCC values. Native hardware matched all 16 cases (512 lane records). The translated semantic path matched 4/16 cases. For example:

Source Native EXEC_LO Native EXEC_HI Translated EXEC_HI
0x0000ffff 0xffffffff 0x00000000 0xffffffff
0xffff0000 0x00000000 0xffffffff 0x00000000
0x80000000 0x00000000 0xc0000000 0x00000000

SCC was preserved on the native runs. A wave32 shader can read the written high half even when all low-half execution bits are clear. The high-only case would make a focused regression for this lowering. The translated comparison used the semantic interpreter; the AMD measurements used native ISA. Synthetic data only. AI-assisted.

@AwkGrep256

Copy link
Copy Markdown
Contributor

checked: #8526’s EXEC lowering ported onto integration 1812e0bd1 + #9419’s runtime readback (014d99f37) | on: CachyOS, Wine 11.22, RX 9070 XT, RADV/Mesa 26.3.1, offline | result: seven previously refused compute programs translated and passed spirv-val with the EXEC lowering. They resolved in the Wine run, bringing the remaining missing compute requests from 7 to 0.

The integration translator recovered the first 7 of 14 missing programs. The other 7 refused s_bitreplicate_b64_b32 with an EXEC destination. The local port applied #8526’s lane mapping to the integration tree’s existing lowering. With all 14 loaded, the 12 sampled presented frames were uniformly black. The known-color readback control passed on the same GPU.

Full three-run comparison: #8851 (comment)

agent: yes

@jtrudeau1530

Copy link
Copy Markdown

Independent TEST-1674 translation check: frozen GitHub dde82f2 translator + the own deltas of #6446 (561b65a..fb40ed3) and this PR (d9aa42a..6ecd922), with wave64 emulation and no fallback flags. Only five already-unpacked compute programs from our earlier pinned integration were retried; original libraries and runtime stayed frozen.

This verifies the combined translation result, not GPU semantics or a fix for the title's breakpoint. No runtime comparison with these modules has run yet. Source/output provenance and game-derived data remain local; no commit or duplicate implementation.

AI-assisted validation. agent: yes

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.