Shaders: MUBUF sub-dword _d16 and _d16_hi loads #2001

Open
iurysf wants to merge 1 commit from upstream-pr/2003 into main
iurysf commented 2026-11-25 02:41:38 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by iurysf on 2026-11-25T02:41:38Z.


What's wrong

Following closed PR #1572 and the triage comment, main lowers the 32-bit-destination sub-dword MUBUF loads (buffer_load_ubyte, buffer_load_sbyte, buffer_load_ushort, buffer_load_sshort) and sub-dword stores, leaving the 6 untyped MUBUF sub-dword _d16 and _d16_hi loads unsupported:

  • buffer_load_ubyte_d16
  • buffer_load_ubyte_d16_hi
  • buffer_load_sbyte_d16
  • buffer_load_sbyte_d16_hi
  • buffer_load_short_d16
  • buffer_load_short_d16_hi

Two sub-dword edge cases were also missing in crates/victory-shader/src/emit/lower.rs:

  1. 16-bit MUBUF loads had a shortcut assuming they never cross a 4-byte dword boundary (starting at byte 3 mod 4).
  2. Sub-dword loads on a constant-buffer descriptor (ResourceType::Cbv) fell through to the dword CBV lowering path instead of failing cleanly.

What the fix does

  • crates/victory-shader/src/emit/lower.rs (+111/-28):
    • Extends Lower::buffer to recognize the 6 untyped MUBUF _d16 and _d16_hi load variants and record their bit width, signedness, and destination VGPR half (low vs high).
    • Preserves the untouched 16-bit half of the destination VGPR from inst.read(Reg::V(reg)), matching the existing LDS _d16/_d16_hi lowering pattern (ir.rs already records written vector destination dwords as reads).
    • Handles 16-bit MUBUF loads at byte 3 mod 4 by fetching the next aligned dword under a begin_guarded/end_guarded branch only for crossing lanes and merging its low byte before sign/zero extension.
    • Explicitly rejects sub-dword reads targeting a CBV with "a sub-dword read of a constant buffer".
  • crates/victory-shader/src/emit/valu_tests.rs (+62/-1):
    • Adds emit::valu_tests::d16_sub_dword_buffer_loads_preserve_the_other_half, encoding all 6 MUBUF _d16 / _d16_hi opcodes (0x20..=0x25) across every byte offset in two adjacent dwords (4..=11 for bytes, 4..=10 for halfwords including dword-crossing at byte 7), verifying sign/zero extension and preservation of the untouched half of 0xA5B6_C7D8 on both hardware GPU and WARP.

Branch mubuf-d16-loads (commit d9b823c on origin/main 42363ab): 2 files changed, 145 insertions(+), 28 deletions(-).

How it behaves after

Verified on Windows 11 with NVIDIA RTX 4070 + WARP (no changes to victory-gpu or victory-hle):

  • cargo clippy --workspace --all-targets -j 4 -- -D warnings: passed (0 warnings, 0 errors).
  • cargo test -p victory-shader -j 4: 244 passed; 3 failed; 3 ignored — new test emit::valu_tests::d16_sub_dword_buffer_loads_preserve_the_other_half passed on both hardware GPU and WARP (+1 passed over untouched origin/main 42363ab's 243 passed; 3 failed; 3 ignored with the exact same 3 pre-existing hardware failures: emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride, emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros, emit::synthetic_tests::gathers_at_a_level_match_the_hardware).
  • cargo test --workspace --exclude victory-shader --no-fail-fast -j 4: all other workspace crates passed (victory: 10 unit + 2 census, victory-core: 13, victory-formats: 38 passed / 5 ignored, victory-game: 15, victory-loader: 34 unit + 1 crash_log + 2 load_probe + 1 title_dlls, victory-pe: 36, victory-pipeline: 7, xtask: 6, victory-hle fidelityfx: 1 + no_dll_planting: 1), with only the identical pre-existing origin/main 42363ab failures in untouched victory-gpu (139 passed; 2 failed; 2 ignored: descriptor::host::tests::dynamic_slots_are_held_until_released, memory::tests::lists_share_a_table_and_copies_keep_their_views) and untouched victory-hle (142 passed; 1 failed; 0 ignored: modules::lifecycle::tests::showing_a_title_window_shows_its_stand_in).
  • cargo xtask policy: passed (asset policy: 182 files ok).
<!-- greyfinch-sync:Marvisak/VIctory:issue:6595958434 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2003). Originally posted by [iurysf](https://github.com/iurysf) on 2026-11-25T02:41:38Z. --- ## What's wrong Following closed PR [#1572](https://github.com/Marvisak/VIctory/pull/1572) and the [triage comment](https://github.com/Marvisak/VIctory/pull/1572#issuecomment-7148795801), `main` lowers the 32-bit-destination sub-dword MUBUF loads (`buffer_load_ubyte`, `buffer_load_sbyte`, `buffer_load_ushort`, `buffer_load_sshort`) and sub-dword stores, leaving the 6 untyped MUBUF sub-dword `_d16` and `_d16_hi` loads unsupported: - `buffer_load_ubyte_d16` - `buffer_load_ubyte_d16_hi` - `buffer_load_sbyte_d16` - `buffer_load_sbyte_d16_hi` - `buffer_load_short_d16` - `buffer_load_short_d16_hi` Two sub-dword edge cases were also missing in `crates/victory-shader/src/emit/lower.rs`: 1. 16-bit MUBUF loads had a shortcut assuming they never cross a 4-byte dword boundary (starting at byte `3 mod 4`). 2. Sub-dword loads on a constant-buffer descriptor (`ResourceType::Cbv`) fell through to the dword CBV lowering path instead of failing cleanly. ## What the fix does - **`crates/victory-shader/src/emit/lower.rs` (`+111/-28`)**: - Extends `Lower::buffer` to recognize the 6 untyped MUBUF `_d16` and `_d16_hi` load variants and record their bit width, signedness, and destination VGPR half (`low` vs `high`). - Preserves the untouched 16-bit half of the destination VGPR from `inst.read(Reg::V(reg))`, matching the existing LDS `_d16`/`_d16_hi` lowering pattern (`ir.rs` already records written vector destination dwords as reads). - Handles 16-bit MUBUF loads at byte `3 mod 4` by fetching the next aligned dword under a `begin_guarded`/`end_guarded` branch only for crossing lanes and merging its low byte before sign/zero extension. - Explicitly rejects sub-dword reads targeting a CBV with `"a sub-dword read of a constant buffer"`. - **`crates/victory-shader/src/emit/valu_tests.rs` (`+62/-1`)**: - Adds `emit::valu_tests::d16_sub_dword_buffer_loads_preserve_the_other_half`, encoding all 6 MUBUF `_d16` / `_d16_hi` opcodes (`0x20..=0x25`) across every byte offset in two adjacent dwords (`4..=11` for bytes, `4..=10` for halfwords including dword-crossing at byte `7`), verifying sign/zero extension and preservation of the untouched half of `0xA5B6_C7D8` on both hardware GPU and WARP. Branch `mubuf-d16-loads` (commit `d9b823c` on `origin/main` `42363ab`): `2 files changed, 145 insertions(+), 28 deletions(-)`. ## How it behaves after Verified on Windows 11 with NVIDIA RTX 4070 + WARP (no changes to `victory-gpu` or `victory-hle`): - `cargo clippy --workspace --all-targets -j 4 -- -D warnings`: passed (0 warnings, 0 errors). - `cargo test -p victory-shader -j 4`: **244 passed; 3 failed; 3 ignored** — new test `emit::valu_tests::d16_sub_dword_buffer_loads_preserve_the_other_half` **passed** on both hardware GPU and WARP (`+1 passed` over untouched `origin/main` `42363ab`'s `243 passed; 3 failed; 3 ignored` with the exact same 3 pre-existing hardware failures: `emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride`, `emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros`, `emit::synthetic_tests::gathers_at_a_level_match_the_hardware`). - `cargo test --workspace --exclude victory-shader --no-fail-fast -j 4`: all other workspace crates passed (`victory`: 10 unit + 2 `census`, `victory-core`: 13, `victory-formats`: 38 passed / 5 ignored, `victory-game`: 15, `victory-loader`: 34 unit + 1 `crash_log` + 2 `load_probe` + 1 `title_dlls`, `victory-pe`: 36, `victory-pipeline`: 7, `xtask`: 6, `victory-hle` `fidelityfx`: 1 + `no_dll_planting`: 1), with only the identical pre-existing `origin/main` `42363ab` failures in untouched `victory-gpu` (`139 passed; 2 failed; 2 ignored`: `descriptor::host::tests::dynamic_slots_are_held_until_released`, `memory::tests::lists_share_a_table_and_copies_keep_their_views`) and untouched `victory-hle` (`142 passed; 1 failed; 0 ignored`: `modules::lifecycle::tests::showing_a_title_window_shows_its_stand_in`). - `cargo xtask policy`: passed (`asset policy: 182 files ok`).
catminou4 commented 2026-11-25 03:03:16 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T02:56:53Z.

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 / 2 ignored. MUBUF sub-dword _d16/_d16_hi loads — extends the sub-dword load path; relates to the LDS sub-dword cluster (#632/#116/#101/#571/#996) but on the buffer side. Suite green.

<!-- greyfinch-sync:Marvisak/VIctory:review:6051183948 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2003#pullrequestreview-6051183948). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T02:56:53Z. **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 / 2 ignored. MUBUF sub-dword _d16/_d16_hi loads — extends the sub-dword load path; relates to the LDS sub-dword cluster (#632/#116/#101/#571/#996) but on the buffer side. Suite green.
Marvisak commented 2026-11-25 10:07:34 +00:00 (Migrated from github.com)

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


Automated triage for the maintainers.

Needs rebase. This PR no longer merges cleanly into main: main has moved since the last triage, and the branch now conflicts in crates/victory-shader/src/emit/valu_tests.rs. It will be reviewed again once it is rebased onto current main.

Previous verdict for this head: merge candidate.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7158129123 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2003#issuecomment-7158129123). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T09:17:20Z. --- <!-- victory-triage v1 head=d9b823c3cd5b46b7cf7b5f4e8dadf19a5f5a8707 verdict=needs-rebase at=2026-11-25T22:25:30Z --> Automated triage for the maintainers. **Needs rebase.** This PR no longer merges cleanly into `main`: `main` has moved since the last triage, and the branch now conflicts in `crates/victory-shader/src/emit/valu_tests.rs`. It will be reviewed again once it is rebased onto current `main`. Previous verdict for this head: merge candidate. --- _Generated by [Claude Code](https://claude.ai/code)_
sinan-cmyk commented 2026-11-25 10:07:54 +00:00 (Migrated from github.com)

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


Offline measurement on a retail dump

Result: no count change against main.

I merged head d9b823c3 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:7159077702 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2003#issuecomment-7159077702). Originally posted by [sinan-cmyk](https://github.com/sinan-cmyk) on 2026-11-25T09:59:36Z. --- ### Offline measurement on a retail dump **Result: no count change against `main`.** I merged head d9b823c3 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).
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/2003:upstream-pr/2003'
git switch 'upstream-pr/2003'

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