shader: lower pixel-stage image_store with d16 in gfx2hlsl #2755
No reviewers
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows!2755
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/2755/head"
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?
@tedin7 on GitHub · 2026-11-26 06:01 UTC · original
tedin7:x2w-ps-image-store-d16→main· +78 −4 · 2 files · 2 commits · closed without mergingPart of #1723
What this unblocks: pixel programs that write a texel with
image_store ... d16(four binary16 values packed in two VGPRs) no longer stop at the store.Source: AMD "RDNA 2" Instruction Set Architecture reference guide, MIMG instruction IMAGE_STORE with the D16 modifier (two binary16 values per VGPR); Microsoft DirectX-Specs, D3D12 typed UAV store behaviour.
What changed
tools/startup/gfx2hlsl.pyop_image_store(): thed16modifier, until now accepted only in compute programs, is accepted in pixel programs too. The two data VGPRs are widened (R, G from the first, B, A from the second, low half first, RDNA 2 ISA 8.2.5) and written to the float UAV exactly as the compute lowering does. Two data registers are required withd16, four without it.tests/startup_pixel_image_store_check.py(already registered in CMake for controls, WARP and hardware): a d16 fixture, its decoded text, the translated store line, refusals (d16 with four or one data registers, two registers without d16, d16 with a16), the llvm-mc word check, and a draw of the texel with three negative controls.Why it is correct
Every binary16 value is exact in binary32, so
f16tof32of each half gives the value the float view stores. The fixture uses 1.0, -2.0, 0.5 and 65504.0 so that a swapped half order, a binary32 reading of the words or a deleted store each change the texel read back.What stays refused
dmask other than 0xf, other image dimensions,
a16,tfe,lwe,r128, and a load and a store of the same image, as before.Verification
python3 -B tests/startup_pixel_image_store_check.py(controls): okpython3 -B tests/startup_pixel_image_store_check.py binary llvm-mc-19(fixture words match llvm-mc): okstartup_compute_image_store_check.py,startup_compute_image_store_d16_check.py: okremote_pycheck.sh <worktree> --compare origin/main: 0 scripts differ from maineb177fdde): the two checks above and both compute image_store checks rc=0, remote_pycheck vs origin/main 0 differ.c7a69877c(before the merge commit, which only resolved a docstring conflict): Win2025 dev 3/3 and release 3/3 passed withpython x2w_pipe.py win2025 2755 --targets offscreen_check --regex startup_pixel_image_store(controls, WARP draw, hardware draw; the three controls fail as required).AI-assisted; commands listed were executed locally.
@RavenCurseBurg on GitHub · 2026-11-26 08:39 UTC · original
I will check the D16 pixel store with additional binary16 encodings, including signed zeros, subnormals and the normal/subnormal boundary. I will compare raw FP32 texel words and the untouched texels on WARP, UHD 770 and RTX 4060 using this PR's translated source-built shader and record a half-order negative control.
@tedin7 on GitHub · 2026-11-26 08:42 UTC · original
Thanks, that is welcome. For reference, the fixture in this PR stores 1.0, -2.0, 0.5 and 65504.0 (all four values differ, so a swapped half order, a binary32 reading of the words or a deleted store each change the texel), and the draw also checks that every other texel keeps its starting value.
The lowering is
f16tof32of each half, which is exact in binary32 for every half (signed zeros, subnormals and the normal/subnormal boundary included), so I expect raw FP32 words of0x80000000,0x33800000(smallest subnormal),0x38800000(smallest normal) and0x387fc000(largest subnormal) for those inputs. If any adapter returns something else, please post the adapter and the words and I will fix it or refuse that case.AI-assisted; commands listed were executed locally.
@RavenCurseBurg on GitHub · 2026-11-26 09:20 UTC · original
I tested the D16 store at
eb177fddon WARP, Intel UHD 770 and RTX 4060. All three adapters passed the PR's fullstartup_pixel_image_store_check.py drawas well as the following additional cases on DXC SM 6.0.I assembled 16 gfx1013 pixel programs. Four rotations put each sign of zero, minimum/maximum subnormal, minimum normal, maximum finite and infinity into each RGBA channel. Two signed pairs of normal values also exercise fraction bits. Expected binary32 words come independently from Python's IEEE
structconversion. For example, half words0000,8000,0001,8001came back as00000000,80000000,33800000,b3800000.On each adapter, all 16 translated draws passed. A second version uses the renderer's zero root constants to keep the inputs dynamic. Each DXIL dump contained four runtime half-to-float conversions and all 16 draws passed again. Each positive draw checks (1,2) and the other 15 sentinel texels of the 4×4 float UAV. Swapping the two halves of both packed words in the dynamic shader produced all 16 expected mismatches, with the exact predicted RGBA bits at (1,2).
Standalone script and input vectors. Run from that revision with:
For physical adapters use
hardwareand select the device withXBOX2WINDOWS_ADAPTER. Environment: Windows 11 build 26100, DXC 1.9.2609.5, D3D12 debug layer unavailable. The vectors cover finite values and infinities. NaN payload handling was outside this run.@tedin7 on GitHub · 2026-11-26 09:43 UTC · original
Thank you for the detailed run. The words you list match what I expected from
f16tof32(0x00000000,0x80000000,0x33800000,0xb3800000for0000,8000,0001,8001), on all three adapters and with the half-order control failing as required. No change is needed from this report; the PR stays as it is ateb177fdduntil it is promoted.AI-assisted; commands listed were executed locally.
@tedin7 on GitHub · 2026-11-26 10:12 UTC · original
Withdrawn: shader translation is moving to the native C++ frontend (see #870), so we are not continuing this change to the Python translator. The branch stays available if any part is useful later. Thank you to everyone who reviewed and tested it.
github-bot referenced this pull request2026-11-28 22:11:19 +00:00
github-bot referenced this pull request2026-11-28 22:12:40 +00:00
Pull request closed