shader: lower v_ceil_f64, v_floor_f64, v_trunc_f64 and v_rndne_f64 in direct compute #3632
No reviewers
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows!3632
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@Ammmae0x on GitHub · 2026-11-30 17:47 UTC · original
Ammmae0x:shader/direct-round-f64→main· +964 −1 · 6 files · 5 commits · merged 2026-12-01 03:12 UTCRefs #2935, #3520
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.
1. MSVC C2561: the rounding block is inside bool float_alu(...), so end it with 'return true;' instead of 'return;'. 2. v_floor_f64 sub-one high word was 3221225472 (0xC0000000 = -2.0); it is 3220176896 (0xBFF00000 = -1.0). The ir needle follows the translator's verbatim constant ('3220176896'); the controls dxc -dumpbin needle uses the signed form ('-1074790400'). 3. Hardware stores: each case stores 4 ops x 8 bytes = 32 bytes, so the store stride is 32 * index, not 16 * index, in both hw_program() branches. 4. The ir spill dump was broken: write() checks has_spill(r) on the state BEFORE clear_vector_spills runs, so any numeric vector write to a VGPR holding symbolic lanes intentionally refuses. Remove the spill chunk; instead the controls refusals pin that both vector_write(i.dst) and vector_write(i.dst + 1) execute write(), with a spill into v10 refusing ': v10' and into v11 refusing ': v11' for each op. The pair entry in clear_vector_spills stays for parity with v_cvt_f64_*. 5. Wave64 ir: pure per-lane VALU ops never emit @waveExchange, and the wave64 EXEC setup uses @dx.op.waveActiveOp.i32, which F.interpret() does not implement. Check the dump text only (returncode 0, NumThreads=(64,1,1), no double/i64/fcmp, no exchange, needles present). Also add a combined abs+neg MOD_CASES entry to verify abs applies before neg.native_compute_ir_dump prints raw LLVM IR metadata ('!6 = !{i32 64, i32 1, i32 1}'); 'NumThreads=(64,1,1)' is only formatted by 'dxc -dumpbin'. Check the metadata form instead.@lukaslw-lab on GitHub · 2026-11-30 20:23 UTC · original · approved these changes
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 #3636.)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).d5970858into shader/direct-round-f64 c53b5f34b7da804b9cinto shader/direct-round-f64 ca0f1c0918@R0Y00 on GitHub · 2026-12-01 03:10 UTC · original · approved these changes
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.