Repository navigation
perf(shader): emit image_bvh_intersect_ray as one shared function per variant - #5455
Closed
overlordxrz-source wants to merge 1 commit into
Closed
overlordxrz-source wants to merge 1 commit into
overlordxrz-source wants to merge 1 commit into
Conversation
… variant A wave64 program on a 32-wide host emitted the query inline once per lane half: GTA V's ray tracing kernel carried its box and triangle tests four times. With BDA probes the query is now one DontInline function per variant (A16, 64-bit node pointer), called at each instruction; the byte-read path keeps the inline form. GTA V's RT kernel: 706k -> 626k SPIR-V words, driver compile -17%, same speed. Test: agc_spirv_bvh_intersect_function recompiles a kernel with all four variants as wave32 and as wave64 on 32 lanes and checks that each variant is one DontInline function, called once per instruction and lane half. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Co-authored-by: overlordxrz-source <overlordxrz-source@users.noreply.github.com>
This was referenced Oct 13, 2026
Merged
|
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.
|
12 tasks done
CnRJay
reviewed
Oct 14, 2026
CnRJay
left a comment
Contributor
There was a problem hiding this comment.
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:
- What
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. - The wave32 case gets only cost. For wave32 there is one call per instruction, the same count as the inline body, so the function only adds call overhead (+320 words in the test). Emitting the function only when an instruction would expand into more than one copy (wave64 on 32 lanes), and keeping wave32 inline, would make the change a pure win.
- Testing. CONTRIBUTING asks shader-recompiler changes for the GPUs the GPU tests ran on, and this was tested on aarch64 without a GPU or SPIRV-Tools validation.
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.
RINNECODER
added a commit
to RINNECODER/AnyPS5
that referenced
this pull request
Oct 14, 2026
…time CPU (#482) * perf(shader): rewrite high-fan-out IR uses in linear time Ported from upstream PR boykopovar#4035 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * perf(shader): index specialization tables by SPIR-V id Ported from upstream PR boykopovar#4772 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(shader): honor disabled optimization during specialization Ported from upstream PR boykopovar#4827 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * perf(shader): discard helper functions unreachable after specialization Ported from upstream PR boykopovar#5064 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(shader): drop module constants nothing references after specialization Ported from upstream PR boykopovar#5315 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(shader): cap SPIR-V scalar replacement Ported from upstream PR boykopovar#4288 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * perf(recompiler): iterate structurizer fixpoints in post-order and bound shared merge splitting growth Includes the stacked upstream commit that structurizes refused control flow with reach flags, which this change builds on. Ported from upstream PR boykopovar#5028 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * perf(shader): emit image_bvh_intersect_ray as one shared function per variant Ported from upstream PR boykopovar#5455 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * perf(shader): avoid redundancy traversal map copies Patches the bundled SPIRV-Tools redundancy elimination (only built with ANYPS5_ENABLE_SPIRV_TOOLS=ON). Ported from upstream PR boykopovar#5511 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(metal): accept a specialized BDA module that dropped one of its two BDA descriptors Specialization removes descriptor variables the final module no longer references. With helper functions now discarded after specialization, a compute module can drop its page-table variable while keeping the fault buffer, and the bridge then rejected the dispatch ("BDA ABI requires page-table and fault-buffer descriptor metadata"). Require at least one of the two roles instead of both; the module's own descriptors are still checked against the prepared plan. Not a port; needed by the port of upstream PR boykopovar#5064. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Collaborator
|
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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)