shader: lower v_ceil_f64, v_floor_f64, v_trunc_f64 and v_rndne_f64 in direct compute #3630
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3630"
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 Ammmae0x on 2026-11-30T17:47:26Z.
Refs #2935, #3518
Lowers the four binary64 rounding instructions (
_e32and_e64) in the direct C++ compute path with pure 32-bit integer arithmetic only, following thev_*_f16rounding shape and thev_cmp_*_f64pair rules.What changed
src/gfx1013_direct_compute.inl(+132): new lowering block after the f16 rounding block. Modifier gate (pixel_stage,graphics_input,i.subword,i.dpp_control,permuted,i.clamp,i.scale,op_sel, modifiers on S1/S2), MODE gate (half_mode_known && !((mode_bits ^ 0xf0u) & 0x8000ccu)), destination must be a VGPR pair (256 <= dst < 511), S0 accepts VGPR pairs, aligned even SGPR pairs, integer0(128->+0.0) and inline binary64 constants240..247(lo = 0); abs then neg act on bit 63 before rounding. Result selected by biased exponent:exp >= 1075passes the pair unchanged (NaN payload included);exp < 1023rounds to a signed zero or one (the nonzero test looks atlotoo, so a tiny subnormal is not mistaken for zero;rndne|x| == 0.5rounds to even±0.0,|x| > 0.5rounds to±1.0, including0x3fe00000_00000001); in between, the fraction sits inlo(1044..1074, carry on wrap), straddles the word boundary (1043, half0x80000000, evennesshi & 1, carry+1tohi), or splits acrosshiandlo(1023..1042, half/sticky comparison across both words, evennessbase_hi & unit_hi). All DXIL shift amounts stay in[0, 31]in every lane (clamped selects outside the range). No DXILdouble, noi64in@main(), nofcmp, neitherDoublePrecisionFloatShaderOpsnorInt64ShaderOps.half_binary = true, so a conditional denorm-mode write before them refuses.src/gfx1013_compute_native.cpp: the four names join thepaircondition inclear_vector_spills, so writingv[d:d+1]invalidates lane spills on bothdandd+1.tests/native_round_f64_check.py(model/ir/controls/hardware) +tests/cmake/native_round_f64.cmake+tests/checks/python-linux/native_round_f64.txt+docs/experiments/native-direct-round-f64.md.Tests
Linux (this host cannot compile the translation unit or run Windows CTest; the C++ executions run in the WIN-VERIFY round):
git diff --checkclean,git merge-tree --write-tree origin/main HEADexits 0, zero personal paths in the diff.Mutation audit
Every branch, guard and constant added is pinned by a test that kills its mutation: the modifier and MODE gates by the
controlsrefusals (26 forms, exact substrings + non-zero exit); thehalf_binaryMODE-loop addition by the conditionals_denorm_moderefusal; the destination/source pair acceptance by thecontrolsrefusals and theire64 chunk (SGPR pairs, inline128/240..247, abs/neg, abs+neg);abs/negby theirmodifier cases and thehardwaree64 program; the1075passthrough,1023sub-one bound and thelo-aware nonzero test by theirboundary values and the modelbig/small/nz_lomutations; the lo-range unit, half, evenness and carry by theexp = 1044/1074values and the modello_unit/lo_half/lo_even/lo_carrymutations; the word-boundary half and evenness by theexp = 1043ties and the modelmid_half/mid_evenmutations; the hi-range unit, half, stickyloand evenness by theexp = 1023..1042values and the modelhi_unit/hi_half/hi_sticky/hi_evenmutations; the sub-one±1.0/±0.0results and the sign by the±0.5 ± 1ulpand subnormal values and the modelrndne_half/trunc_sub/floor_sign/ceil_sign/sign_losemutations. Theclear_vector_spillsaddition joins the pair list for parity withv_cvt_f64_*; it is not what lets a pair write succeed over a symbolic lane spill.write()checkshas_spill(r)on the state beforeclear_vector_spillsruns, so any numeric vector write to a VGPR holding symbolic lanes intentionally refuses, and thecontrolsspill refusals pin that bothvector_write(i.dst)andvector_write(i.dst + 1)executewrite(): a lane spilled intov10refuses withwrite to a VGPR holding symbolic lanes: v10, and one spilled intov11refuses with...: v11, for each of the four ops.Notes
irmode splits the wave32 program into dumps of at most 1024 stores each, sinceF.storemasks offsets to 12 bits.Windows Verification (
ca0f1c09182b4ea25bdea32950956752a449f593)AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-11-30T20:23:28Z.
Review: APPROVED
Reviewed
7503e733by reading the diff; not built or run.Verdict: approve. I traced each exponent range of the lowering and found no wrong result. No MUST.
exp >= 1075passes the pair bit-for-bit, sNaN payload included. An exact compare would pin that on a device too. (Same point as on #3634.)src/gfx1013_direct_compute.inl:2162-2171): floor gives −1 and ceil +1 only for a nonzero input of the right sign; otherwise ±0 keeps its sign. rndne gives ±1 only above 0.5, and thenztest readslo, so a lo-only subnormal is not taken for zero.base_lo & unit_lo, wrapped carry intohi); word boundary 1043 (half0x80000000, LSBhi & 1); hi range 1023..1042 (losticky; at 1023 the odd bit is the exponent LSB, right for [1, 2)). Out-of-range lanes shift by 1, so every shift stays in [0, 31].half_binaryand the spill pair entry matchv_ldexp_f64. In-place pairs are safe.Tests:
modelchecks the model againstFractionround-to-nearest-even, with 18 self-mutations.irruns the C++ lowering on rows at exponents 1042/1043/1044/1074 (every word-split branch), a sweep, and e64 forms.controlspins 26 refusals plus the spill refusals onv[d]andv[d+1]. CI ran onlymodel(Linux checks); thenative_round_f64_*CTest entries are not in the Windowsprpreset filter.ir/controls/hardwarehave only the author's run at this head (RTX 4050, dev + release).Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-01T03:10:59Z.
Review: APPROVED
Reviewed the direct C++ binary64 rounding family and the refusal guards for MODE and unsupported operands.
ctest --test-dir <build> --no-tests=error -j1 -R '^native_round_f64_(ir|controls|hardware)$' --output-on-failurepassed IR, refusal controls and the RTX 4060 Laptop readback.