Skip to content

rdna2spirv: support image_sample_d_{g16,cl_g16,o,cl_o,o_g16,cl_o_g16} - #5820

Open
DenRakEiw wants to merge 1 commit into
ItsNotRexed:mainfrom
DenRakEiw:feat/rdna2-image-sample-d-g16-o
Open

DenRakEiw wants to merge 1 commit into
ItsNotRexed:mainfrom
DenRakEiw:feat/rdna2-image-sample-d-g16-o

Conversation

@DenRakEiw

Copy link
Copy Markdown
Contributor

Claim: #5581 (comment)

Summary

Implements the 6 unclaimed explicit-gradient RDNA2 image_sample_d instruction variants in ools/rdna2spirv.py and fixes MIMG address VGPR count decoding in ools/rdna2_decode.py:

  • image_sample_d_g16
  • image_sample_d_cl_g16
  • image_sample_d_o
  • image_sample_d_cl_o
  • image_sample_d_o_g16
  • image_sample_d_cl_o_g16

Key Details

  • RDNA2 g16 gradient layout (verified against llvm-mc -arch=amdgcn -mcpu=gfx1030): each of dP/dx and dP/dy is packed independently as f16 pairs in (grad_width + 1) // 2 VGPRs (1D: 2 VGPRs (dx, _), (dy, _); 2D/2D_ARRAY/CUBE: 2 VGPRs (dx.x, dx.y), (dy.x, dy.y); 3D: 4 VGPRs (dx.x, dx.y), (dx.z, _), (dy.x, dy.y), (dy.z, _)), unpacked via UnpackHalf2x16.
  • SPIR-V Image Operands mask ordering: emits Grad, Grad|Offset, Grad|MinLod, and Grad|Offset|MinLod in strict SPIR-V operand order.
  • --texel-offset-fallback: extends exel_offset_fold to support explicit-gradient _d samples (computing mip level from log2(max(|dxsize0|, |dysize0|)) and minlod) without requiring VK_KHR_maintenance8.
  • ** ools/rdna2_decode.py (_mimg_addr_count)**: tokenizes MIMG sample/gather suffixes accurately so _cl_o, _g16, _cl_g16, _o_g16, _cl_o_g16, and �16 coordinate+clamp packing ((packable + 1) // 2) match llvm-mc -mcpu=gfx1030 across all dimensions.

Verification (Windows 11, RTX 5090, Vulkan SDK 1.4.363.0, LLVM 21 llvm-mc)

  • python -m unittest discover -s tests/semantic -p test_image_sample_d_g16_o.py -v: 5/5 PASS (all 6 ops x 5 dims x �16/d16/--texel-offset-fallback, 92 SPIR-V modules validated with spirv-val --target-env vulkan1.2, 60 llvm-mc -mcpu=gfx1030 binary decode round-trips).
  • python -I tests/test_text_write_line_endings.py: 3/3 PASS.
  • python -m unittest tests/test_shader_checks.py -v: 86/86 PASS.
  • python -m unittest discover -s tests -p test_decode.py -v: 62/62 PASS (1 skipped).
  • RTX 5090 GPU tests (LEONIDA_W64_EMULATE=1):
    • ps_sample_d_g16_o (native VK_KHR_maintenance8): PASS — 4096/4096 RGBA pixels matched (all 6 variants verified on hardware).
    • ps_sample_d_g16_o (LEONIDA_TEXOFF_FALLBACK=1): PASS — 4096/4096 RGBA pixels matched.
    • ps_texture_grad_a16, ps_texture_grad_cl_a16: 2/2 PASS — 4096/4096 RGBA pixels matched.
  • git diff --check: clean.

AI-assisted (Gemini 4 Neon).

@Kev-Ball

Copy link
Copy Markdown

Retail coverage at eecb9878: I counted explicit-gradient sample mnemonics across all 26,503 disassembled shaders from my Xbox 1.0.2.1 copy. None of the six added spellings occurred. As positive controls, the same scan found 18,664 image_sample_d instructions in 2,901 listings and 273 image_sample_d_cl instructions in 29 listings.

For this package, the hand-written GPU fixture supplies the direct execution coverage for all six new forms. These counts cover the disassembled main shader archive only. CPU-only, CachyOS, AI-assisted.

@gertify

gertify commented Nov 23, 2026

Copy link
Copy Markdown

Tested eecb987 on AMD RADV RAPHAEL_MENDOCINO (Ryzen 9 9950X3D iGPU), subgroup 32..64: run_gpu_tests.py --filter ps_sample_d_g16_o prints "PASS ps_sample_d_g16_o 4096 RGBA pixels matched", also with LEONIDA_TEXOFF_FALLBACK=1. With LEONIDA_VK_DEVICE=NoSuchDevice it fails with "no Vulkan physical device matches", and with tools/rdna2spirv.py and tools/rdna2_decode.py from 561b65a swapped in it fails with "missing .spv (translation failed)". With LEONIDA_W64_EMULATE=1, ps_texture_grad_a16 and ps_texture_grad_cl_a16 pass at 4096 RGBA pixels matched. test_image_sample_d_g16_o runs 5 tests OK. tests/test_rdna2_decode.py test_parity_with_llvm_mc_on_shader_fixtures fails ("op_sel:[0,1,0,0]" != "op_sel:[0,1]" on cs_w32_permlane_fi.asm) on this head and with the 561b65a decoder alike. test_shader_checks.py was not run.

AI-assisted.

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

Reviewed at eecb9878c8 on Windows 11, RTX 5070 Ti, Vulkan 1.4.363.

  • python tests/semantic/test_image_sample_d_g16_o.py: 5/5 OK with llvm-mc 21 through WSL (the 60 binary decode round-trips ran); 5/5 OK without it (1 skip) in 3.2 s.
  • GPU: python -I scripts/run_gpu_tests.py --build <build> --work <work> --filter ps_sample_d_g16_o --llvm-mc <wrapper> -> PASS, 4096/4096 RGBA pixels. Repeated with LEONIDA_TEXOFF_FALLBACK=1 -> PASS, 4096/4096.
  • test_*decode*.py: 62 OK (1 skip). test_shader_checks.py: 86 OK. Existing image semantics (coherent, store d16/dmask, atomics, BVH box/tri): 41 OK.
  • Checked the new operand rules against the existing image_sample_* paths: Grad|Offset|MinLod is emitted in SPIR-V mask order; g16 3D packing (dx.xy, dx.z, _) / (dy.xy, dy.z, _) and the 1D/2D cases match llvm-mc; the fallback LOD is log2(max(|dx*size0|, |dy*size0|)) clamped by MinLod and the S# mip filter.

Verdict: LGTM. Overlaps: this conflicts with open #3300 and #4642 in tools/rdna2spirv.py (both also touch the same image-op dispatch/fallback code).

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

Summary

Implements six explicit-gradient image_sample_d variants (_g16, _cl_g16, _o, _cl_o, _o_g16, _cl_o_g16) in tools/rdna2spirv.py, packing g16 gradient pairs and emitting SPIR-V operands in order, plus --texel-offset-fallback mip-level computation. tools/rdna2_decode.py _mimg_addr_count now tokenizes MIMG suffixes for g16/clamp/offset forms. Adds tests/semantic/test_image_sample_d_g16_o.py, ps_sample_d_g16_o.asm GPU fixture and runtime/test/shaders/check.py support.

Why merge

Closes six previously unhandled translator instruction forms with 92 spirv-val-validated modules and byte-decode round-trips against llvm-mc, plus an end-to-end GPU fixture.

Verdict: Approve

@larpinguser

Copy link
Copy Markdown

Summary

Implements six explicit-gradient image_sample_d variants (_g16, _cl_g16, _o, _cl_o, _o_g16, _cl_o_g16) in tools/rdna2spirv.py, packing g16 gradient pairs and emitting SPIR-V operands in order, plus --texel-offset-fallback mip-level computation. tools/rdna2_decode.py _mimg_addr_count now tokenizes MIMG suffixes for g16/clamp/offset forms. Adds tests/semantic/test_image_sample_d_g16_o.py, ps_sample_d_g16_o.asm GPU fixture and runtime/test/shaders/check.py support.

Why merge

Closes six previously unhandled translator instruction forms with 92 spirv-val-validated modules and byte-decode round-trips against llvm-mc, plus an end-to-end GPU fixture.

Verdict: Approve

@DenRakEiw
DenRakEiw force-pushed the feat/rdna2-image-sample-d-g16-o branch from eecb987 to 95a9ba3 Compare November 23, 2026 17:04
@DenRakEiw

Copy link
Copy Markdown
Contributor Author

Rebased cleanly onto latest main (95a9ba3c0), resolving merge conflicts in tools/rdna2_decode.py and tools/rdna2spirv.py.

Re-verified:

  • git diff --check origin/main..HEAD: clean
  • python -I -m compileall -q tools tests scripts runtime/test/shaders: OK
  • tests/semantic/test_image_sample_d_g16_o.py (llvm-mc + spirv-val): 5/5 passed
  • NVIDIA GeForce RTX 5090 (LEONIDA_VK_VALIDATION=1, LEONIDA_W64_EMULATE=1): ps_sample_d_g16_o 1/1 passed (4096 RGBA pixels matched, 2/2 shaders pass spirv-val)

AI-assisted (Gemini 4 Neon).

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