Skip to content

Commit 7724680

Browse files
committed
Fix high latency on present wait.
1 parent 147fbea commit 7724680

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

MoltenVK/MoltenVK/GPUObjects/MVKImage.mm

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1629,8 +1629,9 @@ static void signalAndUntrack(const MVKSwapchainSignaler& signaler) {
16291629
// Ensure this image, the drawable, and the present fence are not destroyed while
16301630
// awaiting MTLCommandBuffer completion. We retain the drawable separately because
16311631
// a new drawable might be acquired by this image by then.
1632-
// Signal the fence from this callback, because the last one or two presentation
1633-
// completion callbacks can occasionally stall.
1632+
// Signal the fence and notify the swapchain that the present has completed
1633+
// from this callback, because the last one or two presentation completion
1634+
// callbacks can occasionally stall.
16341635
retain();
16351636
[mtlDrwbl retain];
16361637
auto* fence = presentInfo.fence;
@@ -1640,6 +1641,7 @@ static void signalAndUntrack(const MVKSwapchainSignaler& signaler) {
16401641
if (fence) { fence->release(); }
16411642
[mtlDrwbl release];
16421643
release();
1644+
if (_swapchain) { _swapchain->notifyPresentComplete(presentInfo); }
16431645
}];
16441646

16451647
signal(signaler.semaphore, signaler.semaphoreSignalToken, mtlCmdBuff);

MoltenVK/MoltenVK/GPUObjects/MVKSwapchain.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ class MVKSwapchain : public MVKVulkanAPIDeviceObject {
123123
void markFrameInterval();
124124
void beginPresentation(const MVKImagePresentInfo& presentInfo);
125125
void endPresentation(const MVKImagePresentInfo& presentInfo, uint64_t beginPresentTime, uint64_t actualPresentTime = 0);
126+
void notifyPresentComplete(const MVKImagePresentInfo& presentInfo);
126127
void forceUnpresentedImageCompletion();
127128

128129
MVKSurface* _surface = nullptr;

MoltenVK/MoltenVK/GPUObjects/MVKSwapchain.mm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,9 @@
277277
_presentTimingHistory[_presentHistoryIndex].earliestPresentTime = actualPresentTime;
278278
_presentTimingHistory[_presentHistoryIndex].presentMargin = actualPresentTime > beginPresentTime ? actualPresentTime - beginPresentTime : 0;
279279
_presentHistoryIndex = (_presentHistoryIndex + 1) % kMaxPresentationHistory;
280+
}
280281

282+
void MVKSwapchain::notifyPresentComplete(const MVKImagePresentInfo& presentInfo) {
281283
if (presentInfo.presentId != 0) {
282284
std::unique_lock pidLock(_currentPresentIdMutex);
283285
_currentPresentId = std::max(_currentPresentId, presentInfo.presentId);

0 commit comments

Comments
 (0)