Skip to content

Commit

Permalink
[DebugLayer] Refactored command buffer annotations in debug layer (BR…
Browse files Browse the repository at this point in the history
…EAKING CHANGE).

Most CommandBuffer commands now print a formatted string when time recording is enabled to improve frame traces.
This is a breaking change as the annotation field in "ProfileTimeRecord" has been changed from a C-string to "StringLiteral".
  • Loading branch information
LukasBanana committed Feb 2, 2025
1 parent a8ce375 commit 89617e5
Show file tree
Hide file tree
Showing 9 changed files with 255 additions and 72 deletions.
2 changes: 1 addition & 1 deletion examples/Cpp/ExampleBase/ExampleBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ void ExampleBase::MainLoop()
);
const double invTicksFreqMS = 1000.0 / LLGL::Timer::Frequency();
for (const LLGL::ProfileTimeRecord& rec : frameProfile.timeRecords)
LLGL::Log::Printf("%s: GPU time: %" PRIu64 " ns\n", rec.annotation, rec.elapsedTime);
LLGL::Log::Printf("%s: GPU time: %" PRIu64 " ns\n", rec.annotation.c_str(), rec.elapsedTime);

debuggerObj_->SetTimeRecording(false);
showTimeRecords_ = false;
Expand Down
2 changes: 1 addition & 1 deletion examples/Cpp/ExampleBase/FileUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ std::string WriteFrameProfileToJson(const LLGL::FrameProfile& frameProfile)
s += ", ";

s += "\"ph\": \"X\", \"name\": \"";
s += rec.annotation;
s += rec.annotation.c_str();
s += "\", ";

s += "\"args\": { \"Elapsed GPU Time\": ";
Expand Down
3 changes: 2 additions & 1 deletion include/LLGL/RenderingDebuggerFlags.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <LLGL/Export.h>
#include <LLGL/Deprecated.h>
#include <LLGL/Container/DynamicVector.h>
#include <LLGL/Container/StringLiteral.h>
#include <cstdint>


Expand Down Expand Up @@ -49,7 +50,7 @@ enum class WarningType
struct ProfileTimeRecord
{
//! Time record annotation, e.g. function name that was recorded from the CommandBuffer.
const char* annotation = "";
StringLiteral annotation;

/**
\brief CPU ticks at the beginning of the command.
Expand Down
284 changes: 231 additions & 53 deletions sources/Renderer/DebugLayer/DbgCommandBuffer.cpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion sources/Renderer/DebugLayer/DbgCommandBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ class DbgCommandBuffer final : public CommandBuffer
void ResetRecords();
void ResetBindingTable(const DbgPipelineLayout* pipelineLayoutDbg);

void StartTimer(const char* annotation);
void StartTimer(StringLiteral annotation);
void EndTimer();

// Returns true if this command buffer inherits its state from a primary command buffer.
Expand Down
4 changes: 2 additions & 2 deletions sources/Renderer/DebugLayer/DbgQueryTimerPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ void DbgQueryTimerPool::Reset()
cpuTicksBase_ = Timer::Tick();
}

void DbgQueryTimerPool::Start(const char* annotation)
void DbgQueryTimerPool::Start(StringLiteral annotation)
{
pendingRecordStack_.push(records_.size());

/* Store annotation only first */
ProfileTimeRecord record;
{
record.annotation = annotation;
record.annotation = std::move(annotation);
record.cpuTicksStart = Timer::Tick() - cpuTicksBase_;
}
records_.push_back(record);
Expand Down
2 changes: 1 addition & 1 deletion sources/Renderer/DebugLayer/DbgQueryTimerPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class DbgQueryTimerPool
void Reset();

// Starts measuring the time with the specified annotation.
void Start(const char* annotation);
void Start(StringLiteral annotation);

// Stops measing the time and stores the current record.
void Stop();
Expand Down
22 changes: 16 additions & 6 deletions wrapper/C99/C99RenderingDebugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <LLGL/RenderingDebugger.h>
#include <LLGL-C/RenderingDebugger.h>
#include <LLGL/Utils/ForRange.h>
#include "C99Internal.h"
#include <cstring>

Expand Down Expand Up @@ -36,11 +37,20 @@ LLGL_C_EXPORT bool llglGetDebuggerTimeRecording(LLGLRenderingDebugger debugger)
return LLGL_PTR(RenderingDebugger, debugger)->GetTimeRecording();
}

static void ConvertC99ProfileTimeRecord(LLGLProfileTimeRecord& dst, const ProfileTimeRecord& src)
{
dst.annotation = src.annotation.c_str();
dst.cpuTicksStart = src.cpuTicksStart;
dst.cpuTicksEnd = src.cpuTicksEnd;
dst.elapsedTime = src.elapsedTime;
}

LLGL_C_EXPORT void llglFlushDebuggerProfile(LLGLRenderingDebugger debugger, LLGLFrameProfile* outFrameProfile)
{
LLGL_ASSERT_PTR(outFrameProfile);

static thread_local FrameProfile internalFrameProfile;
static thread_local std::vector<LLGLProfileTimeRecord> internalProfileTimeRecords;
LLGL_PTR(RenderingDebugger, debugger)->FlushProfile(&internalFrameProfile);

static_assert(
Expand All @@ -55,12 +65,12 @@ LLGL_C_EXPORT void llglFlushDebuggerProfile(LLGLRenderingDebugger debugger, LLGL
);
std::memcpy(&(outFrameProfile->commandBufferRecord), &(internalFrameProfile.commandBufferRecord), sizeof(LLGLProfileCommandBufferRecord));

static_assert(
sizeof(LLGLProfileTimeRecord) == sizeof(ProfileTimeRecord),
"LLGLProfileTimeRecord and LLGL::ProfileTimeRecord expected to be the same size"
);
outFrameProfile->numTimeRecords = internalFrameProfile.timeRecords.size();
outFrameProfile->timeRecords = reinterpret_cast<const LLGLProfileTimeRecord*>(internalFrameProfile.timeRecords.data());
internalProfileTimeRecords.resize(internalFrameProfile.timeRecords.size());
for_range(i, internalFrameProfile.timeRecords.size())
ConvertC99ProfileTimeRecord(internalProfileTimeRecords[i], internalFrameProfile.timeRecords[i]);

outFrameProfile->numTimeRecords = internalProfileTimeRecords.size();
outFrameProfile->timeRecords = internalProfileTimeRecords.data();
}


Expand Down
6 changes: 0 additions & 6 deletions wrapper/C99/C99TypeAssertions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1139,12 +1139,6 @@ LLGL_STATIC_ASSERT_OFFSET(ProfileCommandBufferRecord, renderConditionSections);
LLGL_STATIC_ASSERT_OFFSET(ProfileCommandBufferRecord, drawCommands);
LLGL_STATIC_ASSERT_OFFSET(ProfileCommandBufferRecord, dispatchCommands);

LLGL_STATIC_ASSERT_SIZE(ProfileTimeRecord);
LLGL_STATIC_ASSERT_OFFSET(ProfileTimeRecord, annotation);
LLGL_STATIC_ASSERT_OFFSET(ProfileTimeRecord, cpuTicksStart);
LLGL_STATIC_ASSERT_OFFSET(ProfileTimeRecord, cpuTicksEnd);
LLGL_STATIC_ASSERT_OFFSET(ProfileTimeRecord, elapsedTime);

LLGL_STATIC_ASSERT_SIZE(ColorCodes);
LLGL_STATIC_ASSERT_OFFSET(ColorCodes, textFlags);
LLGL_STATIC_ASSERT_OFFSET(ColorCodes, backgroundFlags);
Expand Down

0 comments on commit 89617e5

Please sign in to comment.