Skip to content

d16 image_sample_lz and image_gather4_lz on 2D_ARRAY and CUBE round by the T# format (BUILD-1916) - #6264

Open
BetterJdue wants to merge 3 commits into
ItsNotRexed:mainfrom
BetterJdue:shader-308-array-d16
Open

BetterJdue wants to merge 3 commits into
ItsNotRexed:mainfrom
BetterJdue:shader-308-array-d16

Conversation

@BetterJdue

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: BUILD-1916 (claim)

What and why

Follow-up to #4318, from @kacper-serewis's review. #4318 made the d16 image reads that go through Gen.image_read_typed narrow by the T#'s format. On main 561b65a8, d16 image_sample_lz and image_gather4_lz on 2D_ARRAY and CUBE images read the float view directly and still packed with nearest even (pack_f16_pair_int): a 32_FLOAT 0x3f7ff001 read 0x3c00 instead of 0x3bff, and the UNORM/SNORM halfway quotients were not corrected.

  • tools/rdna2spirv.py: those forms narrow through the new Gen.d16_fmt_pair, which is Gen.d16_norm_f16 with Gen.fmt_float_flags of T# word 1, the rule the 2D reads use (UNORM/SNORM: the exact quotient rounded once; 32_FLOAT: toward zero). Other ops and dimensions are unchanged.
  • tools/d16_image_probe.py --dims 2d_array,cube: measures 2D_ARRAY and CUBE image_load, point image_sample_lz and image_gather4_lz, f32 and d16, through tools/hw_oracle. Four array layers, all six cube faces. Each gather tap's texel is identified from the f32 gather of the same footprint, so the tap order and face edges don't matter.
  • tests/semantic/test_image_d16_rounding.py: the CPU-side translator test asked for on d16 image results round like typed buffer loads, and 32_FLOAT truncates (SHADER-308) #4318. It checks the T# format tables (Gen.float_format_masks) and that every d16 half of the 2D reads and of the 2D_ARRAY/CUBE sample and gather goes through Gen.d16_norm_f16, then runs spirv-val on the modules.
  • runtime/test/shaders/ps_d16_array_sample.asm, ps_d16_cube_sample.asm and the new vk_texture_test d16_array|d16_cube f32|unorm16|snorm16 modes run the translated forms on a GPU. The 12-layer array at binding 3 is in R32_SFLOAT, R16_UNORM or R16_SNORM, and the T# carries that format. Every d16 half (one sample and three gather taps per pixel) is checked against the measured rule. scripts/run_gpu_tests.py runs both fixtures in all three formats.
  • docs/design.md ("d16 and f16 format narrowing"):

Tested

AMD Radeon RX 6700 (gfx1031, discrete RDNA2), AMD Windows driver 32.0.21045.29003 (Vulkan driverInfo 26.11.2), Windows 11 Pro 26300. Base main 561b65a8.

Hardware (python -I tools/d16_image_probe.py --dims 2d_array,cube, wave32 and wave64, 0 words differ between them):

format 2D_ARRAY CUBE
UNORM16, SNORM16 load and point sample: 65,536/65,536 the quotient rounded once; gather: 262,144/262,144 taps. Through f32 first: off on the 2 halfway values the same counts
32_FLOAT toward zero on 1,024/1,024 lanes and 4,096/4,096 taps; 0 of 52 halfway patterns (103 in the gather) went to the even neighbour; 0x3f7ff001 gives 0x3bff 2,048/2,048 lanes, 8,192/8,192 taps; 0 of 104 (311) to even; 0x3f7ff001 gives 0x3bff
16_FLOAT its own bits on every lane and tap the same

So the array and cube reads follow the 2D rule exactly. The f32 controls held (the f32 load is the texel's f32, the point sample equals the load).

Translated, on the same GPU through Vulkan (python -I scripts/run_gpu_tests.py --filter ps_d16):

fixture this branch tools/rdna2spirv.py from main
ps_d16_array_sample f32, unorm16, snorm16: 4,096/4,096 samples and 12,288/12,288 gather taps exact f32: 2,115 samples and 2,098/2,177/2,204 taps wrong; unorm16 and snorm16: 12 samples and 6 taps wrong (the pixels reading the 2 halfway values)
ps_d16_cube_sample the same, all exact the same failures

The 768 texels hold 56 f32 halfway points (or the 2 UNORM16/SNORM16 halfway values) plus others. Every module passes spirv-val.

CPU:

  • test_image_d16_rounding: 8/8. With main's translator the 5 array/cube cases fail. With the translator from before d16 image results round like typed buffer loads, and 32_FLOAT truncates (SHADER-308) #4318 (00b9b568), 7 of 8 fail.
  • tests/test_d16_image_probe.py: 21/21, two of them on the hardware.
  • tests/test_run_gpu_tests*.py: 68/68.
  • Compared with 561b65a8 without the patch:
    • python -m unittest discover -s tests/semantic: 6,158 vs 6,150 tests, OK on both.
    • pytest tests/test_translate.py: 635 vs 633 passed (the two new fixtures).
    • 0 new failures, 0 fixed.
    • The node viewer-streaming test fails on both sides.
    • tests/test_rdna2_decode.py's llvm-mc parity fails on main too (cs_w32_permlane_fi.asm, op_sel), not on these fixtures.

Not run: the shader corpus (no game files here), the full GPU suite, and the other sample kinds on these dimensions (image_sample_l, ...), which still use the generic rule and are not measured.

Not changed, noted: on the hardware, a dmask 0x1 d16 point sample on 2D_ARRAY/CUBE keeps the VGPR's high half (65,536/65,536 lanes), as the 2D reads do. The generic sample path here writes the whole VGPR (high half 0), so that is still the case after this change.

AI-assisted: yes

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 verification using synthetic inputs.

…ADER-308 follow-up)

Review on ItsNotRexed#4318: image_sample_lz and image_gather4_lz with d16 on 2D_ARRAY
and CUBE images read the float view directly, not through
image_read_typed, and still rounded every float-class result to nearest
even. They now narrow through Gen.d16_fmt_pair: Gen.d16_norm_f16 with the
T#'s format class (Gen.fmt_float_flags), the rule the 2D reads use
(UNORM/SNORM: the exact quotient rounded once; 32_FLOAT: toward zero).

tools/d16_image_probe.py --dims 2d_array,cube measures those reads on the
hardware (image_load, point image_sample_lz, image_gather4_lz; f32 and d16;
UNORM16, SNORM16, 32_FLOAT, 16_FLOAT; wave32 and wave64). On an RX 6700
(gfx1031) they follow the same rule as 2D on every lane and gather tap.

tests/semantic/test_image_d16_rounding.py checks the format tables and that
every d16 half of the 2D reads and of these array and cube forms goes
through Gen.d16_norm_f16. runtime/test/shaders/ps_d16_array_sample.asm and
ps_d16_cube_sample.asm run the translated forms on a GPU through new
vk_texture_test d16_array / d16_cube modes (the 12-layer array in
R32_SFLOAT, R16_UNORM or R16_SNORM), every d16 half checked.

docs/design.md: the 32_FLOAT tie is narrowed toward zero, not to even; the
leftover "still inferred" sentences go; the array and cube forms and what
checks the image path are listed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@CryingLaughing

Copy link
Copy Markdown
Contributor

Tested 161a31b8d8cc3d48b2fa7c8a2a91319644270aad on an NVIDIA GeForce RTX 4080, NVIDIA driver 621.01, Windows 11 25H2 (26200.9974). Pass: 6/6 cases via native Vulkan.

Ran scripts/run_gpu_tests.py --filter ps_d16 with LEONIDA_VK_DEVICE=RTX 4080. The synthetic 2D_ARRAY and CUBE fixtures each passed in R32_SFLOAT, R16_UNORM and R16_SNORM. Each case matched 4,096 point samples and 12,288 gather taps exactly (24,576 samples and 73,728 taps total).

For the A/B control, I translated the same synthetic inputs with 561b65a832218fbb9e6d2effd392a8eef093a3f8 and ran them through the same vk_texture_test binary. The baseline failed all six cases. For each dimension, R32_SFLOAT had 2,115 sample mismatches and 2,098 / 2,177 / 2,204 mismatches across the three gather channels. R16_UNORM and R16_SNORM each had 12 sample and 6 gather mismatches. All three modules per revision passed spirv-val.

AI-assisted verification and reporting. All fixtures and inputs were synthetic.

@shayderrr shayderrr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Summary

Follow-up to #4318: tools/rdna2spirv.py now routes d16 image_sample_lz and image_gather4_lz on 2D_ARRAY/CUBE images through the new Gen.d16_fmt_pair (Gen.d16_norm_f16 with T# format class from Gen.fmt_float_flags), so 32_FLOAT narrows toward zero and UNORM/SNORM halfway quotients round once. Adds tests/semantic/test_image_d16_rounding.py, new array/cube shader fixtures and vk_texture_test d16_array|d16_cube modes, extends tools/d16_image_probe.py --dims 2d_array,cube, and updates docs/design.md.

Why merge

Closes a real rounding mismatch (e.g. 32_FLOAT 0x3f7ff001 gave 0x3c00 instead of 0x3bff) on array/cube d16 reads, bringing them in line with the already-correct 2D path and measured hardware.

Verdict: Approve

@shayderrr

Copy link
Copy Markdown
Collaborator

Summary

Follow-up to #4318: tools/rdna2spirv.py now routes d16 image_sample_lz and image_gather4_lz on 2D_ARRAY/CUBE images through the new Gen.d16_fmt_pair (Gen.d16_norm_f16 with T# format class from Gen.fmt_float_flags), so 32_FLOAT narrows toward zero and UNORM/SNORM halfway quotients round once. Adds tests/semantic/test_image_d16_rounding.py, new array/cube shader fixtures and vk_texture_test d16_array|d16_cube modes, extends tools/d16_image_probe.py --dims 2d_array,cube, and updates docs/design.md.

Why merge

Closes a real rounding mismatch (e.g. 32_FLOAT 0x3f7ff001 gave 0x3c00 instead of 0x3bff) on array/cube d16 reads, bringing them in line with the already-correct 2D path and measured hardware.

Verdict: Approve

@junaydirfan

Copy link
Copy Markdown

Tested 161a31b8 merged into main 9077af1f on Linux (CachyOS), with LEONIDA_W64_EMULATE=1 and test programs built from the merge: pass.

GPU driver run_gpu_tests.py main
Intel Raptor Lake-S iGPU (Xe-LP), subgroup 8..32 Mesa ANV 26.3.1 201/234 passed, 33 skipped, 0 failed 199/232
RTX 4080 Laptop GPU (Ada) NVIDIA 620.73.04 216/234 passed, 17 skipped, 1 failed (ms_wave_info_s3, fails on main too; #5741) 214/232
  • ps_d16_array_sample and ps_d16_cube_sample pass on both GPUs with the same detail. f32: 4096 samples and 12288 gather taps exact over 768 texels, 56 of them f16 halfway cases. unorm16 and snorm16: exact, 2 halfway cases each.
  • Negative control: with only tools/rdna2spirv.py put back to main's, both fail on both GPUs, with f32: FAILED, wrong d16 halves: 2115 samples, 2098/2177/2204 gather taps (of 4096 each).
  • Every other test has the same result as on main. The semantic test files that mention the changed ops give 1981 passed on the merge, with no failure that main doesn't also have.

Conflicts: docs/design.md (the d16 row: keep main's removal of the
duplicated sentences, keep this branch's 2D_ARRAY/CUBE text) and
runtime/test/vk_texture_test.cpp (keep both the fetch-* and the
d16_array/d16_cube modes).
Conflict: docs/design.md. ItsNotRexed#6828 dropped the whole "d16 and f16 format
narrowing" contract row, which this branch edits and
docs/shader_validation.md still points to; keep the row.
@BetterJdue

Copy link
Copy Markdown
Contributor Author

Merged main into this branch twice, up to main dde82f27; the head is now bc2861b2. This PR's own changes to tools/rdna2spirv.py, tools/d16_image_probe.py, the fixtures, scripts/run_gpu_tests.py and the tests are unchanged. The conflicts:

Re-tested bc2861b2 on an AMD Radeon RX 6700 (gfx1031), AMD Windows driver 32.0.21045.29003, Windows 11 Pro 26300, with test programs built from this commit (MSVC, Ninja):

run translator scripts/run_gpu_tests.py failed
native this PR 225/243 passed, 17 skipped ms_wave_info_s3
LEONIDA_W64_EMULATE=1 this PR 225/243 passed, 17 skipped ms_wave_info_s3
native tools/rdna2spirv.py from main 224/243 passed, 17 skipped ps_d16_array_sample, ps_d16_cube_sample
  • With this PR, ps_d16_array_sample and ps_d16_cube_sample are exact in f32, unorm16 and snorm16 (4,096 samples and 12,288 gather taps each), native and emulated. With main's translator both fail; the runner reports the first failing format, f32: 2,115 wrong samples and 2,098/2,177/2,204 wrong gather taps (of 4,096 each).
  • ms_wave_info_s3 does not come from this PR: its native module is byte-identical with both translators (only the two d16 modules differ), and over six full runs on this card (three per merge) it passed twice, once with each translator.
  • All 249 shaders translated and passed spirv-val.
  • CPU, main dde82f27 against this PR: python -m unittest discover -s tests/semantic 5,956 → 5,964 tests, with the same 49 failing results (48 failures, 1 error) on both sides, all from five tests in test_image_atomics_guard.py, test_image_cube_store_glc.py and test_image_store_d16.py; pytest tests/test_translate.py 648 → 650 passed; tests/test_d16_image_probe.py 14 → 21 OK; tests/test_docs_design_rows.py and tests/test_design_contract_rows.py pass; compileall clean; tests/test_viewer_streaming.cjs 56/57 on both sides.

AI-assisted verification using synthetic inputs.

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.

4 participants