Fix render resolution at different UI scales (#514)

This commit is contained in:
goeiecool9999 2022-11-30 13:39:32 +01:00 committed by GitHub
parent a3476c7b7c
commit d3721c3f46
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 128 additions and 57 deletions

View file

@ -513,9 +513,9 @@ void LatteOverlay_render(bool pad_view)
sint32 w = 0, h = 0;
if (pad_view && gui_isPadWindowOpen())
gui_getPadWindowSize(&w, &h);
gui_getPadWindowPhysSize(w, h);
else
gui_getWindowSize(&w, &h);
gui_getWindowPhysSize(w, h);
if (w == 0 || h == 0)
return;

View file

@ -848,9 +848,9 @@ void LatteRenderTarget_getScreenImageArea(sint32* x, sint32* y, sint32* width, s
{
int w, h;
if(padView && gui_isPadWindowOpen())
gui_getPadWindowSize(&w, &h);
gui_getPadWindowPhysSize(w, h);
else
gui_getWindowSize(&w, &h);
gui_getWindowPhysSize(w, h);
sint32 scaledOutputX;
sint32 scaledOutputY;

View file

@ -418,7 +418,7 @@ void LatteShaderCache_ShowProgress(const std::function <bool(void)>& loadUpdateF
continue;
int w, h;
gui_getWindowSize(&w, &h);
gui_getWindowPhysSize(w, h);
const Vector2f window_size{ (float)w,(float)h };
ImGui_GetFont(window_size.y / 32.0f); // = 24 by default

View file

@ -117,7 +117,7 @@ int Latte_ThreadEntry()
{
SetThreadName("LatteThread");
sint32 w,h;
gui_getWindowSize(&w,&h);
gui_getWindowPhysSize(w,h);
// imgui
ImGui::CreateContext();

View file

@ -556,9 +556,9 @@ void OpenGLRenderer::DrawBackbufferQuad(LatteTextureView* texView, RendererOutpu
{
int windowWidth, windowHeight;
if (padView)
gui_getPadWindowSize(&windowWidth, &windowHeight);
gui_getPadWindowPhysSize(windowWidth, windowHeight);
else
gui_getWindowSize(&windowWidth, &windowHeight);
gui_getWindowPhysSize(windowWidth, windowHeight);
g_renderer->renderTarget_setViewport(0, 0, windowWidth, windowHeight, 0.0f, 1.0f);
g_renderer->ClearColorbuffer(padView);
}

View file

@ -36,9 +36,9 @@ bool Renderer::ImguiBegin(bool mainWindow)
{
sint32 w = 0, h = 0;
if(mainWindow)
gui_getWindowSize(&w, &h);
gui_getWindowPhysSize(w, h);
else if(gui_isPadWindowOpen())
gui_getPadWindowSize(&w, &h);
gui_getPadWindowPhysSize(w, h);
else
return false;

View file

@ -13,8 +13,23 @@
+(Class) layerClass { return [CAMetalLayer class]; }
-(CALayer*) makeBackingLayer { return [self.class.layerClass layer]; }
// copied from https://github.com/KhronosGroup/MoltenVK/blob/master/Demos/Cube/macOS/DemoViewController.m
-(CALayer*) makeBackingLayer
{
CALayer* layer = [self.class.layerClass layer];
CGSize viewScale = [self convertSizeToBacking: CGSizeMake(1.0, 1.0)];
layer.contentsScale = MIN(viewScale.width, viewScale.height);
return layer;
}
-(BOOL) layer: (CALayer *)layer shouldInheritContentsScale: (CGFloat)newScale fromWindow: (NSWindow *)window
{
if (newScale == layer.contentsScale) { return NO; }
layer.contentsScale = newScale;
return YES;
}
@end
VkSurfaceKHR CreateCocoaSurface(VkInstance instance, void* handle)

View file

@ -208,20 +208,14 @@ bool SwapchainInfoVk::AcquireImage(uint64 timeout)
VkSemaphore acquireSemaphore = m_acquireSemaphores[m_acquireIndex];
VkResult result = vkAcquireNextImageKHR(m_logicalDevice, swapchain, timeout, acquireSemaphore, m_imageAvailableFence, &swapchainImageIndex);
if (result == VK_TIMEOUT)
if (result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR)
m_shouldRecreate = true;
if (result < 0)
{
return false;
}
else if (result != VK_SUCCESS)
{
if (result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR)
m_shouldRecreate = true;
if (result == VK_ERROR_OUT_OF_DATE_KHR)
return false;
if (result != VK_ERROR_OUT_OF_DATE_KHR && result != VK_SUBOPTIMAL_KHR)
swapchainImageIndex = -1;
if (result != VK_ERROR_OUT_OF_DATE_KHR)
throw std::runtime_error(fmt::format("Failed to acquire next image: {}", result));
return false;
}
m_currentSemaphore = acquireSemaphore;
m_awaitableFence = m_imageAvailableFence;

View file

@ -643,7 +643,7 @@ VulkanRenderer* VulkanRenderer::GetInstance()
return (VulkanRenderer*)g_renderer.get();
}
void VulkanRenderer::Initialize(const Vector2i& size, bool mainWindow)
void VulkanRenderer::InitializeSurface(const Vector2i& size, bool mainWindow)
{
auto& windowHandleInfo = mainWindow ? gui_getWindowInfo().canvas_main : gui_getWindowInfo().canvas_pad;
@ -2564,20 +2564,20 @@ void VulkanRenderer::RecreateSwapchain(bool mainWindow, bool skipCreate)
if (mainWindow)
{
ImGui_ImplVulkan_Shutdown();
gui_getWindowSize(&size.x, &size.y);
gui_getWindowPhysSize(size.x, size.y);
}
else
{
gui_getPadWindowSize(&size.x, &size.y);
gui_getPadWindowPhysSize(size.x, size.y);
}
chainInfo.swapchainImageIndex = -1;
chainInfo.Cleanup();
chainInfo.m_desiredExtent = size;
if(!skipCreate)
{
chainInfo.Create(m_physicalDevice, m_logicalDevice);
}
chainInfo.swapchainImageIndex = -1;
if (mainWindow)
ImguiInit();
@ -2644,13 +2644,12 @@ void VulkanRenderer::SwapBuffer(bool mainWindow)
presentInfo.pWaitSemaphores = &presentSemaphore;
VkResult result = vkQueuePresentKHR(m_presentQueue, &presentInfo);
if (result != VK_SUCCESS)
if (result < 0 && result != VK_ERROR_OUT_OF_DATE_KHR)
{
if (result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR)
chainInfo.m_shouldRecreate = true;
else
throw std::runtime_error(fmt::format("Failed to present image: {}", result));
throw std::runtime_error(fmt::format("Failed to present image: {}", result));
}
if(result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR)
chainInfo.m_shouldRecreate = true;
chainInfo.hasDefinedSwapchainImage = false;

View file

@ -182,7 +182,7 @@ public:
void GetDeviceFeatures();
void DetermineVendor();
void Initialize(const Vector2i& size, bool mainWindow);
void InitializeSurface(const Vector2i& size, bool mainWindow);
const std::unique_ptr<SwapchainInfoVk>& GetChainInfoPtr(bool mainWindow) const;
SwapchainInfoVk& GetChainInfo(bool mainWindow) const;