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.
This commit is contained in:
Wunkolo 2023-06-20 11:04:48 -07:00
parent dbf0597bd8
commit 62fdb29646
2 changed files with 29 additions and 5 deletions

View file

@ -13,6 +13,8 @@ endif()
project(Alber) project(Alber)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) 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/)
include_directories(${PROJECT_SOURCE_DIR}/include/kernel) include_directories(${PROJECT_SOURCE_DIR}/include/kernel)
include_directories (${FMT_INCLUDE_DIR}) 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} 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}) ${PICA_SOURCE_FILES} ${RENDERER_GL_SOURCE_FILES} ${THIRD_PARTY_SOURCE_FILES} ${HEADER_FILES})
target_link_libraries(Alber PRIVATE dynarmic SDL2-static glad) target_link_libraries(Alber PRIVATE dynarmic SDL2-static glad)
if(GPU_DEBUG_INFO)
target_compile_definitions(Alber PRIVATE GPU_DEBUG_INFO=1)
endif()

View file

@ -44,6 +44,10 @@
#include <span> #include <span>
#endif #endif
#if defined(GPU_DEBUG_INFO)
#define OPENGL_DEBUG_INFO
#endif
#ifdef _MSC_VER #ifdef _MSC_VER
#include <sal.h> #include <sal.h>
#define OPENGL_PRINTF_FORMAT _Printf_format_string_ #define OPENGL_PRINTF_FORMAT _Printf_format_string_
@ -63,23 +67,29 @@ namespace OpenGL {
template <class...> template <class...>
constexpr std::false_type AlwaysFalse{}; 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, ...) { static void setObjectLabel(GLenum identifier, GLuint name, OPENGL_PRINTF_FORMAT const char* format, ...) {
#if defined(OPENGL_DEBUG_INFO)
GLchar label[256] = {}; GLchar label[256] = {};
va_list args; va_list args;
va_start(args, format); va_start(args, format);
const GLsizei length = vsnprintf(label, std::size(label), format, args); const GLsizei length = vsnprintf(label, std::size(label), format, args);
va_end(args); va_end(args);
glObjectLabel(identifier, name, length, label); glObjectLabel(identifier, name, length, label);
#endif
} }
class DebugScope { class DebugScope {
#if defined(OPENGL_DEBUG_INFO)
inline static GLuint scopeDepth = 0; inline static GLuint scopeDepth = 0;
const GLuint m_scope_depth; const GLuint m_scope_depth;
#endif
public: public:
OPENGL_PRINTF_FORMAT_ATTR(2, 3) 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] = {}; GLchar message[256] = {};
va_list args; va_list args;
va_start(args, format); va_start(args, format);
@ -87,13 +97,20 @@ namespace OpenGL {
va_end(args); va_end(args);
glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, m_scope_depth, length, message); glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, m_scope_depth, length, message);
} }
#else
{
}
#endif
~DebugScope() { ~DebugScope() {
#if defined(OPENGL_DEBUG_INFO)
glPopDebugGroup(); glPopDebugGroup();
scopeDepth--; scopeDepth--;
#endif
} }
}; };
struct VertexArray { struct VertexArray {
GLuint m_handle = 0; GLuint m_handle = 0;
void create() { void create() {