Skip to content

Shader: preserve implicit mip selection for typed 2D samples (SHADER-229) - #1641

Merged
ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
evilclanker9000:codex/implicit-typed-mips
Nov 22, 2026
Merged

ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
evilclanker9000:codex/implicit-typed-mips

Conversation

@evilclanker9000

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as SHADER-229.

What and why

Pixel-shader image_sample on a signed or unsigned 2D view needs the matching sampled type. The old float path interprets the integer payload as float when packing D16. Compute UV derivatives before the descriptor-format branch and use those gradients when sampling the selected float, UINT or SINT alias. This keeps mip selection defined even when invocations choose different format branches.

Tested

  • The synthetic ps_sample_implicit_sint fixture minifies a signed 128x128 image onto a 64x64 draw. Clamping at mip 0 selects the four test quadrants. Permitting mip 1 selects cyan. All 4,096 RGBA pixels matched the CPU reference in each pass with the earlier tested patch on RTX 5080 (616.92) and Radeon gfx1036 (32.0.21045.16010). The pre-fix integer D16 readback was wrong at every pixel.
  • On base 41f4482, the new structural test fails because the typed gradient samples are absent. On e5f9661 it verifies the three sampled types and the placement of the derivatives before format dispatch. The typed-image, GPU-runner and shader-checker Python tests pass 83 checks, with two optional SPIR-V-Tools checks skipped on this host.
  • Exact-head GPU and CI runs are pending. Sample integer 2D textures through typed views at LOD zero #1405 covers explicit LOD zero.

Checklist

  • No game data, keys or decryption, including in reports.
  • The translator rule and its evidence are in docs/design.md.

AI-assisted.

Sampling an integer image through a float view makes D16 convert the wrong numeric values. Compute the quad derivatives before branching to the matching view so implicit minification still chooses the correct level.

@dcastell1 dcastell1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardware run: RTX 5090 (621.24), Windows 11, this PR's tree, the six vk_*_test programs rebuilt from the same commit, LEONIDA_W64_EMULATE=1: 146/146 GPU tests pass, with the new one exact:

PASS  ps_sample_implicit_sint   two passes, 4096 RGBA32F pixels each exact; wrong mip and UV rejected

The "wrong mip and UV rejected" part is what makes this a real test rather than a screenshot: it fails if the integer payload is sampled with the wrong LOD. Nothing else moved.

Scope note: this is the type-correctness half. It does not say anything about the untyped/typeless views the game actually binds; if that is a separate item (SHADER-229a?), it deserves its own case.

…d-mips

# Conflicts:
#	scripts/run_gpu_tests.py
@evilclanker9000

Copy link
Copy Markdown
Contributor Author

On 0a1b235 after merging upstream/main a0acd33, the typed-image, GPU runner, shader checker and texel-offset pytest suites pass 119 tests and 235 subtests, with 11 options skipped for missing SPIR-V tools. The new get-LOD fixtures added in main remain registered. AI-assisted.

@evilclanker9000

Copy link
Copy Markdown
Contributor Author

Follow-up on 0a1b235 using the Vulkan SDK tools: the typed-image and texel-offset tests passed 44 tests and 24 subtests with no skips. The source-built ps_sample_implicit_sint also assembled, translated and passed spirv-val. GPU execution is a separate check. AI-assisted.

@ItsNotRexed
ItsNotRexed merged commit 1676a01 into ItsNotRexed:main Nov 22, 2026
2 of 4 checks passed
@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. ctest: 95/95 on the RTX 4080 SUPER. The Intel UHD 770 failures are the known ones, all reported in #1548: d3d12_vulkan_device (line 3768), d3d12_descriptor (min-LOD), d3d12_present, d3d12_copy_xfmt, plus d3d12_m3_frame (doubled occlusion count, also in #1548).

@crastinator

Copy link
Copy Markdown
Contributor

Tested e5f9661 merged into main 41f44826 (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.

  • New test pass natively: ps_sample_implicit_sint (two passes, 4096 RGBA32F pixels each exact; wrong mip and UV rejected).
  • Whole run_gpu_tests.py: 146/146 native, 146/146 with LEONIDA_W64_EMULATE=1 (main alone: 145).
  • tests/test_image_load_typed.py: 14 passed, 24 subtests passed.

No game files. AI-assisted (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.

5 participants