shader: lower pixel-stage image_store with d16 in gfx2hlsl #2747

Closed
tedin7 wants to merge 2 commits from upstream-pr/2755 into main
tedin7 commented 2026-11-26 06:01:25 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T06:01:25Z.


Part 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.py op_image_store(): the d16 modifier, 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 with d16, 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 f16tof32 of 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): ok
  • python3 -B tests/startup_pixel_image_store_check.py binary llvm-mc-19 (fixture words match llvm-mc): ok
  • startup_compute_image_store_check.py, startup_compute_image_store_d16_check.py: ok
  • remote_pycheck.sh <worktree> --compare origin/main: 0 scripts differ from main
  • After merging main into the branch (head eb177fdde): the two checks above and both compute image_store checks rc=0, remote_pycheck vs origin/main 0 differ.
  • Independent review on head c7a69877c (before the merge commit, which only resolved a docstring conflict): Win2025 dev 3/3 and release 3/3 passed with python 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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6620581715 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2755). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T06:01:25Z. --- Part 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.py` `op_image_store()`: the `d16` modifier, 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 with `d16`, 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 `f16tof32` of 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): ok - `python3 -B tests/startup_pixel_image_store_check.py binary llvm-mc-19` (fixture words match llvm-mc): ok - `startup_compute_image_store_check.py`, `startup_compute_image_store_d16_check.py`: ok - `remote_pycheck.sh <worktree> --compare origin/main`: 0 scripts differ from main - After merging main into the branch (head eb177fdde): the two checks above and both compute image_store checks rc=0, remote_pycheck vs origin/main 0 differ. - Independent review on head c7a69877c (before the merge commit, which only resolved a docstring conflict): Win2025 dev 3/3 and release 3/3 passed with `python 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 commented 2026-11-26 09:04:54 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by RavenCurseBurg on 2026-11-26T08:39:47Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7186867255 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2755#issuecomment-7186867255). Originally posted by [RavenCurseBurg](https://github.com/RavenCurseBurg) on 2026-11-26T08:39:47Z. --- 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 commented 2026-11-26 09:04:54 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T08:42:11Z.


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 f16tof32 of 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 of 0x80000000, 0x33800000 (smallest subnormal), 0x38800000 (smallest normal) and 0x387fc000 (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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7186915206 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2755#issuecomment-7186915206). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T08:42:11Z. --- 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 `f16tof32` of 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 of `0x80000000`, `0x33800000` (smallest subnormal), `0x38800000` (smallest normal) and `0x387fc000` (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 commented 2026-11-26 10:04:04 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by RavenCurseBurg on 2026-11-26T09:20:49Z.


I tested the D16 store at eb177fdd on WARP, Intel UHD 770 and RTX 4060. All three adapters passed the PR's full startup_pixel_image_store_check.py draw as 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 struct conversion. For example, half words 0000,8000,0001,8001 came back as 00000000,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:

python tests/verify_pixel_d16_edges.py <clang> <llvm-objcopy> <dxc> <offscreen_check> warp

For physical adapters use hardware and select the device with XBOX2WINDOWS_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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7187825158 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2755#issuecomment-7187825158). Originally posted by [RavenCurseBurg](https://github.com/RavenCurseBurg) on 2026-11-26T09:20:49Z. --- I tested the D16 store at `eb177fdd` on WARP, Intel UHD 770 and RTX 4060. All three adapters passed the PR's full `startup_pixel_image_store_check.py draw` as 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 `struct` conversion. For example, half words `0000,8000,0001,8001` came back as `00000000,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](https://github.com/RavenCurseBurg/Xbox2Windows/blob/74c3c11e84d94329b14d9096a29bb7e48c3c5be0/tests/verify_pixel_d16_edges.py). Run from that revision with: ```text python tests/verify_pixel_d16_edges.py <clang> <llvm-objcopy> <dxc> <offscreen_check> warp ``` For physical adapters use `hardware` and select the device with `XBOX2WINDOWS_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 commented 2026-11-26 10:04:05 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T09:43:23Z.


Thank you for the detailed run. The words you list match what I expected from f16tof32 (0x00000000, 0x80000000, 0x33800000, 0xb3800000 for 0000,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 at eb177fdd until it is promoted.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7188382897 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2755#issuecomment-7188382897). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T09:43:23Z. --- Thank you for the detailed run. The words you list match what I expected from `f16tof32` (`0x00000000`, `0x80000000`, `0x33800000`, `0xb3800000` for `0000,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 at `eb177fdd` until it is promoted. AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-26 11:02:43 +00:00
tedin7 commented 2026-11-26 11:02:58 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T10:12:35Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7189055036 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2755#issuecomment-7189055036). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T10:12:35Z. --- 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.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!2747
No description provided.