Incrased the number of image available semapores to parallel frames + 1 to fix VUID-vkAcquireNextImageKHR-semaphore-01779 due to semaphores still being in use when acquiring the next image.
This commit is contained in:
parent
d41e3588fd
commit
473a3aafab
@ -34,6 +34,7 @@ private:
|
|||||||
|
|
||||||
std::uint32_t mCurrentImageIdx = INVALID_IMAGE_INDEX;
|
std::uint32_t mCurrentImageIdx = INVALID_IMAGE_INDEX;
|
||||||
unsigned mCurrentFrameIdx = 0;
|
unsigned mCurrentFrameIdx = 0;
|
||||||
|
unsigned mCurrentSemaphoreIdx = 0;
|
||||||
ObjectPtr<Window> mWindow;
|
ObjectPtr<Window> mWindow;
|
||||||
std::vector<ObjectPtr<Image>> mImages;
|
std::vector<ObjectPtr<Image>> mImages;
|
||||||
std::vector<ObjectPtr<Semaphore>> mImageAvailableSemaphores;
|
std::vector<ObjectPtr<Semaphore>> mImageAvailableSemaphores;
|
||||||
@ -45,8 +46,8 @@ public:
|
|||||||
~Swapchain() noexcept override;
|
~Swapchain() noexcept override;
|
||||||
|
|
||||||
[[nodiscard]] const ObjectPtr<Window>& getWindow() const noexcept { return mWindow; }
|
[[nodiscard]] const ObjectPtr<Window>& getWindow() const noexcept { return mWindow; }
|
||||||
[[nodiscard]] std::size_t getNumParallelFrames() const noexcept { return mImageAvailableSemaphores.size(); }
|
[[nodiscard]] std::size_t getNumParallelFrames() const noexcept { return mImageAvailableSemaphores.size() - 1; }
|
||||||
[[nodiscard]] const ObjectPtr<Semaphore>& getCurrentAvailableSemaphore() const noexcept { return mImageAvailableSemaphores[mCurrentFrameIdx]; }
|
[[nodiscard]] const ObjectPtr<Semaphore>& getCurrentAvailableSemaphore() const noexcept { return mImageAvailableSemaphores[mCurrentSemaphoreIdx]; }
|
||||||
[[nodiscard]] unsigned getCurrentFrameIdx() const noexcept { return mCurrentFrameIdx; }
|
[[nodiscard]] unsigned getCurrentFrameIdx() const noexcept { return mCurrentFrameIdx; }
|
||||||
[[nodiscard]] const std::vector<ObjectPtr<Image>>& getImages() const noexcept { return mImages; }
|
[[nodiscard]] const std::vector<ObjectPtr<Image>>& getImages() const noexcept { return mImages; }
|
||||||
[[nodiscard]] std::uint32_t getCurrentImageIdx() const noexcept { return mCurrentImageIdx; }
|
[[nodiscard]] std::uint32_t getCurrentImageIdx() const noexcept { return mCurrentImageIdx; }
|
||||||
|
@ -97,8 +97,9 @@ Swapchain::Swapchain(ObjectPtr<Device> owner, SwapchainCreationArgs args)
|
|||||||
: super_t(std::move(owner)), mWindow(std::move(args.window)), mImageUsage(args.imageUsage)
|
: super_t(std::move(owner)), mWindow(std::move(args.window)), mImageUsage(args.imageUsage)
|
||||||
{
|
{
|
||||||
MIJIN_ASSERT(mWindow, "Invalid SwapchainCreationArgs: window cannot be NULL.");
|
MIJIN_ASSERT(mWindow, "Invalid SwapchainCreationArgs: window cannot be NULL.");
|
||||||
|
MIJIN_ASSERT_FATAL(args.parallelFrames > 0, "Invalid SwapchainCreationArgs: parallelFrames must be > 0.");
|
||||||
|
|
||||||
mImageAvailableSemaphores.resize(args.parallelFrames);
|
mImageAvailableSemaphores.resize(args.parallelFrames - 1);
|
||||||
recreate();
|
recreate();
|
||||||
}
|
}
|
||||||
Swapchain::~Swapchain() noexcept
|
Swapchain::~Swapchain() noexcept
|
||||||
@ -131,6 +132,8 @@ mijin::Task<> Swapchain::c_present(const PresentArgs& args)
|
|||||||
|
|
||||||
// next image, please
|
// next image, please
|
||||||
mCurrentFrameIdx = (mCurrentFrameIdx + 1) % static_cast<int>(getNumParallelFrames());
|
mCurrentFrameIdx = (mCurrentFrameIdx + 1) % static_cast<int>(getNumParallelFrames());
|
||||||
|
mCurrentSemaphoreIdx = (mCurrentSemaphoreIdx + 1) % static_cast<int>(mImageAvailableSemaphores.size());
|
||||||
|
// logMsg("frame: {}, semaphore: {}", mCurrentFrameIdx, mCurrentSemaphoreIdx);
|
||||||
if (result == vk::Result::eSuccess) {
|
if (result == vk::Result::eSuccess) {
|
||||||
co_await c_acquireImage();
|
co_await c_acquireImage();
|
||||||
}
|
}
|
||||||
@ -280,7 +283,7 @@ void Swapchain::acquireImage()
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
const vk::ResultValue<std::uint32_t> result = getOwner()->getVkHandle().acquireNextImageKHR(mHandle, std::numeric_limits<std::uint64_t>::max(), *mImageAvailableSemaphores[mCurrentFrameIdx]);
|
const vk::ResultValue<std::uint32_t> result = getOwner()->getVkHandle().acquireNextImageKHR(mHandle, std::numeric_limits<std::uint64_t>::max(), *getCurrentAvailableSemaphore());
|
||||||
if (result.result != vk::Result::eSuccess)
|
if (result.result != vk::Result::eSuccess)
|
||||||
{
|
{
|
||||||
assert(result.result == vk::Result::eSuboptimalKHR);
|
assert(result.result == vk::Result::eSuboptimalKHR);
|
||||||
@ -302,7 +305,7 @@ mijin::Task<> Swapchain::c_acquireImage()
|
|||||||
vk::ResultValue<std::uint32_t> result = vk::ResultValue<std::uint32_t>(vk::Result::eTimeout, 0);
|
vk::ResultValue<std::uint32_t> result = vk::ResultValue<std::uint32_t>(vk::Result::eTimeout, 0);
|
||||||
while(true)
|
while(true)
|
||||||
{
|
{
|
||||||
result = getOwner()->getVkHandle().acquireNextImageKHR(mHandle, 0, *mImageAvailableSemaphores[mCurrentFrameIdx]);
|
result = getOwner()->getVkHandle().acquireNextImageKHR(mHandle, 0, *getCurrentAvailableSemaphore());
|
||||||
if (result.result != vk::Result::eTimeout && result.result != vk::Result::eNotReady) {
|
if (result.result != vk::Result::eTimeout && result.result != vk::Result::eNotReady) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user