Graphics shader fixes (Game: Beast of Reincarnation) #613
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!613
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/613/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?
@psnwd on GitHub · 2026-09-14 07:11 UTC · original
psnwd:graphics-shader-fixes→main· +8275 −334 · 113 files · 38 commits · closed without mergingFixes a set of shader and graphics faults hit by Beast of Reincarnation
(PPSA29343). Each one was a hard failure or silent no-op that blocked the
title from booting into gameplay.
Shader recompiler
S_SWAPPC_B64,S_CODE_END,S_CBRANCH_CDBGSYS.S_CBRANCH_CDBGSYSbranches on the debug-mode bit, clear without adebugger, so it is decoded but kept out of the branch predicates: the CFG
sees a plain instruction rather than an edge that can never be taken.
S_CODE_ENDends the executable body, so decoding stops there instead ofrunning into metadata.
IMAGE_GATHER4_L(MIMG 0x44) was undecoded and failed CFG construction.The shader using it walks a mip pyramid, so base-level sampling would read
the wrong mip.
OpImageGathertakes no Lod operand, so the gather is builtfrom the four samples it is defined to return, sampled at texel centres so
the sampler's address modes still apply at edges. Unverifiable variants
(array, cube, dref, offset) fail loudly instead of rendering wrong.
opcode: two enabled components is one 64-bit value. Image is declared R64ui
with a real 64-bit scalar sampled type (the IR's U64 is a u32 pair, which is
a vector and not a legal sampled type), with bitcasts bridging the two. The
descriptor check now requires the 64-bit guest format for 64-bit atomics
instead of rejecting anything that is not k32UInt.
index, lane base, per-wave caps and wave count, so wave32 was rejected. Also
corrects the thread budget: the wave-count field is 4 bits, so the limit is
15 waves at any width, not
15 * 64.Graphics
for any view at that address and returned before the depth-as-storage guard,
so a colour storage binding on memory the guest had reused was handed a
depth image. Later checks all test
info.pixel_formatwhile the view isbuilt from the backing format, so nothing caught it.
blocks through an uncompressed view writes somewhere. They already carry
eExtendedUsage; only the flag was missing. Layered images qualify onlywhere maintenance6 reports
blockTexelViewCompatibleMultipleLayers.the texel chain. Block level N still covers texel level N, so the range is
clamped to the levels that exist rather than renumbered. Renumbering selects
a mip too large. Multisampled descriptors pass through untouched.
VK_EXT_shader_image_atomic_int64andVK_KHR_maintenance6whenpresent, as optional extensions, so devices without them are still selected.
the prepared frame so the blit converts once.
Audio
uiMaxChannelsis whatthe port can emit, not what the stream carries, so declaring it makes a
stereo stream fail on its first channel pair element. Zero is not an option
either: it needs a program config element the two-byte header has no room
for. Candidate layouts are tried until one decodes, then locked.
AGC
error code instead of aborting on an unsupported layout.
Testing
Built with clang-cl. All test suites pass: shader_cfg, shader_recompiler_compute,
resource_materialization, resource_tracking, image_page_table,
shader_vertex_metadata, scalar_provenance. Verified against the title with
Vulkan and shader validation enabled: no validation errors, no SPIR-V failures.
Known remaining
3D renders correctly into the HDR scene buffer, but the tonemap output contains
different contents, so that pass samples the wrong image. Not addressed here.
Summary by CodeRabbit
New Features
Bug Fixes
@coderabbitai[bot] on GitHub · 2026-09-14 07:12 UTC · original · edited 2026-09-15 05:31 UTC
📝 Walkthrough
Walkthrough
The pull request updates Vulkan image and presentation handling, adds shader decoder and recompiler support for TTMP registers, shader handoffs, explicit-LOD gathers, and 64-bit image atomics, and changes end-of-pipe packet patching and AAC channel-layout detection.
Changes
Graphics and Vulkan behavior
src/graphics/host_gpu/graphicContext.h,src/graphics/presentation/window/vulkanWindow.cpp,src/graphics/presentation/window/swapchain.cppsrc/graphics/host_gpu/renderer/cache/*,src/graphics/host_gpu/renderer/image/*,src/graphics/host_gpu/renderer/pipeline/descriptors.cppsrc/graphics/host_gpu/renderer/image/imageView.cpp,src/graphics/host_gpu/renderer/pipeline/descriptors.cppShader recompiler updates
src/graphics/shader/recompiler/ir/*,src/graphics/shader/recompiler/backend/spirv/*src/graphics/shader/recompiler/frontend/decode/*src/graphics/shader/recompiler/frontend/translate/*,src/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cppsrc/graphics/shader/shader.cpptests/shaderCfgTests.cppCommand patching and AAC decoding
src/libs/agc.cppsrc/libs/ajm/aac_decoder.hPriority: ➖ Normal
Estimated code review effort: 5 (Critical) | ~120 minutes
Change: Bug fix
Sequence Diagram(s)
Suggested reviewers:
nmzikMerge Risk: 🟠 High · up to
8fe8aThe change can cause incorrect audio or graphics and shader failures, including process termination on some Vulkan devices. These issues should be fixed before merge.
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring Coverage
Explanation
Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 84 functions across 29 files. (2 skipped: 1 unsupported, 1 too large.)
✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment
@coderabbitai helpto get the list of available commands.@coderabbitai[bot] on GitHub · 2026-09-14 07:23 UTC · original
On
src/graphics/host_gpu/renderer/pipeline/descriptors.cppline 563 (outdated):🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 184
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 29536
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 8841
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 5058
Align DynamicStorage mip counts with the clamped view range.
StorageMipCountuses the raw descriptor range.ResolveTextureclamps that range to the physicallevelscount.RebindImagesexits whenresource.mip_countdiffers frombinding.desc.view_info.level_count. A DynamicStorage descriptor with collapsed tail mips can therefore fail during rebinding. Make the IR mip count match the effective clamped range.🤖 Prompt for AI Agents
@coderabbitai[bot] on GitHub · 2026-09-14 07:23 UTC · original
On
src/graphics/presentation/window/swapchain.cppline 403 (outdated):🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Select an sRGB surface format in every branch.
When the surface reports the special single
eUndefinedformat, line 394 retainseR8G8B8A8Unorm.PrepareFramenow retains the guest transfer format, so the present blit does not encode linear output for that path. The image appears too dark.Require
vk::ColorSpaceKHR::eSrgbNonlinearin this predicate. Also initialize theeUndefinedfallback with an sRGB format and its reported color space.🤖 Prompt for AI Agents
@ -136,0 +143,4 @@}return state.builder.Type(spv::OpTypeImage, scalar_type, info.spirv_dimension,image.depth_compare ? 1u : 0u, info.arrayed, info.multisampled,sampled, format);@coderabbitai[bot] on GitHub · 2026-09-14 07:23 UTC · original
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Reject unsupported 64-bit image-atomic shaders before SPIR-V emission.
IMAGE_ATOMIC_*64instructions reachResourceTracking::Merge, which setsImageResource::atomic64.PipelineCache::ProgramCache::CompilePermutationthen compiles the shader, whileImageTyperequiresCapabilityInt64ImageEXTandSPV_EXT_shader_image_int64unconditionally.GraphicContext::image_atomic_int64_enabledis not checked. When the device lacks the extension or feature, shader-module or pipeline creation may fail, andRequireVulkanSuccessterminates the process on shader-module failure.Add the shared guard in
CompilePermutationbeforeShaderRecompiler::CompileProgram, using theGraphicContext::image_atomic_int64_enabledcapability. The repository has no fallback that disables this guest path.🤖 Prompt for AI Agents
@ -432,0 +532,4 @@state.builder.AddFunction(spv::OpConvertFToS, TypeI32(state), lod_int, level);const auto size = state.builder.AllocateId();state.builder.AddFunction(spv::OpImageQuerySizeLod, TypeU32Vector(state, 2), size, image,lod_int);@coderabbitai[bot] on GitHub · 2026-09-14 07:23 UTC · original
🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
Resolve the effective gather mip level before querying the extent.
EmitTwoDimensionalGatherLodconverts the rawlodonly forOpImageQuerySizeLod, but passes the original float to eachOpImageSampleExplicitLod. Vulkan sampling applies the sampler’s LOD limits and mipmap mode. A fractional LOD can select another level or interpolate between levels, and sampler limits can clamp the LOD. The queried extent can therefore differ from the texel grid used by the samples.For
IMAGE_GATHER4_L, apply the guest mip-selection and LOD-clamp rules once. Use the resulting level forOpImageQuerySizeLodand all four samples. Ensure the sample operations do not interpolate between mip levels, because a gather must return four texels from one mip level.🤖 Prompt for AI Agents
@coderabbitai[bot] on GitHub · 2026-09-14 07:23 UTC · original
On
src/graphics/shader/recompiler/ir/passes/ResourceTracking.cppline 579 (outdated):🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
Do not merge incompatible storage-image operation widths.
AddImagecan merge a 64-bit atomic with a 32-bit atomic orImageWriteon the same descriptor source. Line 579 then marks the complete resource asatomic64.The backend consequently emits every operation against an
R64uiimage. A narrow atomic then attempts a 32-to-64-bitOpBitcast, andImageWritesupplies a 32-bit texel vector to a 64-bit image type. This produces invalid SPIR-V.Include the storage texel type in the resource identity, or reject mixed-width use before emission.
🤖 Prompt for AI Agents
@coderabbitai[bot] on GitHub · 2026-09-14 07:23 UTC · original
On
src/libs/ajm/aac_decoder.hline 132 (outdated):🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Do not retry after
DecodePacket()has emitted a frame.DecodePacket()returns false whenWriteFrame()cannot fit all samples inoutput. In that path,WriteFrame()has already copied data and advanced gapless and sample counters. This loop reopens another layout and resets onlyoutput_offsetandresult, so it can overwrite output and count or skip samples twice.Retry only when the failed attempt produced no frames. Lock the selected layout once it produces a frame, even when the packet later reports
AJM_RESULT_NOT_ENOUGH_ROOM.Proposed fix
🤖 Prompt for AI Agents
@coderabbitai[bot] on GitHub · 2026-09-14 07:23 UTC · original · reviewed
Actionable comments posted: 6
🤖 Prompt for all review comments with AI agents
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Advanced
Run ID:
1f16d5f0-36f9-4e26-8235-1707f69fc76e📥 Commits
Reviewing files that changed from the base of the PR and between
a9ae04c152and8fe8a7bad0.📒 Files selected for processing (31)
src/graphics/host_gpu/graphicContext.hsrc/graphics/host_gpu/renderer/cache/textureCache.cppsrc/graphics/host_gpu/renderer/cache/textureCache.hsrc/graphics/host_gpu/renderer/image/image.cppsrc/graphics/host_gpu/renderer/image/imageView.cppsrc/graphics/host_gpu/renderer/image/imageView.hsrc/graphics/host_gpu/renderer/pipeline/descriptors.cppsrc/graphics/presentation/window/swapchain.cppsrc/graphics/presentation/window/vulkanWindow.cppsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterAnalysis.cppsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cppsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterInstructions.hsrc/graphics/shader/recompiler/frontend/decode/ImageOps.cppsrc/graphics/shader/recompiler/frontend/decode/ScalarAluOps.cppsrc/graphics/shader/recompiler/frontend/decode/ShaderDecoder.cppsrc/graphics/shader/recompiler/frontend/decode/ShaderDecoder.hsrc/graphics/shader/recompiler/frontend/translate/Control.cppsrc/graphics/shader/recompiler/frontend/translate/Memory.cppsrc/graphics/shader/recompiler/frontend/translate/Scalar.cppsrc/graphics/shader/recompiler/frontend/translate/Translate.cppsrc/graphics/shader/recompiler/frontend/translate/Translator.hsrc/graphics/shader/recompiler/ir/Reg.hsrc/graphics/shader/recompiler/ir/ShaderIR.hsrc/graphics/shader/recompiler/ir/opcodes/ValueOpcodes.cppsrc/graphics/shader/recompiler/ir/opcodes/ValueOpcodes.incsrc/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cppsrc/graphics/shader/recompiler/ir/passes/ResourceTracking.cppsrc/graphics/shader/shader.cppsrc/libs/agc.cppsrc/libs/ajm/aac_decoder.htests/shaderCfgTests.cppIncluded review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.
@psnwd on GitHub · 2026-09-15 19:50 UTC · original
Update:
Seems like it's getting good results. It just needs a bit more work, especially with Unreal support (Nanite, UMG blur, etc.). We also need to work on the audio.
@psnwd on GitHub · 2026-10-02 08:41 UTC · original
Update: The game is now running at 5–7 FPS. There are still some shader issues, which I'm currently working on. :)
@Nmzik on GitHub · 2026-10-03 10:27 UTC · original
@psnwd UPDATE: Game now goes in-game on main (with graphical artifacts in-game/tested quality mode). THANKS! I attributed you wherever possible


@psnwd on GitHub · 2026-10-04 06:23 UTC · original
I think this is done for me. I'll try to contribute whenever I can, but I don't think it's realistic for me to do this as a hobby in real life. The software industry is getting worse every day, so I'm going to focus on retiring from this profession.
Anyway, good luck with your developments! :)
And one more thing, I've been working on some FPS improvements and driver fixes. If I have time, I'll try to finish them and submit them as my last PR.
Pull request closed