Skip to content

Commit

Permalink
Revert guard on addPresentedHandler() and rename startPresentTime to …
Browse files Browse the repository at this point in the history
…beginPresentTime
  • Loading branch information
SRSaunders committed Jul 29, 2024
1 parent f1ec24f commit f4bb1b4
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion MoltenVK/MoltenVK/GPUObjects/MVKImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ class MVKPresentableSwapchainImage : public MVKSwapchainImage {
MVKSmallVector<MVKSwapchainSignaler, 1> _availabilitySignalers;
MVKSwapchainSignaler _preSignaler = {};
std::mutex _availabilityLock;
uint64_t _startPresentTime = 0;
uint64_t _beginPresentTime = 0;
uint64_t _presentationStartTime = 0;
};

Expand Down
10 changes: 5 additions & 5 deletions MoltenVK/MoltenVK/GPUObjects/MVKImage.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1552,14 +1552,14 @@ static void signalAndUntrack(const MVKSwapchainSignaler& signaler) {
id<CAMetalDrawable> mtlDrwbl = getCAMetalDrawable();
MVKSwapchainSignaler signaler = getPresentationSignaler();
[mtlCmdBuff addScheduledHandler: ^(id<MTLCommandBuffer> mcb) {

addPresentedHandler(mtlDrwbl, presentInfo, signaler);

// Try to do any present mode transitions as late as possible in an attempt
// to avoid visual disruptions on any presents already on the queue.
if (presentInfo.presentMode != VK_PRESENT_MODE_MAX_ENUM_KHR) {
mtlDrwbl.layer.displaySyncEnabledMVK = (presentInfo.presentMode != VK_PRESENT_MODE_IMMEDIATE_KHR);
}
if (getEnabledExtensions().vk_GOOGLE_display_timing.enabled) {
addPresentedHandler(mtlDrwbl, presentInfo, signaler);
}
if (presentInfo.desiredPresentTime) {
[mtlDrwbl presentAtTime: (double)presentInfo.desiredPresentTime * 1.0e-9];
} else {
Expand Down Expand Up @@ -1634,7 +1634,7 @@ static void signalAndUntrack(const MVKSwapchainSignaler& signaler) {
void MVKPresentableSwapchainImage::beginPresentation(const MVKImagePresentInfo& presentInfo) {
retain();
_swapchain->beginPresentation(presentInfo);
_startPresentTime = mvkGetRuntimeNanoseconds();
_beginPresentTime = mvkGetRuntimeNanoseconds();
_presentationStartTime = getPerformanceTimestamp();
}

Expand All @@ -1653,7 +1653,7 @@ static void signalAndUntrack(const MVKSwapchainSignaler& signaler) {
// VkDevice, have been destroyed by the time of this callback, so do not reference them.
lock_guard<mutex> lock(_detachmentLock);
if (_device) { addPerformanceInterval(getPerformanceStats().queue.presentSwapchains, _presentationStartTime); }
if (_swapchain) { _swapchain->endPresentation(presentInfo, _startPresentTime, actualPresentTime); }
if (_swapchain) { _swapchain->endPresentation(presentInfo, _beginPresentTime, actualPresentTime); }
}

// Makes an image available for acquisition by the app.
Expand Down
2 changes: 1 addition & 1 deletion MoltenVK/MoltenVK/GPUObjects/MVKSwapchain.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class MVKSwapchain : public MVKVulkanAPIDeviceObject {
void renderWatermark(id<MTLTexture> mtlTexture, id<MTLCommandBuffer> mtlCmdBuff);
void markFrameInterval();
void beginPresentation(const MVKImagePresentInfo& presentInfo);
void endPresentation(const MVKImagePresentInfo& presentInfo, uint64_t startPresentTime, uint64_t actualPresentTime = 0);
void endPresentation(const MVKImagePresentInfo& presentInfo, uint64_t beginPresentTime, uint64_t actualPresentTime = 0);
void forceUnpresentedImageCompletion();

MVKSurface* _surface = nullptr;
Expand Down
4 changes: 2 additions & 2 deletions MoltenVK/MoltenVK/GPUObjects/MVKSwapchain.mm
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@
_unpresentedImageCount++;
}

void MVKSwapchain::endPresentation(const MVKImagePresentInfo& presentInfo, uint64_t startPresentTime, uint64_t actualPresentTime) {
void MVKSwapchain::endPresentation(const MVKImagePresentInfo& presentInfo, uint64_t beginPresentTime, uint64_t actualPresentTime) {
_unpresentedImageCount--;

std::lock_guard<std::mutex> lock(_presentHistoryLock);
Expand All @@ -268,7 +268,7 @@
_presentTimingHistory[_presentHistoryIndex].actualPresentTime = actualPresentTime;
// These details are not available in Metal, but can estimate earliestPresentTime by using actualPresentTime instead
_presentTimingHistory[_presentHistoryIndex].earliestPresentTime = actualPresentTime;
_presentTimingHistory[_presentHistoryIndex].presentMargin = actualPresentTime > startPresentTime ? actualPresentTime - startPresentTime : 0;
_presentTimingHistory[_presentHistoryIndex].presentMargin = actualPresentTime > beginPresentTime ? actualPresentTime - beginPresentTime : 0;
_presentHistoryIndex = (_presentHistoryIndex + 1) % kMaxPresentationHistory;
}

Expand Down

0 comments on commit f4bb1b4

Please sign in to comment.