Shaders: zero missing typed-buffer components #1516

Open
github-bot wants to merge 2 commits from github-bot/gh-1516 into main AGit
Owner

@⁠venglov on GitHub · 2026-11-24 18:40 UTC · original
venglov:fix/mtbuf-missing-channels → main · +72 −18 · 3 files · 2 commits · open

tbuffer_load_format_xyzw currently returns 1 in W when the instruction's format has fewer than four components. The RDNA 2 MTBUF identity selection supplies zero for every missing component. This fixes the missing-channel behavior reported under VIC-BT-019 in #1242. RDNA 2 ISA §8.1.4, Table 31. Issue #1060 measured it on gfx1036 for all 77 buffer formats: every missing channel reads 0, the 4th included, and the typed loads ignore the descriptor's dst_sel.

The change zero-fills the missing channels after format conversion. It applies to GFX10 typed-format loads used for vertex fetch and compute. format_load's doc comment now states this rule in place of the old (0, 0, 0, 1) one.

The typed loads case in diff_tests.rs reads 16_16 SNORM through an R16G16_SNORM typed view, which gives (x, y, 0, 1). Its PC side now takes .xy and zeroes the rest, as #1370 did. The other loads in that case have four channels, or their PC side already pads with 0.

Verification

  • A portable lowering test checks one through four stored components. It failed on main and passed with this fix.
  • A Windows readback test checks 32_UINT and 32_FLOAT through synthetic tbuffer_load_format_xyzw instructions.
  • Rebased onto 940d32f. On Windows the workspace suite passed (703 passed, 10 ignored), and both Clippy configurations passed with warnings denied. The readback tests ran on WARP because the runner has no GPU. The verification branch adds only a CI workflow change on top of 308d7dc. Windows CI run
  • On macOS, the shader suite passed (145 passed, 2 ignored), and cargo xtask policy passed.
  • translated_compute_matches_pc is not run: it needs the console compiler, which neither CI nor I have.

In-game impact is unmeasured. OpenAI Codex assisted with the original change. Claude Code (Claude Opus 5.5) did the rebase and the differential-test update. The regression fixtures are synthetic.

**@⁠venglov** on GitHub · 2026-11-24 18:40 UTC · [original](https://github.com/Marvisak/VIctory/pull/1516) `venglov:fix/mtbuf-missing-channels` → `main` · +72 −18 · 3 files · 2 commits · open `tbuffer_load_format_xyzw` currently returns 1 in W when the instruction's format has fewer than four components. The RDNA 2 MTBUF identity selection supplies zero for every missing component. This fixes the missing-channel behavior reported under VIC-BT-019 in #1242. [RDNA 2 ISA §8.1.4, Table 31](https://docs.amd.com/api/khub/documents/Et~wpu9g~Ffl7d9q0QZ~Og/content#page=60). Issue #1060 measured it on gfx1036 for all 77 buffer formats: every missing channel reads 0, the 4th included, and the typed loads ignore the descriptor's `dst_sel`. The change zero-fills the missing channels after format conversion. It applies to GFX10 typed-format loads used for vertex fetch and compute. `format_load`'s doc comment now states this rule in place of the old `(0, 0, 0, 1)` one. The `typed loads` case in `diff_tests.rs` reads 16_16 SNORM through an `R16G16_SNORM` typed view, which gives `(x, y, 0, 1)`. Its PC side now takes `.xy` and zeroes the rest, as #1370 did. The other loads in that case have four channels, or their PC side already pads with 0. ## Verification - A portable lowering test checks one through four stored components. It failed on main and passed with this fix. - A Windows readback test checks `32_UINT` and `32_FLOAT` through synthetic `tbuffer_load_format_xyzw` instructions. - Rebased onto `940d32f`. On Windows the workspace suite passed (703 passed, 10 ignored), and both Clippy configurations passed with warnings denied. The readback tests ran on WARP because the runner has no GPU. The verification branch adds only a CI workflow change on top of `308d7dc`. [Windows CI run](https://github.com/venglov/VIctory/actions/runs/45632065120) - On macOS, the shader suite passed (145 passed, 2 ignored), and `cargo xtask policy` passed. - `translated_compute_matches_pc` is not run: it needs the console compiler, which neither CI nor I have. In-game impact is unmeasured. OpenAI Codex assisted with the original change. Claude Code (Claude Opus 5.5) did the rebase and the differential-test update. The regression fixtures are synthetic.
The "typed loads" differential case read 16_16 SNORM through an
R16G16_SNORM typed view, which gives (x, y, 0, 1). The console's
tbuffer_load_format_xyzw reads 0 in the 4th channel, as the translation
now does, so the PC side takes .xy and zeroes the rest itself.

format_load's comment now names the measurement the zero-fill rests on:
on gfx1036 the typed loads ignore dst_sel and read 0 past the format
(issue #1060).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:34:44 +00:00
Author
Owner

@⁠marquezinii on GitHub · 2026-11-24 19:12 UTC · original

Ran on an RTX 5070 (desktop, driver 621.40, the only adapter), Windows 11 26300, Rust 1.98.1 at 63be4e0. cargo test -p victory-shader --lib -- --test-threads=1 --nocapture gives 122 passed, 0 failed, 1 ignored.

Two notes for review:

  1. Same change as #1370. The lowering in both is out.resize(channels, 0) in format_load. #1370 adds hardware readbacks over 25 formats (passed on an RTX 5090 and, in my run, on an RTX 5070). This one adds a portable lowering test and rewrites the doc comment.
  2. diff_tests.rs isn't updated here. The typed loads case in CS_CASES compares the translation against the PC reading the same bytes through an R16G16_SNORM typed view, which returns (x, y, 0, 1). After this change the translation returns (x, y, 0, 0) for that format. #1370 changes the PC side to uint4(asuint(snorm16x2[e].xy), 0, 0) for that reason. I couldn't run that test here (it needs the console compiler and skips without it), so this is from reading the code: on a machine that has the compiler, I'd expect translated_compute_matches_pc to fail with this branch alone.
**@⁠marquezinii** on GitHub · 2026-11-24 19:12 UTC · [original](https://github.com/Marvisak/VIctory/pull/1516#issuecomment-7141768202) Ran on an RTX 5070 (desktop, driver 621.40, the only adapter), Windows 11 26300, Rust 1.98.1 at `63be4e0`. `cargo test -p victory-shader --lib -- --test-threads=1 --nocapture` gives 122 passed, 0 failed, 1 ignored. Two notes for review: 1. **Same change as #1370.** The lowering in both is `out.resize(channels, 0)` in `format_load`. #1370 adds hardware readbacks over 25 formats (passed on an RTX 5090 and, in my run, on an RTX 5070). This one adds a portable lowering test and rewrites the doc comment. 2. **`diff_tests.rs` isn't updated here.** The `typed loads` case in `CS_CASES` compares the translation against the PC reading the same bytes through an `R16G16_SNORM` typed view, which returns `(x, y, 0, 1)`. After this change the translation returns `(x, y, 0, 0)` for that format. #1370 changes the PC side to `uint4(asuint(snorm16x2[e].xy), 0, 0)` for that reason. I couldn't run that test here (it needs the console compiler and skips without it), so this is from reading the code: on a machine that has the compiler, I'd expect `translated_compute_matches_pc` to fail with this branch alone.
Author
Owner

@⁠sinan-cmyk on GitHub · 2026-11-24 19:33 UTC · original

Offline measurement on a retail dump, and the shader tests on Ada

Result: no count changes against main, and the tests pass on Ada.

Offline. I merged head 63be4e0 onto main ffe310e (clean merge) and ran victory translate --validate --list on shaders.rpf (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with main program by program (25,889 programs). Validated: 21,724 on both, 0 gained, 0 lost. No program changes its failure reason either.

This is the expected result for a correctness fix whose instructions sit behind the earlier failures on main. The count shows that the change rejects nothing. It does not show whether the output is right.

Tests. With the same merge, cargo test --locked -p victory-shader --lib passed 122, failed 0. The bitcode benchmark is ignored, as on main, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, with VICTORY_WARP unset.

No shader names or data are included, per the asset policy. AI-assisted (Claude Code).

**@⁠sinan-cmyk** on GitHub · 2026-11-24 19:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/1516#issuecomment-7142277520) ### Offline measurement on a retail dump, and the shader tests on Ada **Result: no count changes against `main`, and the tests pass on Ada.** **Offline.** I merged head 63be4e0 onto `main` ffe310e (clean merge) and ran `victory translate --validate --list` on `shaders.rpf` (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with `main` program by program (25,889 programs). Validated: 21,724 on both, 0 gained, 0 lost. No program changes its failure reason either. This is the expected result for a correctness fix whose instructions sit behind the earlier failures on `main`. The count shows that the change rejects nothing. It does not show whether the output is right. **Tests.** With the same merge, `cargo test --locked -p victory-shader --lib` passed 122, failed 0. The bitcode benchmark is ignored, as on `main`, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, with `VICTORY_WARP` unset. No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 01:30 UTC · original · edited 2026-11-25 16:06 UTC

Automated triage for the maintainers.

This pull request no longer merges cleanly into main (conflicts in crates/victory-shader/src/emit/lower.rs). It will be reviewed once it is rebased onto the current main. The earlier verdict (merge-candidate) was for an older state of main.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 01:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/1516#issuecomment-7149616097) · edited 2026-11-25 16:06 UTC <!-- victory-triage v1 head=308d7dc0ba7ea9babc0ac0da6552b24939f8b16f verdict=needs-rebase at=2026-11-25T16:03:30Z --> Automated triage for the maintainers. This pull request no longer merges cleanly into `main` (conflicts in `crates/victory-shader/src/emit/lower.rs`). It will be reviewed once it is rebased onto the current `main`. The earlier verdict (merge-candidate) was for an older state of `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠venglov on GitHub · 2026-11-25 14:21 UTC · original

@⁠marquezinii, thanks. You were right on the second point, and it is fixed in 308d7dc.

b = raw.XB_TypedLoad4(4 * e, FMT(1, 5)) is 16_16 SNORM. The translation now gives (x, y, 0, 0) there, and the R16G16_SNORM view gives (x, y, 0, 1). close() does not accept 1.0 against 0, so translated_compute_matches_pc would have failed. The PC side now reads uint4(asuint(snorm16x2[e].xy), 0, 0), the same as #1370, and the case's comment no longer states (0, 0, 0, 1). The other seven loads in the case are unaffected. Their formats have four channels, or their PC side already pads with 0 (ff, gg). Like you, I cannot run that test: it needs the console compiler.

On the first point, triage closed #1370 in favor of this PR, so this is now the only PR with the change. Its hardware coverage is in #1060, measured on gfx1036 across all 77 formats.

The PR is also rebased onto 940d32f, which resolves the valu_tests.rs conflict that triage reported. Both tests are kept. The readback test now uses main's mtbuf() helper in place of hand-encoded words, and the encoding is the same. format_load's comment now cites the #1060 measurement. Windows CI passed at 308d7dc: run. That covers 703 tests, both Clippy configurations, and the readback tests on WARP.

Written with Claude Code.

**@⁠venglov** on GitHub · 2026-11-25 14:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/1516#issuecomment-7165159567) @⁠marquezinii, thanks. You were right on the second point, and it is fixed in `308d7dc`. `b = raw.XB_TypedLoad4(4 * e, FMT(1, 5))` is 16_16 SNORM. The translation now gives `(x, y, 0, 0)` there, and the `R16G16_SNORM` view gives `(x, y, 0, 1)`. `close()` does not accept 1.0 against 0, so `translated_compute_matches_pc` would have failed. The PC side now reads `uint4(asuint(snorm16x2[e].xy), 0, 0)`, the same as #1370, and the case's comment no longer states `(0, 0, 0, 1)`. The other seven loads in the case are unaffected. Their formats have four channels, or their PC side already pads with 0 (`ff`, `gg`). Like you, I cannot run that test: it needs the console compiler. On the first point, triage closed #1370 in favor of this PR, so this is now the only PR with the change. Its hardware coverage is in #1060, measured on gfx1036 across all 77 formats. The PR is also rebased onto `940d32f`, which resolves the `valu_tests.rs` conflict that triage reported. Both tests are kept. The readback test now uses main's `mtbuf()` helper in place of hand-encoded words, and the encoding is the same. `format_load`'s comment now cites the #1060 measurement. Windows CI passed at `308d7dc`: [run](https://github.com/venglov/VIctory/actions/runs/45632065120). That covers 703 tests, both Clippy configurations, and the readback tests on WARP. Written with Claude Code.
Author
Owner

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

Hardware check of this PR on current main (63bcca4), against RDNA2 silicon. Result: 0 differences from the hardware on all 77 formats, on an AMD and an NVIDIA host.

Setup.

  • Reference: the gfx1036 measurements from #1060. An AMD Radeon iGPU (Ryzen 7 9800X3D, RDNA2), AMD driver 32.0.21042.62. tbuffer_load_format_xyzw with each of the 77 GFX10 formats over 64 rows of edge patterns and random values.
  • Translator: the same MTBUF words through build_valu_cs, run on two hosts:
    • the same Radeon iGPU;
    • an RTX 5080 (driver 610.88).
    • The adapter is picked by name with a local switch (not part of this PR).
  • Tree: this PR's two commits on 63bcca4. lower.rs conflicts with main, so I resolved it by hand:
    • kept this PR's doc comment and the out.resize(channels, 0);
    • dropped the old "Norm formats divide …" shortcut note, since da82e44 made that conversion exact;
    • kept the_code_table_starts_after_the_instructions from main next to the new test.
    • The result is on Lyrnc:rebase-1516-on-63bcca4, with the authorship kept. Feel free to take it.

Results (77 formats × 64 rows × 4 channels):

Tree Radeon gfx1036 RTX 5080
main 63bcca4 — 3,136 values differ: all in channel 3 (1 / 1.0 where the hardware reads 0), 49 formats × 64 rows
this PR on 63bcca4 0 0

main differs from the hardware only in that missing 4th channel. da82e44 already brought the norm conversions in line with the hardware, so no UNORM/SNORM value differs any more. With this PR on top, every value matches the hardware bit for bit on both hosts. NaN payloads aside, though none showed up in this run.

The PR's own tests also pass on the rebased tree, on the 5080:

  • missing_typed_buffer_channels_are_zero
  • typed_buffer_loads_zero_missing_channels
  • normalized_buffer_formats_*

AI use: Claude Code (Claude Opus 5.5) ran the comparison and the tests on the GPUs above, resolved the conflict and drafted this comment. The numbers come from those runs.

**@⁠Lyrnc** on GitHub · 2026-11-26 16:40 UTC · [original](https://github.com/Marvisak/VIctory/pull/1516#issuecomment-7197951278) Hardware check of this PR on current `main` (`63bcca4`), against RDNA2 silicon. Result: **0 differences from the hardware on all 77 formats**, on an AMD and an NVIDIA host. **Setup.** - **Reference:** the gfx1036 measurements from #1060. An AMD Radeon iGPU (Ryzen 7 9800X3D, RDNA2), AMD driver 32.0.21042.62. `tbuffer_load_format_xyzw` with each of the 77 GFX10 formats over 64 rows of edge patterns and random values. - **Translator:** the same `MTBUF` words through `build_valu_cs`, run on two hosts: - the same Radeon iGPU; - an RTX 5080 (driver 610.88). - The adapter is picked by name with a local switch (not part of this PR). - **Tree:** this PR's two commits on `63bcca4`. `lower.rs` conflicts with `main`, so I resolved it by hand: - kept this PR's doc comment and the `out.resize(channels, 0)`; - dropped the old "Norm formats divide …" shortcut note, since da82e44 made that conversion exact; - kept `the_code_table_starts_after_the_instructions` from `main` next to the new test. - The result is on [`Lyrnc:rebase-1516-on-63bcca4`](https://github.com/Lyrnc/VIctory/tree/rebase-1516-on-63bcca4), with the authorship kept. Feel free to take it. **Results (77 formats × 64 rows × 4 channels):** | Tree | Radeon gfx1036 | RTX 5080 | |---|---|---| | `main` `63bcca4` | — | 3,136 values differ: all in channel 3 (`1` / `1.0` where the hardware reads `0`), 49 formats × 64 rows | | this PR on `63bcca4` | **0** | **0** | `main` differs from the hardware only in that missing 4th channel. da82e44 already brought the norm conversions in line with the hardware, so no UNORM/SNORM value differs any more. With this PR on top, every value matches the hardware bit for bit on both hosts. NaN payloads aside, though none showed up in this run. The PR's own tests also pass on the rebased tree, on the 5080: - `missing_typed_buffer_channels_are_zero` - `typed_buffer_loads_zero_missing_channels` - `normalized_buffer_formats_*` AI use: Claude Code (Claude Opus 5.5) ran the comparison and the tests on the GPUs above, resolved the conflict and drafted this comment. The numbers come from those runs.
This pull request has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/lower.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1516/head:github-bot/gh-1516'
git switch 'github-bot/gh-1516'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1516'
git switch 'github-bot/gh-1516'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1516'
git switch 'github-bot/gh-1516'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1516'
git switch 'main'
git merge --squash 'github-bot/gh-1516'
git switch 'main'
git merge --ff-only 'github-bot/gh-1516'
git switch 'main'
git merge 'github-bot/gh-1516'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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!1516
No description provided.