Commit Graph

2 Commits

Author SHA1 Message Date
dfde5f58e9 fix: allow packed A16 coordinates on texel-offset samples
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.
2026-11-22 06:05:34 +01:00
add0b5cfce GPU test for texel offsets (image_sample*_o, image_gather4_lz_o)
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>
2026-11-21 16:55:18 -07:00