Repository navigation
Translator: gather LOD ties select the upper mip (SHADER-152) - #1074
Conversation
native OpImageGather Lod (VK_AMD_texture_gather_bias_lod) selected mip 1 on Radeon Graphics 26.10.1 while the emulation's RoundEven selected mip 0. image_gather4_l(_o) now picks the mip as Floor(clamp(LOD) + 0.5): ties go up like the native draw, and every non-tie LOD selects the same mip as before. The [0, levels-1] clamp is unchanged. Tests: 232 gather sites in the 16 corpus shaders that use image_gather4_l/_o now emit FAdd+Floor instead of RoundEven and still assemble and pass spirv-val (16/16 translated, 16/16 valid, 946 fetches unchanged); a 200-shader corpus slice is 200/200 translated and valid before and after; the full suite passes (3498 passed, 61 skipped). The 0.5 rule is the Radeon measurement; the guest's own gfx1013 tie behaviour is still not hardware-verified.
4fa8336 to
c22798e
Compare
whattheflop
left a comment
There was a problem hiding this comment.
AI-assisted Windows Vulkan verification of c22798eed5a4f0f6e2a8242aec363a1271712613 against parent 48ad23f0, using the synthetic two-mip RGBA8 fixture with isolated ICDs.
Radeon Graphics iGPU 25.10.30.02 and RTX 3080 616.64 both passed the stock minLOD/maxLOD checks (4/4 draws total). For LODs 0.5 - 1/256, 0x3effffff, 0.5, 0x3f000001, and 0.5 + 1/256, parent mips were 0,0,0,1,1 and this head chose 0,1,1,1,1 on both GPUs (4,096 pixels per draw). The exact tie moves up as intended. The adjacent lower float32 also moves up because FAdd rounds to 1.0 before Floor, so the description's claim that every non-tie is unchanged needs narrowing. All five Radeon draws matched the saved native AMD OpImageGather Lod output pixel for pixel. The stock sampler-bound checks passed here, and #1032 concerns a separate RX 7900 XTX result.
7/7 synthetic modules passed spirv-val. Khronos validation 1.4.363 loaded for all 14 draws with zero errors. Windows 11 build 26200, uv-managed Python 3.14.5, LLVM 21.1.8, SPIRV-Tools 2026.4 RC2.
|
Note on CI: the |
# Conflicts: # docs/design.md
|
Tested c22798e (on main) on AMD RDNA2 iGPU and RTX 5070: pass, native and emulated. Windows 11 Home 10.0.26300, llvm-mc 21.1.8 (AMDGPU, native), Vulkan SDK 1.4.363.0, MSVC 14.44.35207, Python 3.14.7,
AI-assisted (Claude Code). No game files. |
Claimed in the coordination issue as: SHADER-152 (claim). Depends on: #973 (merged).
What and why
image_gather4_l(_o)emulates the explicit-LOD gather with fourOpImageFetch, and chose the mip withRoundEven(LOD). #973's contract row records the difference found while checking the sampler LOD bounds: on Radeon Graphics 26.10.1, with an RGBA8 two-level view, nearest mip filtering and bounds [0,1] at UV (0.25,0.25), nativeOpImageGather Lod(VK_AMD_texture_gather_bias_lod) picked mip 1 at exactly LOD 0.5, whileRoundEvenpicked mip 0 (0.5 ± 1/256 agreed: mip 0 and 1).This changes the mip to
Floor(clamp(LOD, S# MIN_LOD, MAX_LOD) + 0.5): exact ties go up like the native draw; every non-tie value selects the same mip as before, and the existing [0, levels−1] clamp is unchanged. Onlyimage_gather4_l/_l_oare touched.New tests in
tests/test_translate.pypin the emitted sequence (clamped LOD →FAddof%fhalf_g→Floor, noRoundEvenon the LOD), and a table covers negative and near-tie LODs plus the level-range clamp, with the old behaviour as the negative control (0.5 → 0, 2.5 → 2).docs/design.mdnow states the rule in both gather rows; the "Other additions" row keeps #1017's d16 packing sentence.Tested
CPU-only: WSL, Python 3.14, LLVM 21
llvm-mc, SPIRV-Tools v2026.1. No GPU run — the machine here has no Vulkan runtime build (RTX 3070 Ti only); the 0.5 rule is @Vonsek's Radeon Graphics 26.10.1 measurement above, and the guest's own gfx1013 tie behaviour is still not hardware-verified.spirv-valin both.image_gather4_l/_l_o(with their FSSM sidecars), before and after: 16/16 translated and 16/16 valid in both;OpImageFetchcount unchanged (946). Normalising the temp ids, the only text differences are the 232 gather sites: oneRoundEvenout,FAdd+Floorin, plus theNoContractiondecoration on the newFAdd.python -m pytest testsat the rebased tip: 3,645 passed, 63 skipped, 22,574 subtests passed (the usual tool-dependent skips).Checklist
docs/design.md, with how it was confirmed.AI-assisted: the change, tests and this description were written with an AI assistant. #1017 merged after this was opened and edits the same function, so the branch is rebased onto 48ad23f (and its docs conflict resolved by keeping both rows' sentences).