mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 22:45:53 +01:00
[PR #225] rdna2spirv: image_sample* outside 2D selects the UINT/SINT sampled view (SHADER-1404) #277
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#277
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/225
Author: @Andretuta
Created: 11/24/2026
Status: 🔄 Open
Base:
main← Head:old-pr/9959📝 Commits (1)
0b416ecrdna2spirv: image_sample* outside 2D selects the UINT/SINT sampled view (SHADER-1404)📊 Changes
11 files changed (+558 additions, -37 deletions)
View changed files
📝
docs/design.md(+2 -1)📝
runtime/test/shaders/check.py(+21 -0)➕
runtime/test/shaders/ps_sample_array_sint.asm(+71 -0)➕
runtime/test/shaders/ps_sample_array_uint.asm(+58 -0)➕
runtime/test/shaders/ps_sample_volume_sint.asm(+71 -0)➕
runtime/test/shaders/ps_sample_volume_uint.asm(+58 -0)📝
runtime/test/vk_texture_test.cpp(+113 -27)📝
scripts/run_gpu_tests.py(+6 -0)➕
tests/semantic/test_sample_implicit_dims.py(+139 -0)📝
tests/semantic/test_sample_typed_dims.py(+2 -2)📝
tools/rdna2spirv.py(+17 -7)📄 Description
Original description (mentions and
#Nreferences are disabled; the numbers refer to the old repository):Item: SHADER-1404 (coordination issue
#9677)Depends on: none. It builds on
#9517(merged), which already sendsimage_sample_l/image_sample_lzthrough the typed read in every dimension. This PR adds the implicitimage_sample, which was the form still left out.#9667(closed, unmerged) covered the same translator change; this is a separate implementation, and it adds GPU fixtures.What and why
Gen.image_opgaveimage_samplethe typed read (the float, UINT or SINT view the T# FORMAT selects) only whenstage == "ps"anddim == SQ_RSRC_IMG_2D. A 2D-array, cube, 3D or 1D implicit sample, and any implicit sample outside the pixel stage, read an integer texture through the float view. With d16, the result is wrong on every driver: the float path narrows the integer bits as a float, which gives 0 for small integer values. Without d16, the float-typed sample of an integer view is undefined in Vulkan, though RADV, NVIDIA and llvmpipe happen to return the integer bits.What changed:
image_sample,image_sample_l,image_sample_lz) now takeimage_read_typedin every dimension and stage.Gradrequires:Lod 0, the same as the float path did.image_sample_b,_cl,_d,_oand the_c*forms still read the float view, in every dimension including 2D. That is listed as an open follow-up below.Runtime side: no change needed. The UINT/SINT aliases are declared on the dimension's own sampled binding (2D 0, 2D-array/cube 3, 1D 5, 3D 6;
Gen.SAMPLED_BINDINGS). The runtime already binds each view in its own format there, which is whatimage_loadrelies on (SHADER-151).Tests
Run on Linux 7.0.0, Python 3, SPIRV-Tools from the distro, llvm-mc 21 (
/usr/lib/llvm-21/bin/llvm-mc).New
tests/semantic/test_sample_implicit_dims.py(6 tests, all pass). For each of the five dimensions it checks:OpDPdx/OpDPdypair at the right width, and threeGradsamples (float, uint, sint) with no implicit-LOD sample;Lod %f0samples and no derivatives;image_sample_bstill reads the float view only;spirv-val --target-env vulkan1.2forimage_sample/_l/_lz× 5 dims × {plain, d16, a16} × {ps, cs}.With
LEONIDA_TOOLS_DIRpointing at the base translator, 11 subtests fail.python -m unittest discover -s tests/semantic -p 'test_sample_*dims.py': 10 tests OK.python -I scripts/run_semantic_tests.py tests/semantic:test_exec_computed,test_image_atomics_guard);upstream/main(e56d9795), same test tree: the same 2 files fail, plus the new file.python -m compileall -q make_game.py tools tests: OK.python -I scripts/check_no_game_data.pyon every new or changed file: clean.GPU fixtures
New files:
runtime/test/shaders/ps_sample_array_uint.asmruntime/test/shaders/ps_sample_array_sint.asmruntime/test/shaders/ps_sample_volume_uint.asmruntime/test/shaders/ps_sample_volume_sint.asmThey run through new
vk_texture_testmodesarray-uint,array-sint,volume-uintandvolume-sint, wired intocheck.py(SAMPLE_DIMS_TESTS) andscripts/run_gpu_tests.py.Each mode binds an RGBA8 UINT or SINT texture whose T# names that format:
array-*: a 12-layer 128x128 2D array at binding 3, with a 64x64 mip 1;volume-*: a 128x128x4 volume at a binding 6 the mode adds, with a 64x64x2 mip 1.Each shader samples the texture three ways, at different layers or slices:
image_sample, whose implicit LOD is 1;image_sample_lat LOD 0;image_sample_lz.The channels are packed so that a wrong value or a wrong sign extension spills into a neighbouring byte, and every pixel is compared in the harness.
e56d9795)image_samplechannels read 0)On RADV and NVIDIA the new modes also run clean under
VK_LAYER_KHRONOS_validation, with 0 validation errors.Full
python -I scripts/run_gpu_tests.py --llvm-mc /usr/lib/llvm-21/bin/llvm-mc:ps_cube_sample,ps_array_resinfoandps_get_lod_arraypass on both.ps_cube_sampleis the one existing fixture whose SPIR-V this change alters.cs_imgload_tfe,cs_imgload_d16_tfe,cs_w32_exec_computed,cs_w64_exec_computed(RADV) andms_wave_info_s3(NVIDIA). They are not from this change: their SPIR-V is byte-identical between base and this branch.ps_m2_array's SPIR-V also changes (animage_sampleon a 2D array), but it is only run by the Windowsd3d12_m2_formats_testand was not run here.Open questions / follow-ups
image_sample_b,_cl,_d,_oand_c*still sample the float view of an integer T# in every dimension, including 2D. Bias and MinLod cannot be combined with theGradoperands the typed branch uses, so they need their own rule.spirv-val. Non-pixel-stage implicit samples are also CPU-only.AI-assisted: yes (Claude Code).
Checklist
.asm.docs/design.md, with how it was confirmed. The#9517row now names this GPU check.🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.