Updated Vulkan on Metal for OSX via MoltenVK

This commit is contained in:
Eric Warmenhoven 2023-01-05 00:33:52 -08:00 committed by LibretroAdmin
parent e447a4e8e6
commit 3c199c794e
12 changed files with 84 additions and 44 deletions

View File

@ -47,7 +47,7 @@
#define VK_USE_PLATFORM_XLIB_KHR
#endif
#ifdef HAVE_COCOA
#if defined(HAVE_COCOA) || defined(HAVE_COCOA_METAL)
#define VK_USE_PLATFORM_MACOS_MVK
#endif

View File

@ -2374,7 +2374,7 @@ bool vulkan_surface_create(gfx_ctx_vulkan_data_t *vk,
return false;
break;
case VULKAN_WSI_MVK_MACOS:
#ifdef HAVE_COCOA
#if defined(HAVE_COCOA) || defined(HAVE_COCOA_METAL)
{
PFN_vkCreateMacOSSurfaceMVK create;
if (!VULKAN_SYMBOL_WRAPPER_LOAD_INSTANCE_SYMBOL(vk->context.instance, "vkCreateMacOSSurfaceMVK", create))

View File

@ -91,15 +91,15 @@ enum vulkan_wsi_type
#ifdef VULKAN_HDR_SWAPCHAIN
#ifndef ALIGN
#ifndef VKALIGN
#ifdef _MSC_VER
#define ALIGN(x) __declspec(align(x))
#define VKALIGN(x) __declspec(align(x))
#else
#define ALIGN(x) __attribute__((aligned(x)))
#define VKALIGN(x) __attribute__((aligned(x)))
#endif
#endif
typedef struct ALIGN(16)
typedef struct VKALIGN(16)
{
math_matrix_4x4 mvp;
float contrast; /* 2.0f */

View File

@ -1596,6 +1596,11 @@ static void *vulkan_init(const video_info_t *video,
video->is_threaded,
FONT_DRIVER_RENDER_VULKAN_API);
#if OSX
// The MoltenVK driver needs this, particularly after driver reinit
vk->flags |= VK_FLAG_SHOULD_RESIZE;
#endif
vulkan_init_readback(vk, settings);
return vk;

View File

@ -43,13 +43,13 @@
#include "../common/metal_common.h"
#endif
typedef struct cocoa_ctx_data
typedef struct cocoa_vk_ctx_data
{
gfx_ctx_vulkan_data_t vk;
int swap_interval;
unsigned width;
unsigned height;
} cocoa_ctx_data_t;
} cocoa_vk_ctx_data_t;
/* TODO/FIXME - static globals */
static unsigned g_vk_minor = 0;
@ -60,7 +60,7 @@ CocoaView *cocoaview_get(void);
static uint32_t cocoa_vk_gfx_ctx_get_flags(void *data)
{
uint32_t flags = 0;
cocoa_ctx_data_t *cocoa_ctx = (cocoa_ctx_data_t*)data;
cocoa_vk_ctx_data_t *cocoa_ctx = (cocoa_vk_ctx_data_t*)data;
#if defined(HAVE_SLANG) && defined(HAVE_SPIRV_CROSS)
BIT32_SET(flags, GFX_CTX_FLAGS_SHADERS_SLANG);
@ -73,7 +73,7 @@ static void cocoa_vk_gfx_ctx_set_flags(void *data, uint32_t flags) { }
static void cocoa_vk_gfx_ctx_destroy(void *data)
{
cocoa_ctx_data_t *cocoa_ctx = (cocoa_ctx_data_t*)data;
cocoa_vk_ctx_data_t *cocoa_ctx = (cocoa_vk_ctx_data_t*)data;
if (!cocoa_ctx)
return;
@ -140,7 +140,7 @@ static void cocoa_vk_gfx_ctx_check_window(void *data, bool *quit,
bool *resize, unsigned *width, unsigned *height)
{
unsigned new_width, new_height;
cocoa_ctx_data_t *cocoa_ctx = (cocoa_ctx_data_t*)data;
cocoa_vk_ctx_data_t *cocoa_ctx = (cocoa_vk_ctx_data_t*)data;
*quit = false;
@ -164,7 +164,7 @@ static void cocoa_vk_gfx_ctx_check_window(void *data, bool *quit,
static void cocoa_vk_gfx_ctx_swap_interval(void *data, int i)
{
unsigned interval = (unsigned)i;
cocoa_ctx_data_t *cocoa_ctx = (cocoa_ctx_data_t*)data;
cocoa_vk_ctx_data_t *cocoa_ctx = (cocoa_vk_ctx_data_t*)data;
if (cocoa_ctx->swap_interval != interval)
{
@ -176,7 +176,7 @@ static void cocoa_vk_gfx_ctx_swap_interval(void *data, int i)
static void cocoa_vk_gfx_ctx_swap_buffers(void *data)
{
cocoa_ctx_data_t *cocoa_ctx = (cocoa_ctx_data_t*)data;
cocoa_vk_ctx_data_t *cocoa_ctx = (cocoa_vk_ctx_data_t*)data;
if (cocoa_ctx->vk.context.flags & VK_CTX_FLAG_HAS_ACQUIRED_SWAPCHAIN)
{
@ -204,7 +204,7 @@ static bool cocoa_vk_gfx_ctx_bind_api(void *data, enum gfx_ctx_api api,
static void *cocoa_vk_gfx_ctx_get_context_data(void *data)
{
cocoa_ctx_data_t *cocoa_ctx = (cocoa_ctx_data_t*)data;
cocoa_vk_ctx_data_t *cocoa_ctx = (cocoa_vk_ctx_data_t*)data;
return &cocoa_ctx->vk.context;
}
@ -217,7 +217,7 @@ static bool cocoa_vk_gfx_ctx_set_video_mode(void *data,
#elif defined(HAVE_COCOA)
CocoaView *g_view = (CocoaView*)nsview_get_ptr();
#endif
cocoa_ctx_data_t *cocoa_ctx = (cocoa_ctx_data_t*)data;
cocoa_vk_ctx_data_t *cocoa_ctx = (cocoa_vk_ctx_data_t*)data;
static bool
has_went_fullscreen = false;
cocoa_ctx->width = width;
@ -239,26 +239,13 @@ static bool cocoa_vk_gfx_ctx_set_video_mode(void *data,
return false;
}
/* TODO: Screen mode support. */
if (fullscreen)
{
if (!has_went_fullscreen)
{
[g_view enterFullScreenMode:(BRIDGE NSScreen *)cocoa_screen_get_chosen() withOptions:nil];
cocoa_show_mouse(data, false);
}
}
else
{
if (has_went_fullscreen)
{
[g_view exitFullScreenModeWithOptions:nil];
[[g_view window] makeFirstResponder:g_view];
cocoa_show_mouse(data, true);
}
[[g_view window] setContentSize:NSMakeSize(width, height)];
}
gfx_ctx_mode_t mode = {
.width = width,
.height = height,
.fullscreen = fullscreen,
};
[apple_platform setVideoMode:mode];
cocoa_show_mouse(data, !fullscreen);
has_went_fullscreen = fullscreen;
@ -267,8 +254,8 @@ static bool cocoa_vk_gfx_ctx_set_video_mode(void *data,
static void *cocoa_vk_gfx_ctx_init(void *video_driver)
{
cocoa_ctx_data_t *cocoa_ctx = (cocoa_ctx_data_t*)
calloc(1, sizeof(cocoa_ctx_data_t));
cocoa_vk_ctx_data_t *cocoa_ctx = (cocoa_vk_ctx_data_t*)
calloc(1, sizeof(cocoa_vk_ctx_data_t));
if (!cocoa_ctx)
return NULL;
@ -286,7 +273,7 @@ static void *cocoa_vk_gfx_ctx_init(void *video_driver)
static bool cocoa_vk_gfx_ctx_set_video_mode(void *data,
unsigned width, unsigned height, bool fullscreen)
{
cocoa_ctx_data_t *cocoa_ctx = (cocoa_ctx_data_t*)data;
cocoa_vk_ctx_data_t *cocoa_ctx = (cocoa_vk_ctx_data_t*)data;
/* TODO: Maybe iOS users should be able to
* show/hide the status bar here? */
@ -295,8 +282,8 @@ static bool cocoa_vk_gfx_ctx_set_video_mode(void *data,
static void *cocoa_vk_gfx_ctx_init(void *video_driver)
{
cocoa_ctx_data_t *cocoa_ctx = (cocoa_ctx_data_t*)
calloc(1, sizeof(cocoa_ctx_data_t));
cocoa_vk_ctx_data_t *cocoa_ctx = (cocoa_vk_ctx_data_t*)
calloc(1, sizeof(cocoa_vk_ctx_data_t));
if (!cocoa_ctx)
return NULL;
@ -308,7 +295,7 @@ static void *cocoa_vk_gfx_ctx_init(void *video_driver)
#ifdef HAVE_COCOA_METAL
static bool cocoa_vk_gfx_ctx_set_resize(void *data, unsigned width, unsigned height)
{
cocoa_ctx_data_t *cocoa_ctx = (cocoa_ctx_data_t*)data;
cocoa_vk_ctx_data_t *cocoa_ctx = (cocoa_vk_ctx_data_t*)data;
cocoa_ctx->width = width;
cocoa_ctx->height = height;

View File

@ -0,0 +1,8 @@
{
"file_format_version" : "1.0.0",
"ICD": {
"library_path": "./libMoltenVK.dylib",
"api_version" : "1.2.0",
"is_portability_driver" : true
}
}

Binary file not shown.

View File

@ -0,0 +1,8 @@
{
"file_format_version" : "1.0.0",
"ICD": {
"library_path": "./libMoltenVK.dylib",
"api_version" : "1.2.0",
"is_portability_driver" : true
}
}

Binary file not shown.

View File

@ -0,0 +1,8 @@
{
"file_format_version" : "1.0.0",
"ICD": {
"library_path": "./libMoltenVK.dylib",
"api_version" : "1.2.0",
"is_portability_driver" : true
}
}

Binary file not shown.

View File

@ -39,7 +39,9 @@
05A8E23C20A63CF50084ABDA /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 05A8E23B20A63CF50084ABDA /* QuartzCore.framework */; };
05D7753520A567A400646447 /* griffin_cpp.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 05D7753320A5678300646447 /* griffin_cpp.cpp */; };
05D7753720A567A700646447 /* griffin_glslang.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 05D7753420A5678400646447 /* griffin_glslang.cpp */; };
072976DD296284F600D6E00C /* OpenGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 072976DC296284F600D6E00C /* OpenGL.framework */; };
072976DD296284F600D6E00C /* OpenGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 072976DC296284F600D6E00C /* OpenGL.framework */; };
079371D0296392420059A71C /* libMoltenVK.dylib in Embed Libraries */ = {isa = PBXBuildFile; fileRef = 07B634CF296391FF00B3D78D /* libMoltenVK.dylib */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
07B634D0296391FF00B3D78D /* libMoltenVK.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 07B634CF296391FF00B3D78D /* libMoltenVK.dylib */; };
5061C8A41AE47E510080AE14 /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 5061C8A31AE47E510080AE14 /* libz.dylib */; };
509F0C9D1AA23AFC00619ECC /* griffin_objc.m in Sources */ = {isa = PBXBuildFile; fileRef = 509F0C9C1AA23AFC00619ECC /* griffin_objc.m */; };
840222FC1A889EE2009AB261 /* griffin.c in Sources */ = {isa = PBXBuildFile; fileRef = 840222FB1A889EE2009AB261 /* griffin.c */; };
@ -65,8 +67,9 @@
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 6;
dstSubfolderSpec = 10;
files = (
079371D0296392420059A71C /* libMoltenVK.dylib in Embed Libraries */,
);
name = "Embed Libraries";
runOnlyForDeploymentPostprocessing = 0;
@ -505,7 +508,8 @@
05F2873F20F2BEEA00632D47 /* task_content.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = task_content.c; sourceTree = "<group>"; };
05F2874020F2BEEA00632D47 /* task_http.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = task_http.c; sourceTree = "<group>"; };
05F2874120F2BEEA00632D47 /* task_patch.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = task_patch.c; sourceTree = "<group>"; };
072976DC296284F600D6E00C /* OpenGL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGL.framework; path = System/Library/Frameworks/OpenGL.framework; sourceTree = SDKROOT; };
072976DC296284F600D6E00C /* OpenGL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGL.framework; path = System/Library/Frameworks/OpenGL.framework; sourceTree = SDKROOT; };
07B634CF296391FF00B3D78D /* libMoltenVK.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libMoltenVK.dylib; path = Frameworks/MoltenVK/dylib/macOS/libMoltenVK.dylib; sourceTree = "<group>"; };
089C165DFE840E0CC02AAC07 /* InfoPlist.strings */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = InfoPlist.strings; path = OSX/en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
29B97324FDCFA39411CA2CEA /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = "<absolute>"; };
5061C8A31AE47E510080AE14 /* libz.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libz.dylib; path = usr/lib/libz.dylib; sourceTree = SDKROOT; };
@ -570,6 +574,7 @@
files = (
D27C508C2228362700113BC0 /* AudioToolbox.framework in Frameworks */,
072976DD296284F600D6E00C /* OpenGL.framework in Frameworks */,
07B634D0296391FF00B3D78D /* libMoltenVK.dylib in Frameworks */,
D27C508B2228361D00113BC0 /* AVFoundation.framework in Frameworks */,
05A8E23C20A63CF50084ABDA /* QuartzCore.framework in Frameworks */,
05A8E23A20A63CED0084ABDA /* IOSurface.framework in Frameworks */,
@ -1418,6 +1423,7 @@
isa = PBXGroup;
children = (
D27C50892228360D00113BC0 /* AudioToolbox.framework */,
07B634CF296391FF00B3D78D /* libMoltenVK.dylib */,
072976DC296284F600D6E00C /* OpenGL.framework */,
D27C50872228360000113BC0 /* AVFoundation.framework */,
053FC25521433F1700D98D46 /* QtConcurrent.framework */,
@ -1724,12 +1730,21 @@
GCC_MODEL_TUNING = G5;
GCC_OPTIMIZATION_LEVEL = 0;
INSTALL_PATH = "$(HOME)/Applications";
LD_RUNPATH_SEARCH_PATHS = (
"$(LD_RUNPATH_SEARCH_PATHS_$(IS_MACCATALYST))",
"@executable_path/../Frameworks",
);
LIBRARY_SEARCH_PATHS = (
"$(SRCBASE)/pkg/apple/Frameworks/MoltenVK/dylib/macOS",
"$(PROJECT_DIR)/Frameworks/MoltenVK/dylib/macOS",
);
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
OTHER_CFLAGS = (
"$(inherited)",
"-DHAVE_MAIN",
"-DHAVE_COCOA_METAL",
"-DHAVE_OPENGL_CORE",
"-DHAVE_VULKAN",
);
OTHER_CODE_SIGN_FLAGS = "--deep --timestamp";
OTHER_CPLUSPLUSFLAGS = "$(OTHER_CFLAGS)";
@ -1755,11 +1770,20 @@
GCC_MODEL_TUNING = G5;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
INSTALL_PATH = "$(HOME)/Applications";
LD_RUNPATH_SEARCH_PATHS = (
"$(LD_RUNPATH_SEARCH_PATHS_$(IS_MACCATALYST))",
"@executable_path/../Frameworks",
);
LIBRARY_SEARCH_PATHS = (
"$(SRCBASE)/pkg/apple/Frameworks/MoltenVK/dylib/macOS",
"$(PROJECT_DIR)/Frameworks/MoltenVK/dylib/macOS",
);
OTHER_CFLAGS = (
"$(inherited)",
"-DHAVE_MAIN",
"-DHAVE_COCOA_METAL",
"-DHAVE_OPENGL_CORE",
"-DHAVE_VULKAN",
);
OTHER_CODE_SIGN_FLAGS = "--deep --timestamp";
OTHER_CPLUSPLUSFLAGS = "$(OTHER_CFLAGS)";