Shaders: decode fixed 4-VGPR data and 4-SGPR rsrc for image_bvh_intersect_ray #3316

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

@⁠mgunes1311-lab on GitHub · 2026-11-26 17:18 UTC · original
mgunes1311-lab:shader-bvh-mimg-operands → main · +274 −28 · 2 files · 1 commits · open

Coordination

Claimed in #1633 (Shaders: decode fixed 4-VGPR data and 4-SGPR resource operands and SP3 formatting for image_bvh_intersect_ray). Checked STATUS.md, CLAIMS.md, and forge/main — zero conflict with open PRs or forge/main hunks in crates/victory-shader/src/gfx10/{fields,sp3}.rs.

Problem

Per the AMD RDNA2 ISA manual (Chapter 11, MIMG image_bvh_intersect_ray 0xe6 and image_bvh64_intersect_ray 0xe7) and LLVM's MIMG_IntersectRay definition:

  1. Both instructions unconditionally write 4 VGPRs (v[dst:dst+3]) and read a 4-SGPR (128-bit, s[rsrc:rsrc+3]) BVH resource descriptor regardless of raw dmask, r128, d16, tfe, or lwe bits in the MIMG header. Previously Encoding::Mimg sized data from dmask.count_ones().max(1) (with d16/tfe/lwe) and rsrc as 8 SGPRs whenever r128 == 0, breaking descriptor tracking and result sizing if r128 or dmask bits are cleared.
  2. SP3 / LLVM disassembly prints only vdst, vaddr, srsrc plus cache flags and a16, omitting image-only modifiers (dmask:, dim:SQ_RSRC_IMG_*, r128, unorm, d16, tfe, lwe).

Fix

  • In gfx10::fields (Encoding::Mimg), force data to 4 VGPRs (ignoring d16, tfe, lwe) and rsrc to 4 SGPRs whenever name.starts_with("image_bvh").
  • In gfx10::sp3 (Fields::Image), emit only cache flags and a16 after the operands for image_bvh*.

Verification

  • Added gfx10::sp3::tests::bvh_intersect_ray_uses_fixed_operands_and_omits_image_modifiers testing SP3 disassembly of image_bvh_intersect_ray (standard + dlc glc a16) and NSA image_bvh64_intersect_ray, plus operand decoding with dmask=0, r128=0, d16=1, tfe=1, lwe=1.
  • Added gfx10::sp3::tests::bvh_intersect_ray_without_r128_or_dmask_bits_executes_on_gpu compiling and dispatching a synthetic compute shader with image_bvh_intersect_ray encoded with dmask=0, r128=0 (and s16 clobbered) on both hardware D3D12 and WARP, verifying DXIL validation and GPU ray-box hit output.
  • Ran cargo test -p victory-shader --all-features --locked bvh_intersect_ray, cargo clippy --workspace --all-targets --all-features --locked -- -D warnings, and cargo xtask policy on Windows 11 (x86_64-pc-windows-msvc).

AI-assisted contribution (Google Antigravity); all code, DXIL validation, and D3D12/WARP GPU tests were locally executed and verified.

**@⁠mgunes1311-lab** on GitHub · 2026-11-26 17:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/3316) `mgunes1311-lab:shader-bvh-mimg-operands` → `main` · +274 −28 · 2 files · 1 commits · open ## Coordination Claimed in https://git.gtahub.st/github/Marvisak--VIctory/issues/1633 (`Shaders: decode fixed 4-VGPR data and 4-SGPR resource operands and SP3 formatting for image_bvh_intersect_ray`). Checked `STATUS.md`, `CLAIMS.md`, and `forge/main` — zero conflict with open PRs or `forge/main` hunks in `crates/victory-shader/src/gfx10/{fields,sp3}.rs`. ## Problem Per the AMD RDNA2 ISA manual (Chapter 11, MIMG `image_bvh_intersect_ray` `0xe6` and `image_bvh64_intersect_ray` `0xe7`) and LLVM's `MIMG_IntersectRay` definition: 1. Both instructions unconditionally write 4 VGPRs (`v[dst:dst+3]`) and read a 4-SGPR (`128`-bit, `s[rsrc:rsrc+3]`) BVH resource descriptor regardless of raw `dmask`, `r128`, `d16`, `tfe`, or `lwe` bits in the MIMG header. Previously `Encoding::Mimg` sized `data` from `dmask.count_ones().max(1)` (with `d16`/`tfe`/`lwe`) and `rsrc` as 8 SGPRs whenever `r128 == 0`, breaking descriptor tracking and result sizing if `r128` or `dmask` bits are cleared. 2. SP3 / LLVM disassembly prints only `vdst, vaddr, srsrc` plus cache flags and `a16`, omitting image-only modifiers (`dmask:`, `dim:SQ_RSRC_IMG_*`, `r128`, `unorm`, `d16`, `tfe`, `lwe`). ## Fix - In `gfx10::fields` (`Encoding::Mimg`), force `data` to 4 VGPRs (ignoring `d16`, `tfe`, `lwe`) and `rsrc` to 4 SGPRs whenever `name.starts_with("image_bvh")`. - In `gfx10::sp3` (`Fields::Image`), emit only cache flags and `a16` after the operands for `image_bvh*`. ## Verification - Added `gfx10::sp3::tests::bvh_intersect_ray_uses_fixed_operands_and_omits_image_modifiers` testing SP3 disassembly of `image_bvh_intersect_ray` (standard + `dlc glc a16`) and NSA `image_bvh64_intersect_ray`, plus operand decoding with `dmask=0, r128=0, d16=1, tfe=1, lwe=1`. - Added `gfx10::sp3::tests::bvh_intersect_ray_without_r128_or_dmask_bits_executes_on_gpu` compiling and dispatching a synthetic compute shader with `image_bvh_intersect_ray` encoded with `dmask=0, r128=0` (and `s16` clobbered) on both hardware D3D12 and WARP, verifying DXIL validation and GPU ray-box hit output. - Ran `cargo test -p victory-shader --all-features --locked bvh_intersect_ray`, `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`, and `cargo xtask policy` on Windows 11 (`x86_64-pc-windows-msvc`). AI-assisted contribution (Google Antigravity); all code, DXIL validation, and D3D12/WARP GPU tests were locally executed and verified.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 17:20:42 +00:00
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 17:27 UTC · original · approved these changes

Reviewed the diff and verified locally on Windows 11 x64:

  • Decoding image_bvh* with fixed 4-VGPR data (ignoring dmask/d16/tfe/lwe) and 4-SGPR rsrc (ignoring r128) plus matching SP3 formatting accurately reflects the RDNA2 ISA encoding.
  • cargo test -p victory-shader --lib gfx10:: -- --test-threads=1: 17 passed, 0 failed (including bvh_intersect_ray_uses_fixed_operands_and_omits_image_modifiers).
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-11-26 17:27 UTC · [original](https://github.com/Marvisak/VIctory/pull/3316#pullrequestreview-6078365148) · **approved these changes** Reviewed the diff and verified locally on Windows 11 x64: - Decoding `image_bvh*` with fixed 4-VGPR `data` (ignoring `dmask`/`d16`/`tfe`/`lwe`) and 4-SGPR `rsrc` (ignoring `r128`) plus matching SP3 formatting accurately reflects the RDNA2 ISA encoding. - `cargo test -p victory-shader --lib gfx10:: -- --test-threads=1`: 17 passed, 0 failed (including `bvh_intersect_ray_uses_fixed_operands_and_omits_image_modifiers`). - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 20:24 UTC · original · approved these changes

LGTM on decoding and SP3 formatting for image_bvh_intersect_ray / image_bvh64_intersect_ray.

Verified

  • crates/victory-shader/src/gfx10/fields.rs (Encoding::Mimg): image_bvh* forces 4-VGPR data (ignoring dmask/d16/tfe/lwe) and 4-SGPR rsrc (ignoring r128), matching RDNA2 ISA operand widths and existing image_addr_dwords counts (11/8 and 12/9).
  • crates/victory-shader/src/gfx10/sp3.rs: omits image-only modifiers while keeping cache flags and a16; both standard and NSA disassembly fixtures match.
  • Local checks (synthetic tests only):
    • cargo run --locked -p xtask -- policy: 191 files ok
    • cargo clippy --locked -p victory-shader --all-targets -- -D warnings (default & --all-features): clean
    • VICTORY_WARP=0 (RTX 5090): gfx10:: 18 passed, 0 failed; emit::bvh_tests:: 14 passed, 0 failed; gfx10:: ir:: structure:: resource:: io:: 79 passed, 0 failed, 1 ignored
    • VICTORY_WARP=1: bvh_intersect_ray 2 passed, 0 failed; emit::bvh_tests:: 14 passed, 0 failed (including dxil.dll validation in bvh_intersect_ray_without_r128_or_dmask_bits_executes_on_gpu)

Minor non-blocking nits

  • rustfmt --edition 2024 reports formatting diffs in touched hunks at crates/victory-shader/src/gfx10/fields.rs:381 and crates/victory-shader/src/gfx10/sp3.rs:975, 995, 1093, 1158.
  • crates/victory-shader/src/gfx10/sp3.rs:1020: the comment says Clobber s16..s19, though only s16 is written (0xDEAD_BEEF), and resource.rs:1349 already rejects non-4-dword descriptors before reading s16.
  • Note for non-canonical encodings: emit/lower.rs:8390 still rejects *tfe || *lwe before reaching self.bvh (8394), which is harmless for valid shaders since AMD requires those bits to be zero.
**@⁠fuzeofficlal** on GitHub · 2026-11-26 20:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/3316#pullrequestreview-6080117952) · **approved these changes** LGTM on decoding and SP3 formatting for `image_bvh_intersect_ray` / `image_bvh64_intersect_ray`. ### Verified - `crates/victory-shader/src/gfx10/fields.rs` (`Encoding::Mimg`): `image_bvh*` forces 4-VGPR `data` (ignoring `dmask`/`d16`/`tfe`/`lwe`) and 4-SGPR `rsrc` (ignoring `r128`), matching RDNA2 ISA operand widths and existing `image_addr_dwords` counts (`11`/`8` and `12`/`9`). - `crates/victory-shader/src/gfx10/sp3.rs`: omits image-only modifiers while keeping cache flags and `a16`; both standard and NSA disassembly fixtures match. - Local checks (synthetic tests only): - `cargo run --locked -p xtask -- policy`: `191 files ok` - `cargo clippy --locked -p victory-shader --all-targets -- -D warnings` (default & `--all-features`): clean - `VICTORY_WARP=0` (RTX 5090): `gfx10::` 18 passed, 0 failed; `emit::bvh_tests::` 14 passed, 0 failed; `gfx10:: ir:: structure:: resource:: io::` 79 passed, 0 failed, 1 ignored - `VICTORY_WARP=1`: `bvh_intersect_ray` 2 passed, 0 failed; `emit::bvh_tests::` 14 passed, 0 failed (including `dxil.dll` validation in `bvh_intersect_ray_without_r128_or_dmask_bits_executes_on_gpu`) ### Minor non-blocking nits - `rustfmt --edition 2024` reports formatting diffs in touched hunks at `crates/victory-shader/src/gfx10/fields.rs:381` and `crates/victory-shader/src/gfx10/sp3.rs:975`, `995`, `1093`, `1158`. - `crates/victory-shader/src/gfx10/sp3.rs:1020`: the comment says `Clobber s16..s19`, though only `s16` is written (`0xDEAD_BEEF`), and `resource.rs:1349` already rejects non-4-dword descriptors before reading `s16`. - Note for non-canonical encodings: `emit/lower.rs:8390` still rejects `*tfe || *lwe` before reaching `self.bvh` (`8394`), which is harmless for valid shaders since AMD requires those bits to be zero.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/3316/head:github-bot/gh-3316'
git switch 'github-bot/gh-3316'

Merge

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