Vulkan surface now initializing on MacOS
Updated Volk library
This commit is contained in:
@@ -839,14 +839,13 @@ KrResult KRContext::createWindowSurface(const KrCreateWindowSurfaceInfo* createW
|
||||
if (!m_deviceManager->haveDevice()) {
|
||||
return KR_ERROR_NO_DEVICE;
|
||||
}
|
||||
#if defined(WIN32) || defined(__APPLE__)
|
||||
|
||||
const std::lock_guard<std::mutex> surfaceLock(KRContext::g_SurfaceInfoMutex);
|
||||
const std::lock_guard<std::mutex> deviceLock(KRContext::g_DeviceInfoMutex);
|
||||
|
||||
#ifdef WIN32
|
||||
HWND hWnd = static_cast<HWND>(createWindowSurfaceInfo->hWnd);
|
||||
KrSurfaceHandle surfaceHandle = 0;
|
||||
KrResult result = m_surfaceManager->create(hWnd, surfaceHandle);
|
||||
KrResult result = m_surfaceManager->create(createWindowSurfaceInfo->platformHandle, surfaceHandle);
|
||||
if (result != KR_SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
@@ -891,4 +890,4 @@ KrResult KRContext::getMappedResource(KrResourceMapIndex resourceHandle, KRResou
|
||||
return KR_ERROR_NOT_MAPPED;
|
||||
}
|
||||
return KR_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,20 +35,10 @@
|
||||
|
||||
using namespace hydra;
|
||||
|
||||
#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
|
||||
KRSurface::KRSurface(KRContext& context, KrSurfaceHandle handle, void* platformHandle)
|
||||
: KRContextObject(context)
|
||||
, m_handle(handle)
|
||||
#ifdef WIN32
|
||||
, m_hWnd(hWnd)
|
||||
#elif defined(__APPLE__)
|
||||
, m_layer(layer)
|
||||
#endif
|
||||
, m_platformHandle(platformHandle)
|
||||
, m_deviceHandle(0)
|
||||
, m_surface(VK_NULL_HANDLE)
|
||||
, m_imageAvailableSemaphores{VK_NULL_HANDLE}
|
||||
@@ -73,14 +63,17 @@ KrResult KRSurface::initialize()
|
||||
VkWin32SurfaceCreateInfoKHR createInfo{};
|
||||
createInfo.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR;
|
||||
createInfo.hinstance = GetModuleHandle(nullptr);
|
||||
createInfo.hwnd = m_hWnd;
|
||||
createInfo.hwnd = static_cast<HWND>(m_platformHandle);
|
||||
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
|
||||
VkMetalSurfaceCreateInfoEXT createInfo{};
|
||||
createInfo.sType = VK_STRUCTURE_TYPE_METAL_SURFACE_CREATE_INFO_EXT;
|
||||
createInfo.pLayer = static_cast<CAMetalLayer*>(m_platformHandle);
|
||||
if (vkCreateMetalSurfaceEXT(m_pContext->getDeviceManager()->getVulkanInstance(), &createInfo, nullptr, &m_surface) != VK_SUCCESS) {
|
||||
return KR_ERROR_VULKAN;
|
||||
}
|
||||
#else
|
||||
#error Unsupported
|
||||
#endif
|
||||
|
||||
@@ -41,13 +41,7 @@ class KRSwapchain;
|
||||
class KRSurface : public KRContextObject
|
||||
{
|
||||
public:
|
||||
#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
|
||||
KRSurface(KRContext& context, KrSurfaceHandle handle, void* platformHandle);
|
||||
~KRSurface();
|
||||
void destroy();
|
||||
uint32_t getWidth() const;
|
||||
@@ -69,11 +63,7 @@ public:
|
||||
void endFrame();
|
||||
KrSurfaceHandle m_handle;
|
||||
|
||||
#ifdef WIN32
|
||||
HWND m_hWnd;
|
||||
#elif defined(__APPLE__)
|
||||
CAMetalLayer* m_layer;
|
||||
#endif
|
||||
void* m_platformHandle;
|
||||
KrDeviceHandle m_deviceHandle;
|
||||
VkSurfaceKHR m_surface;
|
||||
|
||||
|
||||
@@ -48,12 +48,11 @@ void KRSurfaceManager::destroySurfaces()
|
||||
m_surfaces.clear();
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
KrResult KRSurfaceManager::create(HWND hWnd, KrSurfaceHandle& surfaceHandle)
|
||||
KrResult KRSurfaceManager::create(void* platformHandle, KrSurfaceHandle& surfaceHandle)
|
||||
{
|
||||
surfaceHandle = 0;
|
||||
|
||||
std::unique_ptr<KRSurface> surface = std::make_unique<KRSurface>(*m_pContext, m_topSurfaceHandle, hWnd);
|
||||
std::unique_ptr<KRSurface> surface = std::make_unique<KRSurface>(*m_pContext, m_topSurfaceHandle, platformHandle);
|
||||
|
||||
KrResult initialize_result = surface->initialize();
|
||||
if (initialize_result != KR_SUCCESS) {
|
||||
@@ -66,8 +65,6 @@ KrResult KRSurfaceManager::create(HWND hWnd, KrSurfaceHandle& surfaceHandle)
|
||||
return KR_SUCCESS;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
KrResult KRSurfaceManager::destroy(KrSurfaceHandle& surfaceHandle)
|
||||
{
|
||||
auto itr = m_surfaces.find(surfaceHandle);
|
||||
|
||||
@@ -41,9 +41,7 @@ class KRSurfaceManager : KRContextObject
|
||||
public:
|
||||
KRSurfaceManager(KRContext& context);
|
||||
~KRSurfaceManager();
|
||||
#ifdef WIN32
|
||||
KrResult create(HWND hWnd, KrSurfaceHandle& surfaceHandle);
|
||||
#endif
|
||||
KrResult create(void* platformHandle, KrSurfaceHandle& surfaceHandle);
|
||||
KRSurface& get(KrSurfaceHandle surfaceHandle);
|
||||
KrResult destroy(KrSurfaceHandle& surfaceHandle);
|
||||
unordered_map<KrSurfaceHandle, std::unique_ptr<KRSurface>>& getSurfaces();
|
||||
|
||||
@@ -132,11 +132,7 @@ typedef struct
|
||||
{
|
||||
KrStructureType sType;
|
||||
KrSurfaceMapIndex surfaceHandle;
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
void* hWnd; // Can static cast to HWND
|
||||
#elif defined(__APPLE__)
|
||||
void* view; // Can static cast to NSView
|
||||
#endif
|
||||
void* platformHandle; // Can static cast to HWND on Windows and CAMetalLayer* on macOS
|
||||
} KrCreateWindowSurfaceInfo;
|
||||
|
||||
typedef struct
|
||||
|
||||
Reference in New Issue
Block a user