Repository navigation
startup: draw the gfx2hlsl conversion operations - #1708
Conversation
The VEC_U table lowers v_cvt_f32_u32, v_cvt_f32_i32, v_cvt_u32_f32, v_cvt_f32_ubyte0..3, v_cvt_f32_f16 and v_cvt_f16_f32, and no check ran any of them. tests/startup_gfx2hlsl_cvt_alu_check.py draws them with the shared per-lane runner (byte-identical copy of tests/startup_gfx2hlsl_lane_alu.py) against references written from the RDNA 2 ISA: integer to binary32 with round to nearest even (2^31, 2^32 and a tie at 2^24), truncation with 0 for negatives, -0 and NaN, byte selection, S0[15:0] for the binary16 source and a cleared high half for the binary16 result. Each operation has a mutated lowering whose first draw must read its own words. All 34 draws match on WARP and an RX 6600; the 17 mutated draws read their mutated words. v_cvt_f16_f32 is drawn through DXC only: its result words are binary32 denormals in the fixture's float target, and the FXC ps_5_1 output of that stage reads 0 in every channel on both adapters, while the same words with 0x3f800000 ORed in read back exactly.
tedin7
left a comment
There was a problem hiding this comment.
Review of head 9d47aec5d4b1aa75ca9037de551f563327e662cb (Linux only; no D3D12, WARP or RDNA2 hardware here, so the 34 draws were not reproduced).
Verdict: 0 P1, 1 P2, 2 P3. Translator untouched; references match the RDNA2 ISA text; the fixture words are valid. The P2 is a CMake ordering problem that quietly drops the FXC draws on a fresh configure.
P2: STARTUP_FXC is read before it is defined
The new block (CMakeLists.txt ~1638-1647) uses $<$<BOOL:${STARTUP_FXC}>:${STARTUP_FXC}>, but find_program(STARTUP_FXC ...) is at line 1650, after it. ${} expands at configure time, so on a clean build dir the argument is empty and the draw runs DXC only. FXC is picked up only after the cache holds the variable (second configure). Minimal CMake reproduction run locally: first configure prints USE_BEFORE=[], second prints the path.
- Effect: the reported FXC ps_5_1 draws (16 of the 34) can be missing from a fresh CI or developer run, silently; the run still passes.
- Suggestion: place the new block after the
find_programline, asstartup_gfx2hlsl_bit_aluis.
Semantics
- References are plain Python from the ISA text: RNE int to binary32, truncation with negative/NaN to 0, byte N,
S0[15:0], low-half binary16 result. The inputs hit the cases the PR lists. Counts check out: 9 ops x 2 chunks = 18 DXC draws, 16 FXC (f16_f32 excluded), 17 mutated draws. - P3 (not verifiable here): the "bits 31:16 clear" reference for
v_cvt_f16_f32rests on the author's reading of the ISA; this review cannot check it against hardware. - P3: on Linux the controls are structural. They match the translated text (any lowering change fails the
count == 4check on the mutation pattern) but evaluate no value, unlike thebit_alusibling, which has a CPU evaluator. Numeric correctness exists only in the Windows draws.
Commands executed locally
python3 -B tests/startup_gfx2hlsl_cvt_alu_check.py: 29 ok, 0 MISMATCH, exit 0.... cvt_alu_check.py binary llvm-mc-19:fixture words match llvm-mc(CI uses llvm-mc-15).- Local mutations, each reverted afterwards (restored clean):
- translator: ubyte1 shift 8 to 16,
cvt_u32_f32withoutmax,cvt_f32_i32withoutint(),cvt_f16_f32negated. All four fail the controls (pattern no longer matches). - test: ubyte1 mutation replacement made a no-op fails
count == 4; recorded body words of ubyte2 swapped for ubyte1 failsbinary; NaN guard removed from thecvt_u32_f32reference crashes the controls.
- translator: ubyte1 shift 8 to 16,
- A CPU emulation I wrote of the translated expressions over all 72 draw inputs agrees with the references (0 differences) and reports differences for each of the four translator mutations, so the chosen inputs separate the right and wrong lowerings. It is an independent model, not the HLSL compilers.
- Minimal CMake script for the P2.
Limits: no ctest run, no Windows draw, no FXC denormal check (the v_cvt_f16_f32 FXC claim is the author's measurement only).
AI-assisted review.
|
#1707 is now on main at 49634a1. It enables output modifiers on float-result conversions, so the refusal in this fixture for v_cvt_f32_f16 with mul:2 is stale on the combined code. Please keep the conversion draw and replace that refusal with an integer-result case, for example v_cvt_f16_f32 with mul:2. The plain conversion and its existing output mutations should stay intact. |
|
On the "Not covered" item, Hardware. On RDNA 2 silicon (gfx1036, desktop APU of the console's generation), @4usphs ran HLSL side.
So to pin the row rather than leave it adapter-dependent, an explicit clamp is the usual approach. xcl uses AI-assisted (Claude Code). The figures are quoted from the linked threads. |
|
Correction to my earlier note: this candidate already refused the integer-result v_cvt_f16_f32 modifier. I kept that case and added an explicit accepted float-result modifier after integrating main. I also moved the registration after FXC discovery so a clean build runs both compilers where supported. Windows Release controls, WARP and RTX 4060 Laptop passed 3/3 with the existing per-operation negative controls. The merged candidate now needs its own CI. |
Refs #1149.
Change
No check ran the conversion operations of the
VEC_Utable intools/startup/gfx2hlsl.py:v_cvt_f32_u32,v_cvt_f32_i32,v_cvt_u32_f32,v_cvt_f32_ubyte0to3,v_cvt_f32_f16andv_cvt_f16_f32.This PR adds a check only. The translator does not change.
tests/startup_gfx2hlsl_cvt_alu_check.pydraws them with the per-lane runnertests/startup_gfx2hlsl_lane_alu.py. The runner is byte-identical to the copies in #1703 and #1706, so the PRs merge in any order. In each draw:_e32and_e64;binarymode;References, from the AMD RDNA 2 ISA reference:
v_cvt_f32_u32,_i320x80000001→ 2^31,0xffffffff→ 2^32,0x01000001→ 2^24 (tie to even), negative integersv_cvt_u32_f320x4f7fffff(largest below 2^32), 123456.9v_cvt_f32_ubyteNv_cvt_f32_f16v_cvt_f16_f32Each operation has one mutated lowering, and the first draw with it must read the mutation's own reference words:
Results
Commit
9d47aec5onorigin/main. Windows 11 26300.9974, DXC 1.8.2502.11, FXC 10.0.26100, debug layer on.There were no skips.
binarywith llvm-mc 19.1.1 givesfixture words match llvm-mc.FXC and
v_cvt_f16_f32. Eight operations are drawn through both FXCps_5_1and DXCps_6_0;v_cvt_f16_f32is drawn through DXC only.Its results are 16-bit words, so every exported word is a binary32 denormal in the fixture's float target. The FXC
ps_5_1output of that pixel stage read00000000,00000000,00000000,00000000on WARP and on the RX 6600, where00003c00,0000c100,00007bff,00000400was expected. A variant with one channel converting a constant read zeros as well. The same words with0x3f800000ORed in at the export read back exactly (3f803c00,3f80c100,3f807bff,3f800400), on both adapters. The conversion is therefore right, and the zeros come from how the FXC-compiled stage exports denormal bit patterns.This may matter beyond the fixture. A translated pixel stage compiled with FXC that exports packed 16-bit data through a float target could lose it. I have not checked any real pipeline for that.
Not covered:
v_cvt_u32_f32at or above 2^32 and of +inf, where the HLSL conversion of an out-of-range value is not pinned;v_cvt_f16_f32has to round.AI-assisted (Claude Code).