shader: lower v_pack_b32_f16 in the direct C++ DXIL path #2909

Closed
opened 2026-11-26 19:00:08 +00:00 by R0Y00 · 3 comments
R0Y00 commented 2026-11-26 19:00:08 +00:00 (Migrated from github.com)
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-26T19:00:08Z.


Target branch cpp-migration. Open to contributors. Comment here to claim.

On 4036577020 the opcode table recognizes VOP3 0x311, but a source-built pixel shader stops at native compute +0x10: direct DXIL lowering for v_pack_b32_f16 in the pixel profile. Removing only the pack instruction produces DXIL.

Reproduce with patched_pixel from tests/native_direct_container_check.py. Supply the instruction words [0x7e0802ff, 0x11223344, 0x7e0a02ff, 0x55667788, 0xd7110004, 0x00020b04] and export (0xf800180f, 0x05040504). Run compile_dxil <sdk-dir> <empty-cache> gfx1013-container-ps input.cdxil output.cso. For the control remove the final two instruction words and adjust the length. The ordinary pack writes 0x77883344 to v4, which also supplies the first source.

Implementation references include the experimental lowering at a pinned revision and the existing Python reference and synthetic controls. Implement from the instruction semantics and existing public fixture. The experimental repository has a root MIT license and separately attributed third-party material. Preserve applicable notices for any reused source.

Acceptance follows each source's high/low selection, clears the half sign for abs, then toggles it for neg, and places source 0 low and source 1 high. Preserve bit patterns including signed zero and NaN payloads. Cover operand overlap, SGPR input and both wrong-result controls (swapped halves and neg before abs). Document unsupported modifier forms. Generate DXIL with the direct frontend and verify exact packed bits by GPU readback on a synthetic fixture, recording adapter, driver, build, and any capability skips. python -B tests/startup_gfx2hlsl_pack_b32_f16_check.py already passes 2304 reference cases. #1723 tracks the older translator census. #2906–#2908 cover separate branch and descriptor work.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6633320075 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/2909). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-26T19:00:08Z. --- Target branch `cpp-migration`. Open to contributors. Comment here to claim. On 40365770206d355160f364495cd9a72be2c7df8e the opcode table recognizes VOP3 0x311, but a source-built pixel shader stops at `native compute +0x10: direct DXIL lowering for v_pack_b32_f16` in the pixel profile. Removing only the pack instruction produces DXIL. **Reproduce** with `patched_pixel` from `tests/native_direct_container_check.py`. Supply the instruction words `[0x7e0802ff, 0x11223344, 0x7e0a02ff, 0x55667788, 0xd7110004, 0x00020b04]` and export `(0xf800180f, 0x05040504)`. Run `compile_dxil <sdk-dir> <empty-cache> gfx1013-container-ps input.cdxil output.cso`. For the control remove the final two instruction words and adjust the length. The ordinary pack writes 0x77883344 to v4, which also supplies the first source. **Implementation references** include [the experimental lowering at a pinned revision](https://github.com/denn0x/Xbox2Windows/blob/87a6003fcc38661683f6936a614acfa90e420c83/src/x2w_shader/emit/lower_valu.cpp#L878) and [the existing Python reference and synthetic controls](https://github.com/R0Y00/Xbox2Windows/blob/40365770206d355160f364495cd9a72be2c7df8e/tests/startup_gfx2hlsl_pack_b32_f16_check.py). Implement from the instruction semantics and existing public fixture. The experimental repository has a root MIT license and separately attributed third-party material. Preserve applicable notices for any reused source. **Acceptance** follows each source's high/low selection, clears the half sign for abs, then toggles it for neg, and places source 0 low and source 1 high. Preserve bit patterns including signed zero and NaN payloads. Cover operand overlap, SGPR input and both wrong-result controls (swapped halves and neg before abs). Document unsupported modifier forms. Generate DXIL with the direct frontend and verify exact packed bits by GPU readback on a synthetic fixture, recording adapter, driver, build, and any capability skips. `python -B tests/startup_gfx2hlsl_pack_b32_f16_check.py` already passes 2304 reference cases. #1723 tracks the older translator census. #2906–#2908 cover separate branch and descriptor work.
Ybucaille commented 2026-11-26 19:42:04 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by Ybucaille on 2026-11-26T19:42:04Z.


I'd like to take this one. I'll implement the direct-path lowering on cpp-migration from the instruction semantics and the existing fixture, with the overlap, SGPR and wrong-result controls, plus a GPU readback on a synthetic fixture.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7201869982 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/2909#issuecomment-7201869982). Originally posted by [Ybucaille](https://github.com/Ybucaille) on 2026-11-26T19:42:04Z. --- I'd like to take this one. I'll implement the direct-path lowering on `cpp-migration` from the instruction semantics and the existing fixture, with the overlap, SGPR and wrong-result controls, plus a GPU readback on a synthetic fixture.
MasterDomino commented 2026-11-26 21:38:03 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-26T21:38:03Z.


Closing: the fix landed on cpp-migration via #2917, squash-merged as 16099d7c. Fixes #2909 does not close issues automatically outside the default branch. Evidence on #2917: native_pack_b32_f16_ir passed on Windows, and on Linux (Ybucaille) and a GTX 1080 Ti (sydney-0o). The GPU readback native_pack_b32_f16_hardware passed 3/3 on an RTX 3080 (JB2WIN, 528 packed words bit-exact). The issue's words now compile with compile_dxil ... gfx1013-container-ps. The RX 9070 XT readback stays blocked by #2915.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7203913846 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/2909#issuecomment-7203913846). Originally posted by [MasterDomino](https://github.com/MasterDomino) on 2026-11-26T21:38:03Z. --- Closing: the fix landed on `cpp-migration` via #2917, squash-merged as `16099d7c`. `Fixes #2909` does not close issues automatically outside the default branch. Evidence on #2917: `native_pack_b32_f16_ir` passed on Windows, and on Linux (Ybucaille) and a GTX 1080 Ti (sydney-0o). The GPU readback `native_pack_b32_f16_hardware` passed 3/3 on an RTX 3080 (JB2WIN, 528 packed words bit-exact). The issue's words now compile with `compile_dxil ... gfx1013-container-ps`. The RX 9070 XT readback stays blocked by #2915. AI-assisted.
R0Y00 commented 2026-12-02 18:49:49 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-02T18:49:49Z.


Rechecked this on main at 1e2b0d524, Windows 11 build 26300, MSVC Debug and NVIDIA GeForce RTX 4060 Laptop GPU (driver 32.0.16.1656). The fixture did not enable the D3D12 debug layer.

cmake --build --preset dev --target native_pixel_ir_dump native_store_replay and ctest --preset dev --no-tests=error -V -j 1 -R '^native_pack_b32_f16_(ir|hardware)$' passed (2/2). The hardware readback matched all 528 packed words bit for bit. In the IR fixture, all 269 results matched the reference. The no-pack control, overlapping and SGPR sources, constant cases and refusals passed. The swapped-half and neg-before-abs alternatives produced different bits, as expected.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7355216985 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/2909#issuecomment-7355216985). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-02T18:49:49Z. --- Rechecked this on `main` at `1e2b0d524`, Windows 11 build 26300, MSVC Debug and NVIDIA GeForce RTX 4060 Laptop GPU (driver `32.0.16.1656`). The fixture did not enable the D3D12 debug layer. `cmake --build --preset dev --target native_pixel_ir_dump native_store_replay` and `ctest --preset dev --no-tests=error -V -j 1 -R '^native_pack_b32_f16_(ir|hardware)$'` passed (2/2). The hardware readback matched all 528 packed words bit for bit. In the IR fixture, all 269 results matched the reference. The no-pack control, overlapping and SGPR sources, constant cases and refusals passed. The swapped-half and neg-before-abs alternatives produced different bits, as expected.
Sign in to join this conversation.
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#2909
No description provided.