Skip to content

rdna2spirv: texel offset fallback picks the level by the S# mip filter (SHADER-699) - #3882

Closed
tupacfan04 wants to merge 2 commits into
ItsNotRexed:mainfrom
tupacfan04:shader-699-texoff-mip-filter
Closed

tupacfan04 wants to merge 2 commits into
ItsNotRexed:mainfrom
tupacfan04:shader-699-texoff-mip-filter

Conversation

@tupacfan04

@tupacfan04 tupacfan04 commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: SHADER-699 (claim, from @whattheflop's finding)

What and why

--texel-offset-fallback folds an image_sample*_o offset into the coordinate as offset / size of the sampled level. Gen.texel_offset_fold always floored the LOD to pick that level. A nearest-mip sampler rounds instead, so at LOD 0.75 the sample reads mip 1 while the offset was scaled by mip 0's size. @whattheflop's example: 8×8 base, offset (−1, +1), UV (0.6875, 0.5625). The fold lands on mip-1 texel (2, 2), but the native offset selects (1, 3).

The fold now rounds the LOD the way the S#'s MIP_FILTER (word 2 [27:26]) picks a level, matching how the runtime builds the VkSampler (runtime/src/gfx10_descriptors.h, vulkan_sampler):

MIP_FILTER Runtime sampler Folded level
2 linear MIPMAP_MODE_LINEAR floor(lod), unchanged (the documented two-level approximation)
1 point, 3 MIPMAP_MODE_NEAREST nearest, a tie rounds up: floor(lod) + (lod − floor(lod) ≥ 0.5)
0 none nearest, LOD held in [0, 0.25] 0

A literal S# word 2 (from s_mov_b32 in the same block, via sgpr_imm, as gather_addr_modes already does) emits only the rounding it needs. A run-time S# extracts the field and selects. Either way the result is still clamped to the image's levels.

The nearest level isn't computed as floor(lod + 0.5), because the binary32 sum rounds: 0x3f000001 + 0.5 and 0x3effffff + 0.5 both round to exactly 1.0. floor(lod) and lod − floor(lod) are exact, so the fraction is compared with 0.5 directly. A tie rounds up, which is what RTX 5070 GPUs measured on this PR (@kacper-serewis on 616.56, @jeremygold02 on 621.01): native LOD 0.5 samples mip 1. tools/image_query_probe.py records the same for RDNA2. For OpImageQueryLod (implicit samples), an x that a driver already rounded to an integer stays the same.

Not changed:

docs/design.md (the Texel offsets row) is updated with the rule.

Tested

  • tests/test_texel_offsets.py: new test_fallback_level_follows_mip_filter. It evaluates the emitted level chain (the level operand of OpImageQuerySizeLod) for image_sample_l_o with a literal S# and with a run-time S#. Float results are rounded to binary32, as the module computes them. Cases: point at LOD 0.75 → 1 (the finding), 0.25 → 0, 0x3effffff → 0, 0.5 → 1, 0x3f000001 → 1, 0x3f000002 → 1, 2.6 → 3, 9.0 → 3 (clamped to 4 levels), −1 → 0; MIP_FILTER 3 at 0.75 → 1; linear at 0.75 → 0 and 1.99 → 1; none at 2.75 → 0. New test_fallback_literal_mip_filter_emits_one_rounding. Result: 44 passed, including the spirv-val cases (Vulkan SDK 1.4.363). Negative controls: unmodified main fails the new tests. The first head, d1dea0ad, fails exactly the 0.5 and 0x3f000001 cases, the two rows @jeremygold02 measured as wrong on the GPU. The evaluator now agrees with all five native rows of that table.
  • GPU, NVIDIA GeForce RTX 5070, driver 621.24, Windows 11 26300, LEONIDA_VK_VALIDATION=1: scripts/run_gpu_tests.py --filter texoff is 3/3 pass natively and 3/3 pass with LEONIDA_TEXOFF_FALLBACK=1 (ps_texoff, ps_texoff_forms, ps_texoff_implicit, 4096/4096 pixels each; +16/−32 judged under the fallback). These shaders sample mip 0 with a point sampler, so they show no regression. They do not exercise a fractional LOD on a mipped image; that case is covered by the CPU test above.
  • tests/test_translate.py and tests/semantic: 7362 passed, 566 skipped, 1 xfailed, 51751 subtests passed (python -I -m pytest, Python 3.13).

Depends on: none. #2783 changes the same texel_offset_fold signature and call site, so whichever lands second needs a small rebase; its MIN/MAX_LOD clamp runs before this rounding, so the two compose.

AI-assisted (Claude Code).

Checklist

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

🤖 Generated with Claude Code

@shdann

shdann commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested d1dea0a on Windows, CPython 3.14.7, CPU only (no GPU, no game files; no spirv-as/spirv-val here).

python -m pytest -q tests/test_texel_offsets.py (venv with the pinned tests/requirements.txt): 32 passed, 9 skipped. With the merge-base translator (f847748), 5 of this head's tests fail, so they pin the change.

One boundary where the test's evaluator and the emitted arithmetic disagree, reproduced: _folded_level evaluates OpFAdd in Python doubles, but the module adds in binary32. For a point sampler with four levels and LOD bits 0x3f000001 (the first binary32 value above 0.5), the evaluator says mip 1; the same instructions evaluated with binary32 round-to-nearest-even give mip 0, because lod + 0.5 is exactly halfway between two binary32 values and rounds to 1.0, so Ceil - 1 is 0.

import inspect, pathlib, sys, tempfile, struct
sys.path[:0] = ["tests", "tools"]
import test_texel_offsets as t
t.rdna2spirv.TEXEL_OFFSET_FALLBACK = True
src = inspect.getsource(t._folded_level).replace('if op[0] in ("OpFAdd", "OpIAdd"):', '''if op[0] == "OpFAdd":
            return struct.unpack("<f", struct.pack("<f", ev(a[0]) + ev(a[1])))[0]
        if op[0] == "OpIAdd":''')
env = dict(vars(t))
exec(src, env)
with tempfile.TemporaryDirectory() as d:
    for sampler in (1 << 26, None):
        spv = t._sample_l_o(pathlib.Path(d), sampler)
        lod = struct.unpack("<f", struct.pack("<I", 0x3f000001))[0]
        print(t._folded_level(spv, lod, 1 << 26), env["_folded_level"](spv, lod, 1 << 26))

Run from the repository root. Output: 1 0 twice (literal and run-time sampler). At exactly 0.5 both give 0, and at 0x3f000002 both give 1.

Two possible follow-ups: round the float operations to binary32 in _folded_level, so the test checks what the module computes; and, if mip 1 is the intended answer just above 0.5, compare the clamped fractional LOD with 0.5 directly instead of adding 0.5. I have no GPU measurement of what the hardware selects at that value.

AI-assisted.

@kacper-serewis kacper-serewis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On RTX 5070 driver 616.56 at d1dea0a, the documented nearest-mip tie at explicit LOD 0.5 affected all 4,096 pixels. Native Vulkan sampled mip-1 texel (41,38) and the fallback sampled (42,37). The five other nearest-mip controls matched. Across six linear-mip LODs the fallback matched its documented approximation within 0.002 in 8-bit channel units. The 24 synthetic draws used a scratch harness honoring the runtime mip-filter setting.

@jeremygold02 jeremygold02 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first binary32 LOD above 0.5 also gives a wrong texel on the RTX 5070. At 0x3f000001 (0.5000000596046448), native Vulkan Lod|Offset read (1,3) from mip 1. The translated fallback read (2,2) from mip 1 in all 256 pixels for that input, with either a literal or a memory-loaded sampler descriptor. An independent offset-free sample confirmed the selected mip. This answers @shdann’s hardware question and adds a non-tie case to the exact tie already reported.

Tested head d1dea0ad08072a18e338bd00cd79f5c9dba666c6 and merge base f847748cc76bd3777f9c070c4034eb2fc1c04e64. GPU execution used NVIDIA GeForce RTX 5070, driver 621.01 (32.0.16.2101), on Intel Core Ultra 7 265K / Windows 11 Home 25H2 build 26200.9974.

Explicit LOD bits Sampled mip Native offset (x,y) Head fallback (x,y), both S# forms Base fallback (x,y)
0x3effffff (just below 0.5) 0 (4,5) (4,5) (4,5)
0x3f000000 (0.5) 1 (1,3) (2,2) (2,2)
0x3f000001 1 (1,3) (2,2) (2,2)
0x3f000002 1 (1,3) (1,3) (2,2)
0x3f400000 (0.75) 1 (1,3) (1,3) (2,2)

To reproduce, use the two-mip path in vk_texture_test with an 8×8 base and a 4×4 mip, storing RGBA8 bytes (x, y, level+1, 255) at every texel. Use point/nearest S# words 00000092 00100000 04000000 00000000 (LOD range 0..1). A hand-written image_sample_l_o at UV (0.6875, 0.5625) with packed offset 0x013f (−1,+1) supplies RGB. Export the blue channel of an offset-free image_sample_l at the same UV and LOD alongside it. Run with the native offset (maintenance8 enabled) and with --texel-offset-fallback. Four 64×64 draws covered 16 explicit LOD values, 256 pixels each. The local harness changes were confined to the two synthetic mip sizes and texel contents. All tested modules passed spirv-val.

Please add 0x3f000001 to the regression coverage and make the CPU evaluator round the add to binary32. At that input, lod + 0.5 rounds to exactly 1.0 and Ceil - 1 picks the base-level size for the offset. Comparing the fractional LOD with 0.5 directly would preserve this first-above-tie distinction while keeping the exact-tie policy explicit. These results cover explicit LOD and a nearest-mip sampler on this driver.

AI-assisted.

tupacfan04 added a commit to tupacfan04/Leonida that referenced this pull request Nov 22, 2026
ceil(lod + 0.5) - 1 rounds the sum in binary32: 0x3f000001 + 0.5 is 1.0, so
it picked mip 0 where the RTX 5070 samples mip 1, and the exact tie 0.5 went
down where the GPU rounds it up (review on ItsNotRexed#3882). floor(lod) and
lod - floor(lod) are exact, so compare the fraction with 0.5. The test's
evaluator now rounds float results to binary32 and covers 0x3effffff, 0.5,
0x3f000001 and 0x3f000002.

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

Copy link
Copy Markdown
Contributor Author

Thanks @shdann, @kacper-serewis, @jeremygold02. All three findings hold, and d08064b9 addresses them:

  • The nearest level is now floor(lod) + (lod − floor(lod) ≥ 0.5) instead of ceil(lod + 0.5) − 1. Both operations are exact in binary32, so 0x3f000001 selects mip 1, and so does the tie at 0.5, matching native on your RTX 5070s. 0x3effffff stays at mip 0. (floor(lod + 0.5) would get that one wrong: the sum rounds up to 1.0.)
  • _folded_level rounds every float result to binary32. The cases now include 0x3effffff, 0.5, 0x3f000001 and 0x3f000002.
  • Control: the first head d1dea0ad fails exactly the 0.5 and 0x3f000001 cases. The evaluator now agrees with all five native rows of @jeremygold02's table.
  • The design doc and docstring state the round-up tie rule and cite your measurements.

Local results: tests/test_texel_offsets.py 44 passed (with spirv-val); tests/test_translate.py 562 passed. RTX 5070 (621.24), validation on: texoff GPU tests 3/3 natively and 3/3 with LEONIDA_TEXOFF_FALLBACK=1. I didn't rebuild your two-mip harness, so the mip-1 cases rest on your GPU table plus the binary32 evaluation. A rerun of that harness on d08064b9 would close it out. AI-assisted (Claude Code).

@jeremygold02 jeremygold02 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified the fix on d08064b97902fc2514659e5965c3be6c318669ce. Both the literal and memory-loaded S# fallback now match the native Vulkan texel-offset frame byte-for-byte, 4,096/4,096 RGBA32F pixels each, across 16 explicit LOD values. This resolves my previous change request.

LOD bits Native and both revised fallbacks (x, y, mip)
0x3effffff (just below 0.5) (4, 5, 0)
0x3f000000 (exactly 0.5) (1, 3, 1)
0x3f000001 (first above) (1, 3, 1)
0x3f000002 (second above) (1, 3, 1)
0x3f400000 (0.75) (1, 3, 1)

I rebuilt the shaders and scratch texture harness from this head and reran the same synthetic two-mip fixture. Four 64×64 draws compared native maintenance8 offset, the two head fallback forms and merge-base fallback. Relative to d1dea0ad, exactly the 256 pixels at the tie and the 256 at the first-above value changed in each fallback. The native and merge-base frames reproduced their previous bytes, and the independent offset-free sample confirmed each mip. All tested modules passed Vulkan 1.2 SPIR-V validation.

GPU execution used NVIDIA GeForce RTX 5070, driver 621.01 (32.0.16.2101), with Intel Core Ultra 7 265K on Windows 11 Home 25H2 build 26200.9974. This retest covers explicit LOD with point/nearest filtering on that driver.

AI-assisted by GPT-6.2 Astra.

@itsonlysimbo

Copy link
Copy Markdown
Contributor

Tested d08064b9 merged onto main aa2988cc (merges cleanly) on RTX 4070, NVIDIA 621.14, Windows 11 (10.0.26300), Vulkan SDK 1.4.363, llvm-mc 23.1.6, test programs from main aa2988cc: pass.

  • tests/test_texel_offsets.py with spirv-as/spirv-val on PATH: 44 passed, none skipped.
  • run_gpu_tests.py: 164/210 passed, 46 skipped, 0 failed, both without and with LEONIDA_TEXOFF_FALLBACK=1, same as main. ps_texoff, ps_texoff_forms and ps_texoff_implicit are 4096/4096 exact in both modes (with the fallback, the +16/−32 offsets are judged). These fixtures sample mip 0 only, so they check that nothing regressed, not the new level choice; that is covered by the RTX 5070 readbacks above.
  • No suite shader's SPIR-V changes against main.
  • tests/semantic: 7456 tests, with the same 7 failures and 2 errors main aa2988cc has on this machine; none new. pytest outside tests/semantic: the same 4 failures as main, none new.

AI-assisted (Claude Code).

@tupacfan04

Copy link
Copy Markdown
Contributor Author

A limit of this PR's level rule, found through #4321. @whattheflop measured native image_sample_l on an RDNA2 Radeon iGPU (readback): at LOD 0x3effffff it reads mip 1, but RTX 5070 and RTX 4070 Ti SUPER read mip 0. The AMD sampler quantizes the LOD before rounding, so values within about one binary32 ulp below 0.5 land on the tie.

Here the host sampler picks the mip and the fallback only has to scale the offset by that mip's size, so the target is the host's rule. The exact floor + (fraction >= 0.5) matches NVIDIA. On an AMD host it would scale by mip 0 where the sample reads mip 1, but only for LODs just below a .5 boundary (0x3efe0000 already reads mip 0 there). Main's ceil(lod + 0.5) - 1 was wrong at the tie itself and at 0x3f000001 on both vendors, so this PR is still a strict improvement. I've asked for the precise RDNA2 quantization in #4321 and will follow up here if a host-specific rule turns out to be worth it.

@Ingenioeren

Ingenioeren commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Windows Vulkan cross-check on a discrete Radeon RX 6750 XT at d08064b97902. The exact-head tests/test_texel_offsets.py passed 44/44. I also ran a validation-layer-enabled two-mip draw using the PR’s vk_texture_test fixture. A standalone GLSL fragment wrote the native textureLod mip and the mip selected by floor(lod) + float(lod - floor(lod) >= 0.5) into separate readback channels.

Binary32 LOD Native point-mip Arithmetic point-mip
0x3efeffff 0 0
0x3eff0000 (0.498046875) 1 0
0x3effffff 1 0
0x3f000000 (0.5) 1 1

The two consecutive values 0x3efeffff and 0x3eff0000 pin the native transition on this device, corroborating the earlier Radeon iGPU observation and showing a disagreement interval 1/512 LOD wide. The probe uses explicit LOD, nearest mip filtering, and a sampler LOD range of [0, 1]. It isolates mip selection from coordinate folding and uses standalone GLSL. AI-assisted with Codex.

I then assembled and translated a synthetic image_sample_l_o in both modes at the same head. The scratch fixture kept the 128×128 base and encoded each 64×64 mip-1 texel as RGBA8 (x,y,255,255). With UV (0.51171875, 0.25), offset (-1,0), and literal point sampler words 00000092 00100000 04000000 00000000, the Radeon readbacks were:

LOD bits Native offset Translated fallback Pixels different
0x3efeffff mip 0 control same 0/4096
0x3eff0000 mip 1 (31,16) mip 1 (32,16) 4096/4096
0x3effffff mip 1 (31,16) mip 1 (32,16) 4096/4096
0x3f000000 mip 1 (31,16) same 0/4096
0x3f400000 mip 1 (31,16) same 0/4096

All ten fragment modules passed spirv-val. The native harness enabled VK_KHR_maintenance8, and the draws produced no validation messages. This confirms a one-texel horizontal error from scaling the offset by the base mip in the measured interval.

@tupacfan04

tupacfan04 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor Author

CI: both failures are outside this PR's files (it only changes tools/rdna2spirv.py, tests/test_texel_offsets.py and docs/design.md). The jobs checked out "Merge d08064b into aa2988c", which is yesterday's main.

  • windows: d3d12_geometry failed at line 43: d.create() on the GPU-less runner. At aa2988cc that test had EXPECT(d.create()) there. d3d12_geometry: skip with 77 when no Vulkan device is available #3360 (72fb353f, merged 03:37) makes it skip with 77 when no Vulkan device is available, and the other D3D12 tests skipped in the same run.
  • linux-gpu-tools: runtime/test/vk_harness.cpp doesn't compile against the job's Vulkan headers, which lack VK_KHR_pipeline_binary (VkPhysicalDevicePipelineBinaryFeaturesKHR and the rest). That's BUILD-1501, still open as CI: use pinned Vulkan headers in the linux-gpu-tools job #4983.
  • This head merges cleanly onto current main 3faac557. There, tests/test_texel_offsets.py plus the two design-row test files give 67 passed. On the RTX 5070 (621.24), merged onto 0db7fed5 with validation on, ps_texoff, ps_texoff_forms and ps_texoff_implicit pass 3/3 natively and 3/3 with LEONIDA_TEXOFF_FALLBACK=1.

@Ingenioeren, thanks, that closes the question I left open above. Your two consecutive values, together with @whattheflop's iGPU rows, fit only one rule: RDNA2 rounds the LOD to 8 fraction bits before picking the nearest mip. #4321 now follows that for the gather, where the translator picks the mip itself and RDNA2 is the target.

This PR stays on the exact rule on purpose. In the fallback, the host sampler picks the mip, and the offset only has to be scaled by that mip's size, so the right rule is the host's. Your table shows exactly that disagreement on an AMD host: a one-texel error for LODs in [k + 127.5/256, k + 0.5). The fallback only runs on devices without VK_KHR_maintenance8, though (NVIDIA Pascal, per the design row). Your RX 6750 XT has maintenance8, so it only reaches that interval with the fallback forced. The NVIDIA cards measured so far (RTX 5070, RTX 4070 Ti SUPER) compare the binary32 LOD exactly, which is what this rule does. If an AMD or Intel host without maintenance8 needs the fallback, a host-specific rule would be the follow-up. I don't think one should go in on a guess.

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

tupacfan04 and others added 2 commits November 23, 2026 02:59
…r (SHADER-699)

--texel-offset-fallback floored the LOD to choose the level whose size scales
the folded offset. A nearest-mip sampler reads ceil(lod + 0.5) - 1, so at
LOD 0.75 it sampled mip 1 with the offset in mip-0 texels. Read MIP_FILTER
(S# word 2 [27:26], literal or at run time): nearest rounding for point and 3,
level 0 for none, floor kept for linear, as the runtime's vulkan_sampler maps
them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ceil(lod + 0.5) - 1 rounds the sum in binary32: 0x3f000001 + 0.5 is 1.0, so
it picked mip 0 where the RTX 5070 samples mip 1, and the exact tie 0.5 went
down where the GPU rounds it up (review on ItsNotRexed#3882). floor(lod) and
lod - floor(lod) are exact, so compare the fraction with 0.5. The test's
evaluator now rounds float results to binary32 and covers 0x3effffff, 0.5,
0x3f000001 and 0x3f000002.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tupacfan04
tupacfan04 force-pushed the shader-699-texoff-mip-filter branch from d08064b to 4b60cb6 Compare November 23, 2026 09:02
@gertify

gertify commented Nov 23, 2026

Copy link
Copy Markdown

Tested 4b60cb6 on Intel UHD 630 (Coffee Lake GT2), Mesa 25.2.8 ANV, Ubuntu 24.04: tests/test_texel_offsets.py gives 59 passed under pytest (the PR body says 44; I did not look into the difference). run_gpu_tests.py --filter texoff with LEONIDA_VK_DEVICE=Intel skips all three fixtures natively (ps_texoff, ps_texoff_forms and ps_texoff_implicit: "unsupported: VK_KHR_maintenance8 (non-constant texel Offset)"), so the native path has no evidence from this GPU. With LEONIDA_TEXOFF_FALLBACK=1 all three pass, 4096/4096 pixels exact each. A nonexistent device name fails all three with "no Vulkan physical device matches". The full GPU suite gives 154/217 passed, 61 skipped, with only cs_fmt_int_narrow and cs_signed_zero_nan failing, the same counts and failures as the recorded main 3faac55 run on this GPU.

AI-assisted.

@KkelebekK

Copy link
Copy Markdown

Tested 4b60cb65 on AMD Radeon 780M (RADV PHOENIX, gfx1103 / RDNA3, Mesa 26.2.6, subgroup 32..64) and NVIDIA GeForce RTX 4070 Laptop (620.70.06, subgroup 32..32), Linux (CachyOS, kernel 7.3.4): pass on NVIDIA, where it fixes the level choice; on RADV the 1/512-wide AMD interval below each .5 stays wrong, as already discussed above.

The head sits directly on current main 3faac557, so it merges cleanly (git merge-tree). It changes no runtime code, so the test programs are built from 3faac557 (RelWithDebInfo). Each GPU was picked with LEONIDA_VK_DEVICE and confirmed from the device: line.

  • Full scripts/run_gpu_tests.py, PR vs main 3faac557, identical per test (PASS/SKIP and name) in all four runs:

    • 780M native: 202/217 passed, 15 skipped. With LEONIDA_TEXOFF_FALLBACK=1: same.
    • 4070 native: 170/217 passed, 47 skipped. With LEONIDA_TEXOFF_FALLBACK=1: same.
    • ps_texoff, ps_texoff_forms and ps_texoff_implicit are 4096/4096 exact in every run. They sample mip 0 only, so they show nothing else moved.
  • Targeted readback (scratch harness and fixture, not committed). The harness is vk_texture_test --two-mip with one change: every texel holds its own coordinates (base (2x, 2y, 0, 255), mip 1 (4x, 4y, 128, 255)), so a pixel names its level and texel.

    • The shader is image_sample_l_o with offset (−1, +1) at constant UV (0.51171875, 0.25390625), mip-1 texel (32.75, 16.25). S# 92 100000 14500000 0 (point, LOD 0..1), loaded from memory (mem) or as literal s_mov_b32 words (lit).
    • The native maintenance8 offset (VKT_NEED_MAINTENANCE8=1) is the reference. The fallback is the same source translated with --texel-offset-fallback.
    • Every cell is uniform over the 64×64 frame. Both S# forms give the same result in every row, and all 17 modules per build pass spirv-val.
    LOD bits 4070 native 4070 fallback, main 4070 fallback, PR 780M native 780M fallback, main 780M fallback, PR
    0x3e800000 (0.25) (64,33) mip 0 match match (64,33) mip 0 match match
    0x3efeffff (64,33) mip 0 match match (64,33) mip 0 match match
    0x3eff0000 (64,33) mip 0 match match (31,17) mip 1 (32,16) (32,16)
    0x3effffff (64,33) mip 0 match match (31,17) mip 1 (32,16) (32,16)
    0x3f000000 (0.5) (31,17) mip 1 (32,16) match (31,17) mip 1 (32,16) match
    0x3f000001 (31,17) mip 1 (32,16) match (31,17) mip 1 (32,16) match
    0x3f000002 (31,17) mip 1 (32,16) match (31,17) mip 1 (32,16) match
    0x3f400000 (0.75) (31,17) mip 1 (32,16) match (31,17) mip 1 (32,16) match

    Each "(32,16)" cell is mip 1 with 4096/4096 pixels differing from native; each "match" is 0/4096.

    • On the 4070 Laptop, main's fallback reads the wrong texel at 0.5, 0x3f000001, 0x3f000002 and 0.75. With the PR it matches native at all 8 LODs, with both S# forms (red before, green after).
    • On the 780M, the PR fixes the same four LODs. RADV/RDNA3's native sampler still reads mip 1 from 0x3eff0000, so the fallback is one mip-1 texel off at 0x3eff0000 and 0x3effffff, with or without the PR. That's the RX 6750 XT interval @Ingenioeren measured, now on RDNA3/RADV as well. The device has maintenance8, so it only gets there with the fallback forced. A host-specific rule is out of this PR's scope, as you said. The docs/design.md row doesn't mention that interval, though, and says image_query_probe.py records RDNA2 doing the same tie rule. A short note that AMD hosts quantize the LOD to 8 bits first (rdna2spirv: explicit-LOD gather rounds the LOD to 8 fraction bits like RDNA2 #4321) would keep a later reader from taking the fallback as exact there.
  • pytest at the head: tests/test_texel_offsets.py 59 passed; with test_design_contract_rows.py and test_docs_design_rows.py, 67 passed and 6 subtests. tests/test_translate.py: 596 passed. spirv-as/spirv-val on PATH.

  • Negative control: the head's tests/test_texel_offsets.py with main 3faac557's tools/rdna2spirv.py gives 8 failed, 51 passed. The failures are the point cases at 0.75, 0.5, 0x3f000001, 0x3f000002 and 2.6, MIP_FILTER 3 at 0.75, "none" at 2.75, and test_fallback_literal_mip_filter_emits_one_rounding.

Not verified: linear mip filtering, implicit-LOD (OpImageQueryLod) forms and MIN/MAX_LOD other than [0, 1] on the GPU. I didn't run the validation layer.

Synthetic inputs only, no game data. AI-assisted.

ItsNotRexed added a commit that referenced this pull request Nov 23, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tupacfan04

Copy link
Copy Markdown
Contributor Author

Closing as already merged. This PR's change landed in main through 4b63d29b ("Merge pull request #3882", whose parent is this PR's earlier head d08064b9), which reached main with 561b65a8. GitHub still shows the PR open only because I force-pushed a rebased head (4b60cb65) afterwards, and that commit isn't in main. Nothing here is left unmerged: merging 4b60cb65 into main 561b65a8 gives exactly main's tree.

Thanks to everyone who reviewed and tested it.

AI-assisted (Claude Code).

@tupacfan04 tupacfan04 closed this Nov 23, 2026
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.

8 participants