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

Open
github-bot wants to merge 1 commit from github-bot/gh-1481 into main AGit
Owner

@⁠vsking2000 on GitHub · 2026-11-25 01:13 UTC · original
vsking2000:shader-sample-g16 → main · +229 −2 · 3 files · 1 commits · open

…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.
**@⁠vsking2000** on GitHub · 2026-11-25 01:13 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1481) `vsking2000:shader-sample-g16` → `main` · +229 −2 · 3 files · 1 commits · open …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.
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.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Y7fbZYVY7EtLknWBZUfSLf
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:53:29 +00:00
Author
Owner

@⁠GeorgiyDemo on GitHub · 2026-11-25 01:20 UTC · original

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.

**@⁠GeorgiyDemo** on GitHub · 2026-11-25 01:20 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1481#issuecomment-7149445898) 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.
Author
Owner

@⁠tyr0nsur on GitHub · 2026-11-25 02:03 UTC · original

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

**@⁠tyr0nsur** on GitHub · 2026-11-25 02:03 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1481#issuecomment-7150267206) 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)
Author
Owner

@⁠tiguan26 on GitHub · 2026-11-25 06:01 UTC · original · approved these changes

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).

**@⁠tiguan26** on GitHub · 2026-11-25 06:01 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1481#pullrequestreview-6052594652) · **approved these changes** 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).
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1481/head:github-bot/gh-1481'
git switch 'github-bot/gh-1481'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1481'
git switch 'github-bot/gh-1481'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1481'
git switch 'github-bot/gh-1481'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1481'
git switch 'main'
git merge --squash 'github-bot/gh-1481'
git switch 'main'
git merge --ff-only 'github-bot/gh-1481'
git switch 'main'
git merge 'github-bot/gh-1481'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.