Skip to content

Commit 294ba23

Browse files
Fix for Issue 226. Updated gather commands to match PMC.
1 parent f7310da commit 294ba23

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

IntelPresentMon/PresentMonMiddleware/source/FrameEventQuery.cpp

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ namespace pmon::mid
2828

2929
namespace
3030
{
31+
double TimestampDeltaToMilliSeconds(uint64_t timestampDelta, double performanceCounterPeriodMs)
32+
{
33+
return performanceCounterPeriodMs * double(timestampDelta);
34+
}
35+
36+
double TimestampDeltaToUnsignedMilliSeconds(uint64_t timestampFrom, uint64_t timestampTo, double performanceCounterPeriodMs)
37+
{
38+
return timestampFrom == 0 || timestampTo <= timestampFrom ? 0.0 :
39+
TimestampDeltaToMilliSeconds(timestampTo - timestampFrom, performanceCounterPeriodMs);
40+
}
41+
3142
template<auto pMember>
3243
constexpr auto GetSubstructurePointer()
3344
{
@@ -156,8 +167,8 @@ namespace
156167
reinterpret_cast<double&>(pDestBlob[outputOffset_]) = val;
157168
}
158169
else {
159-
const auto qpcDuration = ctx.pSourceFrameData->present_event.*pEnd - start;
160-
const auto val = ctx.performanceCounterPeriodMs * double(qpcDuration);
170+
const auto val = TimestampDeltaToUnsignedMilliSeconds(start,
171+
ctx.pSourceFrameData->present_event.*pEnd, ctx.performanceCounterPeriodMs);
161172
reinterpret_cast<double&>(pDestBlob[outputOffset_]) = val;
162173
}
163174
}
@@ -272,8 +283,8 @@ namespace
272283
return;
273284
}
274285
}
275-
const auto qpcDuration = ctx.pSourceFrameData->present_event.*pEnd - ctx.cpuFrameQpc;
276-
const auto val = ctx.performanceCounterPeriodMs * double(qpcDuration);
286+
const auto val = TimestampDeltaToUnsignedMilliSeconds(ctx.cpuFrameQpc,
287+
ctx.pSourceFrameData->present_event.*pEnd, ctx.performanceCounterPeriodMs);
277288
reinterpret_cast<double&>(pDestBlob[outputOffset_]) = val;
278289
}
279290
uint32_t GetBeginOffset() const override
@@ -310,8 +321,8 @@ namespace
310321
return;
311322
}
312323
}
313-
const auto qpcDuration = ctx.nextDisplayedQpc - ctx.pSourceFrameData->present_event.*pStart;
314-
const auto val = ctx.performanceCounterPeriodMs * double(qpcDuration);
324+
const auto val = TimestampDeltaToUnsignedMilliSeconds(ctx.pSourceFrameData->present_event.*pStart,
325+
ctx.nextDisplayedQpc, ctx.performanceCounterPeriodMs);
315326
reinterpret_cast<double&>(pDestBlob[outputOffset_]) = val;
316327
}
317328
uint32_t GetBeginOffset() const override
@@ -362,9 +373,11 @@ namespace
362373
GpuWaitGatherCommand_(size_t nextAvailableByteOffset) : outputOffset_{ (uint32_t)nextAvailableByteOffset } {}
363374
void Gather(const Context& ctx, uint8_t* pDestBlob) const override
364375
{
365-
const auto qpcDuration = (ctx.pSourceFrameData->present_event.ReadyTime - ctx.pSourceFrameData->present_event.GPUStartTime) -
366-
ctx.pSourceFrameData->present_event.GPUDuration;
367-
const auto val = std::max(0., ctx.performanceCounterPeriodMs * double(qpcDuration));
376+
const auto gpuDuration = TimestampDeltaToUnsignedMilliSeconds(ctx.pSourceFrameData->present_event.GPUStartTime,
377+
ctx.pSourceFrameData->present_event.ReadyTime, ctx.performanceCounterPeriodMs);
378+
const auto gpuBusy = TimestampDeltaToMilliSeconds(ctx.pSourceFrameData->present_event.GPUDuration,
379+
ctx.performanceCounterPeriodMs);
380+
const auto val = std::max(0., gpuDuration - gpuBusy);
368381
reinterpret_cast<double&>(pDestBlob[outputOffset_]) = val;
369382
}
370383
uint32_t GetBeginOffset() const override
@@ -540,7 +553,7 @@ std::unique_ptr<mid::GatherCommand_> PM_FRAME_QUERY::MapQueryElementToGatherComm
540553
case PM_METRIC_CPU_WAIT:
541554
return std::make_unique<QpcDurationGatherCommand_<&Pre::TimeInPresent>>(pos);
542555
case PM_METRIC_GPU_TIME:
543-
return std::make_unique<QpcDifferenceGatherCommand_<&Pre::GPUStartTime, &Pre::ReadyTime, 1, 0, 1, 0>>(pos);
556+
return std::make_unique<QpcDifferenceGatherCommand_<&Pre::GPUStartTime, &Pre::ReadyTime, 0, 0, 0, 0>>(pos);
544557
case PM_METRIC_GPU_WAIT:
545558
return std::make_unique<GpuWaitGatherCommand_>(pos);
546559
case PM_METRIC_DISPLAYED_TIME:

0 commit comments

Comments
 (0)