Skip to content

feat(rdna2spirv): implement image_sample_c_l_o - #3492

Open
klarnet2009 wants to merge 2 commits into
ItsNotRexed:mainfrom
klarnet2009:feat/rdna2spirv-image-sample-c-l
Open

klarnet2009 wants to merge 2 commits into
ItsNotRexed:mainfrom
klarnet2009:feat/rdna2spirv-image-sample-c-l

Conversation

@klarnet2009

Copy link
Copy Markdown
Contributor

Implements image_sample_c_l_o (explicit-LOD depth-compare sample with packed signed 6-bit texel offsets) in tools/rdna2spirv.py.

Changes

  • Added "image_sample_c_l_o" to MIMG dispatch and scalar 2D depth comparison address-length validation (want_addr = 4 under a16, 5 without a16).
  • Allowed texel offset (off) and explicit LOD extraction (lod) for kind == "_c_l", emitting OpImageSampleDrefExplicitLod %float with Lod|Offset {lod} {off} in valid SPIR-V ImageOperands bit order (Lod = 0x2, Offset = 0x10).
  • Updated docs/design.md with image_sample_c_l_o documentation (CPU/assembler-verified; not yet GPU-measured).
  • Added tests/semantic/test_image_sample_c_l_o.py covering Lod|Offset, signed 6-bit offset extraction, d16, a16, Unsupported rejections, and spirv_asm.assemble() verification on every emitted module.

Verification

  • py -3.12 -I tests/semantic/test_image_sample_c_l_o.py -v: 3/3 OK (0.086s)
  • py -3.12 -I tests/test_isa_coverage.py -v: 18 tests OK (3 skipped: LEONIDA_RDNA2_ISA_XML unset)
  • py -3.12 -I tests/test_ctest_registration.py -v: 4/4 OK
  • py -3.12 -I -m compileall -q tools/rdna2spirv.py tests/semantic/test_image_sample_c_l_o.py: OK

@kotorvr

kotorvr commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested ccf30b5 on NVIDIA GeForce RTX 4090 (Ada, subgroup 32..32), 621.14, Windows 11 (26200): pass, no change against main f847748 (the branch's base). The GPU suite has no image_sample_c_l_o fixture, so on hardware this is a no-regression check; the new op itself is only covered by the PR's CPU test.

Test programs: MSVC 19.44 RelWithDebInfo build of main f847748 (the PR changes nothing under runtime/). llvm-mc 21.1.8, Vulkan SDK 1.4.363.0, Python 3.13.7.

main f847748 ccf30b5
python -I scripts/run_gpu_tests.py 153/199 passed, 46 skipped, 0 failed 153/199 passed, 46 skipped, 0 failed
the same with LEONIDA_W64_EMULATE=1 184/199 passed, 15 skipped 184/199 passed, 15 skipped

On the branch:

  • python -m unittest discover -s tests/semantic -p test_image_sample_c_l_o.py: 3 tests OK
  • python -I tests/test_isa_coverage.py: 18 OK (3 skipped)
  • python -I -m compileall -q make_game.py tools tests: exit 0

Not run: the full tests/semantic suite. No game files. AI-assisted check (Claude Code).

@ttd0x

ttd0x commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested ccf30b5b on NVIDIA GeForce RTX 2080 Ti (Turing, subgroup 32..32, driver 610.88), Windows 11: pass, no regression.

  • tests/semantic/test_image_sample_c_l_o.py: 3 tests OK.
  • scripts/run_gpu_tests.py (default, no emulation), 204 shaders translated, all pass spirv-val: 152/199 passed, 46 skipped (native wave64, expected on a 32-wide device), 1 failed. Main f847748c gives the same result lines; the one failure (ps_sdwa_f16_const) also fails on main.
  • Limit: no GPU fixture uses image_sample_c_l_o, so the GPU run shows only that nothing else broke.

Synthetic fixtures only, no game data. AI-assisted (Claude Code).

@sperm

sperm commented Nov 22, 2026

Copy link
Copy Markdown

Tested ccf30b5 on AMD Radeon RX 9070 XT (RADV GFX1201) and the Ryzen 7 9800X3D iGPU (RADV RAPHAEL_MENDOCINO, gfx1036), Mesa 26.2.6, Linux 7.3.4: pass, no regressions.

  • Full python -I scripts/run_gpu_tests.py (Linux build of this branch's runtime/, LEONIDA_VK_DEVICE per GPU): 185/199 passed, 14 skipped, 0 failed on both GPUs. Compared with the same suite at the merge base f847748 on the same machine, every test has the same result.
  • python -m unittest discover -s tests/semantic: 7325 run, OK (expected failures=1)

No game files. AI-assisted.

@whattheflop whattheflop 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.

AI-assisted verification at ccf30b5b. Both LLVM-assembled forms validated with the maintenance8 option. The RTX 3080 readback checked this opcode directly: all 4,096 pixels chose the expected mip and texel. The scratch run used #3045 for the sampled-array dynamic indexing declaration and #3347 for feature chaining in the test device. The exact head omits the declaration even though both descriptor indices are runtime lookups. Standalone spirv-val did not catch that omission.

The new depth-compare form also inherits an issue in the shared --texel-offset-fallback. With nearest mip filtering and explicit LOD 0.75, the sample uses mip 1, while texel_offset_fold() floors that LOD and uses mip 0 to scale the offset. On an 8x8 base mip and 4x4 mip 1, UV (0.6875,0.5625) with offset (-1,+1) computes mip-1 texel (2,2) instead of (1,3). I checked the emitted size-query chain and confirmed the CPU coordinate calculation. The native run covers integer LODs with maintenance8. Vulkan mip selection

@javdc

javdc commented Nov 22, 2026

Copy link
Copy Markdown

Tested ccf30b5 on Steam Deck LCD (Jupiter), AMD Custom GPU 0405 "Van Gogh", RADV Mesa 26.2.0-devel (git-5c65d4fc31), Vulkan 1.4.350, SteamOS 3.9.5 (holo), kernel 7.2.7-valve2-2-neptune-72-g31504582a073: pass

  • python3 -m pytest tests/semantic/test_image_sample_c_l_o.py -q -> 3 passed, 7 subtests passed
  • python3 -I scripts/run_gpu_tests.py --build <build> -> 184/199 passed, 14 skipped, 0 failed (expected D3D12-owned skips)

No runtime C++ changes; GPU suite run from the PR worktree against the existing main runtime build.

AI-assisted (OpenCode).

@im-a-cat

Copy link
Copy Markdown

Tested ccf30b5 on Windows 11 Pro 10.0.26300, Python 3.12.10 (CPU checks; this PR has no GPU fixture):

  • python -I tests/semantic/test_image_sample_c_l_o.py -v: 3/3 OK
  • python -I tests/test_isa_coverage.py: 18 tests OK (3 skipped: LEONIDA_RDNA2_ISA_XML unset)
  • python -I tests/test_ctest_registration.py: 4/4 OK
  • Full tests/semantic at the PR head, one file per process: 333/333 files clean, 7,325 tests, no failures

Run in a temporary worktree at the PR head. Not GPU-checked: the PR adds no fixture for image_sample_c_l_o, so this does not confirm the Lod|Offset result on hardware.

AI-assisted.

@tylerstraub

Copy link
Copy Markdown
Contributor

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

At f88407aa I adapted the synthetic 8×8 D32 gradient draw locally to exercise image_sample_c_l_o with explicit LOD 0 and a compare reference of 0.5. The runner label was ps_sample_c_lz because I reused its texture and readback setup. Both sample instructions in the shader were replaced with the new opcode, one f32 and one d16 widened for readback.

  • Zero offset: both channels matched the expected depth comparison across all 4,096 pixels.
  • Packed offset 0x3f (x = −1, y = 0): the first passing source texel column shifted from 4 to 5 as expected. Both channels matched across all 3,584 interior pixels checked. I excluded the leftmost texel column from this comparison to keep sampler edge behavior outside the measurement.

Both draws passed SPIR-V validation on Linux RTX 5090. These measurements cover 32-bit address operands and mip level zero.

AI-assisted verification.

@editrice

Copy link
Copy Markdown

Tested current head f88407aae4aefff3085a38a528fc4929f302b6d6 on RTX 5070 (NVIDIA 621.01, Windows 11) with a local synthetic 8×8/4×4 D32 mip-chain readback. At explicit LOD 0.75, nearest mip filtering, and packed offset (−1,+1), native VK_KHR_maintenance8 and --texel-offset-fallback differed in exactly 512/4096 pixels in both f32 and d16: native passed columns 48–63 (1024 pixels), while fallback passed columns 40–63 (1536). With offset zero at the same LOD, both paths passed 4096/4096 and their 65,536-byte RGBA32F readbacks were byte-identical. All four shader builds translated and passed spirv-val.

This confirms on the current head the previously reported fallback defect: Floor(LOD) queries mip-0 size although nearest sampling selects mip 1. Please fix shared fallback mip selection or reject this form in fallback mode. Synthetic only; no game files. AI-assisted verification.

@DenRakEiw

Copy link
Copy Markdown
Contributor

Tested f88407aa on NVIDIA GeForce RTX 5090 (Blackwell, driver 32.0.16.1088), Windows 11, Vulkan SDK 1.4.363.0, LLVM 21.1.8 (amdgcn via WSL), Python 3.12.10 (no game files): pass.

  • Trial-merged onto origin/main (3faac557): clean.
  • RTX 5090 (LEONIDA_W64_EMULATE=1): python -I scripts/run_gpu_tests.py --build runtime/build --filter ps_sample_c -> 5/5 translated, 5/5 pass spirv-val, 4/4 passed (ps_sample_c, ps_sample_c_b, ps_sample_c_lz, ps_sample_c_lz_a16).
  • Semantic tests: test_image_sample_c_l_o.py 3/3 OK.

AI-assisted (Gemini 4 Neon).

@klarnet2009

Copy link
Copy Markdown
Contributor Author

Thank you @editrice and @whattheflop for the review!

Updated in 42df062e:

  • tools/rdna2spirv.py (Gen.texel_offset_fold): Replaced the Floor mip-level selection with ceil(lod + 0.5) - 1 clamped to [0, levels - 1] (OpFAdd 0.5 -> GLSL.std.450 Ceil -> OpConvertFToS -> OpISub 1 -> GLSL.std.450 SClamp), matching Vulkan VK_SAMPLER_MIPMAP_MODE_NEAREST (Vulkan 16.6.1) so LOD = 0.75 queries mip 1 while LOD <= 0.5 queries mip 0, and choosing the dominant mip for trilinear.
  • docs/design.md: Updated the --texel-offset-fallback note to document the ceil(lod + 0.5) - 1 nearest-mip selection.
  • tests/semantic/test_image_sample_c_l_o.py: Added test_texel_offset_fallback_nearest_mip_selection verifying that under TEXEL_OFFSET_FALLBACK = True, image_sample_c_l_o (both f32 and d16) translates and assembles via spirv_asm.assemble, emits OpImageSampleDrefExplicitLod ... Lod without Offset, and emits the OpFAdd -> Ceil -> OpConvertFToS -> OpISub -> SClamp -> OpImageQuerySizeLod chain without Floor.

Verification (py -3.12 -I)

  • py -3.12 -I tests/semantic/test_image_sample_c_l_o.py -v: Ran 4 tests in 0.086s — OK
  • py -3.12 -I tests/test_isa_coverage.py -v: Ran 20 tests in 10.266s — OK (skipped=4) (LEONIDA_RDNA2_ISA_XML unset)
  • py -3.12 -I tests/test_ctest_registration.py -v: Ran 4 tests in 0.053s — OK
  • py -3.12 -I -m compileall -q tools/rdna2spirv.py tests/semantic/test_image_sample_c_l_o.py: exit code 0
  • pytest and spirv-as/spirv-val are not installed on this host, so tests/test_texel_offsets.py and external spirv-val were not run here.

@sovljanskii

Copy link
Copy Markdown
Contributor

Tested 42df062e on Apple M4 (subgroup 4..32), macOS 27.2.1, MoltenVK 1.4.2, with the runtime built by AppleClang 21.0.0 from main 3faac557 (the PR head already contains it). Verdict: pass, no regression on Apple. The M4 can't judge the new mip selection itself (details below).

  • Tests: test_image_sample_c_l_o gives 4 OK on Python 3.15.2 and 3.12.16. tests/test_isa_coverage.py and tests/test_ctest_registration.py are OK.
  • Negative controls (LEONIDA_TOOLS_DIR):
    • With f88407aa's rdna2spirv.py, the new test_texel_offset_fallback_nearest_mip_selection fails in both its f32 and d16 subtests (Floor found), so it pins 42df062e.
    • With main's translator, all 4 tests error (Unsupported).
  • Whole tests/semantic (Python 3.15.2): 6,249 tests against main's 6,245 (+4). Both have the same 32 failures and 2 errors, with identical test IDs (the arm64 vop3 test_rows NaN cases and the divergent loop/ballot cases that fail on main on this machine). Nothing new fails.
  • Full run_gpu_tests.py: 221 shaders, 220 translated and valid; 152/217 passed, 58 skipped. Per test this is identical to main on the same machine.
  • Texel offsets on Apple, native and through the fallback. The M4 reports VK_KHR_maintenance8, so MoltenVK runs the native run-time Offset, and --texel-offset-fallback is opt-in there. ps_texoff, ps_texoff_forms and ps_texoff_implicit pass 4096/4096 exact on both main and this head, natively and with LEONIDA_TEXOFF_FALLBACK=1 (12/12).
  • What the M4 can't settle: 42df062e changes the fallback's level from Floor(lod) to ceil(lod + 0.5) - 1 for every _l and implicit offset sample, not only _c_l_o. No GPU fixture exercises a fractional LOD on a textured mip 1:
    • the ps_texoff* texture has one level;
    • vk_texture_test --two-mip's mip 1 is solid cyan, so a wrong offset scale there reads the same colour.
      The native-vs-fallback check stays with editrice's RTX 5070 readback, which was taken at f88407aa, before this fix. A rerun at 42df062e would close it.
  • Corpus (the user's copy, 25,734 listings): none uses image_sample_c_l_o. 26 listings use an offset sample or gather (174 image_gather4_l_o, 55 image_gather4_lz_o, 31 image_sample_o). I translated those 26 with main and with this head:
    • default: all 26 modules are byte-identical, and 26/26 pass spirv-val --allow-offset-texture-operand;
    • --texel-offset-fallback: 4 of the 26 change and 26/26 stay valid. In each changed module the number of Ceil on this head equals the number of Floor on main (3, 10, 8, 10), so the only change is the level rounding of the image_sample_o folds. That reach is wider than _c_l_o, which is why a GPU check of the fallback at a fractional LOD matters.

No game files. AI-assisted.

@klarnet2009

Copy link
Copy Markdown
Contributor Author

Rebased onto upstream/main (dde82f27e, head 85de1feae).

  • Kept upstream/main's MIP_FILTER-aware Gen.texel_offset_fold (floor + (frac >= 0.5) for point / floor for linear) and docs/design.md --texel-offset-fallback documentation, preserving if kind in ("_l", "_c_l"): for image_sample_c_l_o.
  • Updated test_texel_offset_fallback_nearest_mip_selection in tests/semantic/test_image_sample_c_l_o.py to verify the MIP_FILTER-aware path (Floor, FOrdGreaterThanEqual, OpImageQuerySizeLod, OpFDiv, OpImageSampleDrefExplicitLod with Lod and no Offset, plus spirv_asm.assemble).

Verification (py -3.12 -I)

  • py -3.12 -I tests/semantic/test_image_sample_c_l_o.py -v: Ran 4 tests in 0.269s — OK
  • py -3.12 -I tests/test_isa_coverage.py -v: Ran 22 tests in 20.783s — OK (skipped=4) (LEONIDA_RDNA2_ISA_XML unset)
  • py -3.12 -I tests/test_ctest_registration.py -v: Ran 4 tests in 0.980s — OK
  • py -3.12 -I -m compileall -q tools/rdna2spirv.py tests/semantic/test_image_sample_c_l_o.py: exit code 0

@YordiLorenzo

Copy link
Copy Markdown

Tested 85de1fe on RTX 5090, NVIDIA 615.71.09, Ubuntu 26.04: pass

  • run_gpu_tests.py, whole suite: 192 of 241 passed, 48 skipped, 1 failed (ms_wave_info_s3, ms_wave_info_s3 fails natively on NVIDIA RTX 5080 (Windows, subgroup 32): all pixels read back -1 #8306). Same result line for line on main c8ef3d0
  • run_semantic_tests.py tests/semantic: 448 files, 5960 tests, 2 files fail (test_image_atomics_guard, test_image_store_d16). The same 2 fail on main
  • pytest tests/semantic/test_image_sample_c_l_o.py: 4 passed, 9 subtests passed
  • ctest, Linux subset: 64 tests, 0 failed (2 skipped as on main)
  • Negative control: the same test file on a clean main checkout fails (4 failed, the texel offset fallback cases among them)

@lukasas74

Copy link
Copy Markdown

Tested 85de1feae on NVIDIA GeForce RTX 5080 (subgroup 32..32), NVIDIA 621.01, Vulkan 1.4.357, Windows 11 Pro 26200: pass.

Toolchain: standalone tools (-DLEONIDA_BUILD_WINDOWS_RUNTIME=OFF) built with llvm-mingw 20261117 (clang 23.1.6) against Vulkan-Headers 1.4.369; llvm-mc 23.1.6 (conda-forge llvm-tools), SPIRV-Tools 2026.4. Automated run, AI-assisted (Claude Code).

@TG0000

TG0000 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 85de1fe on AMD Radeon RX 6800 (RDNA2 gfx1030, AMD 26.11.2, Windows 11): pass

Trial-merged onto main 7891358 (clean merge). Runtime Vulkan test targets built with llvm-mingw clang (-DLEONIDA_BUILD_WINDOWS_RUNTIME=OFF).

  • pytest tests/semantic/test_image_sample_c_l_o.py: 4 passed, 9 subtests.
  • python -I scripts/run_gpu_tests.py (full): 223/241 passed, 17 skipped, 1 failed. The one failure is ms_wave_info_s3, which is flaky on this GPU on bare main: rerun alone 3 times it passed 1 of 3 on main 7891358 and 1 of 3 with this PR, failing the same way each time ((-1,-1,-1,-1) at (0,0)). Base main full run: 224/241 passed, 17 skipped.
  • python -m compileall on tools/tests/scripts/make_game.py: clean.

Tested by an AI agent (Claude Code) on the maintainer-side test machine.

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.