Fixes from PR review of VK_EXT_swapchain_maintenance1 and VK_EXT_surface_maintenance1.

- Pass MVKImagePresentInfo struct by reference instead of copy.
- Remove unused boolean to pass around
  VK_SWAPCHAIN_CREATE_DEFERRED_MEMORY_ALLOCATION_BIT_EXT status.
This commit is contained in:
Bill Hollings 2023-02-12 19:02:47 +00:00
parent e480e1570b
commit 2f87f85278
6 changed files with 15 additions and 23 deletions

View File

@ -544,7 +544,6 @@ public:
MVKPresentableSwapchainImage* createPresentableSwapchainImage(const VkImageCreateInfo* pCreateInfo,
MVKSwapchain* swapchain,
uint32_t swapchainIndex,
bool deferImgMemAlloc,
const VkAllocationCallbacks* pAllocator);
void destroyPresentableSwapchainImage(MVKPresentableSwapchainImage* mvkImg,
const VkAllocationCallbacks* pAllocator);

View File

@ -3573,11 +3573,9 @@ void MVKDevice::destroySwapchain(MVKSwapchain* mvkSwpChn,
MVKPresentableSwapchainImage* MVKDevice::createPresentableSwapchainImage(const VkImageCreateInfo* pCreateInfo,
MVKSwapchain* swapchain,
uint32_t swapchainIndex,
bool deferImgMemAlloc,
const VkAllocationCallbacks* pAllocator) {
MVKPresentableSwapchainImage* mvkImg = new MVKPresentableSwapchainImage(this, pCreateInfo,
swapchain, swapchainIndex,
deferImgMemAlloc);
swapchain, swapchainIndex);
for (auto& memoryBinding : mvkImg->_memoryBindings) {
addResource(memoryBinding);
}

View File

@ -449,16 +449,13 @@ public:
#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
MVKPresentableSwapchainImage(MVKDevice* device,
const VkImageCreateInfo* pCreateInfo,
MVKSwapchain* swapchain,
uint32_t swapchainIndex,
bool deferImgMemAlloc);
MVKPresentableSwapchainImage(MVKDevice* device, const VkImageCreateInfo* pCreateInfo,
MVKSwapchain* swapchain, uint32_t swapchainIndex);
~MVKPresentableSwapchainImage() override;
@ -466,7 +463,7 @@ protected:
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);

View File

@ -1296,7 +1296,7 @@ id<CAMetalDrawable> MVKPresentableSwapchainImage::getCAMetalDrawable() {
// Present the drawable and make myself available only once the command buffer has completed.
void MVKPresentableSwapchainImage::presentCAMetalDrawable(id<MTLCommandBuffer> mtlCmdBuff,
MVKImagePresentInfo presentInfo) {
MVKImagePresentInfo& presentInfo) {
lock_guard<mutex> lock(_availabilityLock);
_swapchain->willPresentSurface(getMTLTexture(0), mtlCmdBuff);
@ -1359,7 +1359,7 @@ void MVKPresentableSwapchainImage::presentCAMetalDrawable(id<MTLCommandBuffer> m
}
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
@ -1418,13 +1418,10 @@ void MVKPresentableSwapchainImage::makeAvailable() {
#pragma mark Construction
// The deferImgMemAlloc parameter is ignored, because image memory allocation is provided by a MTLDrawable,
// which is retrieved lazily, and hence is already as deferred (or as deferred as we can make it).
MVKPresentableSwapchainImage::MVKPresentableSwapchainImage(MVKDevice* device,
const VkImageCreateInfo* pCreateInfo,
MVKSwapchain* swapchain,
uint32_t swapchainIndex,
bool deferImgMemAlloc) :
uint32_t swapchainIndex) :
MVKSwapchainImage(device, pCreateInfo, swapchain, swapchainIndex) {
_mtlDrawable = nil;

View File

@ -132,10 +132,10 @@ protected:
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(MVKImagePresentInfo& presentInfo, uint64_t actualPresentTime = 0);
CAMetalLayer* _mtlLayer = nil;
MVKWatermark* _licenseWatermark = nil;
MVKWatermark* _licenseWatermark = nullptr;
MVKSmallVector<MVKPresentableSwapchainImage*, kMVKMaxSwapchainImageCount> _presentableImages;
MVKSmallVector<VkPresentModeKHR, 2> _compatiblePresentModes;
static const int kMaxPresentationHistory = 60;

View File

@ -469,11 +469,12 @@ void MVKSwapchain::initSurfaceImages(const VkSwapchainCreateInfoKHR* pCreateInfo
mvkEnableFlags(imgInfo.flags, VK_IMAGE_CREATE_SPLIT_INSTANCE_BIND_REGIONS_BIT);
}
bool deferImgMemAlloc = mvkAreAllFlagsEnabled(pCreateInfo->flags, VK_SWAPCHAIN_CREATE_DEFERRED_MEMORY_ALLOCATION_BIT_EXT);
// The VK_SWAPCHAIN_CREATE_DEFERRED_MEMORY_ALLOCATION_BIT_EXT flag is ignored, because
// swapchain image memory allocation is provided by a MTLDrawable, which is retrieved
// lazily, and hence is already deferred (or as deferred as we can make it).
for (uint32_t imgIdx = 0; imgIdx < imgCnt; imgIdx++) {
_presentableImages.push_back(_device->createPresentableSwapchainImage(&imgInfo, this, imgIdx,
deferImgMemAlloc, NULL));
_presentableImages.push_back(_device->createPresentableSwapchainImage(&imgInfo, this, imgIdx, nullptr));
}
NSString* screenName = @"Main Screen";
@ -543,7 +544,7 @@ VkResult MVKSwapchain::getPastPresentationTiming(uint32_t *pCount, VkPastPresent
return res;
}
void MVKSwapchain::recordPresentTime(MVKImagePresentInfo presentInfo, uint64_t actualPresentTime) {
void MVKSwapchain::recordPresentTime(MVKImagePresentInfo& presentInfo, uint64_t actualPresentTime) {
std::lock_guard<std::mutex> lock(_presentHistoryLock);
if (_presentHistoryCount < kMaxPresentationHistory) {
_presentHistoryCount++;