Repository navigation
Translator: --texel-offset-fallback for image_sample*_o without VK_KHR_maintenance8 - #1127
Conversation
…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
|
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
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
left a comment
There was a problem hiding this comment.
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 (gameinputdisabled, 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), andVUID-vkCreateDevice-ppEnabledExtensionNames-01387from the standalone device ind3d12_fence_timing_test/d3d12_vulkan_device_test(#1027).
quackottu
left a comment
There was a problem hiding this comment.
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 (
main8df277f here: 64/91 passed, 27 skipped, all wave64 tests needing a 64-wide subgroup) LEONIDA_W64_EMULATE=1: 111/111 passed (mainhere: 91/91)python -m unittest discover -s tests/semantic: Ran 1101 tests in 209.324s OK
Claimed in the coordination issue as: texel offsets without VK_KHR_maintenance8 (#1006 (comment))
What and why
image_sample*_otakes a run-time texel offset. As a SPIR-VOffsetoutside gather, that needsVK_KHR_maintenance8(docs/design.md, "Texel offsets"). NVIDIA Pascal doesn't have it, sops_texoffskips on theGTX 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: animage_sample*_ogets noOffset. Instead the offset is foldedinto the coordinate, coordinate + offset ÷ the size of the sampled level (
OpImageQuerySizeLod).Which level:
_lz/_c_lz, and for implicit samples outside the PS, which already sample LOD 0;_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
Gradsamples with the derivatives of the unshifted coordinate (× 2^bias for_b). Sothe LOD and anisotropy are the original sample's, also when the offset changes from pixel to pixel.
Gathers keep their
Offset, since they need onlyshaderImageGatherExtended. The module stops declaringImageGatherExtendedwhen only samples had offsets.LEONIDA_TEXOFF_FALLBACK=1, likeLEONIDA_W64_EMULATE:build.pyandrun_gpu_tests.pytranslate with the flag.vk_texture_testis no longer asked for maintenance8 (check.texoff_env).texoff_problemalso judges the +16/−32 sample, since a coordinate shift has no device offset limit.runtime/test/shaders/ps_texoff_implicit.asm:ps_texoffwith its per-pixel-offset sample asimage_sample_o, theimplicit form the corpus uses. It has the same expected words and is checked by the same
texoff_problem, in bothrunners.
docs/design.md, and adocs/testing.mdsection.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:ps_texoffandps_texoff_implicitskip: nomaintenance8.
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.
LEONIDA_TEXOFF_FALLBACK=1 LEONIDA_BARY_FALLBACK=1: 80/111 passed, 0 failed. The two fallbacks combine.OpImageSample*keeps anOffset; the four gathers do. The implicit sample isExplicitLod … Grad, andneeds_maintenance8is gone from the index.image_sample*_o, which is 4 PS and nothing in otherstages. All 4 translate and pass
spirv-valin both modes, andneeds_maintenance8goes 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):Offset.GradwithOpDPdx/OpDPdy, scaled byExp2for_b.Offset.spirv-valwithout--allow-offset-texture-operand.43d4703): 3596 passed. Two subtests oftest_audio_wav.pyfailidentically on clean
43d4703here (this machine's ffmpeg is a 2020 build). After rebasing ontoc63773d:test_texel_offsets.py,test_translate.py,test_shader_checks.py,test_run_gpu_tests.pyandtest_gpu_unsupported_stage.pypass, 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
docs/design.md, with how it was confirmed.🤖 Generated with Claude Code
https://claude.ai/code/session_01SSJXX67xeoorUsLJ2f9zms