shader: translate GTA V's tessellated tree trunks #1245
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!1245
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1245/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?
@TheCruZ on GitHub · 2026-10-08 19:50 UTC · original
pr/tess-tree-trunks→main· +319 −39 · 8 files · 1 commits · closed without mergingSummary
Makes the tessellated tree trunks of Grand Theft Auto V (PPSA04263) translate. GTA V draws the trunk and lower branches of trees near the camera as tessellated patches. Without
--tessellationthose draws are skipped, so next to a tree only its separately drawn upper branches and leaves remained (floating) while its whole shadow was on the ground; with--tessellation, the interface analysis aborted withstride == 0.Shaders: LS
565d492d8752ae5f/ HS063b41d4cf2d6719with TESfb962980bce03500,ad7ac562a9597df6andd50eb887bc4d8a50; LS0be40d22aeec2cdd/ HSef022c6b5d96334c/ TES2854c49749ef2363.Problem
v_and_b32 0xffof the packed HS ID) andv_add_nc_u32, and contain internal forward branches. Stride reflection did not accept any of these, so the strides came out as 0.0x8000 - 0x150 * (patch + 1)) under CP0's EXEC. Active-address resolution did not look through the multiplies, shifts and bit-field extracts of that address, so it was not a constant.Change
v_add_nc_u32, and internal forward branches (a register keeps its address at a join only if every path agrees on it; code after an unconditional branch starts from the state of its joins).(x << s) & mto zero whenm < 2^s, so the HS per-patch addresses become constants.PatchInputattribute maps the per-patch block to aPatch-decorated TES input at the locations of the HS's patch outputs. Both stages use the patch range found in the HS (patch_base/patch_sizeofShaderTessellationInputInfo, which are part of the program key). Accesses are classified by their byte address, instruction offset included.Tessellation stays behind
--tessellationas today.Relation to #1032
#1032 (My First Gran Turismo) also changes the tessellation stride analysis and patch-constant handling, and adds the same
(x << s) & m == 0fold. The two touch the same files and will likely conflict; whichever lands second needs a rebase. The cases differ: #1032 handles the& 0x1f00control-point field and quad patches, this PR the LDS record accesses, the masked patch ordinal, branches and the offchip per-patch block of GTA V's trees.Testing
shader_recompiler_compute_tests: newTessellationPatchConstantshost case (in--tessellation-onlyand the default run) analyzes an LS/HS pair with this record layout and the per-patch block, and checks the strides, the patch range and the TES patch inputs.--tessellation-only, the default run andshader_cfg_testspass.AI usage
AI (Claude Opus 5.5) was used to investigate the issue and to implement the change. I reviewed the code, understand it, tested it as described above, and wrote this description myself, in general fully tested the game while doing few missions and playing in-game with my GTA V fork, i will be bringing PRs here after test them enough.
@coderabbitai[bot] on GitHub · 2026-10-08 19:55 UTC · original · edited 2026-10-08 21:08 UTC
📝 Walkthrough
Walkthrough
Tessellation analysis now reflects patch-range bounds and classifies patch-area reads and writes as patch inputs and outputs. SPIR-V emission uses patch-array interfaces for both kinds and checks their bounds against the reflected range. The shader stage static key includes the patch bounds. New regression coverage checks translation and SPIR-V output across local, hull, and evaluation stages.
Suggested reviewers:
nmzikPriority: ➖ Normal
Change: Bug fix
Merge Risk: 🟡 Moderate · up to
bd351The new tessellation support for GTA V can still reject some valid shaders. It can also read per-patch data from the wrong place when a buffer access uses an immediate offset, which can render geometry incorrectly. The feature stays behind a flag, but both issues should be fixed before merging.
🚥 Pre-merge checks | ✅ 4 | ❓ 1
❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
Full details: Docstring Coverage
Explanation
Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 7 files. (1 skipped: 1 too large.)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share
Comment
@coderabbitai helpto get the list of available commands.@ -88,0 +120,4 @@if (IsDirectBranch(inst.opcode) && inst.branch_target != program.instructions.back().pc) {EXIT_NOT_IMPLEMENTED(inst.branch_target <= inst.pc);joins.emplace_back(inst.branch_target, registers);}@coderabbitai[bot] on GitHub · 2026-10-08 19:55 UTC · original · edited 2026-10-08 21:08 UTC
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 14112
Exclude unreachable fallthrough instructions from branch joins.
IsDirectBranchincludes unconditionalS_BRANCH. The linear scan continues through instructions after such a branch, so skipped register writes can alter the state before the branch target is processed. Track only reachable paths when applying branch joins. This prevents an unreachable write from invalidating the address state used by a later tessellation access.✅ Confirmed as addressed by @TheCruZ
@coderabbitai[bot] on GitHub · 2026-10-08 19:55 UTC · original · reviewed
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
bec514fd-e400-494a-8714-7ce3dbf46510📥 Commits
Reviewing files that changed from the base of the PR and between
2f4b8a335dand bd3515834c7429e5ac3dfb50046c9d7daf8d5496.📒 Files selected for processing (8)
src/graphics/shader/recompiler/Tessellation.cppsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterInternal.hsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterTessellation.cppsrc/graphics/shader/recompiler/ir/ShaderIR.hsrc/graphics/shader/recompiler/ir/passes/ConstantPropagation.cppsrc/graphics/shader/shader.cppsrc/graphics/shader/shader.htests/ShaderRecompilerComputeTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 2 remain after this review.
@ -273,0 +356,4 @@if (address.IsImmediate() && address.U32() + memory.offset >=tess.hs_stride * tess.output_control_points) {kind = write ? TessellationAttribute::PatchOutput: TessellationAttribute::PatchInput;@coderabbitai[bot] on GitHub · 2026-10-08 19:55 UTC · original · edited 2026-10-08 21:08 UTC
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Classify patch accesses using the effective byte address.
If
addressis belowhs_stride * output_control_pointsbutmemory.offsetmoves the access into the patch block, this test selectsEvaluationInputinstead ofPatchInput. Line 359 adds the offset only after that decision. The emitter then indexes a per-vertex input with a patch address, which can read the wrong value or exceed the vertex array. Includememory.offsetin the classification before selectingkind; handle components separately if an access crosses the boundary.✅ Confirmed as addressed by @TheCruZ
@ -88,0 +120,4 @@if (IsDirectBranch(inst.opcode) && inst.branch_target != program.instructions.back().pc) {EXIT_NOT_IMPLEMENTED(inst.branch_target <= inst.pc);joins.emplace_back(inst.branch_target, registers);}@TheCruZ on GitHub · 2026-10-08 21:08 UTC · original
Fixed in
aaf116a: after an unconditionalS_BRANCH(orS_ENDPGM) the scan marks the state unreachable; the next join takes the branch's saved registers instead of merging them with the skipped fallthrough, and instructions no path reaches are not analyzed.@ -273,0 +356,4 @@if (address.IsImmediate() && address.U32() + memory.offset >=tess.hs_stride * tess.output_control_points) {kind = write ? TessellationAttribute::PatchOutput: TessellationAttribute::PatchInput;@TheCruZ on GitHub · 2026-10-08 21:08 UTC · original
Fixed in
aaf116a: the PatchOutput/PatchInput classification comparesaddress + memory.offset, the same byte address the reflection used to find the patch range.@ -88,0 +120,4 @@if (IsDirectBranch(inst.opcode) && inst.branch_target != program.instructions.back().pc) {EXIT_NOT_IMPLEMENTED(inst.branch_target <= inst.pc);joins.emplace_back(inst.branch_target, registers);}@coderabbitai[bot] on GitHub · 2026-10-08 21:08 UTC · original
@TheCruZ, the supplied code addresses this finding. Unreachable instructions no longer change register state. The next reachable join restores the saved registers before merging any other incoming paths.If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!
✅ Review thread resolved.
You are interacting with an AI system.
@ -273,0 +356,4 @@if (address.IsImmediate() && address.U32() + memory.offset >=tess.hs_stride * tess.output_control_points) {kind = write ? TessellationAttribute::PatchOutput: TessellationAttribute::PatchInput;@coderabbitai[bot] on GitHub · 2026-10-08 21:08 UTC · original
@TheCruZ, thanks for the fix. The supplied code now includesmemory.offsetwhen selectingPatchOutputorPatchInput, consistent with patch-range reflection.If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!
✅ Review thread resolved.
You are interacting with an AI system.
Pull request closed