diff --git a/MobileGL/Includes.h b/MobileGL/Includes.h index 929440e1..77fdb723 100644 --- a/MobileGL/Includes.h +++ b/MobileGL/Includes.h @@ -91,12 +91,19 @@ #endif #ifdef __ANDROID__ -#define VK_USE_PLATFORM_ANDROID_KHR #include #include #include #include #endif + +#ifdef __ANDROID__ +#define VK_USE_PLATFORM_ANDROID_KHR +#elif _WIN32 +#define VK_USE_PLATFORM_WIN32_KHR +#else +#warning "VK_USE_PLATFORM_*_KHR not defined for this platform!" +#endif #include #ifdef TRACY_ENABLE diff --git a/MobileGL/MG_Backend/DirectVulkan/Renderer/VulkanContext.cpp b/MobileGL/MG_Backend/DirectVulkan/Renderer/VulkanContext.cpp index a80bc516..586c780a 100644 --- a/MobileGL/MG_Backend/DirectVulkan/Renderer/VulkanContext.cpp +++ b/MobileGL/MG_Backend/DirectVulkan/Renderer/VulkanContext.cpp @@ -51,6 +51,10 @@ namespace MobileGL::MG_Backend::DirectVulkan { const char* exts[] = {VK_KHR_SURFACE_EXTENSION_NAME, #if __ANDROID__ VK_KHR_ANDROID_SURFACE_EXTENSION_NAME +#elif _WIN32 + VK_KHR_WIN32_SURFACE_EXTENSION_NAME +#else +#error "VulkanContext::CreateInstance: VK_KHR_*_surface extension not defined on this platform" #endif }; // TODO: support more platforms @@ -63,16 +67,23 @@ namespace MobileGL::MG_Backend::DirectVulkan { } void VulkanContext::CreateSurface(NativeWindowType window) { -#if __ANDROID__ if (!Instance) throw RuntimeError("Instance not created"); - +#if defined VK_USE_PLATFORM_ANDROID_KHR auto* nativeWindow = static_cast(window); if (!nativeWindow) throw RuntimeError("ANativeWindowType is null"); VkAndroidSurfaceCreateInfoKHR sci{VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR}; sci.window = nativeWindow; VK_VERIFY(vkCreateAndroidSurfaceKHR(Instance, &sci, nullptr, &Surface), "vkCreateAndroidSurfaceKHR failed"); +#elif defined VK_USE_PLATFORM_WIN32_KHR + auto hwnd = static_cast(window); + MOBILEGL_ASSERT(hwnd, "HWND is null"); + + VkWin32SurfaceCreateInfoKHR sci{VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR}; + sci.hwnd = hwnd; + VK_VERIFY(vkCreateWin32SurfaceKHR(Instance, &sci, nullptr, &Surface), "vkCreateWin32SurfaceKHR failed"); #else + //#warning "VulkanRenderer::Initialize called on a platform which is not supported yet" MGLOG_W("VulkanRenderer::Initialize called on a platform which is not supported yet"); // TODO: support more // platforms #endif diff --git a/MobileGL/MG_Backend/DirectVulkan/Renderer/VulkanContext.h b/MobileGL/MG_Backend/DirectVulkan/Renderer/VulkanContext.h index fc9283d2..b34f1ee6 100644 --- a/MobileGL/MG_Backend/DirectVulkan/Renderer/VulkanContext.h +++ b/MobileGL/MG_Backend/DirectVulkan/Renderer/VulkanContext.h @@ -12,9 +12,7 @@ #define VK_VERIFY(expr, ...) \ do { \ VkResult _vk_verify_result = (expr); \ - if (_vk_verify_result != VK_SUCCESS) { \ - MGLOG_E("Vulkan error %d at %s:%d" __VA_OPT__(" - ") __VA_ARGS__, _vk_verify_result, __FILE__, __LINE__); \ - } \ + MOBILEGL_ASSERT(_vk_verify_result == VK_SUCCESS, "Vulkan error %d at %s:%d" __VA_OPT__(" - ") __VA_ARGS__, _vk_verify_result, __FILE__, __LINE__); \ } while (0) namespace MobileGL::MG_Backend::DirectVulkan { diff --git a/MobileGL/MG_Backend/DirectVulkan/Renderer/VulkanRenderer.cpp b/MobileGL/MG_Backend/DirectVulkan/Renderer/VulkanRenderer.cpp index 31c5a9c7..6649aa61 100644 --- a/MobileGL/MG_Backend/DirectVulkan/Renderer/VulkanRenderer.cpp +++ b/MobileGL/MG_Backend/DirectVulkan/Renderer/VulkanRenderer.cpp @@ -41,6 +41,8 @@ namespace MobileGL::MG_Backend::DirectVulkan { void VulkanRenderer::Shutdown() { if (!Ctx) return; + if (Ctx->GetDevice() == VK_NULL_HANDLE) return; + vkDeviceWaitIdle(Ctx->GetDevice()); DestroyFrameResources();