Skip to content

Commit

Permalink
Merge pull request #2141 from billhollings/surface-extent
Browse files Browse the repository at this point in the history
Don't update currentExtent of headless surface when swapchain attached.
  • Loading branch information
billhollings authored Jan 26, 2024
2 parents b5ffb47 + 3e6b3a7 commit d4d5dcb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 2 additions & 0 deletions Docs/Whats_New.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Released TBD
- Ensure buffers available for buffer addresses in push constants.
- Support `libMoltenVK.dylib` for _iOS Simulator_ architecture.
- Restore support for _iOS Simulator_ destination in recent update to _Cube_ demo that uses dynamic-linking.
- Don't update `currentExtent` of headless surface when swapchain attached.



MoltenVK 1.2.7
Expand Down
1 change: 0 additions & 1 deletion MoltenVK/MoltenVK/GPUObjects/MVKSurface.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,5 @@ class MVKSurface : public MVKVulkanAPIObject {
CAMetalLayer* _mtlCAMetalLayer = nil;
MVKBlockObserver* _layerObserver = nil;
MVKSwapchain* _activeSwapchain = nullptr;
VkExtent2D _headlessExtent = {0xFFFFFFFF, 0xFFFFFFFF};
};

11 changes: 7 additions & 4 deletions MoltenVK/MoltenVK/GPUObjects/MVKSurface.mm
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
#define STR_PLATFORM(NAME) #NAME
#define STR(NAME) STR_PLATFORM(NAME)

// As defined in the Vulkan spec, represents an undefined extent.
// Spec is currently somewhat ambiguous about whether an undefined surface extent should be updated
// once a swapchain is attached, but consensus amoung the spec authors is that it should not.
static constexpr VkExtent2D kMVKUndefinedExtent = {0xFFFFFFFF, 0xFFFFFFFF};


#pragma mark MVKSurface

Expand All @@ -50,17 +55,15 @@
}

VkExtent2D MVKSurface::getExtent() {
return _mtlCAMetalLayer ? mvkVkExtent2DFromCGSize(_mtlCAMetalLayer.drawableSize) : _headlessExtent;
return _mtlCAMetalLayer ? mvkVkExtent2DFromCGSize(_mtlCAMetalLayer.drawableSize) : kMVKUndefinedExtent;
}

VkExtent2D MVKSurface::getNaturalExtent() {
return _mtlCAMetalLayer ? mvkVkExtent2DFromCGSize(_mtlCAMetalLayer.naturalDrawableSizeMVK) : _headlessExtent;
return _mtlCAMetalLayer ? mvkVkExtent2DFromCGSize(_mtlCAMetalLayer.naturalDrawableSizeMVK) : kMVKUndefinedExtent;
}

// Per spec, headless surface extent is set from the swapchain.
void MVKSurface::setActiveSwapchain(MVKSwapchain* swapchain) {
_activeSwapchain = swapchain;
_headlessExtent = swapchain->getImageExtent();
}

MVKSurface::MVKSurface(MVKInstance* mvkInstance,
Expand Down

0 comments on commit d4d5dcb

Please sign in to comment.