Repository navigation
Conversation
|
Tested 4b7b0f5 on Windows 11 with CPython 3.14.7. The CPU translation checks pass. I ran I copied the new test file to the parent revision and ran AI-assisted. |
…'s level (SHADER-842) The texel offset fallback divides the offset by the size of the level the sample reads, but texel_offset_fold never received a _cl form's min-LOD clamp. A clamp above the computed LOD makes the sample read a coarser level, so image_sample*_cl_o shifted by texels of a finer level: twice the offset per level. Outside the pixel stage the fold used level 0 while the sample reads max(0, clamp). The fold now raises its level to max(LOD, clamp) before flooring, with the same clamp value the sample takes as MinLod. Vulkan applies MinLod after the bias and the sampler's clamps, and OpImageQueryLod leaves it out. Tests: - tests/test_texel_offsets.py traces the fold's level back from OpImageQuerySizeLod for image_sample_cl_o, image_sample_c_b_cl_o and a vertex-stage image_sample_cl_o; the three tests fail without the fix. - GPU test ps_texoff_cl on a new vk_texture_test --two-mip-index texture, whose mip 1 texels all differ (the --two-mip mip 1 is solid cyan, so no GPU test could see where an offset lands on a clamped level): image_sample_cl_o with offset (+3, -2), clamp 0 on the left half and 1 on the right. check.py and run_gpu_tests.py judge it against the texels derived in the .asm header; tests/test_shader_checks.py tests the judge. On an RTX 5070 it passes with the native Offset and with LEONIDA_TEXOFF_FALLBACK=1, and the fallback without this change gives 2048 wrong pixels (mip 1 texel 9 instead of 11 at x = 32).
4b7b0f5 to
87535fe
Compare
|
@shdann thanks for testing! Since then I've folded the GPU test into this PR (now |
|
Verified commit
Reviewed the diff ( AI-assisted (Gemini, Antigravity). |
Kam471
left a comment
There was a problem hiding this comment.
Ran this at 87535fe07 on Windows 11: pytest tests/test_texel_offsets.py tests/test_shader_checks.py -q -> 138 passed, 267 subtests passed; git diff --check clean.
--texel-offset-fallback now folds the offset at the _cl clamp's level, matching the measured form, with a new GPU fixture (ps_texoff_cl) and runner/check support; the tests cover the folded form, the non-_cl path and the fixture's expected words. No blocking issue.
|
Verified on Linux: tests/test_texel_offsets.py passes all 48 tests (the two new fallback-level-clamp tests plus the pre-existing suite, so the fold change regresses nothing), the semantic test_sample_cl (10 passed) and the translator-use guard pass, and both design.md contract rows were updated as translator changes require. The SPIR-V checks confirm the fold now uses max(LOD, clamp) in-PS and max(0, clamp) outside it. No CI checks were scheduled yet; your commit also sits on the round-43 stacked base. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run). |
Claimed in the coordination issue as: SHADER-842 (claim). This PR also includes the GPU test claimed as a follow-up here.
Depends on: #3882, #2783. This PR builds on neither, but all three edit the level computation in
texel_offset_fold, so whichever lands later needs a small rebase. #3882 (SHADER-699) rounds the level by the S# mip filter and #2783 (SHADER-491) clamps to the S#'s MIN_LOD/MAX_LOD. Both are about the sampler. This PR is about the instruction's own_clclamp, which neither handles.What and why
With
--texel-offset-fallback(GPUs withoutVK_KHR_maintenance8, for example NVIDIA Pascal), animage_sample*_ohas its offset folded into the coordinate as offset ÷ the size of the sampled level.texel_offset_foldnever received a_clform's min-LOD clamp:image_sample_cl_o,_b_cl_o,_c_cl_oand_c_b_cl_oshifted by texels of a finer level, which is twice the offset per level of difference.Lod max(0, clamp).The fold now raises its level to
max(LOD, clamp)(outside the PS,max(0, clamp)) before flooring and clamping to the image's levels. It uses the same SPIR-V value the sample takes asMinLod/ in itsLod. Vulkan applies theMinLodimage operand after the bias and the sampler's LOD clamps, andOpImageQueryLoddoesn't include it, so the fold must add it itself.The existing GPU fixture couldn't show this:
vk_texture_test --two-miphas a solid-cyan mip 1, so a sample clamped to mip 1 reads the same colour wherever the offset lands. This PR therefore also adds a GPU test that can:vk_texture_test --two-mip-index: the same two-mip texture, but mip 1 texel (x, y) = (4x, 4y, 0x80, 0xFF), so every mip 1 texel is different.runtime/test/shaders/ps_texoff_cl.asm:image_sample_cl_owith offset (+3, −2) and coordinates ÷ 4 (unclamped LOD −1). The clamp is 0 on the left half (mip 0) and 1 on the right half (mip 1). The header derives every expected pixel by hand and lists what a dropped offset, an ignored clamp and the old fold would give.check.py(texoff_cl_pixel,texoff_cl_problem,texoff_cl_test, inPIXEL_TESTS) andscripts/run_gpu_tests.pyjudge it. It skips (exit 77) without maintenance8 unless the fallback is on, and withoutshaderResourceMinLod.tests/test_shader_checks.py(TexoffClJudge) tests the judge: the rule passes, and the pre-fix fold, a dropped offset, an ignored clamp and a short dump all fail.Changes in
tools/rdna2spirv.py: one new parameter and oneFMax.docs/design.mdis updated in the "Min-LOD clamp forms" and "Texel offsets" rows, anddocs/testing.mdlistsps_texoff_clwith the other offset tests.Found by reading the code. No open PR or coordination comment mentioned it.
Tested
On an NVIDIA GeForce RTX 5070, driver 617.42 (32.0.16.1742), Vulkan, Windows 10 22H2:
ps_texoff_cl(run_gpu_tests.py --filter ps_texoff_cl)Offset(maintenance8), this PRLEONIDA_TEXOFF_FALLBACK=1, this PRLEONIDA_TEXOFF_FALLBACK=1, translator frommain.asmheader predictstests/test_texel_offsets.py: three new tests trace the fold's level back fromOpImageQuerySizeLod(SClamp ← ConvertFToS ← Floor ← FMax) and check that theFMaxtakes the sample's own clamp value, forimage_sample_cl_o,image_sample_c_b_cl_oand a vertex-stageimage_sample_cl_o. All three fail onmainand pass with the fix. The whole file plustests/test_texoff_probe.pygives 58 passed, includingspirv-val(SPIRV-Tools v2026.4) of every fallback form.tests/test_shader_checks.py(90 passed),tests/test_run_gpu_tests.py(41 passed),tests/semantictest_sample_clandtest_sample_c(18 passed), and thetests/test_docs_*,test_design_contract_rows, line-ending and CSV tests all pass.python -m compileall -q tools tests scripts runtime/test/shaderspasses.main, the fullscripts/run_gpu_tests.pygave 170/217 passed, 0 failed, 47 skipped (wave64 and ctest-run tests).spirv-valcounts weren't run because I have no game copy. The translator change only affects_cl_osamples under--texel-offset-fallback, which is off by default.AI-assisted: yes (Claude Code)
Checklist
docs/design.md, with how it was confirmed. This is a correction to existing rows, confirmed by the GPU test and the structural tests above.