Shaders: zero missing typed-buffer components #1515

Open
venglov wants to merge 2 commits from upstream-pr/1516 into main
venglov commented 2026-11-24 18:40:33 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by venglov on 2026-11-24T18:40:33Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5478174898 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1516). Originally posted by [venglov](https://github.com/venglov) on 2026-11-24T18:40:33Z. --- `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.
marquezinii commented 2026-11-24 20:03:03 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by marquezinii on 2026-11-24T19:12:57Z.


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.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7141768202 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1516#issuecomment-7141768202). Originally posted by [marquezinii](https://github.com/marquezinii) on 2026-11-24T19:12:57Z. --- 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.
sinan-cmyk commented 2026-11-24 20:03:12 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-24T19:33:52Z.


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).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7142277520 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1516#issuecomment-7142277520). Originally posted by [sinan-cmyk](https://github.com/sinan-cmyk) on 2026-11-24T19:33:52Z. --- ### 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).
Marvisak commented 2026-11-25 02:06:07 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T01:30:03Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7149616097 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1516#issuecomment-7149616097). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T01:30:03Z. --- <!-- 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)_
venglov commented 2026-11-25 15:04:17 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by venglov on 2026-11-25T14:21:44Z.


@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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7165159567 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1516#issuecomment-7165159567). Originally posted by [venglov](https://github.com/venglov) on 2026-11-25T14:21:44Z. --- @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.
Lyrnc commented 2026-11-26 16:40:29 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Lyrnc on 2026-11-26T16:40:29Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7197951278 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1516#issuecomment-7197951278). Originally posted by [Lyrnc](https://github.com/Lyrnc) on 2026-11-26T16:40:29Z. --- 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.
andrewpozdnakov7-jpg commented 2026-11-27 14:12:37 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-27T14:12:37Z.


I combined 308d7dc with the exact D16 work from #1940/#2843 on current main 63bcca4. Branch 7d17835 preserves the PR commits and resolves the overlap in format_load and its tests.

The new tbuffer_load_format_d16_xyzw test reads both packed dwords from R16_UNORM, R16_SNORM and R16_FLOAT. With exact rounding alone at 8bcc0bf, R16_UNORM gets the right first dword but the second is 0x3c000000, representing 1.0 in the missing W channel. The combination produces exact FP16 X and zeros for Y/Z/W in all six checks. A CPU lowering check also confirms the missing normalized channels no longer emit a legacy f32-to-f16 conversion.

On app-local WARP 1.0.22 with DXIL validation, all 12 D16 tests passed. The #1516 typed-buffer readback and CPU missing-channel check passed too, as did strict shader Clippy and the asset check.

The merge resolution and regression are ready for the existing PR. Please retain Git authorship if taking them, or add Co-authored-by: andrewpozdnakov7-jpg <[email protected]> if squashed.

AI-assisted with Codex. All readback data was synthetic.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7220491164 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1516#issuecomment-7220491164). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-27T14:12:37Z. --- I combined `308d7dc` with the exact D16 work from #1940/#2843 on current main `63bcca4`. [Branch 7d17835](https://github.com/andrewpozdnakov7-jpg/VIctory/tree/review/d16-rounded-and-zero-padded) preserves the PR commits and resolves the overlap in `format_load` and its tests. The new `tbuffer_load_format_d16_xyzw` test reads both packed dwords from R16_UNORM, R16_SNORM and R16_FLOAT. With exact rounding alone at `8bcc0bf`, R16_UNORM gets the right first dword but the second is `0x3c000000`, representing 1.0 in the missing W channel. The combination produces exact FP16 X and zeros for Y/Z/W in all six checks. A CPU lowering check also confirms the missing normalized channels no longer emit a legacy f32-to-f16 conversion. On app-local WARP 1.0.22 with DXIL validation, all 12 D16 tests passed. The #1516 typed-buffer readback and CPU missing-channel check passed too, as did strict shader Clippy and the asset check. The merge resolution and regression are ready for the existing PR. Please retain Git authorship if taking them, or add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>` if squashed. AI-assisted with Codex. All readback data was synthetic.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/1516:upstream-pr/1516'
git switch 'upstream-pr/1516'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/1516'
git switch 'upstream-pr/1516'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1516'
git switch 'upstream-pr/1516'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1516'
git switch 'main'
git merge --squash 'upstream-pr/1516'
git switch 'main'
git merge --ff-only 'upstream-pr/1516'
git switch 'main'
git merge 'upstream-pr/1516'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!1515
No description provided.