Skip to content

Commit

Permalink
Merge pull request #1890 from billhollings/fix-display-timing-race-co…
Browse files Browse the repository at this point in the history
…ndition

Fix race condition when updating values in VkPastPresentationTimingGOOGLE.
  • Loading branch information
billhollings authored May 5, 2023
2 parents af9544d + 9e46669 commit dfc0af8
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions Docs/Whats_New.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Released TBD
- Support separate depth and stencil attachments during dynamic rendering.
- Deprecate the obsolete and non-standard `VK_MVK_moltenvk` extension.
- Fix memory leak when waiting on timeline semaphores.
- Fix race condition when updating values in `VkPastPresentationTimingGOOGLE`.
- Ensure shaders that use `PhysicalStorageBufferAddresses` encode the use of the associated `MTLBuffer`.
- Disable pipeline cache compression prior to macOS 10.15 and iOS/tvOS 13.0.
- Add `MVK_ENABLE_EXPLICIT_LOD_WORKAROUND` environment variable to selectively
Expand Down
4 changes: 2 additions & 2 deletions MoltenVK/MoltenVK/GPUObjects/MVKImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ class MVKPresentableSwapchainImage : public MVKSwapchainImage {
#pragma mark Metal

/** Presents the contained drawable to the OS. */
void presentCAMetalDrawable(id<MTLCommandBuffer> mtlCmdBuff, MVKImagePresentInfo& presentInfo);
void presentCAMetalDrawable(id<MTLCommandBuffer> mtlCmdBuff, MVKImagePresentInfo presentInfo);


#pragma mark Construction
Expand All @@ -463,7 +463,7 @@ class MVKPresentableSwapchainImage : public MVKSwapchainImage {
friend MVKSwapchain;

id<CAMetalDrawable> getCAMetalDrawable() override;
void addPresentedHandler(id<CAMetalDrawable> mtlDrawable, MVKImagePresentInfo& presentInfo);
void addPresentedHandler(id<CAMetalDrawable> mtlDrawable, MVKImagePresentInfo presentInfo);
void releaseMetalDrawable();
MVKSwapchainImageAvailability getAvailability();
void makeAvailable(const MVKSwapchainSignaler& signaler);
Expand Down
6 changes: 4 additions & 2 deletions MoltenVK/MoltenVK/GPUObjects/MVKImage.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1294,8 +1294,9 @@ static void signalAndUnmarkAsTracked(const MVKSwapchainSignaler& signaler) {
}

// Present the drawable and make myself available only once the command buffer has completed.
// Pass MVKImagePresentInfo by value because it may not exist when the callback runs.
void MVKPresentableSwapchainImage::presentCAMetalDrawable(id<MTLCommandBuffer> mtlCmdBuff,
MVKImagePresentInfo& presentInfo) {
MVKImagePresentInfo presentInfo) {
lock_guard<mutex> lock(_availabilityLock);

_swapchain->willPresentSurface(getMTLTexture(0), mtlCmdBuff);
Expand Down Expand Up @@ -1357,8 +1358,9 @@ static void signalAndUnmarkAsTracked(const MVKSwapchainSignaler& signaler) {
signalPresentationSemaphore(signaler, mtlCmdBuff);
}

// Pass MVKImagePresentInfo by value because it may not exist when the callback runs.
void MVKPresentableSwapchainImage::addPresentedHandler(id<CAMetalDrawable> mtlDrawable,
MVKImagePresentInfo& presentInfo) {
MVKImagePresentInfo presentInfo) {
#if !MVK_OS_SIMULATOR
if ([mtlDrawable respondsToSelector: @selector(addPresentedHandler:)]) {
retain(); // Ensure this image is not destroyed while awaiting presentation
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 @@ -121,7 +121,7 @@ class MVKSwapchain : public MVKVulkanAPIDeviceObject {
void willPresentSurface(id<MTLTexture> mtlTexture, id<MTLCommandBuffer> mtlCmdBuff);
void renderWatermark(id<MTLTexture> mtlTexture, id<MTLCommandBuffer> mtlCmdBuff);
void markFrameInterval();
void recordPresentTime(MVKImagePresentInfo& presentInfo, uint64_t actualPresentTime = 0);
void recordPresentTime(const MVKImagePresentInfo& presentInfo, uint64_t actualPresentTime = 0);

CAMetalLayer* _mtlLayer = nil;
MVKWatermark* _licenseWatermark = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion MoltenVK/MoltenVK/GPUObjects/MVKSwapchain.mm
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ static CALayerContentsGravity getCALayerContentsGravity(VkSwapchainPresentScalin
return res;
}

void MVKSwapchain::recordPresentTime(MVKImagePresentInfo& presentInfo, uint64_t actualPresentTime) {
void MVKSwapchain::recordPresentTime(const MVKImagePresentInfo& presentInfo, uint64_t actualPresentTime) {
std::lock_guard<std::mutex> lock(_presentHistoryLock);
if (_presentHistoryCount < kMaxPresentationHistory) {
_presentHistoryCount++;
Expand Down

0 comments on commit dfc0af8

Please sign in to comment.