Add support for VK_EXT_metal_surface and prefer it to MVK_macos_surface

This commit is contained in:
baldurk
2019-08-16 16:11:53 +01:00
parent 37242fd97e
commit 08a1ce2e76
12 changed files with 171 additions and 35 deletions
+1 -1
View File
@@ -87,7 +87,7 @@ if(ANDROID)
elseif(APPLE)
list(APPEND sources vk_posix.cpp vk_apple.cpp vk_apple.mm)
add_definitions(-DVK_USE_PLATFORM_MACOS_MVK)
add_definitions(-DVK_USE_PLATFORM_MACOS_MVK -DVK_USE_PLATFORM_METAL_EXT)
elseif(ENABLE_GGP)
list(APPEND sources vk_posix.cpp vk_ggp.cpp)
add_definitions(-DVK_USE_PLATFORM_GGP)
+1 -1
View File
@@ -57,7 +57,7 @@ void VulkanReplay::OutputWindow::SetWindowHandle(WindowingData window)
wnd = window.android.window;
}
void VulkanReplay::OutputWindow::CreateSurface(VkInstance inst)
void VulkanReplay::OutputWindow::CreateSurface(WrappedVulkan *driver, VkInstance inst)
{
VkAndroidSurfaceCreateInfoKHR createInfo;
+69 -8
View File
@@ -32,6 +32,8 @@
extern "C" int getMetalLayerWidth(void *handle);
extern "C" int getMetalLayerHeight(void *handle);
#if defined(VK_USE_PLATFORM_MACOS_MVK)
VkResult WrappedVulkan::vkCreateMacOSSurfaceMVK(VkInstance instance,
const VkMacOSSurfaceCreateInfoMVK *pCreateInfo,
const VkAllocationCallbacks *pAllocator,
@@ -57,23 +59,82 @@ VkResult WrappedVulkan::vkCreateMacOSSurfaceMVK(VkInstance instance,
return ret;
}
#endif
#if defined(VK_USE_PLATFORM_METAL_EXT)
VkResult WrappedVulkan::vkCreateMetalSurfaceEXT(VkInstance instance,
const VkMetalSurfaceCreateInfoEXT *pCreateInfo,
const VkAllocationCallbacks *pAllocator,
VkSurfaceKHR *pSurface)
{
// should not come in here at all on replay
RDCASSERT(IsCaptureMode(m_State));
VkResult ret =
ObjDisp(instance)->CreateMetalSurfaceEXT(Unwrap(instance), pCreateInfo, pAllocator, pSurface);
if(ret == VK_SUCCESS)
{
GetResourceManager()->WrapResource(Unwrap(instance), *pSurface);
WrappedVkSurfaceKHR *wrapped = GetWrapped(*pSurface);
// since there's no point in allocating a full resource record and storing the window
// handle under there somewhere, we just cast. We won't use the resource record for anything
wrapped->record = (VkResourceRecord *)(uintptr_t)pCreateInfo->pLayer;
}
return ret;
}
#endif
void VulkanReplay::OutputWindow::SetWindowHandle(WindowingData window)
{
RDCASSERT(window.system == WindowingSystem::MacOS, window.system);
wnd = window.macOS.layer;
}
void VulkanReplay::OutputWindow::CreateSurface(VkInstance inst)
void VulkanReplay::OutputWindow::CreateSurface(WrappedVulkan *driver, VkInstance inst)
{
VkMacOSSurfaceCreateInfoMVK createInfo;
#if defined(VK_USE_PLATFORM_METAL_EXT)
if(driver->GetExtensions(GetRecord(inst)).ext_EXT_metal_surface)
{
VkMetalSurfaceCreateInfoEXT createInfo;
createInfo.sType = VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK;
createInfo.pNext = NULL;
createInfo.flags = 0;
createInfo.pView = wnd;
createInfo.sType = VK_STRUCTURE_TYPE_METAL_SURFACE_CREATE_INFO_EXT;
createInfo.pNext = NULL;
createInfo.flags = 0;
createInfo.pLayer = wnd;
VkResult vkr = ObjDisp(inst)->CreateMacOSSurfaceMVK(Unwrap(inst), &createInfo, NULL, &surface);
RDCASSERTEQUAL(vkr, VK_SUCCESS);
RDCDEBUG("Creating macOS surface with EXT_metal_surface");
VkResult vkr = ObjDisp(inst)->CreateMetalSurfaceEXT(Unwrap(inst), &createInfo, NULL, &surface);
RDCASSERTEQUAL(vkr, VK_SUCCESS);
return;
}
#endif
#if defined(VK_USE_PLATFORM_MACOS_MVK)
if(driver->GetExtensions(GetRecord(inst)).ext_MVK_macos_surface)
{
VkMacOSSurfaceCreateInfoMVK createInfo;
createInfo.sType = VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK;
createInfo.pNext = NULL;
createInfo.flags = 0;
createInfo.pView = wnd;
RDCDEBUG("Creating macOS surface with MVK_macos_surface");
VkResult vkr = ObjDisp(inst)->CreateMacOSSurfaceMVK(Unwrap(inst), &createInfo, NULL, &surface);
RDCASSERTEQUAL(vkr, VK_SUCCESS);
return;
}
#endif
RDCERR("No enabled macOS surface extension");
}
void VulkanReplay::GetOutputWindowDimensions(uint64_t id, int32_t &w, int32_t &h)
+5
View File
@@ -717,6 +717,11 @@ static const VkExtensionProperties supportedExtensions[] = {
{
VK_EXT_MEMORY_PRIORITY_EXTENSION_NAME, VK_EXT_MEMORY_PRIORITY_SPEC_VERSION,
},
#ifdef VK_EXT_metal_surface
{
VK_EXT_METAL_SURFACE_EXTENSION_NAME, VK_EXT_METAL_SURFACE_SPEC_VERSION,
},
#endif
{
VK_EXT_PCI_BUS_INFO_EXTENSION_NAME, VK_EXT_PCI_BUS_INFO_SPEC_VERSION,
},
+7
View File
@@ -2129,4 +2129,11 @@ public:
IMPLEMENT_FUNCTION_SERIALISED(void, vkCmdSetLineStippleEXT, VkCommandBuffer commandBuffer,
uint32_t lineStippleFactor, uint16_t lineStipplePattern);
#if defined(VK_USE_PLATFORM_METAL_EXT)
// VK_EXT_metal_surface
VkResult vkCreateMetalSurfaceEXT(VkInstance instance,
const VkMetalSurfaceCreateInfoEXT *pCreateInfo,
const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface);
#endif
};
+1 -1
View File
@@ -54,7 +54,7 @@ void VulkanReplay::OutputWindow::SetWindowHandle(WindowingData window)
return; // there are no OS specific handles to save.
}
void VulkanReplay::OutputWindow::CreateSurface(VkInstance inst)
void VulkanReplay::OutputWindow::CreateSurface(WrappedVulkan *driver, VkInstance inst)
{
VkStreamDescriptorSurfaceCreateInfoGGP createInfo;
+42 -6
View File
@@ -81,18 +81,52 @@
HookDefine2(VkResult, vkReleaseFullScreenExclusiveModeEXT, VkDevice, device, VkSwapchainKHR, \
swapchain);
#elif defined(VK_USE_PLATFORM_MACOS_MVK)
#elif defined(VK_USE_PLATFORM_MACOS_MVK) || defined(VK_USE_PLATFORM_METAL_EXT)
#define HookInitInstance_PlatformSpecific() \
#if defined(VK_USE_PLATFORM_MACOS_MVK)
#define HookInitInstance_PlatformSpecific_MVK() \
HookInitExtension(VK_MVK_macos_surface, CreateMacOSSurfaceMVK);
#define HookInitDevice_PlatformSpecific()
#define HookDefine_PlatformSpecific() \
#define HookDefine_PlatformSpecific_MVK() \
HookDefine4(VkResult, vkCreateMacOSSurfaceMVK, VkInstance, instance, \
const VkMacOSSurfaceCreateInfoMVK *, pCreateInfo, const VkAllocationCallbacks *, \
pAllocator, VkSurfaceKHR *, pSurface);
#else
#define HookInitInstance_PlatformSpecific_MVK()
#define HookDefine_PlatformSpecific_MVK()
#endif
#if defined(VK_USE_PLATFORM_METAL_EXT)
#define HookInitInstance_PlatformSpecific_EXT() \
HookInitExtension(VK_EXT_metal_surface, CreateMetalSurfaceEXT);
#define HookDefine_PlatformSpecific_EXT() \
HookDefine4(VkResult, vkCreateMetalSurfaceEXT, VkInstance, instance, \
const VkMetalSurfaceCreateInfoEXT *, pCreateInfo, const VkAllocationCallbacks *, \
pAllocator, VkSurfaceKHR *, pSurface);
#else
#define HookInitInstance_PlatformSpecific_MVK()
#define HookDefine_PlatformSpecific_EXT()
#endif
#define HookInitInstance_PlatformSpecific() \
HookInitInstance_PlatformSpecific_MVK(); \
HookInitInstance_PlatformSpecific_EXT();
#define HookDefine_PlatformSpecific() \
HookDefine_PlatformSpecific_MVK(); \
HookDefine_PlatformSpecific_EXT();
#define HookInitDevice_PlatformSpecific()
#elif defined(VK_USE_PLATFORM_ANDROID_KHR)
#define HookInitInstance_PlatformSpecific() \
@@ -340,6 +374,7 @@
DeclExt(KHR_get_surface_capabilities2); \
DeclExt(KHR_get_display_properties2); \
DeclExt(EXT_headless_surface); \
DeclExt(EXT_metal_surface); \
/* device extensions */ \
DeclExt(EXT_debug_marker); \
DeclExt(GGP_frame_token); \
@@ -421,7 +456,8 @@
CheckExt(EXT_sample_locations, VKXX); \
CheckExt(EXT_calibrated_timestamps, VKXX); \
CheckExt(EXT_full_screen_exclusive, VKXX); \
CheckExt(EXT_headless_surface, VKXX);
CheckExt(EXT_headless_surface, VKXX); \
CheckExt(EXT_metal_surface, VKXX);
#define CheckDeviceExts() \
CheckExt(EXT_debug_marker, VKXX); \
+1 -1
View File
@@ -155,7 +155,7 @@ void VulkanReplay::OutputWindow::SetWindowHandle(WindowingData window)
RDCERR("Unrecognised/unsupported window system %d", window.system);
}
void VulkanReplay::OutputWindow::CreateSurface(VkInstance inst)
void VulkanReplay::OutputWindow::CreateSurface(WrappedVulkan *driver, VkInstance inst)
{
#if ENABLED(RDOC_XLIB)
if(m_WindowSystem == WindowingSystem::Xlib)
+1 -1
View File
@@ -189,7 +189,7 @@ void VulkanReplay::OutputWindow::Create(WrappedVulkan *driver, VkDevice device,
if(surface == VK_NULL_HANDLE && m_WindowSystem != WindowingSystem::Headless)
{
CreateSurface(inst);
CreateSurface(driver, inst);
GetResourceManager()->WrapResource(Unwrap(inst), surface);
}
+41 -14
View File
@@ -54,7 +54,7 @@ void WrappedVulkan::AddRequiredExtensions(bool instance, std::vector<std::string
#if(defined(VK_USE_PLATFORM_ANDROID_KHR) || defined(VK_USE_PLATFORM_XCB_KHR) || \
defined(VK_USE_PLATFORM_XLIB_KHR) || defined(VK_USE_PLATFORM_MACOS_MVK) || \
defined(VK_USE_PLATFORM_GGP))
defined(VK_USE_PLATFORM_METAL_EXT) || defined(VK_USE_PLATFORM_GGP))
#undef EXPECT_WSI
#define EXPECT_WSI 1
@@ -98,18 +98,37 @@ void WrappedVulkan::AddRequiredExtensions(bool instance, std::vector<std::string
}
#endif
#if defined(VK_USE_PLATFORM_MACOS_MVK)
// must be supported
RDCASSERT(supportedExtensions.find(VK_MVK_MACOS_SURFACE_EXTENSION_NAME) !=
supportedExtensions.end());
m_SupportedWindowSystems.push_back(WindowingSystem::MacOS);
// don't add duplicates, application will have added this but just be sure
if(std::find(extensionList.begin(), extensionList.end(), VK_MVK_MACOS_SURFACE_EXTENSION_NAME) ==
extensionList.end())
#if defined(VK_USE_PLATFORM_METAL_EXT)
// check if supported
if(supportedExtensions.find(VK_EXT_METAL_SURFACE_EXTENSION_NAME) != supportedExtensions.end())
{
extensionList.push_back(VK_MVK_MACOS_SURFACE_EXTENSION_NAME);
m_SupportedWindowSystems.push_back(WindowingSystem::MacOS);
RDCLOG("Will create surfaces using " VK_EXT_METAL_SURFACE_EXTENSION_NAME);
// don't add duplicates, application will have added this but just be sure
if(std::find(extensionList.begin(), extensionList.end(),
VK_EXT_METAL_SURFACE_EXTENSION_NAME) == extensionList.end())
{
extensionList.push_back(VK_EXT_METAL_SURFACE_EXTENSION_NAME);
}
}
#endif
#if defined(VK_USE_PLATFORM_MACOS_MVK)
// check if supported
if(supportedExtensions.find(VK_MVK_MACOS_SURFACE_EXTENSION_NAME) != supportedExtensions.end())
{
m_SupportedWindowSystems.push_back(WindowingSystem::MacOS);
RDCLOG("Will create surfaces using " VK_MVK_MACOS_SURFACE_EXTENSION_NAME);
// don't add duplicates, application will have added this but just be sure
if(std::find(extensionList.begin(), extensionList.end(),
VK_MVK_MACOS_SURFACE_EXTENSION_NAME) == extensionList.end())
{
extensionList.push_back(VK_MVK_MACOS_SURFACE_EXTENSION_NAME);
}
}
#endif
@@ -161,9 +180,17 @@ void WrappedVulkan::AddRequiredExtensions(bool instance, std::vector<std::string
{
RDCWARN("No WSI support - only headless replay allowed.");
#if defined(VK_USE_PLATFORM_MACOS_MVK)
#if defined(VK_USE_PLATFORM_MACOS_MVK) && defined(VK_USE_PLATFORM_METAL_EXT)
RDCWARN("macOS Output requires the '%s' or '%s' extensions to be present",
VK_MVK_MACOS_SURFACE_EXTENSION_NAME, VK_EXT_METAL_SURFACE_EXTENSION_NAME);
#elif defined(VK_USE_PLATFORM_MACOS_MVK) || defined(VK_USE_PLATFORM_METAL_EXT)
RDCWARN("macOS Output requires the '%s' extension to be present",
VK_MVK_MACOS_SURFACE_EXTENSION_NAME);
#if defined(VK_USE_PLATFORM_MACOS_MVK)
VK_MVK_MACOS_SURFACE_EXTENSION_NAME
#elif defined(VK_USE_PLATFORM_METAL_EXT)
VK_EXT_METAL_SURFACE_EXTENSION_NAME
#endif
);
#endif
#if defined(VK_USE_PLATFORM_ANDROID_KHR)
+1 -1
View File
@@ -416,7 +416,7 @@ private:
void Destroy(WrappedVulkan *driver, VkDevice device);
// implemented in vk_replay_platform.cpp
void CreateSurface(VkInstance inst);
void CreateSurface(WrappedVulkan *driver, VkInstance inst);
void SetWindowHandle(WindowingData window);
WindowingSystem m_WindowSystem;
+1 -1
View File
@@ -36,7 +36,7 @@ void VulkanReplay::OutputWindow::SetWindowHandle(WindowingData window)
wnd = window.win32.window;
}
void VulkanReplay::OutputWindow::CreateSurface(VkInstance inst)
void VulkanReplay::OutputWindow::CreateSurface(WrappedVulkan *driver, VkInstance inst)
{
VkWin32SurfaceCreateInfoKHR createInfo;