Skip to content

Sample integer 2D textures through typed views at LOD zero - #1405

Merged
ItsNotRexed merged 3 commits into
ItsNotRexed:mainfrom
Vonsek:codex/typed-sample-lz
Nov 22, 2026
Merged

ItsNotRexed merged 3 commits into
ItsNotRexed:mainfrom
Vonsek:codex/typed-sample-lz

Conversation

@Vonsek

@Vonsek Vonsek commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue.

What and why

A 2D image_sample_lz always sampled a float image, even for an integer view. Full-width results happened to be correct on both tested Vulkan drivers despite numeric-type VUID 07753. D16 results were converted from float bits and every integer output pixel was wrong. Select the sampled type using the existing T# FORMAT dispatch, and use the shared packing path. The fixture T# correction is identical to the one in #1363; it names the actual image view.

Tested

  • New cs_sample_lz_int_d16.asm through normal assembly, translation, spirv-val, vk_store_test and both GPU runners. R32 UINT/SINT D16 sum: 64/64 wrong before on both GPUs (texel (5,3) was -1), 0/64 wrong after (71). The UINT source and RGBA8 control also matched.
  • Independently rendered synthetic RGBA8 UINT, SINT and UNORM at 64×64, full and packed output, nearest filtering. All four integer cases per width across the two GPUs raised VUID 07753 before; every D16 integer pixel was wrong. With the fix, all four channels matched the independent reference at every pixel in all 12 cases with GPU-assisted validation. Forcing the wrong mip differed at 4096 pixels and exchanging coordinates differed at 3584.
  • Separate UNORM minification control on an 8×8 four-quadrant base image with a different uniform 4×4 mip, normalized repeat, nearest min/mag/mip, LOD range [0,1]. On a 64×64 triangle UV×16 gives two texels/pixel: the real implicit shader chose mip 1 everywhere; the explicit shader chose level zero everywhere. A shader actually swapping U and V diverged on exactly 2048 pixels starting at (2,0). All 4096 RGBA outputs per draw matched on both adapters, including before this fix. The permanent LOD-control fixture already exists in GPU test: distinguish explicit mip zero from implicit minification #296.
  • Native gfx1036 image_sample_lz on a synthetic RGBA32 HIP image returned every original 32-bit UINT/SINT component. With D16 the hardware saturated out-of-range values; translated narrowing of those wider values depends on the common packing fix in Saturate integer D16 image loads and gathers before packing #1340. The committed D16 sample test uses in-range inputs.
  • Windows, RTX 5080 616.92 (Vulkan 1.4.351), Radeon gfx1036 32.0.21045.16010 (1.4.315); full scripts/run_gpu_tests.py on 35506a0: Radeon 136/136 in each mode, RTX 107 passed and 29 skipped in native mode, 136/136 in wave64 emulation. Typed-image unit tests 12/12, shader runner checks 40/40.

Checklist

  • No game data, keys or decryption, including in reports.
  • Format dispatch, evidence and scope are in docs/design.md.

AI-assisted.

Nearest sampling an integer image through a float view violates Vulkan's numeric-type rule. For D16 the subsequent float-to-half conversion also destroys the sampled integers, including every texel in the synthetic signed/unsigned sum.
The arbitrary texture key named an unsigned format for an RGBA8_UNORM view, sending explicit gathers down the wrong branch. Derive the T# format from the same Vulkan format used to create the view.
@Vonsek

Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

I also ran the committed sample shader with the wider boundary-value fixture from #1340. On both RTX 5080 and gfx1036, 35506a0 alone differs at 4/64 texels with the out-of-range R32 inputs as expected. Combining its translator with #1340 at 05922b7 (local translator blob eab0dbe5f9eec68c37ab066f25ad3c38f67d57cd) yields 0/64 mismatches on both devices. The unchanged UINT source and UNORM control also matched. Once both are integrated the sample fixture can use vk_store_test load-d16 in both runners.

@tylerstraub

Copy link
Copy Markdown
Contributor

Tested 35506a08d0f0cbd09f71705a8e7ec0ec952869db on NVIDIA GeForce RTX 5090, 595.99.02 (Linux).

The committed cs_sample_lz_int_d16 fixture passed on Linux 7.0.0-43-generic with the source-built Vulkan harness. vk_store_test load found 0/64 mismatches in the R32_SINT sum and zero mismatches in the untouched UINT and UNORM views. At texel (5,3), the sum was 71.

For a control I disabled only the typed LOD-zero dispatch in a temporary translator copy, keeping the same shader source, images and harness. The R32_SINT sum then had 64/64 mismatches and texel (5,3) read −1. Both modules passed SPIR-V validation.

The filtered runner also passed ps_texture_sample, ps_texture_sample_d16 and ps_gather_wrap. All 12 typed-image tests and all 40 shader-check tests passed. Tools were llvm-mc 21.1.8 and SPIRV-Tools 2026.1. The committed sampling fixture uses in-range inputs.

AI-assisted verification.

@Vonsek

Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

The Windows CI failure on 35506a0 is the newly registered presentation test: this branch and unmodified base c2967a5e both fail at d3d12_present line 139, d.create(true), on the headless runner. #908 already handles the missing presentation device. I will recheck after that upstream change.

@crastinator

Copy link
Copy Markdown
Contributor

Tested 35506a0 merged into main c2967a5e (clean merge) on AMD Radeon RX 6700 XT (Navi 22, gfx1031, subgroup 32..64), RADV Mesa 26.3.1, CachyOS, Linux 7.3.5, GCC 16.2.1, llvm-mc 23.1.5: pass.

  • cs_sample_lz_int_d16 passes.
  • Whole run_gpu_tests.py: 136/136 native, 136/136 with LEONIDA_W64_EMULATE=1.
  • tests/test_image_load_typed.py and tests/test_shader_checks.py: 54 passed.

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

@kapitche

Copy link
Copy Markdown
Contributor

Tested on Windows 11 with two GPUs on one machine (runtime built from this PR's head, MSVC 14.51): pass. --filter ps_tex: RTX 4080 SUPER 9/9, Intel UHD 770 6/9 with the same 3 skips as main (maintenance8 offsets and shaderResourceMinLod).

@ayozetr

ayozetr commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested 35506a0 on NVIDIA GeForce RTX 3060 (Ampere), driver 620.70.06, Linux 7.3 (CachyOS), Vulkan 1.4.357, LLVM 23.1.5 llvm-mc: pass

  • scripts/run_gpu_tests.py --build runtime/build/linux: 107/136 passed, 29 skipped, 0 failed; 140/140 shaders translate and pass spirv-val.
  • cs_sample_lz_int_d16 passes.
  • The 29 skips are the wave64 tests (32-wide subgroups only), as on main (bb2e184: 109/139, 30 skipped, 0 failed). Not run with LEONIDA_VK_VALIDATION=1.

Use the current common image packer and its boundary-value fixture for the sample shader. Keep the merged explicit-gather paths and the headless presentation skip.
@Vonsek

Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Updated to 1387865 based on bb2e184, which contains the #1340 saturation fix, corrected explicit-gather translation/fixture and #908. Both runners now use vk_store_test load-d16 for this sample shader, covering out-of-range R32 integer inputs. On RTX 5080 and gfx1036 the committed sample and both explicit-gather regressions passed; d3d12_present also passes locally. I am checking CI for this new head.

@tylerstraub

Copy link
Copy Markdown
Contributor

Tested 1387865c3a680ae3f12f415ef746b102af34756a on NVIDIA GeForce RTX 5090, 595.99.02 (Linux).

I rebuilt the harnesses at this head and reran cs_sample_lz_int_d16 with vk_store_test load-d16, which exercises the out-of-range R32 inputs added since the previous AREA52 check. All 64 sum texels matched. The untouched UINT source and UNORM control also matched.

In a temporary translator copy I kept typed sampling and changed only the shared integer image packing to truncate. The same shader and harness then produced 4/64 mismatches in the sum output. This isolates the saturation check in the revised fixture. Both modules passed SPIR-V validation.

The filtered gather runner also passed ps_gather_sampler_lod in both 4,096-pixel draws and ps_gather_wrap at 4,096/4,096. All 13 typed-image and 40 shader-check unit tests passed. Linux 7.0.0-43-generic, llvm-mc 21.1.8 and SPIRV-Tools 2026.1. GPU coverage was limited to these filtered fixtures.

AI-assisted verification.

@Urban225

Copy link
Copy Markdown
Contributor

Tested 35506a0 on AMD Radeon RX 7900 XTX (RDNA3), AMD proprietary 26.10.1, Windows 11, MSVC 19.44: pass.

AI-assisted (Claude wrote the test script and read the logs); the runs are from my machine.

@bobcatchris

Copy link
Copy Markdown
Contributor

Tested 1387865c3a680ae3f12f415ef746b102af34756a on AMD Radeon Pro V540 (RDNA1, Navi 12, RADV Mesa 25.2.8, Ubuntu 24.04, Vulkan 1.4.318, subgroup 32..64): pass. This is the independent RDNA1/RADV data point; no RDNA1 result was on this PR.

  • Command: python -I scripts/run_gpu_tests.py --filter cs_sample_lz_int_d16 --build runtime/build/linux (pinned to one Navi 12 with DRI_PRIME): 1/1 passed, cs_sample_lz_int_d16 PASS.
  • Command: pytest tests/test_image_load_typed.py: 13 passed.
  • Command: python -I scripts/run_gpu_tests.py --build runtime/build/linux: 145 shaders translated, 145 pass spirv-val; 128/140 passed, 12 skipped, 0 failed.
  • Same command on main at bb2e1842 with that commit's own rebuild: 144 shaders translated, 144 pass spirv-val; 127/139 passed, 12 skipped, 0 failed. The one extra test is the new cs_sample_lz_int_d16, so no regression.

The 12 skips are the usual RDNA1/RADV feature limits (5 mesh via no VK_EXT_mesh_shader, 5 barycentric via no VK_KHR_fragment_shader_barycentric, 2 texel-offset via no VK_KHR_maintenance8); no wave64 tests skipped because this card has subgroups 32..64. No code was edited or pushed; no game files used.

AI-assisted.

@Jolymmiles

Copy link
Copy Markdown
Contributor

Tested 1387865c3a680ae3f12f415ef746b102af34756a on Apple M3 Max, MoltenVK 1.4.2, macOS 27.3: pass

Built with Xcode 27.2, Homebrew LLVM 23.1.6 llvm-mc and SPIRV-Tools v2026.4. MoltenVK was loaded directly. The PR head was unchanged for the whole run. Its merge base is main bb2e1842, and that is the baseline.

python3 -I scripts/run_gpu_tests.py --build runtime/build/linux

main bb2e184 PR 1387865
native 85/139 passed, 52 skipped 86/140 passed, 52 skipped
LEONIDA_W64_EMULATE=1 114/139 passed, 23 skipped 115/140 passed, 23 skipped
rdna2spirv.py 144/144 translated and spirv-val-valid 145/145

The per-test status lists differ in one line only: the new cs_sample_lz_int_d16 passes in both modes. The same two tests fail on main and on the PR. ps_interp_f16_high fails pipeline creation with -3 (SHADER-196, #1407). ps_vcmpx_forms has 4096/4096 mismatches (TEST-205). The PR doesn't change either one.

  • --filter sample_lz 1/1, --filter ps_tex 9/9, --filter gather 2/2 (ps_gather_sampler_lod, ps_gather_wrap).
  • Control: I ran the PR's fixture through main's tools/rdna2spirv.py, then vk_store_test <spv> load-d16 directly. With main, R32 SINT was 64 bad and texel (5,3) = -1. With this PR it was 0 bad and texel (5,3) = 71. R32 UINT and the RGBA8 UNORM control were 0 bad both times. These are the same numbers as on RTX 5080, RTX 5090 and gfx1036.
  • python3 -m unittest discover -s tests/semantic: 1220 OK on both. tests/test_image_load_typed.py: 12 tests on main, 13 on the PR, all OK. tests/test_shader_checks.py: 40 OK. python3 -m compileall -q make_game.py tools tests is clean.

I did not run under validation. vk_store_test ignores LEONIDA_VK_VALIDATION. Through the Vulkan loader, MoltenVK is not listed (vkCreateInstance returns -9) because the tool doesn't opt in to portability enumeration. So VUID 07753 is not checked on this driver.

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

🤖 Generated with Claude Code

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.

9 participants