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

Open
github-bot wants to merge 1 commit from github-bot/gh-2003 into main AGit
Owner

@⁠iurysf on GitHub · 2026-11-25 02:41 UTC · original
iurysf:mubuf-d16-loads → main · +145 −28 · 2 files · 1 commits · open

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).
**@⁠iurysf** on GitHub · 2026-11-25 02:41 UTC · [original](https://github.com/Marvisak/VIctory/pull/2003) `iurysf:mubuf-d16-loads` → `main` · +145 −28 · 2 files · 1 commits · open ## What's wrong Following closed PR [#1572](https://git.gtahub.st/github/Marvisak--VIctory/pulls/1572) and the [triage comment](https://git.gtahub.st/github/Marvisak--VIctory/pulls/1572), `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`).
Support MUBUF sub-dword _d16 and _d16_hi loads while preserving the untouched 16-bit half of the destination VGPR, reading the next aligned dword when a 16-bit load crosses at byte 3 mod 4, refusing constant-buffer sub-dword reads, and adding hardware/WARP coverage.

Co-authored-by: OpenBot <335604065+openbotgit[bot]@users.noreply.github.com>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:51:16 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 09:17 UTC · original · edited 2026-11-25 22:22 UTC

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

**@⁠Marvisak** on GitHub · 2026-11-25 09:17 UTC · [original](https://github.com/Marvisak/VIctory/pull/2003#issuecomment-7158129123) · edited 2026-11-25 22:22 UTC <!-- 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)_
Author
Owner

@⁠sinan-cmyk on GitHub · 2026-11-25 09:59 UTC · original

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

**@⁠sinan-cmyk** on GitHub · 2026-11-25 09:59 UTC · [original](https://github.com/Marvisak/VIctory/pull/2003#issuecomment-7159077702) ### 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 has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/valu_tests.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/2003/head:github-bot/gh-2003'
git switch 'github-bot/gh-2003'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2003'
git switch 'github-bot/gh-2003'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2003'
git switch 'github-bot/gh-2003'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2003'
git switch 'main'
git merge --squash 'github-bot/gh-2003'
git switch 'main'
git merge --ff-only 'github-bot/gh-2003'
git switch 'main'
git merge 'github-bot/gh-2003'
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!2003
No description provided.