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

Open
mgunes1311-lab wants to merge 1 commit from upstream-pr/3316 into main
mgunes1311-lab commented 2026-11-26 17:18:50 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mgunes1311-lab on 2026-11-26T17:18:50Z.


Coordination

Claimed in https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7197202703 (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.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5514396814 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3316). Originally posted by [mgunes1311-lab](https://github.com/mgunes1311-lab) on 2026-11-26T17:18:50Z. --- ## Coordination Claimed in https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7197202703 (`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.
Dukestar69 commented 2026-11-26 17:27:59 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T17:27:59Z.

Review: APPROVED


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

<!-- greyfinch-sync:Marvisak/VIctory:review:6078365148 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3316#pullrequestreview-6078365148). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T17:27:59Z. **Review:** APPROVED --- 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).
fuzeofficlal commented 2026-11-26 20:24:25 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T20:24:25Z.

Review: APPROVED


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.
<!-- greyfinch-sync:Marvisak/VIctory:review:6080117952 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3316#pullrequestreview-6080117952). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T20:24:25Z. **Review:** APPROVED --- 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.
Jackster commented 2026-11-26 22:36:58 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Jackster on 2026-11-26T22:36:58Z.


Windows 11, 63bcca4 + this PR, Radeon RX 7900 XTX:

  • bvh_intersect_ray_uses_fixed_operands_and_omits_image_modifiers and bvh_intersect_ray_without_r128_or_dmask_bits_executes_on_gpu (filter bvh_intersect_ray): 2 passed (0.24 s).
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.

The second one executes on the device, so the fixed 4-VGPR/4-SGPR decode is exercised by a real dispatch here. Synthetic only. AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7204836219 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3316#issuecomment-7204836219). Originally posted by [Jackster](https://github.com/Jackster) on 2026-11-26T22:36:58Z. --- Windows 11, `63bcca4` + this PR, Radeon RX 7900 XTX: - `bvh_intersect_ray_uses_fixed_operands_and_omits_image_modifiers` and `bvh_intersect_ray_without_r128_or_dmask_bits_executes_on_gpu` (filter `bvh_intersect_ray`): 2 passed (0.24 s). - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. The second one executes on the device, so the fixed 4-VGPR/4-SGPR decode is exercised by a real dispatch here. Synthetic only. AI-assisted.
andrewpozdnakov7-jpg commented 2026-11-27 06:06:26 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-27T06:06:26Z.


Independent WARP run of head 182bc1f, to go with the RX 7900 XTX run above.

  • App-local WARP SM 6.6 (D3D12Core 1.620.2, d3d10warp 1.0.22), DXIL validation on, --features diagnostics,host.
  • bvh_intersect_ray: 2 passed, 0 failed (1.18 s). Both bvh_intersect_ray_uses_fixed_operands_and_omits_image_modifiers and bvh_intersect_ray_without_r128_or_dmask_bits_executes_on_gpu run; the second one dispatches on the device.
  • cargo clippy -p victory-shader --all-targets --features host -- -D warnings: clean.

Synthetic only and software WARP, so this adds the software side rather than hardware coverage; no game data.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7211221999 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3316#issuecomment-7211221999). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-27T06:06:26Z. --- Independent WARP run of head `182bc1f`, to go with the RX 7900 XTX run above. - App-local WARP SM 6.6 (`D3D12Core` 1.620.2, `d3d10warp` 1.0.22), DXIL validation on, `--features diagnostics,host`. - `bvh_intersect_ray`: 2 passed, 0 failed (1.18 s). Both `bvh_intersect_ray_uses_fixed_operands_and_omits_image_modifiers` and `bvh_intersect_ray_without_r128_or_dmask_bits_executes_on_gpu` run; the second one dispatches on the device. - `cargo clippy -p victory-shader --all-targets --features host -- -D warnings`: clean. Synthetic only and software WARP, so this adds the software side rather than hardware coverage; no game data.
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/3316:upstream-pr/3316'
git switch 'upstream-pr/3316'

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