Repository navigation
Shaders: lower binary64 ceiling and floor - #81
Conversation
Co-authored-by: andrewpozdnakov7-jpg <andrewpozdnakov7-jpg@users.noreply.github.com> Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
| if v.clamp || v.omod != 0 || v.sdwa.is_some() || v.dpp.is_some() { | ||
| return Err("binary64 rounding modifiers"); |
There was a problem hiding this comment.
🔴 Clamped rounding blocks shader translation
round_directed_f64 rejects valid VOP3 ceiling and floor instructions with clamping or output scaling. Instruction lowering marks both result words missing, so translation fails when a store or export needs them.
Learn more
RDNA 2 VOP3 encodes output clamping and scaling on floating-point results, and the VALU decoder passes those fields to the emitter. LLVM's gfx1030 backend can fold a clamp of a double-precision floor result directly into v_floor_f64_e64 ... clamp. The rejection leaves both result words unavailable through instruction lowering. A buffer store that consumes the result then fails translation.
Example: With clamp active, flooring 2.75 and storing the result must store 1.0. The translator rejects the shader instead.
Recommended fix: Support CLAMP and OMOD on the rounded word pair, following RDNA 2's output modifier order and mode rules. Keep unsupported encodings separate from valid output modifiers. Add VOP3 tests for each modifier that consume both result words.
Was this helpful? React with 👍 or 👎 to provide feedback.
| let magnitude = m.bin(c, Bin::Or, mag_hi, lo); | ||
| let nonzero = m.cmp(c, pred::NE, magnitude, zero); | ||
| let to_one = m.bin(c, Bin::And, away, nonzero); |
There was a problem hiding this comment.
🟡 Flushed subnormals round to one
With double-precision input flushing enabled, round_directed_f64 still treats subnormal inputs as nonzero. Instruction lowering ignores s_denorm_mode, so positive ceiling and negative floor produce ±1 instead of signed zero.
Learn more
RDNA 2's double-precision denormal mode controls whether a subnormal input reaches an arithmetic instruction as its original value or as signed zero. The register analysis accepts s_denorm_mode, and instruction lowering treats it as a no-op. The rounding code always tests the original mantissa, so it rounds away from zero even when the guest mode has already flushed the input.
Example: After s_denorm_mode 0, ceiling the positive input with bits 0x0000000000000001 must return +0.0. The emitted shader returns +1.0.
Recommended fix: Use the effective guest double-precision input denormal mode at the rounding instruction. When it requests input flushing, treat an exponent-zero input as signed zero before testing for a nonzero fraction. Add coverage for both flush and preserve modes.
Was this helpful? React with 👍 or 👎 to provide feedback.
| let result_lo = m.select(c, integral, lo, round_lo); | ||
| let result_hi = m.select(c, integral, hi, round_hi); |
| for source in [vgpr(1), sgpr(0)] { | ||
| for (word, shift) in [(6, 0), (7, 32)] { | ||
| let shader = build_valu_cs(&[vop1(op, 6, source), vop1(0x001, 0, vgpr(word))]); |
There was a problem hiding this comment.
🔍 Masked lanes lack rounding coverage
build_valu_cs uses one thread, and the test never masks that thread before rounding. It does not check that both destination words survive when EXEC disables a lane.
Was this helpful? React with 👍 or 👎 to provide feedback.
Summary
v_ceil_f64ev_floor_f64em VOP1/VOP3.Validation
cargo fmt --all -- --checkcargo run --locked --quiet --package xtask -- policyCARGO_FEATURE_PURE=1 RUSTFLAGS='-D warnings' cargo check -p victory-shader --locked --target x86_64-pc-windows-msvcCARGO_FEATURE_PURE=1 RUSTFLAGS='-D warnings' cargo clippy -p victory-shader --all-targets --locked --target x86_64-pc-windows-msvcSem validação real de jogo/GPU/Proton nesta VM; upstream validou os testes em WARP.