shader: lower v_trunc_f64, v_floor_f64, v_ceil_f64 and v_rndne_f64 #102
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/uiliannn--VItoriaBr!102
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-102"
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?
@lcg007xd-c on GitHub · 2026-11-25 22:55 UTC · original
lcg007xd-c:shader-f64-round→main· +188 −0 · 2 files · 1 commits · openWhat is broken
The f64 roundings decode, but a program using one fails to translate with
v_trunc_f64 is not supported(or the matching name):v_trunc_f64v_ceil_f64v_rndne_f64v_floor_f64They round a binary64 to an integral value (AMD's RDNA2 ISA, §12.8, opcodes 23–26). DXIL's
Round_*operations take only half and float, so there is no direct host operation for doubles.The change (
emit/lower.rs)New helper
f64_round(lo, hi, name), worked on the bits in 64-bit integers, with no host doubles:uthe unbiased exponent, bit52 − uof the 63-bit magnitude is the units bit, and the bits below it are the fraction. Clearing them truncates.|x| < 1: 0, or 1 where the rounding goes away from zero (rndne: above 0.5). The sign is kept, soceil(−0.3) = −0andfloor(−0.3) = −1.|x| ≥ 2⁵², infinities and NaNs: already integral, left unchanged. A signalling NaN comes out quiet.abs/negcome throughf64_pair, and output modifiers are refused.Tests
emit::lower::tests::f64_roundings_translate(every host): all four decode, and a program that stores the result translates. Without thelower.rschange it fails:v_trunc_f64 [7e0a2f01, 7e000306]: GFX10 code at 0x24: v_trunc_f64 is not supported.valu_tests::f64_roundings_match_ieee(Windows/GPU): both dwords of each result for 16 inputs against Rust'strunc/ceil/floor/round_ties_even. The inputs are ±0, ±0.3, ±0.5, 0.7, ties 1.5/2.5/−2.5, ±3.7,2⁵² − 0.5, 1e300 and ±inf.CPU run: I ran these on Linux through the CPU harness of #62, which runs the emitted DXIL with LLVM's
lli. I compared against the same Rust functions on 148 values:1 − ε/2, denormals andf64::MAX;negon the source (floor(−2.5) = −3).All match.
Run here (Linux, Rust 1.98.1):
cargo test -p victory-shader --lib --locked: 188 passed, 0 failed, 2 ignored.CARGO_FEATURE_PURE=1 cargo clippy -p victory-shader --all-targets --target x86_64-pc-windows-msvc -- -D warnings: clean.Not run here: the GPU case, since I have no Windows machine.
v_fract_f64is left out because it needs a double subtraction and RDNA2's clamp below 1.0.🤖 Generated with Claude Code
VOP1 0x17..=0x1A decoded but failed to translate ("v_trunc_f64 is not supported"). DXIL's rounding operations take no doubles, so these work on the binary64's bits in 64-bit integers: with u the unbiased exponent, bit 52 - u of the magnitude is the units bit; the bits below it are the fraction, cleared to truncate, and adding the units bit (carrying into the exponent, as IEEE's encoding allows) steps away from zero for floor of a negative, ceil of a positive, or round-to-nearest-even past half (or at half with an odd units bit). Below 1 the result is 0 or 1 with the sign kept; 2^52 and up, infinities and NaNs (made quiet) are already integral. Co-Authored-By: Claude Opus 5.5 <[email protected]>@lmouz823-lang on GitHub · 2026-11-27 14:59 UTC · original
I can take the native Windows/NVIDIA validation at exact head
3491b2d40d6e2315a50f403c6b384eed0904722a:f64_roundings_translateandf64_roundings_match_ieee. I will run the unmodified head first on Windows 11/MSVC with an RTX 4060 Laptop (8 GiB, driver 610.88), the SDK DXIL validator and strict test mode, and report both physical-GPU and WARP execution plus the actual input coverage here.AI-assisted with Codex.
@lmouz823-lang on GitHub · 2026-11-27 15:09 UTC · original
Native Windows/NVIDIA validation completed on exact head
3491b2d40d6e2315a50f403c6b384eed0904722a(Windows 11 build 26200, RTX 4060 Laptop 8 GiB, driver 610.88, Rust 1.98.1 MSVC).Both tests pass on the untouched head:
emit::lower::tests::f64_roundings_translate: 1 passed.emit::valu_tests::f64_roundings_match_ieee: 1 passed, 4.23 s; the existing 16 inputs, four roundings and both result dwords ran on hardware and WARP.The log identifies both actual backends:
I set
VICTORY_STRICT_TESTS=1(no device skips), unsetVICTORY_WARP, and explicitly setVICTORY_DXILto SDK 10.0.26100.0'sdxil.dll1.8.2502.11. The existing validator-load branch remains optional; these results establish actual device execution, not a change to that helper. I cleaned only thevictory-shaderrelease package before the first build to prevent a shared target directory from reusing a sibling PR's test binary, and checked each exact filter ran one test.I also tested the small test-only addition below for the minimum binary64 subnormals,
+2^-1074and-2^-1074. Expected bits are explicit, so the check includes the sign of zero:The added case passed on the RTX 4060 and WARP (1 test, 1.75 s), and both original tests passed again with it present.
cargo run --release --locked -p xtask -- policyreported195 files ok;git diff --checkis clean. No production code was changed.Commands (each test uses
-- --exact --nocapture --test-threads=1):This covers these synthetic inputs on NVIDIA and WARP. AMD hardware, NaNs/signalling NaNs and dynamic MODE behavior remain untested; I have not used this result to claim game behavior or performance.
Optional subnormal regression test, against
3491b2d(not committed)AI-assisted local validation with Codex.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.