Improve Uncharted 4 compat shaders, GPU execution, media playback #512
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!512
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/512/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?
@Almo7aya on GitHub · 2026-09-08 18:56 UTC · original
Almo7aya:fix/uncharted-compatibility→main· +3763 −315 · 49 files · 45 commits · closed without mergingI dont expect this PR to be merged, but I wanted to open it so you can cherrypick/reimplmenet some changes from this branch,
This branch takes Uncharted Legacy of Thieves Collection from unbootable state to rendering the gameplay
FPS is not great, and there are glitches in the 3D rendering
changes:
Support bounded GPU-indexed descriptor tables, improve resource tracking through branches and loops, and add missing
shader instruction support.
Correct texture sampling, depth comparisons, stencil handling, and buffer offsets while reducing redundant shader
preparation and specialization.
Preserve submitted command data and synchronize indirect arguments, GPU readbacks, and completion labels.
Fix Windows memory remapping and stage file reads before copying into protected guest memory.
Implement the Vdecsw software video decoder API, correct end-of-stream reporting, and support streamed ATRAC9 input.
Correct save-dialog results and progress states, and defer swapchain recreation while minimized.
@Gih-pt on GitHub · 2026-09-08 19:15 UTC · original
Screenshot, please.
@Almo7aya on GitHub · 2026-09-08 19:20 UTC · original
@Gih-pt
Gameplay


Menu
@Crispy81 on GitHub · 2026-09-13 06:09 UTC · original
Outstanding. Love both of these games.
@coderabbitai[bot] on GitHub · 2026-09-13 21:03 UTC · original · edited 2026-09-23 14:01 UTC
Navigate logical layers of code changes, visualize relationships, and explore their blast radius.
📝 Walkthrough
Walkthrough
The pull request updates GPU command processing, host rendering, and shader recompilation. It adds indirect resource tracking and emission, changes image and stencil handling, and adds compute-dispatch paths. It also updates guest memory and file operations, zero-sized surface handling, save-data dialog behavior, and video decoder APIs, including a software decoder interface and explicit drain handling.
Priority: ⬆️ High
Merge Risk: 🟡 Moderate · up to
d7554This change makes Uncharted boot and render, but several paths can still end emulation or corrupt results. These include predicated one-dword NOP packets, shaders that select many indirect images, and vectored file reads into GPU-tracked memory. Logging on common memory-map calls also passes the wrong argument type. The software video decoder can use freed memory after cross-API deletion, and it accepts an oversized first input. These issues should be fixed before merging.
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring Coverage
Explanation
Docstring coverage is 7.11% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 211 functions across 53 files. (1 skipped: 1 unsupported.)
Comment
@coderabbitai helpto get the list of available commands.@coderabbitai[bot] on GitHub · 2026-09-13 21:18 UTC · original
On
src/graphics/host_gpu/renderer/image/imageView.cppline 335 (outdated):🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Validate the mip range before calling
std::clamp.A zero
normalized.level_countwith a nonzeronormalized.base_levelmakes the upper bound smaller than the lower bound. This violates thestd::clampprecondition beforelevels_validrejects the descriptor. The result is undefined behavior instead of the intendedEXIT. (eel.is)Move the minimum-LOD clamp after the mip-range validation, or reject zero and overflowing ranges before this calculation.
🤖 Prompt for AI Agents
@coderabbitai[bot] on GitHub · 2026-09-13 21:18 UTC · original · edited 2026-09-23 13:43 UTC
On
src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cppline 1251 (outdated):🚀 Performance & Scalability | 🟠 Major | ⚡ Quick win
Bound the indirect-buffer candidate count during materialization.
table.keyscomes fromEvaluateDispatch, which allows up toMaxValues(65536) entries. For each key this loop performs four guest reads and a linearstd::ranges::findovertable.descriptors. When the keys select many distinct descriptors, the dedupe cost becomes quadratic in the number of candidates, and the work runs on the per-draw specialization path.The image path already bounds this:
MaterializeIndirectImagereturnsfalseoncenext.descriptors.size() >= ShaderInfo::MaxImages. The buffer path has no equivalent bound;ShaderInfo::MaxBuffersis only checked later inBuildResourceSpecialization, after all candidates were already read and compared.Add the same early bound so an over-approximated key domain fails fast instead of stalling specialization.
♻️ Proposed early bound
🤖 Prompt for AI Agents
✅ Addressed in commits
00a16f3tod75549e@ -671,0 +799,4 @@if (queue.consumed >= queue.depth ||(!queue.inputs.empty() &&(queue.queued_input_bytes >= MaxQueuedInputBytes ||input->au_size > MaxQueuedInputBytes - queue.queued_input_bytes))) {@coderabbitai[bot] on GitHub · 2026-09-13 21:18 UTC · original
🔒 Security & Privacy | 🛡️ Analyzed with Security Review | 🟠 Major | ⚡ Quick win
Denial of Service
Reachability: External
Exploitability: Moderate
CWE: CWE-400 — Uncontrolled Resource Consumption
Apply
MaxQueuedInputBytesto the first input.The
!queue.inputs.empty()condition disables the byte limit for an empty queue. A guest can submit an access unit close toINT32_MAX, which causes a multi-gigabytestd::vectorallocation and can terminate the host process.Proposed fix
🤖 Prompt for AI Agents
@ -671,0 +988,4 @@std::scoped_lock lock(g_software_mutex);SoftwareQueue queue;queue.depth = config->decode_input_queue_depth;g_software_queues.emplace(state, std::move(queue));@coderabbitai[bot] on GitHub · 2026-09-13 21:18 UTC · original
🔒 Security & Privacy | 🛡️ Analyzed with Security Review | 🟠 Major | 🏗️ Heavy lift
🧩 Analysis chain
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 29051
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 15269
Reachability: External
Exploitability: Moderate
CWE: CWE-416 — Use After Free
Reject cross-API deletion of Vdecsw decoders.
VideoDec2::DeleteDecoderremoves onlyg_decodersand deletes the decoder. Vdecsw operations validate onlyg_software_queues, so a later operation can pass the deleted pointer toDecoder::DecodeorDecoder::Drain. Remove the Vdecsw queue entry during shared deletion, or enforce API ownership before destruction.🤖 Prompt for AI Agents
@coderabbitai[bot] on GitHub · 2026-09-13 21:18 UTC · original · reviewed
Actionable comments posted: 4
🤖 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:
2ddcd966-8dc0-40d8-821d-e4e1b0929b0a📥 Commits
Reviewing files that changed from the base of the PR and between
d3d7bd33f8and 42ecfe284983772133cd7c5dcbc7fcbb03fddcac.📒 Files selected for processing (52)
src/graphics/guest_gpu/command_processor/commandProcessor.hsrc/graphics/guest_gpu/command_processor/pm4Handlers.cppsrc/graphics/guest_gpu/graphicsRun.cppsrc/graphics/guest_gpu/graphicsRun.hsrc/graphics/guest_gpu/pm4.cppsrc/graphics/guest_gpu/pm4.hsrc/graphics/host_gpu/graphicContext.hsrc/graphics/host_gpu/renderer/cache/textureCache.cppsrc/graphics/host_gpu/renderer/cache/textureCache.hsrc/graphics/host_gpu/renderer/depthRenderTarget.cppsrc/graphics/host_gpu/renderer/image/imageInfo.hsrc/graphics/host_gpu/renderer/image/imageView.cppsrc/graphics/host_gpu/renderer/image/imageView.hsrc/graphics/host_gpu/renderer/pipeline/descriptors.cppsrc/graphics/host_gpu/renderer/pipeline/pipelineCache.cppsrc/graphics/host_gpu/renderer/pipeline/pipelineCache.hsrc/graphics/host_gpu/renderer/renderCompute.cppsrc/graphics/host_gpu/renderer/renderContext.cppsrc/graphics/presentation/window/swapchain.cppsrc/graphics/presentation/window/vulkanWindow.cppsrc/graphics/presentation/window/window.cppsrc/graphics/shader/recompiler/ShaderRecompiler.cppsrc/graphics/shader/recompiler/backend/spirv/SpirvEmitter.cppsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cppsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterInternal.hsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterMemory.cppsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterProgram.cppsrc/graphics/shader/recompiler/frontend/decode/ShaderDecoder.hsrc/graphics/shader/recompiler/frontend/decode/VectorAluOps.cppsrc/graphics/shader/recompiler/frontend/translate/Vector.cppsrc/graphics/shader/recompiler/ir/Program.cppsrc/graphics/shader/recompiler/ir/ResourceSnapshot.hsrc/graphics/shader/recompiler/ir/ShaderIR.hsrc/graphics/shader/recompiler/ir/passes/BindingLayout.cppsrc/graphics/shader/recompiler/ir/passes/ConstantPropagation.cppsrc/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/ResourceTracking.hsrc/graphics/shader/recompiler/ir/passes/SrtWalker.cppsrc/graphics/shader/recompiler/ir/passes/SrtWalker.hsrc/kernel/fileSystem.cppsrc/kernel/memory.cppsrc/kernel/memory.hsrc/kernel/memoryAddressSpace.incsrc/libs/agc.cppsrc/libs/ajm/atrac9_decoder.hsrc/libs/dialog.cppsrc/libs/libVideoDec2.cppsrc/libs/libs.cppsrc/libs/videoDec2Decoder.cppsrc/libs/videoDec2Decoder.hIncluded review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.
@ -17,2 +17,3 @@#define KYTY_PM4_R(cmd_id) (((cmd_id) >> 2u) & (Pm4::R_NUM - 1u))#define KYTY_PM4_LEN(cmd_id) ((((cmd_id) >> 16u) & 0x3fffu) + 2u)// AGC's count=-1 NOP contains only its header.#define KYTY_PM4_LEN(cmd_id) ((cmd_id) == 0xffff1000u ? 1u : ((((cmd_id) >> 16u) & 0x3fffu) + 2u))@coderabbitai[bot] on GitHub · 2026-09-23 14:01 UTC · original
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 4296
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 17825
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 12540
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 7866
Handle predicated header-only AGC NOP packets.
AgcCbNopemits0xffff1000for a one-dword NOP. Both predication helpers can set bit 0, producing0xffff1001.The raw-header checks do not recognize
0xffff1001.KYTY_PM4_LENreturns0x4001from its count field.ProcessPm4can abort for a one-dword final packet or whenm_predicate_skipis enabled.pm4.cppalso rejects the packet in its header-size guard.Mask bit 0 in
KYTY_PM4_LEN,graphicsRun.cpp, andpm4.cppwhen recognizing the header-only NOP.Suggested fix
Also apply the same predicate-bit mask to
header_only_nopinsrc/graphics/guest_gpu/pm4.cpp.📝 Committable suggestion
@ -543,3 +547,3 @@Swapchain::Status Swapchain::AcquireNextImage() {EXIT_IF(m_handle == nullptr || m_frame_index >= m_image_acquired.size());if (m_handle == nullptr) {@coderabbitai[bot] on GitHub · 2026-09-23 14:01 UTC · original
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 41767
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 41389
🌐 Web query:
official Vulkan vkAcquireNextImageKHR reference timeout UINT64_MAX VK_ERROR_OUT_OF_DATE_KHR💡 Result:
<source_evidence>
https://docs.vulkan.org/refpages/latest/refpages/source/vkAcquireNextImageKHR.html vkAcquireNextImageKHR(3) :: Vulkan Documentation Project - Name - C Specification - Parameters - Description - See Also - Document Notes ### Contents - Name - C Specification - Parameters - Description - See Also - Document Notes ## Name vkAcquireNextImageKHR - Retrieve the index of the next available presentable image ## C Specification To acquire an available presentable image to use, and retrieve the index of that image, call: ```c // Provided by VK_KHR_swapchain VkResult vkAcquireNextImageKHR( VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout, VkSemaphore semaphore, VkFence fence, uint32_t* pImageIndex); ``` ## Parameters - `device` is the device associated with `swapchain`. - `swapchain` is the non-retired swapchain from which an image is being acquired. - `timeout` specifies how long the function waits, in nanoseconds, if no image is available. - `semaphore` is VK_NULL_HANDLE or a semaphore defining a semaphore signal operation. - `fence` is VK_NULL_HANDLE or a fence to signal. - `pImageIndex` is a pointer to a `uint32_t` in which the index of the next image to use (i.e. an index into the array of images returned by `vkGetSwapchainImagesKHR`) is returned. ## Description If the `swapchain` has been created with the VK_SWAPCHAIN_CREATE_DEFERRED_MEMORY_ALLOCATION_BIT_KHR flag, the image whose index is returned in `pImageIndex` will be fully backed by memory before this call returns to the application, as if it is bound completely and contiguously to a single `VkDeviceMemory` object. If `semaphore` defines a semaphore signal operation, its first synchronization scope includes acquisition of the image. Valid Usage - VUID-vkAcquireNextImageKHR-swapchain-01285 `swapchain` must not be in the retired state - VUID-vkAcquireNextImageKHR-semaphore-01286 If `semaphore` is not VK_NULL_HANDLE, it must be unsignaled - VUID-vkAcquireNextImageKHR-semaphore-01779 If `semaphore` is not VK_NULL_HANDLE, it must not have any uncompleted signal or wait operations pending - VUID-vkAcquireNextImageKHR-fence-01287 If `fence` is not VK_NULL_HANDLE, `fence` must be unsignaled - VUID-vkAcquireNextImageKHR-fence-10066 If `fence` is not VK_NULL_HANDLE, `fence` must not be associated with any other queue command that has not yet completed execution on that queue - VUID-vkAcquireNextImageKHR-semaphore-01780 `semaphore` and `fence` must not both be equal to VK_NULL_HANDLE - VUID-vkAcquireNextImageKHR-surface-07783 If forward progress cannot be guaranteed for the `surface` used to create the `swapchain` member of `pAcquireInfo`, `timeout` must not be `UINT64_MAX` - VUID-vkAcquireNextImageKHR-semaphore-03265 `semaphore` must have a VkSemaphoreType of VK_SEMAPHORE_TYPE_BINARY Valid Usage (Implicit) - VUID-vkAcquireNextImageKHR-device-parameter `device` must be a valid VkDevice handle - VUID-vkAcquireNextImageKHR-swapchain-parameter `swapchain` must be a valid VkSwapchainKHR handle - VUID-vkAcquireNextImageKHR-semaphore-parameter If `semaphore` is not VK_NULL_HANDLE, `semaphore` must be a valid VkSemaphore handle - VUID-vkAcquireNextImageKHR-fence-parameter If `fence` is not VK_NULL_HANDLE, `fence` must be a valid VkFence handle - VUID-vkAcquireNextImageKHR-pImageIndex-parameter `pImageIndex` must be a valid pointer to a `uint32_t` value - VUID-vkAcquireNextImageKHR-swapchain-parent `swapchain` must have been created, allocated, or retrieved from `device` - VUID-vkAcquireNextImageKHR-semaphore-parent If `semaphore` is a valid handle, it must have been created, allocated, or retrieved from `device` - VUID-vkAcquireNextImageKHR-fence-parent If `fence` is a valid handle, it must have been created, allocated, or retrieved from `device` Host Synchronization - Host access to `swapchain` must be externally synchronized - Host access to `semaphore` must be externally synchronized - Host access to `fence` must be externally synchronized Return Codes Success : - VK_NOT_READY - VK_SUBOPTIMAL_KHR - VK_SUCCESS - VK_TIMEOUT Failure : - VK_ERROR_DEVICE_LOST - V... https://docs.vulkan.org/refpages/latest/refpages/source/VK_KHR_swapchain.html - vkAcquireNextImageKHR - vkCreateSwapchainKHR - vkDestroySwapchainKHR - vkGetSwapchainImagesKHR - vkQueuePresentKHR ... VkResult: - VK_ERROR_OUT_OF_DATE_KHR - VK_SUBOPTIMAL_KHR - ... 7) Does vkAcquireNextImageKHR block if no images are available? ... RESOLVED: The command takes a timeout parameter. Special values for the timeout are 0, which makes the call a non-blocking operation, and `UINT64_MAX`, which blocks indefinitely. Values in between will block for up to the specified time. The call will return when an image becomes available or an error occurs. It may, but is not required to, return before the specified timeout expires if the swapchain becomes out of date. ... - VK_SUBOPTIMAL_KHR - Presentation will still succeed, subject to the window resize behavior, but the swapchain is no longer configured optimally for the surface it targets. Applications should query updated surface information and recreate their swapchain at the next convenient opportunity. ... - VK_ERROR_OUT_OF_DATE_KHR - Failure. The swapchain is no longer compatible with the surface it targets. The application must query updated surface information and recreate the swapchain before presentation will succeed. ... These can be returned by both vkAcquireNextImageKHR and vkQueuePresentKHR. ... - Added issue 9, and the related VK_SUBOPTIMAL_KHR result code. - Renamed VK_OUT_OF_DATE_KHR to VK_ERROR_OUT_OF_DATE_KHR. - Revision 9, 2015-05-27 (James Jones) ... - Clarified the values of VkSurfacePropertiesKHR::minImageCount and the timeout parameter of the vkAcquireNextImageKHR function. - Revision 19, 2015-06-17 (James Jones) https://docs.vulkan.org/tutorial/latest/03_Drawing_a_triangle/04_Swap_chain_recreation.html Now we just need to figure out when swap chain recreation is necessary and call our new `recreateSwapChain` function. Luckily, Vulkan will usually just tell us that the swap chain is no longer adequate during presentation. The `vk::raii::SwapchainKHR::acquireNextImage` and `vk::raii::Queue::presentKHR` functions can return the following special values to indicate this. ... - `vk::Result::eErrorOutOfDateKHR`: The swap chain has become incompatible with the surface and can no longer be used for rendering. Usually happens after a window resize. Note that “vk::Result::eErrorOutOfDateKHR” is actually an error code and would trigger an exception by default. By defining “VULKAN_HPP_HANDLE_ERROR_OUT_OF_DATE_AS_SUCCESS,” this is treated as a success code and can therefore be returned by “vk::raii::SwapchainKHR::acquireNextImage” and “vk::raii::Queue::presentKHR.” - `vk::Result::eSuboptimalKHR`: The swap chain can still be used to successfully present to the surface, but the surface properties are no longer matched exactly. ... ```c++ auto [result, imageIndex] = swapChain.acquireNextImage(UINT64_MAX, *presentCompleteSemaphores[frameIndex], nullptr); if (result == vk::Result::eErrorOutOfDateKHR) { recreateSwapChain(); return; } if (result != vk::Result::eSuccess && result != vk::Result::eSuboptimalKHR) { assert(result == vk::Result::eTimeout || result == vk::Result::eNotReady); throw std::runtime_error("failed to acquire swap chain image!"); } ``` ... If the swap chain turns out to be out of date when attempting to acquire an image, then it is no longer possible to present to it. Therefore, we should immediately recreate the swap chain and try again in the next `drawFrame` call. ... If we try to run the code now, it is possible to encounter a deadlock. Debugging the code, we find that the application reaches `vk::raii::Device::waitForFences` but never continues past it. This is because when `vk::raii::SwapchainKHR::acquireNextImage` returns `vk::Result::eErrorOutOfDateKHR`, we recreate the swapchain and then return from `drawFrame`. But before that happens, the current frame’s fence was waited upon and reset. Since we return immediately, no work is submitted for execution and the fence will never be signaled, causing `vk::raii::Device::waitForFences` to halt forever. ... There is a simple fix thankfully. Delay resetting the fence until after we know for sure, we will be submitting work with it. Thus, if we return early, the fence is still signaled and `vk::raii::Device::waitForFences` wont deadlock the next time we use the same fence object. ... The beginning of `drawFrame` should now look like this: ... ```c++ auto fenceResult = device.waitForFences(*inFlightFences[frameIndex], vk::True, UINT64_MAX); if (fenceResult != vk::Result::eSuccess) { throw std::runtime_error("failed to wait for fence!"); } ... auto [result, imageIndex] = swapChain.acquireNextImage(UINT64_MAX, *presentCompleteSemaphores[frameIndex], nullptr); if (result == vk::Result::eErrorOutOfDateKHR) { recreateSwapChain(); return; } if (result != vk::Result::eSuccess && result != vk::Result::eSuboptimalKHR) { assert(result == vk::Result::eTimeout || result == vk::Result::eNotReady); throw std::runtime_error("failed to acquire swap chain image!"); } ... // Only reset the fence if we are submitting work device.resetFences(*inFlightFences[frameIndex]); ... Although many drivers and platforms trigger `vk::Result::eErrorOutOfDateKHR` automatically after a window resize, it is not guaranteed to happen. That’s why we’ll add some extra code to also handle resizes explicitly. First, add a new member variable that flags that a resize has happened: ... ```c++ if (result == vk::Result::eErrorOutOfDateKHR || result == vk::Result::eSuboptimalKHR || framebufferResized) { framebufferResized = false; recreateSwapChain(); } else { ... } https://vulkan-tutorial.com/Drawing_a_triangle/Swap_chain_recreation Now we just need to figure out when swap chain recreation is necessary and call our new `recreateSwapChain` function. Luckily, Vulkan will usually just tell us that the swap chain is no longer adequate during presentation. The `vkAcquireNextImageKHR` and `vkQueuePresentKHR` functions can return the following special values to indicate this. ... - `VK_ERROR_OUT_OF_DATE_KHR`: The swap chain has become incompatible with the surface and can no longer be used for rendering. Usually happens after a window resize. - `VK_SUBOPTIMAL_KHR`: The swap chain can still be used to successfully present to the surface, but the surface properties are no longer matched exactly. ... ```c++ VkResult result = vkAcquireNextImageKHR(device, swapChain, UINT64_MAX, imageAvailableSemaphores[currentFrame], VK_NULL_HANDLE, &imageIndex); if (result == VK_ERROR_OUT_OF_DATE_KHR) { recreateSwapChain(); return; } else if (result != VK_SUCCESS && result != VK_SUBOPTIMAL_KHR) { throw std::runtime_error("failed to acquire swap chain image!"); } ``` ... If the swap chain turns out to be out of date when attempting to acquire an image, then it is no longer possible to present to it. Therefore we should immediately recreate the swap chain and try again in the next `drawFrame` call. ... If we try to run the code now, it is possible to encounter a deadlock. Debugging the code, we find that the application reaches `vkWaitForFences` but never continues past it. This is because when `vkAcquireNextImageKHR` returns `VK_ERROR_OUT_OF_DATE_KHR`, we recreate the swapchain and then return from `drawFrame`. But before that happens, the current frame&`#39`;s fence was waited upon and reset. Since we return immediately, no work is submitted for execution and the fence will never be signaled, causing `vkWaitForFences` to halt forever. ... There is a simple fix thankfully. Delay resetting the fence until after we know for sure we will be submitting work with it. Thus, if we return early, the fence is still signaled and `vkWaitForFences` wont deadlock the next time we use the same fence object. ... The beginning of `drawFrame` should now look like this: ... ```c++ vkWaitForFences(device, 1, &inFlightFences[currentFrame], VK_TRUE, UINT64_MAX); uint32_t imageIndex; VkResult result = vkAcquireNextImageKHR(device, swapChain, UINT64_MAX, imageAvailableSemaphores[currentFrame], VK_NULL_HANDLE, &imageIndex); if (result == VK_ERROR_OUT_OF_DATE_KHR) { recreateSwapChain(); return; } else if (result != VK_SUCCESS && result != VK_SUBOPTIMAL_KHR) { throw std::runtime_error("failed to acquire swap chain image!"); } // Only reset the fence if we are submitting work vkResetFences(device, 1, &inFlightFences[currentFrame]); ... Although many drivers and platforms trigger `VK_ERROR_OUT_OF_DATE_KHR` automatically after a window resize, it is not guaranteed to happen. That&`#39`;s why we&`#39`;ll add some extra code to also handle resizes explicitly. First add a new member variable that flags that a resize has happened: ... The `drawFrame` function should then be modified to also check for this flag: ... ```c++ if (result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR || framebufferResized) { framebufferResized = false; recreateSwapChain(); } else if (result != VK_SUCCESS) { ... } ``` ... after `vkQueuePresentKHR` to ensure that the semaphores are in a consistent state ... otherwise a signaled semaphore ... never be properly ... izes we can ... SetFramebufferSizeCallback` ... to set up https://registry.khronos.org/vulkan/specs/latest/html/vkspec.html Enumerate\*`. Unless otherwise specified for an individual command, the results are*invariant*; that is, they will remain unchanged when retrieved again by calling the same command with the same parameters, so long as those parameters themselves all remain valid. #### 3.5.2. Array Results Some query commands of the form`vkGet\*`and`vkEnumerate\*`enable retrieving multiple results in the form of a return array. Such commands typically have two pointer arguments as follows: * An element count pointer pointing to an integer variable, conventionally named as`p\*Count`where`\*`is the capitalized singular form of the name of the retrieved values. * A pointer to an array where the result array is retrieved, conventionally named as`p\*`where`\*`is the capitalized plural form of the name of the retrieved values. If such commands are called with the array pointer set to`NULL`, then the number of retrievable elements is returned in the variable pointed to by the element count pointer. Otherwise, the element count pointer**must**point to a variable set by the application to the number of elements in the return array, and on return the variable is overwritten with the number of elements actually written to the return array. If the input element count is less than the number of retrievable array elements, the query will write only as many elements to the return array as specified by the element count variable set by the application, and the command will return`VK\_INCOMPLETE`instead of`VK\_SUCCESS`, to indicate that not all retrievable array elements were returned. Note | In practice, this means that applications will typically call such query commands twice: * First, with the array pointer set to`NULL`, to retrieve the number of retrievable elements. * Second, with the array pointer pointing to an application allocated storage for at least as many elements as indicated by the variable pointed to by the element count pointer, to retrieve at most as many of the retrievable elements. | Query commands that return one or more structures, regardless of whether they return a single or an array of structures with or without a`pNext`chain,**may**also contain arrays within those structures. Such return arrays are typically defined in the form of two members as follows: * An integer value specifying the element count, conventionally named as`\*Count`where`\*`is the singular form of the name of the retrieved values. * A pointer to an array where the result array is retrieved, conventionally named as`p\*`where`\*`is the capitalized plural form of the name of the retrieved values. Analogously to query commands that return multiple results, if the command is called with the array pointer member of the output structure in question set to`NULL`, then the number of retrievable elements is returned in the element count member of that output structure. Otherwise, the element count**must**specify the number of elements in the return array, and on return the element count member is overwritten with the number of elements actually written to the return array. If the input element count is less than the number of retrievable array elements, the query will write only as many elements to the return array as specified by the input element count, and the command will return`VK\_INCOMPLETE`instead of`VK\_SUCCESS`, if the query command has aVkResultreturn type, to indicate that not all retrievable array elements were returned. Note | Applications need to separately track the value they provided as the input element count member for such arrays and compare those with the returned element counts in order to determine whether the actually returned element count is smaller than the size of the return array. Another side effect of this is that it is impossible for the application to determine if the number of retrievable elements has increased beyond the provided input element count so using return arrays in output structures**should**be limited to*invariant*array result...Citations:
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 20030
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 20873
Bound image acquisition during minimization.
Swapchain::Create()handles zero extents only whenm_handleis null. An existing handle therefore reachesacquireNextImageKHRwithUINT64_MAX. Vulkan permits this call to wait indefinitely and does not require an out-of-date swapchain to wake it early. Detect zero extent before acquisition, or use a finite timeout and handlevk::Result::eTimeoutas unavailable.@ -566,0 +644,4 @@}state.builder.AddFunction(spv::OpSelectionMerge, merge_label,spv::SelectionControlMaskNone);state.builder.AddFunction(switch_words);@coderabbitai[bot] on GitHub · 2026-09-23 14:01 UTC · original
🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 29591
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 41988
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 12218
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 3764
Compute implicit-LOD derivatives before the candidate
OpSwitch.When
selecteddiffers across quad lanes, candidate blocks can diverge. Pixel-stageImageSampleRawoperations without derivative, LOD, or level-zero flags then emitOpImageSampleImplicitLodinside those blocks. This makes implicit derivatives undefined and can produce incorrect mip selection. The same applies toOpImageSampleDrefImplicitLodand bias sampling.Compute the float-coordinate derivatives before
OpSelectionMerge. Emit each candidate withGrad. When the input uses bias, scale both gradients byexp2(bias). Alternatively, select only the sampled image descriptor withOpSelectand emit one sample after the merge.@ -919,0 +2186,4 @@for (size_t candidate = 1; candidate < table.descriptors.size(); ++candidate) {snapshot.images.push_back(table.descriptors[candidate]);specialization.images.push_back(root);}@coderabbitai[bot] on GitHub · 2026-09-23 14:01 UTC · original
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Bound direct-offset image candidates before appending them.
The direct-offset path appends
table.descriptors.size() - 1child images tosnapshot.imagesandspecialization.images. It does not checkShaderInfo::MaxImages.table.keyscan hold up to 65536 offsets, so the path can produce more than 128 distinct descriptors.BuildResourceSpecializationthen callsImageRemap(specialization).ImageRemaprunsEXIT_IF(specialization.images.size() > indices.size()), andindiceshasMaxImages(128) entries. The emulator exits instead of failing specialization.MaterializeIndirectImagealready rejects this case withsnapshot.images.size() >= ShaderInfo::MaxImages.Add the same bound here. For the same reason, stop early in
MaterializeDirectImagewhen the number of distinct descriptors reaches the limit. That avoids reading every candidate first.🐛 Proposed fix
📝 Committable suggestion
@coderabbitai[bot] on GitHub · 2026-09-23 14:01 UTC · original · reviewed
Actionable comments posted: 4
🧹 Nitpick comments (2)
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
Review profile: CHILL
Plan: Advanced
Run ID:
5b93981c-095f-4abc-8480-350acc970a63📥 Commits
Reviewing files that changed from the base of the PR and between 42ecfe284983772133cd7c5dcbc7fcbb03fddcac and
d75549e0d7.📒 Files selected for processing (37)
src/graphics/guest_gpu/command_processor/pm4Handlers.cppsrc/graphics/guest_gpu/graphicsRun.cppsrc/graphics/guest_gpu/pm4.hsrc/graphics/host_gpu/renderer/cache/textureCache.cppsrc/graphics/host_gpu/renderer/cache/textureCache.hsrc/graphics/host_gpu/renderer/depthRenderTarget.cppsrc/graphics/host_gpu/renderer/pipeline/descriptors.cppsrc/graphics/host_gpu/renderer/pipeline/pipelineCache.cppsrc/graphics/host_gpu/renderer/pipeline/pipelineCache.hsrc/graphics/host_gpu/renderer/renderCompute.cppsrc/graphics/presentation/videoOut.cppsrc/graphics/presentation/videoOut.hsrc/graphics/presentation/window/swapchain.cppsrc/graphics/presentation/window/window.cppsrc/graphics/shader/recompiler/ShaderRecompiler.cppsrc/graphics/shader/recompiler/backend/spirv/SpirvEmitter.cppsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cppsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterInternal.hsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterMemory.cppsrc/graphics/shader/recompiler/frontend/decode/ShaderDecoder.hsrc/graphics/shader/recompiler/frontend/decode/VectorAluOps.cppsrc/graphics/shader/recompiler/frontend/translate/Vector.cppsrc/graphics/shader/recompiler/ir/Program.cppsrc/graphics/shader/recompiler/ir/ShaderIR.hsrc/graphics/shader/recompiler/ir/passes/ConstantPropagation.cppsrc/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/recompiler/ir/passes/SrtWalker.hsrc/kernel/fileSystem.cppsrc/kernel/memory.cppsrc/kernel/memoryAddressSpace.incsrc/libs/agc.cppsrc/libs/libVideoOut.cppsrc/libs/libs.cppsrc/libs/videoDec2Decoder.cppIncluded review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.
@Nmzik on GitHub · 2026-10-10 23:57 UTC · original · edited 2026-10-10 23:59 UTC
@Almo7aya I am still aware of this PR. Don’t be mad at me :) It should be much easier to get it into gameplay now. I’ll start working on it asap
@Almo7aya on GitHub · 2026-10-11 00:06 UTC · original
@Nmzik , please don't start working on it yet, I have another branch based on main with many more fixes for the FPS and the graphics, I'll keep you updated
@Almo7aya on GitHub · 2026-10-11 20:39 UTC · original
closed in favor of #1430
Pull request closed