diff --git a/rpcsx/gpu/Device.cpp b/rpcsx/gpu/Device.cpp index ecf2e99ea..98f35aa50 100644 --- a/rpcsx/gpu/Device.cpp +++ b/rpcsx/gpu/Device.cpp @@ -309,7 +309,15 @@ Device::~Device() { } void Device::start() { - vk::context->createSwapchain(); + { + int width; + int height; + glfwGetWindowSize(window, &width, &height); + vk::context->createSwapchain({ + .width = static_cast(width), + .height = static_cast(height), + }); + } for (std::size_t i = 0; i < std::size(dmemFd); ++i) { if (dmemFd[i] != -1) { @@ -900,13 +908,23 @@ bool Device::flip(std::uint32_t pid, int bufferIndex, std::uint64_t arg, } void Device::flip(std::uint32_t pid, int bufferIndex, std::uint64_t arg) { + auto recreateSwapchain = [this] { + int width; + int height; + glfwGetWindowSize(window, &width, &height); + vk::context->recreateSwapchain({ + .width = static_cast(width), + .height = static_cast(height), + }); + }; + if (!isImageAcquired) { while (true) { auto acquireNextImageResult = vkAcquireNextImageKHR( vk::context->device, vk::context->swapchain, UINT64_MAX, vk::context->presentCompleteSemaphore, VK_NULL_HANDLE, &imageIndex); if (acquireNextImageResult == VK_ERROR_OUT_OF_DATE_KHR) { - vk::context->recreateSwapchain(); + recreateSwapchain(); continue; } @@ -951,7 +969,7 @@ void Device::flip(std::uint32_t pid, int bufferIndex, std::uint64_t arg) { if (vkQueuePresentResult == VK_ERROR_OUT_OF_DATE_KHR || vkQueuePresentResult == VK_SUBOPTIMAL_KHR) { - vk::context->recreateSwapchain(); + recreateSwapchain(); } else { VK_VERIFY(vkQueuePresentResult); } diff --git a/rpcsx/gpu/lib/vk/include/vk.hpp b/rpcsx/gpu/lib/vk/include/vk.hpp index 1ada906b8..e1caa8b1d 100644 --- a/rpcsx/gpu/lib/vk/include/vk.hpp +++ b/rpcsx/gpu/lib/vk/include/vk.hpp @@ -130,8 +130,8 @@ struct Context { } bool hasDeviceExtension(std::string_view ext); - void createSwapchain(); - void recreateSwapchain(); + void createSwapchain(VkExtent2D extent); + void recreateSwapchain(VkExtent2D extent); void createDevice(VkSurfaceKHR surface, int gpuIndex, std::vector requiredExtensions, std::vector optionalExtensions); diff --git a/rpcsx/gpu/lib/vk/src/vk.cpp b/rpcsx/gpu/lib/vk/src/vk.cpp index 4b5baa704..79c7c1f6d 100644 --- a/rpcsx/gpu/lib/vk/src/vk.cpp +++ b/rpcsx/gpu/lib/vk/src/vk.cpp @@ -167,7 +167,7 @@ bool vk::Context::hasDeviceExtension(std::string_view ext) { deviceExtensions.end(); } -void vk::Context::createSwapchain() { +void vk::Context::createSwapchain(VkExtent2D extent) { uint32_t formatCount; VK_VERIFY(vkGetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, surface, &formatCount, nullptr)); @@ -196,7 +196,7 @@ void vk::Context::createSwapchain() { } } - recreateSwapchain(); + recreateSwapchain(extent); { VkSemaphoreCreateInfo semaphoreCreateInfo{}; @@ -209,7 +209,7 @@ void vk::Context::createSwapchain() { } } -void vk::Context::recreateSwapchain() { +void vk::Context::recreateSwapchain(VkExtent2D extent) { VkSwapchainKHR oldSwapchain = swapchain; VkSurfaceCapabilitiesKHR surfCaps; @@ -225,6 +225,8 @@ void vk::Context::recreateSwapchain() { if (surfCaps.currentExtent.width != (uint32_t)-1) { swapchainExtent = surfCaps.currentExtent; + } else { + swapchainExtent = extent; } VkPresentModeKHR swapchainPresentMode = VK_PRESENT_MODE_FIFO_KHR;