Shaders: emulate image_bvh intersect instructions as miss to enable lighting compute shaders #2191

Closed
github-bot wants to merge 1 commit from gh-pr/2191/head into gh-pr/2191/base
Owner

@⁠Xvania7 on GitHub · 2026-11-25 07:21 UTC · original
Xvania7:feat/bvh-raytracing-fallback → main · +199 −9 · 3 files · 1 commits · closed without merging

Closes #1533 (related to #876, #71, #274).

Summary

Emulates RDNA2 MIMG BVH traversal instructions image_bvh_intersect_ray (x0e6) and image_bvh64_intersect_ray (x0e7) as a clean miss so lighting/RTGI/shadow compute shaders (CS_RaytracingResolve,
tdirectionalshadows) translate and execute instead of failing with ShaderError::Unsupported:

  • crates/victory-shader/src/gfx10/fields.rs: Ensure image_bvh* allocate 4 destination dwords ( data).
  • crates/victory-shader/src/emit/lower.rs: Intercept image_bvh* in image(), zeroing all 4 destination VGPRs under the active lane guard (RDNA2 zero hit mask -> traversal miss), and map BVH descriptors as raw buffer views (kind 11) in descriptor_data().

Verification

  • Added synthetic tests image_bvh_intersect_ray_lowers_as_miss and image_bvh64_intersect_ray_lowers_as_miss in crates/victory-shader/src/emit/lower.rs.
  • Checked against retail shader corpus on RX 9070 XT stack in #1533 comments (10c287 handles both image_bvh_intersect_ray and image_bvh64_intersect_ray).
**@⁠Xvania7** on GitHub · 2026-11-25 07:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/2191) `Xvania7:feat/bvh-raytracing-fallback` → `main` · +199 −9 · 3 files · 1 commits · closed without merging Closes #1533 (related to #876, #71, #274). ### Summary Emulates RDNA2 MIMG BVH traversal instructions image_bvh_intersect_ray (x0e6) and image_bvh64_intersect_ray (x0e7) as a clean miss so lighting/RTGI/shadow compute shaders (CS_RaytracingResolve, tdirectionalshadows) translate and execute instead of failing with ShaderError::Unsupported: - crates/victory-shader/src/gfx10/fields.rs: Ensure image_bvh* allocate 4 destination dwords ( data). - crates/victory-shader/src/emit/lower.rs: Intercept image_bvh* in image(), zeroing all 4 destination VGPRs under the active lane guard (RDNA2 zero hit mask -> traversal miss), and map BVH descriptors as raw buffer views (kind 11) in descriptor_data(). ### Verification - Added synthetic tests image_bvh_intersect_ray_lowers_as_miss and image_bvh64_intersect_ray_lowers_as_miss in crates/victory-shader/src/emit/lower.rs. - Checked against retail shader corpus on RX 9070 XT stack in #1533 comments (10c287 handles both image_bvh_intersect_ray and image_bvh64_intersect_ray).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:57:58 +00:00
github-bot closed this pull request 2026-11-26 04:57:58 +00:00
Author
Owner

@⁠r4tedx on GitHub · 2026-11-25 07:42 UTC · original

A note for the triage, from reading this PR against main 940d32f: main already lowers both instructions for real, so this would replace a working lowering with a miss.

  • crates/victory-shader/src/emit/lower.rs:7661: if name.starts_with("image_bvh") { return self.bvh(inst, b, i); }
  • crates/victory-shader/src/emit/lower/bvh.rs: the ray against one box or triangle node, with the result in the hardware's encoding, so the program's own traversal runs (it came in with 0b35b7f, and #1198 was closed for it).

A miss for every ray was a reasonable way to get the lighting programs to translate while nothing lowered these instructions. On current main it would turn the real result into "nothing hit" for every program that traces. The PR also conflicts with main in the same function.

What still stops ray-tracing programs on main is elsewhere: in an offline count of 940d32f, the 40 compute programs that use image_bvh_intersect_ray are refused for a register joining a lane mask and data, read as data, which #1883 addresses (all 40 emit with it; with #2027 as well, all 40 validate). So my suggestion is to close this one in favour of what is in main, and if #1533 is still open, to point it at #1883.

Local title data was used for the count only (offline, CPU only, counts and reasons). Nothing was run for this comment beyond reading the code.

AI-assisted (Claude Code).

**@⁠r4tedx** on GitHub · 2026-11-25 07:42 UTC · [original](https://github.com/Marvisak/VIctory/pull/2191#issuecomment-7156165421) A note for the triage, from reading this PR against `main` `940d32f`: `main` already lowers both instructions for real, so this would replace a working lowering with a miss. - `crates/victory-shader/src/emit/lower.rs:7661`: `if name.starts_with("image_bvh") { return self.bvh(inst, b, i); }` - `crates/victory-shader/src/emit/lower/bvh.rs`: the ray against one box or triangle node, with the result in the hardware's encoding, so the program's own traversal runs (it came in with `0b35b7f`, and #1198 was closed for it). A miss for every ray was a reasonable way to get the lighting programs to translate while nothing lowered these instructions. On current `main` it would turn the real result into "nothing hit" for every program that traces. The PR also conflicts with `main` in the same function. What still stops ray-tracing programs on `main` is elsewhere: in an offline count of `940d32f`, the 40 compute programs that use `image_bvh_intersect_ray` are refused for `a register joining a lane mask and data, read as data`, which #1883 addresses (all 40 emit with it; with #2027 as well, all 40 validate). So my suggestion is to close this one in favour of what is in `main`, and if #1533 is still open, to point it at #1883. Local title data was used for the count only (offline, CPU only, counts and reasons). Nothing was run for this comment beyond reading the code. AI-assisted (Claude Code).
Author
Owner

@⁠Xvania7 on GitHub · 2026-11-25 07:44 UTC · original

Thanks @⁠r4tedx for checking against \940d32f! Confirmed \main\ now includes full BVH intersection lowering (\␀b35b7f\ / \lower/bvh.rs), so this miss fallback is superseded. Closing in favor of \main\ (and #1883 / #2027 for the remaining register-join validation on the 40 RT programs).

**@⁠Xvania7** on GitHub · 2026-11-25 07:44 UTC · [original](https://github.com/Marvisak/VIctory/pull/2191#issuecomment-7156206461) Thanks @⁠r4tedx for checking against \940d32f\! Confirmed \main\ now includes full BVH intersection lowering (\␀b35b7f\ / \lower/bvh.rs\), so this miss fallback is superseded. Closing in favor of \main\ (and #1883 / #2027 for the remaining register-join validation on the 40 RT programs).

Pull request closed

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!2191
No description provided.