mirror of
https://github.com/glfw/glfw.git
synced 2024-11-10 00:51:47 +00:00
Cocoa: Select Vulkan surface extension at runtime
This mostly just follows the pattern established by X11. Related to #1619.
This commit is contained in:
parent
c5cb4a253a
commit
15d91801b7
@ -145,8 +145,6 @@ elseif (WIN32)
|
|||||||
elseif (APPLE)
|
elseif (APPLE)
|
||||||
set(_GLFW_COCOA 1)
|
set(_GLFW_COCOA 1)
|
||||||
message(STATUS "Using Cocoa for window creation")
|
message(STATUS "Using Cocoa for window creation")
|
||||||
set(VK_USE_PLATFORM_METAL_EXT 1)
|
|
||||||
message(STATUS "Using VK_EXT_metal_surface")
|
|
||||||
elseif (UNIX)
|
elseif (UNIX)
|
||||||
set(_GLFW_X11 1)
|
set(_GLFW_X11 1)
|
||||||
message(STATUS "Using X11 for window creation")
|
message(STATUS "Using X11 for window creation")
|
||||||
|
@ -141,6 +141,7 @@ information on what to include when reporting a bug.
|
|||||||
- [Win32] Bugfix: The window hint `GLFW_MAXIMIZED` did not move or resize the
|
- [Win32] Bugfix: The window hint `GLFW_MAXIMIZED` did not move or resize the
|
||||||
window (#1499)
|
window (#1499)
|
||||||
- [Win32] Bugfix: Disabled cursor mode interfered with some non-client actions
|
- [Win32] Bugfix: Disabled cursor mode interfered with some non-client actions
|
||||||
|
- [Cocoa] Added support for `VK_EXT_metal_surface` (#1619)
|
||||||
- [Cocoa] Removed dependency on the CoreVideo framework
|
- [Cocoa] Removed dependency on the CoreVideo framework
|
||||||
- [Cocoa] Bugfix: `glfwSetWindowSize` used a bottom-left anchor point (#1553)
|
- [Cocoa] Bugfix: `glfwSetWindowSize` used a bottom-left anchor point (#1553)
|
||||||
- [Cocoa] Bugfix: Window remained on screen after destruction until event poll
|
- [Cocoa] Bugfix: Window remained on screen after destruction until event poll
|
||||||
@ -260,6 +261,7 @@ skills.
|
|||||||
- Cem Karan
|
- Cem Karan
|
||||||
- Osman Keskin
|
- Osman Keskin
|
||||||
- Josh Kilmer
|
- Josh Kilmer
|
||||||
|
- Byunghoon Kim
|
||||||
- Cameron King
|
- Cameron King
|
||||||
- Peter Knut
|
- Peter Knut
|
||||||
- Christoph Kubisch
|
- Christoph Kubisch
|
||||||
|
@ -60,8 +60,8 @@ typedef void* id;
|
|||||||
#define NSWindowStyleMaskTitled NSTitledWindowMask
|
#define NSWindowStyleMaskTitled NSTitledWindowMask
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(VK_USE_PLATFORM_MACOS_MVK)
|
|
||||||
typedef VkFlags VkMacOSSurfaceCreateFlagsMVK;
|
typedef VkFlags VkMacOSSurfaceCreateFlagsMVK;
|
||||||
|
typedef VkFlags VkMetalSurfaceCreateFlagsEXT;
|
||||||
|
|
||||||
typedef struct VkMacOSSurfaceCreateInfoMVK
|
typedef struct VkMacOSSurfaceCreateInfoMVK
|
||||||
{
|
{
|
||||||
@ -71,24 +71,16 @@ typedef struct VkMacOSSurfaceCreateInfoMVK
|
|||||||
const void* pView;
|
const void* pView;
|
||||||
} VkMacOSSurfaceCreateInfoMVK;
|
} VkMacOSSurfaceCreateInfoMVK;
|
||||||
|
|
||||||
typedef VkResult (APIENTRY *PFN_vkCreateMacOSSurfaceMVK)(VkInstance,const VkMacOSSurfaceCreateInfoMVK*,const VkAllocationCallbacks*,VkSurfaceKHR*);
|
typedef struct VkMetalSurfaceCreateInfoEXT
|
||||||
|
{
|
||||||
#elif defined(VK_USE_PLATFORM_METAL_EXT)
|
|
||||||
#define VK_EXT_metal_surface 1
|
|
||||||
typedef void CAMetalLayer;
|
|
||||||
|
|
||||||
#define VK_EXT_METAL_SURFACE_SPEC_VERSION 1
|
|
||||||
#define VK_EXT_METAL_SURFACE_EXTENSION_NAME "VK_EXT_metal_surface"
|
|
||||||
typedef VkFlags VkMetalSurfaceCreateFlagsEXT;
|
|
||||||
typedef struct VkMetalSurfaceCreateInfoEXT {
|
|
||||||
VkStructureType sType;
|
VkStructureType sType;
|
||||||
const void* pNext;
|
const void* pNext;
|
||||||
VkMetalSurfaceCreateFlagsEXT flags;
|
VkMetalSurfaceCreateFlagsEXT flags;
|
||||||
const CAMetalLayer* pLayer;
|
const void* pLayer;
|
||||||
} VkMetalSurfaceCreateInfoEXT;
|
} VkMetalSurfaceCreateInfoEXT;
|
||||||
|
|
||||||
typedef VkResult (APIENTRY *PFN_vkCreateMetalSurfaceEXT)(VkInstance, const VkMetalSurfaceCreateInfoEXT*, const VkAllocationCallbacks*, VkSurfaceKHR*);
|
typedef VkResult (APIENTRY *PFN_vkCreateMacOSSurfaceMVK)(VkInstance,const VkMacOSSurfaceCreateInfoMVK*,const VkAllocationCallbacks*,VkSurfaceKHR*);
|
||||||
#endif
|
typedef VkResult (APIENTRY *PFN_vkCreateMetalSurfaceEXT)(VkInstance,const VkMetalSurfaceCreateInfoEXT*,const VkAllocationCallbacks*,VkSurfaceKHR*);
|
||||||
|
|
||||||
#include "posix_thread.h"
|
#include "posix_thread.h"
|
||||||
#include "cocoa_joystick.h"
|
#include "cocoa_joystick.h"
|
||||||
|
@ -1715,19 +1715,16 @@ const char* _glfwPlatformGetClipboardString(void)
|
|||||||
|
|
||||||
void _glfwPlatformGetRequiredInstanceExtensions(char** extensions)
|
void _glfwPlatformGetRequiredInstanceExtensions(char** extensions)
|
||||||
{
|
{
|
||||||
#if defined(VK_USE_PLATFORM_MACOS_MVK)
|
if (_glfw.vk.KHR_surface && _glfw.vk.EXT_metal_surface)
|
||||||
if (!_glfw.vk.KHR_surface || !_glfw.vk.MVK_macos_surface)
|
{
|
||||||
return;
|
extensions[0] = "VK_KHR_surface";
|
||||||
|
extensions[1] = "VK_EXT_metal_surface";
|
||||||
extensions[0] = "VK_KHR_surface";
|
}
|
||||||
extensions[1] = "VK_MVK_macos_surface";
|
else if (_glfw.vk.KHR_surface && _glfw.vk.MVK_macos_surface)
|
||||||
|
{
|
||||||
#elif defined(VK_USE_PLATFORM_METAL_EXT)
|
extensions[0] = "VK_KHR_surface";
|
||||||
if (!_glfw.vk.KHR_surface || !_glfw.vk.EXT_metal_surface)
|
extensions[1] = "VK_MVK_macos_surface";
|
||||||
return;
|
}
|
||||||
extensions[0] = "VK_KHR_surface";
|
|
||||||
extensions[1] = "VK_EXT_metal_surface";
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int _glfwPlatformGetPhysicalDevicePresentationSupport(VkInstance instance,
|
int _glfwPlatformGetPhysicalDevicePresentationSupport(VkInstance instance,
|
||||||
@ -1745,35 +1742,6 @@ VkResult _glfwPlatformCreateWindowSurface(VkInstance instance,
|
|||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
|
|
||||||
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101100
|
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101100
|
||||||
VkResult err;
|
|
||||||
|
|
||||||
#if defined(VK_USE_PLATFORM_MACOS_MVK)
|
|
||||||
VkMacOSSurfaceCreateInfoMVK sci;
|
|
||||||
|
|
||||||
PFN_vkCreateMacOSSurfaceMVK vkCreateMacOSSurfaceMVK;
|
|
||||||
vkCreateMacOSSurfaceMVK = (PFN_vkCreateMacOSSurfaceMVK)
|
|
||||||
vkGetInstanceProcAddr(instance, "vkCreateMacOSSurfaceMVK");
|
|
||||||
if (!vkCreateMacOSSurfaceMVK)
|
|
||||||
{
|
|
||||||
_glfwInputError(GLFW_API_UNAVAILABLE,
|
|
||||||
"Cocoa: Vulkan instance missing VK_MVK_macos_surface extension");
|
|
||||||
return VK_ERROR_EXTENSION_NOT_PRESENT;
|
|
||||||
}
|
|
||||||
|
|
||||||
#elif defined(VK_USE_PLATFORM_METAL_EXT)
|
|
||||||
VkMetalSurfaceCreateInfoEXT sci;
|
|
||||||
|
|
||||||
PFN_vkCreateMetalSurfaceEXT vkCreateMetalSurfaceEXT;
|
|
||||||
vkCreateMetalSurfaceEXT = (PFN_vkCreateMetalSurfaceEXT)
|
|
||||||
vkGetInstanceProcAddr(instance, "vkCreateMetalSurfaceEXT");
|
|
||||||
if (!vkCreateMetalSurfaceEXT)
|
|
||||||
{
|
|
||||||
_glfwInputError(GLFW_API_UNAVAILABLE,
|
|
||||||
"Cocoa: Vulkan instance missing VK_EXT_metal_surface extension");
|
|
||||||
return VK_ERROR_EXTENSION_NOT_PRESENT;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// HACK: Dynamically load Core Animation to avoid adding an extra
|
// HACK: Dynamically load Core Animation to avoid adding an extra
|
||||||
// dependency for the majority who don't use MoltenVK
|
// dependency for the majority who don't use MoltenVK
|
||||||
NSBundle* bundle = [NSBundle bundleWithPath:@"/System/Library/Frameworks/QuartzCore.framework"];
|
NSBundle* bundle = [NSBundle bundleWithPath:@"/System/Library/Frameworks/QuartzCore.framework"];
|
||||||
@ -1799,21 +1767,49 @@ VkResult _glfwPlatformCreateWindowSurface(VkInstance instance,
|
|||||||
[window->ns.view setLayer:window->ns.layer];
|
[window->ns.view setLayer:window->ns.layer];
|
||||||
[window->ns.view setWantsLayer:YES];
|
[window->ns.view setWantsLayer:YES];
|
||||||
|
|
||||||
memset(&sci, 0, sizeof(sci));
|
VkResult err;
|
||||||
#if defined(VK_USE_PLATFORM_MACOS_MVK)
|
|
||||||
sci.sType = VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK;
|
|
||||||
sci.pView = window->ns.view;
|
|
||||||
|
|
||||||
err = vkCreateMacOSSurfaceMVK(instance, &sci, allocator, surface);
|
if (_glfw.vk.EXT_metal_surface)
|
||||||
|
{
|
||||||
|
VkMetalSurfaceCreateInfoEXT sci;
|
||||||
|
|
||||||
#elif defined(VK_USE_PLATFORM_METAL_EXT)
|
PFN_vkCreateMetalSurfaceEXT vkCreateMetalSurfaceEXT;
|
||||||
sci.sType = VK_STRUCTURE_TYPE_METAL_SURFACE_CREATE_INFO_EXT;
|
vkCreateMetalSurfaceEXT = (PFN_vkCreateMetalSurfaceEXT)
|
||||||
sci.pNext = NULL;
|
vkGetInstanceProcAddr(instance, "vkCreateMetalSurfaceEXT");
|
||||||
sci.flags = 0;
|
if (!vkCreateMetalSurfaceEXT)
|
||||||
sci.pLayer = window->ns.layer;
|
{
|
||||||
|
_glfwInputError(GLFW_API_UNAVAILABLE,
|
||||||
|
"Cocoa: Vulkan instance missing VK_EXT_metal_surface extension");
|
||||||
|
return VK_ERROR_EXTENSION_NOT_PRESENT;
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(&sci, 0, sizeof(sci));
|
||||||
|
sci.sType = VK_STRUCTURE_TYPE_METAL_SURFACE_CREATE_INFO_EXT;
|
||||||
|
sci.pLayer = window->ns.layer;
|
||||||
|
|
||||||
|
err = vkCreateMetalSurfaceEXT(instance, &sci, allocator, surface);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
VkMacOSSurfaceCreateInfoMVK sci;
|
||||||
|
|
||||||
|
PFN_vkCreateMacOSSurfaceMVK vkCreateMacOSSurfaceMVK;
|
||||||
|
vkCreateMacOSSurfaceMVK = (PFN_vkCreateMacOSSurfaceMVK)
|
||||||
|
vkGetInstanceProcAddr(instance, "vkCreateMacOSSurfaceMVK");
|
||||||
|
if (!vkCreateMacOSSurfaceMVK)
|
||||||
|
{
|
||||||
|
_glfwInputError(GLFW_API_UNAVAILABLE,
|
||||||
|
"Cocoa: Vulkan instance missing VK_MVK_macos_surface extension");
|
||||||
|
return VK_ERROR_EXTENSION_NOT_PRESENT;
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(&sci, 0, sizeof(sci));
|
||||||
|
sci.sType = VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK;
|
||||||
|
sci.pView = window->ns.view;
|
||||||
|
|
||||||
|
err = vkCreateMacOSSurfaceMVK(instance, &sci, allocator, surface);
|
||||||
|
}
|
||||||
|
|
||||||
err = vkCreateMetalSurfaceEXT(instance, &sci, allocator, surface);
|
|
||||||
#endif
|
|
||||||
if (err)
|
if (err)
|
||||||
{
|
{
|
||||||
_glfwInputError(GLFW_PLATFORM_ERROR,
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
||||||
|
@ -40,7 +40,6 @@
|
|||||||
#cmakedefine _GLFW_WIN32
|
#cmakedefine _GLFW_WIN32
|
||||||
// Define this to 1 if building GLFW for Cocoa
|
// Define this to 1 if building GLFW for Cocoa
|
||||||
#cmakedefine _GLFW_COCOA
|
#cmakedefine _GLFW_COCOA
|
||||||
#cmakedefine VK_USE_PLATFORM_METAL_EXT
|
|
||||||
// Define this to 1 if building GLFW for Wayland
|
// Define this to 1 if building GLFW for Wayland
|
||||||
#cmakedefine _GLFW_WAYLAND
|
#cmakedefine _GLFW_WAYLAND
|
||||||
// Define this to 1 if building GLFW for OSMesa
|
// Define this to 1 if building GLFW for OSMesa
|
||||||
|
@ -559,11 +559,8 @@ struct _GLFWlibrary
|
|||||||
#if defined(_GLFW_WIN32)
|
#if defined(_GLFW_WIN32)
|
||||||
GLFWbool KHR_win32_surface;
|
GLFWbool KHR_win32_surface;
|
||||||
#elif defined(_GLFW_COCOA)
|
#elif defined(_GLFW_COCOA)
|
||||||
#if defined(VK_USE_PLATFORM_MACOS_MVK)
|
|
||||||
GLFWbool MVK_macos_surface;
|
GLFWbool MVK_macos_surface;
|
||||||
#elif defined(VK_USE_PLATFORM_METAL_EXT)
|
|
||||||
GLFWbool EXT_metal_surface;
|
GLFWbool EXT_metal_surface;
|
||||||
#endif
|
|
||||||
#elif defined(_GLFW_X11)
|
#elif defined(_GLFW_X11)
|
||||||
GLFWbool KHR_xlib_surface;
|
GLFWbool KHR_xlib_surface;
|
||||||
GLFWbool KHR_xcb_surface;
|
GLFWbool KHR_xcb_surface;
|
||||||
|
@ -128,13 +128,10 @@ GLFWbool _glfwInitVulkan(int mode)
|
|||||||
else if (strcmp(ep[i].extensionName, "VK_KHR_win32_surface") == 0)
|
else if (strcmp(ep[i].extensionName, "VK_KHR_win32_surface") == 0)
|
||||||
_glfw.vk.KHR_win32_surface = GLFW_TRUE;
|
_glfw.vk.KHR_win32_surface = GLFW_TRUE;
|
||||||
#elif defined(_GLFW_COCOA)
|
#elif defined(_GLFW_COCOA)
|
||||||
#if defined(VK_USE_PLATFORM_MACOS_MVK)
|
|
||||||
else if (strcmp(ep[i].extensionName, "VK_MVK_macos_surface") == 0)
|
else if (strcmp(ep[i].extensionName, "VK_MVK_macos_surface") == 0)
|
||||||
_glfw.vk.MVK_macos_surface = GLFW_TRUE;
|
_glfw.vk.MVK_macos_surface = GLFW_TRUE;
|
||||||
#elif defined(VK_USE_PLATFORM_METAL_EXT)
|
|
||||||
else if (strcmp(ep[i].extensionName, "VK_EXT_metal_surface") == 0)
|
else if (strcmp(ep[i].extensionName, "VK_EXT_metal_surface") == 0)
|
||||||
_glfw.vk.EXT_metal_surface = GLFW_TRUE;
|
_glfw.vk.EXT_metal_surface = GLFW_TRUE;
|
||||||
#endif
|
|
||||||
#elif defined(_GLFW_X11)
|
#elif defined(_GLFW_X11)
|
||||||
else if (strcmp(ep[i].extensionName, "VK_KHR_xlib_surface") == 0)
|
else if (strcmp(ep[i].extensionName, "VK_KHR_xlib_surface") == 0)
|
||||||
_glfw.vk.KHR_xlib_surface = GLFW_TRUE;
|
_glfw.vk.KHR_xlib_surface = GLFW_TRUE;
|
||||||
|
Loading…
Reference in New Issue
Block a user