cocoa: untested vulkan code

This commit is contained in:
IoI_xD 2026-04-14 20:03:59 -07:00
commit 065b0d824c
4 changed files with 43 additions and 0 deletions

View file

@ -70,6 +70,11 @@ if(MW_TRY_VULKAN)
if(HAVE_VULKAN_VULKAN_H) if(HAVE_VULKAN_VULKAN_H)
set(MW_BUILD_VULKAN ON) set(MW_BUILD_VULKAN ON)
list(APPEND SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/widget/vulkan.c") list(APPEND SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/widget/vulkan.c")
target_compile_definitions(
Mw
PRIVATE
MW_VULKAN
)
message(STATUS "Vulkan widget has been enabled") message(STATUS "Vulkan widget has been enabled")
else() else()
message(WARNING "Vulkan widget has been disabled") message(WARNING "Vulkan widget has been disabled")

View file

@ -131,6 +131,7 @@ if (param_get("opengl")) {
new_object("src/widget/opengl.c"); new_object("src/widget/opengl.c");
} }
if (param_get("vulkan")) { if (param_get("vulkan")) {
add_cflags("-DMW_VULKAN");
new_object("src/widget/vulkan.c"); new_object("src/widget/vulkan.c");
} }

View file

@ -2,6 +2,11 @@
#include "../../external/stb_ds.h" #include "../../external/stb_ds.h"
#include "Mw/LowLevel/Cocoa.h" #include "Mw/LowLevel/Cocoa.h"
#ifdef MW_VULKAN
#include <vulkan/vulkan_core.h>
#include <vulkan/vulkan_metal.h>
#endif
#ifdef __clang__ #ifdef __clang__
#pragma clang push #pragma clang push
#pragma clang diagnostic ignored "-Wdeprecated-declarations" #pragma clang diagnostic ignored "-Wdeprecated-declarations"
@ -1087,5 +1092,17 @@ static int MwLLCocoaCallInitImpl(void) {
return 0; return 0;
} }
#ifdef MW_VULKAN
VkMetalSurfaceCreateInfoEXT MwCocoaGetMetalSurfaceCreateInfo(MwWidget handle) {
VkMetalSurfaceCreateInfoEXT createInfo = {
.sType = VK_STRUCTURE_TYPE_METAL_SURFACE_CREATE_INFO_EXT,
.pNext = NULL,
.flags = 0,
.pLayer = (CAMetalLayer*)[handle->lowlevel->cocoa.real->view layer],
};
return createInfo;
};
#endif
#include "call.c" #include "call.c"
CALL(Cocoa); CALL(Cocoa);

View file

@ -26,6 +26,9 @@
#ifdef USE_WAYLAND #ifdef USE_WAYLAND
#include <vulkan/vulkan_wayland.h> #include <vulkan/vulkan_wayland.h>
#endif #endif
#ifdef USE_COCOA
#include <vulkan/vulkan_metal.h>
#endif
#ifdef HAS_VK_ENUM_STRING_HELPER #ifdef HAS_VK_ENUM_STRING_HELPER
#include <vulkan/vk_enum_string_helper.h> #include <vulkan/vk_enum_string_helper.h>
@ -167,6 +170,8 @@ static void destroy(MwWidget handle) {
static void* vulkan_lib_load() { static void* vulkan_lib_load() {
#ifdef _WIN32 #ifdef _WIN32
return MwDynamicOpen("vulkan-1.dll"); return MwDynamicOpen("vulkan-1.dll");
#elif defined(__APPLE__)
return MwDynamicOpen("libvulkan.dylib");
#else #else
return MwDynamicOpen("libvulkan.so"); return MwDynamicOpen("libvulkan.so");
#endif #endif
@ -230,6 +235,11 @@ static int vulkan_instance_setup(MwWidget handle, vulkan_t* o) {
MwWaylandAlwaysRender = MwTRUE; MwWaylandAlwaysRender = MwTRUE;
} }
#endif #endif
#ifdef USE_WAYLAND
if(handle->lowlevel->common.type == MwLLBackendCocoa) {
arrput(enabledExtensions, VK_EXT_METAL_SURFACE_EXTENSION_NAME);
}
#endif
/* passing null gives us all the extensions provided by the current vulkan implementation */ /* passing null gives us all the extensions provided by the current vulkan implementation */
VK_CMD(_vkEnumerateInstanceExtensionProperties(NULL, &extension_count, NULL)); VK_CMD(_vkEnumerateInstanceExtensionProperties(NULL, &extension_count, NULL));
@ -338,6 +348,16 @@ static int vulkan_surface_setup(MwWidget handle, vulkan_t* o) {
}; };
VK_CMD(_vkCreateWaylandSurfaceKHR(o->vkInstance, &createInfo, NULL, &o->vkSurface)); VK_CMD(_vkCreateWaylandSurfaceKHR(o->vkInstance, &createInfo, NULL, &o->vkSurface));
} }
#endif
#ifdef USE_COCOA
if(handle->lowlevel->common.type == MwLLBackendCocoa) {
VkMetalSurfaceCreateInfoEXT MwCocoaGetMetalSurfaceCreateInfo(MwWidget handle);
VkMetalSurfaceCreateInfoEXT inf = MwCocoaGetMetalSurfaceCreateInfo(handle);
LOAD_VK_FUNCTION(vkCreateMetalSurfaceEXT);
VK_CMD(_vkCreateMetalSurfaceEXT(o->vkInstance, &inf, NULL, &o->vkSurface));
}
#endif #endif
return 0; return 0;
} }