Skip to content

GPU test for the S# and T# mip fields (vulkan_sampler, T# view range) - #319

Merged
ItsNotRexed merged 3 commits into
ItsNotRexed:mainfrom
Vonsek:test/ssharp-mip-fields
Nov 22, 2026
Merged

ItsNotRexed merged 3 commits into
ItsNotRexed:mainfrom
Vonsek:test/ssharp-mip-fields

Conversation

@Vonsek

@Vonsek Vonsek commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Requested by Lucas · project thread

Claimed in #156 as: GPU test of the decoded S# and T# mip fields

What and why

#230 added vulkan_sampler() and the T# decode, but they are only checked on the CPU. vk_texture_test and vk_bindless_test both bind a fixed nearest VkSampler and one-level views, so MIP_FILTER, MIN_LOD, MAX_LOD, LOD_BIAS and BASE_LEVEL never reach a GPU.

  • runtime/test/vk_sampler_test.cpp (new): a 128x128 RGBA8 texture with two levels. Level 0 is red, green, blue and yellow quadrants; level 1 is grey (128/255). The T# is encode()d with the BASE_LEVEL/LAST_LEVEL given, and the S# words come from the command line. Both go into the heap and the hash table. The sampler is vulkan_sampler(decode(S#)) and the view's levels come from decode(T#).
  • runtime/test/shaders/ps_ssharp.asm (new): loads the T# and S# from the heap, then exports (lz.r, lz.g, implicit.r, implicit.g). vs_ids runs UV 0..1 over the 64x64 target, so image_sample sees LOD 1 and image_sample_lz LOD 0.
  • check.py: SAMPLER_CASES lists eight S#/T# pairs, with the S# words written in Python from Mesa's field positions. Each pixel is judged against the level sampler_level() works out from those bits, not from the C++ header. Grey differs from every level-0 colour in both channels, so a wrong level fails at every pixel. run_gpu_tests.py runs the same check.
  • docs/d3d12_vulkan.md: the test's paragraph, and what it does not cover.
Case Explicit LOD 0 Implicit LOD 1
point mip filter level 0 level 1
point, MAX_LOD 0 0 0
point, MIN_LOD 1 1 1
point, LOD_BIAS +1 1 1
point, LOD_BIAS −1 0 0
MIP_FILTER_NONE 0 0
MIP_FILTER_NONE, MIN_LOD 1 0 0
point, T# BASE_LEVEL 1 1 1

No translator or runtime change was needed: every case matched on the first run.

Tested

NVIDIA GeForce RTX 5080, driver 616.92 (device reports Vulkan 1.4.351), Windows 11 26200, MSVC 2022, Vulkan-Headers 1.4.363, SPIRV-Tools v2026.4, llvm-mc 21.1.8, on e444c83 (main 83d0637 + this commit).

Check Result
scripts/run_gpu_tests.py (LEONIDA_W64_EMULATE=1) 54 translated, 54 pass spirv-val; 51/52 passed, 1 skipped (ps_vcc_x2, as on main)
runtime/test/shaders/check.py 47 of 47 pass
ps_ssharp 8 cases, 4096 pixels each exact
ctest 14/14
python -m pytest tests -q --ignore=tests/semantic 1118 passed, 10 skipped, 1 xfailed
python -m unittest discover -s tests/semantic 423 OK
python -I tests/test_*.py (stdlib ones, as CI runs them) all pass

Negative controls. Each was a one-line edit, rebuilt or re-translated, run on the GPU, then reverted. All nine failed at the predicted pixel:

Mutation First failing case and pixel
vulkan_sampler: no [0, 0.25] LOD clamp for MIP_FILTER_NONE none (0,0): implicit grey instead of red
vulkan_sampler: minLod = 0 point min_lod 1 (0,0)
vulkan_sampler: mipLodBias = 0 point bias +1 (0,0)
vulkan_sampler: maxLod = VK_LOD_CLAMP_NONE point max_lod 0 (0,0)
decode(S#): MIN_LOD and MAX_LOD fields swapped point (0,0)
decode(S#): MIP_FILTER read one bit too high point (0,0)
decode(T#): BASE_LEVEL ignored point base 1 (0,0)
translator: image_sample_lz as ImplicitLod point (0,0)
translator: 2D coordinates swapped point (32,0), as predicted

tests/test_shader_checks.py gets four CPU tests: hand-worked levels for every case, the S# words against Mesa's positions, a wrong value in each channel of the last pixel, and a wrong level or swapped UV failing at the predicted first pixel.

Not covered. On Vulkan the sampler's minLod and mipLodBias also apply to an explicit LOD. That the console's image_sample_lz and _l behave the same way rests on radv, which writes those Vulkan fields straight into the S#. It was not measured on RDNA2 here: I have no AMD card. The T#'s MIN_LOD (ResourceMinLODClamp) is not mapped to the view yet. Linear mip filtering, anisotropy and fractional LODs are not tested. Results are from one GPU and driver.

Overlaps: check.py, run_gpu_tests.py and tests/test_shader_checks.py are also touched by #269 and #296, in different hunks. I'll rebase whichever lands later.

AI-assisted.

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • No new translator rule (the test exercises the existing descriptor mapping).

vk_sampler_test binds a 128x128 two-level texture with the VkSampler from
vulkan_sampler(decode(S#)) and the view range from decode(T#). ps_ssharp
samples it with image_sample_lz and image_sample. check.py judges eight
S#/T# cases per pixel against levels worked out from the S# and T# bits.

AI-assisted (Claude Code).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Vonsek
Vonsek marked this pull request as ready for review November 21, 2026 22:54
@Vonsek

Vonsek commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

Two additional controls from a separate detached build of e444c83335ea6f3cabf68539c2f6d63d39d0a868 on the same RTX 5080 / 616.92:

  1. T# LAST_LEVEL versus the sampler clamp. I set both sampler LOD limits to 1 with S# words 92 100100 4000000 0. With T# levels 0 0, both samples returned the level-0 quadrants at all 4,096 pixels. Changing only LAST_LEVEL to 1 gave grey on both samples. To test coverage, I built a scratch copy of the harness with the view count set to levels - view_of.first_mip, so it always exposes every remaining physical mip. All eight existing cases still passed on this mutation. The 0 0 case rejected it on 4,096/4,096 pixels, in all four channels, starting at (0,0): grey in every channel instead of (1,0,1,0). This input would cover the decoded LAST_LEVEL independently of BASE_LEVEL.
  2. Non-finite readback. On the unmodified renderer's passing readback, replacing only the last output channel at (63,63) with a quiet NaN left sampler_mismatch returning success. A synthetic all-NaN buffer also passed. Testing not math.isfinite(g) before the tolerance comparison would catch both cases.

The ordinary eight-case GPU run and four SamplerMipChecks passed on this head. The detached build used parent 83d0637 and required no code from #296. The shared runner and test registration files are the integration overlap. AI-assisted follow-up testing.

@EchoTD

EchoTD commented Nov 21, 2026 •

Copy link
Copy Markdown

Tested e444c83 on AMD Radeon RX 6800 (RDNA2, RADV NAVI21, Mesa 26.2.5, Vulkan 1.4.354), Linux kernel 7.2.15: pass

  • Toolchain: llvm-mc 23.1.3, GCC 16.2.1, subgroup 32..64.
  • Build: OK (vk_sampler_test built).
  • run_gpu_tests.py: ps_ssharp PASS (8 S#/T# cases, 4096 pixels each exact). 51/52 passed, 1 skipped (ps_vcc_x2, needs the seeded V# memory of tests/semantic).
  • Note: with a relative --build, ps_texture_sample fails with "missing runtime/build/linux/vk_texture_test". The branch predates run_gpu_tests: ps_texture_sample with a relative --build or a --filter #290's abspath fix, so a rebase on main should clear that and the conflict.

AI-assisted: the test runs and this comment were done with Claude Code; I reviewed the results.

@tylerstraub

Copy link
Copy Markdown
Contributor

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

I ran the focused ps_ssharp Vulkan test with the sampler harness built from this PR head. Both shaders translated and passed spirv-val. All eight sampler and texture-view descriptor cases passed, with all 4,096 pixels exact in each case (32,768 pixel comparisons).

This verifies the translated Vulkan mip-selection cases in the fixture on Linux/NVIDIA. Native RDNA2 sampling, fractional LODs, and linear mip filtering were outside this run.

AI-assisted verification.

Conflicts in docs/d3d12_vulkan.md, runtime/CMakeLists.txt, check.py,
run_gpu_tests.py and test_shader_checks.py: main's versions with
vk_sampler_test, ps_ssharp and its checks added back (ps_ssharp is drawn
with vs_ids through DRAWN_WITH now).

AI-assisted (Claude Code).

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

Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Merged main (d937b7f..0d61c35) into this branch as 8ccf429 (no force-push). Main's versions won the conflicts in docs/d3d12_vulkan.md, runtime/CMakeLists.txt, check.py, run_gpu_tests.py and test_shader_checks.py, with this PR's parts added back: vk_sampler_test in the tool list, ps_ssharp in DRAWN_WITH (drawn with vs_ids), its runner branch and check, and TOTAL +1. The PR diff is unchanged otherwise: 7 files.

Re-run on 8ccf429, RTX 5080 / 616.92, Windows 11:

  • run_gpu_tests.py (LEONIDA_W64_EMULATE=1): 119 translated, 119 pass spirv-val, 117/117 passed; ps_ssharp 8 cases, 4096 pixels each exact.
  • check.py: 109 of 109.
  • ctest: 57/57 (gameinput disabled as on main).
  • pytest tests --ignore=tests/semantic: 2832 passed, 58 skipped.
  • unittest discover -s tests/semantic: OK. Stdlib tests/test_*.py: all pass.

Thanks @EchoTD (RX 6800) and @tylerstraub (RTX 5090) for the runs on e444c83.

AI-assisted (Claude Code).

Conflicts were list/registration hunks in runtime/CMakeLists.txt, check.py, run_gpu_tests.py and tests/test_shader_checks.py; kept main's side and re-added vk_sampler_test, ps_ssharp and the TOTAL count.

AI-assisted (Claude Code).

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

Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Merged main as f94fc77. Conflicting files: runtime/CMakeLists.txt, runtime/test/shaders/check.py, scripts/run_gpu_tests.py, tests/test_shader_checks.py (tool list, pixels() signature, DRAWN_WITH and the TOTAL count; kept main's side and re-added vk_sampler_test, ps_ssharp and sampler_test).

Re-test after the merge (ps_ssharp, 8 S#/T# cases):

  • RTX 5080, driver 616.92: pass, 4096 pixels exact in each case
  • Radeon iGPU, driver 26.10.1: pass, same results
  • tests/semantic unittest OK, regen_fixtures.py --check clean, test_shader_checks.py OK (44 tests), test_run_gpu_tests.py OK

AI-assisted (Claude Code).

@ItsNotRexed
ItsNotRexed merged commit db6c579 into ItsNotRexed:main Nov 22, 2026
3 of 4 checks passed
@Vonsek

Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Correction: vk_sampler_test ignored LEONIDA_VK_DEVICE and always picked the discrete GPU. So the runs I reported here as "Radeon iGPU" for ps_ssharp actually ran on the RTX 5080. The RTX 5080 results stand. The RX 6800 and RTX 5090 results posted by others are unaffected. Open #1799 makes the tool honour the variable; once it lands I'll rerun ps_ssharp on the RDNA2 iGPU. AI-assisted.

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.

4 participants