Recompiler: typed buffer loads past the format and dst_sel differ from RDNA2 (tbuffer reads 0 and ignores dst_sel) #1414
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl#1414
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@Lyrnc on GitHub · 2026-11-24 15:44 UTC · original
Typed buffer loads (
fmt_comp/dst_selinrecomp/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 incrates/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.
offen.main930e8b4. The same loads went through a local test (not committed) usingprogandrunner::run_code, with the same rows at0x1000and 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_compreturns 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 identitydst_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#'sdst_sel. XCL applies it to both encodings (// format from the instruction (tbuffer) or from the V#; DST_SEL from the V#). On the hardware theMTBUFform returns the channels in order, whatever the swizzle:dst_seltbuffer_load_format_xyzw format:32_32_32_32_FLOAT(hardware)(x, y, z, w)(x, y, z, w)(x, y, z, w)(x, y, z, 1.0)(x, y, z, w)(x, y, z, 0)(x, y, z, w)(y, x, z, w)32_32_32_FLOATwith 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 withtbufferthrough a descriptor set to W = ONE, or to a BGRA swizzle, comes out different.3.
buffer_load_format_*(MUBUF, the V#'s format) does applydst_sel, but an identity swizzle that points at a missing channel reads the format's channels again, not 0 / 1:dst_sel)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_selof ONE or ZERO gives 1 or 0 on the hardware, as in XCL. So with those formats, an identitydst_selgives 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. Yourgpu_typed_buffer_loads_and_storescase 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 run16_16_FLOATitself throughMUBUF.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. Byte0xfeas8_UNORMreads0x3f7efeffon the hardware and0x3f7eff00in 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)isk'snbits 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:
fmt_comp, return 0 forc >= n.ENC_MTBUF, use the channels in order instead ofdst_sel.ENC_MUBUF, havedst_sel4..7 (X..W) on a missing channel read channelsel % 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.
@tiagonogueiraa-bit on GitHub · 2026-11-24 15:46 UTC · original
claiming, from your measurements:
tbuffer_load_format_*reads 0 in every channel its format lacks, the 4th too.dst_sel.buffer_load_format_*with an identity selector on a missing channel reads channelc mod nof 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_storeswhere 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: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_storeson #1423's head (7c6a1b9) would check the new cases G / H / I and the changed B against your hardware. Onmainthey should fail, and on the PR pass.Written with Claude Code (Claude Opus 5.5).
@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:
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-2238atmain06c9f550, theBufKind::FormatStorearm; nodst_selthere).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: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 (
_xyor_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.
@CryingLaughing on GitHub · 2026-11-26 13:54 UTC · original
I tested the store side on main
b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7and fork commit138e36d6f56e3b6112bf0fa935a9147e9eb5d71c. The change applies channel selection before packing non-D16 MUBUFBUFFER_STORE_FORMAT_XYZWwith32_32_UINT. It follows the desktop RDNA2 hardware measurements.The same synthetic fixture failed at
XYZWon 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_channelswithXCL_DIRECT_DXIL=0and1.cargo build --workspace --locked -j 4succeeded.cargo test --workspace --locked -j 4 --no-fail-fast -- --test-threads=4 --show-outputreported 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.