Recompiler: typed buffer loads past the format and dst_sel differ from RDNA2 (tbuffer reads 0 and ignores dst_sel) #1414

Open
opened 2026-11-26 04:53:09 +00:00 by github-bot · 4 comments
Owner

@⁠Lyrnc on GitHub · 2026-11-24 15:44 UTC · original

Typed buffer loads (fmt_comp / dst_sel in recomp/emit.rs) differ from RDNA2 hardware in three ways. I measured all 77 GFX10 buffer formats on gfx1036 and ran the same instructions through XCL's recompiler. I haven't written a fix PR: the change is in crates/xcl/src, so it would need a smoke run on a title, and I don't have one. The data is below, if someone wants to take it.

Setup.

  • Hardware: an AMD Radeon iGPU (Ryzen 7 9800X3D), gfx1036 / RDNA2, AMD driver 32.0.21042.62, Windows 11. A HIP kernel (assembled by the driver's amd_comgr) builds a raw V# over 64 rows of 4 dwords (byte, half and float edge patterns, plus random), and each lane loads its own row with offen.
  • XCL: main 930e8b4. The same loads went through a local test (not committed) using prog and runner::run_code, with the same rows at 0x1000 and V# [0x1000, 0, 0x1000, dst_sel | format << 12]. It ran on the same Radeon iGPU (XCL_ADAPTER=radeon) and on an RTX 5080 (driver 610.88). Both adapters give the same results apart from 1-ULP and NaN-payload differences.

This is RDNA2 desktop silicon, not the console's GPU. No game data was used.

1. tbuffer_load_format_* reads 0 past the format's channels, the 4th too. fmt_comp returns 1 / 1.0 for a missing channel 3. On gfx1036, every format with fewer than 4 channels returns 0 in every missing channel, for every numeric kind: 0 exceptions in 6,208 values. With an identity dst_sel, XCL differs from the hardware in the 4th channel on 64 of 64 rows for each of those 49 formats.

2. tbuffer_load_format_* ignores the V#'s dst_sel. XCL applies it to both encodings (// format from the instruction (tbuffer) or from the V#; DST_SEL from the V#). On the hardware the MTBUF form returns the channels in order, whatever the swizzle:

V# dst_sel tbuffer_load_format_xyzw format:32_32_32_32_FLOAT (hardware) XCL
identity (x, y, z, w) (x, y, z, w)
W = ONE (x, y, z, w) (x, y, z, 1.0)
W = ZERO (x, y, z, w) (x, y, z, 0)
X↔Y (x, y, z, w) (y, x, z, w)

32_32_32_FLOAT with W = ONE gives (x, y, z, 0) on the hardware and (x, y, z, 1.0) in XCL. The same holds for 8_UNORM, 8_8_UNORM, 8_UINT, 32_FLOAT, 32_32_FLOAT and 8_8_8_8_UNORM, with all 4 swizzles. A vertex stream that a title reads with tbuffer through a descriptor set to W = ONE, or to a BGRA swizzle, comes out different.

3. buffer_load_format_* (MUBUF, the V#'s format) does apply dst_sel, but an identity swizzle that points at a missing channel reads the format's channels again, not 0 / 1:

V# format (identity dst_sel) hardware XCL
32_FLOAT, 8_UNORM, 8_UINT (x, x, x, x) (x, 0, 0, 1)
32_32_FLOAT, 8_8_UNORM (x, y, x, y) (x, y, 0, 1)
32_32_32_FLOAT (x, y, z, x) (x, y, z, 1)

A dst_sel of ONE or ZERO gives 1 or 0 on the hardware, as in XCL. So with those formats, an identity dst_sel gives a different result in every channel the format lacks, and an explicit ONE/ZERO differs only where the swizzle still points at a missing channel. Your gpu_typed_buffer_loads_and_stores case B (16_16_FLOAT, identity) expects (1.0, -2.0, 0, 1.0). By the 2-channel formats above, the hardware would give (1.0, -2.0, 1.0, -2.0). I didn't run 16_16_FLOAT itself through MUBUF.

Also, for the record: UNORM / SNORM are correctly rounded on the hardware (0 exceptions over all 20 norm formats). fmt_comp's division is 1 ULP off on some values, as its comment and the test's 2-ULP tolerance already say. Byte 0xfe as 8_UNORM reads 0x3f7efeff on the hardware and 0x3f7eff00 in XCL; on 8_8_8_8_UNORM, 80 of 256 values differ. An exact conversion without a division is described in Marvisak/VIctory#1060, with code on a branch. In binary, k / (2^n - 1) is k's n bits repeating, so the f32 is 24 bits of that stream from its leading 1, rounded by the 25th.

The packed formats (10_11_11, 11_11_10, 10_10_10_2, 2_10_10_10), USCALED/SSCALED, UINT/SINT and FLOAT otherwise match the hardware bit for bit, apart from NaN payloads of small floats on NVIDIA.

What a fix would change, as far as I can tell:

  • In fmt_comp, return 0 for c >= n.
  • For ENC_MTBUF, use the channels in order instead of dst_sel.
  • For ENC_MUBUF, have dst_sel 4..7 (X..W) on a missing channel read channel sel % n. My guess is that (x, x, x, x), (x, y, x, y) and (x, y, z, x) all fit that, but I've only seen it for 1, 2 and 3 channels with identity and X↔Y, not as a general rule.

I can share the probe, the local test and the JSON results, or run a branch on the Radeon and the 5080.

AI use: Claude Code (Claude Opus 5.5) wrote the probes, the local test and the comparison, ran them on the GPUs above and drafted this issue; the numbers come from those runs.

**@⁠Lyrnc** on GitHub · 2026-11-24 15:44 UTC · [original](https://github.com/xcl-dev/xcl/issues/1414) Typed buffer loads (`fmt_comp` / `dst_sel` in `recomp/emit.rs`) differ from RDNA2 hardware in three ways. I measured all 77 GFX10 buffer formats on gfx1036 and ran the same instructions through XCL's recompiler. I haven't written a fix PR: the change is in `crates/xcl/src`, so it would need a smoke run on a title, and I don't have one. The data is below, if someone wants to take it. **Setup.** - **Hardware:** an AMD Radeon iGPU (Ryzen 7 9800X3D), **gfx1036 / RDNA2**, AMD driver 32.0.21042.62, Windows 11. A HIP kernel (assembled by the driver's amd_comgr) builds a raw V# over 64 rows of 4 dwords (byte, half and float edge patterns, plus random), and each lane loads its own row with `offen`. - **XCL:** `main` `930e8b4`. The same loads went through a local test (not committed) using `prog` and `runner::run_code`, with the same rows at `0x1000` and V# `[0x1000, 0, 0x1000, dst_sel | format << 12]`. It ran on the same Radeon iGPU (`XCL_ADAPTER=radeon`) and on an RTX 5080 (driver 610.88). Both adapters give the same results apart from 1-ULP and NaN-payload differences. This is RDNA2 desktop silicon, not the console's GPU. No game data was used. **1. `tbuffer_load_format_*` reads 0 past the format's channels, the 4th too.** `fmt_comp` returns 1 / 1.0 for a missing channel 3. On gfx1036, every format with fewer than 4 channels returns 0 in every missing channel, for every numeric kind: 0 exceptions in 6,208 values. With an identity `dst_sel`, XCL differs from the hardware in the 4th channel on 64 of 64 rows for each of those 49 formats. **2. `tbuffer_load_format_*` ignores the V#'s `dst_sel`.** XCL applies it to both encodings (`// format from the instruction (tbuffer) or from the V#; DST_SEL from the V#`). On the hardware the `MTBUF` form returns the channels in order, whatever the swizzle: | V# `dst_sel` | `tbuffer_load_format_xyzw format:32_32_32_32_FLOAT` (hardware) | XCL | |---|---|---| | identity | `(x, y, z, w)` | `(x, y, z, w)` | | W = ONE | `(x, y, z, w)` | `(x, y, z, 1.0)` | | W = ZERO | `(x, y, z, w)` | `(x, y, z, 0)` | | X↔Y | `(x, y, z, w)` | `(y, x, z, w)` | `32_32_32_FLOAT` with W = ONE gives `(x, y, z, 0)` on the hardware and `(x, y, z, 1.0)` in XCL. The same holds for 8_UNORM, 8_8_UNORM, 8_UINT, 32_FLOAT, 32_32_FLOAT and 8_8_8_8_UNORM, with all 4 swizzles. A vertex stream that a title reads with `tbuffer` through a descriptor set to W = ONE, or to a BGRA swizzle, comes out different. **3. `buffer_load_format_*` (`MUBUF`, the V#'s format) does apply `dst_sel`, but an identity swizzle that points at a missing channel reads the format's channels again, not 0 / 1:** | V# format (identity `dst_sel`) | hardware | XCL | |---|---|---| | `32_FLOAT`, `8_UNORM`, `8_UINT` | `(x, x, x, x)` | `(x, 0, 0, 1)` | | `32_32_FLOAT`, `8_8_UNORM` | `(x, y, x, y)` | `(x, y, 0, 1)` | | `32_32_32_FLOAT` | `(x, y, z, x)` | `(x, y, z, 1)` | A `dst_sel` of ONE or ZERO gives 1 or 0 on the hardware, as in XCL. So with those formats, an identity `dst_sel` gives a different result in every channel the format lacks, and an explicit ONE/ZERO differs only where the swizzle still points at a missing channel. Your `gpu_typed_buffer_loads_and_stores` case B (`16_16_FLOAT`, identity) expects `(1.0, -2.0, 0, 1.0)`. By the 2-channel formats above, the hardware would give `(1.0, -2.0, 1.0, -2.0)`. I didn't run `16_16_FLOAT` itself through `MUBUF`. **Also, for the record:** UNORM / SNORM are correctly rounded on the hardware (0 exceptions over all 20 norm formats). `fmt_comp`'s division is 1 ULP off on some values, as its comment and the test's 2-ULP tolerance already say. Byte `0xfe` as `8_UNORM` reads `0x3f7efeff` on the hardware and `0x3f7eff00` in XCL; on 8_8_8_8_UNORM, 80 of 256 values differ. An exact conversion without a division is described in [Marvisak/VIctory#1060](https://github.com/Marvisak/VIctory/issues/1060), with code on a branch. In binary, `k / (2^n - 1)` is `k`'s `n` bits repeating, so the f32 is 24 bits of that stream from its leading 1, rounded by the 25th. The packed formats (10_11_11, 11_11_10, 10_10_10_2, 2_10_10_10), USCALED/SSCALED, UINT/SINT and FLOAT otherwise match the hardware bit for bit, apart from NaN payloads of small floats on NVIDIA. **What a fix would change**, as far as I can tell: - In `fmt_comp`, return 0 for `c >= n`. - For `ENC_MTBUF`, use the channels in order instead of `dst_sel`. - For `ENC_MUBUF`, have `dst_sel` 4..7 (X..W) on a missing channel read channel `sel % n`. My guess is that `(x, x, x, x)`, `(x, y, x, y)` and `(x, y, z, x)` all fit that, but I've only seen it for 1, 2 and 3 channels with identity and X↔Y, not as a general rule. I can share the probe, the local test and the JSON results, or run a branch on the Radeon and the 5080. AI use: Claude Code (Claude Opus 5.5) wrote the probes, the local test and the comparison, ran them on the GPUs above and drafted this issue; the numbers come from those runs.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:53:09 +00:00
Author
Owner

@⁠tiagonogueiraa-bit on GitHub · 2026-11-24 15:46 UTC · original

claiming, from your measurements:

  1. tbuffer_load_format_* reads 0 in every channel its format lacks, the 4th too.
  2. The MTBUF form ignores the V#'s dst_sel.
  3. buffer_load_format_* with an identity selector on a missing channel reads channel c mod n of the format: (x,x,x,x), (x,y,x,y), (x,y,z,x).

Explicit ONE / ZERO stay as they are. I'll check the translation on the CPU against your tables and adjust gpu_typed_buffer_loads_and_stores where it encodes the old behaviour. PR within a couple of hours.

Written with Claude Code (Claude Opus 5.5).

**@⁠tiagonogueiraa-bit** on GitHub · 2026-11-24 15:46 UTC · [original](https://github.com/xcl-dev/xcl/issues/1414#issuecomment-7136580979) claiming, from your measurements: 1. `tbuffer_load_format_*` reads 0 in every channel its format lacks, the 4th too. 2. The MTBUF form ignores the V#'s `dst_sel`. 3. `buffer_load_format_*` with an identity selector on a missing channel reads channel `c mod n` of the format: `(x,x,x,x)`, `(x,y,x,y)`, `(x,y,z,x)`. Explicit ONE / ZERO stay as they are. I'll check the translation on the CPU against your tables and adjust `gpu_typed_buffer_loads_and_stores` where it encodes the old behaviour. PR within a couple of hours. Written with Claude Code (Claude Opus 5.5).
Author
Owner

@⁠tiagonogueiraa-bit on GitHub · 2026-11-24 15:48 UTC · original

@⁠Lyrnc PR #1423 covers points 1 and 3; point 2 is #875. You offered to run a branch on the Radeon and the 5080. gpu_typed_buffer_loads_and_stores on #1423's head (7c6a1b9) would check the new cases G / H / I and the changed B against your hardware. On main they should fail, and on the PR pass.

Written with Claude Code (Claude Opus 5.5).

**@⁠tiagonogueiraa-bit** on GitHub · 2026-11-24 15:48 UTC · [original](https://github.com/xcl-dev/xcl/issues/1414#issuecomment-7136649120) @⁠Lyrnc PR #1423 covers points 1 and 3; point 2 is #875. You offered to run a branch on the Radeon and the 5080. `gpu_typed_buffer_loads_and_stores` on #1423's head (`7c6a1b9`) would check the new cases G / H / I and the changed B against your hardware. On `main` they should fail, and on the PR pass. Written with Claude Code (Claude Opus 5.5).
Author
Owner

@⁠upipibi on GitHub · 2026-11-25 14:58 UTC · original

The store side of this, which #1423 (loads) and #875 (MTBUF loads) don't cover:

  • XCL: buffer_store_format_* / tbuffer_store_format_* ignore the V#'s DST_SEL and write the data components in order (crates/xcl/src/gpu/recomp/emit.rs:2221-2238 at main 06c9f550, the BufKind::FormatStore arm; no dst_sel there).
  • RDNA2: boykopovar/AnyPS5 measured MUBUF format stores on gfx1036 (AMD driver 32.0.21045.16010, through their hardware oracle; c8b83bac8b, docs/dev/debt/changes/docs-mubuf-format-store-dst-sel.md). The V# DST_SEL is applied by the same channel rule as their image stores:
    • 8_8_8_8 and 32_32_32_32 UINT store (w, z, y, x) for W,Z,Y,X, and (1, w, 0, y) for Z,0,X,1.
    • 32_UINT stores w whenever DST_SEL X isn't X.
    • 16_16_UINT stores (x, w) even for X,Y,Z,W.
    • Identity X,Y,Z,W agrees with in-order writing for four- and one-channel formats.
  • The full two-channel rule, from their image-store entry (docs/dev/debt/shader.md, StoreTexel): the hardware reads DST_SEL X, Y and Z only. With X=X it stores (x, y) when Y is X/Y/Z/W and Z is 0/1, else (x, w).

So XCL would differ from RDNA2 for non-identity DST_SEL on every format store, and for a two-channel format whenever that rule picks (x, w). shadPS4 found the load half independently on PS4 with homebrew (shadps4-emu/shadPS4#5763), which fits #1423's sel mod n.

Limits: the PS5's gfx1013 isn't measured. AnyPS5's note doesn't say which store width (_xy or _xyzw) produced the (x, w) case, and I haven't measured anything myself. This is only a pointer to their data. A synthetic GPU test here could check only what XCL writes, not what the hardware does.

AI-assisted (Claude Code). Read only.

**@⁠upipibi** on GitHub · 2026-11-25 14:58 UTC · [original](https://github.com/xcl-dev/xcl/issues/1414#issuecomment-7166096434) The store side of this, which #1423 (loads) and #875 (MTBUF loads) don't cover: - **XCL:** `buffer_store_format_*` / `tbuffer_store_format_*` ignore the V#'s DST_SEL and write the data components in order (`crates/xcl/src/gpu/recomp/emit.rs:2221-2238` at `main` `06c9f550`, the `BufKind::FormatStore` arm; no `dst_sel` there). - **RDNA2:** boykopovar/AnyPS5 measured MUBUF format stores on gfx1036 (AMD driver 32.0.21045.16010, through their hardware oracle; [`c8b83bac8b`](https://github.com/boykopovar/AnyPS5/commit/c8b83bac8b), `docs/dev/debt/changes/docs-mubuf-format-store-dst-sel.md`). The V# DST_SEL is applied by the same channel rule as their image stores: - 8_8_8_8 and 32_32_32_32 UINT store (w, z, y, x) for W,Z,Y,X, and (1, w, 0, y) for Z,0,X,1. - 32_UINT stores w whenever DST_SEL X isn't X. - 16_16_UINT stores (x, w) even for X,Y,Z,W. - Identity X,Y,Z,W agrees with in-order writing for four- and one-channel formats. - The full two-channel rule, from their image-store entry (`docs/dev/debt/shader.md`, `StoreTexel`): the hardware reads DST_SEL X, Y and Z only. With X=X it stores (x, y) when Y is X/Y/Z/W and Z is 0/1, else (x, w). So XCL would differ from RDNA2 for non-identity DST_SEL on every format store, and for a two-channel format whenever that rule picks (x, w). shadPS4 found the load half independently on PS4 with homebrew (shadps4-emu/shadPS4#5763), which fits #1423's `sel mod n`. Limits: the PS5's gfx1013 isn't measured. AnyPS5's note doesn't say which store width (`_xy` or `_xyzw`) produced the (x, w) case, and I haven't measured anything myself. This is only a pointer to their data. A synthetic GPU test here could check only what XCL writes, not what the hardware does. AI-assisted (Claude Code). Read only.
Author
Owner

@⁠CryingLaughing on GitHub · 2026-11-26 13:54 UTC · original

I tested the store side on main b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7 and fork commit 138e36d6f56e3b6112bf0fa935a9147e9eb5d71c. The change applies channel selection before packing non-D16 MUBUF BUFFER_STORE_FORMAT_XYZW with 32_32_UINT. It follows the desktop RDNA2 hardware measurements.

The same synthetic fixture failed at XYZW on main in both HLSL and direct DXIL. It read (17,34) where the expected pair was (17,68). The patched fixture passed all 13 raw-memory cases in both modes, including reserved selectors, MTBUF, neighboring formats and out-of-bounds guards. That is 0/1/0 per base mode, 1/0/0 per patched mode, zero capability skips.

Tested on RTX 4080 driver 621.01, Core i5-13600K, Windows 11 25H2 build 26200.9974, Rust 1.100.0 x64 MSVC and DXC 1.8.2502.11. The focused test was gpu_mubuf_u32x2_xyzw_store_selects_channels with XCL_DIRECT_DXIL=0 and 1. cargo build --workspace --locked -j 4 succeeded. cargo test --workspace --locked -j 4 --no-fail-fast -- --test-threads=4 --show-output reported 1,436 passed, 0 failed, 47 ignored across 37 harnesses, including 29 capability skips in the pass count.

Not tested were Xbox-native behavior, wider W-selector variations, retail regression and performance.

**@⁠CryingLaughing** on GitHub · 2026-11-26 13:54 UTC · [original](https://github.com/xcl-dev/xcl/issues/1414#issuecomment-7193999327) I tested the store side on main `b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7` and [fork commit `138e36d6f56e3b6112bf0fa935a9147e9eb5d71c`](https://github.com/CryingLaughing/xcl/commit/138e36d6f56e3b6112bf0fa935a9147e9eb5d71c). The change applies channel selection before packing non-D16 MUBUF `BUFFER_STORE_FORMAT_XYZW` with `32_32_UINT`. It follows the [desktop RDNA2 hardware measurements](https://github.com/scarlett-commons/scarlett-commons/blob/eb4431d8f7712d5b4f5bda54ef92595f9b8bbb2f/engine/tools/buffer_store_probe.py#L211-L254). The same synthetic fixture failed at `XYZW` on main in both HLSL and direct DXIL. It read `(17,34)` where the expected pair was `(17,68)`. The patched fixture passed all 13 raw-memory cases in both modes, including reserved selectors, MTBUF, neighboring formats and out-of-bounds guards. That is **0/1/0 per base mode, 1/0/0 per patched mode, zero capability skips**. **Tested** on RTX 4080 driver 621.01, Core i5-13600K, Windows 11 25H2 build 26200.9974, Rust 1.100.0 x64 MSVC and DXC 1.8.2502.11. The focused test was `gpu_mubuf_u32x2_xyzw_store_selects_channels` with `XCL_DIRECT_DXIL=0` and `1`. `cargo build --workspace --locked -j 4` succeeded. `cargo test --workspace --locked -j 4 --no-fail-fast -- --test-threads=4 --show-output` reported **1,436 passed, 0 failed, 47 ignored** across 37 harnesses, including 29 capability skips in the pass count. **Not tested** were Xbox-native behavior, wider W-selector variations, retail regression and performance.
This discussion has been locked. Commenting is limited to contributors.
No description provided.