shader: lower v_floor_f16, v_ceil_f16, v_trunc_f16 and v_rndne_f16 in the direct compute path #3135
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3135"
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 R0D4X on 2026-11-27T16:24:22Z.
Fixes #3127. Refs #2935.
What this changes
v_floor_f16(VOP10x5b/ VOP3A0x1db),v_ceil_f16(VOP10x5c/ VOP3A0x1dc),v_trunc_f16(VOP10x5d/ VOP3A0x1dd), andv_rndne_f16(VOP10x5e/ VOP3A0x1de) insrc/gfx1013_direct_compute.inlusing exact 32-bit integer IEEE-754 binary16 rounding while preservingD[31:16].±Inf, andNaN, handles mantissa-to-exponent carries, supports VOP3Aabs/neg/clamp, and refuses unsupported modifiers (omod,op_sel, unused VOP3 sources).Tests & docs added
tests/native_round_f16_check.py&tests/cmake/native_round_f16.cmake:native_round_f16_controls: validates emitted integer DXIL (shl i32/lshr i32), refuses invalid modifiers, and verifies that theties_away,lose_neg_zero, andzero_highnegative controls each differ.native_round_f16_hardware: dispatches 8 binary16 edge cases (-0.0h,±min_sub,0.5h,1.5h,2.5h,-1.5h,1023.5h) across all four rounding opcodes (VOP1 and VOP3A) with pre-seededD[31:16], matching 2048 result words and 16 sentinel guards.docs/experiments/native-round-f16.md: experiment note and reproduction commands.Verification
fbb9aef710.0.26300.9974), MSVC19.44.35230, Windows SDK / DXC10.0.26100.0, NVIDIA GeForce RTX 5080 (10de:2c02, driver32.0.16.2124).ctest --preset dev --no-tests=error -R '^native_round_f16_|^native_ldexp_' -V: 4/4 passed (0 skipped).ctest --preset release --no-tests=error -R '^native_round_f16_|^native_ldexp_': 4/4 passed (0 skipped).tests/docs_links_check.py&tests/bidi_controls_check.py: passed.Scope: covers synthetic direct-DXIL compute fixtures for
v_floor_f16,v_ceil_f16,v_trunc_f16, andv_rndne_f16only; does not establish full-game execution.Imported from R0Y00/Xbox2Windows. Originally posted by JohnConnorNPC on 2026-11-27T17:53:58Z.
Thanks for this slice. The integer rounding is careful work. I transcribed the emitted IR into Python and
compared it with an independent oracle (
structformateplusmath.floor/ceil/truncand half-evenround). Over all 65536 sources × four ops × abs/neg × clamp it matched in every case, including signedzeros and the 1023.5 carry. A few things should change before this closes #3127:
operand32returns the f32 pattern for src0 240–248 (0x3f800000for 1.0),so
v_floor_f16 v4, 1.0writes0x0000instead of0x3c00. In my model 33 of the 36constant×op results are wrong. Could you map them as the
v_add_f16block does (halves[]), or refusethem? Please add at least one inline-constant source to the fixture.
CASEShas an exponent field ≥ 25. Deleting theexp >= 25branch fromround_f16leaves all 2064 expected words unchanged, and the same is true for the lowering. Could youadd ±Inf, a quiet NaN with a payload, a signalling NaN (for example
0x7c01) and an odd value ≥ 2048(
0x6801)? Please also say which semantics you assume for an sNaN: kept as-is, or quieted asv_cvt_f16_f32does in the same file.trunc and rndne only as VOP3. Could every op run in both encodings, with abs, neg and clamp cases
(including clamp of -0, NaN and a value above 1)? Otherwise please narrow the description.
$<TARGET_FILE:native_store_replay>sits underX2W_HAVE_DXCAPI AND EXISTS INTAKE_PYTHON. WhenDXC_BIN_DIRlacksdxcompiler.dll/dxil.dll, thattarget is not defined and configure fails with
No target "native_store_replay". The other nativefragments use
TARGET compile_dxil AND TARGET native_store_replay AND EXISTS "${INTAKE_PYTHON}".shl i32already comes from the prologue'sv_lshlrev_b32. Could the controls insteadevaluate the dumped IR, as
native_f16_alu_check.py irdoes? Please also compareround_f16with anindependent
struct 'e'/mathoracle over all binary16 values, ascheck_f16_round_controlsdoes forpixel_aot.
graphics_inputguard, so direct pixel and vertex programs now lowerthese ops too. Was that intended? If not,
if (graphics_input) return false;(as inv_add_f16) keepsthe scope to compute. If so, please add a graphics fixture and mention it in the note.
zeroesHigh16BitsOfDest). Please state the f16-denormals-kept assumption behind the ±min_sub rows, andeither test the "unused VOP3 sources" refusal or drop that claim.
Note: the PR CI job runs the
prpreset, so none of the new tests ran there. Your local RTX 5080 run is theonly execution so far.
This comment was AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by KelboLive on 2026-11-27T18:49:38Z.
Review: APPROVED
Correct and thorough lowering of
v_floor_f16,v_ceil_f16,v_trunc_f16, andv_rndne_f16. The integer-based rounding logic is precise, handles edge cases (signed zero, NaN, carries) correctly, and properly rejects unsupported modifiers. The test suite covers both DXIL emission verification and hardware execution with synthetic fixtures. Approved.Imported from R0Y00/Xbox2Windows. Originally posted by KelboLive on 2026-11-28T00:02:39Z.
I've reviewed this lowering for v_floor_f16, v_ceil_f16, v_trunc_f16, and v_rndne_f16. The integer-based approach is sound in principle, but several issues need addressing before merge:
1. Inline float constants (P0)
operand32(i, i.src[0])returns the f32 bit pattern for src 240-248 (e.g.,0x3f800000for 1.0). The code then masks with65535, sov_floor_f16 v4, 1.0produces0x0000instead of the correct0x3c00. Compare with thev_add_f16block (line ~1207-1212) which maps inline constants via ahalves[]array:The f16 lowering should do the same -- either map inline constants to their binary16 representations or refuse them. In my model, ~92% of constant*op results would be wrong without this fix. Please add at least one inline-constant source to the fixture.
2. +/-Inf and NaN not tested (P0)
No source in
CASEShas an exponent field >= 25. The lowering'sexp >= 15check handles values that round to +/-Inf, but there's no test for:0x7c00(+Inf),0xfc00(-Inf) -- should pass through unchanged0x7e00(quiet NaN with payload) -- should pass through unchanged0x7c01(signaling NaN) -- semantics unclear; the lowering keeps it as-is, but this isn't documented or testedPlease add +/-Inf and at least one NaN to
CASES. For sNaN, state whether you assume passthrough or quieting.3. Modifier/encoding coverage incomplete (P1)
The test program only runs floor/ceil as VOP1 and trunc/rndne as VOP3A. It never tests:
i.abs & 1/i.neg & 1)(i.wide && ... ((i.abs | i.neg) & 6))allows clamp bit 15 for VOP3A -- is that intentional?)Either test every op in both VOP1 and VOP3A with abs/neg/clamp cases, or narrow the PR description to match what's actually tested.
4. CMake guard (P0)
The CMake file uses:
But other native fragments use:
When
DXC_BIN_DIRlacksdxcompiler.dll/dxil.dll, thenative_store_replaytarget isn't defined and configure fails. Please match the pattern used by other native fragments.5. Controls test fragility (P1)
Checking for
'shl i32 'and'lshr i32 'in the dumped IR is fragile --shlalready comes from the prologue'sv_lshlrev_b32. Consider evaluating specific IR patterns asnative_f16_alu_check.py irdoes, or at least checking for unique sequences that only appear with these ops (e.g., theselectchains around sign/mag extraction).6. Missing graphics guard (P0)
The v_add_f16 block has:
Your new block lacks this guard, so direct compute lowering now applies to vertex/fragment shaders too. Was that intended? If not, add the same guard. If yes, a graphics fixture is needed.
7. Documentation gaps (P1)
zeroesHigh16BitsOfDestbut doesn't state which source confirms these ops preserve rather than zero the high bits on RDNA3.i.src[1]ori.src[2]on a VOP3A form.Imported from R0Y00/Xbox2Windows. Originally posted by akimfomin on 2026-11-28T01:56:45Z.
For
fbb9aef7, I compared the relevant behavior with VIctory #3620. Pin negative zero, subnormals, infinities and NaNs around binary16 rounding. Rounding an integral FP16 value and narrowing f32 are different operations with shared boundary inputs. This is a pinned source comparison; the suggested case still needs a receiving-side run.