mirror of
https://github.com/cemu-project/Cemu.git
synced 2025-07-14 18:58:29 +12:00
Fix render resolution at different UI scales (#514)
This commit is contained in:
parent
a3476c7b7c
commit
d3721c3f46
18 changed files with 128 additions and 57 deletions
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue