Shaders: a normalized buffer format's ends load as exactly 1.0 and -1.0 (port of VIctory#169) #190

Open
lcg007xd-c wants to merge 1 commit from upstream-pr/190 into main
lcg007xd-c commented 2026-11-25 20:25:51 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by lcg007xd-c on 2026-11-25T20:25:51Z.


Port of Marvisak/VIctory#169 by Duff. It is cherry-picked with -x, so the commit keeps its author and its upstream hash. This fork's main (000ffdd) does not have it, and it is not in #142.

What it fixes

The fork already gave UNORM's top code exactly 1.0, but SNORM's ends (the most negative code and the top one) did not load as exactly -1.0 and 1.0. Only the PR's second commit is ported: its first (d16 tbuffer packing) is already here as a103937.

Tested (Linux, Rust 1.98.1)

  • Upstream's GPU test is included (Windows). On Linux a temporary IR test found no SNORM end handling without the port; not committed.
  • cargo test -p victory-shader --lib on this branch alone: no failures.
  • It applies to main without conflicts, and does not depend on the other open ports.

Not run here: Windows/GPU tests, since I have no Windows machine.

🤖 Generated with Claude Code

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:issue:5498605943 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/190). Originally posted by [lcg007xd-c](https://github.com/lcg007xd-c) on 2026-11-25T20:25:51Z. --- Port of [Marvisak/VIctory#169](https://github.com/Marvisak/VIctory/pull/169) by Duff. It is cherry-picked with `-x`, so the commit keeps its author and its upstream hash. This fork's `main` (000ffdd) does not have it, and it is not in #142. ## What it fixes The fork already gave UNORM's top code exactly 1.0, but SNORM's ends (the most negative code and the top one) did not load as exactly -1.0 and 1.0. Only the PR's second commit is ported: its first (d16 tbuffer packing) is already here as `a103937`. ## Tested (Linux, Rust 1.98.1) - Upstream's GPU test is included (Windows). On Linux a temporary IR test found no SNORM end handling without the port; not committed. - `cargo test -p victory-shader --lib` on this branch alone: no failures. - It applies to `main` without conflicts, and does not depend on the other open ports. **Not run here:** Windows/GPU tests, since I have no Windows machine. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MamaLeVrai commented 2026-11-26 05:00:16 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by MamaLeVrai on 2026-11-26T05:00:16Z.


RDNA2 data point. This PR (7cf46b6) merged on main 4f62c2a, cargo test --release -p victory-shader --lib on an RX 6950 XT (Windows 11 build 26300, Rust 1.98.1):

  • main: 275 passed, 2 failed.
  • This PR: 276 passed, 2 failed, in 2 runs out of 2. The new test passes.

The 2 failures are the same as on main: the RDNA2 wave-size tests scalar_counted_in_a_divergent_loop_read_after_it and scalar_counted_in_nested_divergent_loops, fixed by #110 and #204. No regression here. Not run in the game.

harness machine: rx6950xt-w11 | AMD Radeon RX 6950 XT (RDNA2), driver 32.0.21045.29003 | 32 GB RAM | Windows 11 build 26300

AI-assisted (Claude Code); no game data.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7183092032 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/190#issuecomment-7183092032). Originally posted by [MamaLeVrai](https://github.com/MamaLeVrai) on 2026-11-26T05:00:16Z. --- RDNA2 data point. This PR (`7cf46b6`) merged on `main` `4f62c2a`, `cargo test --release -p victory-shader --lib` on an RX 6950 XT (Windows 11 build 26300, Rust 1.98.1): - `main`: 275 passed, 2 failed. - This PR: 276 passed, 2 failed, in 2 runs out of 2. The new test passes. The 2 failures are the same as on `main`: the RDNA2 wave-size tests `scalar_counted_in_a_divergent_loop_read_after_it` and `scalar_counted_in_nested_divergent_loops`, fixed by #110 and #204. No regression here. Not run in the game. harness machine: rx6950xt-w11 | AMD Radeon RX 6950 XT (RDNA2), driver 32.0.21045.29003 | 32 GB RAM | Windows 11 build 26300 AI-assisted (Claude Code); no game data.
adrianmjim commented 2026-11-26 19:44:22 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by adrianmjim on 2026-11-26T19:44:22Z.


Tested on Windows 11 with an RX 7900 XT (RDNA3, driver 32.0.32029.2010) and Rust 1.98.1. Head 7cf46b6, on its own base 000ffdd and also applied to current main 4f62c2a (applies cleanly).

Full shaders.rpf from the game, translate --validate --host-lanes 32-64:

  • Counts are the same as main: 26084 programs translated, the same IR instruction total, every emitted VS/PS/CS/MS program validates, and the same refusals (195 + 71).
  • 8163 programs get different DXIL: 6532 mesh, 1065 compute, 566 vertex, 0 pixel. The set is the same on 000ffdd and on 4f62c2a, so the clean-up passes do not hide or add changes.
  • Every changed program has a tbuffer_load_format_x/xy with 16_16_SNORM. The 1530 emitted programs whose only normalized tbuffer loads are UNORM are unchanged, so the UNORM rewrite gives identical DXIL.
  • Changed programs grow by +0.13% DXIL in total (median +48 bytes each).

Tests:

  • cargo test -p victory-shader --lib -- --test-threads=1 on the PR applied to 4f62c2a: 278 passed, 0 failed, 6 ignored (main: 277 / 0 / 6).
  • The new test runs on both the hardware adapter and WARP here, and passes.
  • With only the test applied to 4f62c2a (no fix), it also passes on both adapters. So this machine does not show the bug.
  • The test does reach this code: with the old FMax(-1) clamp removed as well, it fails on the hardware adapter (8_SNORM 0x80 loads as about -1.0079). On this GPU and WARP, the old divide plus clamp already gives exactly 1.0 and -1.0 for these values.

Not tested: RDNA4, runtime rendering, and whether the game's vertex data actually stores the SNORM end codes.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7201909824 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/190#issuecomment-7201909824). Originally posted by [adrianmjim](https://github.com/adrianmjim) on 2026-11-26T19:44:22Z. --- Tested on Windows 11 with an RX 7900 XT (RDNA3, driver 32.0.32029.2010) and Rust 1.98.1. Head 7cf46b6, on its own base 000ffdd and also applied to current main 4f62c2a (applies cleanly). Full shaders.rpf from the game, `translate --validate --host-lanes 32-64`: - Counts are the same as main: 26084 programs translated, the same IR instruction total, every emitted VS/PS/CS/MS program validates, and the same refusals (195 + 71). - 8163 programs get different DXIL: 6532 mesh, 1065 compute, 566 vertex, 0 pixel. The set is the same on 000ffdd and on 4f62c2a, so the clean-up passes do not hide or add changes. - Every changed program has a `tbuffer_load_format_x/xy` with 16_16_SNORM. The 1530 emitted programs whose only normalized tbuffer loads are UNORM are unchanged, so the UNORM rewrite gives identical DXIL. - Changed programs grow by +0.13% DXIL in total (median +48 bytes each). Tests: - `cargo test -p victory-shader --lib -- --test-threads=1` on the PR applied to 4f62c2a: 278 passed, 0 failed, 6 ignored (main: 277 / 0 / 6). - The new test runs on both the hardware adapter and WARP here, and passes. - With only the test applied to 4f62c2a (no fix), it also passes on both adapters. So this machine does not show the bug. - The test does reach this code: with the old FMax(-1) clamp removed as well, it fails on the hardware adapter (8_SNORM 0x80 loads as about -1.0079). On this GPU and WARP, the old divide plus clamp already gives exactly 1.0 and -1.0 for these values. Not tested: RDNA4, runtime rendering, and whether the game's vertex data actually stores the SNORM end codes.
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/190:upstream-pr/190'
git switch 'upstream-pr/190'

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/190'
git switch 'upstream-pr/190'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/190'
git switch 'upstream-pr/190'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/190'
git switch 'main'
git merge --squash 'upstream-pr/190'
git switch 'main'
git merge --ff-only 'upstream-pr/190'
git switch 'main'
git merge 'upstream-pr/190'
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
Belobug/VIctory-Belobug-AMD!190
No description provided.