From e42e4d2f69cfa56da34e8217b7698a00c6ce57df Mon Sep 17 00:00:00 2001 From: Carsten Rudolph <18394207+crud89@users.noreply.github.com> Date: Wed, 10 Jul 2024 12:06:44 +0200 Subject: [PATCH] Add option to explicitly toggle debug marker support. --- README.md | 1 + src/Backends/DirectX12/CMakeLists.txt | 13 ++++--------- .../DirectX12/include/litefx/backends/dx12.hpp | 4 ++-- src/Backends/DirectX12/src/queue.cpp | 4 ++-- .../Vulkan/include/litefx/backends/vulkan.hpp | 4 ++-- src/Backends/Vulkan/src/backend.cpp | 4 ++-- src/Backends/Vulkan/src/queue.cpp | 4 ++-- src/CMakePresets.json | 15 +++++++++------ src/Core/config.tmpl | 2 ++ src/cmake/Options.cmake | 9 ++++++++- 10 files changed, 34 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 6376d1fe..725ed01d 100644 --- a/README.md +++ b/README.md @@ -134,6 +134,7 @@ Within the cache variables, you can override the build options, LiteFX exports. - `LITEFX_BUILD_VULKAN_BACKEND` (default: `ON`): builds the Vulkan 🌋 backend (requires [LunarG Vulkan SDK](https://vulkan.lunarg.com/) 1.3.204.1 or later to be installed on your system). - `LITEFX_BUILD_DX12_BACKEND` (default: `ON`): builds the DirectX 12 ❎ backend. - `LITEFX_BUILD_DEFINE_BUILDERS` (default: `ON`): enables the [builder architecture](https://github.com/crud89/LiteFX/wiki/Builders) for backends. +- `LITEFX_BUILD_SUPPORT_DEBUG_MARKERS` (default: `OFF`): implements support for setting debug regions on device queues. - `LITEFX_BUILD_WITH_GLM` (default: `ON`): adds [glm](https://glm.g-truc.net/0.9.9/index.html) converters to math types. † - `LITEFX_BUILD_WITH_DIRECTX_MATH` (default: `ON`): adds [DirectX Math](https://github.com/microsoft/DirectXMath) converters to math types. † - `LITEFX_BUILD_HLSL_SHADER_MODEL` (default: `6_5`): specifies the default HLSL shader model. diff --git a/src/Backends/DirectX12/CMakeLists.txt b/src/Backends/DirectX12/CMakeLists.txt index b7151317..10b9c9ae 100644 --- a/src/Backends/DirectX12/CMakeLists.txt +++ b/src/Backends/DirectX12/CMakeLists.txt @@ -92,15 +92,10 @@ TARGET_LINK_LIBRARIES(${PROJECT_NAME} ) # Link PIX runtime, if available. -IF("pix-support" IN_LIST VCPKG_MANIFEST_FEATURES) - FIND_PACKAGE(WinPixEventRuntime CONFIG) - - IF(WinPixEventRuntime_FOUND) - TARGET_LINK_LIBRARIES(${PROJECT_NAME} PRIVATE Microsoft::WinPixEventRuntime) - ELSE() - MESSAGE(WARNING "PIX runtime was not found and will not be linked.") - ENDIF(WinPixEventRuntime_FOUND) -ENDIF("pix-support" IN_LIST VCPKG_MANIFEST_FEATURES) +IF(LITEFX_BUILD_WITH_PIX_RUNTIME) + FIND_PACKAGE(WinPixEventRuntime CONFIG REQUIRED) + TARGET_LINK_LIBRARIES(${PROJECT_NAME} PRIVATE Microsoft::WinPixEventRuntime) +ENDIF(LITEFX_BUILD_WITH_PIX_RUNTIME) # Add shader modules. ADD_SHADER_LIBRARY(${PROJECT_NAME}.Shaders SOURCE_FILE "shader_resources.hpp" NAMESPACE "LiteFX::Backends::DirectX12::Shaders") diff --git a/src/Backends/DirectX12/include/litefx/backends/dx12.hpp b/src/Backends/DirectX12/include/litefx/backends/dx12.hpp index 366ab4e7..ce9c5085 100644 --- a/src/Backends/DirectX12/include/litefx/backends/dx12.hpp +++ b/src/Backends/DirectX12/include/litefx/backends/dx12.hpp @@ -1254,7 +1254,7 @@ namespace LiteFX::Rendering::Backends { /// QueueType type() const noexcept override; -#if !defined(NDEBUG) && defined(_WIN64) +#if defined(LITEFX_BUILD_SUPPORT_DEBUG_MARKERS) && defined(LITEFX_BUILD_WITH_PIX_RUNTIME) public: /// void beginDebugRegion(const String& label, const Vectors::ByteVector3& color = { 128_b, 128_b, 128_b }) const noexcept override; @@ -1264,7 +1264,7 @@ namespace LiteFX::Rendering::Backends { /// void setDebugMarker(const String& label, const Vectors::ByteVector3& color = { 128_b, 128_b, 128_b }) const noexcept override; -#endif // !defined(NDEBUG) && defined(_WIN64) +#endif // defined(LITEFX_BUILD_SUPPORT_DEBUG_MARKERS) && defined(LITEFX_BUILD_WITH_PIX_RUNTIME) public: /// diff --git a/src/Backends/DirectX12/src/queue.cpp b/src/Backends/DirectX12/src/queue.cpp index 1e0e326c..0dc4c16b 100644 --- a/src/Backends/DirectX12/src/queue.cpp +++ b/src/Backends/DirectX12/src/queue.cpp @@ -111,7 +111,7 @@ QueueType DirectX12Queue::type() const noexcept return m_impl->m_type; } -#if !defined(NDEBUG) && defined(_WIN64) +#if defined(LITEFX_BUILD_SUPPORT_DEBUG_MARKERS) && defined(LITEFX_BUILD_WITH_PIX_RUNTIME) void DirectX12Queue::beginDebugRegion(const String& label, const Vectors::ByteVector3& color) const noexcept { ::PIXBeginEvent(this->handle().Get(), PIX_COLOR(color.x(), color.y(), color.z()), label.c_str()); @@ -126,7 +126,7 @@ void DirectX12Queue::setDebugMarker(const String& label, const Vectors::ByteVect { ::PIXSetMarker(this->handle().Get(), PIX_COLOR(color.x(), color.y(), color.z()), label.c_str()); } -#endif // !defined(NDEBUG) && defined(_WIN64) +#endif // defined(LITEFX_BUILD_SUPPORT_DEBUG_MARKERS) && defined(LITEFX_BUILD_WITH_PIX_RUNTIME) QueuePriority DirectX12Queue::priority() const noexcept { diff --git a/src/Backends/Vulkan/include/litefx/backends/vulkan.hpp b/src/Backends/Vulkan/include/litefx/backends/vulkan.hpp index 30c7109f..d5a3f84e 100644 --- a/src/Backends/Vulkan/include/litefx/backends/vulkan.hpp +++ b/src/Backends/Vulkan/include/litefx/backends/vulkan.hpp @@ -1263,7 +1263,7 @@ namespace LiteFX::Rendering::Backends { /// QueueType type() const noexcept override; -#ifndef NDEBUG +#ifdef LITEFX_BUILD_SUPPORT_DEBUG_MARKERS public: /// void beginDebugRegion(const String& label, const Vectors::ByteVector3& color = { 128_b, 128_b, 128_b }) const noexcept override; @@ -1273,7 +1273,7 @@ namespace LiteFX::Rendering::Backends { /// void setDebugMarker(const String& label, const Vectors::ByteVector3& color = { 128_b, 128_b, 128_b }) const noexcept override; -#endif +#endif // LITEFX_BUILD_SUPPORT_DEBUG_MARKERS public: /// diff --git a/src/Backends/Vulkan/src/backend.cpp b/src/Backends/Vulkan/src/backend.cpp index e919f3b6..90c6c317 100644 --- a/src/Backends/Vulkan/src/backend.cpp +++ b/src/Backends/Vulkan/src/backend.cpp @@ -43,10 +43,10 @@ class VulkanBackend::VulkanBackendImpl : public Implement { m_extensions.push_back(VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME); #endif // LITEFX_BUILD_DIRECTX_12_BACKEND -#ifndef NDEBUG +#if defined(LITEFX_BUILD_SUPPORT_DEBUG_MARKERS) || !defined(NDEBUG) // Debugging extension should be guaranteed to be available. m_extensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); -#endif // NDEBUG +#endif // defined(LITEFX_BUILD_SUPPORT_DEBUG_MARKERS) || !defined(NDEBUG) } #ifndef NDEBUG diff --git a/src/Backends/Vulkan/src/queue.cpp b/src/Backends/Vulkan/src/queue.cpp index c9dc4e51..438c1d83 100644 --- a/src/Backends/Vulkan/src/queue.cpp +++ b/src/Backends/Vulkan/src/queue.cpp @@ -123,7 +123,7 @@ QueueType VulkanQueue::type() const noexcept return m_impl->m_type; } -#ifndef NDEBUG +#ifdef LITEFX_BUILD_SUPPORT_DEBUG_MARKERS void VulkanQueue::beginDebugRegion(const String& label, const Vectors::ByteVector3& color) const noexcept { VkDebugUtilsLabelEXT labelInfo { @@ -150,7 +150,7 @@ void VulkanQueue::setDebugMarker(const String& label, const Vectors::ByteVector3 ::vkQueueInsertDebugUtilsLabel(this->handle(), &labelInfo); } -#endif +#endif // LITEFX_BUILD_SUPPORT_DEBUG_MARKERS QueuePriority VulkanQueue::priority() const noexcept { diff --git a/src/CMakePresets.json b/src/CMakePresets.json index abb87df6..380fe79e 100644 --- a/src/CMakePresets.json +++ b/src/CMakePresets.json @@ -31,7 +31,8 @@ }, "cacheVariables": { "CMAKE_BUILD_TYPE": "Debug", - "VCPKG_MANIFEST_FEATURES": "pix-support" + "VCPKG_MANIFEST_FEATURES": "pix-support", + "LITEFX_BUILD_SUPPORT_DEBUG_MARKERS": "ON" } }, { @@ -42,8 +43,7 @@ "strategy": "external" }, "cacheVariables": { - "CMAKE_BUILD_TYPE": "Release", - "VCPKG_MANIFEST_FEATURES": "pix-support" + "CMAKE_BUILD_TYPE": "Release" } }, { @@ -56,7 +56,8 @@ "cacheVariables": { "CMAKE_BUILD_TYPE": "Debug", "LITEFX_BUILD_TESTS": "ON", - "VCPKG_MANIFEST_FEATURES": "pix-support" + "VCPKG_MANIFEST_FEATURES": "pix-support", + "LITEFX_BUILD_SUPPORT_DEBUG_MARKERS": "ON" } }, { @@ -67,7 +68,8 @@ "strategy": "external" }, "cacheVariables": { - "CMAKE_BUILD_TYPE": "Debug" + "CMAKE_BUILD_TYPE": "Debug", + "LITEFX_BUILD_SUPPORT_DEBUG_MARKERS": "ON" } }, { @@ -90,7 +92,8 @@ }, "cacheVariables": { "CMAKE_BUILD_TYPE": "Debug", - "LITEFX_BUILD_TESTS": "ON" + "LITEFX_BUILD_TESTS": "ON", + "LITEFX_BUILD_SUPPORT_DEBUG_MARKERS": "ON" } } ], diff --git a/src/Core/config.tmpl b/src/Core/config.tmpl index b11f69a2..b9d9ac3b 100644 --- a/src/Core/config.tmpl +++ b/src/Core/config.tmpl @@ -5,7 +5,9 @@ #cmakedefine LITEFX_BUILD_WITH_GLM #cmakedefine LITEFX_BUILD_WITH_DIRECTX_MATH +#cmakedefine LITEFX_BUILD_WITH_PIX_RUNTIME #cmakedefine LITEFX_BUILD_DEFINE_BUILDERS +#cmakedefine LITEFX_BUILD_SUPPORT_DEBUG_MARKERS #define LITEFX_CXX_VERSION @CMAKE_CXX_STANDARD@ \ No newline at end of file diff --git a/src/cmake/Options.cmake b/src/cmake/Options.cmake index 091a8459..52c5dec1 100644 --- a/src/cmake/Options.cmake +++ b/src/cmake/Options.cmake @@ -8,6 +8,7 @@ OPTION(LITEFX_BUILD_VULKAN_BACKEND "Builds the Vulkan backend." ON) OPTION(LITEFX_BUILD_DIRECTX_12_BACKEND "Builds the DirectX 12 backend." ON) OPTION(LITEFX_BUILD_DEFINE_BUILDERS "Defines builder types to allow to use builder syntax in applications." ON) +OPTION(LITEFX_BUILD_SUPPORT_DEBUG_MARKERS "Implements support for setting debug markers on device queues." OFF) OPTION(LITEFX_BUILD_EXAMPLES "When set to OFF, no samples will be built, regardless of their individual option." ON) OPTION(LITEFX_BUILD_EXAMPLES_DX12_PIX_LOADER "Add code to samples to load PIX GPU capture library when starting with --dx-load-pix=1 command line argument." ON) @@ -33,4 +34,10 @@ IF(NOT MSVC OR (MSVC AND MSVC_VERSION LESS 1910)) IF(LITEFX_BUILD_DIRECTX_12_BACKEND OR LITEFX_BUILD_WITH_DIRECTX_MATH) MESSAGE(WARNING "DirectX features may only be working with Visual Studio 2017 or newer.") ENDIF(LITEFX_BUILD_DIRECTX_12_BACKEND OR LITEFX_BUILD_WITH_DIRECTX_MATH) -ENDIF(NOT MSVC OR (MSVC AND MSVC_VERSION LESS 1910)) \ No newline at end of file +ENDIF(NOT MSVC OR (MSVC AND MSVC_VERSION LESS 1910)) + +IF("pix-support" IN_LIST VCPKG_MANIFEST_FEATURES) + SET(LITEFX_BUILD_WITH_PIX_RUNTIME ON CACHE BOOL "Link DirectX 12 backend against PIX runtime (required for debug marker support).") +ELSE() + SET(LITEFX_BUILD_WITH_PIX_RUNTIME OFF CACHE BOOL "Link DirectX 12 backend against PIX runtime (required for debug marker support).") +ENDIF("pix-support" IN_LIST VCPKG_MANIFEST_FEATURES) \ No newline at end of file