Skip to content

rdna2spirv: image_sample_c and image_sample_c_b, depth compares with implicit LOD (EGEN-MIMG-SAMPLE-C) - #2965

Merged
ItsNotRexed merged 4 commits into
ItsNotRexed:mainfrom
evilclanker9000:feat/image-sample-c
Nov 23, 2026
Merged

ItsNotRexed merged 4 commits into
ItsNotRexed:mainfrom
evilclanker9000:feat/image-sample-c

Conversation

@evilclanker9000

@evilclanker9000 evilclanker9000 commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Requested by Lucas · project thread

Claimed in the coordination issue as: EGEN-MIMG-SAMPLE-C, #2716 (comment)

What and why

image_sample_c (HLSL SampleCmp, the usual PCF shadow tap) and image_sample_c_b were refused with Unsupported; only image_sample_c_lz (and _c_lz_o) translated. The image-op code already parsed the compare and bias operands for these kinds but had no emission branch, so this adds it:

  • image_sample_c in a pixel shader is OpImageSampleDrefImplicitLod; image_sample_c_b adds Bias. The _o forms add the texel Offset (or, with --texel-offset-fallback, the existing coordinate shift with a Grad sample of the unshifted coordinate's derivatives, scaled by 2^bias for _c_b). The result is one value: f32 bits, or an f16 in the low half with d16, as for _c_lz.
  • Outside a pixel shader there are no derivatives: image_sample_c samples LOD 0 (as image_sample does), image_sample_c_b stays Unsupported.
  • Bug fixed on the way: the address order after the offset dword is bias, then z-compare (GFX10 MIMG); the parser took the compare first for _c_b, which no path reached before. ps_sample_c_b fails on that (a bias of 1.0 read as the reference compares false everywhere); the a16 branch already assumed bias first.
  • vk_texture_test ignored LEONIDA_VK_DEVICE (it kept its own rank loop), so LEONIDA_VK_DEVICE=radeon ran the texture tests on the RTX 5080. It now uses pick_device like the other harnesses; a filter that names no GPU exits 1 as in vk_compute_test. This hunk is the same as the one in GPU tests: image_sample_l, image_sample_b_o, image_sample_c_lz_o, image_gather4_lz, image_load_mip #2225 (character for character, apart from my modes in the neighbouring lines), so whichever of the two merges first leaves the other a trivial merge there; this PR does not depend on GPU tests: image_sample_l, image_sample_b_o, image_sample_c_lz_o, image_gather4_lz, image_load_mip #2225.

Left out: image_sample_c_l (#2685), _cl, and the compare samples with gradients (_c_d, _c_cd), still refused. image_sample_c_b is covered with its own GPU test but a one-level texture cannot show a bias changing the mip; the operand order and the Bias operand are what the tests pin.

Tested

  • New GPU tests ps_sample_c and ps_sample_c_b (hand-written, the D32 depth texture and comparison sampler of ps_sample_c_lz; all 4096 pixels exact for the f32 result and the d16 one) through new vk_texture_test modes dref_c and dref_c_b; derivation in each header.
  • Red on main: both fail with "missing .spv (translation failed)". With this change:
    • NVIDIA GeForce RTX 5080 (driver 616.92, device: NVIDIA GeForce RTX 5080): 4/4 of --filter ps_sample_c (the two new tests, ps_sample_c_lz, ps_sample_c_lz_a16).
    • AMD Radeon iGPU, RDNA2 (driver 26.10.1, device: AMD Radeon(TM) Graphics, selected with LEONIDA_VK_DEVICE=radeon now that the harness honours it): 4/4.
  • Negative controls: restoring the old compare-before-bias order fails ps_sample_c_b on the Radeon (2048 of 4096 pixels wrong) and the semantic order test; replacing the reference with 0 fails ps_sample_c. Both reverted.
  • tests/semantic/test_sample_c.py: Dref implicit LOD, Bias, Offset, d16, LOD 0 outside the PS, the _c_b refusal there, the bias-before-compare order, spirv-val. tests/test_texel_offsets.py gains the _c_o, _c_b_o and a16 forms (signed offset fields, and the fallback's Grad Dref sample).
  • python -m unittest discover -s tests/semantic, python tests/semantic/regen_fixtures.py --check, python -I tests/test_shader_checks.py, pytest tests/test_translate.py tests/test_texel_offsets.py: pass.

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.

AI-assisted.

…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.
@Doffi4

Doffi4 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Independently tested 9f6d4c68 on Windows 11 (26200), Radeon 780M (26.11.2) and RTX 5060 Laptop (621.01). With each ICD isolated in turn, run_gpu_tests.py --filter ps_sample_c --require-pass passed 4/4 on both GPUs (ps_sample_c, ps_sample_c_b, ps_sample_c_lz, ps_sample_c_lz_a16), with 5/5 modules translated and validated in each run. I also ran the texture harness directly with both ICDs visible: LEONIDA_VK_DEVICE=780M and 5060 each logged the correct device and matched all 4,096 pixels for the f32 and d16 depth compares, and a nonexistent adapter returned exit 1 without falling back. Synthetic inputs only. AI-assisted testing and reporting.

@KiryaAfimin

Copy link
Copy Markdown
Contributor

Tested e620b926 on Windows 11 with an RTX 4070 (driver 621.01). To check the effect of the bias on mip selection, I used a local vk_texture_test harness with a 64×64 D32 base level and a 32×32 second level. The two levels had opposite depth patterns, so selecting mip 1 flipped the comparison result at every pixel.

ps_sample_c matched mip 0 and ps_sample_c_b with bias +1.0 matched mip 1. Both the f32 and d16 results matched at all 4,096 pixels. As a control, I removed only the two Bias operands from the generated SPIR-V and reran the draw. Both outputs returned to the mip 0 pattern across the entire frame.

AI-assisted

@Marukooh

Copy link
Copy Markdown
Contributor

Tested e620b926 on CachyOS Linux, Python 3.14. tests/semantic/test_sample_c.py, tests/test_texel_offsets.py: 47 passed, 8 subtests passed.

The sample-C and texel-offset suites passed, including the explicit bias and unsupported-form assertions. This run used the CPU tests.

AI-assisted, synthetic inputs only.

@UNYTIX

UNYTIX commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Independent check on an AMD Radeon RX 7800 XT (gfx1101, driver 32.0.32029.2010, Windows 11), at e620b926 — which already contains origin/main (16282101), so this is the merge result as it stands.

Pass. Rebuilt vk_texture_test (MSVC 2022, cmake --build runtime/build --target vk_texture_test) and ran both new modes from a directory holding the translated vs_ids.spv and the shader:

vk_texture_test dref_c   -> "vk_texture_test dref: PASSED (4096 pixels, f32 and d16 depth compares exact)"
vk_texture_test dref_c_b -> "vk_texture_test dref: PASSED (4096 pixels, f32 and d16 depth compares exact)"
device: AMD Radeon RX 7800 XT

Two extra checks that the pass is not just the harness being generous:

  • Byte-identical to the already-verified LOD-0 shader. ps_sample_c_lz run through dref produces the same 65,536-byte RGBA32F readback as ps_sample_c and ps_sample_c_b (same SHA-256 prefix 2c5b4fb11d690e4a). So the implicit-LOD and bias forms give exactly the image the existing test expects, not merely "a pass".
  • The pixel oracle is independent of the mode selector. Before rebuilding, the same two shaders also passed the pre-PR binary's dref mode when dropped in as ps_sample_c_lz.spv, so the words pass on the old harness too; the mode plumbing is the only new part.

LEONIDA_VK_DEVICE through the new pick_device path: RTX 9999 → rc 1 and LEONIDA_VK_DEVICE=rtx 9999: no Vulkan physical device matches; RX 7800 → picks the card and passes. Correct in both directions.

Also on this tree: tests/semantic/test_sample_c.py 8 tests OK, tests/test_texel_offsets.py 39 passed (pytest), tests/test_shader_checks.py OK, tests/test_run_gpu_tests.py OK. The two new shaders translate with 2 shaders: … 2 translated, 2 pass spirv-val (with vs_ids).

One limitation of my run, not of the PR: llvm-mc is not installed here, so I built the disassembly from the .asm files by tab-indenting them (same mnemonics, no -show-encoding columns) and translated that; the translator reports spirv-val clean for all three. Everything above is the translated path on real hardware, not a native run.

@crastinator

Copy link
Copy Markdown
Contributor

Tested e620b92 merged into main 16282101 (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 tests pass natively: ps_sample_c (ok); ps_sample_c_b (ok).
  • Whole run_gpu_tests.py: 177/191 native, 177/191 with LEONIDA_W64_EMULATE=1 (the skips are the D3D12-only fixtures and ps_w64x_readlane, as on main). ctest 37/37.
  • tests/semantic/test_sample_c.py, tests/test_texel_offsets.py: 47 passed, 8 subtests passed.

No game files. AI-assisted (Claude Code).

@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):

No problems found. ctest on the RTX 4080 SUPER: 129/129 passed. Intel UHD 770 ctest: only the two known base failures, d3d12_descriptor (fixed by #2948) and d3d12_subgroup (fixed by #2934). d3d12_present also failed once in the full Intel run but is intermittent under load (passes alone on Intel).
Fixtures ps_sample_c, ps_sample_c_b, ps_sample_c_lz, ps_sample_c_lz_a16: all PASS on both RTX 4080 SUPER and Intel UHD 770.

tools/rdna2spirv.py

AI-assisted.
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.

8 participants