Shaders: lower SOP2 s_pack_{ll,lh,hh}_b32_b16 (#815) #2361

Open
github-bot wants to merge 1 commit from github-bot/gh-2361 into main AGit
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 11:53 UTC · original
fuzeofficlal:feat/shader-spack-b32-b16-815 → main · +124 −0 · 3 files · 1 commits · open

Summary

Lowers the three RDNA2 SOP2 scalar 16-bit half-word pack instructions in Lower::sop (crates/victory-shader/src/emit/lower.rs):

  • s_pack_ll_b32_b16 (0x32): (S0.u32 & 0xFFFF) | (S1.u32 << 16)
  • s_pack_lh_b32_b16 (0x33): (S0.u32 & 0xFFFF) | (S1.u32 & 0xFFFF_0000)
  • s_pack_hh_b32_b16 (0x34): (S0.u32 >> 16) | (S1.u32 & 0xFFFF_0000)

In the native compute pipeline measurements reported in #815 (#issuecomment world run breakdown), s_pack_ll_b32_b16 (104 distinct programs) and s_pack_hh_b32_b16 (48 distinct programs) account for 152 refused compute programs.

ISA Semantics

  • Decoding: gfx10/opcodes.rs (0x32..=0x34) and gfx10/fields.rs (salu_dwords) already decode all three opcodes as 32-bit SOP2 instructions.
  • No SCC write: Per the AMD RDNA2 ISA Reference Guide (SOP2 S_PACK_*_B32_B16), none of the three variants reads or modifies SCC. ir::writes_scc already leaves SCC untouched (write(Reg::Scc) == None), and Lower::sop returns None for the SCC flag.
  • 32-bit scalar inline constants: Both sources are SSrc_b32 operands, so inline float constants (240..=248) expand to their 32-bit f32 bit patterns via src32 (self.operand -> resource::inline), e.g. 1.0 (242) = 0x3F80_0000 (lo16 = 0x0000, hi16 = 0x3F80).

Verification

  • ir::tests::scalar_pack_does_not_clobber_scc: verifies IR SSA wiring leaves SCC live across s_cmp_eq_u32 -> s_pack_{ll,lh,hh}_b32_b16 -> s_cselect_b32.
  • emit::valu_tests::scalar_pack_b16_halves_and_preserves_scc: validates emitted DXIL with dxil.dll and executes on both hardware (AMD Radeon(TM) Graphics RDNA2) and WARP, covering SGPRs, inline signed/unsigned integers, NULL, 32-bit literals, inline float 1.0 (242), and SCC preservation.
  • cargo clippy -p victory-shader --lib --tests --all-features --locked -- -D warnings & cargo xtask policy pass.

Refs #815

**@⁠fuzeofficlal** on GitHub · 2026-11-25 11:53 UTC · [original](https://github.com/Marvisak/VIctory/pull/2361) `fuzeofficlal:feat/shader-spack-b32-b16-815` → `main` · +124 −0 · 3 files · 1 commits · open ### Summary Lowers the three RDNA2 SOP2 scalar 16-bit half-word pack instructions in `Lower::sop` (`crates/victory-shader/src/emit/lower.rs`): - `s_pack_ll_b32_b16` (`0x32`): `(S0.u32 & 0xFFFF) | (S1.u32 << 16)` - `s_pack_lh_b32_b16` (`0x33`): `(S0.u32 & 0xFFFF) | (S1.u32 & 0xFFFF_0000)` - `s_pack_hh_b32_b16` (`0x34`): `(S0.u32 >> 16) | (S1.u32 & 0xFFFF_0000)` In the native compute pipeline measurements reported in #815 (`#issuecomment` world run breakdown), `s_pack_ll_b32_b16` (104 distinct programs) and `s_pack_hh_b32_b16` (48 distinct programs) account for 152 refused compute programs. ### ISA Semantics - **Decoding**: `gfx10/opcodes.rs` (`0x32..=0x34`) and `gfx10/fields.rs` (`salu_dwords`) already decode all three opcodes as 32-bit SOP2 instructions. - **No `SCC` write**: Per the AMD RDNA2 ISA Reference Guide (SOP2 `S_PACK_*_B32_B16`), none of the three variants reads or modifies `SCC`. `ir::writes_scc` already leaves `SCC` untouched (`write(Reg::Scc) == None`), and `Lower::sop` returns `None` for the `SCC` flag. - **32-bit scalar inline constants**: Both sources are `SSrc_b32` operands, so inline float constants (`240..=248`) expand to their 32-bit `f32` bit patterns via `src32` (`self.operand` -> `resource::inline`), e.g. `1.0` (`242`) = `0x3F80_0000` (`lo16 = 0x0000`, `hi16 = 0x3F80`). ### Verification - `ir::tests::scalar_pack_does_not_clobber_scc`: verifies IR SSA wiring leaves `SCC` live across `s_cmp_eq_u32 -> s_pack_{ll,lh,hh}_b32_b16 -> s_cselect_b32`. - `emit::valu_tests::scalar_pack_b16_halves_and_preserves_scc`: validates emitted DXIL with `dxil.dll` and executes on both hardware (`AMD Radeon(TM) Graphics` RDNA2) and `WARP`, covering SGPRs, inline signed/unsigned integers, `NULL`, 32-bit literals, inline float `1.0` (`242`), and `SCC` preservation. - `cargo clippy -p victory-shader --lib --tests --all-features --locked -- -D warnings` & `cargo xtask policy` pass. Refs #815
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:03:30 +00:00
Author
Owner

@⁠welisonzika14-jpg on GitHub · 2026-11-25 12:25 UTC · original

First run on NVIDIA hardware here, as far as I can see. RTX 5070 (Blackwell, driver 621.24), Ryzen 7 5700X, Windows 11, Rust 1.98.1 MSVC, no game files. Head 58727a2 merged onto main 940d32f, cargo test -p victory-gpu -p victory-shader --lib --no-fail-fast.

The PR's new test(s) pass on this card: emit::valu_tests::scalar_pack_b16_halves_and_preserves_scc, ir::tests::scalar_pack_does_not_clobber_scc. The rest is the same as main on this card: the 5 known NVIDIA failures from #1744 (2 view heap cap tests in victory-gpu, 3 in victory-shader), nothing new.

One run, unit tests only, title not run.

Written with AI help (Claude/Kiro); the numbers are from runs on my machine.

**@⁠welisonzika14-jpg** on GitHub · 2026-11-25 12:25 UTC · [original](https://github.com/Marvisak/VIctory/pull/2361#issuecomment-7162348867) First run on NVIDIA hardware here, as far as I can see. RTX 5070 (Blackwell, driver 621.24), Ryzen 7 5700X, Windows 11, Rust 1.98.1 MSVC, no game files. Head `58727a2` merged onto `main` `940d32f`, `cargo test -p victory-gpu -p victory-shader --lib --no-fail-fast`. The PR's new test(s) pass on this card: `emit::valu_tests::scalar_pack_b16_halves_and_preserves_scc`, `ir::tests::scalar_pack_does_not_clobber_scc`. The rest is the same as `main` on this card: the 5 known NVIDIA failures from #1744 (2 view heap cap tests in `victory-gpu`, 3 in `victory-shader`), nothing new. One run, unit tests only, title not run. Written with AI help (Claude/Kiro); the numbers are from runs on my machine.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 14:46 UTC · original · edited 2026-11-25 14:48 UTC

Automated triage for the maintainers.

Merge candidate. Adds s_pack_ll/lh/hh_b32_b16 to the SOP2 lowering in crates/victory-shader/src/emit/lower.rs; the opcodes were already decoded (gfx10/opcodes.rs 0x32-0x34) but not lowered. I checked the three formulas against the public RDNA2 ISA description of the instructions, and that ir::writes_scc (stem pack not in its list) already leaves SCC untouched, which the new IR test pins down; the GPU test covers SGPRs, inline integers and floats, literals and SCC preservation.

CI: check passing. A contributor also reports the new tests passing on an RTX 5070.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 14:46 UTC · [original](https://github.com/Marvisak/VIctory/pull/2361#issuecomment-7165795283) · edited 2026-11-25 14:48 UTC <!-- victory-triage v1 head=58727a25d00531f387036b407b599a2241e587c9 verdict=merge-candidate at=2026-11-25T14:46:20Z --> Automated triage for the maintainers. **Merge candidate.** Adds `s_pack_ll/lh/hh_b32_b16` to the SOP2 lowering in `crates/victory-shader/src/emit/lower.rs`; the opcodes were already decoded (`gfx10/opcodes.rs` 0x32-0x34) but not lowered. I checked the three formulas against the public RDNA2 ISA description of the instructions, and that `ir::writes_scc` (stem `pack` not in its list) already leaves SCC untouched, which the new IR test pins down; the GPU test covers SGPRs, inline integers and floats, literals and SCC preservation. CI: `check` passing. A contributor also reports the new tests passing on an RTX 5070. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠catminou4 on GitHub · 2026-11-25 12:35 UTC · original · approved these changes

Tested locally: merged into main 940d32f69b, cargo test -p victory-shader --locked on macOS arm64 — 145 passed, 0 failed, 2 ignored (Windows-gated hardware execution tests not run here). Approving — SOP2 s_pack_{ll,lh,hh}_b32_b16 lowered (#815).

**@⁠catminou4** on GitHub · 2026-11-25 12:35 UTC · [original](https://github.com/Marvisak/VIctory/pull/2361#pullrequestreview-6057694647) · **approved these changes** Tested locally: merged into main 940d32f69b, `cargo test -p victory-shader --locked` on macOS arm64 — 145 passed, 0 failed, 2 ignored (Windows-gated hardware execution tests not run here). Approving — SOP2 s_pack_{ll,lh,hh}_b32_b16 lowered (#815).
Author
Owner

@⁠Victorzinn704 on GitHub · 2026-11-26 18:08 UTC · original · reviewed

Independent graphics-stage check for this SOP2 lowering. I exercised s_pack_ll_b32_b16, s_pack_lh_b32_b16, and s_pack_hh_b32_b16 in three synthetic pixel shaders with runtime root constants. On main 63bcca43c6a0 the new test stops at Unsupported { what: "s_pack_ll_b32_b16", … }. With the shader changes from 58727a25d005 applied, all 12 RGBA pixels matched the RDNA2 ISA expectations on each of RTX 5060 Ti (616.92) and WARP. The SDK DXIL validator accepted the VS and all three PS modules.

This complements the existing compute and SCC tests by going through D3D12 graphics pipeline creation, drawing, and reading back the render target. The patch applies to the PR head. To verify it on Windows, run cargo test --locked -p victory-shader --lib scalar_pack -- --nocapture --test-threads=1.

Optional pixel shader regression patch

Save the diff as a patch file and use git apply on the PR branch.

diff --git a/crates/victory-shader/src/emit/synthetic_tests.rs b/crates/victory-shader/src/emit/synthetic_tests.rs
index e6cee0d..dd24e5c 100644
--- a/crates/victory-shader/src/emit/synthetic_tests.rs
+++ b/crates/victory-shader/src/emit/synthetic_tests.rs
@@ -856,13 +856,8 @@ fn ordered_pixel_sections_use_rasterizer_ordered_views() {
     assert_eq!(what, "a hardware SGPR input");
 }
 
-#[test]
-fn pops_wait_loop_exits_immediately_for_inactive_lanes() {
-    use super::container::SigElement;
-    use super::host::Draw;
-    use crate::native::{Usage, VsInput};
-
-    let pos_sig = |name: &str, kind: u8, interp: u8| SigElement {
+fn fixture_signature(name: &str, kind: u8, interp: u8) -> super::container::SigElement {
+    super::container::SigElement {
         name: name.into(),
         index: 0,
         kind,
@@ -873,48 +868,55 @@ fn pops_wait_loop_exits_immediately_for_inactive_lanes() {
         cols: 4,
         usage: 0xF,
         half: false,
-    };
-    let to_host = |native: &NativeProgram, inputs: Vec<SigElement>, outputs: Vec<SigElement>| {
-        let p = ir::build(&native.code, native.wave64, native.vgprs).expect("ir");
-        let st = structure::structure(&p).expect("structure");
-        let res = resource::track(&p, &native.layout, native.stage, Some(&st)).expect("resource");
-        let io = io::raise(&p, native).expect("io");
-        let l = lower::lower(&lower::Parts {
-            native,
-            p: &p,
-            st: &st,
-            io: &io,
-            res: &res,
-            inputs,
-            outputs,
-            prims: Vec::new(),
-            mesh_stride: 0,
-            view_marks: false,
-        })
-        .expect("lower");
-        if let Ok(mut v) =
-            validator::Validator::load(validator::Validator::default_path().as_deref())
-        {
-            let mut copy = l.dxil.clone();
-            v.validate(&mut copy).expect("DXIL validation failed");
-        }
-        HostShader {
-            stage: native.stage,
-            dxil: l.dxil,
-            user_data: l.user_data,
-            samplers: l.samplers,
-            static_samplers: Vec::new(),
-            root_cbvs: l.root_cbvs,
-            root_srvs: l.root_srvs,
-            root_uavs: l.root_uavs,
-            memory: l.memory,
-            memory_writes: l.memory_writes,
-            view_addresses: l.view_addresses,
-            heap: l.heap,
-            heap_writes: l.heap_writes,
-            view_marks: false,
-        }
-    };
+    }
+}
+
+fn lower_graphics_fixture(
+    native: &NativeProgram,
+    inputs: Vec<super::container::SigElement>,
+    outputs: Vec<super::container::SigElement>,
+) -> HostShader {
+    let p = ir::build(&native.code, native.wave64, native.vgprs).expect("ir");
+    let st = structure::structure(&p).expect("structure");
+    let res = resource::track(&p, &native.layout, native.stage, Some(&st)).expect("resource");
+    let io = io::raise(&p, native).expect("io");
+    let l = lower::lower(&lower::Parts {
+        native,
+        p: &p,
+        st: &st,
+        io: &io,
+        res: &res,
+        inputs,
+        outputs,
+        prims: Vec::new(),
+        mesh_stride: 0,
+        view_marks: false,
+    })
+    .expect("lower");
+    if let Ok(mut v) = validator::Validator::load(validator::Validator::default_path().as_deref()) {
+        let mut copy = l.dxil.clone();
+        v.validate(&mut copy).expect("DXIL validation failed");
+    }
+    HostShader {
+        stage: native.stage,
+        dxil: l.dxil,
+        user_data: l.user_data,
+        samplers: l.samplers,
+        static_samplers: Vec::new(),
+        root_cbvs: l.root_cbvs,
+        root_srvs: l.root_srvs,
+        root_uavs: l.root_uavs,
+        memory: l.memory,
+        memory_writes: l.memory_writes,
+        view_addresses: l.view_addresses,
+        heap: l.heap,
+        heap_writes: l.heap_writes,
+        view_marks: false,
+    }
+}
+
+fn fullscreen_fixture_vs() -> HostShader {
+    use crate::native::{Usage, VsInput};
 
     // Pass-through full-screen vertex shader (attributes in v4..v7; v0..v3 hold hardware ids).
     let vs_code: [u32; 3] = [
@@ -939,11 +941,18 @@ fn pops_wait_loop_exits_immediately_for_inactive_lanes() {
         },
         code: vs_code.iter().flat_map(|w| w.to_le_bytes()).collect(),
     };
-    let vs = to_host(
+    lower_graphics_fixture(
         &vs_native,
-        vec![pos_sig("POSITION", 0, 0)],
-        vec![pos_sig("SV_Position", 3, 4)],
-    );
+        vec![fixture_signature("POSITION", 0, 0)],
+        vec![fixture_signature("SV_Position", 3, 4)],
+    )
+}
+
+#[test]
+fn pops_wait_loop_exits_immediately_for_inactive_lanes() {
+    use super::host::Draw;
+
+    let vs = fullscreen_fixture_vs();
 
     // Pixel shader with narrowed EXEC before the title's wrap-around POPS
     // wait loop: lanes with SV_Position.x >= 2.0 have EXEC cleared at
@@ -997,10 +1006,10 @@ fn pops_wait_loop_exits_immediately_for_inactive_lanes() {
         },
         code: ps_bytes,
     };
-    let ps = to_host(
+    let ps = lower_graphics_fixture(
         &ps_native,
-        vec![pos_sig("SV_Position", 3, 4)],
-        vec![pos_sig("SV_Target", 16, 0)],
+        vec![fixture_signature("SV_Position", 3, 4)],
+        vec![fixture_signature("SV_Target", 16, 0)],
     );
 
     let host = Host::new(true).expect("WARP host");
@@ -1027,3 +1036,97 @@ fn pops_wait_loop_exits_immediately_for_inactive_lanes() {
     // never spinning to LOOP_LIMIT (1 << 20).
     assert_eq!(pixels, vec![[0.0; 4], [0.0; 4], [1.0; 4], [1.0; 4]]);
 }
+
+#[test]
+fn scalar_pack_b16_pixel_channels_match_rdna2() {
+    use super::host::Draw;
+
+    let vs = fullscreen_fixture_vs();
+    let variants = [
+        (0x32u32, [18.0, 52.0, 38.0, 171.0]),   // low, low
+        (0x33u32, [18.0, 52.0, 93.0, 241.0]),   // low, high
+        (0x34u32, [145.0, 200.0, 93.0, 241.0]), // high, high
+    ];
+    let shaders = variants.map(|(op, expected)| {
+        // Pack s0 and s1 into s2, then export its four unsigned bytes as RGBA.
+        let code = [
+            0x8002_0100 | (op << 23), // s_pack_*_b32_b16 s2, s0, s1
+            0x7E00_2202,              // v_cvt_f32_ubyte0 v0, s2
+            0x7E02_2402,              // v_cvt_f32_ubyte1 v1, s2
+            0x7E04_2602,              // v_cvt_f32_ubyte2 v2, s2
+            0x7E06_2802,              // v_cvt_f32_ubyte3 v3, s2
+            0xF800_180F,
+            0x0302_0100, // exp mrt0, v0, v1, v2, v3 done vm
+            0xBF81_0000, // s_endpgm
+        ];
+        let native = NativeProgram {
+            stage: HwStage::Ps,
+            wave64: true,
+            vgprs: 8,
+            layout: vec![RootParam {
+                root: RootType::Constants,
+                table_offset_dwords: 0,
+                sgprs: 2,
+                base_register: 0,
+                user_data: 0,
+                slot: 0,
+            }],
+            used: Vec::new(),
+            io: StageIo::Ps {
+                inputs: Vec::new(),
+                input_addr: 0,
+                db_shader_control: 0,
+                patches: Vec::new(),
+            },
+            code: code.into_iter().flat_map(u32::to_le_bytes).collect(),
+        };
+        let ps = lower_graphics_fixture(
+            &native,
+            Vec::new(),
+            vec![fixture_signature("SV_Target", 16, 0)],
+        );
+        (op, expected, ps)
+    });
+
+    let _one = super::valu_tests::ONE_AT_A_TIME
+        .lock()
+        .unwrap_or_else(|e| e.into_inner());
+    let warp = Host::new(true).expect("WARP host");
+    let hardware = if std::env::var("VICTORY_WARP").as_deref() == Ok("1") {
+        None
+    } else {
+        Host::new(false)
+            .map_err(|e| eprintln!("hardware path skipped: {e}"))
+            .ok()
+    };
+    let hosts = [("WARP", warp)]
+        .into_iter()
+        .chain(hardware.map(|host| ("hardware", host)));
+    for (label, host) in hosts {
+        for (op, expected, ps) in &shaders {
+            let (root, pso) = host.pipeline(&vs, ps).expect("graphics pipeline");
+            let pixels = host
+                .draw(
+                    &root,
+                    &pso,
+                    &Draw {
+                        roots: vec![
+                            (0, Root::Constants(vec![0])),
+                            (1, Root::Constants(vec![0xC891_3412, 0xF15D_AB26])),
+                        ],
+                        textures: &[],
+                        samplers: &[],
+                        vertices: &[
+                            -1.0, -1.0, 0.0, 1.0, -1.0, 3.0, 0.0, 1.0, 3.0, -1.0, 0.0, 1.0,
+                        ],
+                        stride: 16,
+                        size: (2, 2),
+                        mesh_groups: 0,
+                    },
+                )
+                .unwrap_or_else(|e| panic!("{label}, SOP2 0x{op:02x}: {e}"));
+            assert_eq!(pixels, vec![*expected; 4], "{label}, SOP2 0x{op:02x}");
+        }
+        eprintln!("{label}: 12 rendered RGBA pixels match");
+    }
+}

AI-assisted. The results are from local runs with synthetic shaders.

**@⁠Victorzinn704** on GitHub · 2026-11-26 18:08 UTC · [original](https://github.com/Marvisak/VIctory/pull/2361#pullrequestreview-6078788041) · **reviewed** Independent graphics-stage check for this SOP2 lowering. I exercised `s_pack_ll_b32_b16`, `s_pack_lh_b32_b16`, and `s_pack_hh_b32_b16` in three synthetic pixel shaders with runtime root constants. On main `63bcca43c6a0` the new test stops at `Unsupported { what: "s_pack_ll_b32_b16", … }`. With the shader changes from `58727a25d005` applied, all 12 RGBA pixels matched the RDNA2 ISA expectations on each of RTX 5060 Ti (616.92) and WARP. The SDK DXIL validator accepted the VS and all three PS modules. This complements the existing compute and SCC tests by going through D3D12 graphics pipeline creation, drawing, and reading back the render target. The patch applies to the PR head. To verify it on Windows, run `cargo test --locked -p victory-shader --lib scalar_pack -- --nocapture --test-threads=1`. <details> <summary>Optional pixel shader regression patch</summary> Save the diff as a patch file and use `git apply` on the PR branch. ```diff diff --git a/crates/victory-shader/src/emit/synthetic_tests.rs b/crates/victory-shader/src/emit/synthetic_tests.rs index e6cee0d..dd24e5c 100644 --- a/crates/victory-shader/src/emit/synthetic_tests.rs +++ b/crates/victory-shader/src/emit/synthetic_tests.rs @@ -856,13 +856,8 @@ fn ordered_pixel_sections_use_rasterizer_ordered_views() { assert_eq!(what, "a hardware SGPR input"); } -#[test] -fn pops_wait_loop_exits_immediately_for_inactive_lanes() { - use super::container::SigElement; - use super::host::Draw; - use crate::native::{Usage, VsInput}; - - let pos_sig = |name: &str, kind: u8, interp: u8| SigElement { +fn fixture_signature(name: &str, kind: u8, interp: u8) -> super::container::SigElement { + super::container::SigElement { name: name.into(), index: 0, kind, @@ -873,48 +868,55 @@ fn pops_wait_loop_exits_immediately_for_inactive_lanes() { cols: 4, usage: 0xF, half: false, - }; - let to_host = |native: &NativeProgram, inputs: Vec<SigElement>, outputs: Vec<SigElement>| { - let p = ir::build(&native.code, native.wave64, native.vgprs).expect("ir"); - let st = structure::structure(&p).expect("structure"); - let res = resource::track(&p, &native.layout, native.stage, Some(&st)).expect("resource"); - let io = io::raise(&p, native).expect("io"); - let l = lower::lower(&lower::Parts { - native, - p: &p, - st: &st, - io: &io, - res: &res, - inputs, - outputs, - prims: Vec::new(), - mesh_stride: 0, - view_marks: false, - }) - .expect("lower"); - if let Ok(mut v) = - validator::Validator::load(validator::Validator::default_path().as_deref()) - { - let mut copy = l.dxil.clone(); - v.validate(&mut copy).expect("DXIL validation failed"); - } - HostShader { - stage: native.stage, - dxil: l.dxil, - user_data: l.user_data, - samplers: l.samplers, - static_samplers: Vec::new(), - root_cbvs: l.root_cbvs, - root_srvs: l.root_srvs, - root_uavs: l.root_uavs, - memory: l.memory, - memory_writes: l.memory_writes, - view_addresses: l.view_addresses, - heap: l.heap, - heap_writes: l.heap_writes, - view_marks: false, - } - }; + } +} + +fn lower_graphics_fixture( + native: &NativeProgram, + inputs: Vec<super::container::SigElement>, + outputs: Vec<super::container::SigElement>, +) -> HostShader { + let p = ir::build(&native.code, native.wave64, native.vgprs).expect("ir"); + let st = structure::structure(&p).expect("structure"); + let res = resource::track(&p, &native.layout, native.stage, Some(&st)).expect("resource"); + let io = io::raise(&p, native).expect("io"); + let l = lower::lower(&lower::Parts { + native, + p: &p, + st: &st, + io: &io, + res: &res, + inputs, + outputs, + prims: Vec::new(), + mesh_stride: 0, + view_marks: false, + }) + .expect("lower"); + if let Ok(mut v) = validator::Validator::load(validator::Validator::default_path().as_deref()) { + let mut copy = l.dxil.clone(); + v.validate(&mut copy).expect("DXIL validation failed"); + } + HostShader { + stage: native.stage, + dxil: l.dxil, + user_data: l.user_data, + samplers: l.samplers, + static_samplers: Vec::new(), + root_cbvs: l.root_cbvs, + root_srvs: l.root_srvs, + root_uavs: l.root_uavs, + memory: l.memory, + memory_writes: l.memory_writes, + view_addresses: l.view_addresses, + heap: l.heap, + heap_writes: l.heap_writes, + view_marks: false, + } +} + +fn fullscreen_fixture_vs() -> HostShader { + use crate::native::{Usage, VsInput}; // Pass-through full-screen vertex shader (attributes in v4..v7; v0..v3 hold hardware ids). let vs_code: [u32; 3] = [ @@ -939,11 +941,18 @@ fn pops_wait_loop_exits_immediately_for_inactive_lanes() { }, code: vs_code.iter().flat_map(|w| w.to_le_bytes()).collect(), }; - let vs = to_host( + lower_graphics_fixture( &vs_native, - vec![pos_sig("POSITION", 0, 0)], - vec![pos_sig("SV_Position", 3, 4)], - ); + vec![fixture_signature("POSITION", 0, 0)], + vec![fixture_signature("SV_Position", 3, 4)], + ) +} + +#[test] +fn pops_wait_loop_exits_immediately_for_inactive_lanes() { + use super::host::Draw; + + let vs = fullscreen_fixture_vs(); // Pixel shader with narrowed EXEC before the title's wrap-around POPS // wait loop: lanes with SV_Position.x >= 2.0 have EXEC cleared at @@ -997,10 +1006,10 @@ fn pops_wait_loop_exits_immediately_for_inactive_lanes() { }, code: ps_bytes, }; - let ps = to_host( + let ps = lower_graphics_fixture( &ps_native, - vec![pos_sig("SV_Position", 3, 4)], - vec![pos_sig("SV_Target", 16, 0)], + vec![fixture_signature("SV_Position", 3, 4)], + vec![fixture_signature("SV_Target", 16, 0)], ); let host = Host::new(true).expect("WARP host"); @@ -1027,3 +1036,97 @@ fn pops_wait_loop_exits_immediately_for_inactive_lanes() { // never spinning to LOOP_LIMIT (1 << 20). assert_eq!(pixels, vec![[0.0; 4], [0.0; 4], [1.0; 4], [1.0; 4]]); } + +#[test] +fn scalar_pack_b16_pixel_channels_match_rdna2() { + use super::host::Draw; + + let vs = fullscreen_fixture_vs(); + let variants = [ + (0x32u32, [18.0, 52.0, 38.0, 171.0]), // low, low + (0x33u32, [18.0, 52.0, 93.0, 241.0]), // low, high + (0x34u32, [145.0, 200.0, 93.0, 241.0]), // high, high + ]; + let shaders = variants.map(|(op, expected)| { + // Pack s0 and s1 into s2, then export its four unsigned bytes as RGBA. + let code = [ + 0x8002_0100 | (op << 23), // s_pack_*_b32_b16 s2, s0, s1 + 0x7E00_2202, // v_cvt_f32_ubyte0 v0, s2 + 0x7E02_2402, // v_cvt_f32_ubyte1 v1, s2 + 0x7E04_2602, // v_cvt_f32_ubyte2 v2, s2 + 0x7E06_2802, // v_cvt_f32_ubyte3 v3, s2 + 0xF800_180F, + 0x0302_0100, // exp mrt0, v0, v1, v2, v3 done vm + 0xBF81_0000, // s_endpgm + ]; + let native = NativeProgram { + stage: HwStage::Ps, + wave64: true, + vgprs: 8, + layout: vec![RootParam { + root: RootType::Constants, + table_offset_dwords: 0, + sgprs: 2, + base_register: 0, + user_data: 0, + slot: 0, + }], + used: Vec::new(), + io: StageIo::Ps { + inputs: Vec::new(), + input_addr: 0, + db_shader_control: 0, + patches: Vec::new(), + }, + code: code.into_iter().flat_map(u32::to_le_bytes).collect(), + }; + let ps = lower_graphics_fixture( + &native, + Vec::new(), + vec![fixture_signature("SV_Target", 16, 0)], + ); + (op, expected, ps) + }); + + let _one = super::valu_tests::ONE_AT_A_TIME + .lock() + .unwrap_or_else(|e| e.into_inner()); + let warp = Host::new(true).expect("WARP host"); + let hardware = if std::env::var("VICTORY_WARP").as_deref() == Ok("1") { + None + } else { + Host::new(false) + .map_err(|e| eprintln!("hardware path skipped: {e}")) + .ok() + }; + let hosts = [("WARP", warp)] + .into_iter() + .chain(hardware.map(|host| ("hardware", host))); + for (label, host) in hosts { + for (op, expected, ps) in &shaders { + let (root, pso) = host.pipeline(&vs, ps).expect("graphics pipeline"); + let pixels = host + .draw( + &root, + &pso, + &Draw { + roots: vec![ + (0, Root::Constants(vec![0])), + (1, Root::Constants(vec![0xC891_3412, 0xF15D_AB26])), + ], + textures: &[], + samplers: &[], + vertices: &[ + -1.0, -1.0, 0.0, 1.0, -1.0, 3.0, 0.0, 1.0, 3.0, -1.0, 0.0, 1.0, + ], + stride: 16, + size: (2, 2), + mesh_groups: 0, + }, + ) + .unwrap_or_else(|e| panic!("{label}, SOP2 0x{op:02x}: {e}")); + assert_eq!(pixels, vec![*expected; 4], "{label}, SOP2 0x{op:02x}"); + } + eprintln!("{label}: 12 rendered RGBA pixels match"); + } +} ``` </details> AI-assisted. The results are from local runs with synthetic shaders.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2361/head:github-bot/gh-2361'
git switch 'github-bot/gh-2361'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2361'
git switch 'github-bot/gh-2361'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2361'
git switch 'github-bot/gh-2361'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2361'
git switch 'main'
git merge --squash 'github-bot/gh-2361'
git switch 'main'
git merge --ff-only 'github-bot/gh-2361'
git switch 'main'
git merge 'github-bot/gh-2361'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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!2361
No description provided.