From 2e9ffd9444f18076987c85c2851d3a2f874fd85f Mon Sep 17 00:00:00 2001 From: Alejandro Saucedo Date: Sat, 3 Oct 2020 15:25:20 +0100 Subject: [PATCH] Updated to make debug layers guarded by macro --- .ccls | 1 + CMakeLists.txt | 7 ++++++- src/Manager.cpp | 8 ++++++++ src/include/kompute/Core.hpp | 21 ++++++++++++--------- src/include/kompute/Manager.hpp | 2 ++ 5 files changed, 29 insertions(+), 10 deletions(-) diff --git a/.ccls b/.ccls index 7ce6ab1c0..43ab67d8d 100644 --- a/.ccls +++ b/.ccls @@ -16,5 +16,6 @@ -I/c/Users/axsau/Programming/lib/vcpkg/installed/x64-linux/include/ -I./src/include/ -I./single_include/ +-I./vulkan_ndk_patch_include/ -I./test/compiled_shaders_include/ diff --git a/CMakeLists.txt b/CMakeLists.txt index d329a8281..c374887ca 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,6 +14,8 @@ option(KOMPUTE_OPT_BUILD_SINGLE_HEADER "Enable if you want to build the single h option(KOMPUTE_OPT_INSTALL "Enable if you want to enable installation" 1) option(KOMPUTE_OPT_ENABLE_SPDLOG "Extra compile flags for Kompute, see docs for full list" 0) option(KOMPUTE_OPT_ANDOID_BUILD "Enable android compilation flags required" 0) +# TODO: Add on docs +option(KOMPUTE_OPT_DISABLE_VK_DEBUG_LAYERS "Explicitly disable debug layers even on debug" 0) set(KOMPUTE_EXTRA_CXX_FLAGS "" CACHE STRING "Extra compile flags for Kompute, see docs for full list") @@ -25,8 +27,11 @@ if(KOMPUTE_OPT_ANDOID_BUILD) set(KOMPUTE_EXTRA_CXX_FLAGS "${KOMPUTE_EXTRA_CXX_FLAGS} -DVK_USE_PLATFORM_ANDROID_KHR") endif() +if(KOMPUTE_OPT_DISABLE_VK_DEBUG_LAYERS) + set(KOMPUTE_EXTRA_CXX_FLAGS "${KOMPUTE_EXTRA_CXX_FLAGS} -DKOMPUTE_DISABLE_VK_DEBUG_LAYERS=1") +endif() -set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG=1 ${KOMPUTE_EXTRA_CXX_FLAGS}") +set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG=1 ${KOMPUTE_EXTRA_CXX_FLAGS} -DUSE_DEBUG_EXTENTIONS") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DRELEASE=1 ${KOMPUTE_EXTRA_CXX_FLAGS}") # Allow scripts to call main kompute Makefile diff --git a/src/Manager.cpp b/src/Manager.cpp index 40c81b2de..6a7fd3345 100644 --- a/src/Manager.cpp +++ b/src/Manager.cpp @@ -7,6 +7,7 @@ namespace kp { #if DEBUG +#ifndef KOMPUTE_DISABLE_VK_DEBUG_LAYERS static VKAPI_ATTR VkBool32 VKAPI_CALL debugMessageCallback(VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT objectType, @@ -21,6 +22,7 @@ debugMessageCallback(VkDebugReportFlagsEXT flags, return VK_FALSE; } #endif +#endif Manager::Manager() : Manager(0) @@ -73,11 +75,13 @@ Manager::~Manager() } #if DEBUG +#ifndef KOMPUTE_DISABLE_VK_DEBUG_LAYERS if (this->mDebugReportCallback) { this->mInstance->destroyDebugReportCallbackEXT( this->mDebugReportCallback, nullptr, this->mDebugDispatcher); SPDLOG_DEBUG("Kompute Manager Destroyed Debug Report Callback"); } +#endif #endif if (this->mFreeInstance) { @@ -133,6 +137,7 @@ Manager::createInstance() } #if DEBUG +#ifndef KOMPUTE_DISABLE_VK_DEBUG_LAYERS SPDLOG_DEBUG("Kompute Manager adding debug validation layers"); // We'll identify the layers that are supported std::vector validLayerNames; @@ -160,6 +165,7 @@ Manager::createInstance() (uint32_t)validLayerNames.size(); computeInstanceCreateInfo.ppEnabledLayerNames = validLayerNames.data(); } +#endif #endif this->mInstance = std::make_shared(); @@ -168,6 +174,7 @@ Manager::createInstance() SPDLOG_DEBUG("Kompute Manager Instance Created"); #if DEBUG +#ifndef KOMPUTE_DISABLE_VK_DEBUG_LAYERS SPDLOG_DEBUG("Kompute Manager adding debug callbacks"); if (validLayerNames.size() > 0) { vk::DebugReportFlagsEXT debugFlags = @@ -184,6 +191,7 @@ Manager::createInstance() debugCreateInfo, nullptr, this->mDebugDispatcher); } #endif +#endif } void diff --git a/src/include/kompute/Core.hpp b/src/include/kompute/Core.hpp index 8b4d9f120..47e98b5a6 100644 --- a/src/include/kompute/Core.hpp +++ b/src/include/kompute/Core.hpp @@ -1,20 +1,23 @@ #pragma once -#if defined(VK_USE_PLATFORM_ANDROID_KHR) -#include -#include -#endif - //#define VK_NO_PROTOTYPES 1 //#undef VK_NO_PROTOTYPES -#undef DEBUG -#ifndef RELEASE -#define RELEASE 1 -#endif +//#undef DEBUG +//#ifndef RELEASE +//#define RELEASE 1 +//#endif //#define USE_DEBUG_EXTENTIONS + +#ifdef VK_USE_PLATFORM_ANDROID_KHR +#include +#include #include +// VK_NO_PROTOTYPES required before vulkan import but after wrapper.hpp #undef VK_NO_PROTOTYPES +#define DVULKAN_HPP_DISPATCH_LOADER_DYNAMIC 1 +#endif + #include // SPDLOG_ACTIVE_LEVEL must be defined before spdlog.h import diff --git a/src/include/kompute/Manager.hpp b/src/include/kompute/Manager.hpp index e3e522791..e2c7832fd 100644 --- a/src/include/kompute/Manager.hpp +++ b/src/include/kompute/Manager.hpp @@ -154,8 +154,10 @@ class Manager mManagedSequences; #if DEBUG +#ifndef KOMPUTE_DISABLE_VK_DEBUG_LAYERS vk::DebugReportCallbackEXT mDebugReportCallback; vk::DispatchLoaderDynamic mDebugDispatcher; +#endif #endif // Create functions