Skip to content

Shaders: lower binary64 ceiling and floor - #2713

Open
andrewpozdnakov7-jpg wants to merge 3 commits into
Marvisak:mainfrom
andrewpozdnakov7-jpg:codex2/directed-f64-rounding
Open

andrewpozdnakov7-jpg wants to merge 3 commits into
Marvisak:mainfrom
andrewpozdnakov7-jpg:codex2/directed-f64-rounding

Conversation

@andrewpozdnakov7-jpg

Copy link
Copy Markdown
Contributor

Summary

Lower RDNA 2 V_CEIL_F64 and V_FLOOR_F64 in VOP1 and VOP3. The lowering rounds the two 32-bit register words directly, keeps the sign of zero, and writes both destination words under the lane guard. The emitted shader requires neither the doubles nor the int64 optional feature.

The RDNA 2 ISA defines these as rounding toward positive and negative infinity.

Verification

  • On base 13f91ca, the same two synthetic D3D12 tests fail during translation with Unsupported v_ceil_f64 and Unsupported v_floor_f64.
  • With this change, both pass on app-local WARP and verify both output words for 23 inputs through VGPR and SGPR source pairs. These include signed zeros, subnormals, fractions requiring 31 to 33 discarded bits, the 2^52 boundary, and infinities. The VOP3 test checks a negated literal and both optional DXIL feature flags.
  • The VALU suite passed all 32 project tests on app-local WARP. Strict shader Clippy and the staged asset policy also passed.

Coordination claim

Please retain the Git author if cherry-picking or rebasing this commit. If folding it into another commit, add Co-authored-by: andrewpozdnakov7-jpg andrewpozdnakov7-jpg@users.noreply.github.com.

@kotekompotek

Copy link
Copy Markdown

Verified the bit-level algorithm: exponent >= 1075 short-circuits to integral (covers NaN/inf passthrough), the low-word bias plus carry-into-high handles the 32-bit boundary, clears_high (>32) vs clears_low (>=32) split is exactly right, and below-one maps to signed zero or signed one preserving -0.0 semantics (ceil(-0.5) = -0.0). Inline float constants widened f32->f64 and the 1/(2pi) constant handled explicitly. No doubles/int64 feature needed is a nice property for older hosts.

@fuzeofficlal

Copy link
Copy Markdown
Contributor

Independent Windows 11 + NVIDIA GeForce RTX 5090 + WARP + dxil.dll verification and IEEE-754 review of 0af08f5 (on 13f91ca):

Verification (rustc 1.98.1 MSVC, Windows SDK 10.0.26100.0 dxil.dll)

  • cargo xtask policy: 184 files ok.
  • cargo clippy --locked -p victory-shader --all-targets -- -D warnings and --features host: 0 warnings.
  • cargo test --locked -p victory-shader --lib -- directed_f64 emit::tests emit::lower --test-threads=1 (RTX 5090 hardware + WARP + dxil.dll active): 46 passed, 0 failed.
  • Combined merge test with Shaders: lower binary64 fractional parts #2728 (325fda6): clean zero-conflict merge; all 4 binary64 tests (directed_f64_* and fract_f64_*) pass together on RTX 5090 + WARP + dxil.dll.

Review Notes

  • Pure 32-bit integer lowering leaves SFI0 DOUBLE and INT64 flags clear while handling ±0.0 sign preservation (ceil(-0.0) = floor(-0.0) = -0.0), subnormals (±2^-1074), word-boundary shifts (n < 32, n == 32, n > 32 with shift = n & 31), |x| >= 2^52, ±Inf, abs/neg, and 240..=248 inline constants cleanly, while conservatively rejecting clamp/omod/sdwa/dpp.
  • Minor notes (non-blocking): round_directed_f64 passes an sNaN through unquieted (unlike Shaders: lower binary64 fractional parts #2728's | 0x0008_0000 quietening), and if both Shaders: lower binary64 ceiling and floor #2713 and Shaders: lower binary64 fractional parts #2728 land, the ~40-line f64 source operand + abs/neg decode block can be shared in a single helper.

@oni-swr

oni-swr commented Nov 25, 2026

Copy link
Copy Markdown

Independent WARP/CPU verification

Head: 0af08f5419502a3054bcdd0d61af2cbff1e6a797
Base: origin/main 13f91caee25f2fdf2c062be5f7a27f058e51cbca
Status: open, non-draft; clean merge tree; no oni-swr comment on this head.

Environment: Windows x64, WARP selected (VICTORY_WARP=1, VICTORY_D3D12_WARP=1), dxil.dll 1.8.2502.11 from Windows SDK 10.0.26100.0; rustc 1.98.1.

Commands (each with CARGO_TARGET_DIR=D:\victory-warp-2690-target and the WARP variables above):

  • Baseline and PR: cargo test --locked -p victory-shader
  • PR targeted: cargo test --locked -p victory-shader directed_f64_
  • PR lint: cargo clippy --locked -p victory-shader --all-targets -- -D warnings

Results: baseline 267 passed, 3 failed, 3 ignored; PR 269 passed, the same 3 failed, 3 ignored. The unchanged WARP failures are a_mask_joined_with_data_at_a_uniform_loop_is_its_number, gathers_at_a_level_match_the_hardware, and permutes_read_the_lane_named_and_zero_from_lanes_left_out (two wave-32 pipeline availability failures and one gather mismatch). Both new f64 tests passed (2/2). Clippy passed.

Negative control: disabled the new dispatch arm; the directed-f64 targeted test failed (exit 101), as expected. No issue found in the changed lowering by review.

Not tested: physical GPU, retail title, release build. AI-assisted: Codex (gpt-6-luna).

@pablogonz12

Copy link
Copy Markdown
Contributor

AMD/RADV offline check of the head commit (no game run).

  • Hardware / stack: RX 9070 XT, Mesa 26.3.1 RADV, GE-Proton11-14; base = origin/main 13f91ca.
  • Method: the 751-program world-shader dump, translated by each tree's own victory-shader --example retranslate, then dxil-spirv (master), spirv-val --target-env vulkan1.3, and a real vkCreateCompute/GraphicsPipelines on RADV (vkpipe, one process per program, so a driver crash or hang is recorded per program rather than stopping the batch).
  • Offline only: pipelines are created, never bound or drawn, so wrong pixels and ISA-level miscompiles are out of reach here.
    Result, base 13f91ca vs head 0af08f5: both translate 749 / 751 (the same 2 refused in both: a lane mask read as data is not supported). 0 of the 751 programs' DXIL bytes change, no pipeline result or time differs.

These 751 world shaders do no binary64 floor/ceiling, so the lowering is not reached by the dump; the tests added in the branch are the evidence (and victory-shader's test target does not build on Linux here, Windows validator module). No regression visible from this side.

Not tested in a game run; not tested on NVIDIA.

@cloph-dsp

Copy link
Copy Markdown

Independent local verification (Windows, rustc/cargo 1.100.0/MSVC, --locked, CARGO_BUILD_JOBS=2, synthetic inputs only, no game data, no physical GPU, no clippy/rustup):

  • PR head 0af08f5 checked out in a separate worktree. Diff is 2 files, +168/-0, in crates/victory-shader/src/emit/lower.rs and valu_tests.rs; git diff --check origin/main..HEAD is clean.
  • cargo test --locked -p victory-shader --lib directed_f64_ceil_and_floor_write_both_words --quiet → 1 passed, 0 failed.
  • Full -p victory-shader --lib run cannot complete here: it crashes with STATUS_ACCESS_VIOLATION at emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index. That exact test also crashes on unmodified origin/main (13f91ca in a detached worktree), so it is pre-existing and unrelated to this PR. All 20 emit::lower::tests reached before the crash passed, including the new one.
  • Negative control: directed_f64_ceil_and_floor_write_both_words is absent from origin/main (git grep in valu_tests.rs), so the added coverage is genuinely new.

No blocking finding from this check; the full-suite limitation is a pre-existing hardware/WARP issue, not introduced here. AI-assisted (Hy4 flash).

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Verdict: merge candidate (unchanged). The new head merges main and moves Lower::round_directed_f64 into crates/victory-shader/src/emit/lower/directed.rs. lower.rs keeps mod directed; and the v_ceil_f64 / v_floor_f64 arm. I compared the moved function with the one reviewed at 0af08f5. It differs only in rustfmt line breaks, pub(super) and imports, and the tests are unchanged. The earlier minor note still applies: a signaling NaN passes through unquieted.

Note for maintainers: #2350 (same author) adds mod frexp; at the same line of lower.rs. Whichever lands second needs a trivial conflict fix.

CI: passing (check).


Generated by Claude Code

@Dukestar69 Dukestar69 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Tested merged onto origin/main (63bcca4) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP, dxil.dll validator active):

  • cargo test -p victory-shader --lib emit::valu_tests::directed_f64: 2 passed, 0 failed (directed_f64_ceil_and_floor_write_both_words and directed_f64_vop3_negated_literal_rounds_in_both_directions pass on both RTX 5090 hardware and WARP).
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
  • cargo xtask policy: 192 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants