Skip to content

Commit 0f47cf6

Browse files
committed
Adding CPU time offset to GPU markers
Adding but disabling for now seeing as the GPU is always 3 frames behind, meaning we don't get a good overlap with the state the profiler is in now (where it shows a single frame)
1 parent b063792 commit 0f47cf6

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

code/foundation/profiling/profiling.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ struct ProfilingContext
177177
Util::Array<ProfilingScope> topLevelScopes;
178178

179179
Timing::Timer timer;
180+
Timing::Time start;
180181
Util::StringAtom threadName;
181182
Threading::ThreadId threadId;
182183
int priority = 0;

code/render/coregraphics/commandbuffer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ struct FrameProfilingMarker
9191
IndexT gpuEnd;
9292
uint64_t start;
9393
uint64_t duration;
94+
uint64_t cpuBegin;
9495
Util::Array<FrameProfilingMarker> children;
9596
};
9697
#endif

code/render/coregraphics/vk/vkcommandbuffer.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1590,6 +1590,7 @@ CmdBeginMarker(const CmdBufferId id, const Math::vec4& color, const char* name)
15901590
marker.color = color;
15911591
marker.name = name;
15921592
marker.queue = usage;
1593+
marker.cpuBegin = 0;// Profiling::ProfilingGetTime() * 1000000000.0f;
15931594
marker.gpuBegin = chunk.offset + chunk.queryCount++;
15941595
vkCmdWriteTimestamp(cmdBuf, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, pool, marker.gpuBegin);
15951596
markers.markerStack.Push(marker);

toolkit/editor/editor/ui/windows/profiler.cc

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,10 @@ RecursiveDrawScope(const Profiling::ProfilingScope& scope, Profiler::HighLightRe
129129
/**
130130
*/
131131
int
132-
RecursiveDrawGpuMarker(const CoreGraphics::FrameProfilingMarker& marker, Profiler::HighLightRegion& highlightRegion, ImDrawList* drawList, const ImVec2 start, const ImVec2 fullSize, ImVec2 pos, const ImVec2 canvas, const float fullFrameTime, const float startSection, const float endSection, const int level)
132+
RecursiveDrawGpuMarker(const CoreGraphics::FrameProfilingMarker& marker, Profiler::HighLightRegion& highlightRegion, ImDrawList* drawList, const ImVec2 start, const ImVec2 fullSize, ImVec2 pos, const ImVec2 canvas, const float fullFrameTime, const float startSection, const float endSection, const float cpuOffset, const int level)
133133
{
134134
// convert to milliseconds
135-
float begin = marker.start / 1000000000.0f;
135+
float begin = (marker.start + marker.cpuBegin) / 1000000000.0f;
136136
float duration = marker.duration / 1000000000.0f;
137137

138138
const float startTime = startSection * fullFrameTime;
@@ -193,7 +193,7 @@ RecursiveDrawGpuMarker(const CoreGraphics::FrameProfilingMarker& marker, Profile
193193
int deepest = level + 1;
194194
for (IndexT i = 0; i < marker.children.Size(); i++)
195195
{
196-
int childLevel = RecursiveDrawGpuMarker(marker.children[i], highlightRegion, drawList, start, fullSize, pos, canvas, fullFrameTime, startSection, endSection, level + 1);
196+
int childLevel = RecursiveDrawGpuMarker(marker.children[i], highlightRegion, drawList, start, fullSize, pos, canvas, fullFrameTime, startSection, endSection, cpuOffset, level + 1);
197197
deepest = Math::max(deepest, childLevel);
198198
}
199199
return deepest;
@@ -375,8 +375,9 @@ Profiler::Run(SaveMode save)
375375
totalMarker.queue = CoreGraphics::GraphicsQueueType;
376376
totalMarker.children = frameMarkersGraphics;
377377
totalMarker.start = first.start;
378-
totalMarker.duration = (last.start + last.duration - first.start);
379-
int level = RecursiveDrawGpuMarker(totalMarker, this->highlightRegion, drawList, start, fullSize, pos, canvasSize, this->currentFrameTime, this->timeStart, this->timeEnd, 0);
378+
totalMarker.duration = (last.start + last.duration + last.cpuBegin - (first.start + first.cpuBegin));
379+
totalMarker.cpuBegin = first.cpuBegin;
380+
int level = RecursiveDrawGpuMarker(totalMarker, this->highlightRegion, drawList, start, fullSize, pos, canvasSize, this->currentFrameTime, this->timeStart, this->timeEnd, first.cpuBegin, 0);
380381
levels = Math::max(levels, level);
381382
}
382383
pos.y += Math::max(1, (levels - 1)) * 20.0f;
@@ -396,8 +397,9 @@ Profiler::Run(SaveMode save)
396397
totalMarker.queue = CoreGraphics::ComputeQueueType;
397398
totalMarker.children = frameMarkersCompute;
398399
totalMarker.start = first.start;
399-
totalMarker.duration = (last.start + last.duration - first.start);
400-
int level = RecursiveDrawGpuMarker(totalMarker, this->highlightRegion, drawList, start, fullSize, pos, canvasSize, this->currentFrameTime, this->timeStart, this->timeEnd, 0);
400+
totalMarker.duration = (last.start + last.duration + last.cpuBegin - (first.start + first.cpuBegin));
401+
totalMarker.cpuBegin = first.cpuBegin;
402+
int level = RecursiveDrawGpuMarker(totalMarker, this->highlightRegion, drawList, start, fullSize, pos, canvasSize, this->currentFrameTime, this->timeStart, this->timeEnd, first.cpuBegin, 0);
401403
levels = Math::max(levels, level);
402404
}
403405

0 commit comments

Comments
 (0)