GPU Recompiler: PS helper lanes dropped in ballot()/WQM, TextureCubeArray mismatch, 4 GiB window carry, and DXC -Gis / CLAMP-OMOD gaps #105

Open
opened 2026-11-26 04:10:17 +00:00 by github-bot · 3 comments
Owner

@⁠raylitebull on GitHub · 2026-11-23 11:15 UTC · original

Summary

Verified 4 larger GPU recompiler correctness issues during an audit of crates/xcl/src/gpu/ (on main 60599a9) that warrant dedicated PRs with thorough GPU testing (AMD + NVIDIA):

1. Pixel-shader ballot() / write_mask() drops helper lanes in WQM (crates/xcl/src/gpu/recomp/emit.rs)

  • WaveActiveBallot(b) unconditionally returns 0 for helper lanes in HLSL SM 6.6.
  • While rla() already has an #ifdef XCL_PIXEL workaround using QuadReadLaneAt, ballot() does not.
  • After s_wqm_b64 exec, exec, helper lanes have EXEC == 1, yet v_cmp_*, v_cmpx_*, v_add_co_u32, and v_sub_co_u32 clear helper-lane mask bits to 0: v_cndmask_b32 picks the false branch, 64-bit carries are lost on helper lanes, and s_and_saveexec_b64 kills helper lanes before subsequent DPP/swizzle/implicit Sample() derivatives on primitive edges.
  • Direction: Under #ifdef XCL_PIXEL, reconstruct active-quad nibbles via QuadReadLaneAt((uint)b, 0..3) and merge across the wave with two 32-bit WaveActiveBitOr calls.

2. TextureCubeArray view-dimension mismatch between desc::image_d3d12 and MIMG emission (crates/xcl/src/gpu/desc.rs, crates/xcl/src/gpu/recomp/emit.rs, crates/xcl/src/hle/d3d12x/real.rs)

  • For ImageType::Cube with depth > 6, desc::image_d3d12 creates a D3D12_SRV_DIMENSION_TEXTURECUBEARRAY SRV, but emit.rs always casts DIM == 3 (SQ_RSRC_IMG_CUBE) to TextureCube<float4>, cube_dir discards the array slice (floor(face / 8)), and get_resinfo hardcodes depth to 1u.
  • Related in hle/d3d12x/real.rs: dev_create_srv_x / view_shape hit fallback defaults for D3D12_SRV_DIMENSION_TEXTURECUBEARRAY (10) (hardcoding MipLevels = 1 and depth 6 instead of NumCubes * 6).

3. Missing 64-bit carry/borrow into xcl_w across 4 GiB UMA boundaries (crates/xcl/src/gpu/recomp/emit.rs)

  • In smem, mubuf, buffer_atomic, mubuf_d16, flat, and flat_atomic, self.window(&hi) is computed before adding voff / soff / imm / stride * index (unlike bvh_intersect_ray, which computes uint64_t a first).
  • Any buffer or global address crossing a 4 GiB window boundary (e.g., inside Uma::sparse_reserve spanning windows 0..2, or global_load_* with negative 12-bit signed OFFSET near a window start) wraps inside the previous window instead of carrying/borrowing into the adjacent window.
  • Also in Mode::Geometry, IO_GS_VERTICES is only a 32-bit uint xcl_vin without xcl_w, so pre-fetched vertices in window 3 read from window 0.

4. DXC fast-math (-Gis) & missing CLAMP / OMOD modifiers (crates/xcl/src/gpu/recomp/dxc.rs, crates/xcl/src/gpu/recomp/emit.rs)

  • dxc.rs does not pass -Gis (IEEE strictness), allowing DXC fast-math contraction/reassociation on translated float ops (and note that changing DXC flags in dxc.rs should be included in the disk cache hash so existing cached DXIL invalidates).
  • valu64 emits saturate(double) for CLAMP=1 (HLSL SM 6.6 saturate has no double overload, narrowing to float and losing 29 bits of precision) and ignores m.omod; v_cvt_f32_f64 and v_cvt_f16_f32 ignore m.omod/m.clamp; integer CLAMP=1 saturation is only handled on v_add_nc_i32/v_sub_nc_i32 and dropped on v_add_nc_u32/v_sub_nc_u32/v_add3_u32/v_pk_add_u16/v_dot4_i32_i8.
  • Also noticed: packed ISG1 vertex inputs sharing a register emit duplicate XclIn field names (a{e.register}) in Mode::Vertex, code32 src_vccz/src_execz checks (lo | hi) == 0 in wave32 mode, SDWA passes f16 = false to code32, and Mode::Compute tg_size uses truncating division instead of div_ceil.
**@⁠raylitebull** on GitHub · 2026-11-23 11:15 UTC · [original](https://github.com/xcl-dev/xcl/issues/105) ## Summary Verified 4 larger GPU recompiler correctness issues during an audit of `crates/xcl/src/gpu/` (on `main` `60599a9`) that warrant dedicated PRs with thorough GPU testing (AMD + NVIDIA): ### 1. Pixel-shader `ballot()` / `write_mask()` drops helper lanes in WQM (`crates/xcl/src/gpu/recomp/emit.rs`) - `WaveActiveBallot(b)` unconditionally returns `0` for helper lanes in HLSL SM 6.6. - While `rla()` already has an `#ifdef XCL_PIXEL` workaround using `QuadReadLaneAt`, `ballot()` does not. - After `s_wqm_b64 exec, exec`, helper lanes have `EXEC == 1`, yet `v_cmp_*`, `v_cmpx_*`, `v_add_co_u32`, and `v_sub_co_u32` clear helper-lane mask bits to `0`: `v_cndmask_b32` picks the false branch, 64-bit carries are lost on helper lanes, and `s_and_saveexec_b64` kills helper lanes before subsequent DPP/swizzle/implicit `Sample()` derivatives on primitive edges. - **Direction:** Under `#ifdef XCL_PIXEL`, reconstruct active-quad nibbles via `QuadReadLaneAt((uint)b, 0..3)` and merge across the wave with two 32-bit `WaveActiveBitOr` calls. ### 2. `TextureCubeArray` view-dimension mismatch between `desc::image_d3d12` and MIMG emission (`crates/xcl/src/gpu/desc.rs`, `crates/xcl/src/gpu/recomp/emit.rs`, `crates/xcl/src/hle/d3d12x/real.rs`) - For `ImageType::Cube` with `depth > 6`, `desc::image_d3d12` creates a `D3D12_SRV_DIMENSION_TEXTURECUBEARRAY` SRV, but `emit.rs` always casts `DIM == 3` (`SQ_RSRC_IMG_CUBE`) to `TextureCube<float4>`, `cube_dir` discards the array slice (`floor(face / 8)`), and `get_resinfo` hardcodes depth to `1u`. - Related in `hle/d3d12x/real.rs`: `dev_create_srv_x` / `view_shape` hit fallback defaults for `D3D12_SRV_DIMENSION_TEXTURECUBEARRAY` (`10`) (hardcoding `MipLevels = 1` and depth `6` instead of `NumCubes * 6`). ### 3. Missing 64-bit carry/borrow into `xcl_w` across 4 GiB UMA boundaries (`crates/xcl/src/gpu/recomp/emit.rs`) - In `smem`, `mubuf`, `buffer_atomic`, `mubuf_d16`, `flat`, and `flat_atomic`, `self.window(&hi)` is computed **before** adding `voff` / `soff` / `imm` / `stride * index` (unlike `bvh_intersect_ray`, which computes `uint64_t a` first). - Any buffer or global address crossing a 4 GiB window boundary (e.g., inside `Uma::sparse_reserve` spanning windows 0..2, or `global_load_*` with negative 12-bit signed `OFFSET` near a window start) wraps inside the previous window instead of carrying/borrowing into the adjacent window. - Also in `Mode::Geometry`, `IO_GS_VERTICES` is only a 32-bit `uint xcl_vin` without `xcl_w`, so pre-fetched vertices in window 3 read from window 0. ### 4. DXC fast-math (`-Gis`) & missing `CLAMP` / `OMOD` modifiers (`crates/xcl/src/gpu/recomp/dxc.rs`, `crates/xcl/src/gpu/recomp/emit.rs`) - `dxc.rs` does not pass `-Gis` (IEEE strictness), allowing DXC fast-math contraction/reassociation on translated float ops (and note that changing DXC flags in `dxc.rs` should be included in the disk cache hash so existing cached DXIL invalidates). - `valu64` emits `saturate(double)` for `CLAMP=1` (HLSL SM 6.6 `saturate` has no `double` overload, narrowing to `float` and losing 29 bits of precision) and ignores `m.omod`; `v_cvt_f32_f64` and `v_cvt_f16_f32` ignore `m.omod`/`m.clamp`; integer `CLAMP=1` saturation is only handled on `v_add_nc_i32`/`v_sub_nc_i32` and dropped on `v_add_nc_u32`/`v_sub_nc_u32`/`v_add3_u32`/`v_pk_add_u16`/`v_dot4_i32_i8`. - Also noticed: packed `ISG1` vertex inputs sharing a register emit duplicate `XclIn` field names (`a{e.register}`) in `Mode::Vertex`, `code32` `src_vccz`/`src_execz` checks `(lo | hi) == 0` in wave32 mode, SDWA passes `f16 = false` to `code32`, and `Mode::Compute` `tg_size` uses truncating division instead of `div_ceil`.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:10:17 +00:00
Author
Owner

@⁠ivall on GitHub · 2026-11-23 11:42 UTC · original

Thanks. Triage against current main:

  • 1. helper lanes in ballot() – known (HANDOFF: "Ballots (v_cmp) still leave helper lanes out"). Note [WaveOpsIncludeHelperLanes] (ps_6_7) was tried and hung the device ~9 s in (the entry ballot then included helper lanes forever), so a quad-read reconstruction like you suggest is the way – it needs GPU tests on primitive edges (console_compiled_derivatives_hold_on_triangle_edges is the model).
  • 2. cube arrays – plausible gap; a PR with a GPU test sampling a cube array slice > 0 would be welcome.
  • 3. 4 GiB window carry – real in principle; titles keep buffers inside one window in practice (allocations never straddle windows), so low priority; a PR computing the 64-bit address before choosing the window is fine if it keeps the single-window HLSL unchanged (DXIL cache).
  • 4. -Gis, omod / clamp gaps – -Gis was measured in #73 (it changes codegen, not rounding); the clamp / omod gaps are worth fixing in a PR with per-instruction GPU tests.
**@⁠ivall** on GitHub · 2026-11-23 11:42 UTC · [original](https://github.com/xcl-dev/xcl/issues/105#issuecomment-7099992817) Thanks. Triage against current `main`: - **1. helper lanes in `ballot()`** – known (HANDOFF: "Ballots (v_cmp) still leave helper lanes out"). Note `[WaveOpsIncludeHelperLanes]` (ps_6_7) was tried and hung the device ~9 s in (the entry ballot then included helper lanes forever), so a quad-read reconstruction like you suggest is the way – it needs GPU tests on primitive edges (`console_compiled_derivatives_hold_on_triangle_edges` is the model). - **2. cube arrays** – plausible gap; a PR with a GPU test sampling a cube array slice > 0 would be welcome. - **3. 4 GiB window carry** – real in principle; titles keep buffers inside one window in practice (allocations never straddle windows), so low priority; a PR computing the 64-bit address before choosing the window is fine if it keeps the single-window HLSL unchanged (DXIL cache). - **4. `-Gis`, omod / clamp gaps** – `-Gis` was measured in #73 (it changes codegen, not rounding); the clamp / omod gaps are worth fixing in a PR with per-instruction GPU tests.
Author
Owner

@⁠ivall on GitHub · 2026-11-23 21:14 UTC · original

Progress: the TextureCubeArray mismatch is fixed by #149 (merged). The helper-lane masks (#134) crashed the driver's compiler on RDNA4 in gpu_wave64_ps_whole_wave_reductions and are not merged yet; the 4 GiB window carry is #138, next in line.

**@⁠ivall** on GitHub · 2026-11-23 21:14 UTC · [original](https://github.com/xcl-dev/xcl/issues/105#issuecomment-7114204045) Progress: the TextureCubeArray mismatch is fixed by #149 (merged). The helper-lane masks (#134) crashed the driver's compiler on RDNA4 in `gpu_wave64_ps_whole_wave_reductions` and are not merged yet; the 4 GiB window carry is #138, next in line.
Author
Owner

@⁠Luislariosss on GitHub · 2026-11-24 01:06 UTC · original

Item 2 (TextureCubeArray mismatch) looks fixed on main at 2997c9aca, so the issue may be worth narrowing to items 1, 3 and 4.

Evidence from the tree:

  • desc.rs:262 states the intent: // always a cube array (of one cube, too): translated shaders declare TextureCubeArray.
  • emit.rs:2165 and :2272 now emit TextureCubeArray<float4> for DIM == 3, and the sample form passes cube_slice(face) as the array coordinate.
  • emit.rs:5366: float cube_slice(float face) { return (float)(((uint)round(face)) / 8u); } - the console's face + 8 * slice encoding, so the slice is no longer discarded.
  • emit.rs:2296: get_resinfo declares TextureCubeArray and does {t}_d *= 6u, instead of hardcoding depth to 1.
  • runner.rs:292-293 creates D3D12_SRV_DIMENSION_TEXTURECUBEARRAY with NumCubes: t.depth / 6.

Item 1 is not addressed as far as I can see: rla() has the #ifdef XCL_PIXEL quad-read workaround (emit.rs:5314-5333) but ballot() (:5308-5311) still returns WaveActiveBallot(b) unchanged, so helper lanes are dropped there.

I did not test any of this on a GPU beyond a full cargo test --workspace run on an RX 9060 XT (677 passed, 0 failed, 41 ignored), which exercises the recompiler but not a pixel shader with s_wqm on a primitive edge. Treat the above as a reading of the code, not as a measured fix.

AI-assisted.

**@⁠Luislariosss** on GitHub · 2026-11-24 01:06 UTC · [original](https://github.com/xcl-dev/xcl/issues/105#issuecomment-7118756693) Item 2 (TextureCubeArray mismatch) looks fixed on main at `2997c9aca`, so the issue may be worth narrowing to items 1, 3 and 4. Evidence from the tree: - `desc.rs:262` states the intent: `// always a cube array (of one cube, too): translated shaders declare TextureCubeArray`. - `emit.rs:2165` and `:2272` now emit `TextureCubeArray<float4>` for `DIM == 3`, and the sample form passes `cube_slice(face)` as the array coordinate. - `emit.rs:5366`: `float cube_slice(float face) { return (float)(((uint)round(face)) / 8u); }` - the console's `face + 8 * slice` encoding, so the slice is no longer discarded. - `emit.rs:2296`: `get_resinfo` declares `TextureCubeArray` and does `{t}_d *= 6u`, instead of hardcoding depth to 1. - `runner.rs:292-293` creates `D3D12_SRV_DIMENSION_TEXTURECUBEARRAY` with `NumCubes: t.depth / 6`. Item 1 is not addressed as far as I can see: `rla()` has the `#ifdef XCL_PIXEL` quad-read workaround (`emit.rs:5314-5333`) but `ballot()` (`:5308-5311`) still returns `WaveActiveBallot(b)` unchanged, so helper lanes are dropped there. I did not test any of this on a GPU beyond a full `cargo test --workspace` run on an RX 9060 XT (677 passed, 0 failed, 41 ignored), which exercises the recompiler but not a pixel shader with `s_wqm` on a primitive edge. Treat the above as a reading of the code, not as a measured fix. AI-assisted.
This discussion has been locked. Commenting is limited to contributors.
No description provided.