Repository navigation
rdna2spirv: image_sample_cl, _b_cl, _c_cl, _c_b_cl: min-LOD clamp forms (EGEN-MIMG-SAMPLE-CL) - #3058
Conversation
…implicit LOD (EGEN-MIMG-SAMPLE-C) 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.
The same pick_device block as ItsNotRexed#2225, so whichever merges first leaves the other a trivial merge there. AI-assisted.
…ms (EGEN-MIMG-SAMPLE-CL) 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.
|
Tested
Tools: llvm-mc 21.1.8 with AMDGPU target, SPIRV-Tools 2026.1, GCC 13.3.0, Python 3.12.3. No code was edited or pushed; only synthetic fixtures were used. AI-assisted. |
|
Tested 600037c on NVIDIA GeForce RTX 3060 Ti (Ampere), driver 610.88, Vulkan 1.4.341, Windows 11 (26200): pass. Test programs built from this commit (MSVC from VS 2026 + Ninja, including the vk_texture_test change); llvm-mc 23.1.6 (conda-forge llvm-tools); SPIRV-Tools from Vulkan SDK 1.4.357.0.
This adds NVIDIA/Ampere to the RDNA1 run above. No game files. AI-assisted (Claude Code). |
|
Tested 600037c on NVIDIA GeForce RTX 3090 (Ampere, subgroup 32..32), driver 610.88 (Vulkan 1.4.341), Windows 11 Pro 26300: pass. The PR's diff applied cleanly to
|
|
Tested 600037c on AMD Radeon RX 9060 XT (RDNA4), AMD driver 26.10.44 (LLPC, Vulkan driver 2.0.395), Windows 11 Pro 10.0.26300, subgroup 32..64: pass. The AMD run above is RDNA1 on RADV; this one is AMD's Windows driver, which is a different sampler implementation for the min-LOD clamp forms.
Test programs: built from this head with MSVC 14.44 ( |
Kam471
left a comment
There was a problem hiding this comment.
Verified on the PR head: test_sample_cl.py -> 10 tests OK (9 spirv-as/val subtests); test_texel_offsets.py 45 passed; test_sample_c.py 8 OK. On the parent and current main the same tests fail with 10 tests / 17 errors (only the refusal test passes), so the clamp forms are exercised. The operand order matches the ISA: cl clamp v6; b_cl bias v4/minlod v7; c_cl minlod v7; c_b_cl bias v4/minlod v8; cl_o offset v4/minlod v7; MinLod (0x80) follows Offset (0x10), and spirv-val is clean. Mutation of the clamp VGPR 7->6 gives 1 failure. No game data or absolute paths. Approve.
Caveat: ISA Table 44 prose says _CL clamps LOD to "no larger" (max), which would contradict MinLod; the D3D Sample clamp/SPIR-V MinLod and the PR's Radeon 8/8 negative control are lower-bound. The GPU test was not rerun here.
|
Tested
Tools: llvm-mc 23.1.6 (conda-forge), SPIRV-Tools from the Vulkan SDK. No game files. AI-assisted (Claude Code). |
|
Tested The four new shaders pass on this adapter — All 5 translated, spirv-val clean. First NVIDIA coverage for the |
tools/rdna2spirv.py AI-assisted.
tools/rdna2spirv.py AI-assisted.
jeremygold02
left a comment
There was a problem hiding this comment.
The updated head 5c93bc42dcb9b001b58ee7ac186eb1bc2e249301 passed a native Vulkan two-mip test for image_sample_c_cl and image_sample_c_b_cl on the RTX 5070.
Each synthetic 16×16 draw sampled D32_SFLOAT with nearest filtering and compared a reference of 0.5 using LESS_OR_EQUAL. Mip 0 was 8×8 at depth 0.25 and mip 1 was 4×4 at 0.75. The UVs gave an implicit LOD of −1. R and G used _c_cl with MinLod 0 and 1. B and A used _c_b_cl with the same two clamps, with bias −2 on the left and +2 on the right.
| Address format and depth order | Left half RGBA | Right half RGBA | Exact pixels |
|---|---|---|---|
| A32, 0.25 / 0.75 | 0,1,0,1 |
0,1,1,1 |
256/256 |
| A16, 0.25 / 0.75 | 0,1,0,1 |
0,1,1,1 |
256/256 |
| A16, 0.75 / 0.25 | 1,0,1,0 |
1,0,0,0 |
256/256 |
R/G show that raising MinLod selected mip 1. B changed across the bias boundary while A stayed on mip 1. The A16 fixture placed the opposite clamp and bias in their unused high halves. Its normal-order RGBA32F frame matched A32 byte for byte. Swapping only the depth contents inverted all 1,024 A16 components.
I built a local two-mip variant of this head’s vk_texture_test, enabled dynamic sampled-image indexing and preserved shaderDrawParameters in the device feature chain. For the runtime-loaded texture and sampler descriptors I added OpCapability SampledImageArrayDynamicIndexing to each executed PS. Removing that single 8-byte declaration reproduced the original module byte for byte. The original VS, both original PS modules and both executed PS modules passed spirv-val --target-env vulkan1.2.
Hardware was an Intel Core Ultra 7 265K and NVIDIA GeForce RTX 5070, driver 621.01, on Windows 11 Home 25H2 build 26200.9974. The RTX ran all three draws.
GPT-6 Luna helped identify the gap in earlier GPU coverage. AI-assisted by GPT-6.2 Astra.
Requested by Lucas · project thread
Claimed in the coordination issue as: EGEN-MIMG-SAMPLE-CL, #2716 (comment)
Depends on #2965 (the
_c/_c_bemission this extends). The branch is stacked on it, so until #2965 merges this diff also shows its commits; the change here is the last commit.What and why
image_sample_cl,image_sample_b_cl,image_sample_c_cl,image_sample_c_b_cl(HLSLSample/SampleBias/SampleCmpwith the clamp argument) and their_oforms were refused. Onlyimage_sample_d_clexisted. The clamp is the component after the coordinates; it is now theMinLodoperand of the implicit-LOD sample (afterBiasandOffsetin mask order), and the module declaresMinLodas_d_clalready did. Outside a pixel shader there are no derivatives, the LOD is 0 and the clamp raises it, so the sample is explicit withLod = max(0, clamp). a16 packs the clamp with the coordinates (the code already did for_d_cl; the extras count now ignores the_clsuffix, since_clstarts with_cand would have been counted as a z-compare). With--texel-offset-fallbackthe Grad sample getsGrad|MinLod. SHADER-491 (clamping explicit forms to the S# MIN_LOD/MAX_LOD in the fallback) is a different thing and is untouched. A clamp on a form with no_clinstruction (_l,_lz,_c_lz) stays refused.Tested
ps_texture_clandps_texture_b_clonvk_texture_test --two-mip(128x128 quadrants, cyan mip 1) drawn at 64x64 with coordinates / 4, so the unclamped LOD is -1: clamp 0.0 left of x = 32 must read mip 0 (red), clamp 1.0 from there on mip 1 (cyan), 4096 pixels exact; the bias test puts a 0.0 bias and the clamp in separate VGPRs. They run incheck.py/run_gpu_tests.pywith the existing gradient tests.--filter ps_texture_:LEONIDA_VK_DEVICE=radeon; the harness honours it since rdna2spirv: image_sample_c and image_sample_c_b, depth compares with implicit LOD (EGEN-MIMG-SAMPLE-C) #2965 / GPU tests: image_sample_l, image_sample_b_o, image_sample_c_lz_o, image_gather4_lz, image_load_mip #2225): 8/8.MinLodoperand fails both tests on the Radeon (2048 of 4096 pixels, the right half red instead of cyan). Reverted.tests/semantic/test_sample_cl.py: MinLod placement and the clamp's VGPR, Bias|MinLod with each operand from its own VGPR, the compare forms, Offset|MinLod, a16,max(0, clamp)outside the PS, the declared capability, the forms that stay refused, spirv-val.tests/test_texel_offsets.pygains_cl_oand_c_b_cl_o(and reads the Offset operand by mask position).python -m unittest discover -s tests/semantic,python tests/semantic/regen_fixtures.py --check,python -I tests/test_shader_checks.py,pytest tests/test_texel_offsets.py tests/test_translate.py: pass._c_cl,_c_b_cl), because the depth fixture has one mip level; they are covered by the SPIR-V shape and spirv-val.Checklist
docs/design.md, with how it was confirmed.AI-assisted.