Shaders: lower v_cmp_{f,t}_{i64,u64} constant 64-bit compares #1531

Open
opened 2026-11-26 04:35:20 +00:00 by github-bot · 2 comments
Owner

@⁠davi713albano-coder on GitHub · 2026-11-24 18:49 UTC · original

Summary

In emit::lower::compare, the "u32" | "i32" | "u16" | "i16" arm handles constant-false ("f") and constant-true ("t") compares via self.lane(inst, Some(op == "t")), while the "u64" | "i64" arm fell through to Err("a 64-bit compare").

This branch adds "f" | "t" handling to the "u64" | "i64" compare arm (covering v_cmp_{f,t}_{i64,u64} and v_cmpx_{f,t}_{i64,u64}), short-circuiting before self.src64 so constant 64-bit compares do not spuriously set flags::INT64 (0x8000 in SFI0).

Changes (shader/cmp64-f-and-t, commit 41715fc)

  • crates/victory-shader/src/emit/lower.rs: handle "f" | "t" in the "u64" | "i64" arm of compare() before src64.
  • crates/victory-shader/src/emit/valu_tests.rs: add synthetic compute test v_cmp_f_and_t_64bit_match_rdna2 testing v_cmp_f_i64, v_cmp_t_i64, v_cmp_f_u64, and v_cmp_t_u64 against dxil.dll validation, SFI0 Int64 flag absence, and D3D12 WARP execution.

Branch & Verification

(No game data used. AI-assisted.)

**@⁠davi713albano-coder** on GitHub · 2026-11-24 18:49 UTC · [original](https://github.com/Marvisak/VIctory/issues/1531) ### Summary In `emit::lower::compare`, the `"u32" | "i32" | "u16" | "i16"` arm handles constant-false (`"f"`) and constant-true (`"t"`) compares via `self.lane(inst, Some(op == "t"))`, while the `"u64" | "i64"` arm fell through to `Err("a 64-bit compare")`. This branch adds `"f" | "t"` handling to the `"u64" | "i64"` compare arm (covering `v_cmp_{f,t}_{i64,u64}` and `v_cmpx_{f,t}_{i64,u64}`), short-circuiting before `self.src64` so constant 64-bit compares do not spuriously set `flags::INT64` (`0x8000` in `SFI0`). ### Changes (`shader/cmp64-f-and-t`, commit `41715fc`) - `crates/victory-shader/src/emit/lower.rs`: handle `"f" | "t"` in the `"u64" | "i64"` arm of `compare()` before `src64`. - `crates/victory-shader/src/emit/valu_tests.rs`: add synthetic compute test `v_cmp_f_and_t_64bit_match_rdna2` testing `v_cmp_f_i64`, `v_cmp_t_i64`, `v_cmp_f_u64`, and `v_cmp_t_u64` against `dxil.dll` validation, `SFI0` `Int64` flag absence, and D3D12 WARP execution. ### Branch & Verification - **Branch:** https://github.com/davi713albano-coder/VIctory/tree/shader/cmp64-f-and-t - **Compare against `main` (`ffe310e`):** https://github.com/Marvisak/VIctory/compare/main...davi713albano-coder:VIctory:shader/cmp64-f-and-t - **Unmodified upstream CI (`windows-latest`):** https://github.com/davi713albano-coder/VIctory/actions/runs/45461692979 - `cargo clippy --workspace --all-targets --locked -- -D warnings`: passed - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: passed - `cargo test --workspace --locked` (including `xtask` asset-policy check, `dxil.dll` validation, and D3D12 WARP tests): 343 passed, 0 failed (`emit::valu_tests::v_cmp_f_and_t_64bit_match_rdna2 ... ok`) *(No game data used. AI-assisted.)*
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:35:20 +00:00
Author
Owner

@⁠studiostephe on GitHub · 2026-11-25 03:55 UTC · original

In emit::lower::compare, the "u64" | "i64" arm calls self.src64(...) before matching the op, and src64 unconditionally sets flags::INT64. So v_cmp_f_i64 / v_cmp_t_i64 / v_cmp_f_u64 / v_cmp_t_u64 — constant compares that read no 64-bit source — still take the SFI0 Int64 feature (0x8000), where the "u32" | "i32" | "u16" | "i16" arm already short-circuits f/t through self.lane(...) before touching the sources.

The fix mirrors the integer arm: handle f/t in the 64-bit arm before src64, so constant 64-bit compares emit a lane constant and never set INT64.

diff --git a/crates/victory-shader/src/emit/lower.rs b/crates/victory-shader/src/emit/lower.rs
index caab7ea..32056ce 100644
--- a/crates/victory-shader/src/emit/lower.rs
+++ b/crates/victory-shader/src/emit/lower.rs
@@ -7318,6 +7318,10 @@ impl<'a> Lower<'a> {
                 }
             }
             "u64" | "i64" => {
+                if op == "f" || op == "t" {
+                    self.lane(inst, Some(op == "t"));
+                    return Ok(());
+                }
                 let (a, b) = (self.src64(inst, 0)?, self.src64(inst, 1)?);
                 let signed = ty == "i64";
                 let p = match op {
diff --git a/crates/victory-shader/src/emit/valu_tests.rs b/crates/victory-shader/src/emit/valu_tests.rs
index 3bf9d61..0e300b8 100644
--- a/crates/victory-shader/src/emit/valu_tests.rs
+++ b/crates/victory-shader/src/emit/valu_tests.rs
@@ -1095,6 +1095,50 @@ fn signed_64_bit_operands_sign_extend_their_literal() {
     check("s_ashr_i64", &ashr, &[([0; 4], u32::MAX)]);
 }
 
+/// The SFI0 feature payload of an emitted container: the 8 little-endian bytes
+/// that follow the `SFI0` chunk tag (its length is a multiple of 8, so the tag
+/// cannot be a false hit inside another chunk).
+fn sfi0_features(dxil: &[u8]) -> u64 {
+    let tag = *b"SFI0";
+    let at = (0..dxil.len() - 4)
+        .find(|&i| dxil[i..i + 4] == tag)
+        .expect("SFI0 chunk");
+    u64::from_le_bytes(dxil[at + 4..at + 12].try_into().unwrap())
+}
+
+/// `v_cmp_{f,t}_{i64,u64}` are constant compares: they must lower to a lane
+/// constant without reading the 64-bit sources, so the module must not take the
+/// SFI0 `Int64` feature (`0x8000`) that a real `v_cmp_*_{i64,u64}` does.
+#[test]
+fn v_cmp_f_and_t_64bit_do_not_require_int64() {
+    // SFI0 bit the emitter sets for `flags::INT64`.
+    const INT64_FEATURE: u64 = 0x8000;
+    for (name, op) in [
+        ("v_cmp_f_i64", 0x0a0u16),
+        ("v_cmp_t_i64", 0x0a7),
+        ("v_cmp_f_u64", 0x0e0),
+        ("v_cmp_t_u64", 0x0e7),
+    ] {
+        // v_cmp_*_64 s6, v1, v2 (VOP3, two source dwords); the constant result
+        // ignores them. No `src64` read, so no 64-bit feature is required.
+        let [a, b] = vop3(op, 6, vgpr(1), vgpr(2), 0);
+        let shader = build_valu_cs(&[a, b]);
+        let f = sfi0_features(&shader.dxil);
+        assert!(
+            f & INT64_FEATURE == 0,
+            "{name} must not set the SFI0 Int64 feature (got {f:#x})"
+        );
+    }
+    // A real 64-bit compare reads both sources and must set the feature, so the
+    // check above is not vacuous.
+    let [a, b] = vop3(0x0a2, 6, vgpr(1), vgpr(2), 0); // v_cmp_eq_i64
+    let f = sfi0_features(&build_valu_cs(&[a, b]).dxil);
+    assert!(
+        f & INT64_FEATURE != 0,
+        "v_cmp_eq_i64 must set the SFI0 Int64 feature (got {f:#x})"
+    );
+}
+
 #[test]
 fn bfe_signed_and_unsigned_match_rdna2() {
     // v_bfe_i32 v0, v1, v2, v3 (VOP3 opcode 0x149)

Verified:

  • New test v_cmp_f_and_t_64bit_do_not_require_int64 builds each of the four constant compares, reads the SFI0 feature payload out of the emitted container, and asserts the Int64 bit is clear; a real v_cmp_eq_i64 is the control and must set it (so the check is not vacuous).
  • The test is CPU-side (it only lowers and inspects the container — no D3D12 dispatch), but it lives in valu_tests, which is #[cfg(all(test, windows))] because that module imports the D3D12 host. So I could not run it on this Mac; I cross-compiled it:
    • cargo check -p victory-shader --profile test --target x86_64-pc-windows-msvc: clean.
    • cargo clippy -p victory-shader --profile test --target x86_64-pc-windows-msvc: 0 warnings.
    • cargo test -p victory-shader --locked (the 144 non-Windows tests): 144 passed, 0 failed, 2 ignored — the lower.rs change introduces no regression in the runnable suite.

Not covered: I could not execute the new test against dxil.dll/WARP (no Windows here), and the pre-existing fmt drift in lower.rs (unrelated long lines) is left as-is; my added lines are fmt-clean.

Local commit 4808a39 on a clean 940d32f (two files, +44/−1).

qwen3.8_27b running locally on an M1 Mac
shout out to Digital Debris Los Angeles

**@⁠studiostephe** on GitHub · 2026-11-25 03:55 UTC · [original](https://github.com/Marvisak/VIctory/issues/1531#issuecomment-7152372023) In `emit::lower::compare`, the `"u64" | "i64"` arm calls `self.src64(...)` before matching the op, and `src64` unconditionally sets `flags::INT64`. So `v_cmp_f_i64` / `v_cmp_t_i64` / `v_cmp_f_u64` / `v_cmp_t_u64` — constant compares that read no 64-bit source — still take the SFI0 `Int64` feature (`0x8000`), where the `"u32" | "i32" | "u16" | "i16"` arm already short-circuits `f`/`t` through `self.lane(...)` before touching the sources. The fix mirrors the integer arm: handle `f`/`t` in the 64-bit arm before `src64`, so constant 64-bit compares emit a lane constant and never set `INT64`. ```diff diff --git a/crates/victory-shader/src/emit/lower.rs b/crates/victory-shader/src/emit/lower.rs index caab7ea..32056ce 100644 --- a/crates/victory-shader/src/emit/lower.rs +++ b/crates/victory-shader/src/emit/lower.rs @@ -7318,6 +7318,10 @@ impl<'a> Lower<'a> { } } "u64" | "i64" => { + if op == "f" || op == "t" { + self.lane(inst, Some(op == "t")); + return Ok(()); + } let (a, b) = (self.src64(inst, 0)?, self.src64(inst, 1)?); let signed = ty == "i64"; let p = match op { diff --git a/crates/victory-shader/src/emit/valu_tests.rs b/crates/victory-shader/src/emit/valu_tests.rs index 3bf9d61..0e300b8 100644 --- a/crates/victory-shader/src/emit/valu_tests.rs +++ b/crates/victory-shader/src/emit/valu_tests.rs @@ -1095,6 +1095,50 @@ fn signed_64_bit_operands_sign_extend_their_literal() { check("s_ashr_i64", &ashr, &[([0; 4], u32::MAX)]); } +/// The SFI0 feature payload of an emitted container: the 8 little-endian bytes +/// that follow the `SFI0` chunk tag (its length is a multiple of 8, so the tag +/// cannot be a false hit inside another chunk). +fn sfi0_features(dxil: &[u8]) -> u64 { + let tag = *b"SFI0"; + let at = (0..dxil.len() - 4) + .find(|&i| dxil[i..i + 4] == tag) + .expect("SFI0 chunk"); + u64::from_le_bytes(dxil[at + 4..at + 12].try_into().unwrap()) +} + +/// `v_cmp_{f,t}_{i64,u64}` are constant compares: they must lower to a lane +/// constant without reading the 64-bit sources, so the module must not take the +/// SFI0 `Int64` feature (`0x8000`) that a real `v_cmp_*_{i64,u64}` does. +#[test] +fn v_cmp_f_and_t_64bit_do_not_require_int64() { + // SFI0 bit the emitter sets for `flags::INT64`. + const INT64_FEATURE: u64 = 0x8000; + for (name, op) in [ + ("v_cmp_f_i64", 0x0a0u16), + ("v_cmp_t_i64", 0x0a7), + ("v_cmp_f_u64", 0x0e0), + ("v_cmp_t_u64", 0x0e7), + ] { + // v_cmp_*_64 s6, v1, v2 (VOP3, two source dwords); the constant result + // ignores them. No `src64` read, so no 64-bit feature is required. + let [a, b] = vop3(op, 6, vgpr(1), vgpr(2), 0); + let shader = build_valu_cs(&[a, b]); + let f = sfi0_features(&shader.dxil); + assert!( + f & INT64_FEATURE == 0, + "{name} must not set the SFI0 Int64 feature (got {f:#x})" + ); + } + // A real 64-bit compare reads both sources and must set the feature, so the + // check above is not vacuous. + let [a, b] = vop3(0x0a2, 6, vgpr(1), vgpr(2), 0); // v_cmp_eq_i64 + let f = sfi0_features(&build_valu_cs(&[a, b]).dxil); + assert!( + f & INT64_FEATURE != 0, + "v_cmp_eq_i64 must set the SFI0 Int64 feature (got {f:#x})" + ); +} + #[test] fn bfe_signed_and_unsigned_match_rdna2() { // v_bfe_i32 v0, v1, v2, v3 (VOP3 opcode 0x149) ``` **Verified:** - New test `v_cmp_f_and_t_64bit_do_not_require_int64` builds each of the four constant compares, reads the SFI0 feature payload out of the emitted container, and asserts the `Int64` bit is clear; a real `v_cmp_eq_i64` is the control and must set it (so the check is not vacuous). - The test is CPU-side (it only lowers and inspects the container — no D3D12 dispatch), but it lives in `valu_tests`, which is `#[cfg(all(test, windows))]` because that module imports the D3D12 `host`. So I could not *run* it on this Mac; I cross-compiled it: - `cargo check -p victory-shader --profile test --target x86_64-pc-windows-msvc`: clean. - `cargo clippy -p victory-shader --profile test --target x86_64-pc-windows-msvc`: 0 warnings. - `cargo test -p victory-shader --locked` (the 144 non-Windows tests): 144 passed, 0 failed, 2 ignored — the `lower.rs` change introduces no regression in the runnable suite. **Not covered:** I could not execute the new test against `dxil.dll`/WARP (no Windows here), and the pre-existing fmt drift in `lower.rs` (unrelated long lines) is left as-is; my added lines are fmt-clean. Local commit `4808a39` on a clean `940d32f` (two files, +44/−1). qwen3.8_27b running locally on an M1 Mac shout out to Digital Debris Los Angeles
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 10:25 UTC · original

Automated triage for the maintainers.

Confirmed on main: in crates/victory-shader/src/emit/lower.rs, compare, the "u64" | "i64" arm reads both 64-bit sources (src64, which sets the 64-bit-integer flag) and then has no case for f or t, so v_cmp_{f,t}_{i64,u64} fail translation with "a 64-bit compare" and the program is dropped. The 32/16-bit arm already lowers f/t to a lane constant. Open pull request #1685 carries this change, so please continue on that PR rather than the fork branch. The diff in the comment takes the same approach.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 10:25 UTC · [original](https://github.com/Marvisak/VIctory/issues/1531#issuecomment-7159674996) <!-- victory-issue-triage v1 verdict=confirmed seen=2026-11-25T03:55:51Z at=2026-11-25T09:50:38Z --> Automated triage for the maintainers. Confirmed on `main`: in `crates/victory-shader/src/emit/lower.rs`, `compare`, the `"u64" | "i64"` arm reads both 64-bit sources (`src64`, which sets the 64-bit-integer flag) and then has no case for `f` or `t`, so `v_cmp_{f,t}_{i64,u64}` fail translation with "a 64-bit compare" and the program is dropped. The 32/16-bit arm already lowers `f`/`t` to a lane constant. Open pull request #1685 carries this change, so please continue on that PR rather than the fork branch. The diff in the comment takes the same approach. --- _Generated by [Claude Code](https://claude.ai/code)_
This discussion has been locked. Commenting is limited to contributors.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory#1531
No description provided.