feat(shader): implement image_bvh64_intersect_ray #524

Merged
DotDebian merged 1 commit from upstream-pr/524 into main 2026-10-05 05:08:57 +00:00
DotDebian commented 2026-10-04 14:46:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by DotDebian on 2026-10-04T14:46:20Z.


What

Implements IMAGE_BVH64_INTERSECT_RAY (MIMG 0xe7): the node test of image_bvh_intersect_ray with a 64-bit node pointer.

  • Decoder: 0xe7 decodes to ImageBvh64IntersectRay. The node pointer takes the first two address dwords (low, high), so the instruction addresses 12 dwords, 9 with A16.
  • Translation: the same ImageBvhIntersectRay IR op, with MemoryInfo::addressIsFull marking the 64-bit pointer. APS5_RAYTRACING=strict and miss apply as for the 32-bit form.
  • SPIR-V: the node index and node address are computed from the whole pointer, and the ray operands are read one dword later. The triangle and box tests are unchanged.
  • Null BVH: a zero T# base is still a null BVH for the 32-bit form. It is not for the 64-bit form: there the T# may have base 0 and cover all of memory, with the node address carried by the pointer, so only the T# size bounds the node. A node address that is not mapped records the usual BDA fault.

Sources:

  • AMD machine-readable RDNA2 ISA: same instruction "using 64 bit node pointers".
  • LLVM AMDGPU: opcode 0xe7 on GFX10 (MIMGInstructions.td); operand order and NumVAddrDwords = IsA16 ? (Is64 ? 9 : 8) : (Is64 ? 12 : 11) (SIISelLowering.cpp).
  • Mesa RADV, create_bvh_descriptor and build_addr_to_node: on RDNA2 it uses this instruction with a T# of base 0 and size 2^42 - 1, and a node pointer of (address >> 3) + node.

Tested

Windows 11, MinGW-w64 GCC 15.2.0, ctest: 184/184 pass. No title run.

  • New execution test agc_driver_bvh64_intersect_ray. A compute shader runs four forms on the host Vulkan device over the same nodes: image_bvh64_intersect_ray (contiguous address), image_bvh_intersect_ray (NSA), and both with A16 (NSA).
    • The nodes are in a guest block mapped above 32 GiB, so the high dword of the pointer is not zero.
    • Cases: float32 and float16 box nodes (sorted children, one clipped by the ray extent), both triangles of a triangle node (hit and miss), an unknown node type, and a box and a triangle node past the T# size.
    • It runs twice: with a T# of base 0 and the address in the pointer, and with the base in the T# and a block-relative pointer. Each form must return the expected dwords in both.
  • Without the change the test fails with "unsupported MIMG opcode". Three mutants of the emitter each fail it: high dword ignored, zero base treated as null, ray operands not shifted.
  • ray_tracing_miss now decodes and translates both opcodes, with and without A16, and checks the address dword count (11, 8, 12, 9). It passes with APS5_RAYTRACING unset, miss and strict; the execution test skips itself in the last two.

Not verified: behaviour on real hardware, and pointer bits above the 42-bit node index (they make the node fail the T# size check here). The mmap path of the test was not run (no Linux build here).

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4735194888 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/524). Originally posted by [DotDebian](https://github.com/DotDebian) on 2026-10-04T14:46:20Z. --- ### What Implements `IMAGE_BVH64_INTERSECT_RAY` (MIMG `0xe7`): the node test of `image_bvh_intersect_ray` with a 64-bit node pointer. - **Decoder**: `0xe7` decodes to `ImageBvh64IntersectRay`. The node pointer takes the first two address dwords (low, high), so the instruction addresses 12 dwords, 9 with A16. - **Translation**: the same `ImageBvhIntersectRay` IR op, with `MemoryInfo::addressIsFull` marking the 64-bit pointer. `APS5_RAYTRACING=strict` and `miss` apply as for the 32-bit form. - **SPIR-V**: the node index and node address are computed from the whole pointer, and the ray operands are read one dword later. The triangle and box tests are unchanged. - **Null BVH**: a zero T# base is still a null BVH for the 32-bit form. It is not for the 64-bit form: there the T# may have base 0 and cover all of memory, with the node address carried by the pointer, so only the T# size bounds the node. A node address that is not mapped records the usual BDA fault. Sources: - AMD machine-readable RDNA2 ISA: same instruction "using 64 bit node pointers". - LLVM AMDGPU: opcode `0xe7` on GFX10 (`MIMGInstructions.td`); operand order and `NumVAddrDwords = IsA16 ? (Is64 ? 9 : 8) : (Is64 ? 12 : 11)` (`SIISelLowering.cpp`). - Mesa RADV, `create_bvh_descriptor` and `build_addr_to_node`: on RDNA2 it uses this instruction with a T# of base 0 and size 2^42 - 1, and a node pointer of `(address >> 3) + node`. ### Tested Windows 11, MinGW-w64 GCC 15.2.0, `ctest`: 184/184 pass. No title run. - New execution test `agc_driver_bvh64_intersect_ray`. A compute shader runs four forms on the host Vulkan device over the same nodes: `image_bvh64_intersect_ray` (contiguous address), `image_bvh_intersect_ray` (NSA), and both with A16 (NSA). - The nodes are in a guest block mapped above 32 GiB, so the high dword of the pointer is not zero. - Cases: float32 and float16 box nodes (sorted children, one clipped by the ray extent), both triangles of a triangle node (hit and miss), an unknown node type, and a box and a triangle node past the T# size. - It runs twice: with a T# of base 0 and the address in the pointer, and with the base in the T# and a block-relative pointer. Each form must return the expected dwords in both. - Without the change the test fails with "unsupported MIMG opcode". Three mutants of the emitter each fail it: high dword ignored, zero base treated as null, ray operands not shifted. - `ray_tracing_miss` now decodes and translates both opcodes, with and without A16, and checks the address dword count (11, 8, 12, 9). It passes with `APS5_RAYTRACING` unset, `miss` and `strict`; the execution test skips itself in the last two. Not verified: behaviour on real hardware, and pointer bits above the 42-bit node index (they make the node fail the T# size check here). The `mmap` path of the test was not run (no Linux build here). ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source (none added) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-04 14:46:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-04T14:46:43Z.


Progress report (8387b4d → bf635fa)

📈 GPU shader instructions: 86.96% (+0.08%, +1 implemented instructions)

✅ 1 implemented
Encoding Name
MIMG IMAGE_BVH64_INTERSECT_RAY
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5981222541 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/524#issuecomment-5981222541). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-04T14:46:43Z. --- <!-- progress-report --> ### Progress report (8387b4d → bf635fa) 📈 **GPU shader instructions**: 86.96% (+0.08%, +1 implemented instructions) <details> <summary>✅ 1 implemented</summary> | Encoding | Name | | - | - | | MIMG | `IMAGE_BVH64_INTERSECT_RAY` | </details>
oneandonlydean commented 2026-10-04 21:08:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T21:08:15Z.


Thanks, the 64-bit addressing checks out. LLVM's gfx1013 model accepts image_bvh64_intersect_ray (MIMG 0xe7, 12 address dwords, 9 with A16), and the operand offsets (ray + 1, ray + 4, ray + 7) land on the right dwords for both forms, so the 32-bit layout is unchanged. Not treating a zero T# base as a null BVH for the 64-bit form matches radv, which builds exactly that descriptor (base 0, size 2^42 - 1) with a node pointer of (address >> 3) + node on RDNA2.

The new test fails on main with unsupported MIMG opcode and passes here. Since the shared emitter for image_bvh_intersect_ray changes as well and PPSA21564 uses that instruction, I'll run it through my PPSA21564 check before merging; ready to merge from my side otherwise.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5984398161 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/524#issuecomment-5984398161). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-04T21:08:15Z. --- Thanks, the 64-bit addressing checks out. LLVM's gfx1013 model accepts `image_bvh64_intersect_ray` (MIMG 0xe7, 12 address dwords, 9 with A16), and the operand offsets (`ray + 1`, `ray + 4`, `ray + 7`) land on the right dwords for both forms, so the 32-bit layout is unchanged. Not treating a zero T# base as a null BVH for the 64-bit form matches radv, which builds exactly that descriptor (base 0, size 2^42 - 1) with a node pointer of `(address >> 3) + node` on RDNA2. The new test fails on main with `unsupported MIMG opcode` and passes here. Since the shared emitter for `image_bvh_intersect_ray` changes as well and PPSA21564 uses that instruction, I'll run it through my PPSA21564 check before merging; ready to merge from my side otherwise.
oneandonlydean commented 2026-10-05 05:04:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-05T05:04:05Z.


Gated on PPSA21564: no visual or FPS change.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5988442668 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/524#issuecomment-5988442668). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-05T05:04:05Z. --- Gated on PPSA21564: no visual or FPS change.
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
boykopovar/AnyPS5!524
No description provided.