tombox-xshader: structured-buffer GetDimensions stride is a DXC constant, and WARP hides stride mismatches that AMD hosts expose #376

Open
opened 2026-11-26 06:20:45 +00:00 by github-bot · 1 comment
Owner

@⁠SchmashinPrunes on GitHub · 2026-11-24 18:45 UTC · original

Library / area: tombox-xshader, the structured-buffer byte-offset reads (tb_sbw_* in hlsl.rs, used by s_buffer_load*), and how CI catches stride mismatches.

Two measured facts relevant to #346 and #347. Those PRs fix the stride mismatches GPU-based validation found on The Matrix Awakens, but the fallback they keep, and CI's ability to notice the problem, rest on assumptions that don't hold.

1. GetDimensions never returns the view's stride

tb_sbw_* is commented "the element stride is a property of the view, not of the shader, so it is queried", and it computes e = off / st from GetDimensions(n, st). DXC compiles the stride output of a structured buffer's GetDimensions to a constant: the size of the declared element.

struct E { uint w[4]; };
RWStructuredBuffer<E> b : register(u1);
RWStructuredBuffer<uint> o : register(u0);
[numthreads(1,1,1)] void main() { uint n, st; b.GetDimensions(n, st); o[0] = st; o[1] = n; }

dxc -T cs_6_0 emits bufferStore(..., i32 0, i32 0, i32 16, ...), so o[0] is always 16, whatever the view's StructureByteStride is. In other words, tb_sbw_* always addresses with the extent-guessed element size from sbuf_words. #347 still falls back to that size for slots where the FSSM table gives no single stride (conflicting strides, other spaces, bindless, no table).

2. WARP hides stride mismatches; AMD does not

I took scalar_smem_loads with the harness view fix from #375, kept the shader's TbElem at uint w[4] (16 bytes), and created the UAV with StructureByteStride = 64:

host result
WARP 47/47 pass
Radeon RX 9060 XT (TOMBOX_EXEC_HW=1) 34 failing

The AMD values match exactly one model: indexing uses the view's 64-byte stride, while st is the declared 16. For example, offset 0x24 in slot 1 gives e = 2, w[1], so the read lands at 128 + 2·64 + 4 = 260 bytes, which is word 65 (0xa5004141), and that's what AMD returned. WARP evidently addresses with the shader's declared element, so it gets the right word anyway.

So any remaining mismatch between a declared TbElem and a title's view can't be seen on WARP-only CI, but gives wrong data on AMD hosts and, per #346/#347, on RDNA2 under GPU-based validation.

Suggestions

  • For the fallback case, don't rely on GetDimensions for the stride. Fix the misleading comment either way.
  • A WARP-runnable guard: the exec harness could create views with the declared stride, as #375 makes it do for every ubufN, and a separate case could assert that the translator's declared element matches a given view stride. That would catch regressions without needing an AMD host.

Measurements: origin/main f89e410, RX 9060 XT on Windows 11, DXC from TOMBOX_DXC_DIR. Happy to rerun anything on that card.

🤖 Generated with Claude Code

**@⁠SchmashinPrunes** on GitHub · 2026-11-24 18:45 UTC · [original](https://github.com/omonkeyz/xbox-emulator/issues/376) **Library / area:** tombox-xshader, the structured-buffer byte-offset reads (`tb_sbw_*` in `hlsl.rs`, used by `s_buffer_load*`), and how CI catches stride mismatches. Two measured facts relevant to #346 and #347. Those PRs fix the stride mismatches GPU-based validation found on The Matrix Awakens, but the fallback they keep, and CI's ability to notice the problem, rest on assumptions that don't hold. ### 1. `GetDimensions` never returns the view's stride `tb_sbw_*` is commented "the element stride is a property of the view, not of the shader, so it is queried", and it computes `e = off / st` from `GetDimensions(n, st)`. DXC compiles the stride output of a structured buffer's `GetDimensions` to a constant: the size of the declared element. ```hlsl struct E { uint w[4]; }; RWStructuredBuffer<E> b : register(u1); RWStructuredBuffer<uint> o : register(u0); [numthreads(1,1,1)] void main() { uint n, st; b.GetDimensions(n, st); o[0] = st; o[1] = n; } ``` `dxc -T cs_6_0` emits `bufferStore(..., i32 0, i32 0, i32 16, ...)`, so `o[0]` is always 16, whatever the view's `StructureByteStride` is. In other words, `tb_sbw_*` always addresses with the extent-guessed element size from `sbuf_words`. #347 still falls back to that size for slots where the FSSM table gives no single stride (conflicting strides, other spaces, bindless, no table). ### 2. WARP hides stride mismatches; AMD does not I took `scalar_smem_loads` with the harness view fix from #375, kept the shader's `TbElem` at `uint w[4]` (16 bytes), and created the UAV with `StructureByteStride = 64`: | host | result | |---|---| | WARP | 47/47 pass | | Radeon RX 9060 XT (`TOMBOX_EXEC_HW=1`) | 34 failing | The AMD values match exactly one model: indexing uses the view's 64-byte stride, while `st` is the declared 16. For example, offset `0x24` in slot 1 gives `e = 2, w[1]`, so the read lands at 128 + 2·64 + 4 = 260 bytes, which is word 65 (`0xa5004141`), and that's what AMD returned. WARP evidently addresses with the shader's declared element, so it gets the right word anyway. So any remaining mismatch between a declared `TbElem` and a title's view can't be seen on WARP-only CI, but gives wrong data on AMD hosts and, per #346/#347, on RDNA2 under GPU-based validation. ### Suggestions - For the fallback case, don't rely on `GetDimensions` for the stride. Fix the misleading comment either way. - A WARP-runnable guard: the exec harness could create views with the declared stride, as #375 makes it do for every `ubufN`, and a separate case could assert that the translator's declared element matches a given view stride. That would catch regressions without needing an AMD host. Measurements: `origin/main` f89e410, RX 9060 XT on Windows 11, DXC from `TOMBOX_DXC_DIR`. Happy to rerun anything on that card. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:20:45 +00:00
Author
Owner

@⁠SchmashinPrunes on GitHub · 2026-11-25 15:30 UTC · original

Update: #347, now on main, sizes structured-buffer elements from the FSSM stride table, and slots that the PSV marks as raw are now declared ByteAddressBuffer. So the cases measured here are covered whenever the table gives a stride.

What remains is the fallback, where there's no single FSSM stride. There, tb_sbw_* still calls GetDimensions, which DXC folds to the declared element size. The comment above it is therefore misleading, and a mismatch with the title's view would still read the wrong words on AMD hosts. Fixing that properly needs raw views from d3d12_xs, so I'm leaving it as a note here rather than a PR.

**@⁠SchmashinPrunes** on GitHub · 2026-11-25 15:30 UTC · [original](https://github.com/omonkeyz/xbox-emulator/issues/376#issuecomment-7166963236) Update: #347, now on main, sizes structured-buffer elements from the FSSM stride table, and slots that the PSV marks as raw are now declared `ByteAddressBuffer`. So the cases measured here are covered whenever the table gives a stride. What remains is the fallback, where there's no single FSSM stride. There, `tb_sbw_*` still calls `GetDimensions`, which DXC folds to the declared element size. The comment above it is therefore misleading, and a mismatch with the title's view would still read the wrong words on AMD hosts. Fixing that properly needs raw views from d3d12_xs, so I'm leaving it as a note here rather than a PR.
This discussion has been locked. Commenting is limited to contributors.
No description provided.