Typed buffer loads: channels past the format read 0 on RDNA2, not w = 1 (all 77 formats measured) #1060

Open
opened 2026-11-26 04:18:42 +00:00 by github-bot · 6 comments
Owner

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

format_load pads the 4th channel of a tbuffer_load_format_* with 1 / 1.0 when the format has fewer channels. RDNA2 hardware reads 0 there. I measured all 77 GFX10 buffer formats; the full result tables are below.

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 and runs tbuffer_load_format_xyzw … format:N offen for N = 1..77. The rows hold byte, half and float edge patterns, plus random values.
  • Translator: the same MTBUF words through build_valu_cs, on main ffe310e. The test stores the 4 input dwords to the UAV, loads them back with format:N and stores the 4 results. It ran on an RTX 5080 (driver 610.88) and on the same Radeon iGPU (picked with #94's VICTORY_ADAPTER). Both hosts give the same results, apart from NaN payloads of the 16-, 11- and 10-bit floats on NVIDIA.

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

1. Channels a format doesn't have read 0, including the 4th. This holds on gfx1036 for every format with fewer than 4 channels and every numeric kind. All 6,208 missing-channel values in the run are 0. main gives 1 / 1.0 in the 4th channel, so with these rows the translation differs from the hardware in 64 of 64 rows for each of the 49 formats with 1-3 channels.

The descriptor's dst_sel doesn't change this for tbuffer loads. In one kernel, with one descriptor, I set the V#'s dst_sel to identity, W=ONE, W=ZERO, all ONE, X↔Y, and X=W:

tbuffer_load_format_xyzw format:32_32_32_FLOAT buffer_load_format_xyzw, V# format 32_32_32_FLOAT
identity (x, y, z, 0) (x, y, z, x)
dst_sel_w = ONE (x, y, z, 0) (x, y, z, 1.0)
dst_sel_w = ZERO (x, y, z, 0) (x, y, z, 0)
X↔Y (x, y, z, 0) (y, x, z, x)

So the typed (MTBUF) form ignores dst_sel and reads 0 past the format, which matches the shortcut: in format_load. The MUBUF form applies dst_sel. With an identity swizzle the MUBUF form reads the format's own channels again in the missing slots: 32_FLOAT gives (x, x, x, x), 32_32_FLOAT gives (x, y, x, y), 8_8_UNORM gives (x, y, x, y). That second column doesn't affect format_load. It may matter for the typed-view path of buffer_load_format_*, where a D3D typed view reads (…, 0, 0, 1).

2. UNORM / SNORM: the hardware rounds correctly. #25's comment already notes that the division is 1 ULP off. For the record, on gfx1036 every UNORM and SNORM value in the run is the correctly rounded k / (2^n - 1) (0 exceptions over all 20 norm formats, the 2-, 10- and 11-bit fields included). The host's division is off on these values, identically on AMD and NVIDIA:

Format values differing from the hardware (1 ULP)
8_UNORM, 8_8_UNORM, 8_8_8_8_UNORM 16 of 64, 40 of 128, 80 of 256
8_8_SNORM, 8_8_8_8_SNORM 4 of 128, 6 of 256
16_UNORM, 16_16_UNORM, 16_16_16_16_UNORM 1, 1, 3
16_SNORM, 16_16_SNORM, 16_16_16_16_SNORM 1, 2, 3
10_11_11_UNORM, _SNORM 1, 6
11_11_10_UNORM, _SNORM 1, 4
10_10_10_2_SNORM 6
2_10_10_10_UNORM, _SNORM 3, 6

For example, byte 0xfe as 8_UNORM is 0x3f7efeff on the hardware and 0x3f7eff00 on the host.

The packed formats from #25 (10_11_11, 11_11_10, 10_10_10_2) otherwise match the hardware bit for bit, including the _FLOAT ones.

A fix. On Lyrnc/VIctory branch fix/tbuffer-hw-channels (one commit on ffe310e):

  • Missing channels read 0, and the doc comment says why.
  • The UNORM/SNORM conversion no longer divides. In binary, k / (2^n - 1) is the n bits of k repeating forever. So the f32 is the first 24 bits of that stream after its leading 1, rounded up when the 25th bit is set. A tie can't happen, because the stream never ends. In the lowering, k times a repeat constant gives the stream in an i64. k's f32 exponent gives the shift, and a 39-bit right shift gives 24 bits plus the rounding bit. SNORM is the same on |s| with n - 1 bits, then the sign, with the most negative value clamped to -1.
  • The typed loads diff test zero-pads snorm16x2 on the PC side. That was the only case with a 2-channel format loaded as 4. I couldn't run the diff tests, since they need the console compiler.
  • Two GPU tests in valu_tests.rs. One checks for 0 past the format's channels (8 formats). The other checks norm rounding for 15 formats, with every byte in every position and the values from the table above. Expected values come from an f64 division in the test, which is exact here.

Results on that branch:

Run RTX 5080 Radeon gfx1036 WARP
new tests pass pass pass
new tests with main's lower.rs fail (format 5: [1, 0, 0, 1], want 0 past channel 1) — —
all 77 formats × 64 rows against the hardware 0 differences (NaN payloads aside) 0 differences —

I'll open it as a PR once external pull requests are open again, or a maintainer can take it from the branch.

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

**@⁠Lyrnc** on GitHub · 2026-11-24 15:23 UTC · [original](https://github.com/Marvisak/VIctory/issues/1060) `format_load` pads the 4th channel of a `tbuffer_load_format_*` with `1` / `1.0` when the format has fewer channels. RDNA2 hardware reads 0 there. I measured all 77 GFX10 buffer formats; the full result tables are below. **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 and runs `tbuffer_load_format_xyzw … format:N offen` for N = 1..77. The rows hold byte, half and float edge patterns, plus random values. - **Translator:** the same `MTBUF` words through `build_valu_cs`, on `main` `ffe310e`. The test stores the 4 input dwords to the UAV, loads them back with `format:N` and stores the 4 results. It ran on an RTX 5080 (driver 610.88) and on the same Radeon iGPU (picked with #94's `VICTORY_ADAPTER`). Both hosts give the same results, apart from NaN payloads of the 16-, 11- and 10-bit floats on NVIDIA. This is RDNA2 desktop silicon, not the console's GPU. No game data was used. **1. Channels a format doesn't have read 0, including the 4th.** This holds on gfx1036 for every format with fewer than 4 channels and every numeric kind. All 6,208 missing-channel values in the run are 0. `main` gives 1 / 1.0 in the 4th channel, so with these rows the translation differs from the hardware in 64 of 64 rows for each of the 49 formats with 1-3 channels. The descriptor's `dst_sel` doesn't change this for `tbuffer` loads. In one kernel, with one descriptor, I set the V#'s `dst_sel` to identity, W=ONE, W=ZERO, all ONE, X↔Y, and X=W: | | `tbuffer_load_format_xyzw format:32_32_32_FLOAT` | `buffer_load_format_xyzw`, V# format `32_32_32_FLOAT` | |---|---|---| | identity | `(x, y, z, 0)` | `(x, y, z, x)` | | `dst_sel_w` = ONE | `(x, y, z, 0)` | `(x, y, z, 1.0)` | | `dst_sel_w` = ZERO | `(x, y, z, 0)` | `(x, y, z, 0)` | | X↔Y | `(x, y, z, 0)` | `(y, x, z, x)` | So the typed (`MTBUF`) form ignores `dst_sel` and reads 0 past the format, which matches the `shortcut:` in `format_load`. The `MUBUF` form applies `dst_sel`. With an identity swizzle the `MUBUF` form reads the format's own channels again in the missing slots: `32_FLOAT` gives `(x, x, x, x)`, `32_32_FLOAT` gives `(x, y, x, y)`, `8_8_UNORM` gives `(x, y, x, y)`. That second column doesn't affect `format_load`. It may matter for the typed-view path of `buffer_load_format_*`, where a D3D typed view reads `(…, 0, 0, 1)`. **2. UNORM / SNORM: the hardware rounds correctly.** #25's comment already notes that the division is 1 ULP off. For the record, on gfx1036 every UNORM and SNORM value in the run is the correctly rounded `k / (2^n - 1)` (0 exceptions over all 20 norm formats, the 2-, 10- and 11-bit fields included). The host's division is off on these values, identically on AMD and NVIDIA: | Format | values differing from the hardware (1 ULP) | |---|---| | `8_UNORM`, `8_8_UNORM`, `8_8_8_8_UNORM` | 16 of 64, 40 of 128, 80 of 256 | | `8_8_SNORM`, `8_8_8_8_SNORM` | 4 of 128, 6 of 256 | | `16_UNORM`, `16_16_UNORM`, `16_16_16_16_UNORM` | 1, 1, 3 | | `16_SNORM`, `16_16_SNORM`, `16_16_16_16_SNORM` | 1, 2, 3 | | `10_11_11_UNORM`, `_SNORM` | 1, 6 | | `11_11_10_UNORM`, `_SNORM` | 1, 4 | | `10_10_10_2_SNORM` | 6 | | `2_10_10_10_UNORM`, `_SNORM` | 3, 6 | For example, byte `0xfe` as `8_UNORM` is `0x3f7efeff` on the hardware and `0x3f7eff00` on the host. The packed formats from #25 (`10_11_11`, `11_11_10`, `10_10_10_2`) otherwise match the hardware bit for bit, including the `_FLOAT` ones. **A fix.** On `Lyrnc/VIctory` branch [`fix/tbuffer-hw-channels`](https://github.com/Lyrnc/VIctory/tree/fix/tbuffer-hw-channels) (one commit on `ffe310e`): - Missing channels read 0, and the doc comment says why. - The UNORM/SNORM conversion no longer divides. In binary, `k / (2^n - 1)` is the `n` bits of `k` repeating forever. So the f32 is the first 24 bits of that stream after its leading 1, rounded up when the 25th bit is set. A tie can't happen, because the stream never ends. In the lowering, `k` times a repeat constant gives the stream in an i64. `k`'s f32 exponent gives the shift, and a 39-bit right shift gives 24 bits plus the rounding bit. SNORM is the same on `|s|` with `n - 1` bits, then the sign, with the most negative value clamped to -1. - The `typed loads` diff test zero-pads `snorm16x2` on the PC side. That was the only case with a 2-channel format loaded as 4. I couldn't run the diff tests, since they need the console compiler. - Two GPU tests in `valu_tests.rs`. One checks for 0 past the format's channels (8 formats). The other checks norm rounding for 15 formats, with every byte in every position and the values from the table above. Expected values come from an f64 division in the test, which is exact here. Results on that branch: | Run | RTX 5080 | Radeon gfx1036 | WARP | |---|---|---|---| | new tests | pass | pass | pass | | new tests with `main`'s `lower.rs` | fail (`format 5: [1, 0, 0, 1], want 0 past channel 1`) | — | — | | all 77 formats × 64 rows against the hardware | 0 differences (NaN payloads aside) | 0 differences | — | I'll open it as a PR once external pull requests are open again, or a maintainer can take it from the branch. AI use: Claude Code (Claude Opus 5.5) wrote the probes, the comparison, the fix and this issue, and ran them on the GPUs above; the numbers come from those runs.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:18:42 +00:00
Author
Owner

@⁠MichaelSmithAI on GitHub · 2026-11-24 15:26 UTC · original

We checked the MTBUF changes on our integration branch on an RTX 4090 under Wine/vkd3d-proton 3.2. To isolate the load, we uploaded the input words before dispatch and supplied the integration branch’s heap bounds. Microsoft DXIL validation passed, and both the missing-channel and normalized-rounding tests passed.

With the same input, the old lowering returned [1, 0, 0, 1] for R8_UINT where the measured expectation is [1, 0, 0, 0]. With zero padding fixed but the old normalization retained, UNORM 3/255 produced 0x3c40c0c2; your conversion produced the expected 0x3c40c0c1. The original same-dispatch store/load fixture gave inconsistent inputs on our backend, so these comparisons use the seeded fixture throughout.

This covers translated MTBUF loads on an Int64-capable host. We did not test MUBUF descriptor swizzles or identify a title pass using the affected values.

**@⁠MichaelSmithAI** on GitHub · 2026-11-24 15:26 UTC · [original](https://github.com/Marvisak/VIctory/issues/1060#issuecomment-7136027629) We checked the MTBUF changes on our integration branch on an RTX 4090 under Wine/vkd3d-proton 3.2. To isolate the load, we uploaded the input words before dispatch and supplied the integration branch’s heap bounds. Microsoft DXIL validation passed, and both the missing-channel and normalized-rounding tests passed. With the same input, the old lowering returned `[1, 0, 0, 1]` for R8_UINT where the measured expectation is `[1, 0, 0, 0]`. With zero padding fixed but the old normalization retained, UNORM `3/255` produced `0x3c40c0c2`; your conversion produced the expected `0x3c40c0c1`. The original same-dispatch store/load fixture gave inconsistent inputs on our backend, so these comparisons use the seeded fixture throughout. This covers translated MTBUF loads on an Int64-capable host. We did not test MUBUF descriptor swizzles or identify a title pass using the affected values.
Author
Owner

@⁠DrDarkDK on GitHub · 2026-11-24 15:29 UTC · original

Following up on the Int64-capable host result above, I checked the emitted DXIL for the same synthetic MTBUF shaders on ffe310e and efd39a3. The patch adds the Int64 requirement bit (SFI0 & 0x8000) for 8_UNORM and 16_SNORM. The 8_UINT control keeps the same flags.

All three shaders ran on an RTX 4070 Ti and WARP, both with Int64ShaderOps=true. Do we support SM 6.6 devices without Int64ShaderOps? If so, the channel zero-fill could land separately because it doesn’t need the new normalization path.

AI-assisted with Codex.

**@⁠DrDarkDK** on GitHub · 2026-11-24 15:29 UTC · [original](https://github.com/Marvisak/VIctory/issues/1060#issuecomment-7136124691) Following up on the Int64-capable host result above, I checked the emitted DXIL for the same synthetic MTBUF shaders on `ffe310e` and `efd39a3`. The patch adds the Int64 requirement bit (`SFI0 & 0x8000`) for `8_UNORM` and `16_SNORM`. The `8_UINT` control keeps the same flags. All three shaders ran on an RTX 4070 Ti and WARP, both with `Int64ShaderOps=true`. Do we support SM 6.6 devices without `Int64ShaderOps`? If so, the channel zero-fill could land separately because it doesn’t need the new normalization path. *AI-assisted with Codex.*
Author
Owner

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

Thanks both.

@⁠DrDarkDK main already sets the Int64 flag in other places: mul_hi (v_mul_hi_u32 / _i32), src64 (64-bit VALU operands) and one more site. So a title whose shaders use any of those already needs Int64ShaderOps. Still, the two parts are independent, and I'm happy to split them: one commit for the zero-fill, one for the exact norm conversion. If devices without Int64 matter, the conversion can also be done with two 32-bit words instead of one i64. That costs a few more ops and needs no new requirement.

@⁠MichaelSmithAI About the same-dispatch fixture: the tests store the inputs into the UAV and load them back in the same thread, because View::RawUav starts zeroed. On D3D12 that store→load is ordered (same thread, same address), and the test asserts the inputs read back first (the stored inputs). If vkd3d-proton returned something else there, I'd be curious what it was. That might be worth its own look. If a seeded buffer is preferred, I can switch the tests to one.

AI use: Claude Code (Claude Opus 5.5) checked the flags in main and drafted this reply.

**@⁠Lyrnc** on GitHub · 2026-11-24 15:44 UTC · [original](https://github.com/Marvisak/VIctory/issues/1060#issuecomment-7136545834) Thanks both. @⁠DrDarkDK `main` already sets the Int64 flag in other places: `mul_hi` (`v_mul_hi_u32` / `_i32`), `src64` (64-bit VALU operands) and one more site. So a title whose shaders use any of those already needs `Int64ShaderOps`. Still, the two parts are independent, and I'm happy to split them: one commit for the zero-fill, one for the exact norm conversion. If devices without Int64 matter, the conversion can also be done with two 32-bit words instead of one i64. That costs a few more ops and needs no new requirement. @⁠MichaelSmithAI About the same-dispatch fixture: the tests store the inputs into the UAV and load them back in the same thread, because `View::RawUav` starts zeroed. On D3D12 that store→load is ordered (same thread, same address), and the test asserts the inputs read back first (`the stored inputs`). If vkd3d-proton returned something else there, I'd be curious what it was. That might be worth its own look. If a seeded buffer is preferred, I can switch the tests to one. AI use: Claude Code (Claude Opus 5.5) checked the flags in `main` and drafted this reply.
Author
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-24 15:56 UTC · original

I tried the 32-bit approach on top of Lyrnc’s exact efd39a3dd8eeefc67241ec7ba6d0175c1a73f83e: 78af907.

I added an assertion to tbuffer_load_norm_formats_round_correctly for the shader's Int64ShaderOps requirement. The same test sees SFI0 bit 0x8000 on the original branch and passes with the bit clear after the change. Microsoft DXIL validation and WARP readback also passed, including the existing exact UNORM/SNORM bit comparisons. The full shader suite passed with 122 tests and one ignored. A separate arithmetic check matched the correctly rounded float for all 131,070 inputs across 1–16-bit normalized widths.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-24 15:56 UTC · [original](https://github.com/Marvisak/VIctory/issues/1060#issuecomment-7136870006) I tried the 32-bit approach on top of Lyrnc’s exact `efd39a3dd8eeefc67241ec7ba6d0175c1a73f83e`: [78af907](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/78af9079ee8d1703878d2f2b794bd9f514a010ef). I added an assertion to `tbuffer_load_norm_formats_round_correctly` for the shader's `Int64ShaderOps` requirement. The same test sees SFI0 bit `0x8000` on the original branch and passes with the bit clear after the change. Microsoft DXIL validation and WARP readback also passed, including the existing exact UNORM/SNORM bit comparisons. The full shader suite passed with 122 tests and one ignored. A separate arithmetic check matched the correctly rounded float for all 131,070 inputs across 1–16-bit normalized widths.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 09:59 UTC · original

Automated triage for the maintainers.

Confirmed by reading main (940d32f): format_load in crates/victory-shader/src/emit/lower.rs pads a missing 4th channel with 1 / 1.0 (its doc comment says "0, 0, 1"), and UNORM/SNORM values are converted by a float division, which its own shortcut: note says can be 1 ULP off the hardware.

Open PRs that cover the two parts:

  • zero-fill of missing channels: #1516 ("zero missing typed-buffer components");
  • exact norm rounding without Int64ShaderOps: #1112, which refs this issue (the 32-bit approach discussed above).

PRs are open to everyone now. @⁠Lyrnc, if your branch fix/tbuffer-hw-channels carries anything those two do not (for example the 77-format comparison tests), please open it as a PR against current main, or add it to #1516 / #1112, so review has one place per change.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 09:59 UTC · [original](https://github.com/Marvisak/VIctory/issues/1060#issuecomment-7159073152) <!-- victory-issue-triage v1 verdict=confirmed seen=2026-11-24T15:56:37Z at=2026-11-25T09:50:38Z --> Automated triage for the maintainers. Confirmed by reading `main` (`940d32f`): `format_load` in `crates/victory-shader/src/emit/lower.rs` pads a missing 4th channel with 1 / 1.0 (its doc comment says "0, 0, 1"), and UNORM/SNORM values are converted by a float division, which its own `shortcut:` note says can be 1 ULP off the hardware. Open PRs that cover the two parts: - zero-fill of missing channels: #1516 ("zero missing typed-buffer components"); - exact norm rounding without `Int64ShaderOps`: #1112, which refs this issue (the 32-bit approach discussed above). PRs are open to everyone now. @⁠Lyrnc, if your branch `fix/tbuffer-hw-channels` carries anything those two do not (for example the 77-format comparison tests), please open it as a PR against current `main`, or add it to #1516 / #1112, so review has one place per change. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠Lyrnc on GitHub · 2026-11-26 16:40 UTC · original

Thanks. My branch carries nothing beyond those, so I won't open it:

  • Norm rounding: main already has it (da82e44, without Int64ShaderOps). The 77-format comparison against gfx1036 shows no UNORM/SNORM difference on 63bcca4.
  • Missing channels: #1516 covers them. I ran the same comparison on #1516 rebased onto 63bcca4, and it gives 0 differences from the hardware on the Radeon and on an RTX 5080. The numbers and a rebased branch are in my comment there.

Once #1516 is in, this issue can be closed.

**@⁠Lyrnc** on GitHub · 2026-11-26 16:40 UTC · [original](https://github.com/Marvisak/VIctory/issues/1060#issuecomment-7197954080) Thanks. My branch carries nothing beyond those, so I won't open it: - **Norm rounding:** `main` already has it (da82e44, without `Int64ShaderOps`). The 77-format comparison against gfx1036 shows no UNORM/SNORM difference on `63bcca4`. - **Missing channels:** #1516 covers them. I ran the same comparison on #1516 rebased onto `63bcca4`, and it gives 0 differences from the hardware on the Radeon and on an RTX 5080. The numbers and a rebased branch are in [my comment there](https://git.gtahub.st/github/Marvisak--VIctory/pulls/1516). Once #1516 is in, this issue can be closed.
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#1060
No description provided.