Skip to content

vk_compute_test: seed s4.. from VKC_SGPRS, so a compute test can take an input word - #398

Merged
ItsNotRexed merged 2 commits into
ProjectLeonida:mainfrom
troythedecoyx:feat/vkc-seed-user-sgprs
Nov 22, 2026
Merged

ItsNotRexed merged 2 commits into
ProjectLeonida:mainfrom
troythedecoyx:feat/vkc-seed-user-sgprs

Conversation

@troythedecoyx

@troythedecoyx troythedecoyx commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

What and why

vk_compute_test always puts the output V# in s[0:3] and zero in every other user SGPR, so a compute test shader can't be given an input word. #300's cs_cvt_f32_sat reads its float from s4, so on a GPU it could only be checked by building one shader variant per input by hand (@EchoTD did 16 on #300; @NWX10 and I noted the gap there too).

  • VKC_SGPRS=w4,w5,... sets s4, s5, ... up to s31; s[0:3] stay the output V#. Same syntax and checks as vk_harness's VKH_SGPRS: decimal or 0x hex, no sign, nothing above 32 bits, no trailing comma, at most 28 words; anything else exits 2 with a message. Unset, everything is as before.
  • cs_user_sgprs.asm declares eight user SGPRs (RSRC2 0x8090) and stores s4..s7 back. Both runners seed it with 0x4f000000,0xdeadbeef,7,0xffffffff (check.USER_SGPRS) and expect those words, then the 0xEEEEEEEE fill.
  • check.compute_test() takes an env for vk_compute_test.
  • tests/test_shader_checks.py: the fake harness only answers cs_user_sgprs with the seeded words when VKC_SGPRS was passed, and no other test may get VKC_SGPRS.

With this, #300 (or a follow-up) can run cs_cvt_f32_sat with VKC_SGPRS=<input> once per input from test_float_to_int.py. Doesn't touch #368's VKC_OUT_WORDS/VKC_DUMP (different lines of the same file).

Item: TEST-43 (claimed in #374).

Tested

NVIDIA GeForce RTX 4060 Ti (Ada, subgroup 32..32), driver 32.0.16.2124, Windows 11 Home 26300, on main d937b7f; LLVM 21.1.8 (WSL), Vulkan SDK 1.4.363, MSVC 2022.

  • run_gpu_tests.py: cs_user_sgprs PASS (0x4f000000 0xdeadbeef 0x7 0xffffffff, then the fill), natively and with LEONIDA_W64_EMULATE=1. Whole suite: 62/62 translated and spirv-val valid; 35/59 passed, 24 skipped natively; 59/59 emulated; none failed. Every other test's PASS/SKIP is identical to main d937b7f.
  • build.py + check.py: cs_user_sgprs ok.
  • vk_compute_test directly: unset → s4..s7 read 0; 5 sets s4 only; 28 words (s4..s31) accepted; 1,2,, -1, 0x1ffffffff, abc and 29 words exit 2 with the message.
  • tests/test_shader_checks.py 15/15; it fails (7) if check.py stops passing VKC_SGPRS. ctest 18/18, tests/test_*.py all pass, tests/semantic 440 OK.

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (No translator change.)

AI-assisted (Claude Code); I ran the tests above.

🤖 Generated with Claude Code

@troythedecoyx

Copy link
Copy Markdown
Contributor Author

What this is for, run on the same RTX 4060 Ti: #300's cs_cvt_f32_sat (now on main) with VKC_SGPRS=<input> for each of the 16 inputs in tests/semantic/test_float_to_int.py, built with build.py and run as vk_compute_test cs_cvt_f32_sat.spv 1 dump:

16/16 exact (u32 in out[0], i32 in out[1]), including ±0, a subnormal, ±1.5, the largest binary32 below 2^31 and 2^32, ±2^31, 2^32, ±infinity and two NaNs. No shader variants needed.

Wiring that sweep into check.py/run_gpu_tests.py would be a small follow-up on top of this PR; happy to do it if wanted.

AI-assisted.

@FreddyxS

Copy link
Copy Markdown
Contributor

Independently checked b306d8e3b095beb7df0580023d15633a65db90a7 on Windows with Python 3.13.13 and MSVC 2022. All 15 tests in test_shader_checks.py passed. I compiled the PR’s parse_user_sgprs function in a standalone C++ test: a full 28-word list stopped at s31, s0..s3 and the next push-constant word stayed intact, decimal and hex values parsed correctly, and the parser rejected 29 words, overflow, whitespace, signs, empty elements and a trailing comma. This was CPU-only; no Vulkan dispatch was run here.

AI-assisted (Codex).

@troythedecoyx

troythedecoyx commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor Author

Rebased onto main 4abd545 (conflicts were only neighbouring names in run_gpu_tests.py's import and the TOTAL count in test_shader_checks.py; both sides kept) and pushed a second commit: both runners now run #300's cs_cvt_f32_sat once per input of tests/semantic/test_float_to_int.py through VKC_SGPRS, judged on both words (check.CVT_F32_SAT_CASES).

RTX 4060 Ti at b5b48be: cs_cvt_f32_sat 16/16 inputs exact and cs_user_sgprs PASS, natively and emulated; whole suite 70/70 translated and valid, 42/68 passed (26 skips) natively, 68/68 emulated, none failed; ctest 19/19, tests/semantic 462 OK, tests/test_shader_checks.py all pass, including checks that every input is sent, one wrong input fails and is named, and the table equals the interpreter test's CASES.

One caveat, also in the commit message: on NVIDIA this can't catch the bug #300 fixed. With the translator from before #300 (273e53c^1) this card also gives 16/16, because SPIR-V leaves an out-of-range conversion undefined and this hardware saturates anyway. It can fail on a driver that doesn't (like @EchoTD's RADV constant-input case); test_float_to_int.py pins the rule itself.

AI-assisted.

@Aminecsmc

Copy link
Copy Markdown
Contributor

Tested b306d8e on NVIDIA GeForce RTX 3050 Laptop GPU (Ampere, subgroup 32), driver 610.91, Windows 11 build 26300, MSVC 14.44, Vulkan SDK 1.4.363: pass. AI-assisted (Claude Code).

  • Built the runtime from this head. ctest: 18/18.
  • run_gpu_tests.py: 62/62 translated, 62/62 pass spirv-val. 35/59 pass, 24 skipped (wave64), 0 fail. cs_user_sgprs PASS: 0x4f000000 0xdeadbeef 0x7 0xffffffff 0xeeeeeeee ×4.
  • Real use: this is what Translator: saturate RDNA2 float-to-int conversions #300 needed. I built main's cs_cvt_f32_sat and ran all 16 inputs from test_float_to_int.py's CASES as VKC_SGPRS=<bits> vk_compute_test cs_cvt_f32_sat.spv 1 dump, one input per run. 16/16 exact (u32 and i32 words), with no edited copies of the shader. Earlier I had to prepend s_mov_b32 s4, ... to scratch copies to do this.
  • unittest discover -s tests/semantic: 440 OK.
  • Note: it conflicts with main as of 4abd545 (scripts/run_gpu_tests.py, tests/test_shader_checks.py).

@troythedecoyx
troythedecoyx force-pushed the feat/vkc-seed-user-sgprs branch from b306d8e to b5b48be Compare November 22, 2026 00:00
@troythedecoyx

Copy link
Copy Markdown
Contributor Author

Thanks @FreddyxS and @Aminecsmc. The conflict with 4abd545 is gone: the branch is rebased onto it (b5b48be), and the second commit wires your 16-input sweep into both runners (cs_cvt_f32_sat, "16/16 inputs exact"), so it no longer needs running by hand.

AI-assisted.

@tylerstraub

Copy link
Copy Markdown
Contributor

Tested b5b48be1f2e14e9d46ca4e960f5ba3b7506047dd on NVIDIA GeForce RTX 5090, 595.99.02 (Linux).

Verified the integrated conversion sweep and register seeding on Ubuntu 26.04.1 LTS. I built the unmodified Vulkan harness from this head and ran the two filters from separate empty work directories. Both shaders translated and passed SPIR-V validation. The runner reported exact signed and unsigned results for all 16 inputs to cs_cvt_f32_sat. The cs_user_sgprs dispatch returned all four configured words.

I also dispatched the same cs_user_sgprs module three times, varying only VKC_SGPRS. With it unset, s4–s7 read back as four zeros. With 0xcafebabe they read back as cafebabe 0 0 0. With 0xcafebabe,1,2,3 they read back as cafebabe 1 2 3. The four adjacent output words retained their eeeeeeee sentinel on every dispatch.

Coverage was limited to these two synthetic compute fixtures through the filtered runner and the direct register readbacks.

AI-assisted verification.

@troythedecoyx
troythedecoyx force-pushed the feat/vkc-seed-user-sgprs branch from b5b48be to c72bb72 Compare November 22, 2026 00:41
@troythedecoyx

troythedecoyx commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Rebased onto main 91b36cf (c72bb72), now mergeable. The conflicts were only #421's GLOBAL_OFFSET landing next to USER_SGPRS in check.py and run_gpu_tests.py, and the TOTAL count in test_shader_checks.py; both sides kept.

RTX 4060 Ti, against a baseline run of main 91b36cf on the same machine: cs_user_sgprs PASS and cs_cvt_f32_sat 16/16 inputs exact, natively and emulated; every other test's PASS/SKIP is identical to main (47/73 passed, 26 skipped natively; 73/73 emulated). ctest 23/23.

For the record, main 91b36cf itself fails three tests here (and in its own CI run): test_mem_diff and test_alu_shift_b64 both get bit 22 set on a signalling-NaN-shaped word, the interpreter issue #509/#533/#543 fix, and test_swizzle_search's test_preview_with_no_fitting_layout_reports_the_problem needs numpy, which the other 17 tests in that file skip without. Same three on this branch, none from it.

CI on c72bb72 matches: the failing semantic-tests (ubuntu-latest) and Runtime / linux-gpu-tools jobs fail the same way on main 91b36cf (the NaN-bit tests above; cs_w32_lane_wrap and cs_wqm_w32 on llvmpipe). On llvmpipe this PR's cs_user_sgprs passes and cs_cvt_f32_sat is 16/16 exact.

AI-assisted.

@troythedecoyx
troythedecoyx force-pushed the feat/vkc-seed-user-sgprs branch from c72bb72 to f9e6c98 Compare November 22, 2026 01:11
@troythedecoyx

Copy link
Copy Markdown
Contributor Author

Rebased onto the merge round's main 22590c7 (f9e6c98), mergeable, as asked. The only conflicts were #296's mip-zero names next to USER_SGPRS in run_gpu_tests.py's import and the TOTAL count in test_shader_checks.py; both sides kept.

RTX 4060 Ti, against a baseline run of main 22590c7 on the same machine: cs_user_sgprs PASS and cs_cvt_f32_sat 16/16 inputs exact, natively and emulated; every other test's PASS/SKIP is identical to main (59/85 passed, 26 skipped natively; 85/85 emulated); ctest 24/24, tests/test_*.py all pass, tests/semantic 783 OK. The three main failures noted above are gone with this round.

AI-assisted.

troythedecoyx and others added 2 commits November 21, 2026 19:22
… an input word

vk_compute_test always put the output V# in s[0:3] and zero in every
other user SGPR, so a compute test shader could not be given an input
word: ProjectLeonida#300's cs_cvt_f32_sat reads its float from s4 and could only be
checked on a GPU by building one shader variant per input by hand.

- VKC_SGPRS=w4,w5,... sets s4, s5, ... up to s31 (s[0:3] stay the output
  V#), with the same syntax and checks as vk_harness's VKH_SGPRS: decimal
  or 0x hex, no sign, nothing above 32 bits, no trailing comma, at most
  28 words; anything else exits 2 with a message.
- cs_user_sgprs.asm declares eight user SGPRs (RSRC2 0x8090) and stores
  s4..s7 back. Both runners seed it with 0x4f000000,0xdeadbeef,7,
  0xffffffff (check.USER_SGPRS) and expect those words, then the
  0xEEEEEEEE fill.
- check.compute_test() takes an env for vk_compute_test.
- tests/test_shader_checks.py: the fake harness only answers
  cs_user_sgprs with the seeded words when VKC_SGPRS was passed, and no
  other test may get VKC_SGPRS.

AI-assisted (Claude Code). Tested on NVIDIA GeForce RTX 4060 Ti (Ada,
subgroup 32), driver 32.0.16.2124, Windows 11, on main d937b7f:
- run_gpu_tests.py cs_user_sgprs PASS natively and with
  LEONIDA_W64_EMULATE=1; check.py cs_user_sgprs ok
- vk_compute_test directly: unset -> s4..s7 read 0; "5" sets s4 only;
  28 words accepted; "1,2,", "-1", "0x1ffffffff", "abc" and 29 words
  exit 2
- test_shader_checks.py fails (7) if check.py stops passing VKC_SGPRS
- full suite: see the PR

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ough VKC_SGPRS

cs_cvt_f32_sat (ProjectLeonida#300) takes its binary32 input in s4, so neither runner
ran it. Now both do: one dispatch per input of
tests/semantic/test_float_to_int.py (check.CVT_F32_SAT_CASES), each
judged on both words (v_cvt_u32_f32 in out[0], v_cvt_i32_f32 in out[1]).

- check.cvt_f32_sat_test() and the run_gpu_tests.py branch report
  "16/16 inputs exact", or how many were wrong and the first one.
- tests/test_shader_checks.py: the fake device answers from the word in
  VKC_SGPRS; every input must be sent, one wrong input must fail and be
  named, and the table must equal the interpreter test's CASES.

On NVIDIA this checks the fixed translation, but it cannot catch the old
bug: with the translator from before ProjectLeonida#300 (273e53c^1) the RTX 4060 Ti
also gives 16/16, since SPIR-V leaves an out-of-range conversion
undefined and this hardware saturates anyway. A driver that does not
(@EchoTD's RADV case on ProjectLeonida#300, constant inputs) is where it can fail;
tests/semantic/test_float_to_int.py pins the rule itself.

AI-assisted (Claude Code). Tested on NVIDIA GeForce RTX 4060 Ti (Ada,
subgroup 32), driver 32.0.16.2124, Windows 11, on main d937b7f:
run_gpu_tests.py cs_cvt_f32_sat "16/16 inputs exact" natively and with
LEONIDA_W64_EMULATE=1; check.py cs_cvt_f32_sat ok;
tests/test_shader_checks.py 18/18.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@troythedecoyx

Copy link
Copy Markdown
Contributor Author

Rebased onto c432cdc (b928011), mergeable. The one real merge was check.compute_test(): main added needs_32_lanes where this PR adds env, so it now takes both (the env is passed to vk_compute_test, then the 32-lane skip applies as on main). The rest were neighbouring names in run_gpu_tests.py's import and the TOTAL count.

RTX 4060 Ti at b928011: cs_user_sgprs PASS and cs_cvt_f32_sat 16/16 inputs exact, natively and emulated; run_gpu_tests.py 89/89 translated and valid, 61/87 passed (26 wave64 skips) natively, 87/87 emulated, none failed; ctest 27/27, tests/test_*.py all pass (including test_shader_checks.py), tests/semantic 805 OK.

AI-assisted.

@ItsNotRexed
ItsNotRexed merged commit b95f0f8 into ProjectLeonida:main Nov 22, 2026
9 checks passed
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.

5 participants