summaryrefslogtreecommitdiff
path: root/tools/gfx/vulkan/vk-swap-chain.cpp
diff options
context:
space:
mode:
authorSimon Kallweit <simon.kallweit@gmail.com>2024-02-27 00:32:03 +0100
committerGitHub <noreply@github.com>2024-02-26 15:32:03 -0800
commit4f03eb9d657fd74da341bb2b0d391c6b855073af (patch)
treebd091ec05b0878f92757de8b3ac011b856be9a33 /tools/gfx/vulkan/vk-swap-chain.cpp
parentceb87b25b387411dbb7978caf04ecd9e948493e3 (diff)
switch to vkCreateMetalSurfaceEXT and create metal layer in swapchain (#3627)
* switch to vkCreateMetalSurfaceEXT and create metal layer in swapchain * fix window content size on macos --------- Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'tools/gfx/vulkan/vk-swap-chain.cpp')
-rw-r--r--tools/gfx/vulkan/vk-swap-chain.cpp14
1 files changed, 9 insertions, 5 deletions
diff --git a/tools/gfx/vulkan/vk-swap-chain.cpp b/tools/gfx/vulkan/vk-swap-chain.cpp
index 856fa2489..7580e01b3 100644
--- a/tools/gfx/vulkan/vk-swap-chain.cpp
+++ b/tools/gfx/vulkan/vk-swap-chain.cpp
@@ -40,7 +40,7 @@ void SwapchainImpl::getWindowSize(int* widthOut, int* heightOut) const
*widthOut = rc.right - rc.left;
*heightOut = rc.bottom - rc.top;
#elif SLANG_APPLE_FAMILY
- CocoaUtil::getNSViewRectSize((void*)m_windowHandle.handleValues[0], widthOut, heightOut);
+ CocoaUtil::getNSWindowContentSize((void*)m_windowHandle.handleValues[0], widthOut, heightOut);
#elif defined(SLANG_ENABLE_XLIB)
XWindowAttributes winAttr = {};
XGetWindowAttributes(
@@ -182,6 +182,9 @@ SwapchainImpl::~SwapchainImpl()
m_surface = VK_NULL_HANDLE;
}
m_renderer->m_api.vkDestroySemaphore(m_renderer->m_api.m_device, m_nextImageSemaphore, nullptr);
+#if SLANG_APPLE_FAMILY
+ CocoaUtil::destroyMetalLayer(m_metalLayer);
+#endif
}
Index SwapchainImpl::_indexOfFormat(List<VkSurfaceFormatKHR>& formatsIn, VkFormat format)
@@ -225,11 +228,12 @@ Result SwapchainImpl::init(DeviceImpl* renderer, const ISwapchain::Desc& desc, W
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];
+ m_metalLayer = CocoaUtil::createMetalLayer((void*)window.handleValues[0]);
+ VkMetalSurfaceCreateInfoEXT surfaceCreateInfo = {};
+ surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_METAL_SURFACE_CREATE_INFO_EXT;
+ surfaceCreateInfo.pLayer = (CAMetalLayer*)m_metalLayer;
SLANG_VK_RETURN_ON_FAIL(
- m_api->vkCreateMacOSSurfaceMVK(m_api->m_instance, &surfaceCreateInfo, nullptr, &m_surface));
+ m_api->vkCreateMetalSurfaceEXT(m_api->m_instance, &surfaceCreateInfo, nullptr, &m_surface));
#elif SLANG_ENABLE_XLIB
VkXlibSurfaceCreateInfoKHR surfaceCreateInfo = {};
surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR;