Skip to content

shader: handle dword-straddling 16-bit typed buffer loads at byte offset 3 - #1669

Open
geiyiliyabumo wants to merge 1 commit into
Marvisak:mainfrom
geiyiliyabumo:fix/shader-tbuffer-16bit-straddle
Open

geiyiliyabumo wants to merge 1 commit into
Marvisak:mainfrom
geiyiliyabumo:fix/shader-tbuffer-16bit-straddle

Conversation

@geiyiliyabumo

Copy link
Copy Markdown
Contributor

Summary

  • Fixes 16-bit typed buffer format loads (total == 16: 16_* and 8_8_* families) in Lower::format_load (crates/victory-shader/src/emit/lower.rs) when the byte offset satisfies off & 3 == 3.
  • Previously format_load aligned at = off & !3, loaded a single dword, and shifted right by (off & 3) * 8, which left bits [15:8] zeroed whenever a 16-bit element straddled into dword at + 4.
  • Now total == 16 loads the second dword at select(byte == 3, at + 4, at) and merges (w0 >> 24) | (w1 << 8) when byte == 3. Re-reading at when byte != 3 ensures loads at buffer_end - 2 never touch past the buffer end; 8-bit formats (total == 8) remain single-dword loads.
  • Intentionally scoped only to 16-bit dword straddling (does not overlap with Shaders: preserve signaling NaNs in typed buffer loads #1642's float sNaN widening or Shaders: zero missing typed-buffer components #1516/Shaders: zero missing channels on typed buffer loads #1370's missing-channel filling).

Verification

  • cargo test -p victory-shader --lib: 121 passed, 0 failed, 1 ignored on both AMD Radeon RX 9060 XT (D3D12 hardware) and Microsoft Basic Render Driver (WARP), including tbuffer_16bit_format_loads_handle_dword_straddling_and_tail_bounds covering 16_UINT across all byte offsets 0..=6 (including straddling offset 3 and tail offset buffer_end - 2 on both 8-byte and 4-byte buffers), 16_SINT negative sign extension at offset 3, 16_FLOAT at offset 3, and 2-channel 8_8_UINT (tbuffer_load_format_xy) at offset 3.
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
  • cargo xtask policy: pass (154 files).

AI-assisted; synthetic tests only, no game files.

@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 on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (ffe310e), cargo test -p victory-shader --locked → 96 passed, 0 failed. Hardware/valu/waterfall execution tests are #[cfg(all(test, windows))] and run only on Windows; macOS covers lowering/structure unit tests.

Dword-straddling 16-bit typed buffer loads at byte offset 3 and tail bounds handled (tbuffer_load_format_offen, run_cases_with_uav_dwords); tests cover 16_UINT/16_SINT straddle and tail offsets on hardware/WARP.

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 (conflict in crates/victory-shader/src/emit/valu_tests.rs). It will be reviewed again once it is rebased.

From the earlier needs-work note, still open: evidence (console capture or a title program) that 16-bit format loads at byte offset 3 straddle two dwords on the console.


Generated by Claude Code

@Headache3318

Copy link
Copy Markdown

Tested on Linux (Arch, kernel 7.3.5, 3× RTX 4090 driver 620.73.04), Rust 1.98.1 (pinned). PR head 70d3a82 applied cleanly onto current main ccfb029.

  • cargo test -p victory-shader --locked: 96 passed, 0 failed, 1 ignored. All tests pass.
  • cargo clippy -p victory-shader --all-targets -- -D warnings: 2 unused-import errors in test code — these are pre-existing on main (ccfb029 fails identically). The PR introduces no new clippy warnings.

Not tested: Windows MSVC build, the title itself. AI-assisted.

@geiyiliyabumo

Copy link
Copy Markdown
Contributor Author

Rebased cleanly onto \main\ (\ccfb029). \cargo test -p victory-shader --locked tbuffer\ (verified on physical AMD RX 9060 XT + WARP + Microsoft \dxil.dll), \cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings, and \cargo xtask policy\ all pass.

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