shader: lower d16 image_sample and image_sample_lz in gfx2hlsl #3908
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3908"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-12-03T01:32:16Z.
Refs #2023, #2463
Change
Pixel-stage
image_sampleandimage_sample_lzwithd16were refused asimage_sample[_lz] modifier d16.This is one refusal reason that recurs across many pixel shaders; this PR removes it for the forms below and
leaves the others refused by name.
tools/startup/gfx2hlsl.py(Stage.image): for 2D, 2D-array and 3D images,d16is accepted onimage_sample(implicit LOD) andimage_sample_lz. The channels enabled bydmask, indmaskorder, arenarrowed to binary16 with the existing
pack16_rnehelper and packed pairwise, the first channel of each pairin bits 15:0. This is the same rounding and packing as the native compute
d16_sample_srvlowering(
packed_half_rne).ceil(popcount(dmask) / 2)VGPRs. With an odd channel count, bits 31:16 ofthe last VGPR are undefined: it is marked with the existing
low16_onlytracking, so a whole-word read of itstays refused.
a16together withd16, a destination width other thanceil(popcount(dmask) / 2), arepeated
d16, cube and 1Dd16samples (both were already refused by the earlier cube and 1D modifierchecks),
d16withtfe/lwe/r128/unorm, compute stages, andimage_sample_l/image_sample_bwith
d16.docs/startup-runtime.md: new "D16 sample results" entry;d16removed from the refused list of the packed2D sample entry.
Verification
Commit d6788f2aa on main
b6171650f, Windows, MSVC, WARP and one hardware adapter:Result: 9 of 9 passed:
startup_image_sample_d16_controls,startup_image_sample_d16_warp,startup_image_sample_d16_hardware, and the existingstartup_image_sample_a16_*andstartup_image_load_d16_*tests.New
tests/startup_image_sample_d16_check.py:image_sample_lzand implicit-LODimage_sample), odd dmask 0x7 and single channel 0x2, 3D and 2D-array with both ops, and the non-d16 formunchanged; refusals for the odd-tail whole-word read, a16+d16, cube and 1D d16,
tfe/lwe/r128/unormwith d16, wrong destination widths, a repeated d16 and a compute stage.draw <dxc> <offscreen_check> <warp|hardware> [fxc]: four fixtures (_lzNSA dmask 0xf, implicitimage_sampledmask 0xf,_lzdmask 0x7,_lzNSA dmask 0x2) draw against the 2x2 RGBA32F texture oftests/startup_image_3d.cpp(--startup-image-2d). The packed halves are widened back withv_cvt_f32_f16and must equal the sampled texel. Swapped-half, missing-shift, wrong-pair and wrong-channel mutants must fail
readback.
binary <llvm-mc>: reassembles every fixture source and compares it with the recorded words. It was not runhere: the Windows build has no llvm-mc. The diff adds it to the
pixel-binaryjob (LLVM 15) in.github/workflows/windows.yml, so its first run is CI.tests/startup_image_sample_a16_check.pyandtests/startup_image_load_d16_check.pypinned the old refusal;they now pin the a16+d16 refusal.
Evidence and follow-up
sample result was not measured independently, and filtering itself is not bit-exact across GPUs. The draw
texels are exact in binary16, so the draws check packing and channel order, not rounding.
pack16_rnemaps every NaN to the canonicalsign | 0x7e00; the NaN payload is lost.image_loadlowering, no per-format exact UNORM16 mode is applied: a filtered result has noexact binary16 value to select per format.
test.
a16withd16, cube and 1D d16 samples,image_sample_l/image_sample_bwithd16.Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-03T02:10:36Z.
Review: APPROVED
Independently reviewed
b157bd11after the baseline update. The selected channels pack in dmask order. The odd destination tail carries the existing low16-only guard, and unsupported sample forms stay refused. MSVC Debug, Windows 11 build 26300:ctest --preset dev --no-tests=error -j 1 -V -R '^(startup_image_sample_(d16|a16)_|startup_image_load_d16_)'passed 9/9 on WARP and RTX 4060 Laptop (616.56), zero skips. In the new D16 case, DXC and FXC each read back eight sampled texels per adapter and all four shader mutations per compiler and adapter were caught. 3D and array coverage here is translation-only. The GPU fixture's exact half inputs verify packing and channel order.