From 62fdb296460409821b22ab0c28068e726f404767 Mon Sep 17 00:00:00 2001 From: Wunkolo Date: Tue, 20 Jun 2023 11:04:48 -0700 Subject: [PATCH] Add `GPU_DEBUG_INFO` CMake-Option Adds a project-wide setting for allowing renderer code to add additional diagnostic data. Currently used to allow `opengl.hpp` to conditionally implement debug-labeling and scopes. --- CMakeLists.txt | 9 ++++++++- include/opengl.hpp | 25 +++++++++++++++++++++---- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 34542f84..74c2d429 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,8 @@ endif() project(Alber) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) +option(GPU_DEBUG_INFO "Enable additional GPU debugging info" OFF) + include_directories(${PROJECT_SOURCE_DIR}/include/) include_directories(${PROJECT_SOURCE_DIR}/include/kernel) include_directories (${FMT_INCLUDE_DIR}) @@ -138,4 +140,9 @@ source_group("Source Files\\Third Party" FILES ${THIRD_PARTY_SOURCE_FILES}) add_executable(Alber ${SOURCE_FILES} ${FS_SOURCE_FILES} ${KERNEL_SOURCE_FILES} ${LOADER_SOURCE_FILES} ${SERVICE_SOURCE_FILES} ${PICA_SOURCE_FILES} ${RENDERER_GL_SOURCE_FILES} ${THIRD_PARTY_SOURCE_FILES} ${HEADER_FILES}) -target_link_libraries(Alber PRIVATE dynarmic SDL2-static glad) \ No newline at end of file +target_link_libraries(Alber PRIVATE dynarmic SDL2-static glad) + + +if(GPU_DEBUG_INFO) + target_compile_definitions(Alber PRIVATE GPU_DEBUG_INFO=1) +endif() \ No newline at end of file diff --git a/include/opengl.hpp b/include/opengl.hpp index 42167388..67c45689 100644 --- a/include/opengl.hpp +++ b/include/opengl.hpp @@ -44,6 +44,10 @@ #include #endif +#if defined(GPU_DEBUG_INFO) +#define OPENGL_DEBUG_INFO +#endif + #ifdef _MSC_VER #include #define OPENGL_PRINTF_FORMAT _Printf_format_string_ @@ -63,23 +67,29 @@ namespace OpenGL { template constexpr std::false_type AlwaysFalse{}; - OPENGL_PRINTF_FORMAT_ATTR(3, 4) + OPENGL_PRINTF_FORMAT_ATTR(3, 4) static void setObjectLabel(GLenum identifier, GLuint name, OPENGL_PRINTF_FORMAT const char* format, ...) { +#if defined(OPENGL_DEBUG_INFO) GLchar label[256] = {}; va_list args; va_start(args, format); const GLsizei length = vsnprintf(label, std::size(label), format, args); va_end(args); glObjectLabel(identifier, name, length, label); +#endif } - class DebugScope { + class DebugScope { +#if defined(OPENGL_DEBUG_INFO) inline static GLuint scopeDepth = 0; const GLuint m_scope_depth; +#endif public: OPENGL_PRINTF_FORMAT_ATTR(2, 3) - DebugScope(OPENGL_PRINTF_FORMAT const char* format, ...) : m_scope_depth(scopeDepth++) { + DebugScope(OPENGL_PRINTF_FORMAT const char* format, ...) +#if defined(OPENGL_DEBUG_INFO) + : m_scope_depth(scopeDepth++) { GLchar message[256] = {}; va_list args; va_start(args, format); @@ -87,13 +97,20 @@ namespace OpenGL { va_end(args); glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, m_scope_depth, length, message); } +#else + { + } +#endif + ~DebugScope() { +#if defined(OPENGL_DEBUG_INFO) glPopDebugGroup(); scopeDepth--; +#endif } }; - struct VertexArray { + struct VertexArray { GLuint m_handle = 0; void create() {