Repository navigation
fix(translator): clamp explicit forms and _b_o bias to S# word 1 MIN_LOD/MAX_LOD in --texel-offset-fallback (SHADER-491) - #2783
Conversation
|
Independent nearest-mipmap fractional clamp check ( Synthetic inputs only. AI-assisted (Codex). |
kacper-serewis
left a comment
There was a problem hiding this comment.
AI-assisted independent RTX 5070 readback (driver 616.56). Synthetic raw LOD 2, instruction bias −1, sampler bounds [0,1], offset (+2,0). Parent 4947579 and head 5012b84 both sampled mip 1 at all 4,096 pixels. Both produced the RGBA value for a one-texel shift throughout. Only the 64 pixels in the clamped rightmost column matched the expected two-texel shift. The native Vulkan textureOffset control matched all 4,096 pixels. All three shaders passed Vulkan 1.2 spirv-val and created graphics pipelines. The fallback adds bias to the sampler-clamped query, selecting mip 0 dimensions when scaling the offset. This is a second failure case alongside the fractional clamp review.
…LOD/MAX_LOD in --texel-offset-fallback (SHADER-491) In --texel-offset-fallback (Gen.texel_offset_fold), texel offsets for image_sample*_o are folded into the UV coordinates by dividing by the size of the sampled level. Previously, explicit forms (_l_o, _lz_o, _c_lz_o, and explicit LOD 0 outside PS) ignored the sampler descriptor's [MIN_LOD, MAX_LOD] bounds, and _b_o added its instruction bias after OpImageQueryLod had already applied sampler clamping, potentially overshooting MAX_LOD or falling below MIN_LOD. Fix this by reading MIN_LOD and MAX_LOD from S# word 1 (unsigned 4.8 fixed-point, bits [11:0] and [23:12]): - Clamp explicit LOD (_l_o) and biased LOD (_b_o) using clamp_gather_lod. - For _lz_o and _c_lz_o (LOD 0.0), if S# word 1 is literal and MIN_LOD is 0.0, emit level 0 directly without extra instructions; otherwise clamp LOD 0.0 to [MIN_LOD, MAX_LOD]. - Updated docs/design.md contract. - Added 5 new regression tests in tests/test_texel_offsets.py covering literal MIN_LOD, literal MAX_LOD, literal zero MIN_LOD direct level 0, runtime sampler clamping, and bias clamping. Item: SHADER-491
5012b84 to
f9d6038
Compare
|
Code read of f9d6038 (CPU only, no GPU run):
The rest ( |
jeremygold02
left a comment
There was a problem hiding this comment.
Confirmed @MiguelMatMar’s negative-LOD / positive-bias case on hardware at f9d60386d0fb6fcb3d1bcd0bd29d29ef60eed27a. With measured raw LOD −3, instruction bias +2 and sampler LOD bounds [0,1], native Vulkan applied offset (−1,+1) to mip 0. The fallback applied (−2,+2) to that same mip. 3,840 of 4,096 pixels differed. The remaining 256 matched because both coordinates clamped to the same edges.
| Path | Bias | Pixels matching native | Texel at pixel (36,36) |
|---|---|---|---|
Native Vulkan Bias|Offset |
+2 | 4,096/4,096 | (3,5) |
Head --texel-offset-fallback |
+2 | 256/4,096 | (2,6) |
| Fallback with only the offset calculation’s query component changed from 0 to 1 | +2 | 4,096/4,096 | (3,5) |
| Native and head fallback, zero-bias control | 0 | 4,096/4,096 each | (3,5) |
Reproduction used hand-written image_sample_b_o with address registers [0x013f, bias, u, v], UV ((px+0.5)/64, (py+0.5)/64), point sampling, and S# words 00000092 00100000 04000000 00000000. The synthetic RGBA8 texture had 8×8 and 4×4 levels with bytes (x,y,level+1,255). Each draw exported the sampled texel alongside the unclamped image_get_lod result. All 4,096 pixels in all five draws independently reported raw LOD −3 and sampled mip 0. The harness was a scratch version of vk_texture_test from d1dea0ad with only the synthetic texture sizes and texels changed. All shaders came from the tested PR's translator except the single-component diagnostic edit, and all passed Vulkan 1.2 SPIR-V validation. Native used VK_KHR_maintenance8.
In Gen.texel_offset_fold, component 0 already reflects the sampler clamp. Adding +2 there and clamping again uses the 4×4 mip dimensions for the shift. The intended order takes raw −3 from component 1, adds +2, then clamps −1 to zero and uses the 8×8 dimensions. A regression with both signs of instruction bias would cover this case and the previously reported raw +2 / bias −1 case. The diagnostic module establishes this change for the measured case.
GPU execution used NVIDIA GeForce RTX 5070, driver 621.01 (32.0.16.2101), Intel Core Ultra 7 265K, Windows 11 Home 25H2 build 26200.9974.
AI-assisted by GPT-6.2 Astra.
|
Tested current head This independently confirms the raw-positive / bias-negative For a diagnostic positive control, I changed only the Scope: 2D float |
Summary
Implements SHADER-491 (follow-up to @Jolymmiles's finding in #2516).
In
--texel-offset-fallback(Gen.texel_offset_fold), texel offsets forimage_sample*_oare folded into the UV coordinates by dividing by the size of the sampled level.Previously:
_l_o,_lz_o,_c_lz_o, and explicit LOD 0 outside PS) ignored the sampler descriptor's[MIN_LOD, MAX_LOD]bounds. For example, if a sampler hadMIN_LOD = 1.0, animage_sample_lz_ooperation would calculate the texel shift using level 0's dimensions while the GPU hardware sampled from level 1 (halving the effective offset)._b_oadded its instruction bias afterOpImageQueryLodhad already applied the sampler clamp, potentially overshootingMAX_LODor falling belowMIN_LOD.Changes
tools/rdna2spirv.py:smp_word1(a[3]["r"] + 1) totexel_offset_fold._l_o) and biased LOD (_b_o) to S# word 1's[MIN_LOD, MAX_LOD]usingclamp_gather_lod._lz_oand_c_lz_o(requested LOD 0.0): if S# word 1 is a literal constant withMIN_LOD == 0.0, emit level 0 directly with zero instruction overhead; otherwise clamp LOD 0.0 to[MIN_LOD, MAX_LOD].docs/design.md:tests/test_texel_offsets.py:Testing
python -m compileall -q make_game.py tools tests: OKpython -I make_game.py --help: OKpython tests/semantic/regen_fixtures.py --check: OKpython tests/test_shader_checks.py: 60/60 OKpytest -v tests/test_texel_offsets.py: 26 passed, 9 skipped (0 regressions, 5 new tests)python -m unittest discover -s tests/semantic: 2,567 passed, 3 skipped (0 regressions)Item: SHADER-491
Claim: #2716 (comment)