perf(shader): emit image_bvh_intersect_ray as one shared function per variant #5455
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5455"
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?
Imported from boykopovar/AnyPS5. Originally posted by overlordxrz-source on 2026-10-13T20:08:33Z.
What
Port of @MichonGoddijn231849's
a25a7e9afrom hisgta-v/testingbranch, with him as the commit author. He okayed this port in #1203: "yes, if it still applies tomain's image emitter. A test that compiles an RT kernel and checks the function is emitted once would cover it."A wave64 program on a 32-wide host emitted the
image_bvh_intersect_rayquery inline once per lane half. That means the box and triangle tests were emitted again for every instruction and every half. When BDA probes are available (the default), each variant is now emitted once as aDontInlinefunction, and each instruction calls it. The variants are A16 and the 64-bit node pointer, so there are up to four functions. WhenAPS5_BDA_BYTE_READSforces the byte-read path, the query stays inline as before, since those reads need the instruction.The query body is unchanged. It moves into
EmitBvhQuery, which takes the descriptor, the address VGPRs and the pc as values, so it can serve as a function body.DefineBvhIntersectFunctionsruns next toDefineDot2F32F16Functionbefore the entry function, and it only defines the variants the program uses.Why
These numbers are Michon's, measured on his branch (#1203, Fidelity and Performance RT modes). GTA V's ray tracing kernel went from 706k to 626k SPIR-V words, and driver compile time dropped 17%, at the same speed.
On current
main, using the new test's kernel (four BVH instructions, one per variant):mainAPS5_BDA_BYTE_READS=1(inline path)main)Test
New test
agc_spirv_bvh_intersect_function(tests/SpirvBvhIntersectFunction.cpp). It recompiles a compute kernel with all four BVH variants, once as wave32 and once as wave64 on 32 lanes. It checks:DontInlinefunction namedimage_bvh_intersect_rayThe module is validated with SPIRV-Tools when
ANYPS5_ENABLE_SPIRV_TOOLSis on. The test skips underAPS5_RAYTRACINGandAPS5_BDA_BYTE_READS.Tested
main'sSpirvImageEmitter.cppandSpirvModuleEmitter.cppit fails ("expected one image_bvh_intersect_ray function per variant, found 0").Bvh64IntersectRayexecution test needs a GPU and was not run either.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T20:32:15Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterHelpers.hppL145core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hppL128core/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cppL1032core/libs/prx/libSceAgcDriver/CMakeLists.txtL1225core/libs/prx/libSceAgcDriver/CMakeLists.txtL1225core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hppL128core/libs/prx/libSceAgcDriver/CMakeLists.txtL1225Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-14T00:58:26Z.
Review: COMMENTED
Splitting a large repeated body into a function is a reasonable way to cut SPIR-V size for wave64-on-32 programs, and the table shows the expected shape: −39% for wave64, +0.7% call overhead for wave32, the byte-read path unchanged.
A few points:
DontInlinebuys depends on the driver. It is a hint. NVIDIA's compiler and Mesa (NIR inlines every function before ACO/LLVM) generally inline anyway, so the final ISA and the register allocation are the same as before. The gain is in parsing and the front-end passes before inlining, which matches the 17% compile-time drop with unchanged speed on Michon's branch. On a driver that honours the hint, the call also forces the 9-ish argument values through the calling convention, and the GPU-time side would need a check there. Worth saying in the description which driver the 17% was measured on.Bvh64IntersectRay, plus a run of the new test withANYPS5_ENABLE_SPIRV_TOOLS=ON, on at least one desktop driver would cover the moved body. The template'sGPUs tested,UnblocksandAI-assistedlines are also missing.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T02:26:33Z.
Closing: no title is known to reach this. With the queue at 700+ open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line.
Pull request closed