Skip to content

Translator: --texel-offset-fallback for image_sample*_o without VK_KHR_maintenance8 - #1127

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
Jess-Doit:translator/texoff-fallback
Nov 22, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
Jess-Doit:translator/texoff-fallback

Conversation

@Jess-Doit

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: texel offsets without VK_KHR_maintenance8 (#1006 (comment))

What and why

image_sample*_o takes a run-time texel offset. As a SPIR-V Offset outside gather, that needs
VK_KHR_maintenance8 (docs/design.md, "Texel offsets"). NVIDIA Pascal doesn't have it, so ps_texoff skips on the
GTX 1060 (#166), and 4 of the 12,101 PS, all through image_sample_o (31 samples), can't run there. Together with
#804 (barycentrics) and #1053 (mesh shaders), this is the last Pascal-specific gap in the corpus. Like those two, it's
opt-in.

  • tools/rdna2spirv.py --texel-offset-fallback: an image_sample*_o gets no Offset. Instead the offset is folded
    into the coordinate, coordinate + offset ÷ the size of the sampled level (OpImageQuerySizeLod).
    • Which level:

      • 0 for _lz / _c_lz, and for implicit samples outside the PS, which already sample LOD 0;
      • the given LOD for _l;
      • OpImageQueryLod's for implicit samples, plus the bias for _b.

      The level is floored and clamped to the image's levels.

    • Why it's exact: a texel offset applies before wrapping and clamping, and an integer offset commutes with both,
      so the shift is exact for every address mode at that level. The one case that differs is a trilinear blend of
      two levels: there the coarser level moves by offset ÷ 2 of its texels, and the docs say so.

    • Implicit samples become Grad samples with the derivatives of the unshifted coordinate (× 2^bias for _b). So
      the LOD and anisotropy are the original sample's, also when the offset changes from pixel to pixel.

    • Gathers keep their Offset, since they need only shaderImageGatherExtended. The module stops declaring
      ImageGatherExtended when only samples had offsets.

  • LEONIDA_TEXOFF_FALLBACK=1, like LEONIDA_W64_EMULATE:
    • build.py and run_gpu_tests.py translate with the flag.
    • vk_texture_test is no longer asked for maintenance8 (check.texoff_env).
    • texoff_problem also judges the +16/−32 sample, since a coordinate shift has no device offset limit.
  • runtime/test/shaders/ps_texoff_implicit.asm: ps_texoff with its per-pixel-offset sample as image_sample_o, the
    implicit form the corpus uses. It has the same expected words and is checked by the same texoff_problem, in both
    runners.
  • Docs: the "Texel offsets" row in docs/design.md, and a docs/testing.md section.

Tested

AI-assisted change. NVIDIA GeForce GTX 1060 6GB (no VK_KHR_maintenance8), driver 560.94, Vulkan 1.3.280,
Windows 10 22H2, Vulkan SDK 1.4.363.0, llvm-mc 23.1.6, MSVC 19.44, on main c63773d:

  • run_gpu_tests.py:
    • Without the variable: 75/111 passed, 36 skipped, 0 failed. ps_texoff and ps_texoff_implicit skip: no
      maintenance8.
    • With LEONIDA_TEXOFF_FALLBACK=1: 77/111 passed, 34 skipped, 0 failed. Both are 4096/4096 pixels exact, with the
      +16/−32 sample judged. No other result changed.
    • With LEONIDA_TEXOFF_FALLBACK=1 LEONIDA_BARY_FALLBACK=1: 80/111 passed, 0 failed. The two fallbacks combine.
  • In the translated modules, no OpImageSample* keeps an Offset; the four gathers do. The implicit sample is
    ExplicitLod … Grad, and needs_maintenance8 is gone from the index.
  • Corpus (my own copy, outcomes only): every shader with an image_sample*_o, which is 4 PS and nothing in other
    stages. All 4 translate and pass spirv-val in both modes, and needs_maintenance8 goes from 4 of 4 to 0 of 4.
  • tests/test_texel_offsets.py (30 tests, 20 new), for every sample form (2D, 3D, a16, _b, _c_lz):
    • No sample keeps an Offset.
    • The offset fields still come from signed 6-bit fields at byte steps.
    • The level source is right for each form.
    • Implicit forms use Grad with OpDPdx/OpDPdy, scaled by Exp2 for _b.
    • Gathers keep their Offset.
    • The module passes spirv-val without --allow-offset-texture-operand.
  • Python suite (before the last rebase, on 43d4703): 3596 passed. Two subtests of test_audio_wav.py fail
    identically on clean 43d4703 here (this machine's ffmpeg is a 2020 build). After rebasing onto c63773d:
    test_texel_offsets.py, test_translate.py, test_shader_checks.py, test_run_gpu_tests.py and
    test_gpu_unsupported_stage.py pass, 407 tests.

Not covered by a GPU test: a mipmapped texture under a trilinear sampler, where the docs state the difference above.
The game's 31 samples go through it, so a check of those on real content would be welcome once the runtime draws
them.

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

https://claude.ai/code/session_01SSJXX67xeoorUsLJ2f9zms

…R_maintenance8

A run-time texel Offset outside gather needs VK_KHR_maintenance8, which NVIDIA
Pascal lacks, so ps_texoff skips there and 4 PS (31 image_sample_o) can't run.
With --texel-offset-fallback the offset is folded into the coordinate:
coordinate + offset / size of the sampled level (0 for _lz/_c_lz, the LOD for
_l, OpImageQueryLod's for implicit samples, plus the bias for _b; floored and
clamped). An integer offset commutes with wrapping and clamping, so this is
exact at that level for every address mode; only a trilinear blend differs
(the coarser level moves by offset / 2). Implicit samples become Grad samples
with the unshifted coordinate's derivatives, so the LOD doesn't change with a
per-pixel offset. Gathers keep their Offset (shaderImageGatherExtended).

- LEONIDA_TEXOFF_FALLBACK=1 for build.py, check.py and run_gpu_tests.py;
  vk_texture_test then isn't asked for maintenance8, and texoff_problem also
  judges the +16/-32 sample.
- runtime/test/shaders/ps_texoff_implicit.asm: ps_texoff's per-pixel sample
  as image_sample_o, the corpus form.
- tests/test_texel_offsets.py: the fallback for every sample form, including
  spirv-val without --allow-offset-texture-operand.
- docs/design.md "Texel offsets", docs/testing.md.

GTX 1060: ps_texoff and ps_texoff_implicit 4096/4096 exact (SKIP before).
Corpus: the 4 PS translate and validate; needs_maintenance8 4 -> 0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SSJXX67xeoorUsLJ2f9zms
@kapitche

Copy link
Copy Markdown
Contributor

Tested a0a6d2f on Windows 11 with two GPUs on one machine (runtime built from this PR's head, MSVC 14.51, llvm-mc 23.1.6). This is the hardware the flag is for: the Intel UHD 770 has no VK_KHR_maintenance8.

run_gpu_tests.py --filter texoff:

Intel UHD 770 (32.0.101.6129) RTX 4080 SUPER (32.0.16.1714)
no flag both skip (VK_KHR_maintenance8) both pass, but offsets +16/−32 not judged (device limits −8..7)
LEONIDA_TEXOFF_FALLBACK=1 2/2 pass, 4096/4096, offsets +16/−32 judged 2/2 pass, 4096/4096, offsets +16/−32 judged

So the fallback gives this iGPU a working path where it had none. It also lets NVIDIA check the out-of-range offsets that its native path can't judge.

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

Tested a0a6d2f on NVIDIA GeForce RTX 5070, driver 621.24, Windows 11 Pro (26300), VS 2022 Build Tools, Vulkan SDK 1.4.363.0, with LEONIDA_VK_VALIDATION=1 and LEONIDA_D3D12=vulkan: pass

  • Build ok. ctest: 100% tests passed, 0 tests failed out of 54 (gameinput disabled, no SDL3).
  • This run covers the runtime only. The translator change (--texel-offset-fallback, ps_texoff_implicit) needs the shader suite, which I've queued separately.
  • 44 test programs exit 0 with 0 validation messages.
  • Same on main, not from this PR: d3d12_clear_test (NVIDIA 0.5 tie rounding, #521), vk_binary_occlusion_test (needs an input file), and VUID-vkCreateDevice-ppEnabledExtensionNames-01387 from the standalone device in d3d12_fence_timing_test/d3d12_vulkan_device_test (#1027).

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

Tested a0a6d2f on NVIDIA GeForce RTX 5070 (subgroup 32), driver 621.24, Windows 11 Pro (26300), Vulkan SDK 1.4.363.0, llvm-mc 21.1.8 (built with scripts/build_llvm_mc.ps1), scripts/run_gpu_tests.py:

  • native: 84/111 passed, 27 skipped (main 8df277f here: 64/91 passed, 27 skipped, all wave64 tests needing a 64-wide subgroup)
  • LEONIDA_W64_EMULATE=1: 111/111 passed (main here: 91/91)
  • python -m unittest discover -s tests/semantic: Ran 1101 tests in 209.324s OK

@ItsNotRexed
ItsNotRexed merged commit b4db783 into ItsNotRexed:main Nov 22, 2026
10 of 11 checks passed
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