startup: draw the gfx2hlsl conversion operations #1701
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1708"
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?
Imported from R0Y00/Xbox2Windows. Originally posted by Asimmimx on 2026-11-24T17:33:10Z.
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).
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T17:42:05Z.
Review: COMMENTED
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_FXCis read before it is definedThe new block (
CMakeLists.txt~1638-1647) uses$<$<BOOL:${STARTUP_FXC}>:${STARTUP_FXC}>, butfind_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 printsUSE_BEFORE=[], second prints the path.find_programline, asstartup_gfx2hlsl_bit_aluis.Semantics
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.v_cvt_f16_f32rests on the author's reading of the ISA; this review cannot check it against hardware.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).cvt_u32_f32withoutmax,cvt_f32_i32withoutint(),cvt_f16_f32negated. All four fail the controls (pattern no longer matches).count == 4; recorded body words of ubyte2 swapped for ubyte1 failsbinary; NaN guard removed from thecvt_u32_f32reference crashes the controls.Limits: no ctest run, no Windows draw, no FXC denormal check (the
v_cvt_f16_f32FXC claim is the author's measurement only).AI-assisted review.
upstream-sync referenced this pull request2026-11-24 18:02:49 +00:00
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T17:53:27Z.
#1707 is now on main at
49634a12. 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.Imported from R0Y00/Xbox2Windows. Originally posted by KainanP on 2026-11-24T18:18:54Z.
On the "Not covered" item,
v_cvt_u32_f32at or above 2^32 and of +inf: here is data for both sides of it.Hardware. On RDNA 2 silicon (gfx1036, desktop APU of the console's generation), @4usphs ran
v_cvt_u32_f32as inline assembly over xcl's #639 inputs, including ±inf and the integer range limits. It saturates: an out-of-range value gives0xFFFFFFFFand negative values give 0. NaN gives 0 forv_cvt_u32_f32/v_cvt_i32_f32: https://github.com/xcl-dev/xcl/pull/639#issuecomment-7127563021. (In the same run,v_cvt_flr/rpi_i32_f32of a NaN gave0x7FFFFFFF/0x80000000by the NaN's sign, not 0. That is not relevant to this table, but it matters if those two are added later.)HLSL side.
uint(max(F(x), 0.0))leaves values ≥ 2^32 to an out-of-range cast, which HLSL leaves undefined. What comes out depends on whether the value gets constant-folded:(int)asfloat(x)gave 0 for ±inf on an RTX 4060 Laptop (driver 32.0.16.1047) and on WARP, instead of saturating. With a constant NaN, dxc folded the cast to an undefined value and the validator refused the shader (Assignment of undefined values to UAV): https://github.com/LooperSalty/AnyXboxX/pull/138So to pin the row rather than leave it adapter-dependent, an explicit clamp is the usual approach. xcl uses
select(isnan(f) || f <= 0, 0, select(f >= 4294967296.0, 0xFFFFFFFF, (uint)f)); AnyXboxX tests NaN on the bits, because dxc foldsx != xto false. A row with0x4f800000(2^32) and +inf expecting0xffffffffwould then cover it. None of this was measured on Scarlett or through FXC.AI-assisted (Claude Code). The figures are quoted from the linked threads.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T18:48:44Z.
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.