Commit 6623ca14 by Jonah Ryan-Davis Committed by Alexis Hétu

Fix vulkan builds in ANGLE on MacOS

MacOS requires a few defines that were missing from BUILD.gn. It also requires being linked to Cocoa/IOSurface/QuartzCore. It also needs macros to define API availability to use CAMetalLayer. Bug: chromium:1015454 Change-Id: I6b298cc805ce1f927d2eed8f4d0e11a271f75f24 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/37628 Kokoro-Presubmit: kokoro <noreply+kokoro@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Tested-by: 's avatarAlexis Hétu <sugoi@google.com>
parent 1737a30e
...@@ -33,6 +33,11 @@ config("swiftshader_libvulkan_private_config") { ...@@ -33,6 +33,11 @@ config("swiftshader_libvulkan_private_config") {
"VK_USE_PLATFORM_WIN32_KHR=1", "VK_USE_PLATFORM_WIN32_KHR=1",
"VK_EXPORT=", "VK_EXPORT=",
] ]
} else if (is_mac) {
defines = [
"VK_USE_PLATFORM_MACOS_MVK=1",
"VK_EXPORT=__attribute__((visibility(\"default\")))",
]
} else { } else {
defines = [ "VK_EXPORT=" ] defines = [ "VK_EXPORT=" ]
} }
......
...@@ -40,6 +40,17 @@ swiftshader_source_set("WSI") { ...@@ -40,6 +40,17 @@ swiftshader_source_set("WSI") {
] ]
} }
if (is_mac) {
sources += [
"MacOSSurfaceMVK.mm",
"MacOSSurfaceMVK.h"
]
libs = [
"Cocoa.framework",
"QuartzCore.framework",
]
}
include_dirs = [ include_dirs = [
"..", "..",
"../../include", "../../include",
......
...@@ -25,7 +25,7 @@ namespace vk { ...@@ -25,7 +25,7 @@ namespace vk {
class MetalLayer class MetalLayer
{ {
public: public:
void init(const void* pView) void init(const void* pView) API_AVAILABLE(macosx(10.11))
{ {
view = nullptr; view = nullptr;
layer = nullptr; layer = nullptr;
...@@ -53,7 +53,7 @@ public: ...@@ -53,7 +53,7 @@ public:
} }
} }
void release() void release() API_AVAILABLE(macosx(10.11))
{ {
if(layer) if(layer)
{ {
...@@ -66,7 +66,7 @@ public: ...@@ -66,7 +66,7 @@ public:
} }
} }
VkExtent2D getExtent() const VkExtent2D getExtent() const API_AVAILABLE(macosx(10.11))
{ {
if(layer) if(layer)
{ {
...@@ -82,7 +82,7 @@ public: ...@@ -82,7 +82,7 @@ public:
} }
} }
id<CAMetalDrawable> getNextDrawable() const id<CAMetalDrawable> getNextDrawable() const API_AVAILABLE(macosx(10.11))
{ {
if(layer) if(layer)
{ {
...@@ -94,16 +94,16 @@ public: ...@@ -94,16 +94,16 @@ public:
private: private:
NSView* view; NSView* view;
CAMetalLayer* layer; CAMetalLayer* layer API_AVAILABLE(macosx(10.11));
}; };
MacOSSurfaceMVK::MacOSSurfaceMVK(const VkMacOSSurfaceCreateInfoMVK *pCreateInfo, void *mem) : MacOSSurfaceMVK::MacOSSurfaceMVK(const VkMacOSSurfaceCreateInfoMVK *pCreateInfo, void *mem) API_AVAILABLE(macosx(10.11)) :
metalLayer(reinterpret_cast<MetalLayer*>(mem)) metalLayer(reinterpret_cast<MetalLayer*>(mem))
{ {
metalLayer->init(pCreateInfo->pView); metalLayer->init(pCreateInfo->pView);
} }
void MacOSSurfaceMVK::destroySurface(const VkAllocationCallbacks *pAllocator) void MacOSSurfaceMVK::destroySurface(const VkAllocationCallbacks *pAllocator) API_AVAILABLE(macosx(10.11))
{ {
if(metalLayer) if(metalLayer)
{ {
...@@ -113,12 +113,12 @@ void MacOSSurfaceMVK::destroySurface(const VkAllocationCallbacks *pAllocator) ...@@ -113,12 +113,12 @@ void MacOSSurfaceMVK::destroySurface(const VkAllocationCallbacks *pAllocator)
vk::deallocate(metalLayer, pAllocator); vk::deallocate(metalLayer, pAllocator);
} }
size_t MacOSSurfaceMVK::ComputeRequiredAllocationSize(const VkMacOSSurfaceCreateInfoMVK *pCreateInfo) size_t MacOSSurfaceMVK::ComputeRequiredAllocationSize(const VkMacOSSurfaceCreateInfoMVK *pCreateInfo) API_AVAILABLE(macosx(10.11))
{ {
return sizeof(MetalLayer); return sizeof(MetalLayer);
} }
void MacOSSurfaceMVK::getSurfaceCapabilities(VkSurfaceCapabilitiesKHR *pSurfaceCapabilities) const void MacOSSurfaceMVK::getSurfaceCapabilities(VkSurfaceCapabilitiesKHR *pSurfaceCapabilities) const API_AVAILABLE(macosx(10.11))
{ {
SurfaceKHR::getSurfaceCapabilities(pSurfaceCapabilities); SurfaceKHR::getSurfaceCapabilities(pSurfaceCapabilities);
...@@ -128,7 +128,7 @@ void MacOSSurfaceMVK::getSurfaceCapabilities(VkSurfaceCapabilitiesKHR *pSurfaceC ...@@ -128,7 +128,7 @@ void MacOSSurfaceMVK::getSurfaceCapabilities(VkSurfaceCapabilitiesKHR *pSurfaceC
pSurfaceCapabilities->maxImageExtent = extent; pSurfaceCapabilities->maxImageExtent = extent;
} }
VkResult MacOSSurfaceMVK::present(PresentImage* image) VkResult MacOSSurfaceMVK::present(PresentImage* image) API_AVAILABLE(macosx(10.11))
{ {
auto drawable = metalLayer->getNextDrawable(); auto drawable = metalLayer->getNextDrawable();
if(drawable) if(drawable)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment