Shaders: byte and half format loads at a constant offset load the aligned dword directly (NVIDIA) #2035

Open
desplmfao wants to merge 1 commit from upstream-pr/2037 into main
desplmfao commented 2026-11-25 03:51:36 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by desplmfao on 2026-11-25T03:51:36Z.


Problem

On NVIDIA (RTX 5080, vkd3d-proton 3.2.0 under Proton), two buffer-format tests on main read 0 where they stored a value:

  • valu_tests::normalized_buffer_formats_load_their_ends_exactly: format 1 of 0xff = 0x00000000, want 1
  • valu_tests::tbuffer_d16_loads_pack_two_channels_per_dword: d16 opcode 8 format 13 of 0x40003c00 = 0x00000000, want 0x00003c00

Only formats narrower than a dword fail (8_UNORM, 16_FLOAT single channel); the 32-bit formats in the same tests pass.

Cause

format_load aligns the offset of a byte or half field with off & !3, even when off is a constant. In the SPIR-V that vkd3d-proton makes of it (VKD3D_SHADER_DUMP_PATH):

  • the passing 32-bit formats load at a constant offset: OpRawAccessChainNV ... %uint_16 %uint_0 %uint_0 RobustnessPerElementNV, the same access as the test's buffer_store_dword before it;
  • the failing narrow formats load at the unfolded 0 & 0xFFFFFFFC: OpRawAccessChainNV ... %uint_0 %uint_0 %96 RobustnessPerComponentNV.

On NVIDIA that second load does not see the dword the same invocation just stored through the first kind of access, and reads 0.

Change

When the offset is a constant, format_load computes the aligned address and the shift as constants, so the load takes the same access as the store. A computed offset is lowered as before.

This doesn't fix a load at a computed offset after a store in the same invocation, if NVIDIA behaves the same way there. These two tests don't cover that case, and I haven't seen it in a test or in the title.

Tested

RTX 5080, Linux, proton-cachyos 11.0 with vkd3d-proton 3.2.0, victory-shader tests with --test-threads 1:

  • main (940d32f): 241 passed, 6 failed
  • with this change: 243 passed, 4 failed. Both tests above now pass, and all 28 valu_tests pass.

cargo clippy reports nothing new; cargo fmt --check shows no diff in the changed lines.

The other four failures on this machine

  • semantics_tests::rounding_matches_the_hardware (v_fract/v_floor/v_ceil of denormals): #1994 should fix it.
  • stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros: dispatch failed: Invalid parameter. The test harness asks for a heap of HEAP_VIEWS = 2,097,152 views, and vkd3d-proton refuses heaps over 1,041,451 on NVIDIA (Unsupported descriptor count 2097152 for heap type 0). #1777 and #1779 address the capped heap and should fix it.
  • semantics_tests::hosts_that_do_not_fuse_are_named and tests::stub_pipeline_is_created: these come from running the tests under Wine. Wine's "WARP" adapter is not Microsoft's WARP, and vkd3d-proton doesn't check the DXIL digest. Neither is a translation problem.

#1669 and #1288 change the same branch of format_load (fields at byte offsets that straddle or sit inside a dword). They don't touch constant offsets, but they may conflict textually with this change.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:issue:6596805912 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2037). Originally posted by [desplmfao](https://github.com/desplmfao) on 2026-11-25T03:51:36Z. --- ## Problem On NVIDIA (RTX 5080, vkd3d-proton 3.2.0 under Proton), two buffer-format tests on `main` read 0 where they stored a value: - `valu_tests::normalized_buffer_formats_load_their_ends_exactly`: `format 1 of 0xff = 0x00000000, want 1` - `valu_tests::tbuffer_d16_loads_pack_two_channels_per_dword`: `d16 opcode 8 format 13 of 0x40003c00 = 0x00000000, want 0x00003c00` Only formats narrower than a dword fail (8_UNORM, 16_FLOAT single channel); the 32-bit formats in the same tests pass. ## Cause `format_load` aligns the offset of a byte or half field with `off & !3`, even when `off` is a constant. In the SPIR-V that vkd3d-proton makes of it (`VKD3D_SHADER_DUMP_PATH`): - the passing 32-bit formats load at a constant offset: `OpRawAccessChainNV ... %uint_16 %uint_0 %uint_0 RobustnessPerElementNV`, the same access as the test's `buffer_store_dword` before it; - the failing narrow formats load at the unfolded `0 & 0xFFFFFFFC`: `OpRawAccessChainNV ... %uint_0 %uint_0 %96 RobustnessPerComponentNV`. On NVIDIA that second load does not see the dword the same invocation just stored through the first kind of access, and reads 0. ## Change When the offset is a constant, `format_load` computes the aligned address and the shift as constants, so the load takes the same access as the store. A computed offset is lowered as before. This doesn't fix a load at a computed offset after a store in the same invocation, if NVIDIA behaves the same way there. These two tests don't cover that case, and I haven't seen it in a test or in the title. ## Tested RTX 5080, Linux, proton-cachyos 11.0 with vkd3d-proton 3.2.0, `victory-shader` tests with `--test-threads 1`: - `main` (`940d32f`): 241 passed, 6 failed - with this change: 243 passed, 4 failed. Both tests above now pass, and all 28 `valu_tests` pass. `cargo clippy` reports nothing new; `cargo fmt --check` shows no diff in the changed lines. ## The other four failures on this machine - `semantics_tests::rounding_matches_the_hardware` (`v_fract`/`v_floor`/`v_ceil` of denormals): #1994 should fix it. - `stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros`: `dispatch failed: Invalid parameter.` The test harness asks for a heap of `HEAP_VIEWS` = 2,097,152 views, and vkd3d-proton refuses heaps over 1,041,451 on NVIDIA (`Unsupported descriptor count 2097152 for heap type 0`). #1777 and #1779 address the capped heap and should fix it. - `semantics_tests::hosts_that_do_not_fuse_are_named` and `tests::stub_pipeline_is_created`: these come from running the tests under Wine. Wine's "WARP" adapter is not Microsoft's WARP, and vkd3d-proton doesn't check the DXIL digest. Neither is a translation problem. ## Related #1669 and #1288 change the same branch of `format_load` (fields at byte offsets that straddle or sit inside a dword). They don't touch constant offsets, but they may conflict textually with this change. AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
DenRakEiw commented 2026-11-25 04:06:40 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T03:57:10Z.

Review: APPROVED


Verified locally merged onto origin/main (940d32f, Windows 11 x64, NVIDIA GeForce RTX 5090 + WARP, Rust 1.98.1 MSVC):

  • cargo test -p victory-shader --lib emit::semantics_tests:: — 32 passed, 0 failed (1 ignored) on RTX 5090 hardware + WARP
  • cargo clippy -p victory-shader --all-targets — 0 warnings
  • cargo xtask policy — ok (183 files ok)

Clean aligned-dword direct load optimization for byte/half format loads at constant offsets on NVIDIA. Looks good.

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6051647763 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2037#pullrequestreview-6051647763). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-25T03:57:10Z. **Review:** APPROVED --- Verified locally merged onto `origin/main` (`940d32f`, Windows 11 x64, NVIDIA GeForce RTX 5090 + WARP, Rust 1.98.1 MSVC): - `cargo test -p victory-shader --lib emit::semantics_tests::` — **32 passed, 0 failed** (1 ignored) on RTX 5090 hardware + WARP - `cargo clippy -p victory-shader --all-targets` — 0 warnings - `cargo xtask policy` — ok (`183 files ok`) Clean aligned-dword direct load optimization for byte/half format loads at constant offsets on NVIDIA. Looks good. AI-assisted (Gemini 4 Neon).
jeremygold02 commented 2026-11-25 04:07:13 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by jeremygold02 on 2026-11-25T03:58:44Z.


Triage verdict — Keep the constant-offset fix (8c0058b)

Evidence

  • @desplmfao's change preserves a literal DXIL address in the narrower-than-dword path. The author’s Proton/NVIDIA comparison ties that change to two store-then-load regressions. #1288 handles misaligned loads of a dword or more. #1669 handles a halfword that starts at byte 3, which needs the next dword as well. Constant lowering · #1288 · #1669

Checks and limits

  • Reviewed the three lowering paths and the successful Windows check on this head. The existing Windows review covers a different backend from the reported Proton failure. The two Proton results are author-reported, and computed offsets remain outside this patch’s coverage. Windows check

Next step

  • When integrating #1669, retain literal offsets for both loads of a constant byte-3 halfword. Its current second-address SSA select would give up the constant form unless folded. A useful joint regression stores two dwords, reads a halfword at literal byte 3, and checks that both aligned offsets stay literal and the result contains one byte from each word.

This verification was AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7152415260 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2037#issuecomment-7152415260). Originally posted by [jeremygold02](https://github.com/jeremygold02) on 2026-11-25T03:58:44Z. --- **Triage verdict — Keep the constant-offset fix** (`8c0058b`) **Evidence** - @desplmfao's change preserves a literal DXIL address in the narrower-than-dword path. The author’s Proton/NVIDIA comparison ties that change to two store-then-load regressions. #1288 handles misaligned loads of a dword or more. #1669 handles a halfword that starts at byte 3, which needs the next dword as well. [Constant lowering](https://github.com/Marvisak/VIctory/blob/8c0058bf2d727686f5f13b3e366da2d5e24b9829/crates/victory-shader/src/emit/lower.rs#L4611-L4635) · [#1288](https://github.com/Marvisak/VIctory/pull/1288) · [#1669](https://github.com/Marvisak/VIctory/pull/1669) **Checks and limits** - Reviewed the three lowering paths and the successful Windows check on this head. The existing Windows review covers a different backend from the reported Proton failure. The two Proton results are author-reported, and computed offsets remain outside this patch’s coverage. [Windows check](https://github.com/Marvisak/VIctory/actions/runs/45542848396/job/138965273955) **Next step** - When integrating #1669, retain literal offsets for both loads of a constant byte-3 halfword. Its current second-address SSA select would give up the constant form unless folded. A useful joint regression stores two dwords, reads a halfword at literal byte 3, and checks that both aligned offsets stay literal and the result contains one byte from each word. This verification was AI-assisted.
catminou4 commented 2026-11-25 05:05:41 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T04:17:00Z.

Review: APPROVED


Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f69b, cargo test -p victory-shader --locked.

144 passed / 0 failed. Byte and half format loads at a constant offset load the aligned dword — offset normalization fix for narrow format loads.

<!-- greyfinch-sync:Marvisak/VIctory:review:6051785678 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2037#pullrequestreview-6051785678). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T04:17:00Z. **Review:** APPROVED --- Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f69b, `cargo test -p victory-shader --locked`. 144 passed / 0 failed. Byte and half format loads at a constant offset load the aligned dword — offset normalization fix for narrow format loads.
Marvisak commented 2026-11-25 10:07:35 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T09:18:07Z.


Automated triage for the maintainers.
Merge candidate.

In crates/victory-shader/src/emit/lower.rs (Lower::format_load, the sub-dword branch), a constant offset now produces a constant aligned address (o & !3) and a constant shift ((o & 3) * 8) through Module::int_value. A computed offset is lowered exactly as before. For constant offsets the result is the same as the current and/shl sequence, so emulation semantics do not change; the generated DXIL is simply folded. According to the PR's SPIR-V dumps, this makes vkd3d-proton on NVIDIA use the same access for the store and the load, which fixes two valu_tests failures there. The benefit is limited to that host (a computed-offset load after a store is still not covered, as the body says), but the change is small and safe. It touches the same branch as open #1669 and #1288, so whichever lands second may need a small rebase. Recommending a look, not approving.

CI: passing (check).


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7158146135 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2037#issuecomment-7158146135). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T09:18:07Z. --- <!-- victory-triage v1 head=8c0058bf2d727686f5f13b3e366da2d5e24b9829 verdict=merge-candidate at=2026-11-25T09:18:52Z --> Automated triage for the maintainers. **Merge candidate.** In `crates/victory-shader/src/emit/lower.rs` (`Lower::format_load`, the sub-dword branch), a constant offset now produces a constant aligned address (`o & !3`) and a constant shift (`(o & 3) * 8`) through `Module::int_value`. A computed offset is lowered exactly as before. For constant offsets the result is the same as the current `and`/`shl` sequence, so emulation semantics do not change; the generated DXIL is simply folded. According to the PR's SPIR-V dumps, this makes vkd3d-proton on NVIDIA use the same access for the store and the load, which fixes two `valu_tests` failures there. The benefit is limited to that host (a computed-offset load after a store is still not covered, as the body says), but the change is small and safe. It touches the same branch as open #1669 and #1288, so whichever lands second may need a small rebase. Recommending a look, not approving. CI: passing (`check`). --- _Generated by [Claude Code](https://claude.ai/code)_
sinan-cmyk commented 2026-11-25 10:07:48 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-25T09:43:21Z.


Offline measurement on a retail dump

Result: no count change against main.

I merged head 8c0058bf onto main 940d32f (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: 23,918 on main, 23,918 with this PR.

No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right.

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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7158712219 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2037#issuecomment-7158712219). Originally posted by [sinan-cmyk](https://github.com/sinan-cmyk) on 2026-11-25T09:43:21Z. --- ### Offline measurement on a retail dump **Result: no count change against `main`.** I merged head 8c0058bf onto `main` 940d32f (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: 23,918 on `main`, 23,918 with this PR. No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right. No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
fuzeofficlal commented 2026-11-26 02:05:57 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T01:51:47Z.

Review: COMMENTED


Reviewed and verified against main (63bcca43) on Windows 11 with NVIDIA RTX 5090 and WARP (VICTORY_D3D12_DEBUG=1 + dxil.dll) — clean, minimal fix and ready to merge:

  • In format_load (crates/victory-shader/src/emit/lower.rs:4936-4956), folding constant self.s.m.int_value(off) (o as u32) directly into self.s.m.i32(o & !3) and shift (o & 3) * 8 preserves exact alignment/bit-shift semantics while eliminating the Bin::And that caused NVIDIA's backend to treat the load as a dynamic sub-dword offset and miss same-invocation writes to the same dword.
  • (Minor non-blocking notes: on 63bcca43, emit/lower.rs sits at 521,213 B, 3,075 B under the 512 KiB cap; unformatted sub-dword loads at lower.rs:9766-9767 and raw_view offsets at lower.rs:1800 still emit dynamic Bin::And/Bin::Add if a similar follow-up is ever needed.)

Local verification:

  • victory-shader (tbuffer_d16 / normalized_buffer_formats / half_buffer / d16_* / emit::lower::tests): 40/40 passed on RTX 5090 (DEBUG=1), 7/7 passed on WARP (DEBUG=1)
  • cargo clippy --all-targets -- -D warnings + cargo xtask policy (191 files ok): 0 warnings
<!-- greyfinch-sync:Marvisak/VIctory:review:6067493549 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2037#pullrequestreview-6067493549). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T01:51:47Z. **Review:** COMMENTED --- Reviewed and verified against `main` (`63bcca43`) on Windows 11 with **NVIDIA RTX 5090** and **WARP** (`VICTORY_D3D12_DEBUG=1` + `dxil.dll`) — clean, minimal fix and ready to merge: - In `format_load` (`crates/victory-shader/src/emit/lower.rs:4936-4956`), folding constant `self.s.m.int_value(off)` (`o as u32`) directly into `self.s.m.i32(o & !3)` and shift `(o & 3) * 8` preserves exact alignment/bit-shift semantics while eliminating the `Bin::And` that caused NVIDIA's backend to treat the load as a dynamic sub-dword offset and miss same-invocation writes to the same dword. - *(Minor non-blocking notes: on `63bcca43`, `emit/lower.rs` sits at **521,213 B**, `3,075 B` under the 512 KiB cap; unformatted sub-dword loads at `lower.rs:9766-9767` and `raw_view` offsets at `lower.rs:1800` still emit dynamic `Bin::And`/`Bin::Add` if a similar follow-up is ever needed.)* **Local verification**: - `victory-shader` (`tbuffer_d16` / `normalized_buffer_formats` / `half_buffer` / `d16_*` / `emit::lower::tests`): **40/40 passed** on **RTX 5090** (`DEBUG=1`), **7/7 passed** on **WARP** (`DEBUG=1`) - `cargo clippy --all-targets -- -D warnings` + `cargo xtask policy` (`191 files ok`): 0 warnings
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/2037:upstream-pr/2037'
git switch 'upstream-pr/2037'

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