Skip to content

Commit 0e7de65

Browse files
Enhance present event processing in CompletePresent
Improved handling of `Displayed` timestamps in the `CompletePresent` function of `PresentMonTraceConsumer.cpp`. The new logic copies timestamps from the source present while preserving `FrameType` information. Added checks for propagating application timing data and updated comments for clarity. Code structure has been refined for better readability and maintainability.
1 parent 1a08500 commit 0e7de65

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

PresentData/PresentMonTraceConsumer.cpp

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2115,7 +2115,29 @@ void PMTraceConsumer::CompletePresent(std::shared_ptr<PresentEvent> const& p)
21152115
} else if (p2->FinalState != PresentResult::Discarded) {
21162116
VerboseTraceBeforeModifyingPresent(p2.get());
21172117
p2->FinalState = p->FinalState;
2118-
p2->Displayed = p->Displayed;
2118+
// If the DWM present was displayed, then the dependent present was also displayed.
2119+
// However keep the FrameType information from the dependent present.
2120+
{
2121+
// Copy timestamps from p (source) into p2 (dest), preserving p2's FrameType(s).
2122+
if (!p->Displayed.empty()) {
2123+
const size_t nCommon = std::min(p2->Displayed.size(), p->Displayed.size());
2124+
2125+
// Reserve space upfront if we know we'll be adding elements
2126+
if (p->Displayed.size() > nCommon) {
2127+
p2->Displayed.reserve(p->Displayed.size());
2128+
}
2129+
2130+
// Overwrite timestamps for shared entries (keep existing FrameType).
2131+
for (size_t i = 0; i < nCommon; ++i) {
2132+
p2->Displayed[i].second = p->Displayed[i].second;
2133+
}
2134+
2135+
// Append extra timestamps from source
2136+
for (size_t i = nCommon; i < p->Displayed.size(); ++i) {
2137+
p2->Displayed.emplace_back(p->Displayed[i].first, p->Displayed[i].second);
2138+
}
2139+
}
2140+
}
21192141
p2->WaitingForFlipFrameType = p->WaitingForFlipFrameType;
21202142
p2->DoneWaitingForFlipFrameType = p->DoneWaitingForFlipFrameType;
21212143
}
@@ -2209,8 +2231,10 @@ void PMTraceConsumer::CompletePresent(std::shared_ptr<PresentEvent> const& p)
22092231
});
22102232
if (it != p2->Displayed.end()) {
22112233
// Propagate the Present information attached to the generated frame
2212-
// TODO -> explain why we have two paths for copying
22132234
if (p2->AppPropagatedPresentStartTime != 0) {
2235+
// If the completed present has propagated app timing data from an earlier
2236+
// present, propagate the data to this present and clear it from the completed
2237+
// present so it doesn't get propagated again.
22142238
present->AppPropagatedPresentStartTime = p2->AppPropagatedPresentStartTime;
22152239
present->AppPropagatedTimeInPresent = p2->AppPropagatedTimeInPresent;
22162240
present->AppPropagatedGPUStartTime = p2->AppPropagatedGPUStartTime;
@@ -2224,6 +2248,8 @@ void PMTraceConsumer::CompletePresent(std::shared_ptr<PresentEvent> const& p)
22242248
p2->AppPropagatedGPUDuration = 0;
22252249
p2->AppPropagatedGPUVideoDuration = 0;
22262250
} else {
2251+
// Otherwise set the propagated data using the values from
2252+
// the completed present itself.
22272253
present->AppPropagatedPresentStartTime = p2->PresentStartTime;
22282254
present->AppPropagatedTimeInPresent = p2->TimeInPresent;
22292255
present->AppPropagatedGPUStartTime = p2->GPUStartTime;
@@ -2240,7 +2266,6 @@ void PMTraceConsumer::CompletePresent(std::shared_ptr<PresentEvent> const& p)
22402266
present->InputType = p2->InputType;
22412267
}
22422268
}
2243-
break;
22442269
}
22452270
p2->WaitingForFrameId = false;
22462271
}

0 commit comments

Comments
 (0)