Skip to content

Shaders: lower binary64 ceiling and floor - #81

Merged
devin-ai-integration[bot] merged 1 commit into
mainfrom
devin/f64-rounding
Nov 25, 2026
Merged

devin-ai-integration[bot] merged 1 commit into
mainfrom
devin/f64-rounding

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Porta a upstream #2713: implementa v_ceil_f64 e v_floor_f64 em VOP1/VOP3.
  • O lowering arredonda diretamente as duas words de 32 bits, preserva zero com sinal e escreve ambas as words sob o lane guard, sem exigir features opcionais de doubles/int64 no host DXIL.
  • Inclui os testes sintéticos upstream de VGPR/SGPR, zeros com sinal, subnormais, limites de 2^52, infinitos e literal VOP3 negado.

Validation

  • cargo fmt --all -- --check
  • cargo run --locked --quiet --package xtask -- policy
  • CARGO_FEATURE_PURE=1 RUSTFLAGS='-D warnings' cargo check -p victory-shader --locked --target x86_64-pc-windows-msvc
  • CARGO_FEATURE_PURE=1 RUSTFLAGS='-D warnings' cargo clippy -p victory-shader --all-targets --locked --target x86_64-pc-windows-msvc

Sem validação real de jogo/GPU/Proton nesta VM; upstream validou os testes em WARP.


Devin Review

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>

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 4 potential issues.

Devin Review

Comment on lines +7185 to +7186
if v.clamp || v.omod != 0 || v.sdwa.is_some() || v.dpp.is_some() {
return Err("binary64 rounding modifiers");

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 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.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +7274 to +7276
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);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +7284 to +7285
let result_lo = m.select(c, integral, lo, round_lo);
let result_hi = m.select(c, integral, hi, round_hi);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Unverified signaling NaN behavior

round_directed_f64 returns signaling NaNs without quieting them. A native RDNA 2 comparison would establish whether ceiling and floor preserve those bits.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +465 to +467
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))]);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 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.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

@devin-ai-integration
devin-ai-integration Bot merged commit 24708d2 into main Nov 25, 2026
5 checks passed
@devin-ai-integration
devin-ai-integration Bot deleted the devin/f64-rounding branch November 25, 2026 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant