Skip to content

Use the texture format for 2D explicit-LOD samples - #2458

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
Vonsek:codex/typed-explicit-lod-2d
Nov 22, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
Vonsek:codex/typed-explicit-lod-2d

Conversation

@Vonsek

@Vonsek Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as 2D explicit-LOD texture format dispatch.

What and why

A 2D image_sample_l always used a floating-point sampled image, including when T# word 1 specified R32_UINT or R32_SINT. Vulkan gives a poison texel when the sampled type or signedness mismatches the image view. The instruction now uses the same format dispatch as image_sample_lz and passes the explicit LOD to every branch. A descriptor lookup miss still reads the float fallback. Vulkan sampling validation

Tested

  • Used LLVM MC for gfx1030 to assemble four hand-written instructions combining ordinary or A16 addresses with full-width or D16 destinations. All four synthetic shaders translated, assembled and passed SPIRV-Tools validation for Vulkan 1.2 on both revisions.
  • Evaluated the generated descriptor branch on the CPU for three descriptor words per instruction. Before the change, four of twelve hits selected the matching type (the four float cases). After the change, all twelve selected the matching type. The regression checks that every full-address branch reads the LOD from v6 and that misses select float.
  • Ran the typed image, cube sampling and texel offset test files together. 62 tests and 26 subtests passed on Windows. No GPU, driver readback or game corpus was used.

AI-assisted with Codex.

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • The new translator rule is in the contract table of docs/design.md, with the reference and CPU check.

Integer images need an integer sampled type for defined Vulkan texels. Use the descriptor format to select it while carrying the supplied mip level into every branch.
@duudiis

duudiis commented Nov 22, 2026

Copy link
Copy Markdown

Independent GPU regression check of ede5918 against its parent 4947579 on Windows 11 build 26300, RTX 5070, driver 621.24. I temporarily extended the two-mip Vulkan texture harness to bind R32_UINT, R32_SINT, and R32_SFLOAT views, with distinct constant texels per mip. The harness source has been restored.

A hand-written fragment shader used image_sample_l with both address widths, both destination widths, and explicit LOD 0 or 1. The A16 address put the opposite LOD in the unused upper half to catch selection of the wrong half. The shader unpacked the signed and unsigned D16 outputs and converted them to float for readback. I also tested two lookup misses with integer T# format words against the float fallback.

  • PR: 26/26 draws exact (4,096/4,096 pixels each). Mip 0/1 returned 37/271, -37/-271, and 0.25/0.75 for UINT, SINT and FLOAT respectively. Both misses returned 1.0 from the fallback.
  • Parent: 18/26 draws exact. Every integer D16 draw failed in all 4,096 pixels at both LODs and both address widths. UINT returned zero and SINT returned -1 on this driver. The other 18 cases matched. These baseline outputs describe this run with the old lowering.

All generated modules passed Vulkan 1.2 spirv-val and all 14 tests in test_image_load_typed.py passed on the PR. Synthetic inputs only. AI-assisted review.

@kacper-serewis

Copy link
Copy Markdown
Contributor

Independent package check of ede5918 against its parent 4947579, using ten local Xbox 1.0.2.1 shaders selected for containing image_sample_l from a previously disassembled slice. All ten compiled modules changed. With wave64 emulation, 10/10 translated and passed spirv-val on each revision. With a separate fresh Vulkan pipeline cache per revision, an RTX 5070 (32-lane subgroups, Windows 11, NVIDIA 616.56) created all eight mesh pipelines and both pixel pipelines on both revisions, with no failures or skips. This check covered package compilation and pipeline creation; the sample was bounded and did not measure texture readback. AI-assisted.

@sperm

sperm commented Nov 22, 2026

Copy link
Copy Markdown

Tested ede5918 on AMD Radeon RX 9070 XT (RADV GFX1201) and the Ryzen 7 9800X3D iGPU (RADV RAPHAEL_MENDOCINO, gfx1036), Mesa 26.2.6, Linux 7.3.4: pass, no regressions.

  • Full python -I scripts/run_gpu_tests.py (Linux build of this branch's runtime/, LEONIDA_VK_DEVICE per GPU): 170/185 passed, 15 skipped, 0 failed on both GPUs. Compared with the same suite at the merge base 4947579 on the same machine, every test has the same result.
  • python -m unittest discover -s tests/semantic: 2567 OK
  • tests/test_image_load_typed.py: 14 OK

No game files. AI-assisted.

@RSK2707X

Copy link
Copy Markdown

Tested ede5918 against its parent 4947579 on the AMD proprietary Windows driver: AMD Radeon RX 7600 (RDNA3, subgroup 32..64), AMD 26.11.2 (LLPC), Windows 11 10.0.26300. Pass, no regressions.

  • Full python -I scripts/run_gpu_tests.py, same runtime build: 170/185 passed, 15 skipped on both revisions, and all 185 result lines identical. That includes the sampling tests ps_texoff (whose image_sample_l_o goes through the changed LOD path), ps_texoff_implicit, ps_texture_mip0, ps_texture_sample, ps_sample_implicit_sint, ps_gather_sampler_lod and cs_sample_lz_int_d16. rdna2spirv: 190/190 translated and passed spirv-val on each.
  • python -I tests/test_image_load_typed.py on this PR: 14 tests OK.

Not covered by this run: an integer (R32 UINT/SINT) image_sample_l on the GPU. The suite has no such fixture, so the new branches are checked here only by the CPU test and by @duudiis's harness run.

Run with an AI assistant (Claude).

@zneel

zneel commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested ede59188 on AMD Radeon RX 9070 XT (RDNA4, subgroup 32..64), AMD 26.11.2, Windows 11 Pro 10.0.26300, AMD Ryzen 7 9800X3D CPU (64 GB RAM), Python 3.12.10: pass.

Runtime and test programs built from this head (MSVC 14.51, Ninja, RelWithDebInfo), native Windows llvm-mc 21.1.8, Vulkan SDK 1.4.363.0. No game files.

run result
run_gpu_tests.py (whole suite, native wave64) 170/185, 15 skipped, 0 failed (main 49475796: 170/185)
same with LEONIDA_W64_EMULATE=1 170/185, 15 skipped, 0 failed
pytest tests/test_image_load_typed.py tests/test_translate.py 540 passed, 2 skipped, 26 subtests passed in 64.33s (0:01:04)

No suite shader uses a 2D image_sample_l: every module from the native run is byte-identical to main 49475796. So the GPU rows show no regression, not the new format dispatch on hardware. An R32_UINT/SINT explicit-LOD readback would be the GPU test for it.

AI-assisted (Claude Code); I checked the results.

@Doorriiaann

Copy link
Copy Markdown

Tested ede5918 on NVIDIA GeForce RTX 3070 (Ampere, subgroup 32..32), driver 610.57.04 (Vulkan 1.4.341), Debian 13 (kernel 6.12.115): pass, no regression. Adds Linux NVIDIA to the runs above.

Base is main 4947579; runtime/build/linux built from each side; llvm-mc 21.1.8, SPIRV-Tools v2025.5, GCC 14.2.0.

main 4947579 this PR
python -I tests/test_image_load_typed.py 2 failures, test_2d_lod_samples_use_matching_typed_views 14 tests OK
python -I -m unittest discover -s tests/semantic 2567 tests OK 2567 tests OK
scripts/run_gpu_tests.py 139/185 passed, 46 skipped 139/185 passed, 46 skipped
LEONIDA_W64_EMULATE=1 scripts/run_gpu_tests.py 170/185 passed, 15 skipped 170/185 passed, 15 skipped

The main column for test_image_load_typed.py is the negative control (this PR's file against main's translator).

AI-assisted: yes

@lunisahdidouch

Copy link
Copy Markdown

Tested ede5918 on an RX 9070 (RDNA4), AMD 26.11.1 (LLPC), Vulkan 1.4.359, Windows 11: pass

tests/test_image_load_typed.py passes (14 tests), tests/semantic passes (2567 tests, OK). Full run_gpu_tests.py: 170/185 passed, 15 skipped, nothing failed, all the texture sampling tests included, identical to main 4947579.

AI-assisted

@JRamos1993

Copy link
Copy Markdown
Contributor

Tested ede5918 on an RTX 5090 (driver 616.92), Windows 11, Vulkan SDK 1.4.363. The GPU test programs were built from the same tree:

  • scripts/run_gpu_tests.py: 139/185 passed, 46 skipped, 0 failed. main 4947579 gives 139/185, 46 skipped, 0 failed. All 190 test shaders translate and pass spirv-val.
  • tests/test_image_load_typed.py: ran 14 tests in 0.572s; OK (skipped=2).

AI-assisted (Claude Code).

@MiguelMatMar

Copy link
Copy Markdown

Tested ede5918 on RTX 4080 SUPER (Ada, subgroup 32), NVIDIA 621.24 (Vulkan 1.4.357), Windows 11 Pro build 26300; MSVC 14.44, Vulkan SDK 1.4.363.0, llvm-mc 21.1.8 built with scripts/build_llvm_mc.ps1, Python 3.14: pass

  • python -I scripts/run_gpu_tests.py (runtime built at the PR's base 49475796): 139/185 passed, 46 skipped, 0 failed. 190/190 translated, 190 pass spirv-val. Same as the base on this GPU. The skips are the 64-wide-subgroup tests and the ones another harness runs.
  • LEONIDA_W64_EMULATE=1 ... --filter w64: 25/26 passed, 1 skipped, 0 failed (same as the base).
  • tests/test_image_load_typed.py: 12 passed, 2 skipped.
  • python -m unittest discover -s tests/semantic: OK. tests/test_translate.py with llvm-mc + SPIRV-Tools on PATH: all passed (2 skipped).

@edubox

edubox commented Nov 22, 2026

Copy link
Copy Markdown

Tested ede59188 on an NVIDIA GeForce RTX 4080 SUPER (Ada), driver 620.70.06, Vulkan 1.4.357, Linux x86-64: pass, no regression.
Tested ede59188 on an AMD Radeon 610M iGPU (RDNA2, gfx1036), RADV Mesa 26.2.6, Vulkan 1.4.354, same host: pass, no regression.

The PR touches only tools/rdna2spirv.py, tests/ and docs/ (no C++), and its base is our main 49475796, so I ran its Python against a runtime/build from that same main and compared the per-test status lists, not just the totals:

Device run_gpu_tests.py vs main
RTX 4080 SUPER 139/185 passed, 46 skipped, 0 failed identical line by line
Radeon 610M (RADV) 170/185 passed, 15 skipped, 0 failed identical line by line

So the descriptor branch change does not move a single texture, cube, texel-offset or integer-format fixture on either driver. test_image_load_typed.py 14 OK, test_image_load_d16_typed.py 4 OK (pytest).

Red on main, as claimed. Running the PR's tests/test_image_load_typed.py against main's tools/ fails 2 tests with Items in the second set but not the first: '%v4uint_st', '%v4int_st', i.e. exactly the integer sampled-array aliases this PR adds; on the PR head the file is 14 OK. The fix is what makes those two declarations appear, not a test that already passed.

AI-assisted.

@erickbobd

Copy link
Copy Markdown
Contributor

Tested ede5918 merged onto main ec8ec4c on an NVIDIA GeForce RTX 5070 Ti (desktop), driver 617.14, Windows 11 (build 26200), subgroup 32..32: pass, no regression, but the GPU suite doesn't reach the changed path.

  • scripts/run_gpu_tests.py (runtime built from main): native 143/189 passed, 46 skipped; LEONIDA_W64_EMULATE=1 174/189 passed, 15 skipped; identical per test to main
  • none of the 197 translated test shaders change with this PR, so no current fixture has a 2D image_sample_l on an R32_UINT/R32_SINT view; the fix itself is still checked only on the CPU
  • semantic suite merged with main: 4137 tests OK; tests/test_image_load_typed.py: 16/16 OK

A GPU fixture for 2D explicit-LOD samples on integer views (uint and sint, plus the float miss path) would check it on hardware. I can write one if that helps.

Setup note: LLVM_MC pointed at a shim over AMD RGA 2.15's clang -cc1as (LLVM 23.0.0git); see my note on #2463.

@Vonsek

Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for checking the suite against main. A permanent R32_UINT/R32_SINT explicit-LOD fixture would be useful. The independent RTX 5070 check already exercised the changed path in a temporary harness, but those cases are missing from the committed suite. If you pick it up, please coordinate the follow-up in the tracker and include the float fallback as a control. Keeping the fixture in a follow-up PR makes the two changes independently reviewable.

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.