From c3a82efcdd6423490da60f96f1cd45f5deb7f3f2 Mon Sep 17 00:00:00 2001 From: Squareys Date: Fri, 22 Apr 2016 10:59:06 +0200 Subject: [PATCH] fixup! Vk: Add Context Signed-off-by: Squareys --- src/Magnum/Vk/Context.cpp | 53 +++++++++++++++++++++++++++++++++++---- src/Magnum/Vk/Context.h | 36 +++++++++++++++++++++++--- 2 files changed, 81 insertions(+), 8 deletions(-) diff --git a/src/Magnum/Vk/Context.cpp b/src/Magnum/Vk/Context.cpp index 474ca0f41..6a63e3b6e 100644 --- a/src/Magnum/Vk/Context.cpp +++ b/src/Magnum/Vk/Context.cpp @@ -123,14 +123,14 @@ bool Context::tryCreate() { instanceCreateInfo.enabledLayerCount = 1; instanceCreateInfo.ppEnabledLayerNames = validationLayerNames; } - if (enabledExtensions.size() > 0) { + if (!enabledExtensions.empty()) { instanceCreateInfo.enabledExtensionCount = enabledExtensions.size(); instanceCreateInfo.ppEnabledExtensionNames = enabledExtensions.data(); } VkResult ret = vkCreateInstance(&instanceCreateInfo, nullptr, &_instance); if(ret != VK_SUCCESS) { - Error() << "Vulkan Instance creation failed with error" << ret; + Error() << "Vulkan instance creation failed with error" << ret; return false; } @@ -138,9 +138,9 @@ bool Context::tryCreate() { /* setup debugging */ if (_flags >= Flag::EnableValidation) { - CreateDebugReportCallback = (PFN_vkCreateDebugReportCallbackEXT)vkGetInstanceProcAddr(_instance, "vkCreateDebugReportCallbackEXT"); - DestroyDebugReportCallback = (PFN_vkDestroyDebugReportCallbackEXT)vkGetInstanceProcAddr(_instance, "vkDestroyDebugReportCallbackEXT"); - dbgBreakCallback = (PFN_vkDebugReportMessageEXT)vkGetInstanceProcAddr(_instance, "vkDebugReportMessageEXT"); + CreateDebugReportCallback = PFN_vkCreateDebugReportCallbackEXT(vkGetInstanceProcAddr(_instance, "vkCreateDebugReportCallbackEXT")); + DestroyDebugReportCallback = PFN_vkDestroyDebugReportCallbackEXT(vkGetInstanceProcAddr(_instance, "vkDestroyDebugReportCallbackEXT")); + dbgBreakCallback = PFN_vkDebugReportMessageEXT(vkGetInstanceProcAddr(_instance, "vkDebugReportMessageEXT")); VkDebugReportCallbackCreateInfoEXT dbgCreateInfo = {}; dbgCreateInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT; @@ -161,4 +161,47 @@ bool Context::isVersionSupported(Version) const { return true; } +Debug& operator<<(Debug& debug, Result value) { + switch(value) { + #define _c(value) case Result::value: return debug << "Vk::Result::" #value; + _c(Success) + _c(NotReady) + _c(Timeout) + _c(EventSet) + _c(EventReset) + _c(Incomplete) + _c(ErrorOutOfHostMemory) + _c(ErrorOutOfDevieMemory) + _c(ErrorInitializationFailed) + _c(ErrorDeviceLost) + _c(ErrorMemoryMapFailed) + _c(ErrorLayerNotPresent) + _c(ErrorExtensionNotPresent) + _c(ErrorFeatureNotPresent) + _c(ErrorIncompatibleDriver) + _c(ErrorTooManyObjects) + _c(ErrorFormatNotSupported) + _c(ErrorSurfaceLost) + _c(ErrorNativeWindowInUse) + _c(Suboptimal) + _c(ErrorOutOfDate) + _c(ErrorIncompatibleDisplay) + _c(ErrorValidationFailed) + _c(ErrorInvalidShader) + #undef _c + } + + return debug << "Vk::Result::(invalid)"; +} + +Debug& operator<<(Debug& debug, Context::Flag value) { + switch(value) { + #define _c(value) case Context::Flag::value: return debug << "Context::Flag::" #value; + _c(EnableValidation) + #undef _c + } + + return debug << "Context::Flag::(invalid)"; +} + }} diff --git a/src/Magnum/Vk/Context.h b/src/Magnum/Vk/Context.h index 53899431f..429054371 100644 --- a/src/Magnum/Vk/Context.h +++ b/src/Magnum/Vk/Context.h @@ -46,8 +46,35 @@ namespace Magnum { namespace Vk { enum class Version: UnsignedInt { - None = 0, /**< No version */ - Vulkan_1_0 = VK_API_VERSION, /**< Vulkan 1.0 */ + None, /**< No version */ + Vulkan_1_0 = VK_API_VERSION_1_0, /**< Vulkan 1.0 */ +}; + +enum class Result: Int { + Success = VK_SUCCESS, /**< Success */ + NotReady = VK_NOT_READY, /**< Not ready */ + Timeout = VK_TIMEOUT, /**< Timeout */ + EventSet = VK_EVENT_SET, /**< Event set */ + EventReset = VK_EVENT_RESET, /**< Event reset */ + Incomplete = VK_INCOMPLETE, /**< Incomplete */ + ErrorOutOfHostMemory = VK_ERROR_OUT_OF_HOST_MEMORY, /**< Out of host memory */ + ErrorOutOfDevieMemory = VK_ERROR_OUT_OF_DEVICE_MEMORY, /**< Out of device memory */ + ErrorInitializationFailed = VK_ERROR_INITIALIZATION_FAILED, /**< Initialization failed */ + ErrorDeviceLost = VK_ERROR_DEVICE_LOST, /**< Device lost */ + ErrorMemoryMapFailed = VK_ERROR_MEMORY_MAP_FAILED, /**< Memory map failed */ + ErrorLayerNotPresent = VK_ERROR_LAYER_NOT_PRESENT, /**< Layer not present */ + ErrorExtensionNotPresent = VK_ERROR_EXTENSION_NOT_PRESENT, /**< Extension not present */ + ErrorFeatureNotPresent = VK_ERROR_FEATURE_NOT_PRESENT, /**< Feature not present */ + ErrorIncompatibleDriver = VK_ERROR_INCOMPATIBLE_DRIVER, /**< Incompatible driver */ + ErrorTooManyObjects = VK_ERROR_TOO_MANY_OBJECTS, /**< Too many objects */ + ErrorFormatNotSupported = VK_ERROR_FORMAT_NOT_SUPPORTED, /**< Format not supported */ + ErrorSurfaceLost = VK_ERROR_SURFACE_LOST_KHR, /**< Surface lost */ + ErrorNativeWindowInUse = VK_ERROR_NATIVE_WINDOW_IN_USE_KHR, /**< Native window in use */ + Suboptimal = VK_SUBOPTIMAL_KHR, /**< Suboptimal */ + ErrorOutOfDate = VK_ERROR_OUT_OF_DATE_KHR, /**< Out of date */ + ErrorIncompatibleDisplay = VK_ERROR_INCOMPATIBLE_DISPLAY_KHR, /**< Incompatible display */ + ErrorValidationFailed = VK_ERROR_VALIDATION_FAILED_EXT, /**< Validation failed */ + ErrorInvalidShader = VK_ERROR_INVALID_SHADER_NV /**< Invalid shader */ }; /** @@ -83,7 +110,7 @@ class MAGNUM_VK_EXPORT Context { * @ref Platform::Sdl2Application::Configuration::setFlags() "Platform::*Application::Configuration::setFlags()" */ enum class Flag: Int { - EnableValidation = 1, /**< Enable validation layer */ + EnableValidation, /**< Enable validation layer */ }; /** @@ -156,6 +183,9 @@ class MAGNUM_VK_EXPORT Context { VkInstance _instance; }; +MAGNUM_VK_EXPORT Debug& operator<<(Debug& debug, Result value); +MAGNUM_VK_EXPORT Debug& operator<<(Debug& debug, Context::Flag value); + }} #endif