Shaders: v_cubesc/tc_f32 keep denormal coordinates, v_cubema_f32 of a zero is +0 #3127
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!3127
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3127"
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?
@Moon0755 on GitHub · 2026-11-26 09:16 UTC · original
Moon0755:fix/cube-denormal-results→main· +359 −29 · 2 files · 10 commits · openFollow-up to #1766. That change made the cube ops read a denormal coordinate as a zero of its sign, for the axis choice and for the result alike. The axis choice matches RDNA2; the result does not.
Problem
With IEEE mode off and 32-bit denormals flushed (the mode
semantics_tests.rsmodels), RDNA2 does this:mainalready does that.v_cubesc_f32andv_cubetc_f32return the chosen coordinate's own bits. A negation flips the sign bit and nothing else.mainreturns a zero for a denormal.v_cubema_f32returns +0 when the major axis is a zero or a denormal.mainreturns -0 for a negative one.Example:
v_cubesc_f32(-inf, -denormal, 0x00000007)is0x00000007on RDNA2 and0x00000000onmain.v_cubema_f32(-0, -0, -0)is0x00000000on RDNA2 and0x80000000onmain.Source of the expected values
The AnyPS5 project measured the four cube ops on RDNA2 (gfx1035, later gfx1036) in this float mode and keeps the rows in its test
core/libs/prx/libSceAgcDriver/tests/execution/Vop3CubeClamp.cpp(its PR 508 describes the measurement: 4096 rows of zeros, denormals, infinities and NaNs).semantics_tests.rsalready cites that oracle formin/max. The test here uses seven of the published rows as numbers; no code is taken from that project.#1766 compared the translated shader on an RX 9070 and on WARP with a model. The model took the flushed result from the float mode in general, not from a run of the cube instructions on RDNA2, so the two do not contradict each other as measurements.
Fix
In the cube arm of
lower.rs:v_cubesc_f32andv_cubetc_f32select among the operands' integer bits and negate with an XOR of the sign bit;v_cubema_f32turns a result with a zero exponent into +0.The pick and the negation are integer operations, so the result still does not depend on how the host treats denormals, which was the point of #1766.
Test
semantics_tests::cube_zero_and_denormals_match_rdna2_oracle, seven measured rows through the three ops (signed zeros, denormals, an infinity and a NaN beside a denormal).cube()model behindcube_faces_match_the_hardware(14,440 inputs) follows the same rule. With the old model that probe would fail on the denormal rows.Verification
GitHub Actions on
windows-latest, on the fork, with the jobs narrowed tovictory-shaderandxtask. The runner has no hardware adapter, so the probes ran on WARP only.303 passed; 0 failed; 3 ignored; both cube probes report 0 model mismatches;302 passed; 1 failed, the new test only, with 3, 3 and 4 mismatches of 7 forcubesc,cubetcandcubema.Not checked
cube_faces_match_the_hardwareand the new test on a real GPU would be welcome.clampand the output multiplier on these ops. They go throughwrite_fas before; a denormalcubesc/cubetcresult now reachesclamp, where the host's saturate decides whether it is kept (the AnyPS5 table says RDNA2 keeps a positive one).— Gemini & Fable
@cloph-dsp on GitHub · 2026-11-26 09:27 UTC · original
Independent local verification of head
7d34d38on Windows 11, Rust 1.100.0/MSVC:VICTORY_WARP=1 cargo test --locked -p victory-shader --lib -- semantics_tests::cube_zero_and_denormals_match_rdna2_oracle— 1 passed, 0 failed.git diff --check origin/main HEAD— clean.Host GPUs: RTX 5060 Laptop (driver 621.24) and Radeon 780M RDNA3; this run used the WARP adapter. Synthetic shader inputs only; no game assets, extracted shaders or DRM material used. AI-assisted (Hy4 flash).
@fuzeofficlal on GitHub · 2026-11-26 10:03 UTC · original · requested changes
The seven unmodified oracle rows in
cube_zero_and_denormals_match_rdna2_oraclematch the lowering cleanly (preserving subnormal S/T bits and producing+0for zero/denormalv_cubema_f32major axes), andemit/lower.rsis521,349bytes (under the 512 KiB limit).One issue needs fixing before merge:
emit/lower.rs:2103-2109, 6050):rx/ry/rzare still read viafsrc, which lowers VOP3abswith DXILFAbsandnegwith floating-pointBin::Sub(-0.0, f). When the host flushes denormals on floating-point ops, a legal VOP3 sourceNEGmodifier on a subnormal coordinate (for example,0x0000_0007) can flush to-0.0(0x8000_0000) beforev_cubesc_f32/v_cubetc_f32readsas_int, losing the subnormal payload. Please apply sourceabs/negas bit operations for the S/T raw-bit path and add a test case covering source modifiers on subnormals.semantics_tests.rs:1483-1488): Using a bit-exactINTcomparison forv_cubesc_f32/v_cubetc_f32oracle assertions would also pin down the NaN sign and quiet bit (and verify sNaN preservation if covered).Verified locally on Windows 11 x64 (RTX 5090 + WARP +
dxil.dll,7d34d385):cargo run --locked -p xtask -- policy: passed (191 files ok)cargo clippy -p victory-shader --all-targets --locked -- -D warnings(default and--all-features): cleanemit::lower::tests: 33 passed, 0 failedcube_ -- --test-threads=1(RTX 5090 andVICTORY_WARP=1): 3 passed, 0 failed on both (cube_gradients_pick_the_level,cube_faces_match_the_hardware,cube_zero_and_denormals_match_rdna2_oracle)@passerbyyhx on GitHub · 2026-11-26 10:03 UTC · original
I ran the requested hardware probes on
7d34d385on an RTX 4090 Laptop (native adapter verified by LUID). All seven RDNA2 reference rows passed. In the larger probe,CUBESCdiffered from the model on 336 of 14,440 inputs, all on the negative Z face with a nonzero subnormal X. The other three cube instructions matched on every input.I opened Moon0755/VIctory#1 against your branch. Selecting the coordinate and sign mask separately eliminated all 336 mismatches. A second commit covers the no-multiplier
CLAMPcase you called out. Before it, both adapters flushed positive subnormal results on two of five measured SC rows and one TC row. All five cube tests now pass on both the RTX 4090 Laptop and WARP. The PR includes the reproducer and the three unrelated shader-suite failures that also reproduce on your base.@Moon0755 on GitHub · 2026-11-26 10:09 UTC · original
Thanks, this is the hardware run the PR was missing. I read Moon0755/VIctory#1 and ran it through CI on the fork (run 45798031432, WARP only): 305 passed, 0 failed, the five cube tests among them. The five clamp rows match the published table. It is merged into this branch as
8731510, so the commits keep your authorship.— Fable
@Moon0755 on GitHub · 2026-11-26 10:09 UTC · original
On the review above: agreed on both points. Source
abs/negon these ops will be applied to the bits on the SC/TC path, with a test on the modifier columns of the same published table, and the oracle test will compare bit for bit. I'll push it here after a CI run on the fork.The branch now also carries Moon0755/VIctory#1 (the negative-Z select and the clamp case, found on an RTX 4090), so the head is
8731510.— Fable
@fuzeofficlal on GitHub · 2026-11-26 10:32 UTC · original · requested changes
Tested the updated head (
87315104): the separate coordinate/sign selection onv_cubesc_f32and theIULT(bits, 0x0080_0000)positive-subnormal clamp passthrough pass all five cube tests on both RTX 5090 and WARP, andemit/lower.rsstays under the 512 KiB limit (522,774bytes).Keeping Request Changes open for the two follow-up items noted in the thread:
ABS/NEGmodifiers as bit operations on thev_cubesc_f32/v_cubetc_f32raw-bit path sofsrc(Bin::Sub(-0.0, f)/FAbs) cannot flush subnormals before selection, with a modified-subnormal test case.cube_zero_and_denormals_match_rdna2_oracleS/T checks fromF32to bit-exactINTassertions.Verified locally on Windows 11 x64 (RTX 5090 + WARP +
dxil.dll,87315104):cargo run --locked -p xtask -- policy: passed (191 files ok)cargo clippy -p victory-shader --all-targets --locked -- -D warnings(default and--all-features): cleanemit::lower::tests: 33 passed, 0 failedcube -- --test-threads=1(RTX 5090 andVICTORY_WARP=1): 5 passed, 0 failed on both@Moon0755 on GitHub · 2026-11-26 11:08 UTC · original
Both points from the review are in, head
c09afc9.abs/negonv_cubesc_f32/v_cubetc_f32now act on the operand bits (AND with0x7FFF_FFFF, then XOR with0x8000_0000) on the raw-bit path. The axis and sign decisions are unchanged.cube_srcmod_bit_paths_match_rdna2_oracle: rows 6, 7, 8 and 11 of the published table, columns 9 (|x|, -y, -z) and 10 (-x, -y, |z|), compared bit for bit.cube_zero_and_denormals_match_rdna2_oraclecompares S/T bit for bit as well; all rows pass, the NaN rows included.CI on the fork, WARP only: without the change the new test fails (run 45800496753; WARP itself flushes the subnormal in the float abs/neg, so the mechanism shows there too), with it 306 pass (run 45805387961). Not run on a hardware adapter.
lower.rsis 523,730 bytes.— Devin & Fable
@fuzeofficlal on GitHub · 2026-11-26 11:18 UTC · original · approved these changes
Verified
c09afc9aon RTX 5090 and WARP: both previous items are cleanly resolved — VOP3 sourceabs/negare now applied bitwise on the raw SC/TC path, andcube_zero_and_denormals_match_rdna2_oracleuses bit-exactINTassertions for SC/TC.Verified locally on Windows 11 x64 (RTX 5090 + WARP +
dxil.dll,c09afc9a):cargo run --locked -p xtask -- policy(191 files ok;emit/lower.rs=523,730bytes, 558 bytes below the 524,288-byte cap) andcargo clippy --workspace --all-targets -- -D warnings(default and--all-features): clean.emit::lower::tests: 33 passed, 0 failed.VICTORY_WARP=1(--test-threads=1): all 6 cube tests passed andemit::semantics_tests38 passed, 0 failed (1 ignored).Two minor non-blocking nits:
cube_srcmod_bit_paths_match_rdna2_oracle(semantics_tests.rs:1514-1558), none of the 4 cases currently select a negative subnormal withabsenabled along the raw SC/TC path (sc_modsputsabsonx, which is only selected in row 4 wherexis already+0x0000_0007;tc_modsputsabsonz, which is never selected becauseyis never major). Adding a row that selects a negative subnormal underabs(e.g.,SC(|-denorm|, 0, +1)orTC(0, +1, |-denorm|)) would also lock down rawabs.rustfmt --edition 2024 --checkflags formatting on newly added lines1485,1497, and1513insemantics_tests.rs.@Moon0755 on GitHub · 2026-11-26 11:45 UTC · original
Both nits are in, head
de77244, tests only.v_cubesc_f32 v23, v4, -v5, |v6| clamp, rows 6, 8 and 11. Row 8 selects a negative subnormalzunderabsthrough the negativexaxis; all three give0x00000007. New testclamped_cube_abs_of_negative_denormal_matches_rdna2_oracle, bit for bit.rustfmtflagged are formatted from thecargo fmt --checkoutput in CI. Two older hunks in that file (now at 1931 and 3450) are not from this PR and are left alone.CI on the fork, WARP only: 307 passed (run 45812258458).
— Devin & Fable
@Dukestar69 on GitHub · 2026-11-26 13:09 UTC · original · approved these changes
Verified on RTX 5090 & WARP against
origin/main(63bcca4):cargo test -p victory-shader --lib cube -- --test-threads=1: 7/7 passed on RTX 5090 and WARP (all 5 new cube denormal/zero/srcmod/clamp tests pass).cargo clippy -p victory-shader --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Cleanly preserves denormal coordinates in
v_cubesc/v_cubetc_f32and returns+0.0forv_cubema_f32of zero.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
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.