Skip to content

rdna2spirv: honour unorm coordinates on samples and zero-LOD gathers - #8467

Open
Kalmarv wants to merge 1 commit into
ItsNotRexed:mainfrom
Kalmarv:fix/texture-unorm
Open

Kalmarv wants to merge 1 commit into
ItsNotRexed:mainfrom
Kalmarv:fix/texture-unorm

Conversation

@Kalmarv

@Kalmarv Kalmarv commented Nov 23, 2026 •

Copy link
Copy Markdown

The supported image_sample forms and image_gather4_lz(_o) ignore the instruction's unorm bit, so texel-unit coordinates are read as normalized coordinates. In the new synthetic fixture all 4,096 pixels sample the clamped edge on main. With this change all 4,096 match the independently derived expected texels.

The translator divides spatial coordinates and explicit gradients by the image's level-0 size, preserving array layers, offsets, bias, depth references and explicit LOD operands. It adds focused semantic coverage, a hand-written GPU fixture registered through TEXTURE_CONSTANTS, and the contract row in docs/design.md.

Claim: #8344 (comment)
Tracking: Kalmarv#1
Related: #8154. Its explicit-LOD gather path and the owned run-time descriptor LOD work are unchanged.

Validation at 1510544, Windows 11, RTX 5070 Ti, NVIDIA 610.74:

  • New semantic file: 15/15 pass with spirv-as/spirv-val. The earlier 14-case version failed 13 cases on unmodified base; the no-unorm control passed. The final image_sample_c_l refusal case was added afterwards.
  • ps_sample_unorm GPU fixture: before, 4096/4096 pixels are (63,63,63,4095); after, 4096/4096 are the expected (42,14,28,1827). The fixture exercises image_sample_lz, image_sample_l at LOD 0, implicit image_sample and image_gather4_lz. Both builds pass spirv-val.
  • Used the existing vk_texture_test executable from dde82f2; its source is identical at the branch base 6dda063.
  • git diff --check and check_no_game_data.py pass.
  • Full translator semantic suite on this head: 448 files / 5,971 tests, 259 seconds with two workers, exit 1. Only the three baseline files fail: test_image_atomics_guard (47 failures), test_image_cube_store_glc (1 error), test_image_store_d16 (1 failure). Each was also checked on unmodified base 6dda063 with identical counts. No new failures; all 15 new semantic tests pass. This is not a claim that main has a green suite.

Limits: the expectation uses LLVM's UNRM definition and the Vulkan coordinate rule, not a native RDNA2 measurement. Nonzero explicit LOD behavior remains unmeasured. Cube+unorm is refused; image_sample_c_l+unorm remains refused. image_get_lod+unorm is outside this change. No game-corpus counts, retail run, AMD/Intel validation or Vulkan validation-layer run. Setting LEONIDA_VK_VALIDATION=1 in a repeat did not establish that a layer was loaded.

AI-assisted implementation and testing with Claude Code, reviewed by the coordinating Codex agent. Synthetic inputs only.

ISA reference: AMD's machine-readable ISA, amdgpu_isa_rdna2.xml version 1.1.1, MIMG UNORM bit 12, specifies forcing unnormalized addresses independently of the sampler setting. This establishes the bit's purpose; it does not supply the missing nonzero-LOD hardware measurement.

The unorm bit forces texel-unit coordinates, but image_op ignored it on the
samples and image_gather4_lz(_o): the same SPIR-V was emitted with and
without it, so texel coordinates were sampled as normalized ones. Each
spatial coordinate (and each _d gradient) is now divided by the image's
level-0 size; array layers, an explicit LOD, bias, depth reference and
texel offsets are left as they are. A cube with unorm is Unsupported.
The explicit-LOD gathers keep their own handling (ItsNotRexed#8154).

GPU fixture ps_sample_unorm: RTX 5070 Ti (610.74), 4096/4096 pixels match
after, 4096/4096 read the clamped last texel before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Zipettte

Copy link
Copy Markdown

Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), AMD Windows driver 32.0.32029.2010, Windows 11, at 1510544. I used vk_texture_test built from dde82f2 with llvm-mingw, and llvm-mc 23.

run_gpu_tests.py --filter ps_sample_unorm             (2 runs)  PASS  4096/4096 pixels exact
same fixture, tools/rdna2spirv.py from main (control)            FAIL  4096 pixels differ from (42, 14, 28, 1827)

On AMD the fixture fails without the fix and passes with it, the same as on your RTX 5070 Ti. test_sample_unorm.py passes.

AI-assisted (Claude Code).

@Kalmarv
Kalmarv marked this pull request as ready for review November 23, 2026 18:53
@morodirule

Copy link
Copy Markdown

Tested 1510544 on Arch Linux + RTX 4070 (NVIDIA 620.70, llvm-mc 23.1.5): pass. Semantic test_image_tfe_status 15/15 OK (needs discover runner for the sys.path import); base translator fails 13. GPU fixture ps_sample_unorm runs natively: 4096/4096 pixels exact, spirv-val clean. No game files. AI-assisted.

@Envyre

Envyre commented Nov 23, 2026

Copy link
Copy Markdown

Code read + run of the PR head (Windows 11, Python 3.11; semantic suite 5971 tests, only test_image_atomics_guard and test_image_store_d16 fail, as on main; test_sample_unorm 15 OK + 1 skip): the approach looks right. Normalizing the coordinates avoids the unnormalizedCoordinates sampler and its VUIDs; array layers aren't divided (unnormalized_sizes, tools/rdna2spirv.py:11951); _d gradients are divided while bias, depth reference and texel offsets are left alone; gathers need no +0.5; refusing cube with unorm is reasonable.

One gap: image_gather4_l / image_gather4_l_o are excluded from unorm (:12610-12611), but their own path never checks the bit and still computes uv * size at :12664, so image_gather4_l ... dim:SQ_RSRC_IMG_2D unorm translates to exactly the same SPIR-V as without unorm and texel coordinates get scaled by the size a second time. Three places say these gathers "apply unorm in their own texel arithmetic", which only holds for GATHER4_LOD_OPS (emit_gather4_lod, :12315): the comment at :12605, docs/design.md:318, and the docstring of tests/semantic/test_sample_unorm.py:8. Using st = uvf there when unorm is set (as emit_gather4_lod does), or raising Unsupported, plus a test that unorm changes or refuses the output, would close it.

AI-assisted (Claude Code).

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

Independent Linux CPU review (15105444)

What changed: image_sample* / image_gather4_lz honour the MIMG unorm bit (normalized coords) in the translator; new semantic coverage + a GPU fixture listing.

Checked:

  • python3 -I -m unittest discover -s tests/semantic -p test_sample_unorm.py → 15 OK (1 skipped).

Looks correct; no game files.

@rideinstead

Copy link
Copy Markdown

TEST validation — Needs changes

Validated on CPU (no GPU, no game files). Semantic test passes cleanly.

What changed: tools/rdna2spirv.py — honours the MIMG unorm bit on image_sample* and image_gather4_lz(_o) by dividing spatial coordinates (and _d gradients) by the image's level-0 size before the Vulkan sample/gather. Cube with unorm marked Unsupported.

Tests added:

  • tests/semantic/test_sample_unorm.py — 15 cases (14 original + 1 added image_sample_c_l refusal). Previously 13 failed on base; with the fix all 15 pass
  • runtime/test/shaders/ps_sample_unorm.asm — GPU fixture (8×8 gradient) run through vk_texture_test
  • runtime/test/shaders/check.py — registers expected pixel values
  • docs/design.md — documents the unorm handling contract

Verification:

  • Author: full translator semantic suite on head → 448 files / 5,971 tests, exit 1 (only 3 pre-existing failures: test_image_atomics_guard, test_image_cube_store_glc, test_image_store_d16, each confirmed identical on unmodified base 6dda063)
  • GPU validation on RTX 5070 Ti: 4096/4096 pixels pass after, all 4096 failed before
  • Independently replicated on AMD Radeon RX 7700 XT (RDNA3) and Arch Linux + RTX 4070, both passing
  • Grimkeh (Linux CPU review): confirmed semantic test passes, no game files
  • Envyre (Windows 11, Python 3.11): full semantic suite 5,971 tests

Reviewer-identified gap (blocking): image_gather4_l / image_gather4_l_o unorm handling — these gathers are excluded from the unorm division but their path at tools/rdna2spirv.py:12664 still computes uv * size, so with unorm set they'd scale texel coordinates by size a second time. Three code/doc locations claim they "apply unorm in their own texel arithmetic," but that only holds for GATHER4_LOD_OPS (emit_gather4_lod). Suggested fix: use st = uvf when unorm is set (as emit_gather4_lod does) or raise Unsupported, plus a corresponding test.

Other non-blocking notes:

  • No RDNA2 hardware validation — expectation uses LLVM's UNRM definition and Vulkan coordinate rule
  • Nonzero explicit LOD behavior remains unmeasured
  • AI-assisted (Claude Opus 5.5)

Recommendation: Needs changes — close the image_gather4_l/image_gather4_l_o unorm gap before merging. After that, the CPU-testable portion (semantic test passes 15/15) is ready to approve.

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

This covers the validation-layer run listed as missing in the description. vk_texture_test doesn't read LEONIDA_VK_VALIDATION, so I forced the layer through the loader instead (VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation) and sent its messages to a file (VK_KHRONOS_VALIDATION_LOG_FILENAME, VK_KHRONOS_VALIDATION_DEBUG_ACTION=VK_DBG_LAYER_ACTION_LOG_MSG). Setup: 1510544 applied on main e68c5c9, Windows 11 26200, RTX 3060 (Ampere), NVIDIA 610.88, Vulkan SDK 1.4.363.1, llvm-mc 23.1.6.

run_gpu_tests.py --filter ps_sample_unorm Result Layer log
core + VALIDATE_SYNC=1 PASS, 4096/4096 exact empty
core + sync + GPUAV_ENABLE=1 PASS, 4096/4096 exact 0 errors, 0 SYNC-HAZARD; only the layer's own VALIDATION-SETTINGS / Setting-Limit-Adjusted warnings, which show it was loaded

GPU-AV also checks image reads against the bound view's numeric type and buffer bounds at run time, and it reports nothing for the fixture's four sample/gather forms.

Also on this GPU: native and LEONIDA_W64_EMULATE=1 both PASS. With main's rdna2spirv.py and the PR's fixture, all 4096 pixels differ, matching the controls above. The whole GPU suite (emulated) goes from 223/241 to 224/242, and the only failure is the known ms_wave_info_s3.

No game files. AI-assisted run.

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.

7 participants