Enable VK_EXT_metal_surface for MacOS

Remove unused ObjC files
Fix MacOS build
This commit is contained in:
2023-11-23 21:30:20 -08:00
parent 03f76ff8b8
commit 67d8e6773a
7 changed files with 23 additions and 80 deletions

View File

@@ -31,15 +31,6 @@ add_sources(KRSurface.cpp)
add_sources(KRSurfaceManager.cpp)
add_sources(KRStreamerThread.cpp)
add_sources(KRSwapchain.cpp)
IF(APPLE)
add_sources(KREngine.mm)
IF(IOS)
add_sources(KRContext_ios.mm)
ELSE()
add_sources(KRContext_osx.mm)
ENDIF()
ENDIF (APPLE)
add_sources(KRContextObject.cpp)
add_sources(KRDirectionalLight.cpp)
IF(APPLE)

View File

@@ -1,34 +0,0 @@
//
// KRContext_ios.mm
// Kraken Engine
//
// Copyright 2023 Kearwood Gilbert. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// The views and conclusions contained in the software and documentation are those of the
// authors and should not be interpreted as representing official policies, either expressed
// or implied, of Kearwood Gilbert.
//
#include "KREngine-common.h"
#include "KRContext.h"

View File

@@ -1,35 +0,0 @@
//
// KRContext_osx.mm
// Kraken Engine
//
// Copyright 2023 Kearwood Gilbert. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// The views and conclusions contained in the software and documentation are those of the
// authors and should not be interpreted as representing official policies, either expressed
// or implied, of Kearwood Gilbert.
//
#include "KREngine-common.h"
#include <AppKit/AppKit.h>
#include "KRContext.h"

View File

@@ -100,6 +100,9 @@ KRDeviceManager::initialize()
#endif
#ifdef WIN32
"VK_KHR_win32_surface",
#endif
#ifdef __APPLE__
"VK_EXT_metal_surface",
#endif
};

View File

@@ -62,6 +62,8 @@ using namespace kraken;
#include "../3rdparty/glslang/glslang/Public/ShaderLang.h"
#include "../3rdparty/glslang/SPIRV/GlslangToSpv.h"
#if defined(__APPLE__)
#define VK_USE_PLATFORM_METAL_EXT
#define stricmp strcasecmp
#include <sys/mman.h>
#include <unistd.h>

View File

@@ -35,8 +35,10 @@
using namespace hydra;
#ifdef WIN32
#if defined(WIN32)
KRSurface::KRSurface(KRContext& context, KrSurfaceHandle handle, HWND hWnd)
#elif defined(__APPLE__)
KRSurface::KRSurface(KRContext& context, KrSurfaceHandle handle, CAMetalLayer* layer)
#else
KRSurface::KRSurface(KRContext& context, KrSurfaceHandle handle)
#endif
@@ -44,6 +46,8 @@ KRSurface::KRSurface(KRContext& context, KrSurfaceHandle handle)
, m_handle(handle)
#ifdef WIN32
, m_hWnd(hWnd)
#elif defined(__APPLE__)
, m_layer(layer)
#endif
, m_deviceHandle(0)
, m_surface(VK_NULL_HANDLE)
@@ -65,6 +69,7 @@ KRSurface::~KRSurface()
KrResult KRSurface::initialize()
{
#if defined(WIN32)
VkWin32SurfaceCreateInfoKHR createInfo{};
createInfo.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR;
createInfo.hinstance = GetModuleHandle(nullptr);
@@ -72,6 +77,13 @@ KrResult KRSurface::initialize()
if (vkCreateWin32SurfaceKHR(m_pContext->getDeviceManager()->getVulkanInstance(), &createInfo, nullptr, &m_surface) != VK_SUCCESS) {
return KR_ERROR_VULKAN;
}
#elif defined(__APPLE__)
VkMetalSurfaceCreateInfoEXT createInfo{};
createInfo.sType = VK_STRUCTURE_TYPE_METAL_SURFACE_CREATE_INFO_EXT;
createInfo.pLayer = m_layer; // CAMetalLayer
#else
#error Unsupported
#endif
m_deviceHandle = m_pContext->getDeviceManager()->getBestDeviceForSurface(m_surface);
if (m_deviceHandle == 0) {

View File

@@ -41,8 +41,10 @@ class KRSwapchain;
class KRSurface : public KRContextObject
{
public:
#ifdef WIN32
#if defined(WIN32)
KRSurface(KRContext& context, KrSurfaceHandle handle, HWND hWnd);
#elif defined(__APPLE__)
KRSurface(KRContext& context, KrSurfaceHandle handle, CAMetalLayer* layer);
#else
KRSurface(KRContext& context, KrSurfaceHandle handle);
#endif
@@ -69,6 +71,8 @@ public:
#ifdef WIN32
HWND m_hWnd;
#elif defined(__APPLE__)
CAMetalLayer* m_layer;
#endif
KrDeviceHandle m_deviceHandle;
VkSurfaceKHR m_surface;