shader: fix BVH resource classification and specialization crash #555

Closed
github-bot wants to merge 17 commits from gh-pr/555/head into gh-pr/555/base
Owner

@⁠FirasDev on GitHub · 2026-09-10 13:53 UTC · original
FirasDev:feat/hardware-raytracing → main · +1563 −112 · 20 files · 17 commits · closed without merging

This builds on #493 by @⁠frans (cherry-picked as-is: the opcode decode, the stub, the --stub-bvh flag, and his tests), plus two fixes I found by running Astro Bot (PPSA21567) against it with --stub-bvh enabled.

Fix 1: the BVH resource was classified wrong. The stub registered its resource operand as a buffer resource, which routes it through SRT specialization to resolve the descriptor as a compile-time constant. But the BVH node-pool base address is a runtime pointer (two SGPRs read directly), not something specialization can resolve, so it crashed immediately. This reads it the same way S_LOAD's raw-address path already does, and leaves it unregistered with resource tracking, so nothing tries to constant-fold it.

Fix 2: resource specialization aborted the whole process on a control-flow-dependent descriptor. With fix 1 in, Astro Bot got much further, then hit an unrelated crash: some other shader (not BVH) computes part of a descriptor differently depending on runtime control flow, and ResolveInvariantPhi correctly detects that divergence, but the caller treated it as fatal for the entire shader. That's the same kind of "descriptor doesn't make sense" situation NullImageDescriptor/ValidImageDescriptor already tolerate elsewhere in this file, so this applies the same tolerance: zero out just that one resource and keep going instead of aborting.

Testing: ran against Astro Bot (PPSA21567) with --stub-bvh. Before these fixes: hard crash before the BVH instruction is even reached. After: compiles far more shaders than before, then hits a separate, unrelated access violation in the PS5 module loader (runtimeLinker.cpp) that has nothing to do with either fix or with ray tracing. Astro Bot does not fully boot yet, these two fixes remove two real crashes along the way.

This also carries the from-scratch BVH parsing/walking work (src/graphics/rt/), a standalone test confirming the host GPU can create an RT-capable Vulkan device, and a working bottom-level acceleration structure builder verified to actually build a BLAS on real hardware. None of that is wired into the shader pipeline yet, still blocked on real ray-query codegen, it's groundwork for that.

AI disclosure: I used Claude to help investigate, implement, and test this. I reviewed and ran everything against real hardware and a real game before submitting.

**@⁠FirasDev** on GitHub · 2026-09-10 13:53 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/555) `FirasDev:feat/hardware-raytracing` → `main` · +1563 −112 · 20 files · 17 commits · closed without merging This builds on #493 by @⁠frans (cherry-picked as-is: the opcode decode, the stub, the --stub-bvh flag, and his tests), plus two fixes I found by running Astro Bot (PPSA21567) against it with --stub-bvh enabled. Fix 1: the BVH resource was classified wrong. The stub registered its resource operand as a buffer resource, which routes it through SRT specialization to resolve the descriptor as a compile-time constant. But the BVH node-pool base address is a runtime pointer (two SGPRs read directly), not something specialization can resolve, so it crashed immediately. This reads it the same way S_LOAD's raw-address path already does, and leaves it unregistered with resource tracking, so nothing tries to constant-fold it. Fix 2: resource specialization aborted the whole process on a control-flow-dependent descriptor. With fix 1 in, Astro Bot got much further, then hit an unrelated crash: some other shader (not BVH) computes part of a descriptor differently depending on runtime control flow, and ResolveInvariantPhi correctly detects that divergence, but the caller treated it as fatal for the entire shader. That's the same kind of "descriptor doesn't make sense" situation NullImageDescriptor/ValidImageDescriptor already tolerate elsewhere in this file, so this applies the same tolerance: zero out just that one resource and keep going instead of aborting. Testing: ran against Astro Bot (PPSA21567) with --stub-bvh. Before these fixes: hard crash before the BVH instruction is even reached. After: compiles far more shaders than before, then hits a separate, unrelated access violation in the PS5 module loader (runtimeLinker.cpp) that has nothing to do with either fix or with ray tracing. Astro Bot does not fully boot yet, these two fixes remove two real crashes along the way. This also carries the from-scratch BVH parsing/walking work (src/graphics/rt/), a standalone test confirming the host GPU can create an RT-capable Vulkan device, and a working bottom-level acceleration structure builder verified to actually build a BLAS on real hardware. None of that is wired into the shader pipeline yet, still blocked on real ray-query codegen, it's groundwork for that. AI disclosure: I used Claude to help investigate, implement, and test this. I reviewed and ran everything against real hardware and a real game before submitting.
Use an explicit selector switch and descriptive channel, mip, and slice names. Share volume/array tile setup, hoist per-mip copy work, consolidate tiled validation, and remove redundant code.

Preserve layout bounds, mip tails, source strides, and cache interfaces. Independent correctness and compactness audits passed; native packed-texture tests and 330 GPU tiler parity cases passed.
Fix PS5 boot failure when an optional empty sound path opens /app0/ and the game seeks and reads that directory. Pack directory records once and share their bytes and position across raw reads, enumeration, seeking, and size reporting. Apply seek and read error semantics with checked offsets.

Add multiblock directory regression coverage using the existing production Vulkan resource lifecycle. Existing CMake build and kernel_file_system test pass. Independent correctness, fixture, runtime, and final compactness audits passed; launch.json run reached Jurassic Park gameplay with 4560 sampled flips, no Vulkan validation errors, and normal window-close exit.
Co-Authored-By: Claude Sonnet 5 <[email protected]>
Classifying it as a buffer resource routes it through SRT specialization, which tries to resolve the descriptor to a compile-time constant. The BVH node-pool base address is a runtime pointer instead, so this reads it the same way S_LOAD's raw-address path does: two SGPRs read directly, left unregistered with resource tracking so nothing tries to constant-fold it.
A descriptor dword can be genuinely unresolvable at specialization time when the guest shader computes it differently depending on runtime control flow (ResolveInvariantPhi finds divergent incoming values on a Phi node). That previously aborted the whole process. Fall back to a zeroed descriptor for just that one resource instead, the same tolerance NullImageDescriptor/ValidImageDescriptor already apply to descriptors that don't make sense, and keep going.
francoisatt's cherry-picked stub commit and our own new graphics/rt and tests files
had French comments and space-based indentation instead of this project's
tabs, per review feedback on the PR. Translates every French comment to
English, runs clang-format over every src/*.{cpp,h,inc} file this branch
touches, strips a stray UTF-8 BOM that had been on nine files since they were
first written, and fixes the three CMakeLists.txt lines that lost their tabs
to an earlier PowerShell paste. tests/ShaderRecompilerComputeTests.cpp keeps
its existing 2-space indentation: it's outside the project's clang-format
scope (only src/ is covered) and already used that convention before this PR.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:25:22 +00:00
github-bot closed this pull request 2026-11-26 09:25:22 +00:00
Author
Owner

@⁠rodjunger on GitHub · 2026-09-10 17:25 UTC · original · edited 2026-09-10 17:27 UTC

Some comments are in french. Please at least read what Claude has generated before submitting a PR.

**@⁠rodjunger** on GitHub · 2026-09-10 17:25 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/555#issuecomment-5622722269) · edited 2026-09-10 17:27 UTC Some comments are in french. Please at least read what Claude has generated before submitting a PR.
Author
Owner

@⁠rodjunger on GitHub · 2026-09-10 17:26 UTC · original
On src/graphics/shader/recompiler/frontend/translate/Memory.cpp line 1058 (outdated):

@@ -1049,6 +1052,27 @@ bool Translator::EmitMemory(const Decoder::Instruction& inst) {
 		case Decoder::Opcode::IMAGE_GATHER4_C_LZ_O:
 		case Decoder::Opcode::IMAGE_GATHER4H: return IMAGE_GATHER(inst);
 
+		case Decoder::Opcode::IMAGE_BVH_INTERSECT_RAY:
+		case Decoder::Opcode::IMAGE_BVH64_INTERSECT_RAY: {
+			// Stub : sémantique inerte « aucune intersection » — 4 canaux 0xFFFFFFFF
+			// (pointeur d'enfant absent pour un nœud boîte / temps NaN pour un nœud triangle)

french comment

**@⁠rodjunger** on GitHub · 2026-09-10 17:26 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/555#discussion_r3981766058) On `src/graphics/shader/recompiler/frontend/translate/Memory.cpp` line 1058 (outdated): ```diff @@ -1049,6 +1052,27 @@ bool Translator::EmitMemory(const Decoder::Instruction& inst) { case Decoder::Opcode::IMAGE_GATHER4_C_LZ_O: case Decoder::Opcode::IMAGE_GATHER4H: return IMAGE_GATHER(inst); + case Decoder::Opcode::IMAGE_BVH_INTERSECT_RAY: + case Decoder::Opcode::IMAGE_BVH64_INTERSECT_RAY: { + // Stub : sémantique inerte « aucune intersection » — 4 canaux 0xFFFFFFFF + // (pointeur d'enfant absent pour un nœud boîte / temps NaN pour un nœud triangle) ``` french comment
Author
Owner

@⁠FirasDev on GitHub · 2026-09-10 17:33 UTC · original

Some comments are in french. Please at least read what Claude has generated before submitting a PR.

Those are unmodified, from @⁠francoisatt's own commits in #493 (c1befc761d, 3b16edede2), cherry-picked as-is like the PR description says, would you like me to translate them ?

**@⁠FirasDev** on GitHub · 2026-09-10 17:33 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/555#issuecomment-5622818048) > Some comments are in french. Please at least read what Claude has generated before submitting a PR. Those are unmodified, from @⁠francoisatt's own commits in #493 (c1befc761d, 3b16edede2), cherry-picked as-is like the PR description says, would you like me to translate them ?
Author
Owner

@⁠rodjunger on GitHub · 2026-09-10 17:43 UTC · original

Some comments are in french. Please at least read what Claude has generated before submitting a PR.

Those are unmodified, from @⁠francoisatt's own commits in #493 (c1befc7, 3b16ede), cherry-picked as-is like the PR description says, would you like me to translate them ?

I'm not an official maintainer but I don't see how a maintainer or anyone would want comments in french, so it's good to update them to english. The next thing that looks off to me is the formatting, I don't know if it's a github bug but most files seem to have really broken formatting, running a linter/formatter wouldn't hurt

**@⁠rodjunger** on GitHub · 2026-09-10 17:43 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/555#issuecomment-5622948202) > > Some comments are in french. Please at least read what Claude has generated before submitting a PR. > > Those are unmodified, from @⁠francoisatt's own commits in #493 ([c1befc7](https://github.com/KytyPS5/KytyPS5/commit/c1befc761d3c363c0de596e9cdb05100a1b41f90), [3b16ede](https://github.com/KytyPS5/KytyPS5/commit/3b16edede2ce5173e9f25f906692a17644fed65c)), cherry-picked as-is like the PR description says, would you like me to translate them ? I'm not an official maintainer but I don't see how a maintainer or anyone would want comments in french, so it's good to update them to english. The next thing that looks off to me is the formatting, I don't know if it's a github bug but most files seem to have really broken formatting, running a linter/formatter wouldn't hurt
Author
Owner

@⁠francoisatt on GitHub · 2026-09-11 06:58 UTC · original

@⁠FirasDev sorry about the French comments — those were mine, thanks for translating them. I'll keep code comments in English from now on.

**@⁠francoisatt** on GitHub · 2026-09-11 06:58 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/555#issuecomment-5630700537) @⁠FirasDev sorry about the French comments — those were mine, thanks for translating them. I'll keep code comments in English from now on.
Author
Owner

@⁠Nmzik on GitHub · 2026-10-06 18:08 UTC · original

Software Rt is on main

**@⁠Nmzik** on GitHub · 2026-10-06 18:08 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/555#issuecomment-6022451165) Software Rt is on main

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.