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 #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>
--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>
The clamp, the component after the coordinates, becomes MinLod on the
implicit-LOD sample (after Bias and Offset in mask order); outside the pixel
stage the LOD is max(0, clamp). a16 and --texel-offset-fallback (Grad|MinLod)
included. GPU tests ps_texture_cl and ps_texture_b_cl on the two-mip texture,
semantic tests, design.md row. Stacked on the image_sample_c change.
AI-assisted.
image_sample_c / image_sample_c_b (and their _o forms) were Unsupported. In a
pixel shader they are OpImageSampleDrefImplicitLod (Bias for _c_b); LOD 0 for
_c elsewhere. The _c_b address order is bias then z-compare (the parser read
the compare first). vk_texture_test now honours LEONIDA_VK_DEVICE. GPU tests
ps_sample_c and ps_sample_c_b, semantic tests, design.md row.
AI-assisted.
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.
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
The address decoder already preserves the full offset VGPR before reading the packed coordinates. Let the existing offset path use those operands, and compare asymmetric packed UVs to the full-precision texel on the GPU.
SHADER-14. runtime/test/shaders/ps_texoff.asm samples vk_texture_test's 8x8
texture (every texel different, point sampler, clamp to edge) through the
translated shader and exports the texel coordinates it read as integers:
- image_sample_lz_o with an offset computed per pixel: all 64 pairs of x, y
in -4..3 from the centre of texel (4, 4), each a different texel, none
clamped;
- image_sample_l_o with (-3, +2) and image_sample_lz_o with (+16, -32), the
offset dword loaded from an immediate. The second one tells 4-bit, 5-bit
and 6-bit fields apart; it is outside Vulkan's guaranteed -8..7 and is
judged only where the device's texel offset limits cover it;
- image_gather4_lz_o of red and of green with the per-pixel offset, at a
texel corner (shaderImageGatherExtended, not maintenance8).
Expected words are derived by hand from the docs/design.md rule (signed
6-bit fields, x [5:0], y [13:8]) and the texture contents, before any run;
the derivation is in the .asm header and check.py's texoff_words().
Harness: vk_texture_test enables VK_KHR_maintenance8 and
shaderImageGatherExtended when the device has them, prints the texel offset
limits, and with VKT_NEED_MAINTENANCE8=1 exits 77 without the extension
(SKIP in check.py and scripts/run_gpu_tests.py).
vk_harness.cpp is unchanged: its maintenance8 guard (#if defined() on the
structure-type enumerator, never true) was already fixed upstream, which now
uses #ifdef VK_KHR_MAINTENANCE_8_EXTENSION_NAME.
tests/conftest.py: the sample validator retries with
--allow-offset-texture-operand (what rdna2spirv.py validates with) when
spirv-val rejects a non-gather Offset, and skips on a spirv-val that does not
know the flag.
Tested on an AMD Radeon RX 6800, Windows, driver 26.11.2 (texel offset limits
-64..63, gather -32..31, maintenance8 enabled):
run_gpu_tests.py: 49/50 passed, 1 skipped (was 48/49, 1 skipped)
PASS ps_texoff 4096/4096 pixels exact (offsets +16/-32 judged)
check.py: 45 of 45 pass, 0 skipped (was 44 of 44)
No translator bug found: tools/rdna2spirv.py is unchanged.
Negative controls (translator sabotaged, test run, reverted). FAIL: sample
offset dropped, x/y swapped, y field at bit 6, 4-bit fields, 5-bit fields;
gather offset dropped, x/y swapped, y field at bit 6; three corrupted
expectations. PASS, so not detected on this GPU:
- fields read unsigned (sample and gather): Offset 60..63 sampled as -4..-1
and +32 as -32, so the sign extension cannot be seen through Vulkan here;
- 4-bit and 5-bit gather fields: the gather offsets stay in -4..3.
Both are pinned by the new structural test tests/test_texel_offsets.py
instead (signed, bit 8k, 6 bits; it fails with OpBitFieldUExtract).
The test shows that the translated SPIR-V implements the documented rule on
Vulkan; it does not measure the field layout on the hardware. Still not
GPU-tested: sign extension, gather field width, image_sample_o, _b_o,
_c_lz_o, image_gather4_l_o, the z field (3D), 1D/2D-array/cube targets, wrap
or mirror addressing, linear filtering, mips other than 0, other vendors'
drivers, devices without maintenance8.
unittest tests/semantic: 388 OK before and after.
pytest tests (LLVM_MC set): 1467 passed, 6 skipped, 1 xfailed before;
1478 passed, 6 skipped, 1 xfailed after.
AI-assisted.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>