Skip to content

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

Open
iurysf wants to merge 1 commit into
Marvisak:mainfrom
iurysf:mubuf-d16-loads
Open

iurysf wants to merge 1 commit into
Marvisak:mainfrom
iurysf:mubuf-d16-loads

Conversation

@iurysf

@iurysf iurysf commented Nov 25, 2026

Copy link
Copy Markdown

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

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>

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f, 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 Nov 25, 2026 •

Copy link
Copy Markdown
Owner

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

@sinan-cmyk

Copy link
Copy Markdown

Offline measurement on a retail dump

Result: no count change against main.

I merged head d9b823c 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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants