mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-11-17 03:14:34 +01:00
Android Vulkan: Check the surface extent against the latest window size
g_display lags behind surfaceChanged until the render thread applies the resize, and a recreate after a suboptimal present can run in between. The check then swapped a correct extent for a frame. Android now sets the draw size callback to the latest size from backbufferResize, and the check uses that. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
ea5e39c440
commit
f8e7efc8b0
3 files changed
+19
-5
No files matched your search
@@ -1554,12 +1554,14 @@ bool VulkanContext::InitSwapchain(VkPresentModeKHR desiredPresentMode) {
|
||||
#if PPSSPP_PLATFORM(ANDROID)
|
||||
// After an in-place rotation, the surface can report the new transform together with the previous
|
||||
// orientation's extent. A Redmi 9A (PowerVR, Android 11) keeps doing it after surfaceChanged has given us the
|
||||
// new size, so the swapchain stays wrong until the next rotation. The window size we were told about is
|
||||
// current, so if the extent is exactly that transposed, it's stale.
|
||||
if (g_display.pixel_xres > 0 && g_display.pixel_yres > 0 && g_display.pixel_xres != g_display.pixel_yres &&
|
||||
currentExtent.width == (uint32_t)g_display.pixel_yres && currentExtent.height == (uint32_t)g_display.pixel_xres) {
|
||||
// new size, so the swapchain stays wrong until the next rotation. The latest window size from surfaceChanged
|
||||
// is current (g_display can lag behind it, until the render thread applies the resize), so if the extent is
|
||||
// exactly that transposed, it's stale.
|
||||
const VkExtent2D windowSize = cbGetDrawSize_ ? cbGetDrawSize_() : VkExtent2D{};
|
||||
if (windowSize.width > 0 && windowSize.height > 0 && windowSize.width != windowSize.height &&
|
||||
currentExtent.width == windowSize.height && currentExtent.height == windowSize.width) {
|
||||
WARN_LOG(Log::G3D, "Surface extent %dx%d is the window transposed, probably stale after a rotation. Using %dx%d.",
|
||||
currentExtent.width, currentExtent.height, g_display.pixel_xres, g_display.pixel_yres);
|
||||
currentExtent.width, currentExtent.height, windowSize.width, windowSize.height);
|
||||
std::swap(currentExtent.width, currentExtent.height);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -522,6 +522,7 @@ private:
|
||||
// that we really don't want in everything that uses VulkanContext.
|
||||
void *winsysData1_ = nullptr;
|
||||
void *winsysData2_ = nullptr;
|
||||
// The window's current size in pixels, from the platform. Optional.
|
||||
std::function<VkExtent2D()> cbGetDrawSize_;
|
||||
|
||||
VkInstance instance_ = VK_NULL_HANDLE;
|
||||
|
||||
@@ -89,6 +89,7 @@ struct JNIEnv {};
|
||||
#include "Common/VR/PPSSPPVR.h"
|
||||
#include "Common/GPU/Vulkan/VulkanLoader.h"
|
||||
#include "Common/GPU/GraphicsContext.h"
|
||||
#include "Common/GPU/Vulkan/VulkanContext.h"
|
||||
#include "Common/GPU/Vulkan/VulkanGraphicsContext.h"
|
||||
#include "android/jni/AndroidEGLGraphicsContext.h"
|
||||
#include "Common/StringUtils.h"
|
||||
@@ -202,6 +203,10 @@ static void SetPermissionStatusFromJava(std::string_view name, PermissionStatus
|
||||
|
||||
static GraphicsContext *graphicsContext;
|
||||
|
||||
// The latest surface size from backbufferResize, width in the high half, for Vulkan to check the surface's extent
|
||||
// against. Atomic rather than under g_pendingResizeLock (below), since a resize applied directly can recreate the swapchain.
|
||||
static std::atomic<uint64_t> g_surfaceSize;
|
||||
|
||||
#if PPSSPP_ARCH(ARMV7)
|
||||
// Old Android workaround
|
||||
extern "C" {
|
||||
@@ -730,6 +735,10 @@ retry:
|
||||
delete ctx;
|
||||
goto retry;
|
||||
}
|
||||
((VulkanContext *)ctx->GetAPIContext())->SetCbGetDrawSize([]() {
|
||||
const uint64_t size = g_surfaceSize;
|
||||
return VkExtent2D{ (uint32_t)(size >> 32), (uint32_t)size };
|
||||
});
|
||||
graphicsContext = ctx;
|
||||
// Now, we wait until we get a surface to continue initializing Vulkan.
|
||||
break;
|
||||
@@ -908,6 +917,8 @@ extern "C" void JNICALL Java_org_ppsspp_ppsspp_NativeApp_backbufferResize(JNIEnv
|
||||
const bool rotated = lastRotation != -1 && rotation != lastRotation;
|
||||
lastRotation = rotation;
|
||||
|
||||
g_surfaceSize = ((uint64_t)(uint32_t)pixel_xres << 32) | (uint32_t)pixel_yres;
|
||||
|
||||
// pixel_*res is the backbuffer resolution.
|
||||
if (IsVREnabled()) {
|
||||
GetVRResolutionPerEye(&pixel_xres, &pixel_yres);
|
||||
|
||||
Reference in new issue
Block a user