fix(android): treat VK_SUBOPTIMAL_KHR as success in the presenter - #1
Open
KLCLAU wants to merge 1 commit into
Open
fix(android): treat VK_SUBOPTIMAL_KHR as success in the presenter#1KLCLAU wants to merge 1 commit into
KLCLAU wants to merge 1 commit into
Conversation
On Android the display surface is portrait-native while the game renders landscape, so surfaceCapabilities.currentTransform is a 90/270-degree rotation that the swapchain's preTransform never matches. Every vkAcquireNextImageKHR / vkQueuePresentKHR then returns VK_SUBOPTIMAL_KHR and Presenter treats it like OUT_OF_DATE, recreating the swapchain on *every single frame* (observed: 761 'recreating swapchain' log lines in 45 seconds, plus the wasted GPU work). The acquired image is fully usable and the Android compositor performs the rotation for free, so on __ANDROID__ treat VK_SUBOPTIMAL_KHR as success for the recreate decision (presenterResultOk). Non-Android behaviour is unchanged. With this, the recreate-per-frame loop drops from 761 to 0 on a Galaxy S26+ (Adreno 840) and the game holds a steady frame rate in menus and in-game. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On Android the display surface is portrait-native while GeneralsX renders landscape, so
surfaceCapabilities.currentTransformis a 90/270° rotation the swapchain'spreTransformnever matches. EveryvkAcquireNextImageKHR/vkQueuePresentKHRreturnsVK_SUBOPTIMAL_KHR, andPresentertreats that likeVK_ERROR_OUT_OF_DATE_KHR— recreating the swapchain every single frame:Fix
The acquired image is fully usable and the Android compositor does the rotation for free, so on
__ANDROID__treatVK_SUBOPTIMAL_KHRas success for the recreate decision (presenterResultOk()), at all three sites: the post-acquire check, the pre-acquire-after-present optimization, and the post-present dirty flag. Desktop behaviour is unchanged (presenterResultOkisr == VK_SUCCESSoff Android).Result: recreate-per-frame loop 761 → 0; steady frame rate in menus and in-game on Adreno 840.
A proper pre-rotation implementation (render with
preTransform == currentTransform, apply the inverse in the final blit) would be better still, but this stops the pathological loop with a one-liner and no behavioural risk.Companion to fadi-labib/Generals-Android#24.