Skip to content

Commit

Permalink
Merge pull request #87999 from bruvzg/metal_layer
Browse files Browse the repository at this point in the history
[macOS / iOS] Switch Vulkan init to `VK_EXT_metal_surface` extension.
  • Loading branch information
akien-mga committed Feb 13, 2024
2 parents b364806 + f458943 commit b50001e
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion platform/ios/display_server_ios.mm
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
if (!layer) {
ERR_FAIL_MSG("Failed to create iOS Vulkan rendering layer.");
}
wpd.vulkan.layer_ptr = &layer;
wpd.vulkan.layer_ptr = (CAMetalLayer *const *)&layer;
rendering_context = memnew(RenderingContextDriverVulkanIOS);
}
#endif
Expand Down
4 changes: 2 additions & 2 deletions platform/ios/rendering_context_driver_vulkan_ios.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

#include "drivers/vulkan/rendering_context_driver_vulkan.h"

#import <UIKit/UIKit.h>
#import <QuartzCore/CAMetalLayer.h>

class RenderingContextDriverVulkanIOS : public RenderingContextDriverVulkan {
private:
Expand All @@ -46,7 +46,7 @@ class RenderingContextDriverVulkanIOS : public RenderingContextDriverVulkan {

public:
struct WindowPlatformData {
CALayer *const *layer_ptr;
CAMetalLayer *const *layer_ptr;
};

RenderingContextDriverVulkanIOS();
Expand Down
12 changes: 6 additions & 6 deletions platform/ios/rendering_context_driver_vulkan_ios.mm
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,22 @@
#ifdef USE_VOLK
#include <volk.h>
#else
#include <vulkan/vulkan.h>
#include <vulkan/vulkan_metal.h>
#endif

const char *RenderingContextDriverVulkanIOS::_get_platform_surface_extension() const {
return VK_MVK_IOS_SURFACE_EXTENSION_NAME;
return VK_EXT_METAL_SURFACE_EXTENSION_NAME;
}

RenderingContextDriver::SurfaceID RenderingContextDriverVulkanIOS::surface_create(const void *p_platform_data) {
const WindowPlatformData *wpd = (const WindowPlatformData *)(p_platform_data);

VkIOSSurfaceCreateInfoMVK create_info = {};
create_info.sType = VK_STRUCTURE_TYPE_IOS_SURFACE_CREATE_INFO_MVK;
create_info.pView = (__bridge const void *)(*wpd->layer_ptr);
VkMetalSurfaceCreateInfoEXT create_info = {};
create_info.sType = VK_STRUCTURE_TYPE_METAL_SURFACE_CREATE_INFO_EXT;
create_info.pLayer = *wpd->layer_ptr;

VkSurfaceKHR vk_surface = VK_NULL_HANDLE;
VkResult err = vkCreateIOSSurfaceMVK(instance_get(), &create_info, nullptr, &vk_surface);
VkResult err = vkCreateMetalSurfaceEXT(instance_get(), &create_info, nullptr, &vk_surface);
ERR_FAIL_COND_V(err != VK_SUCCESS, SurfaceID());

Surface *surface = memnew(Surface);
Expand Down
2 changes: 1 addition & 1 deletion platform/macos/display_server_macos.mm
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@
} wpd;
#ifdef VULKAN_ENABLED
if (rendering_driver == "vulkan") {
wpd.vulkan.view_ptr = &wd.window_view;
wpd.vulkan.layer_ptr = (CAMetalLayer *const *)&layer;
}
#endif
Error err = rendering_context->window_create(window_id_counter, &wpd);
Expand Down
4 changes: 2 additions & 2 deletions platform/macos/rendering_context_driver_vulkan_macos.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

#include "drivers/vulkan/rendering_context_driver_vulkan.h"

#import <AppKit/AppKit.h>
#import <QuartzCore/CAMetalLayer.h>

class RenderingContextDriverVulkanMacOS : public RenderingContextDriverVulkan {
private:
Expand All @@ -46,7 +46,7 @@ class RenderingContextDriverVulkanMacOS : public RenderingContextDriverVulkan {

public:
struct WindowPlatformData {
const id *view_ptr;
CAMetalLayer *const *layer_ptr;
};

RenderingContextDriverVulkanMacOS();
Expand Down
12 changes: 6 additions & 6 deletions platform/macos/rendering_context_driver_vulkan_macos.mm
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,22 @@
#ifdef USE_VOLK
#include <volk.h>
#else
#include <vulkan/vulkan.h>
#include <vulkan/vulkan_metal.h>
#endif

const char *RenderingContextDriverVulkanMacOS::_get_platform_surface_extension() const {
return VK_MVK_MACOS_SURFACE_EXTENSION_NAME;
return VK_EXT_METAL_SURFACE_EXTENSION_NAME;
}

RenderingContextDriver::SurfaceID RenderingContextDriverVulkanMacOS::surface_create(const void *p_platform_data) {
const WindowPlatformData *wpd = (const WindowPlatformData *)(p_platform_data);

VkMacOSSurfaceCreateInfoMVK create_info = {};
create_info.sType = VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK;
create_info.pView = (__bridge const void *)(*wpd->view_ptr);
VkMetalSurfaceCreateInfoEXT create_info = {};
create_info.sType = VK_STRUCTURE_TYPE_METAL_SURFACE_CREATE_INFO_EXT;
create_info.pLayer = *wpd->layer_ptr;

VkSurfaceKHR vk_surface = VK_NULL_HANDLE;
VkResult err = vkCreateMacOSSurfaceMVK(instance_get(), &create_info, nullptr, &vk_surface);
VkResult err = vkCreateMetalSurfaceEXT(instance_get(), &create_info, nullptr, &vk_surface);
ERR_FAIL_COND_V(err != VK_SUCCESS, SurfaceID());

Surface *surface = memnew(Surface);
Expand Down

0 comments on commit b50001e

Please sign in to comment.