Skip to content

Commit ecc9881

Browse files
add OUT_OF_DATE reporting to acquireNextImage, make SSharedCreationParams::deduce return true even when width or height is zero even though thats not valid, and factor out the deduction of parameters for re-creation
Still have a bug on the unacquired assert, might want to rethink that.
1 parent 06175cb commit ecc9881

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

include/nbl/video/ISwapchain.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ class ISwapchain : public IBackendObject
3737
return false;
3838
if (height<caps.minImageExtent.height || height>caps.maxImageExtent.height)
3939
return false;
40+
// surface caps might report `minImageExtent=={0,0}` but thats not valid anyway according to Vulkan specification
41+
if (width==0 || height==0)
42+
return false;
4043
if (hlsl::bitCount(compositeAlpha.value)!=1 || !caps.supportedCompositeAlpha.hasFlags(compositeAlpha))
4144
return false;
4245
if (arrayLayers==0 || arrayLayers>caps.maxImageArrayLayers)
@@ -147,8 +150,8 @@ class ISwapchain : public IBackendObject
147150
// in case of no preferred list
148151
if (preTransform.hasFlags(caps.currentTransform))
149152
preTransform = caps.currentTransform;
150-
151-
assert(valid(physDev,surface));
153+
154+
// we might deduce invalid, because of 0-sized renderareas
152155
return true;
153156
}
154157

@@ -332,6 +335,7 @@ class ISwapchain : public IBackendObject
332335
TIMEOUT,
333336
NOT_READY,
334337
SUBOPTIMAL,
338+
OUT_OF_DATE,
335339
_ERROR // GDI macros getting in the way of just ERROR
336340
};
337341
// Even though in Vulkan image acquisition is not a queue operation, we perform a micro-submit to adapt a Timeline Semaphore to work with it
@@ -454,9 +458,13 @@ class ISwapchain : public IBackendObject
454458
};
455459

456460
// utility function
461+
inline bool deduceRecreationParams(SSharedCreationParams& params) const
462+
{
463+
return params.deduce(getOriginDevice()->getPhysicalDevice(),m_params.surface.get(),{&m_params.sharedParams.presentMode.value,1},{&m_params.sharedParams.compositeAlpha.value,1},{&m_params.sharedParams.preTransform.value,1});
464+
}
457465
inline core::smart_refctd_ptr<ISwapchain> recreate(SSharedCreationParams params={})
458466
{
459-
if (!params.deduce(getOriginDevice()->getPhysicalDevice(),m_params.surface.get(),{&m_params.sharedParams.presentMode.value,1},{&m_params.sharedParams.compositeAlpha.value,1},{&m_params.sharedParams.preTransform.value,1}))
467+
if (!deduceRecreationParams(params))
460468
return nullptr;
461469
return recreate_impl(std::move(params));
462470
}

src/nbl/video/CVulkanSwapchain.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,13 +256,16 @@ auto CVulkanSwapchain::acquireNextImage_impl(const SAcquireInfo& info, uint32_t*
256256
case VK_SUBOPTIMAL_KHR:
257257
suboptimal = true;
258258
break;
259+
case VK_ERROR_OUT_OF_DATE_KHR:
260+
return ACQUIRE_IMAGE_RESULT::OUT_OF_DATE;
259261
default:
260262
return ACQUIRE_IMAGE_RESULT::_ERROR;
261263
}
262264
}
263265
const auto imgIx = *out_imgIx;
264266

265267
// The previous present on the image MUST have had finished
268+
// TODO: why do I crash here? maybe cause I don't wait on the acquired fence!
266269
assert(unacquired(imgIx));
267270
// Now put the fence into UNSIGNALLED state where it will stay until "just before" the present
268271
{

0 commit comments

Comments
 (0)