Repository navigation
Conversation
… zero is +0 A denormal coordinate still reads as a zero where the major axis and the signs are chosen (Marvisak#1766). The result is different: v_cubesc_f32 and v_cubetc_f32 return the chosen coordinate's own bits, negated by flipping the sign bit, and v_cubema_f32 returns +0 when the major axis is a zero or a denormal. Measured on RDNA2 (gfx1035, gfx1036) with IEEE mode off and 32-bit denormals flushed, as recorded in the AnyPS5 hardware-oracle tables. The pick and the negation work on the bits, so the result does not depend on how the host treats denormals. A probe checks seven measured rows, and the cube() model follows the same rule. Co-Authored-By: Gemini 4 Neon <noreply@google.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
Independent local verification of head
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). |
A negative Z face negates X by changing its sign bit alone. Selecting the signed values directly lost the subnormal payload on the RTX 4090 Laptop. Select the operand and its sign mask separately, then apply one integer XOR. Check both Z faces and both signs at the endpoints of the subnormal range.
The measured RDNA2 SC and TC clamp rows retain a selected positive subnormal without an output multiplier. Preserve that bit pattern while using the ordinary saturate for other values. Leave output multipliers on their existing path.
fuzeofficlal
left a comment
There was a problem hiding this comment.
The seven unmodified oracle rows in cube_zero_and_denormals_match_rdna2_oracle match the lowering cleanly (preserving subnormal S/T bits and producing +0 for zero/denormal v_cubema_f32 major axes), and emit/lower.rs is 521,349 bytes (under the 512 KiB limit).
One issue needs fixing before merge:
- Source modifiers on subnormal S/T coordinates (
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. - NaN bit precision (
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)
|
I ran the requested hardware probes on 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 |
Shaders: preserve subnormal cube coordinates on negative Z and through clamp
|
Thanks, this is the hardware run the PR was missing. I read Moon0755#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 — Fable |
|
On the review above: agreed on both points. Source The branch now also carries Moon0755#1 (the negative-Z select and the clamp case, found on an RTX 4090), so the head is — Fable |
fuzeofficlal
left a comment
There was a problem hiding this comment.
Tested the updated head (87315104): the separate coordinate/sign selection on v_cubesc_f32 and the IULT(bits, 0x0080_0000) positive-subnormal clamp passthrough pass all five cube tests on both RTX 5090 and WARP, and emit/lower.rs stays under the 512 KiB limit (522,774 bytes).
Keeping Request Changes open for the two follow-up items noted in the thread:
- Apply VOP3 source
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. - Switch
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
|
Both points from the review are in, head
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. — Devin & Fable |
fuzeofficlal
left a comment
There was a problem hiding this comment.
Verified c09afc9a on RTX 5090 and WARP: both previous items are cleanly resolved — VOP3 source abs/neg are now applied bitwise on the raw SC/TC path, and cube_zero_and_denormals_match_rdna2_oracle uses bit-exact INT assertions 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.- RTX 5090 and
VICTORY_WARP=1(--test-threads=1): all 6 cube tests passed andemit::semantics_tests38 passed, 0 failed (1 ignored).
Two minor non-blocking nits:
- In
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.
|
Both nits are in, head
CI on the fork, WARP only: 307 passed (run 45812258458). — Devin & Fable |
Dukestar69
left a comment
There was a problem hiding this comment.
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_f32 and returns +0.0 for v_cubema_f32 of zero.
Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Follow-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