Skip to content

Translator: v_dot4_i32_i8 refuses neg_lo/neg_hi, which RDNA2 hardware does not ignore (follow-up to SHADER-303) - #1913

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
aslan2142:shader-dot4-neg
Nov 22, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
aslan2142:shader-dot4-neg

Conversation

@aslan2142

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: finding + claim (follow-up to SHADER-303, #1754)

What and why

#1754 translated v_dot4_i32_i8 with a neg_lo or neg_hi field as the plain instruction. llvm-mc accepts those fields on it for gfx1036 (not on v_dot4c_i32_i8), and the hardware does not ignore them:

  • On S0 and S1, neg_lo flips bit 15 and neg_hi flips bit 31 of the dword.
  • On S2, neg_hi clears bit 31 and neg_lo then flips it.
  • That is what the fields do to float operands, applied to integer ones.

The change:

  • A set bit is now Unsupported, like clamp and op_sel. An all-zero field stays the plain instruction.
  • tests/semantic/test_alu_dot4_i8.py gets the measured table MEASURED_NEG and three tests.
  • The contract row "Signed-byte dot products" in docs/design.md says what was measured.

The other five integer dot products behave the same way on this hardware (words posted on #1808, whose rules already refuse these fields).

Tested

  • Hardware: gfx1036 (the integrated GPU of a Ryzen 9 7950X3D), raw kernels through tools/hw_oracle. 5 operand sets under 8 forms plus the plain one: 45 words, all as the model above predicts. Nine of them are MEASURED_NEG.
  • tests/semantic/test_alu_dot4_i8.py: 10 tests pass. The three new ones: the reference reproduces the measured words (7 of the 8 forms differ from the plain word), a set bit is refused, an all-zero field gives the plain result.
  • python -m unittest discover -s tests/semantic: 1,647 tests OK. python -I -m compileall -q make_game.py tools tests: OK.
  • Effect on real shaders: none today. No listing of the 29 FSPX programs carries either field on these two instructions (0 lines, counted on my own copy of 1.0.2.1), and the game's own shaders have neither instruction.
  • Not run: the GPU test suites and the other Python suites, since the change only adds a refusal.

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. The test's words were measured with my own kernels.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed (the row "Signed-byte dot products" is extended).

AI-assisted (Claude Code, Claude Fable 5.2 and Claude Opus 5.5).

…re does not ignore

The rule took v_dot4_i32_i8 with a neg_lo or neg_hi field as the plain instruction. llvm-mc accepts those
fields on it for gfx1036 (not on v_dot4c_i32_i8), and on RDNA2 hardware they change the result: neg_lo flips
bit 15 and neg_hi bit 31 of S0 or S1, and on S2 neg_hi clears bit 31 before neg_lo flips it, as the fields do
to float operands.

Measured on gfx1036 through tools/hw_oracle: 5 operand sets under 8 forms plus the plain one, 45 words, all as
that model predicts. Nine of them are the table MEASURED_NEG of tests/semantic/test_alu_dot4_i8.py.

A set bit is now Unsupported, like clamp and op_sel; an all-zero field stays the plain instruction. No listing
of the 29 FSPX programs carries either field on these two instructions (0 lines), so what translates there
does not change.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@Youssefrah16

Copy link
Copy Markdown

Tested 186d793b on AMD Radeon 680M (gfx1035, RDNA2, Windows 11 10.0.26300, driver 26.5.1 / amdhip64_6.dll): pass (AI-assisted).

  • python -I tests/semantic/test_alu_dot4_i8.py -v: 10/10 OK
  • Native gfx1035 hardware confirmation (tools/hw_oracle, wave32 & wave64) with v1=0x01020304, v2=0x05060708, v3=0:
    • plain v_dot4_i32_i8: 0x00000046
    • neg_lo:[1,0,0]: 0xfffffcc6
    • neg_hi:[1,0,0]: 0xfffffdc6
      (Identical across wave32 and wave64 — independently confirms RDNA2 hardware does not ignore neg_lo/neg_hi, so refusing non-zero neg_lo/neg_hi is the right fix.)

@Impre-visible

Copy link
Copy Markdown

Tested 186d793 on NVIDIA GeForce GTX 1660 (Turing, TU116, subgroup 32..32), driver 620.73.04 (proprietary, Vulkan 1.4.357), Arch Linux (kernel 6.18): pass, no regression.

Native build of runtime/ from this head (Ninja, RelWithDebInfo, clang 23.1.5), llvm-mc 23.1.5, SPIRV-Tools v2026.4.

  • spirv-val on the modules the PR's semantic tests translate (test_alu_dot4_i8.py): distinct modules: 13, pass spirv-val: 13, rejected: 0
  • tests/semantic: 1647 OK
  • build.py: 185 shaders, 185 translated, 185 pass spirv-val; check.py: 122 of 157 pass, 35 skipped (wave64 without emulation, mesh fixtures)
  • run_gpu_tests.py: 178 shaders: 178 translated, 178 pass spirv-val; 133/173 passed, 40 skipped, 0 failed
  • LEONIDA_W64_EMULATE=1 run_gpu_tests.py: 164/173 passed, 9 skipped (8 fixtures run by the d3d12 tests, 1 needs a 64-wide fragment subgroup), 0 failed

The PR adds no GPU fixture, so the refusal itself is covered only by the semantic tests here.

AI-assisted run (Claude). Synthetic programs only, no game files involved.

@Spaghetih

Copy link
Copy Markdown
Contributor

Corpus check on my own 1.0.2.1 package (26,503 shaders disassembled with llvm-mc 21, gfx1013), comparing this PR's head with its own base, not with today's main.

6a6704df vs 186d793b: no shipped shader uses v_dot4_i32_i8, so this PR changes no game shader's translation. Its new path is covered by its own tests only.

AI-assisted (Claude Code).

@sovljanskii

Copy link
Copy Markdown
Contributor

Tested 186d793 on macOS 27.2.1, Apple M4 (MoltenVK), LLVM 23.1.6, against its merge base 6a6704d, with my own 1.0.2.1 copy. Pass, nothing to change.

  • Tests: tests/semantic/test_alu_dot4_i8.py gives 10/10 OK. Negative control: the same file against the base tools/rdna2spirv.py fails 3 times, once for each subtest of test_a_set_neg_bit_is_refused. The other new tests pass on base too, as they should: the reference table, and the all-zero field. The full semantic suite passes 1,647 OK, and compileall is clean.
  • Corpus: none of the 26,503 game listings contains v_dot4_i32_i8 or v_dot4c_i32_i8, which matches your count. The reason is that llvm-mc 23.1.6 rejects both instructions for gfx1013, the listings' target ("instruction not supported on this GPU"), while it accepts both, and neg_lo on v_dot4_i32_i8, for gfx1030. Only the FSPX programs can carry them. Those listings aren't in my work folder, so I did not recount your 0 lines there.
  • Control slices (--wave64-emulate --mesh-compute --f16-interp-fallback):
    • --limit 200: 200/200 translated and 200/200 spirv-val-valid, on base and on the PR.
    • --shard 0/132 (201 shaders spread over the corpus): 197/197 on both, with the same 4 refusals.
    • Every .spvasm is byte-identical between base and PR.
  • Code: a field with any 1 is refused and an all-zero field goes through. op_sel_hi was already caught by the op_sel prefix test. Refusing is the safe choice while no listing carries these fields.

No game data. AI-assisted.

@snrubrm

snrubrm commented Nov 22, 2026

Copy link
Copy Markdown

Tested 186d793 on NVIDIA GeForce RTX 5070 Ti (Blackwell, subgroup 32..32), NVIDIA 621.01 (Vulkan 1.4.357), Windows 11 Pro 26300: pass, no regression.

VS 2022 Build Tools 17.14, Vulkan SDK 1.4.363.0 / SPIRV-Tools v2026.4, llvm-mc 21.1.8 (native, scripts\build_llvm_mc.ps1), Python 3.12.10. Harness programs built from main 6a6704d, this PR's base (it changes no C++). Run with LEONIDA_VK_DEVICE=5070.

  • python -I tests/semantic/test_alu_dot4_i8.py -v: 10/10 OK, including the three new neg tests.
  • python -m unittest discover -s tests/semantic: 1647 tests OK (2 skipped).
  • python -m compileall -q make_game.py tools tests: OK.
  • run_gpu_tests.py at this head: 178 shaders: 178 translated, 178 pass spirv-val; 133/173 passed, 40 skipped (wave64 on a 32-wide GPU), no failures. Identical to the same run on main 6a6704d on this machine.

No GPU test exercises the new refusal itself; this run only checks that the translator change doesn't disturb anything else on NVIDIA.

AI-assisted run (Claude Code).

@ItsNotRexed
ItsNotRexed merged commit a5e776f into ItsNotRexed:main Nov 22, 2026
10 of 11 checks passed
@aslan2142
aslan2142 deleted the shader-dot4-neg branch November 22, 2026 22:30
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.

7 participants