Skip to content

Honor texel coordinates in explicit-LOD gathers - #8154

Open
gautch29 wants to merge 1 commit into
ItsNotRexed:mainfrom
gautch29:codex/gather-unorm
Open

gautch29 wants to merge 1 commit into
ItsNotRexed:mainfrom
gautch29:codex/gather-unorm

Conversation

@gautch29

Copy link
Copy Markdown

Coordination claim

Depends on: #7097, #4321 (overlap in the same lowering only). This branch is based on current main and applies independently.

What changed

The 2D explicit-LOD lowering for image_gather4_l and image_gather4_l_o always multiplied XY by the mip dimensions. RDNA2’s UNRM instruction bit already supplies texel coordinates. This patch uses those coordinates directly and preserves the existing half-texel bias, signed offsets, and sampler address modes.

The hand-written regression samples an 8 × 8 gradient and checks both UNRM forms, positive and negative offset components, and a normalized control.

Verification

  • Apple M3 Pro, macOS 27.0, MoltenVK 1.4.2, LLVM 23.1.6, SPIRV-Tools 1.4.363.0. The new fixture failed on main and matched all 4,096 pixels with this change. All five GPU gather cases passed.
  • Six assembled shader modules passed spirv-val. All 13 gather semantic tests passed.

Synthetic fixtures only. AI-assisted (Codex).

@matheusfermiano-source

Copy link
Copy Markdown

Independent GPU check of 9cdfefd5f2aca8d600c7c2f07501d0300023a294 on AMD Radeon Vega 8 (Ryzen 7 5825U, gfx90c), RADV Mesa 26.2.6-arch3.1, Vulkan 1.4.354, CachyOS 7.3.3-1-cachyos.

  • python -I scripts/run_gpu_tests.py --build <build-dir> --filter gather --require-pass passed 5/5 GPU cases with no skips. All six generated modules passed spirv-val.
  • ps_gather_unorm matched 4,096/4,096 pixels on the PR. Using the same fixture, test runner and Vulkan binary with only tools/rdna2spirv.py restored to the base commit dde82f2 gave 0/4,096 matches. The base returned (7, 7, 7, 3) throughout and the PR returned the expected (3, 5, 4, 3).
  • python -m unittest discover -s tests/semantic -p 'test_*gather*.py' -v passed 13/13.

LLVM 23.1.4, SPIRV-Tools 2026.4 and GCC 16.2.1. Synthetic fixtures only. AI-assisted (Codex).

@ECHOZwei

Copy link
Copy Markdown

Tested 9cdfefd5f2aca8d600c7c2f07501d0300023a294 on Windows 11 (MSVC 14.51 / Visual Studio Community 2026, RelWithDebInfo, Vulkan SDK 1.4.363.0, LLVM 23.1.6, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation) on two GPUs (synthetic shaders only; no game files): pass

  • Negative control (tools/rdna2spirv.py at HEAD~1): python -I scripts/run_gpu_tests.py --build runtime/build --filter ps_gather_unorm fails as expected (4096 pixels differ from (3.0, 5.0, 4.0, 3.0), exit 1); restored to HEAD, passes cleanly.
  • NVIDIA GeForce RTX 4080 SUPER (driver 621.01, validation on):
    • python -I scripts/run_gpu_tests.py --build runtime/build --filter gather: 5/5 passed (ps_gather4_c_l, ps_gather_border, ps_gather_sampler_lod, ps_gather_unorm, ps_gather_wrap; 6/6 pass spirv-val, 4096/4096 pixels exact), 0 validation errors.
  • AMD Radeon(TM) Graphics iGPU (driver 25.10, LEONIDA_VK_DEVICE=AMD, validation on):
    • Same --filter gather run: 5/5 passed (4096/4096 pixels exact), 0 validation errors.
  • python -I tests/semantic/test_image_gather4_variants.py: 13/13 OK (4.819s).
  • git diff --check and python -I scripts/check_no_game_data.py on all 4 modified files: clean (exit 0).
  • Code review: passing unorm=unorm in mods to gather_addr_modes() matches rdna2spirv.py:12219, and skipping OpConvertSToF/OpFMul for unorm cleanly preserves the half-texel bias, signed offsets, and address modes.

AI-assisted.

@lordra9-svg

Copy link
Copy Markdown

Independent check of 9cdfefd5f2aca8d600c7c2f07501d0300023a294 (PR head) on AMD Radeon RX 7800 XT (RDNA3, gfx1101), RADV Mesa 26.3.1, Vulkan 1.4.363, Linux (Bazzite 45), llvm-mc 23.1.6, SPIRV-Tools v2026.4.

Build — python3 -I runtime/test/shaders/build.py: 271 shaders, 271 translated, 271 pass spirv-val.

GPU (check.py, fresh RelWithDebInfo Linux build of the test programs at the PR head) — 209 of 212 pass, 3 skipped, no failures. The three skips are the mesh fixtures ms_w64x_ballot, ms_wave_info_s3 and ms_v5_workgroup that only scripts/run_gpu_tests.py builds.

  • ps_gather_unorm ok — (3, 5, 4, 3), unnormalized, offset and normalized control all as derived in the .asm
  • the four existing gather cases also pass: ps_gather_wrap, ps_gather_border, ps_gather4_c_l, ps_gather_sampler_lod

Differential against main — the same new fixture, built with tools/rdna2spirv.py from main dde82f27e and run through the PR's check.py on the same device:

ps_gather_unorm      4096 of 4096 pixels differ from (3.0, 5.0, 4.0, 3.0)

So the fixture does fail on main and the lowering change is what makes it match on RADV, not the test or the device.

CPU — python3 -I tests/semantic/test_image_gather4_variants.py: 13 tests, OK.

Synthetic fixtures only; no game data. AI-assisted (OpenCode).

@lohant27-netizen

Copy link
Copy Markdown

Tested 9cdfefd5f on Windows 11 (10.0.26300), NVIDIA GeForce RTX 5070 (driver 32.0.16.2101, subgroup 32), MSVC with SDK 10.0.26100, Release, llvm-mc 21.1.8 (AMDGPU, built with scripts/build_llvm_mc.ps1): pass.

  • run_gpu_tests.py --filter ps_gather: 5/5, ps_gather_unorm 4096/4096 pixels exact. The four existing gather tests also pass on main before the change.
  • Negative control: ps_gather_unorm translated with main's rdna2spirv.py fails (4096 pixels differ), so the new test catches the bug.

@kamilolejnik

Copy link
Copy Markdown

Tested 9cdfefd on Intel Iris Xe Graphics (TGL GT2, Xe-LP), Mesa ANV 26.3.1, Vulkan 1.4.363, Linux 6.12 (Arch container), llvm-mc 23.1.5, SPIRV-Tools v2026.4: pass. The first Intel run.

run_gpu_tests.py --filter ps_gather:

tree ps_gather_unorm other four gathers
this PR 4096/4096 exact all pass
negative control: this PR's fixture with tools/rdna2spirv.py reverted to the merge-base dde82f27e FAIL (4096 pixels differ) all pass

The "other four gathers" are ps_gather4_c_l, ps_gather_border, ps_gather_sampler_lod and ps_gather_wrap. So the UNRM explicit-LOD gather goes wrong on ANV without the change and is exact with it.

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

@PingasMech

Copy link
Copy Markdown

I tested this PR together with #7097 and #4321 on a Windows Intel UHD 770. All 65,536 pixel readbacks matched all four expected gather taps across 16 synthetic 2D-array draws. I started from 9cdfefd5f, merged #4321 at b6a341ede, then #7097 at fb32681dc.

Three choices matter when resolving the conflicts in tools/rdna2spirv.py. I changed each one separately and reran the same draws.

Tested merge resolution What happened when reverted
Keep #7097’s array layer in f[2] and read LOD from f[ncoord]. Reading LOD from f[2] broke exactly the eight draws whose layer and expected mip differed.
Feed that LOD through #4321’s 8-fraction-bit rounding before clamping to the view. Restoring the old rounding picked mip 0 at 0x3eff0000. All eight draws at that value failed. The adjacent lower input, 0x3efeffff, still passed.
Keep this PR’s unorm argument to gather_addr_modes. Use XY directly for UNRM and multiply normalized XY by #7097’s two-component sz2. Multiplying both forms by the mip dimensions broke all eight UNRM draws. The eight normalized controls passed.

The array texture encoded X, Y, layer and mip in each texel’s red byte. The matrix crossed two layers, the adjacent LOD values above, normalized or texel coordinates, and plain gather or signed offset (+1, -1). Each control changed 32,768 of 65,536 pixels. The PR’s original 2D fixture also matched all 4,096 pixels. All 18 modules for the combined run passed spirv-val, and the three translator/semantic test files passed (688 tests, 258 subtests).

This checks the translated 2D-array path on Intel. Native RDNA2 array-UNRM behavior and cube seams remain outside this run. Synthetic inputs only. AI-assisted.

@Ekabusto

Copy link
Copy Markdown

Tested 9cdfefd5f on AMD Radeon RX 9070 XT (RDNA4), AMD driver 26.11.2, Windows 11 10.0.26300: pass.

  • Full scripts/run_gpu_tests.py: 225/242 passed, 16 skipped. Against main on the same card (224/241), the only
    difference is the new ps_gather_unorm: PASS, 4096/4096 pixels exact. The other gather fixtures are unchanged
    and pass (ps_gather4_c_l, _border, _sampler_lod, _wrap, ps_texoff_forms).
  • Negative control: the same fixture with main's tools/rdna2spirv.py fails: "4096 pixels differ from
    (3.0, 5.0, 4.0, 3.0)". So the fixture catches the bug on AMD hardware too.
  • The one suite failure, ms_wave_info_s3, is on main too and is intermittent on this card (ms_wave_info_s3 intermittently fails on RX 7900 XT / RADV NAVI31 (pass rate 100% -> 2.5%, same binaries) #6172).

AI-assisted: yes (Claude ran the build and tests; results checked by me).

@rojasruiz

Copy link
Copy Markdown

Tested 9cdfefd (on main dde82f2) on a second GPU vendor: NVIDIA GeForce RTX 3080, driver 615.78.08 (native driver, no MoltenVK/SPIRV-Cross), Linux 7.2.15; llvm-mc 23.1.3, SPIRV-Tools v2026.4: pass, with a negative control.

run_gpu_tests.py --filter ps_gather, test programs built from this tree:

translator ps_gather_unorm other 4 gather fixtures
main's tools/rdna2spirv.py (fixture rebuilt with it) FAIL: 4096 pixels differ from (3.0, 5.0, 4.0, 3.0) PASS
this branch PASS, 4096/4096 exact PASS

So the fixture catches the old lowering on NVIDIA as well as on your M3.

  • Full run_gpu_tests.py: 193/242, 48 skipped. main is 192/241, and the extra pass is ps_gather_unorm. The one failure is the known ms_wave_info_s3, on both.
  • scripts/run_semantic_tests.py tests/semantic: 447 files / 5,956 tests, the same as main. Only the 2 files already red there fail (test_image_atomics_guard, test_image_store_d16).
  • check_no_game_data.py on the four files: clean.

AI-assisted (Claude Code).

@harrisotiropoulos-jpg

Copy link
Copy Markdown

Tested 9cdfefd5f (this PR's diff applied onto main 1bd565f) on an NVIDIA GeForce RTX 4080, driver 621.01, Windows 11, subgroup 32..32: pass. This is the first NVIDIA check of this head.

Test programs: the Runtime workflow's runtime-windows artifact built from 1bd565f (this PR changes no C++). llvm-mc 23.1.6 (conda-forge llvm-tools), Vulkan SDK 1.4.363.0 (spirv-as/spirv-val), Python 3.12.10.

Check Result
Control: run_gpu_tests.py --filter gather with main's translator plus this PR's ps_gather_unorm.asm and check.py 4/5: ps_gather_unorm FAIL ("4096 pixels differ from (3.0, 5.0, 4.0, 3.0)"); ps_gather4_c_l, ps_gather_border, ps_gather_sampler_lod and ps_gather_wrap pass
run_gpu_tests.py --filter gather with this PR, 3 runs 5/5 each run; ps_gather_unorm 4096/4096 pixels exact. ps_gather_wrap, the case that sent #1363 back on an RTX 4060 Ti, stays 4096/4096
test_image_gather4_variants.py 13/13 OK
Full run_gpu_tests.py, native 247/247 translated and spirv-val valid; 192/241 passed, 48 skipped. main gives 191/240 on the same machine, so the only difference is the new test, which passes. The one failure is ms_wave_info_s3, the same as on main (#5741 / #7136)
Full run_gpu_tests.py, LEONIDA_W64_EMULATE=1 223/241 passed, 17 skipped (main: 222/240)
scripts/run_semantic_tests.py tests/semantic 446 files, 5,951 tests: the same 3 files fail as on main (test_image_atomics_guard, test_image_store_d16, test_image_cube_store_glc; see #7284). None is touched here

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

@philip-roy-jones

Copy link
Copy Markdown

On my Windows 11 Radeon RX 580 (AMD 26.5.2, Vulkan 1.3.260), the new ps_gather_unorm fixture returned (3, 5, 4, 3) at all 4,096 pixels on 9cdfefd5. I ran the identical fixture on its direct parent dde82f27 and got (7, 7, 7, 3) at every pixel. The two channels using the signed texel offset (+2, -1) read 5 and 4 on the PR. The normalized control read 3 on both revisions. The four existing gather cases also matched their references on both, including both sampler-LOD draws.

The default 144-byte layout skipped all five cases on this 128-byte card (native exit 77). With LEONIDA_PC_TAIL_UBO=1, scripts/run_gpu_tests.py --filter gather --require-pass passed 5/5 on the PR and 4/5 on the parent. Both runs reported two FP16 denormal validation errors per draw. I repeated them with only the translator option --no-denorm-preserve from #4988 added to each revision. FP32 preservation stayed enabled, all six frame readbacks per revision were byte-identical to the preceding run, and Vulkan core and synchronization validation reported zero warnings or errors.

Synthetic shaders and textures. AI-assisted.

@matheusfermiano-source

Copy link
Copy Markdown

Tested 9cdfefd5f (the PR's diff applied on main dde82f2), full python -I scripts/run_gpu_tests.py, each GPU compared with main on the same machine and binaries, CachyOS Linux: pass.

GPU Driver main this PR Difference
AMD Radeon 660M (RDNA2 iGPU, gfx1035, Ryzen 5 7535HS), subgroup 32..64 RADV, Mesa 26.3.1 225/241 passed, 16 skipped 226/242 passed, 16 skipped new PASS: ps_gather_unorm
NVIDIA GeForce RTX 3050 Laptop (Ampere), subgroup 32 NVIDIA 620.73.04 192/241 passed, 48 skipped 193/242 passed, 48 skipped new PASS: ps_gather_unorm; fails on main too: ms_wave_info_s3 (#6172)
AMD Radeon Vega 8 (GCN 5 iGPU, gfx90c, Ryzen 7 5825U), subgroup 64 RADV, Mesa 26.2.6 193/241 passed, 48 skipped 194/242 passed, 48 skipped new PASS: ps_gather_unorm

No game files. AI-assisted (Claude Code).

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.