shader: accept tessellation loops, indexed HS ring reads, integer spacing #1482
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!1482
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1482/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?
@NeySlim on GitHub · 2026-10-13 19:05 UTC · original
NeySlim:fix/tess-gow→main· +599 −77 · 3 files · 4 commits · closed without mergingTested in God of War Ragnarok (PPSA08332, 05.005).
The game draws its displaced terrain and snow with tessellation (patch draws, triangle domain, 3 control points). Without
--tessellationthese draws are skipped, so the ground is missing in the opening cutscene, on the sled track and in the Freya fight: flat white snow, holes where the background shows through, a white band across the frozen river.With
--tessellationon current main the game exits before gameplay:Main now handles forward branches, wide DS writes, the patch range and
PatchInput(4a2961cdf,0957f088a) and caches the ring layouts (c71589124). What the game still hits:(cp + 1) % 3with an address that is not affine incp. A "multiple of c" address kind (exact product: power of two, or 24-bit multiply by at most 256) is accepted for a read when c is a multiple of the LS stride.v_add3_u32andv_mov_b32are tracked.s_barrier(buffer_loadon the HS ring). This is lowered to a read of the output variable ataddress / stride. Vulkan allows readinggl_out[i]of any invocation afterbarrier(), writes stay atgl_InvocationID.SpacingEqual, fractional even toSpacingFractionalEven. pow2 is still refused (no equivalent).Testing (Linux, Radeon 8060S, RADV 26.2.5):
--tessellation-only:TessellationBranchedRing(indexed read, output read back, integer partitioning) andCheckTessellationLoop(a loop before the LS and HS ring stores, plus a case that must be refused). Both fail on main.TessellationPatchDrawinCheckRasterization: a real patch draw throughRenderExecutor::DrawAutowith guest LS/HS/DS/PS. The HS of control point 0 reads control point 1's output and passes it as patch data, the DS exports it, the target must be (3, 3, 3, 1) everywhere. Fails on main.--tessellation, on current main with my other open PRs (the game needs several of them to reach gameplay): new-game runs of about 13 minutes (opening cutscene, sled, Freya fight, end of the chapter), no exit, no device lost. The terrain and snow are drawn, the white band and the holes are gone. Screenshots below.Tessellation is still off by default, this only makes
--tessellationwork for this game. Cost with it on, same build: -1.1 fps in the opening cutscene (22.9 -> 21.9, -4.7%), -0.8 fps on the sled (-3.6%), Freya fight within noise. Startup to gameplay is also slower (about 42k patch draws in the menus and intro). Most of the cutscene cost is probably the indirect patch draws, which stay on the CPU path of #1288.Not tested on Windows. Recompiler and SPIR-V emitter code only, no platform specific code.
Before (left, without
--tessellation) and after (right, with this change):AI use
I used Claude Code to write the change and the test and to run the measurements above. I reviewed the code and the results before opening the PR.
@coderabbitai[bot] on GitHub · 2026-10-13 19:09 UTC · original · edited 2026-10-20 19:41 UTC
📝 Walkthrough
Tessellation address analysis now supports additional arithmetic patterns and iterates dataflow across branches and loops before validating ring accesses. Tessellation buffer classification distinguishes control-stage and evaluation-stage accesses. SPIR-V emission handles derivable record offsets, control-point output reads, and equal or fractional partitioning modes. Tests cover branched and loop-carried addresses, out-of-record stores, static offsets, and a tessellated patch draw.
Suggested reviewers:
nmzikPriority: ➖ Normal
Change: Feature
Merge Risk: 🟡 Moderate · up to
fecf7Tessellated shaders whose ring addresses add a negative constant can read or write the wrong per-control-point attribute when the record stride is not a power of two. This would cause incorrect tessellated geometry. Tessellation is disabled by default, which limits exposure, but the offset folding should be fixed before merge.
Pre-merge checks:
4 ·
1
Full details: Docstring Coverage
Explanation
Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 12 functions across 6 files. (1 skipped: 1 too large.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
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.@coderabbitai[bot] on GitHub · 2026-10-13 19:09 UTC · original · edited 2026-10-13 19:21 UTC
On
src/graphics/shader/recompiler/Tessellation.cppline 273 (outdated):🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 16408
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 16349
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 35455
Handle affine patch stores before computing the patch range.
A non-constant affine control-store address can target the patch region, but
fixed_storesrecords only constant addresses. If that store is the only patch producer,patch_beginandpatch_endremain zero. A TES patch read can then reachDefineTessellationInterfaces, which rejects its address as outside[0, 0). Classify these stores as patch outputs, or reject the unsupported form during reflection instead of treating it as a control-point store.✅ Addressed in commit e55a14c
@coderabbitai[bot] on GitHub · 2026-10-13 19:09 UTC · original · reviewed
Actionable comments posted: 1
🧹 Nitpick comments: 1
ℹ️ Review info
⚙️ Run configuration
3adb9910-3bd9-4225-9bb2-d35708d0c664📥 Commits
Reviewing files that changed from the base of the PR and between
df5b9b92beand 412547341c1b085869ad4a2f20a3535f764aa43f.📒 Files selected for processing: 7
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/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; 7 remain after this review.
@NeySlim on GitHub · 2026-10-13 19:19 UTC · original
On
src/graphics/shader/recompiler/Tessellation.cppline 273 (outdated):Yes, an affine store with a constant at or past the stride lands in the next record, and the last control point's lands in the patch region. The lowering would write it to the invocation's own output, so reflection now exits on any per-control-point store that leaves its record (e55a14c6, host test added). The 12 LS/HS/DS sets from the game all pass the check.
Also switched the fixed store check to is_constant() in the same commit. A Scaled store can't reach it since non-affine stores exit just above, but it reads clearer.
@coderabbitai[bot] on GitHub · 2026-10-13 19:21 UTC · original
On
src/graphics/shader/recompiler/Tessellation.cppline 273 (outdated):@NeySlimThanks for the fix and the clarification. The supplied code now checks the full store width, includinginst.offset, and rejects per-control-point HS stores that exceed their record. This addresses the unsupported affine-store case.The
is_constant()check also makes the purpose offixed_storesclearer.✏️ Learnings added
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.
@NeySlim on GitHub · 2026-10-14 05:59 UTC · original
Related: #1245 (GTA V tree trunks) touches the same code. It adds the patch input attribute, reflects the patch range from the HS and follows LS/HS data through branches and wide LDS accesses, which is roughly the first half of this PR. The two conflict textually in Tessellation.cpp, spirvEmitterTessellation.cpp, shader.cpp/h and the tessellation tests.
#1245 alone does not get God of War Ragnarök's terrain through. On top of it the game needs:
partitioning == 2, GoW uses 0)cp + 1 mod 3)#1245 also has
V_AND_B32for the masked patch ordinal, which this PR does not need for GoW.If #1245 lands first I can rebase this one on it so that only the cases above remain in the diff.
@NeySlim on GitHub · 2026-10-15 16:50 UTC · original
Pushed 090aad7de on top. Once the DS gets real patch data, the snowy terrain in the Freya scene turned into a flat grey slab in front of her: the depth prepass and the gbuffer pass ended up with different tessellated positions.
The trigger is a RADV bug (Mesa 26.2.4): when a TCS writes a per-vertex output at a dynamic location/component, the TES reads 0 from its non-constant patch outputs. We addressed every ring attribute as
address % strideat runtime, while the guest always usesstride * cp + const. The emitter now turns that into a constant offset when it's the same for every lane passing the access predicate, and keeps the old path otherwise. Only the control point index stays dynamic.CheckTessellationProgram now requires no OpUMod for the stride programs, and fails without the change. I couldn't get a GPU test to hit the driver bug inside the emulator, so the GPU evidence is the game plus a standalone GLSL repro, which I'll file with Mesa.
@coderabbitai[bot] on GitHub · 2026-10-16 00:46 UTC · original · reviewed
🧹 Nitpick comments: 1
ℹ️ Review info
⚙️ Run configuration
6e729fa5-767b-4736-ad2c-4b7608d24721📥 Commits
Reviewing files that changed from the base of the PR and between 090aad7de90d9461bbd5bd45a556e892b9360207 and 01e9147f9451f96e2b6b5421c24e0cfefd33828a.
📒 Files selected for processing: 5
src/graphics/shader/recompiler/backend/spirv/spirvEmitterInternal.hsrc/graphics/shader/recompiler/ir/ShaderIR.hsrc/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; 6 remain after this review.
@coderabbitai[bot] on GitHub · 2026-10-20 18:34 UTC · original · edited 2026-10-20 19:41 UTC
On
src/graphics/shader/recompiler/backend/spirv/spirvEmitterTessellation.cppline 26 (outdated):🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 26123
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 41898
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 35367
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 8056
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 41902
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 41646
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 26944
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 37639
Normalize negative inline constants before computing the record offset.
The decoder represents inline
-16as0xFFFFFFF0, andV_ADD_NC_U32passes that source throughSimpleIntegerasIAdd32.RecordOffsetthen applies unsigned modulo to the immediate. Withstride == 48, this produces0instead of the correct signed offset32, which can select the wrong tessellation attribute and component.Dynamic bases still use the existing runtime modulo fallback.
🐛 Suggested fix
📝 Committable suggestion
✅ Confirmed as addressed by @NeySlim
@coderabbitai[bot] on GitHub · 2026-10-20 18:34 UTC · original · reviewed
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
41287c7d-2fb2-499d-8216-e7467bab0ed1📥 Commits
Reviewing files that changed from the base of the PR and between 01e9147f9451f96e2b6b5421c24e0cfefd33828a and fecf7e689df03d5bcae4ae7e2371290f575bc496.
📒 Files selected for processing: 3
src/graphics/shader/recompiler/Tessellation.cppsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterTessellation.cpptests/ShaderRecompilerComputeTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
@NeySlim on GitHub · 2026-10-20 19:40 UTC · original
On
src/graphics/shader/recompiler/backend/spirv/spirvEmitterTessellation.cppline 26 (outdated):Right, a negative inline constant next to a control point term gave the wrong residue when the stride does not divide 2^32. Immediates are now taken as signed, and
CheckTessellationProgramcovers it with a-16add on the HS read (fails without the fix).@NeySlim on GitHub · 2026-10-20 19:41 UTC · original
Rebased on main.
4a2961cdfand0957f088anow cover forward branches, wide DS writes, the reflected patch range andPatchInput, andc71589124caches the layouts with a better key, so I dropped my cache commit and moved the rest onto main's structures. What's left is what main still refuses in this game: a loop before the ring stores (main's scan only takes forward branches, GoW stops on Tessellation.cpp:133 without it), HS reads of another control point ((cp + 1) % 3), the HS reading back its own outputs, wide DS reads, integer and fractional even spacing, plus the two follow-ups (stores outside the control point record, static ring offsets).CheckTessellationLoop,TessellationBranchedRingandTessellationPatchDrawfail on main without it. Checked in game with--tessellationon top of current main: no stop, terrain and snow look right.@coderabbitai[bot] on GitHub · 2026-10-20 19:41 UTC · original
On
src/graphics/shader/recompiler/backend/spirv/spirvEmitterTessellation.cppline 26 (outdated):@NeySlim Thanks for fixing this. The signed conversion and residue normalization address the incorrect offset. The reported
-16HS-read regression inCheckTessellationProgramcovers the failing case.🧠 Learnings used
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.
@Nmzik on GitHub · 2026-10-21 03:47 UTC · original
Credited
Pull request closed