Shaders: mask ops in a pixel/vertex program never read the high ballot half, so a 64-lane host wave loses lanes 32-63 #125

Open
opened 2026-11-26 03:51:11 +00:00 by github-bot · 5 comments
Owner

@⁠Luislariosss on GitHub · 2026-11-24 00:42 UTC · original

What I see in the code

For a pixel or vertex program, Lower sets mask_data = MaskData::Host and leaves s.wave_size at None
(crates/victory-shader/src/emit/lower.rs:472-476). The doc on that variant (lower.rs:226-231) says ballots are
taken "over the host's wave, whatever its size" and that only uses which mean the same on any wave are allowed.

mask_dword (lower.rs:1153-1189) does waveActiveBallot and returns if high { y } else { x }. With a console
wave32 program nothing goes into st.highs, so every mask read returns the low dword, x.

The mask uses then go through src32, which also returns x only:

  • s_bcnt1_i32_b32 / s_ff1_i32_b32 (lower.rs:2549-2557): one unaryBits.i32 over x.
  • v_mbcnt_lo_u32_b32 (lower.rs:4879-4927): reads x only, and clamps to 32 for lane >= 32.
  • s_cmp_eq_u32 / s_cmp_lg_u32 (lower.rs:2322-2353): compares the low halves only.

The 64-bit forms right above them (s_bcnt1_i32_b64, s_ff1_i32_b64, lower.rs:2363-2397) already work on a pair,
so they are not affected.

Why it looks wrong on AMD

Nothing forces a wave size outside compute, so the host picks one. On an AMD RX 9060 XT (RDNA4, Windows), a vertex
shader is not necessarily wave32: if the host runs the shader at 64 lanes, waveActiveBallot returns a real 64-bit
mask, and reading only x drops lanes 32-63 from every count, from v_mbcnt, and from mask equality. AMD is also
the vendor where pixel and vertex stages default to different wave sizes, so the same shader can hit both cases.

I have not run the title (I do not have the game), so I cannot say how often the emitted code takes this path in
practice. I can only show that the lowering does not use the high half at all.

A test that fails on main

A synthetic wave32 pixel program with MaskData::Host and s.wave_size == None, built through ir::build(&code, false, 8) and the usual pipeline, using exec_lo as the mask:

0xBE80_0F7E                  // s_bcnt1_i32_b32 s0, exec_lo
0xBE81_137E                  // s_ff1_i32_b32   s1, exec_lo
0xD765_0002, 0x0001_007E     // v_mbcnt_lo_u32_b32 v2, exec_lo, 0
0x7E00_0200                  // v_mov_b32 v0, s0
0x7E02_0201                  // v_mov_b32 v1, s1
0xF800_180F, 0x0302_0100     // exp mrt0, v0, v1, v2, v3 done vm
0xBF81_0000                  // s_endpgm

Counting how many times the high half of the cached ballot pair is referenced, the assertion fails on main:

expected high ballot half to be used by s_bcnt1_i32_b32, s_ff1_i32_b32, and v_mbcnt_lo_u32_b32 (>= 3 uses), got 0

The question

Is the intended semantics for MaskData::Host the host wave (so a 64-lane host counts all 64 active lanes and the
high half must be used), or is a mask from a console wave32 program deliberately capped at 32 bits whatever the host
wave is?

If it is the host wave, the fix is four sites and I can send it with the test above: s_bcnt1_i32_b32 and
s_ff1_i32_b32 delegate to the _b64 logic when the operand is a tracked mask, s_cmp_eq/lg_u32 compare
(x, y) pairs, and v_mbcnt_lo_u32_b32 counts over both halves for a mask (and lowers -1 straight to
waveGetLaneIndex()), which is exact on any wave size. If it is the cap, then the code is right as it stands and I
will drop it.

I would rather ask than send a change that touches the mask paths of every translated pixel and vertex shader on an
assumption.

AI-assisted.

**@⁠Luislariosss** on GitHub · 2026-11-24 00:42 UTC · [original](https://github.com/Marvisak/VIctory/issues/125) ## What I see in the code For a pixel or vertex program, `Lower` sets `mask_data = MaskData::Host` and leaves `s.wave_size` at `None` (`crates/victory-shader/src/emit/lower.rs:472-476`). The doc on that variant (`lower.rs:226-231`) says ballots are taken "over the host's wave, whatever its size" and that only uses which mean the same on any wave are allowed. `mask_dword` (`lower.rs:1153-1189`) does `waveActiveBallot` and returns `if high { y } else { x }`. With a console wave32 program nothing goes into `st.highs`, so every mask read returns the low dword, `x`. The mask uses then go through `src32`, which also returns `x` only: * `s_bcnt1_i32_b32` / `s_ff1_i32_b32` (`lower.rs:2549-2557`): one `unaryBits.i32` over `x`. * `v_mbcnt_lo_u32_b32` (`lower.rs:4879-4927`): reads `x` only, and clamps to 32 for `lane >= 32`. * `s_cmp_eq_u32` / `s_cmp_lg_u32` (`lower.rs:2322-2353`): compares the low halves only. The 64-bit forms right above them (`s_bcnt1_i32_b64`, `s_ff1_i32_b64`, `lower.rs:2363-2397`) already work on a pair, so they are not affected. ## Why it looks wrong on AMD Nothing forces a wave size outside compute, so the host picks one. On an AMD RX 9060 XT (RDNA4, Windows), a vertex shader is not necessarily wave32: if the host runs the shader at 64 lanes, `waveActiveBallot` returns a real 64-bit mask, and reading only `x` drops lanes 32-63 from every count, from `v_mbcnt`, and from mask equality. AMD is also the vendor where pixel and vertex stages default to different wave sizes, so the same shader can hit both cases. I have not run the title (I do not have the game), so I cannot say how often the emitted code takes this path in practice. I can only show that the lowering does not use the high half at all. ## A test that fails on main A synthetic wave32 pixel program with `MaskData::Host` and `s.wave_size == None`, built through `ir::build(&code, false, 8)` and the usual pipeline, using `exec_lo` as the mask: ``` 0xBE80_0F7E // s_bcnt1_i32_b32 s0, exec_lo 0xBE81_137E // s_ff1_i32_b32 s1, exec_lo 0xD765_0002, 0x0001_007E // v_mbcnt_lo_u32_b32 v2, exec_lo, 0 0x7E00_0200 // v_mov_b32 v0, s0 0x7E02_0201 // v_mov_b32 v1, s1 0xF800_180F, 0x0302_0100 // exp mrt0, v0, v1, v2, v3 done vm 0xBF81_0000 // s_endpgm ``` Counting how many times the high half of the cached ballot pair is referenced, the assertion fails on `main`: ``` expected high ballot half to be used by s_bcnt1_i32_b32, s_ff1_i32_b32, and v_mbcnt_lo_u32_b32 (>= 3 uses), got 0 ``` ## The question Is the intended semantics for `MaskData::Host` the *host wave* (so a 64-lane host counts all 64 active lanes and the high half must be used), or is a mask from a console wave32 program deliberately capped at 32 bits whatever the host wave is? If it is the host wave, the fix is four sites and I can send it with the test above: `s_bcnt1_i32_b32` and `s_ff1_i32_b32` delegate to the `_b64` logic when the operand is a tracked mask, `s_cmp_eq/lg_u32` compare `(x, y)` pairs, and `v_mbcnt_lo_u32_b32` counts over both halves for a mask (and lowers `-1` straight to `waveGetLaneIndex()`), which is exact on any wave size. If it is the cap, then the code is right as it stands and I will drop it. I would rather ask than send a change that touches the mask paths of every translated pixel and vertex shader on an assumption. AI-assisted.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:51:11 +00:00
Author
Owner

@⁠Luislariosss on GitHub · 2026-11-24 00:42 UTC · original

The test-only reproduction is on the fork: branch verify/wave32-mask at https://github.com/Luislariosss/VIctory/tree/verify/wave32-mask (commit 7c5abba, two files, #[cfg(test)] only, no production change).

cargo test -p victory-shader host_wave32 on that branch:

thread 'emit::lower::tests::host_wave32_mask_ops_use_both_ballot_halves' panicked at crates\victory-shader\src\emit\lower.rs:6678:9:
expected high ballot half to be used by s_bcnt1_i32_b32, s_ff1_i32_b32, and v_mbcnt_lo_u32_b32 (>= 3 uses), got 0
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 61 filtered out

It adds Module::uses_of under #[cfg(test)] so the assertion can count operands, and builds the wave32 pixel program from hand-written GFX10 words. The rest of the crate is untouched: cargo test -p victory-shader -- --skip host_wave32 still passes.

**@⁠Luislariosss** on GitHub · 2026-11-24 00:42 UTC · [original](https://github.com/Marvisak/VIctory/issues/125#issuecomment-7118353887) The test-only reproduction is on the fork: branch `verify/wave32-mask` at https://github.com/Luislariosss/VIctory/tree/verify/wave32-mask (commit `7c5abba`, two files, `#[cfg(test)]` only, no production change). `cargo test -p victory-shader host_wave32` on that branch: ``` thread 'emit::lower::tests::host_wave32_mask_ops_use_both_ballot_halves' panicked at crates\victory-shader\src\emit\lower.rs:6678:9: expected high ballot half to be used by s_bcnt1_i32_b32, s_ff1_i32_b32, and v_mbcnt_lo_u32_b32 (>= 3 uses), got 0 test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 61 filtered out ``` It adds `Module::uses_of` under `#[cfg(test)]` so the assertion can count operands, and builds the wave32 pixel program from hand-written GFX10 words. The rest of the crate is untouched: `cargo test -p victory-shader -- --skip host_wave32` still passes.
Author
Owner

@⁠Luislariosss on GitHub · 2026-11-24 00:47 UTC · original

Rebased onto main 9aef3d9c0 (27 commits later) and re-run: the reproduction still fails, at lower.rs:6682 now.

thread 'emit::lower::tests::host_wave32_mask_ops_use_both_ballot_halves' panicked:
expected high ballot half to be used by s_bcnt1_i32_b32, s_ff1_i32_b32, and v_mbcnt_lo_u32_b32 (>= 3 uses), got 0
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 69 filtered out

Branch verify/wave32-mask at 7004dfe3b, still test-only, still 0 commits behind main.

One thing worth knowing before this is fixed: #54 touches crates/victory-shader/src/emit/lower.rs too (+990/-21) and adds emit/wave_tests.rs, so whichever lands second will need a rebase. #54 is about forcing WaveSize(32) for small compute groups, which does not change the pixel/vertex path this report is about.

**@⁠Luislariosss** on GitHub · 2026-11-24 00:47 UTC · [original](https://github.com/Marvisak/VIctory/issues/125#issuecomment-7118436301) Rebased onto `main` `9aef3d9c0` (27 commits later) and re-run: the reproduction still fails, at `lower.rs:6682` now. ``` thread 'emit::lower::tests::host_wave32_mask_ops_use_both_ballot_halves' panicked: expected high ballot half to be used by s_bcnt1_i32_b32, s_ff1_i32_b32, and v_mbcnt_lo_u32_b32 (>= 3 uses), got 0 test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 69 filtered out ``` Branch `verify/wave32-mask` at `7004dfe3b`, still test-only, still 0 commits behind main. One thing worth knowing before this is fixed: #54 touches `crates/victory-shader/src/emit/lower.rs` too (+990/-21) and adds `emit/wave_tests.rs`, so whichever lands second will need a rebase. #54 is about forcing `WaveSize(32)` for small *compute* groups, which does not change the pixel/vertex path this report is about.
Author
Owner

@⁠TheHoracio on GitHub · 2026-11-24 00:59 UTC · original

Measured on AMD RDNA3: on this GPU the host does run plain vertex and pixel shaders at 64 lanes, so the path in this report is taken in practice. This answers the "how often in practice" part; it does not settle the semantics question.

Environment: RX 7800 XT (driver 32.0.32015.7029), Windows 11 Pro 10.0.26300, DXC 1.9.2602.17, SM 6.6, no WaveSize attribute, default PSO flags.

Probe: a full-screen triangle drawn with hand-written HLSL (not VIctory output, no game data). The VS passes WaveGetLaneCount() and WaveActiveCountBits(true) to the PS as nointerpolation values, and the PS writes its own two values next to them. I ran two pixel shaders: a trivial one and one with a 64-iteration ALU loop. Targets were 16×16, 64×64 and 256×256.

Pixel shader Target sizes WaveGetLaneCount() in PS / VS Most active lanes in one PS wave
trivial 16², 64², 256² 64 / 64 for every pixel 64
64-iteration loop 16², 64², 256² 64 / 64 for every pixel 64

A PS wave here had all 64 lanes active, so a ballot taken over the host wave has real bits in its high dword. Reading only x (s_bcnt1_i32_b32, s_ff1_i32_b32, v_mbcnt_lo_u32_b32, s_cmp_eq/lg_u32 as listed above) drops lanes 32-63 for a console wave32 program on this GPU. The VS draw had 3 vertices, so it shows only the wave size (64), not a full wave.

Not tested: VIctory's own translated shaders on the GPU (no harness for that here), RDNA2 and RDNA4, and whether the driver ever picks 32 lanes for VS/PS under other conditions, such as larger PS input counts or other PSO states.

AI use: Claude Code (Claude Opus 5.5) wrote the probe, ran it and drafted this comment; the numbers come from a real run on the GPU above.

**@⁠TheHoracio** on GitHub · 2026-11-24 00:59 UTC · [original](https://github.com/Marvisak/VIctory/issues/125#issuecomment-7118635766) Measured on AMD RDNA3: on this GPU the host does run plain vertex and pixel shaders at **64 lanes**, so the path in this report is taken in practice. This answers the "how often in practice" part; it does not settle the semantics question. **Environment:** RX 7800 XT (driver 32.0.32015.7029), Windows 11 Pro 10.0.26300, DXC 1.9.2602.17, SM 6.6, no `WaveSize` attribute, default PSO flags. **Probe:** a full-screen triangle drawn with hand-written HLSL (not VIctory output, no game data). The VS passes `WaveGetLaneCount()` and `WaveActiveCountBits(true)` to the PS as `nointerpolation` values, and the PS writes its own two values next to them. I ran two pixel shaders: a trivial one and one with a 64-iteration ALU loop. Targets were 16×16, 64×64 and 256×256. | Pixel shader | Target sizes | `WaveGetLaneCount()` in PS / VS | Most active lanes in one PS wave | |---|---|---|---| | trivial | 16², 64², 256² | 64 / 64 for every pixel | 64 | | 64-iteration loop | 16², 64², 256² | 64 / 64 for every pixel | 64 | A PS wave here had all 64 lanes active, so a ballot taken over the host wave has real bits in its high dword. Reading only `x` (`s_bcnt1_i32_b32`, `s_ff1_i32_b32`, `v_mbcnt_lo_u32_b32`, `s_cmp_eq/lg_u32` as listed above) drops lanes 32-63 for a console wave32 program on this GPU. The VS draw had 3 vertices, so it shows only the wave size (64), not a full wave. **Not tested:** VIctory's own translated shaders on the GPU (no harness for that here), RDNA2 and RDNA4, and whether the driver ever picks 32 lanes for VS/PS under other conditions, such as larger PS input counts or other PSO states. AI use: Claude Code (Claude Opus 5.5) wrote the probe, ran it and drafted this comment; the numbers come from a real run on the GPU above.
Author
Owner

@⁠TheHoracio on GitHub · 2026-11-24 01:19 UTC · original

A GPU test for this, run on the RX 7800 XT (RDNA3, driver 32.0.32015.7029, Windows 11 26300, Rust 1.98.1 from rust-toolchain.toml, debug). It draws a synthetic console wave32 pixel program (hand-written GFX10 words, no game data) through lower::lower and Host::draw, with a full-screen triangle from a PC-compiled vs_6_6. It checks two things in every pixel:

  • v_mbcnt_lo_u32_b32(exec_lo, 0) < s_bcnt1_i32_b32(exec_lo). This must hold on any host wave size.
  • v_mbcnt_lo_u32_b32(-1, 0) reaches the widest wave's last lane, so lanes past 31 do not share an index.

Results, with the test appended to each tree:

Tree Widest pixel wave seen Result
main d2a4bae 32 active lanes (high half lost), lane indices up to 32 fails: pixel 256: v_mbcnt_lo(exec) = 32 is not below s_bcnt1(exec) = 32 (lane 32 …)
#145 head ecc4eb6 64 active lanes, lane indices up to 63 passes
#147 head 35caba4 64 active lanes, lane indices up to 32 fails the second check: the exec-mask counts are right, but v_mbcnt_lo(-1) still clamps to 32 for lanes 32-63

So on this GPU, #145 fixes both checks, while #147 fixes the mask counts but not v_mbcnt_lo of -1. Whether lanes past 31 should get their own index is the semantics question asked above. The test makes that choice visible either way.

On a host that runs pixel shaders 32 lanes wide, both checks hold trivially. The test skips without a hardware SM 6.6 device or a PC dxc.exe (VICTORY_PC_DXC, else next to dxil.dll).

The test (appended to crates/victory-shader/src/emit/valu_tests.rs)
/// A console wave32 pixel program's lane masks on the host's wave, whatever
/// its size (#125): `v_mbcnt_lo_u32_b32` of EXEC must stay below
/// `s_bcnt1_i32_b32` of EXEC in every lane, and `v_mbcnt_lo_u32_b32` of -1 is
/// the lane's index in the host wave. A host that runs pixel shaders 64 lanes
/// wide (AMD RDNA) loses lanes 32-63 when only the low ballot dword is read.
#[test]
fn pixel_lane_masks_count_every_lane_of_the_host_wave() {
    use super::container::SigElement;
    use super::host::Draw;

    let pc_dxc = match std::env::var_os("VICTORY_PC_DXC") {
        Some(p) => Some(std::path::PathBuf::from(p)),
        None => validator::Validator::default_path().map(|p| p.with_file_name("dxc.exe")),
    };
    let Some(pc_dxc) = pc_dxc.filter(|p| p.exists()) else {
        eprintln!("no PC dxc.exe for the full-screen vertex shader; skipped");
        return;
    };
    let Ok(host) = Host::new(false) else {
        eprintln!("no SM 6.6 hardware device; skipped");
        return;
    };

    // A full-screen triangle from the vertex index (PC HLSL; outside the repo).
    let dir = std::env::temp_dir().join(format!("victory-lane-masks-{}", std::process::id()));
    std::fs::create_dir_all(&dir).unwrap();
    let src = dir.join("vs.hlsl");
    let bin = dir.join("vs.bin");
    std::fs::write(
        &src,
        "float4 vs(uint id : SV_VertexID) : SV_Position {\n\
         float2 uv = float2((id << 1) & 2, id & 2);\n\
         return float4(uv * float2(2, -2) + float2(-1, 1), 0.5, 1);\n}\n",
    )
    .unwrap();
    let out = std::process::Command::new(&pc_dxc)
        .args(["-T", "vs_6_6", "-E", "vs", "-Fo"])
        .arg(&bin)
        .arg(&src)
        .output()
        .unwrap();
    assert!(out.status.success(), "{}", String::from_utf8_lossy(&out.stderr));
    let vs = HostShader {
        stage: HwStage::Vs,
        dxil: std::fs::read(&bin).unwrap(),
        user_data: Vec::new(),
        samplers: Vec::new(),
        static_samplers: Vec::new(),
        root_cbvs: Vec::new(),
        root_srvs: Vec::new(),
    };
    let _ = std::fs::remove_dir_all(&dir);

    let words = [
        0xBE80_0F7E, // s_bcnt1_i32_b32 s0, exec_lo
        0xD765_0002, 0x0001_007E, // v_mbcnt_lo_u32_b32 v2, exec_lo, 0
        0xD765_0003, 0x0001_00C1, // v_mbcnt_lo_u32_b32 v3, -1, 0
        vop1(0x006, 0, sgpr(0)), // v_cvt_f32_u32 v0, s0
        vop1(0x006, 1, vgpr(2)), // v_cvt_f32_u32 v1, v2
        vop1(0x006, 2, vgpr(3)), // v_cvt_f32_u32 v2, v3
        vop1(0x001, 3, 0x80), // v_mov_b32 v3, 0
        0xF800_180F, 0x0302_0100, // exp mrt0, v0, v1, v2, v3 done vm
        S_ENDPGM,
    ];
    let code: Vec<u8> = words.iter().flat_map(|w| w.to_le_bytes()).collect();
    let native = NativeProgram {
        stage: HwStage::Ps,
        wave64: false,
        vgprs: 8,
        layout: vec![],
        used: vec![],
        io: StageIo::Ps {
            inputs: vec![],
            input_addr: 0,
            db_shader_control: 0,
            patches: vec![],
        },
        code,
    };
    let p = ir::build(&native.code, native.wave64, native.vgprs).expect("ir::build");
    let res = resource::track(&p, &native.layout, native.stage).expect("resource::track");
    let io = io::raise(&p, &native).expect("io::raise");
    let st = structure::structure(&p).expect("structure");
    let target = SigElement {
        name: "SV_Target".into(),
        index: 0,
        kind: 16,
        comp: 9,
        interp: 0,
        row: Some(0),
        col: 0,
        cols: 4,
        usage: 0,
        half: false,
    };
    let lowered = lower::lower(&lower::Parts {
        native: &native,
        p: &p,
        st: &st,
        io: &io,
        res: &res,
        inputs: Vec::new(),
        outputs: vec![target],
        prims: Vec::new(),
        mesh_stride: 0,
    })
    .expect("lower");
    let ps = HostShader {
        stage: HwStage::Ps,
        dxil: lowered.dxil,
        user_data: lowered.user_data,
        samplers: lowered.samplers,
        static_samplers: Vec::new(),
        root_cbvs: lowered.root_cbvs,
        root_srvs: lowered.root_srvs,
    };
    if let Ok(mut v) = validator::Validator::load(validator::Validator::default_path().as_deref()) {
        v.validate(&mut ps.dxil.clone()).expect("DXIL validation failed");
    }

    let (root, pso) = host.pipeline(&vs, &ps).expect("pipeline");
    let (w, h) = (64, 64);
    let px = host
        .draw(
            &root,
            &pso,
            &Draw {
                roots: vec![],
                textures: &[],
                samplers: &[],
                vertices: &[],
                stride: 0,
                size: (w, h),
                mesh_groups: 0,
            },
        )
        .expect("draw");
    assert_eq!(px.len(), (w * h) as usize);
    let widest = px.iter().map(|t| t[0] as u32).max().unwrap();
    let last_lane = px.iter().map(|t| t[2] as u32).max().unwrap();
    eprintln!("host pixel waves: up to {widest} active lanes, lane indices up to {last_lane}");
    for (i, t) in px.iter().enumerate() {
        let (count, below, lane) = (t[0] as u32, t[1] as u32, t[2] as u32);
        assert!(
            below < count,
            "pixel {i}: v_mbcnt_lo(exec) = {below} is not below s_bcnt1(exec) = {count} \
             (lane {lane}; the host wave is wider than 32 lanes and its high half is lost)"
        );
        assert!(lane < 64, "pixel {i}: lane index {lane}");
    }
    assert!(
        last_lane + 1 >= widest,
        "v_mbcnt_lo(-1) reaches lane {last_lane} only, in waves of up to {widest} active lanes; lanes past 31 share an index"
    );
}

Not tested: RDNA2 / RDNA4, NVIDIA, Intel; the vertex stage; a release build.

AI use: Claude Code (Claude Opus 5.5) wrote the test, ran it on the GPU above and drafted this comment.

**@⁠TheHoracio** on GitHub · 2026-11-24 01:19 UTC · [original](https://github.com/Marvisak/VIctory/issues/125#issuecomment-7118989345) A GPU test for this, run on the RX 7800 XT (RDNA3, driver 32.0.32015.7029, Windows 11 26300, Rust 1.98.1 from `rust-toolchain.toml`, debug). It draws a synthetic console **wave32 pixel program** (hand-written GFX10 words, no game data) through `lower::lower` and `Host::draw`, with a full-screen triangle from a PC-compiled `vs_6_6`. It checks two things in every pixel: - `v_mbcnt_lo_u32_b32(exec_lo, 0) < s_bcnt1_i32_b32(exec_lo)`. This must hold on any host wave size. - `v_mbcnt_lo_u32_b32(-1, 0)` reaches the widest wave's last lane, so lanes past 31 do not share an index. Results, with the test appended to each tree: | Tree | Widest pixel wave seen | Result | |---|---|---| | `main` `d2a4bae` | 32 active lanes (high half lost), lane indices up to 32 | **fails**: `pixel 256: v_mbcnt_lo(exec) = 32 is not below s_bcnt1(exec) = 32 (lane 32 …)` | | #145 head `ecc4eb6` | 64 active lanes, lane indices up to 63 | passes | | #147 head `35caba4` | 64 active lanes, lane indices up to 32 | **fails** the second check: the exec-mask counts are right, but `v_mbcnt_lo(-1)` still clamps to 32 for lanes 32-63 | So on this GPU, #145 fixes both checks, while #147 fixes the mask counts but not `v_mbcnt_lo` of -1. Whether lanes past 31 should get their own index is the semantics question asked above. The test makes that choice visible either way. On a host that runs pixel shaders 32 lanes wide, both checks hold trivially. The test skips without a hardware SM 6.6 device or a PC `dxc.exe` (`VICTORY_PC_DXC`, else next to `dxil.dll`). <details><summary>The test (appended to <code>crates/victory-shader/src/emit/valu_tests.rs</code>)</summary> ```rust /// A console wave32 pixel program's lane masks on the host's wave, whatever /// its size (#125): `v_mbcnt_lo_u32_b32` of EXEC must stay below /// `s_bcnt1_i32_b32` of EXEC in every lane, and `v_mbcnt_lo_u32_b32` of -1 is /// the lane's index in the host wave. A host that runs pixel shaders 64 lanes /// wide (AMD RDNA) loses lanes 32-63 when only the low ballot dword is read. #[test] fn pixel_lane_masks_count_every_lane_of_the_host_wave() { use super::container::SigElement; use super::host::Draw; let pc_dxc = match std::env::var_os("VICTORY_PC_DXC") { Some(p) => Some(std::path::PathBuf::from(p)), None => validator::Validator::default_path().map(|p| p.with_file_name("dxc.exe")), }; let Some(pc_dxc) = pc_dxc.filter(|p| p.exists()) else { eprintln!("no PC dxc.exe for the full-screen vertex shader; skipped"); return; }; let Ok(host) = Host::new(false) else { eprintln!("no SM 6.6 hardware device; skipped"); return; }; // A full-screen triangle from the vertex index (PC HLSL; outside the repo). let dir = std::env::temp_dir().join(format!("victory-lane-masks-{}", std::process::id())); std::fs::create_dir_all(&dir).unwrap(); let src = dir.join("vs.hlsl"); let bin = dir.join("vs.bin"); std::fs::write( &src, "float4 vs(uint id : SV_VertexID) : SV_Position {\n\ float2 uv = float2((id << 1) & 2, id & 2);\n\ return float4(uv * float2(2, -2) + float2(-1, 1), 0.5, 1);\n}\n", ) .unwrap(); let out = std::process::Command::new(&pc_dxc) .args(["-T", "vs_6_6", "-E", "vs", "-Fo"]) .arg(&bin) .arg(&src) .output() .unwrap(); assert!(out.status.success(), "{}", String::from_utf8_lossy(&out.stderr)); let vs = HostShader { stage: HwStage::Vs, dxil: std::fs::read(&bin).unwrap(), user_data: Vec::new(), samplers: Vec::new(), static_samplers: Vec::new(), root_cbvs: Vec::new(), root_srvs: Vec::new(), }; let _ = std::fs::remove_dir_all(&dir); let words = [ 0xBE80_0F7E, // s_bcnt1_i32_b32 s0, exec_lo 0xD765_0002, 0x0001_007E, // v_mbcnt_lo_u32_b32 v2, exec_lo, 0 0xD765_0003, 0x0001_00C1, // v_mbcnt_lo_u32_b32 v3, -1, 0 vop1(0x006, 0, sgpr(0)), // v_cvt_f32_u32 v0, s0 vop1(0x006, 1, vgpr(2)), // v_cvt_f32_u32 v1, v2 vop1(0x006, 2, vgpr(3)), // v_cvt_f32_u32 v2, v3 vop1(0x001, 3, 0x80), // v_mov_b32 v3, 0 0xF800_180F, 0x0302_0100, // exp mrt0, v0, v1, v2, v3 done vm S_ENDPGM, ]; let code: Vec<u8> = words.iter().flat_map(|w| w.to_le_bytes()).collect(); let native = NativeProgram { stage: HwStage::Ps, wave64: false, vgprs: 8, layout: vec![], used: vec![], io: StageIo::Ps { inputs: vec![], input_addr: 0, db_shader_control: 0, patches: vec![], }, code, }; let p = ir::build(&native.code, native.wave64, native.vgprs).expect("ir::build"); let res = resource::track(&p, &native.layout, native.stage).expect("resource::track"); let io = io::raise(&p, &native).expect("io::raise"); let st = structure::structure(&p).expect("structure"); let target = SigElement { name: "SV_Target".into(), index: 0, kind: 16, comp: 9, interp: 0, row: Some(0), col: 0, cols: 4, usage: 0, half: false, }; let lowered = lower::lower(&lower::Parts { native: &native, p: &p, st: &st, io: &io, res: &res, inputs: Vec::new(), outputs: vec![target], prims: Vec::new(), mesh_stride: 0, }) .expect("lower"); let ps = HostShader { stage: HwStage::Ps, dxil: lowered.dxil, user_data: lowered.user_data, samplers: lowered.samplers, static_samplers: Vec::new(), root_cbvs: lowered.root_cbvs, root_srvs: lowered.root_srvs, }; if let Ok(mut v) = validator::Validator::load(validator::Validator::default_path().as_deref()) { v.validate(&mut ps.dxil.clone()).expect("DXIL validation failed"); } let (root, pso) = host.pipeline(&vs, &ps).expect("pipeline"); let (w, h) = (64, 64); let px = host .draw( &root, &pso, &Draw { roots: vec![], textures: &[], samplers: &[], vertices: &[], stride: 0, size: (w, h), mesh_groups: 0, }, ) .expect("draw"); assert_eq!(px.len(), (w * h) as usize); let widest = px.iter().map(|t| t[0] as u32).max().unwrap(); let last_lane = px.iter().map(|t| t[2] as u32).max().unwrap(); eprintln!("host pixel waves: up to {widest} active lanes, lane indices up to {last_lane}"); for (i, t) in px.iter().enumerate() { let (count, below, lane) = (t[0] as u32, t[1] as u32, t[2] as u32); assert!( below < count, "pixel {i}: v_mbcnt_lo(exec) = {below} is not below s_bcnt1(exec) = {count} \ (lane {lane}; the host wave is wider than 32 lanes and its high half is lost)" ); assert!(lane < 64, "pixel {i}: lane index {lane}"); } assert!( last_lane + 1 >= widest, "v_mbcnt_lo(-1) reaches lane {last_lane} only, in waves of up to {widest} active lanes; lanes past 31 share an index" ); } ``` </details> **Not tested:** RDNA2 / RDNA4, NVIDIA, Intel; the vertex stage; a release build. AI use: Claude Code (Claude Opus 5.5) wrote the test, ran it on the GPU above and drafted this comment.
Author
Owner

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

Automated triage for the maintainers.

Confirmed on current main (line numbers have moved since the report). In crates/victory-shader/src/emit/lower.rs, pixel and vertex programs use MaskData::Host, whose doc says ballots are taken over the host's wave "whatever its size". Lower::mask_dword returns the high ballot dword only for a value in st.highs, so for a wave32 program every mask read gets the low dword. The 32-bit forms built on it (s_bcnt1_i32_b32 / s_ff1_i32_b32 in sop, s_cmp_eq/lg_u32, and v_mbcnt_lo_u32_b32 in valu, which also clamps the count at lane 32) never see lanes 32-63 of a 64-lane host wave. The RDNA3 measurements in the comments above show pixel shaders do run 64 lanes wide on that GPU, so this code path is taken in practice.

The open design question (count over the host wave, or cap at the console's 32 lanes) is for the maintainers. Two open PRs take different answers: #145 reads both ballot halves (and lowers v_mbcnt_lo of -1 to the host lane index), and #434 picks each lane's own half of the ballot (it treats the upper 32 host lanes as a second console wave). Both currently need a rebase. #131, by the same reporter, describes the same defect; this issue is where it is tracked.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 01:44 UTC · [original](https://github.com/Marvisak/VIctory/issues/125#issuecomment-7149905143) <!-- victory-issue-triage v1 verdict=confirmed seen=2026-11-24T01:19:37Z at=2026-11-25T01:44:31Z --> Automated triage for the maintainers. Confirmed on current `main` (line numbers have moved since the report). In `crates/victory-shader/src/emit/lower.rs`, pixel and vertex programs use `MaskData::Host`, whose doc says ballots are taken over the host's wave "whatever its size". `Lower::mask_dword` returns the high ballot dword only for a value in `st.highs`, so for a wave32 program every mask read gets the low dword. The 32-bit forms built on it (`s_bcnt1_i32_b32` / `s_ff1_i32_b32` in `sop`, `s_cmp_eq/lg_u32`, and `v_mbcnt_lo_u32_b32` in `valu`, which also clamps the count at lane 32) never see lanes 32-63 of a 64-lane host wave. The RDNA3 measurements in the comments above show pixel shaders do run 64 lanes wide on that GPU, so this code path is taken in practice. The open design question (count over the host wave, or cap at the console's 32 lanes) is for the maintainers. Two open PRs take different answers: #145 reads both ballot halves (and lowers `v_mbcnt_lo` of -1 to the host lane index), and #434 picks each lane's own half of the ballot (it treats the upper 32 host lanes as a second console wave). Both currently need a rebase. #131, by the same reporter, describes the same defect; this issue is where it is tracked. --- _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#125
No description provided.