Repository navigation
shader: lower v_pack_b32_f16 in the direct C++ DXIL path - #2917
Conversation
Lower VOP3 0x311 with integer operations only: pick the half of each source with op_sel, clear the sign for abs, then toggle it for neg, and place source 0 low and source 1 high. Signed zeros and NaN payloads keep their exact bits, and the destination may overlap a source. Refuse clamp, omod, a destination or third-source op_sel bit, abs/neg on the third source, inline constants and literals with a named diagnostic. native_pack_b32_f16_check.py evaluates the emitted IR against the model of the Python translator (issue repro, overlap, SGPR input, all op_sel, abs and neg forms, wrong-order controls) and has a compute readback mode for a GPU run. Fixes R0Y00#2909
MasterDomino
left a comment
There was a problem hiding this comment.
Review of head 0850d32d on cpp-migration 40365770. This includes the Windows run you asked for.
Environment: Windows 11 build 26300.9974, AMD Radeon RX 9070 XT, driver 32.0.32029.2010, MSVC 19.44.35221, release preset, Windows SDK 10.0.26100 DXC, D3D12 debug layer not enabled. The build is clean, native_pixel_ir_dump included.
Lowering: it matches the acceptance list in #2909.
op_selbits 11 and 12 pick each source's half.- abs clears bit 15, and neg then toggles it.
- Source 0 goes low and source 1 high.
- Only
lshr/and/xor/shl/oron i32 are emitted. - Clamp, omod,
op_selbits 13 and 14, abs/neg on source 2, inline constants and a literal are refused with named diagnostics. - Both sources are read before
vector_write, so overlap is safe.
Results here
| check | result |
|---|---|
native_pack_b32_f16_ir |
passed: 261 results match the model; issue reproduction, control, overlap, SGPR and refusals pass; swapped-half and neg-before-abs variants differ from the emitted bits |
issue words through compile_dxil ... gfx1013-container-ps |
compiles (rc 0), and dxc -dumpbin reads the .cso (rc 0). The control without the pack also compiles |
native_pack_b32_f16_hardware |
not verified: native_store_replay.exe ... pack-readback.bin --direct exits 0xC0000005 with no output. This is the crash in #2915, where 5 of the base branch's native_store_replay --direct tests crash the same way on this adapter. It is not caused by this PR, but it means the readback still has no run on any machine. |
Bug in the GPU readback layout (please fix before a GPU run counts). In run_gpu, each workgroup stores len(want) = 66 words: 64 op_sel/abs/neg forms, then the SGPR case and the overlap case. Each store is at byte offset 4 * index, from a per-group base that is 64 words apart (v8 = group * 256 bytes). So group 0's last two stores land on group 1's first two words, at words 72 and 73 of the 2064-word buffer. The final value there depends on which workgroup writes last. expected assigns group 0 and then group 1, so it assumes group 1 wins. On a GPU where group 0 finishes last, the test fails with a correct lowering. Either way, group 0's SGPR and overlap results are never compared. Splitting the cases across two dispatches, or adding a guard band at the edge, would fix it. So would writing at most 64 words per group, or using a wider stride if the root layout allows it.
Minor
- #2909 asks to document the unsupported modifier forms. They are listed in the code comment and the test docstring. A short
docs/experiments/<topic>.mdnote (seedocs/experiments/README.md) would also give the GPU result a place to live once someone has one. native_pack_b32_f16_hardwarehas no WARP variant, becausenative_store_replayalways takes the default adapter. That is consistent with the other replay tests, but this check stays unexercised until someone runs it on a GPU that does not crash in #2915.
AI-assisted; the commands above were run locally.
Each workgroup stores 66 words (64 modifier forms, the SGPR case and the overlap case) but groups were 64 words apart, so group 0's last two results shared words with group 1's first two and the final value depended on which group wrote last. Space the groups 128 words (512 bytes) apart: s_lshl by 9 instead of 8. The expected buffer is built from per-group offsets that are asserted disjoint and inside the 2064-word buffer, so every group's SGPR and overlap results are compared with no write-order assumption.
Record the lowering semantics, the refused modifier forms, the Linux IR verification and the Windows result from the review of R0Y00#2917. The GPU readback has no run yet because native_store_replay --direct crashes with 0xC0000005 (R0Y00#2915).
|
Thank you for the review and for running it on Windows.
The readback itself still has no run, since |
|
Tested PR head Configured with ctest --preset dev -R 'native_pack_b32_f16|native_direct_container|native_scalar_lds' -V
CTest exited 0: 2 passed, 2 skipped, 0 failed. The hardware checks stopped at the combined capability gate before GPU readback; the diagnostic does not identify which requirement was missing. These results do not establish hardware correctness for the skipped fixtures. |
MasterDomino
left a comment
There was a problem hiding this comment.
Follow-up on head 21408d7e. My requested change is addressed.
- Layout (
076b950d): the shader moves the stride as well asexpected.scalar(0x1e, 7, 5, 137)iss_lshl_b32 s7, s5, 9, so each workgroup's base isgroup * 512bytes, and that matchesSTRIDE = 128words. Group 0 writes words 8–73 and group 1 writes 136–201, both inside the 2064-word buffer.group_offsetsasserts that the groups are disjoint and in range, andexpectedis built from the same offsets, so the result no longer depends on which group writes last. A small nit, not blocking: the shift137(inline 9) andSTRIDEare two separate constants. Deriving the shift fromSTRIDE, or asserting4 * STRIDE == 1 << 9, would keep them from drifting apart. - Note (
21408d7e):docs/experiments/pack-b32-f16-direct.mdmatches the code and the runs. It reports the Windows results I posted, and it states that the GPU readback has produced no result anywhere. - The lowering (
src/gfx1013_direct_compute.inl) and the IR path are unchanged since0850d32d, wherenative_pack_b32_f16_irpassed here, so I did not rebuild for this read.
Still open, as the note says: native_pack_b32_f16_hardware has no GPU result. It crashes in #2915 on the RX 9070 XT. On @sydney-0o's GTX 1080 Ti it skipped (77) at the SM 6.6 with wave32 gate. That needs an adapter with SM 6.6, wave32 and no #2915 crash, for example R0Y00's RTX 4060. That is a measurement still to make, not a defect in the PR.
AI-assisted.
|
GPU readback on an adapter that does not hit #2915:
Setup: AI-assisted. |
MasterDomino
left a comment
There was a problem hiding this comment.
Approving at 74537dc6 and merging into cpp-migration.
- Since my approval at
21408d7e, the only change is74537dc6, which ties the readback shift toSTRIDE(SHIFT = 9,assert 4 * STRIDE == 1 << SHIFT,128 + SHIFTin thes_lshl_b32). That settles my nit. - The lowering in
src/is unchanged since0850d32d, wherenative_pack_b32_f16_irpassed here on Windows and the issue's words compiled withcompile_dxiland were read bydxc -dumpbin. - The missing GPU run is now in: @JB2WIN's RTX 3080 (driver 32.0.16.2124, Windows 11 26200,
dev) on this head givesnative_pack_b32_f16_hardware3/3, with528 packed words matched the model bit for bit, andnative_pack_b32_f16_irpasses too. @sydney-0o's GTX 1080 Ti skipped (77) at the SM 6.6 with wave32 gate, and the RX 9070 XT here still hits #2915, so this NVIDIA run is the readback evidence. - It merges cleanly on the current
cpp-migration(ee76dfa8)..github/workflows/windows.ymldoes not run for this base, so the runs above stand in for CI.
AI-assisted.
#2931) This reverts commit ee76dfa. Those are the 17 XMem commits of #2911, which is still under review against main, plus two fixture changes. Keeping them off cpp-migration keeps the branch to the native compiler work. When #2911 lands on main, merging main into cpp-migration brings in the reviewed version. Every file #2918 touched is restored to its state at cd752a8. The later #2917 touches none of them. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Fixes #2909
Change
src/gfx1013_direct_compute.inl:float_alulowers VOP3v_pack_b32_f16(0x311). It is shared by the computeand pixel profiles, so the pixel profile failure from the issue goes through the same code.
it. D[15:0] is source 0 and D[31:16] is source 1. Only
lshr/and/xor/shl/oron i32 are emitted, so signedzero and NaN payloads keep their exact bits. Sources are read before the destination is written, so a destination
overlapping a source is fine. VGPR and SGPR sources are supported.
constants and a literal source (same set as the Python path, plus omod). No approximation.
tests/native_pack_b32_f16_check.py(modesirandgpu), helpertests/native_pixel_ir_dump.cpp,registration in
tests/cmake/native_pack_b32_f16.cmake. The model isref()fromstartup_gfx2hlsl_pack_b32_f16_check.py.Verified on Linux (no Windows, no GPU)
python -B tests/startup_gfx2hlsl_pack_b32_f16_check.py: 2304 cases pass (unchanged).-fsyntax-onlyand object code;d3d12.hfrom the Wine headersand a stub
wrl/client.h, not part of the change). A small Linux build ofnative_pixel_ir_dumpfromgfx1013_compute_native.cpp,gfx1013_isa.cpp,gfx1013_compute_ir.cppandguest_shader_container.cppranpython -B tests/native_pack_b32_f16_check.py ir <dumper>: 261 results match the model (issue words give0x77883344in v4, the control without the pack gives0x11223344; 64 op_sel/abs/neg forms x 4 value pairs;overlap; SGPR sources; nine refusals).
applied before abs fails the check (first at op_sel 0, abs 1, neg 1).
Verified on Windows (review of this PR)
RX 9070 XT, driver 32.0.32029.2010, MSVC 19.44.35221,
releasepreset, SDK 10.0.26100 DXC, debug layer off.native_pack_b32_f16_irpassed (261 results match the model).compile_dxil ... gfx1013-container-ps(rc 0) anddxc -dumpbinreads the.cso.native_pack_b32_f16_hardwareis not verified:native_store_replay --directexits 0xC0000005 (cpp-migration 40365770: native _hardware tests crash (0xC0000005) on an RX 9070 XT; wave_request expects a different refusal message #2915).Review fix
Workgroups were 64 words apart but each stores 66 words, so two results overlapped the next group. They are now
128 words apart (
s_lshlby 9), the offsets are asserted disjoint and inside the 2064-word buffer, andexpectedcompares every group's SGPR and overlap results without a write-order assumption(commit 076b950). The unsupported forms and results are also in
docs/experiments/pack-b32-f16-direct.md.Still open
The GPU readback has no run on any machine; it needs #2915 fixed or an adapter that does not crash.