summaryrefslogtreecommitdiff
path: root/tools/gfx/vulkan/vk-swap-chain.cpp
diff options
context:
space:
mode:
authorskallweitNV <64953474+skallweitNV@users.noreply.github.com>2023-12-19 00:16:14 +0100
committerGitHub <noreply@github.com>2023-12-18 15:16:14 -0800
commit93b8f68b2e9ddc450ce63f1b6e1806960312d803 (patch)
treed5c9c38efe1e7c86637c4be6157595b44a5c4856 /tools/gfx/vulkan/vk-swap-chain.cpp
parentb6da04424aff71ddba9629c94401a9a897b152a0 (diff)
macos/vulkan support (#3418)
Diffstat (limited to 'tools/gfx/vulkan/vk-swap-chain.cpp')
-rw-r--r--tools/gfx/vulkan/vk-swap-chain.cpp16
1 files changed, 15 insertions, 1 deletions
diff --git a/tools/gfx/vulkan/vk-swap-chain.cpp b/tools/gfx/vulkan/vk-swap-chain.cpp
index 384ca86ed..856fa2489 100644
--- a/tools/gfx/vulkan/vk-swap-chain.cpp
+++ b/tools/gfx/vulkan/vk-swap-chain.cpp
@@ -2,6 +2,7 @@
#include "vk-swap-chain.h"
#include "vk-util.h"
+#include "../apple/cocoa-util.h"
namespace gfx
{
@@ -38,6 +39,8 @@ void SwapchainImpl::getWindowSize(int* widthOut, int* heightOut) const
::GetClientRect((HWND)m_windowHandle.handleValues[0], &rc);
*widthOut = rc.right - rc.left;
*heightOut = rc.bottom - rc.top;
+#elif SLANG_APPLE_FAMILY
+ CocoaUtil::getNSViewRectSize((void*)m_windowHandle.handleValues[0], widthOut, heightOut);
#elif defined(SLANG_ENABLE_XLIB)
XWindowAttributes winAttr = {};
XGetWindowAttributes(
@@ -221,6 +224,12 @@ Result SwapchainImpl::init(DeviceImpl* renderer, const ISwapchain::Desc& desc, W
surfaceCreateInfo.hwnd = (HWND)window.handleValues[0];
SLANG_VK_RETURN_ON_FAIL(
m_api->vkCreateWin32SurfaceKHR(m_api->m_instance, &surfaceCreateInfo, nullptr, &m_surface));
+#elif SLANG_APPLE_FAMILY
+ VkMacOSSurfaceCreateInfoMVK surfaceCreateInfo = {};
+ surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK;
+ surfaceCreateInfo.pView = (void*)window.handleValues[0];
+ SLANG_VK_RETURN_ON_FAIL(
+ m_api->vkCreateMacOSSurfaceMVK(m_api->m_instance, &surfaceCreateInfo, nullptr, &m_surface));
#elif SLANG_ENABLE_XLIB
VkXlibSurfaceCreateInfoKHR surfaceCreateInfo = {};
surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR;
@@ -347,7 +356,12 @@ int SwapchainImpl::acquireNextImage()
VK_NULL_HANDLE,
(uint32_t*)&m_currentImageIndex);
- if (result != VK_SUCCESS)
+ if (
+ result != VK_SUCCESS
+#if SLANG_APPLE_FAMILY
+ && result != VK_SUBOPTIMAL_KHR
+#endif
+ )
{
m_currentImageIndex = -1;
destroySwapchainAndImages();