shader: IMAGE_BVH_INTERSECT_RAY behind --stub-bvh (MIMG 0xe6/0xe7) #493
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!493
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/493/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@francoisatt on GitHub · 2026-09-06 17:32 UTC · original
francoisatt:feat/image-bvh-intersect-ray→main· +120 −3 · 10 files · 4 commits · closed without mergingMIMG 0xe6 blocks five titles in #281 — Astro Bot (PPSA21564), Little Nightmares 2
(PPSA02154), Avatar: Frontiers of Pandora (PPSA01576), Severed Steel (PPSA05106),
and the original report. On Astro Bot the recompiler gets through 19 shaders
before hitting it.
Ray tracing is not implemented here. This adds decode plus an inert
always-miss stub, behind an opt-in flag. It removes one blocker so the next
one becomes visible; it does not make ray tracing work.
The trade
Without
--stub-bvh(the default) nothing changes: the shader still fails torecompile, but with a message that says what to do —
MIMG BVH opcode requires --stub-bvh (ray tracing is not implemented).With the flag the shader compiles and the game runs past this point, but
rendering is wrong wherever the title uses ray tracing. A one-shot
LOGFwarning is emitted the first time the stub fires so this isn't silent.
I've made it opt-in precisely because a silent stub that reports success is
worse than an honest failure. If you'd rather not have it at all, say so and
I'll drop the stub and keep only the decode — that alone turns the crash into a
clear message.
Changes
decode — MIMG 0xe6 / 0xe7 added to
DecodeMimgOpcode, two entries in theOpcodeenum placed outside the atomic range checks. Address-component countsare 11/8 (0xe6) and 12/9 (0xe7) depending on A16, per the RDNA2 ISA;
DecodeMimgAddressComponentsgains ana16parameter that other opcodesreturn before ever reading.
stub — returns
{0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF}. Thatvalue is neutral under both readings of the result: as a child pointer on a box
node it's the "absent child" sentinel, so traversal terminates; as a float on a
triangle node it's a NaN, so every ordered comparison is false and no hit is
recorded regardless of how the shader reads
hit_status. Zero would have beenwrong on both counts — child pointer 0 can be the root, and
t = 0.0beats anyinitial best.
flag —
--stub-bvh, off by default. The gate sits at decode time so theexisting
SetUnsupportedpath carries the message.tests —
CheckBvhStubcovers both paths: with the flag off, the MIMG mustdecode as
UNSUPPORTEDwith a reason mentioning the flag; with it on, the fullpipeline must compile and the IR must contain exactly one
ImageBvhIntersectRay.Two things worth flagging in review
The decode gate reads
Config::BvhStubEnabled()directly from the recompiler,which is not how options normally reach it —
CompileOptionsis. I went thisway because
DecodeProgram(code, program)is a free function with no optionsstruct, and threading one through would touch 22 call sites in the tests. The
&&short-circuit means Config is only read for a BVH opcode. Happy to do itthe other way if you prefer the recompiler stay free of Config.
In the test, a minimal
[MIMG + s_endpgm]shader produces an empty IR: nothingreads the destination VGPR, so
EliminateDeadCoderemoves the stub along withit. The test appends a buffer store to keep the result live. Real shaders
consume the result, so this doesn't affect them — noting it because the
first version of the test passed while proving nothing.
Testing
Build: clean build on Windows, clang-cl 19.1.5, Ninja — no new warnings.
Tests: 36/36, on
74a78f3.Decode verified by hand against three real encodings from #281 (Astro Bot,
Little Nightmares 2, Severed Steel): opcode, dword count, address register
count and dmask all match.
Not verified at runtime. I don't have any of the affected titles, so I
can't confirm a game actually gets further with the flag on. Someone who can
run Astro Bot would settle that quickly — and would also reveal what the next
blocker is, which is the point of the flag.
AI assistance
Written with AI assistance. The RDNA2 semantics, the choice of sentinel value
and the test design were worked out in conversation with Claude; every change
was reviewed, built and tested locally by me.
@francoisatt on GitHub · 2026-09-07 19:47 UTC · original
Rebased onto
6aa6e39, no conflicts. 35/36 tests pass — the only failure iskernel_file_system, which fails on clean main as well (see #505). Unrelatedto this PR.
@Randomuser8219 on GitHub · 2026-09-07 22:55 UTC · original
No change on Astro Bot with the new upstream.
@FirasDev on GitHub · 2026-09-08 15:29 UTC · original · edited 2026-09-08 15:50 UTC
Tested against Astro Bot (ASTRO BOT V01.018.000,
PPSA21567, EUR release, one of the five titles from #281). Note #281/#204 testedPPSA21564, which redump.org identifies as the NA release of the same v01.018 build, so same game/version, different regional title ID.Without
--stub-bvh: confirms the new message fires as intended: the old generic "MIMG opcode is not implemented" is nowMIMG BVH opcode requires --stub-bvh (ray tracing is not implemented), same PC/opcode as before.With
--stub-bvh: the shader that was blocking at PC0x2190(MIMG0xe6) compiles and the emulator gets past it, the decode + stub does what it says. But it doesn't reach the menu. It hits a second, unrelated crash a few shaders later:Symbolized call chain (Release build,
/DYNAMICBASE:NO, so addresses resolved directly against the matching PDB):So this is a compute shader, reached via an indirect dispatch (
CpOpDispatchIndirect), that also usesIMAGE_BVH_INTERSECT_RAY.Edit: my original theory here was wrong, leaving this in place with the correction rather than pretending I got it right the first time. I'd guessed resource-plan extraction was treating the BVH instruction's resource operand as a normal image descriptor and rejecting it. Checked the actual stub code (Memory.cpp, IMAGE_BVH_INTERSECT_RAY / IMAGE_BVH64_INTERSECT_RAY case):
ir.Emit(IR::ValueOpcode::ImageBvhIntersectRay)takes no arguments. UnlikeIMAGE_SAMPLE/IMAGE_LOAD's handlers, it never touchesinst.src1/inst.src2(SRSRC/SSAMP), so it never registers a resource anywhere. I also checkedExtractResourcePlandirectly: it doesn't classify opcodes itself, it just copies whatever's already inprogram.info.buffers/images/samplers, which gets populated during translation by the resource-registering opcodes. Since the stub never calls that registration path, there's no BVH-shaped descriptor forMaterializeResourcesto see, let alone misclassify.So the second crash is caused by something else in that shader, unrelated to the BVH instruction's resource operand. Planning to rerun with
--shader-log-direction Fileto get the actual failing shader's IR instead of guessing again.Net result: at least for this title,
--stub-bvhremoves the blocker it targets but doesn't get the game running. There's a second, separate crash in resource materialization for this shader, not yet confirmed whether it's actually related to the BVH instruction or just another pre-existing gap that happened to be next in line. No idea whether the other four titles in #281 hit the same wall or get further.Tested on: Windows, clang-cl 19.1.5, Release, branch built at
adc8e95.@francoisatt on GitHub · 2026-09-08 17:01 UTC · original
Thanks both — this is exactly the validation I couldn't do myself.
@FirasDev your correction is right, and it matches what I found earlier:
ImageBvhIntersectRay isn't classified in ImageOpcodeInfoOf (ValueOpcodes.cpp),
so ResourceTracking::Collect returns early and never calls AddImage. The stub
registers no resource at all — nothing for MaterializeResources to reject.
Worth noting for whoever picks up that second crash: that same gap means the
BVH descriptor never reaches the host as a resolved resource. It'll matter for
a real implementation, which needs the descriptor's base address to read nodes.
Classifying the opcode would be part of that work, not of this PR.
The --shader-log-direction File run sounds like the right next step. Happy to
look at the IR if you post it.
@francoisatt on GitHub · 2026-09-08 17:16 UTC · original
@FirasDev main has moved a fair bit since adc8e95 — #457 (dense image resource
limit raised to 64) landed in
c6f6e30and touches image resources, which iswhere your second crash lands. Might be worth a retest on that build before
digging into the IR. I've rebased this branch onto
c6f6e30.@FirasDev on GitHub · 2026-09-08 18:00 UTC · original
@francoisatt retested on the rebase (
3b16edeontoc6f6e30). Same crash, same file:line, and the stack frames from CommandProcessor down to thread entry are byte-identical to the pre-rebase trace posted above (only frames 0-4 shifted, consistent with just recompilation moving code around inside pipelineCache.cpp itself).@francoisatt on GitHub · 2026-09-08 18:35 UTC · original
Thanks for the retest — that rules out #457 cleanly.
MaterializeResources fails through SpecializationFail, which formats an actual
reason string ("... uses unsupported format {}", "... unsupported resource
class", etc). That message is almost certainly being swallowed: printf_direction
defaults to Silent, so every LOGF is dropped.
Worth a run with
--printf-direction Consolebefore anything else — the linejust before the EXIT should name which descriptor and why. That turns this from
guesswork into a one-line answer, and it's cheaper than dumping the IR.
If it does need the IR after that, --shader-log-direction File is the right
next step.
@Randomuser8219 on GitHub · 2026-09-08 22:54 UTC · original
@francoisatt on GitHub · 2026-09-11 18:06 UTC · original
Superseded by #558, which fixes the actual root cause (the SRT plan bug) and
implements real traversal rather than a stub. Closing — the stub was only ever
meant to make the next blocker visible, and it did its job.
Pull request closed