Skip to content

Preserve integer texels in 2D GATHER4_LZ and D16 packing - #1291

Merged
ItsNotRexed merged 3 commits into
ItsNotRexed:mainfrom
Vonsek:codex/typed-gather-lz
Nov 22, 2026
Merged

ItsNotRexed merged 3 commits into
ItsNotRexed:mainfrom
Vonsek:codex/typed-gather-lz

Conversation

@Vonsek

@Vonsek Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: #1218 (comment)

What and why

A 2D image_gather4_lz with d16 returned zeros for UINT texels and -1 for SINT texels. The translator read all views through float sampled images and packed the result as two half floats per VGPR. GFX10 MIMG D16 instead uses the image format to select integer or float narrowing (AMD RDNA 2 ISA, §8.2).

Use the sampled array's numeric-type aliases from #1153 to issue the 2D gather, sharing image_load's result packing. DMASK selects the texture component and four gathered taps reach the destination. The signed-offset form uses the same selection. The checked-in regression verifies binding 0, the component index and the low/high integer pairs. It fails on main for both packed and unpacked gathers.

Tested

Windows 11, NVIDIA RTX 5080 (616.92, Vulkan 1.4.351) and AMD Radeon Graphics (32.0.21045.16010, Vulkan 1.4.315). Synthetic RDNA2 shaders assembled with llvm-mc and translated through Leonida. I used vk_image_fuzz with a 64×64 RGBA32F target, an 8×8 RGBA8 source and a nearest clamp-to-edge sampler. Green held 128 + 8*y + x, red held 3. The CPU oracle used each pixel's 2×2 footprint, including clamped edge pixels.

D16 green gather at the center Main on both GPUs This change on both GPUs
R8G8B8A8_UINT 0, 0, 0, 0 163, 164, 156, 155
R8G8B8A8_SINT -1, -1, -1, -1 -93, -92, -100, -101

Every one of the 4,096 pixels on each GPU failed both integer D16 cases before the change. Afterward, all four channels matched in every pixel for UINT, SINT and UNORM, unpacked and D16, both with no offset and with offset (+1,-1). All 12 draws per GPU passed GPU-assisted Vulkan validation; the offset runs enabled shaderImageGatherExtended. Changing the gathered component from green to red made all 4,096 pixels fail for each of the six no-offset combinations on both GPUs.

Six no-offset synthetic PS inputs translated and passed spirv-val before and after; all six additional offset PS inputs passed on this head. No full game-corpus count was measured. Integer texels were in range for 16-bit packing; the existing uncertainty for out-of-range narrowing is documented in docs/design.md.

The typed-load and translator Python tests passed (342 passed, 2 skipped, 14 subtests passed), as did the gfx10_descriptors CTest.

Checklist

  • No game data, keys or decryption, including in logs or reports quoted here.
  • The translator rule and its hardware confirmation are in docs/design.md.

AI-assisted implementation and testing.

Packing integer gather results as half floats discarded the texture values in both signed and unsigned views. Use the descriptor format for the Vulkan image type and pack each integer pair into its destination register.
@bobcatchris

Copy link
Copy Markdown
Contributor

Independent CPU-side verification of 4155021b on Windows 11, Python 3.12.10; no GPU, corpus or game data:

  • python -m pytest -q tests/test_image_load_typed.py tests/test_image_load_d16_typed.py tests/test_translate.py: 342 passed, 2 skipped.
  • python -m compileall -q tools/rdna2spirv.py tests/test_image_load_typed.py: clean.
  • Negative control with this PR's test_image_load_typed.py copied into a detached main (e7584c52) worktree: 1 failed, 6 passed. The new gather test fails there because the emitted gather types lack both %v4uint_st and %v4int_st; so it pins the typed integer path.

Static review agrees with the new contract row: the typed branch is taken only for 2D image_gather4_lz(_o), dmask still selects the green/selected channel via bit_length()-1, and the d16 packing reuses the existing low-half-first integer pair writer. The extra OpTypeSampledImage declarations are gated on uses_int_gather and di == 0, matching the sampled binding 0 the test checks.

I did not run the GPU fixtures; the RTX 5080/Radeon pixel evidence remains the author's measurement. From the CPU checks, this looks ready.

@kapitche

Copy link
Copy Markdown
Contributor

Tested on Windows 11 with two GPUs on one machine (runtime built from this PR's head, MSVC 14.51): pass. ctest: 59/59. On both the RTX 4080 SUPER and the Intel UHD 770:

  • --filter gather: ps_gather_sampler_lod (both passes exact, wrong mip and UV rejected) and ps_gather_wrap 4096/4096;
  • --filter cs_img: 3/3.

Typed gathers emit three parallel image operations. Check that all of them apply the same signed offset so a missing or divergent operand remains observable.
# Conflicts:
#	docs/design.md
#	tools/rdna2spirv.py
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.

4 participants