tessellation: LS/HS/TES lowering fixes for My First Gran Turismo (quad patches, barriers, patch constants) #1032
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!1032
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1032/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?
@defektu on GitHub · 2026-10-04 01:02 UTC · original
defektu:pr/mfgt-tess→main· +383 −68 · 7 files · 4 commits · closed without mergingPart of getting My First Gran Turismo (PPSA24156) running. Earlier parts landed in
main(font, HLE stubs, host and shader fixes: #1030, #1031, #1033, #1034). This PR is the tessellation lowering behind--tessellation(off by default). Rebased on currentmain(9e41d832).Dependency: the title does not start on
mainplus this PR alone. It stops withbecause
mainstill lacks the EQAA colour/depth target fix (accept EQAA colour targets without FMASK, ignore the depthPARTIALLY_RESIDENThint), and then #1035 (mixed sample counts). Those are not part of this PR; they are what the game needs next to it.What it fixes
& 0x1f00= control point index x 256),v_add_nc_u32/v_add3_u32, HS control point reads at a data-dependent address;TF[i]in a loop);patch_base/patch_size, part of the program key), control point stores past the output array are dropped;OutputMemoryneeds the Vulkan memory model, which this module does not use);(x << s) & mfolds to 0 when the mask lies below the shift;Commits
Known gaps (not in this PR): tessellation level is sometimes too low (tires can look boxy), an empty LUT and a slight shading flicker remain. The first launch compiles dozens of large HS pipelines in the driver (HS up to ~42k SPIR-V words), so it takes minutes with a cold pipeline cache.
Testing: builds on Windows (Release, clang-cl) and
shader_cfg_testspasses. Run in the game on top of this PR plus the EQAA fix and #1035 (RTX 5060 Ti, Windows 11): the title runs with--tessellation. This PR alone was not run in the game for the reason above.🤖 Generated with Claude Code
@coderabbitai[bot] on GitHub · 2026-10-04 01:14 UTC · original · edited 2026-10-16 17:35 UTC
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
ef976081-68f6-468f-85fc-f1e013985553📥 Commits
Reviewing files that changed from the base of the PR and between 6c9cd1a95eeb5079ace6bcb64f5d0f154b312229 and
bddfee9388.📒 Files selected for processing: 2
src/graphics/shader/shader.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.
📝 Walkthrough
Tessellation analysis now reports failures and records reflected strides and patch-output ranges. Memory lowering returns a status and reports unsupported tessellation-memory cases to the translation caller. The SPIR-V backend handles additional tessellation domains, topologies, factor indices, and patch and control-point accesses. Shader preparation and static keys use the reflected metadata, and the test checks analysis success and the patch-output range.
Priority: ➖ Normal
Change: Bug fix
Merge Risk: 🟡 Moderate · up to
bddfeWith tessellation enabled, affected hull shaders can stall or lose per-vertex and patch outputs, causing hangs or incorrect rendering. These current lowering and emission risks warrant resolution before merging; the analysis-failure exit behavior predates this change.
Security architecture risk: 🟡 Moderate · up to
ab928The change improves compatibility and adds write protections, but newly supported reads and synchronization paths leave bounds and convergence guarantees unresolved. The optional feature is reported as disabled by default, and effects beyond the running application have not been demonstrated.
Retained concerns
Security review details
Security Blast Radius
Security Findings and Attack Paths
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
Pre-merge checks:
4 ·
1
#1030is closed and provides historical context only. This pull request has no linked-issue coding requirements.Full details: Out of Scope Changes check
Explanation
The changes remain within the stated tessellation-lowering scope. They update tessellation reflection, memory lowering, SPIR-V emission, static-key data, diagnostics, and related tests. No unrelated change is demonstrated.
Full details: Docstring Coverage
Explanation
Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 16 functions across 8 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-04 01:14 UTC · original
On
src/graphics/shader/recompiler/backend/spirv/spirvEmitterTessellation.cppline 118 (outdated):🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🌐 Web query:
Vulkan tessellation control shader write per-vertex output only gl_InvocationID SPIR-V rule💡 Result:
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 16604
🌐 Web query:
Vulkan specification tessellation control shader per-vertex output index InvocationId restriction SPIR-V OpAccessChain💡 Result:
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 2946
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 290
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 2262
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 11096
Use
InvocationIdforControlOutputstores.LowerTessellationMemorypasses the guest ring-buffer address toSetTessellationAttribute. The emitter derives the vertex index from that address and only checks that the index is in range. If the address selects another control point, the store targets that point instead of the current invocation’s output, violating the Vulkan tessellation-control output contract.EmitLaneIdresolves toInvocationIdin the tessellation-control stage. Keep address-derived indexing for reads.🛠 Suggested fix
📝 Committable suggestion
@ -156,1 +258,4 @@// Factor stores go through the helper: it also handles an index only known at runtime.EmitSetTessellationFactor(ctx, inst, floating);return;}@coderabbitai[bot] on GitHub · 2026-10-04 01:14 UTC · original · edited 2026-10-04 02:05 UTC
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 19630
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 32237
Dispatch dynamic factor stores before pointer construction.
LowerTessellationMemorypasses the resolved factor-buffer address as theSetTessellationAttributeindex. When that index is non-immediate,EmitSetTessellationAttributestill callsTessellationPointer, which rejects it. The newEmitSetTessellationFactorhelper is not called, so the dynamic-index support added by this PR cannot emit the store. Route Factor stores at this live store path through a dynamic-index implementation with domain bounds.✅ Addressed in commit 81c7910
@ -278,0 +462,4 @@} else if (!post_read_barrier && block != read_block) {block->PrependNewInst(it, ValueOpcode::Barrier, {});post_read_barrier = true;}@coderabbitai[bot] on GitHub · 2026-10-04 01:14 UTC · original
🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 32435
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 41996
Place tessellation barriers in uniform control flow.
A hull-shader
ControlOutputself-read can occur in the per-lane patch-constant phase. Whenlast_write_blockis null or is the read’s block, this code insertsValueOpcode::Barrierimmediately before the read, inside that branch. The SPIR-V emitter turns it intoOpControlBarrier, but every patch invocation must reach the barrier.Place the pre-read barrier at a point reached by every patch invocation, after the relevant writes and before the self-reads. Apply the same rule to any post-read barrier. Reject programs when no such placement exists.
@coderabbitai[bot] on GitHub · 2026-10-04 01:14 UTC · original
On
src/graphics/shader/recompiler/Tessellation.hline 21 (outdated):🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 2882
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 36748
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 29923
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 26973
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 21949
Propagate failed tessellation analysis so the draw can be skipped.
When interface reflection fails for a supported domain and topology,
AnalyzeTessellationProgramsreturns false and leaves the strides at zero.PrepareTessellationProgramsignores the result and copies those zero strides to every stage.ProgramCache::Getthen callsTranslateProgram;LowerTessellationMemoryrejects the zero strides, and the newEXITpath callsstd::_Exit(321). The emulator terminates instead of skipping the draw. Propagate the failure to the draw path and skip the draw before compiling its tessellation stages.@coderabbitai[bot] on GitHub · 2026-10-04 01:14 UTC · original · reviewed
Actionable comments posted: 4
ℹ️ Review info
⚙️ Run configuration
4cfb511c-d846-440b-b83a-8a8ca0d48dcc📥 Commits
Reviewing files that changed from the base of the PR and between
db17585277and ab928bc73c449f9ed441e9ceac1e07cc724f3ec1.📒 Files selected for processing (6)
src/graphics/shader/recompiler/ShaderRecompiler.cppsrc/graphics/shader/recompiler/Tessellation.cppsrc/graphics/shader/recompiler/Tessellation.hsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterFlow.cppsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterTessellation.cppsrc/graphics/shader/recompiler/ir/passes/ConstantPropagation.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.
@coderabbitai[bot] on GitHub · 2026-10-15 23:22 UTC · original · reviewed
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
3c73bdaf-7024-4427-a303-bec7da108ff4📥 Commits
Reviewing files that changed from the base of the PR and between 81c791099dfa64a0b7583fa14b47b352b7c7d0cb and f1217f9113132cda5db1157131dfa81168bcc3e8.
📒 Files selected for processing: 8
src/graphics/shader/recompiler/ShaderRecompiler.cppsrc/graphics/shader/recompiler/Tessellation.cppsrc/graphics/shader/recompiler/Tessellation.hsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterTessellation.cppsrc/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; 7 remain after this review.
@ -151,0 +248,4 @@ConstantU32(ctx.state, tess.output_control_points));ctx.state.builder.AddFunction(spv::OpLogicalAnd, TypeBool(ctx.state), both, condition,inside);condition = both;@coderabbitai[bot] on GitHub · 2026-10-15 23:22 UTC · original
🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 8072
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 43630
Do not silently discard dynamically addressed patch-constant stores.
LowerTessellationMemorykeeps non-immediate patch-range stores classified asControlOutput. The emitter then suppresses them when their derived vertex is outsideoutput_control_points. A matching TES patch read can therefore observe an unwritten patch output.Classify proven patch-range stores as
PatchOutput. Otherwise, report unsupported lowering instead of dropping the write.@defektu on GitHub · 2026-10-16 14:44 UTC · original
@Nmzik this is resolved for main with #1035
@Nmzik on GitHub · 2026-10-29 04:56 UTC · original
@defektu in main. credited
Pull request closed