Skip to content

Commit

Permalink
Add option to toggle debug markers
Browse files Browse the repository at this point in the history
  • Loading branch information
sergcpp committed Aug 29, 2024
1 parent 2791d54 commit 60a3979
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ else(NOT CMAKE_SYSTEM_NAME MATCHES "Android")
OPTION(ENABLE_VK_IMPL "Enable Vulkan GPU implementation" OFF)
OPTION(ENABLE_DX_IMPL "Enable DirectX12 GPU implementation" OFF)
endif(NOT CMAKE_SYSTEM_NAME MATCHES "Android")
OPTION(ENABLE_DEBUG_MARKERS "Enable GPU debug markers" OFF)
OPTION(ENABLE_PIX "Enable PIX debug/capture API" OFF)

set(CMAKE_CONFIGURATION_TYPES "Debug;Release;RelWithDebInfo;Asan;Tsan" CACHE STRING "" FORCE)
Expand Down
4 changes: 4 additions & 0 deletions internal/Dx/DebugMarkerDX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,22 @@

Ray::Dx::DebugMarker::DebugMarker(Context *, ID3D12GraphicsCommandList *_cmd_buf, const char *name)
: cmd_buf_(_cmd_buf) {
#ifdef ENABLE_DEBUG_MARKERS
#ifdef ENABLE_PIX
PIXBeginEvent(cmd_buf_, 0, name);
#else
std::wstring wstr(name, name + strlen(name));
cmd_buf_->BeginEvent(0, wstr.c_str(), UINT(wstr.length() * sizeof(wchar_t)));
#endif
#endif
}

Ray::Dx::DebugMarker::~DebugMarker() {
#ifdef ENABLE_DEBUG_MARKERS
#ifdef ENABLE_PIX
PIXEndEvent(cmd_buf_);
#else
cmd_buf_->EndEvent();
#endif
#endif
}
6 changes: 6 additions & 0 deletions internal/Vk/DebugMarkerVK.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include "../../Config.h"

namespace Ray {
namespace Vk {
class Context;
Expand All @@ -15,13 +17,17 @@ struct DebugMarker {

inline Ray::Vk::DebugMarker::DebugMarker(Context *ctx, VkCommandBuffer _cmd_buf, const char *name)
: ctx_(ctx), cmd_buf_(_cmd_buf) {
#ifdef ENABLE_DEBUG_MARKERS
VkDebugUtilsLabelEXT label = {VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT};
label.pLabelName = name;
label.color[0] = label.color[1] = label.color[2] = label.color[3] = 1.0f;

ctx_->api().vkCmdBeginDebugUtilsLabelEXT(cmd_buf_, &label);
#endif
}

inline Ray::Vk::DebugMarker::~DebugMarker() {
#ifdef ENABLE_DEBUG_MARKERS
ctx_->api().vkCmdEndDebugUtilsLabelEXT(cmd_buf_);
#endif
}

0 comments on commit 60a3979

Please sign in to comment.