shader: recompiler fixes for My First Gran Turismo (ForceUnorm samplers, F64 ops, scratch descriptor dwords, z slices, RTE) #1034
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!1034
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1034/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:06 UTC · original
defektu:pr/mfgt-shader→main· +457 −22 · 25 files · 13 commits · closed without mergingThis is one of a few PRs that together get My First Gran Turismo (PPSA24156) running: #1030 (font), #1031 (hle), #1032 (tess), #1033 (host), #1034 (shader), and the draft #1035 (mixed sample counts), which the game also needs to get past the loading screen after "Start" (without it the game stops with "mixed color/depth sample counts are unsupported"). Each PR builds and passes the tests on its own; the title only works with all of them.
Checked by hand on a combined branch (all of the above) on an RTX 5060 Ti, Windows 11, clean save data: intro, title screen (car, lighting, reflections), main menu and the License Center screen. The individual PRs were not run in the game on their own.
Note: on current
mainthis title waits at the "Sign in to PlayStation Network" dialog untilCancelis pressed; that comes from the sign-in dialog change, not from this PR.Commits
Body
Shared recompiler changes needed by My First Gran Turismo:
ForceUnormCoords(S# bit 15) is recorded per snapshot sampler and applied in the emitter by normalizing thecoordinate, because Vulkan forbids unnormalized coordinates with implicit LOD;
S_CBRANCH_CDBG*opcodes;S_ENDPGMat0x1f(RDNA pads the code tail withit);
is replaced by zero. Image/sampler words that trace to a subgroup ballot are stale lane masks and are zeroed too;
RoundingModeRTEdeclaration for FP64 shaders (round-to-nearest-even is the FP32 default; the NVIDIA compilernever returned from
vkCreateComputePipelinesfor a large module that carried it);SPI_SHADER_COL_FORMATsnorm16 mode are unpacked as snorm16 (they were read as half floats);once per dispatch on the host, so z cannot be known otherwise);
S_SWAPPC_B64with a return address is skipped with one log line. The one My First Gran Turismoruns every frame (
CS 0x2218a07ab01d4f46) holds sixIMAGE_BVH_INTERSECT_RAY, i.e. it is a ray tracing shader.Any other unsupported instruction still exits. The ray tracing work replaces the unconditional skip with a check of
its
--raytracingoption.Review notes
titles, so a regression check on a few of them (for example their menus, which exercise the sampler and
barrier paths) from someone with those games would be very welcome before merging.
ResourceMaterialization.cppafter nmzik's "Share sampler descriptor snapshots"(
7f158c65); the unnormalized flag is looked up bybinding.source.Testing: builds, 23 test executables pass.
🤖 Generated with Claude Code
@coderabbitai[bot] on GitHub · 2026-10-04 01:12 UTC · original · edited 2026-10-04 02:20 UTC
Navigate logical layers of code changes, visualize relationships, and explore their blast radius.
📝 Walkthrough
Walkthrough
The changes add compute-shader handling for per-z-slice specialization and unsupported function calls. They move forced unnormalized sampler handling into shader specialization and coordinate normalization. They add FP64 shader operations and update descriptor validation, runtime operation handling, opcode decoding, and SPIR-V lane and export emission.
Suggested reviewers:
francoisatt,nmzikPriority: ➖ Normal
Change: Bug fix
Merge Risk: 🟡 Moderate · up to
8d415Some affected dispatches can terminate the emulator or select the wrong resource, and a narrower sampler case can fail shader generation. Address these issues before merging.
Security Architecture Review
Security architecture risk: 🟡 Moderate · up to
8d415Unsupported resource-selection expressions can now be replaced with different, accepted descriptors. This creates a risk of incorrect resource reads or writes within the running game. Access beyond the game's existing authority has not been demonstrated.
Retained concerns
Security review details
Security Blast Radius
Security Findings and Attack Paths
Trust Boundaries and Controls
Resilience and Maintainability Implications
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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.@ -139,0 +141,4 @@// S# bit 15 (ForceUnormCoords) from uniform data, known only at bind time, so the decision lives// in the shader: the bit is recorded in ResourceSpecialization::unnormalized_samplers and the// emitter divides the texel-space coordinates by the level 0 extent (NormalizeForcedUnormCoord).sampler_info.unnormalizedCoordinates = VK_FALSE;@coderabbitai[bot] on GitHub · 2026-10-04 01:12 UTC · original
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Normalize forced-unnormalized gather coordinates.
When
ForceUnormCoordsis set, this sampler now expects normalized coordinates.spirvEmitterImage.cppstill passes texel-space coordinates toOpImageGatherandOpImageDrefGatherat Lines 722–769. For example, an x coordinate of 8 on a 64-texel image reaches the host as 8 instead of 8/64. Apply the conversion to gathers, including the 1D gather helper, before switching the host sampler to normalized coordinates. (docs.vulkan.org)@coderabbitai[bot] on GitHub · 2026-10-04 01:12 UTC · original
On
src/graphics/host_gpu/renderer/renderCompute.cppline 395 (outdated):🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
The thread-dimensions indirect path dispatches with possibly stale host counts.
The comment says the device handles the dispatch: "Hand the address to the device and let it do both steps." The code does the opposite. It sets
indirect_args = 0, so the CPU-sidethread_group_*values are used for the dispatch.Lines 235-237 state that these values "can be stale or zero" for indirect dispatches. The zero-count skip was also bypassed for this case. As a result, this path can dispatch the wrong number of groups, or silently dispatch zero groups.
Choose one fix:
In either case, update the comment to match the behavior.
@coderabbitai[bot] on GitHub · 2026-10-04 01:12 UTC · original
On
src/graphics/host_gpu/renderer/renderCompute.cppline 457 (outdated):🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Obtain the indirect argument buffer before you finalize the bindings, and check the result.
ObtainBufferruns here, afterRebindBuffersandCommitBindings.DispatchIndirect(Lines 513-517) explains why that order is unsafe: "Acquiring arguments can merge cache buffers; finalize shader bindings afterward." If a merge happens here, the descriptors that are already committed can reference a stale or destroyed buffer.This path also does not check for
args_buffer == nullptror a misalignedargs_offset, whileDispatchIndirectdoes.Move the
ObtainBuffercall betweenRebindImagesandRebindBuffers. Then add the sameEXIT_IFchecks thatDispatchIndirectuses.Proposed fix
Then use the prefetched
args_bufferandargs_offsetin theindirect_args != 0branch.@ -780,2 +843,3 @@const auto& candidate = state.program.info.images[resource];const auto coord =const auto coord = NormalizeForcedUnormCoord(ctx, resource, mem.sampler,@coderabbitai[bot] on GitHub · 2026-10-04 01:12 UTC · original · edited 2026-10-04 02:05 UTC
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Scale explicit gradients with the sample coordinate.
When
ImageSampleFlagDerivativeandforce_unnormalizedare both set, this call divides the coordinate by the image extent. TheGradoperands built at Lines 808–813 remain in texel-space units. Those operands describe the sampling derivatives, so the host receives an incorrect footprint even though it receives the corrected coordinate. Divide each spatial gradient component by the same extent. (registry.khronos.org)✅ Addressed in commits
d78c73cto8d41536@coderabbitai[bot] on GitHub · 2026-10-04 01:12 UTC · original · edited 2026-10-04 01:50 UTC
On
src/graphics/shader/recompiler/frontend/decode/ScalarAluOps.cppline 100 (outdated):📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Describe
0x1fas theS_CODE_ENDpadding marker.RDNA assigns SOPP opcode
0x1ftoS_CODE_END; this table already maps0x01toS_ENDPGM. The alias may be intentional to stop decoding at padding, but the comment currently misstates the ISA. Clarify that intent. (amd.com)Proposed comment correction
📝 Committable suggestion
✅ Addressed in commits
e1dd200to11343ef@ -1676,0 +1731,4 @@std::unordered_set<const Inst*> visited;if (TracesToWaveMask(descriptor.dwords[bad_dword], visited, 0u)) {descriptor.dwords[bad_dword] = Value(0u);handle->SetArg(bad_dword, Value(0u));@coderabbitai[bot] on GitHub · 2026-10-04 01:12 UTC · original
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Do not treat ballot ancestry as proof of a scratch descriptor word.
If a shader uses a ballot result to select or address an image descriptor,
TracesToWaveMaskalso finds that ballot through the descriptor word’s operands. The retry then replaces the selected descriptor word with zero. This can silently select the wrong image instead of preserving or rejecting the dynamic descriptor. Require proof that the word itself is dead scratch before substituting zero.@ -272,6 +275,18 @@ private:source->GetOpcode() != ValueOpcode::IAddCarry32)) {return finish(false);}} else if (op == ValueOpcode::CompositeExtractU32x4) {@coderabbitai[bot] on GitHub · 2026-10-04 01:12 UTC · original · edited 2026-10-04 02:05 UTC
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Implement evaluation for accepted U32x4 extracts.
When a validated descriptor word uses
CompositeExtractU32x4,SrtWalker::EvaluateInsthas no matching case and returnsfalse. Adding the opcode toIsRuntimeUniformOpdoes not make the value evaluable. Add U32x4 extraction evaluation, including the accepted source forms, so these descriptor values can reachEvaluateDescriptorsuccessfully.✅ Addressed in commits
d78c73cto8d41536@coderabbitai[bot] on GitHub · 2026-10-04 01:12 UTC · original · reviewed
Actionable comments posted: 7
ℹ️ Review info
⚙️ Run configuration
923e1010-0f0b-401a-bc43-f7de51526f2e📥 Commits
Reviewing files that changed from the base of the PR and between
db17585277andaafa72eeb7.📒 Files selected for processing (25)
src/graphics/host_gpu/renderer/cache/samplerCache.cppsrc/graphics/host_gpu/renderer/pipeline/pipelineCache.cppsrc/graphics/host_gpu/renderer/render.hsrc/graphics/host_gpu/renderer/renderCompute.cppsrc/graphics/shader/recompiler/ShaderRecompiler.cppsrc/graphics/shader/recompiler/ShaderRecompiler.hsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterFlow.cppsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterHelpers.cppsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cppsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterInstructions.hsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterInternal.hsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterModule.cppsrc/graphics/shader/recompiler/frontend/decode/ScalarAluOps.cppsrc/graphics/shader/recompiler/frontend/decode/ShaderDecoder.hsrc/graphics/shader/recompiler/frontend/decode/VectorAluOps.cppsrc/graphics/shader/recompiler/frontend/translate/Translate.cppsrc/graphics/shader/recompiler/frontend/translate/Vector.cppsrc/graphics/shader/recompiler/ir/ShaderIR.hsrc/graphics/shader/recompiler/ir/opcodes/ValueOpcodes.incsrc/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cppsrc/graphics/shader/recompiler/ir/passes/ResourceMaterialization.hsrc/graphics/shader/recompiler/ir/passes/ResourceTracking.cppsrc/graphics/shader/recompiler/ir/passes/SrtWalker.cppsrc/graphics/shader/shader.cppsrc/graphics/shader/shader.hIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 3 remain after this review.
@ -259,0 +294,4 @@EXIT("compute shader 0x%016" PRIx64 " needs per-slice compilation that this dispatch cannot use ""(thread dimensions or more than 16 z groups)\n",sh_ctx.GetCs().cs_regs.data_addr);}@coderabbitai[bot] on GitHub · 2026-10-04 01:59 UTC · original
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 1465
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 9989
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 256
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 8550
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 5653
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 2492
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 238
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 1282
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 2062
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 3804
Skip unsupported group-Z dispatches instead of exiting.
CpOpDispatchDirectforwards the packet’s Z count and mode unchanged. When the initialGetComputeProgramprobe returns no program for a non-function-call shader markedneeds_group_z, thread-dimensions mode or a Z count above 16 prevents slicing and reachesEXIT.EXITinvokesstd::_Exit(321), so a guest dispatch can terminate the emulator process. Log, reset bindings, and return instead.🐛 Suggested fix
📝 Committable suggestion
@coderabbitai[bot] on GitHub · 2026-10-04 01:59 UTC · original · reviewed
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
e8d127ea-0e88-47a3-86c8-478997775116📥 Commits
Reviewing files that changed from the base of the PR and between
aafa72eeb7and11343ef63f.📒 Files selected for processing (3)
src/graphics/host_gpu/renderer/render.hsrc/graphics/host_gpu/renderer/renderCompute.cppsrc/graphics/shader/recompiler/frontend/decode/ScalarAluOps.cpp🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 0 remain after this review.
@ -470,0 +514,4 @@words.insert(words.end(), parts, parts + components);state.builder.AddFunction(spv::OpCompositeConstruct, words);return result;}@coderabbitai[bot] on GitHub · 2026-10-04 02:16 UTC · original
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 32412
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 6473
Extract the 1D-array extent before converting gradients.
For
Dim1DArraysamples with explicit gradients and aforce_unnormalizedsampler,componentsis 1, so the code skips extracting fromsize.ImageViewSizeTypereturns auvec2, which then reachesOpConvertUToFwith a scalarf32result type. Extract the extent whenevercoordinate_componentsis greater than 1.🐛 Suggested fix
📝 Committable suggestion
@coderabbitai[bot] on GitHub · 2026-10-04 02:16 UTC · original · reviewed
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
4dd9b6d2-459f-4e8a-bea9-a898cc2f51fc📥 Commits
Reviewing files that changed from the base of the PR and between
11343ef63fand8d41536079.📒 Files selected for processing (2)
src/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cppsrc/graphics/shader/recompiler/ir/passes/SrtWalker.cpp🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 4 remain after this review.
@Nmzik on GitHub · 2026-10-04 23:06 UTC · original
@defektu Most of changes are in main(some were hacks). Credited
@Nmzik on GitHub · 2026-10-10 23:50 UTC · original
@defektu this was merged into main. Forgot to close. Credited ofc
Pull request closed