rdna2spirv: 16-bit gradients for image_sample_d_g16 and image_sample_… #1481

Merged
leonida/mandy
vsking2000 merged 1 commit from shader-sample-g16 into main 2026-11-28 11:52:43 +00:00

Pull request successfully merged and closed

vsking2000 commented 2026-11-25 01:13:20 +00:00

…d_cl_g16 (SHADER-SAMPLE-G16)

The two g16 forms whose f32-gradient sibling main translates are now the same sample as image_sample_d / image_sample_d_cl, with dP/dx and dP/dy read as f16 halves: two per VGPR, low half first, each axis padded to a whole VGPR (1D (dx, -) (dx, -); 2D/array/cube (x, y) (x, y); 3D (x, y) (z, -) (x, y) (z, -)). Coordinates and clamp follow, packed only under a16; g16 and a16 are independent. Gen.g16_gradients widens each half with UnpackHalf2x16 and drops the pad; the f32-gradient path does the rest. LLVM (SIISelLowering lowerImage, packImage16bitOpsToDwords) and Mesa ACO (aco_select_nir.cpp, emit_pack_v1) agree on every point.

The six compare/offset g16 forms stay refused until their f32 siblings are translated (SHADER-SAMPLE-GRAD-FORMS), and the eight _cd g16 forms stay refused. docs/design.md gets a row. Not run on a GPU.

Claude-Session: https://claude.ai/code/session_01Y7fbZYVY7EtLknWBZUfSLf

Claimed in the coordination issue as:

Depends on:

Fixes:

What and why

Tested

GPUs tested:

AI-assisted:

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • 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.
…d_cl_g16 (SHADER-SAMPLE-G16) The two g16 forms whose f32-gradient sibling main translates are now the same sample as image_sample_d / image_sample_d_cl, with dP/dx and dP/dy read as f16 halves: two per VGPR, low half first, each axis padded to a whole VGPR (1D (dx, -) (dx, -); 2D/array/cube (x, y) (x, y); 3D (x, y) (z, -) (x, y) (z, -)). Coordinates and clamp follow, packed only under a16; g16 and a16 are independent. Gen.g16_gradients widens each half with UnpackHalf2x16 and drops the pad; the f32-gradient path does the rest. LLVM (SIISelLowering lowerImage, packImage16bitOpsToDwords) and Mesa ACO (aco_select_nir.cpp, emit_pack_v1) agree on every point. The six compare/offset g16 forms stay refused until their f32 siblings are translated (SHADER-SAMPLE-GRAD-FORMS), and the eight _cd g16 forms stay refused. docs/design.md gets a row. Not run on a GPU. Claude-Session: https://claude.ai/code/session_01Y7fbZYVY7EtLknWBZUfSLf Claimed in the coordination issue as: <!-- the item ID from the open "Coordinating who works on what" issue, for example TEST-17, or a link to your claim --> Depends on: <!-- #N for every pull request this one builds on or conflicts with (the coordination issue's Commands section, AGENTS.md); delete the line if it builds on none and conflicts with none --> Fixes: <!-- #N for each issue this closes (GitHub closes it on merge); delete the line if it closes none --> ### What and why <!-- What this changes and the problem it solves. --> ### Tested <!-- What you ran and on which GPU and driver (CONTRIBUTING.md). For the shader translator: how many shaders translate and pass spirv-val, before and after. --> GPUs tested: <!-- vendor, model, driver and OS of each GPU the GPU tests ran on, or n/a --> AI-assisted: <!-- yes or no (AGENTS.md asks a coding agent to say so) --> ### Checklist - [ ] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [ ] One topic; follow-up work goes in a new pull request. - [ ] 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.
GeorgiyDemo commented 2026-11-25 01:20:23 +00:00

Tested ece08d3b1 on Apple M5 Pro (16-core GPU), macOS 26.7.3 (25G342), against main b4b7756e8 (translator-only PR; binaries from the build at 66d4f5aa3):

  • python3 -m unittest test_sample_g16 (from tests/semantic): OK at this head. The same file on main errors 46 times — every g16 gradient form is refused there, so the coverage is real.
  • GPU regression, --filter ps_sample_ on MoltenVK 1.4.2: 6/6 PASS (ps_sample_c, ps_sample_c_b, ps_sample_c_lz, ps_sample_c_lz_a16, ps_sample_implicit_sint, ps_sample_implicit_uint).
  • Not run: GPU execution of the new g16 forms themselves — there is no .asm fixture for them; the semantic suite is the evidence here.

AI-assisted; synthetic fixtures only, no game data.

Tested `ece08d3b1` on Apple M5 Pro (16-core GPU), macOS 26.7.3 (25G342), against `main` `b4b7756e8` (translator-only PR; binaries from the build at `66d4f5aa3`): - `python3 -m unittest test_sample_g16` (from `tests/semantic`): **OK** at this head. The same file on `main` errors **46 times** — every g16 gradient form is refused there, so the coverage is real. - GPU regression, `--filter ps_sample_` on **MoltenVK 1.4.2**: **6/6 PASS** (`ps_sample_c`, `ps_sample_c_b`, `ps_sample_c_lz`, `ps_sample_c_lz_a16`, `ps_sample_implicit_sint`, `ps_sample_implicit_uint`). - Not run: GPU execution of the new g16 forms themselves — there is no `.asm` fixture for them; the semantic suite is the evidence here. AI-assisted; synthetic fixtures only, no game data.
tyr0nsur commented 2026-11-25 02:03:30 +00:00

I ran both new opcodes through this PR’s own rdna2spirv.py and vk_texture_test at ece08d3b1, on a desktop RTX 4060, driver 32.0.16.2114, Windows 11 Pro build 26300. All four 64×64 draws matched every expected RGBA pixel.

Instruction 32-bit coordinates 16-bit coordinates
image_sample_d_g16 4096/4096 4096/4096
image_sample_d_cl_g16 4096/4096 4096/4096

The ordinary G16 sample uses a larger horizontal gradient on the right half to select the cyan mip. The clamped form keeps both gradients small and raises the minimum LOD on that half. The left half retains the red/blue pattern of mip 0. The parent translator at b4b7756e8 rejected all four programs by opcode. The PR’s seven test_sample_g16.py tests also passed, including spirv-val, with zero skips.

To repeat on another Vulkan device, build this PR’s vk_texture_test, put spirv-as and spirv-val on PATH, and run python leonida_g16.py <leonida-checkout> <vk_texture_test.exe>. The fixture uses handwritten shader listings and the renderer’s own texture. AI-assisted (Codex, GPT-6). Runnable test and pixel reference

I ran both new opcodes through this PR’s own `rdna2spirv.py` and `vk_texture_test` at `ece08d3b1`, on a desktop RTX 4060, driver 32.0.16.2114, Windows 11 Pro build 26300. All four 64×64 draws matched every expected RGBA pixel. | Instruction | 32-bit coordinates | 16-bit coordinates | | --- | ---: | ---: | | `image_sample_d_g16` | 4096/4096 | 4096/4096 | | `image_sample_d_cl_g16` | 4096/4096 | 4096/4096 | The ordinary G16 sample uses a larger horizontal gradient on the right half to select the cyan mip. The clamped form keeps both gradients small and raises the minimum LOD on that half. The left half retains the red/blue pattern of mip 0. The parent translator at `b4b7756e8` rejected all four programs by opcode. The PR’s seven `test_sample_g16.py` tests also passed, including `spirv-val`, with zero skips. To repeat on another Vulkan device, build this PR’s `vk_texture_test`, put `spirv-as` and `spirv-val` on PATH, and run `python leonida_g16.py <leonida-checkout> <vk_texture_test.exe>`. The fixture uses handwritten shader listings and the renderer’s own texture. AI-assisted (Codex, GPT-6). [Runnable test and pixel reference](https://github.com/tyr0nsur/PortVI/blob/d0cb833051d5c100a790246c71d8363c7a5315c3/probes/leonida_g16.py)
tiguan26 approved these changes 2026-11-25 06:01:42 +00:00
tiguan26 left a comment

Approving. Merged into current main (42537e7) with no conflicts; the PR's test passes and the full translator suite gives 488 files / 6,286 tests with only test_int32_to_f64 failing, as on main here (Linux, Python 3.13). The G16 layout matches LLVM's packImage16bitOpsToDwords: dP/dx and dP/dy packed separately, two halves per VGPR, low half first, each axis padded to a whole VGPR (so 3D is (dx/dh, dy/dh), (dz/dh, -), (dx/dv, dy/dv), (dz/dv, -)); each half is widened with UnpackHalf2x16 and the pad half dropped, and only the gradient words change.

AI-assisted (Claude).

Approving. Merged into current main (42537e7) with no conflicts; the PR's test passes and the full translator suite gives 488 files / 6,286 tests with only `test_int32_to_f64` failing, as on main here (Linux, Python 3.13). The G16 layout matches LLVM's packImage16bitOpsToDwords: dP/dx and dP/dy packed separately, two halves per VGPR, low half first, each axis padded to a whole VGPR (so 3D is (dx/dh, dy/dh), (dz/dh, -), (dx/dv, dy/dv), (dz/dv, -)); each half is widened with UnpackHalf2x16 and the pad half dropped, and only the gradient words change. AI-assisted (Claude).
MoonEyes commented 2026-11-27 22:43:02 +00:00

Hi @vsking2000, thanks for this pull request.

CONTRIBUTING.md asks contributors to claim their work in the coordination issue ("Coordinating who works on what", currently #1608) before opening a pull request: post claiming: <ID> there, or a one-line description if the item is not listed yet, and put the ID in the pull request. I could not find a claim from you for this one (the ID SHADER-SAMPLE-G16 appears in the pull request, but there is no claiming: line for it).

The claim matters because "it is claimed in the coordination issue by the pull request's author" is the first item on the maintainers' checklist for a mergeable pull request, and because it lets others see that the work is taken before they write it a second time.

Could you post the claim in #1608 and add the ID to the pull request description? If you already claimed it in another form, a link to your comment is enough.

AI-assisted (Claude Code, Claude Opus 5.5).

Hi @vsking2000, thanks for this pull request. CONTRIBUTING.md asks contributors to claim their work in the coordination issue ("Coordinating who works on what", currently #1608) before opening a pull request: post `claiming: <ID>` there, or a one-line description if the item is not listed yet, and put the ID in the pull request. I could not find a claim from you for this one (the ID `SHADER-SAMPLE-G16` appears in the pull request, but there is no `claiming:` line for it). The claim matters because "it is claimed in the coordination issue by the pull request's author" is the first item on the maintainers' checklist for a mergeable pull request, and because it lets others see that the work is taken before they write it a second time. Could you post the claim in #1608 and add the ID to the pull request description? If you already claimed it in another form, a link to your comment is enough. AI-assisted (Claude Code, Claude Opus 5.5).
sodove commented 2026-11-28 10:44:22 +00:00

#1481 | head ece08d3b1e2c51af15c133ae95480ad27cfb522b | python3 -m unittest discover -s tests/semantic -p test_sample_g16.py -v | red: 7 run, 46 errors | green: 7 passed | Red → green

Main raised translation errors for the 16-bit gradient cases, including cube and dmask variants. All seven test methods passed after merge.

Captured 25 distinct complete SPIR-V module(s) emitted while rerunning test_sample_g16.py on the merged tree. All assembled and passed spirv-val for Vulkan 1.2 with --allow-offset-texture-operand.

Base 3bd936ecd98995bca3e1da83d5e28d2343001aef was merged into the recorded PR head for the second run. Ubuntu 26.04.1 (WSL2), Python 3.14.4. Counts include unittest subtest events where applicable. AI-assisted with OpenAI Codex. Batch claim.

#1481 | head `ece08d3b1e2c51af15c133ae95480ad27cfb522b` | `python3 -m unittest discover -s tests/semantic -p test_sample_g16.py -v` | red: 7 run, 46 errors | green: 7 passed | **Red → green** Main raised translation errors for the 16-bit gradient cases, including cube and dmask variants. All seven test methods passed after merge. Captured 25 distinct complete SPIR-V module(s) emitted while rerunning test_sample_g16.py on the merged tree. All assembled and passed spirv-val for Vulkan 1.2 with --allow-offset-texture-operand. Base `3bd936ecd98995bca3e1da83d5e28d2343001aef` was merged into the recorded PR head for the second run. Ubuntu 26.04.1 (WSL2), Python 3.14.4. Counts include unittest subtest events where applicable. AI-assisted with OpenAI Codex. [Batch claim](https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7237873883).
DadaCap commented 2026-11-28 11:52:45 +00:00

Merged, thank you @vsking2000! This translator PR (rdna2spirv: 16-bit gradients for image_sample_d_g16 and image_sample_…) passed its own tests with main merged in during sodove's verification of this batch, so it went in with the batch.

AI-assisted (Claude Code, Claude Opus 5.5), posted for the maintainers.

Merged, thank you @vsking2000! This translator PR (rdna2spirv: 16-bit gradients for image_sample_d_g16 and image_sample_…) passed its own tests with main merged in during sodove's verification of this batch, so it went in with the batch. AI-assisted (Claude Code, Claude Opus 5.5), posted for the maintainers.
Sign in to join this conversation.
No description provided.