From 9c0f0b5f19b7a2134fa5197e3dd045e8e92a9f07 Mon Sep 17 00:00:00 2001 From: MoritzRoth Date: Wed, 5 Jul 2023 20:09:28 +0200 Subject: [PATCH] fix bugged semaphore_wait_until_signaled impl change semaphore_wait/signal_info construction for timeline semaphores --- include/avk/avk.hpp | 9 +++++---- include/avk/commands.hpp | 34 ++++++++++------------------------ include/avk/semaphore.hpp | 2 +- src/avk.cpp | 36 ++++++++++++++++-------------------- 4 files changed, 32 insertions(+), 49 deletions(-) diff --git a/include/avk/avk.hpp b/include/avk/avk.hpp index 0c99902..1c6cde3 100644 --- a/include/avk/avk.hpp +++ b/include/avk/avk.hpp @@ -975,10 +975,11 @@ namespace avk #pragma region semaphore static semaphore create_semaphore(vk::Device aDevice, const DISPATCH_LOADER_CORE_TYPE& aDispatchLoader, std::function aAlterConfigBeforeCreation = {}); semaphore create_semaphore(std::function aAlterConfigBeforeCreation = {}); - /** @brief Creates a timeline semaphore - * @param aPayload (optional) The initial value of the payload. Defaults to 0. - * @param aAlterConfigBeforeCreation (optional) Use it to alter the timeline semaphore configuration before it is actually being created. - * @return The created semaphore. + /** + * @brief Creates a timeline semaphore + * @param aPayload (optional) The initial value of the payload. Defaults to 0. + * @param aAlterConfigBeforeCreation (optional) Use it to alter the timeline semaphore configuration before it is actually being created. + * @return The created semaphore. */ semaphore create_timeline_semaphore(uint64_t aPayload = 0, std::function aAlterConfigBeforeCreation = {}); #pragma endregion diff --git a/include/avk/commands.hpp b/include/avk/commands.hpp index 1819526..dbf6b0c 100644 --- a/include/avk/commands.hpp +++ b/include/avk/commands.hpp @@ -1114,6 +1114,11 @@ namespace avk avk::resource_argument mWaitSemaphore; avk::stage::pipeline_stage_flags mDstStage; uint64_t mValue; + + semaphore_wait_info& at_value(uint64_t aValue) { + mValue = aValue; + return *this; + } }; inline semaphore_wait_info operator>> (avk::resource_argument a, avk::stage::pipeline_stage_flags b) @@ -1121,23 +1126,16 @@ namespace avk return semaphore_wait_info{ std::move(a), b, 0 }; } - inline semaphore_wait_info&& operator| (uint64_t aValue, semaphore_wait_info&& aInfo) - { - aInfo.mValue = aValue; - return std::move(aInfo); - } - - inline semaphore_wait_info& operator| (uint64_t aValue, semaphore_wait_info& aInfo) - { - aInfo.mValue = aValue; - return aInfo; - } - struct semaphore_signal_info { avk::stage::pipeline_stage_flags mSrcStage; avk::resource_argument mSignalSemaphore; uint64_t mValue; + + semaphore_signal_info& to_value(uint64_t aValue) { + mValue = aValue; + return *this; + } }; inline semaphore_signal_info operator>> (avk::stage::pipeline_stage_flags a, avk::resource_argument b) @@ -1145,18 +1143,6 @@ namespace avk return semaphore_signal_info{ a, std::move(b), 0 }; } - inline semaphore_signal_info&& operator| (semaphore_signal_info&& aInfo, uint64_t aValue) - { - aInfo.mValue = aValue; - return std::move(aInfo); - } - - inline semaphore_signal_info& operator| (semaphore_signal_info& aInfo, uint64_t aValue) - { - aInfo.mValue = aValue; - return aInfo; - } - class recorded_command_buffer; diff --git a/include/avk/semaphore.hpp b/include/avk/semaphore.hpp index 25c3ffc..8b1c14b 100644 --- a/include/avk/semaphore.hpp +++ b/include/avk/semaphore.hpp @@ -68,7 +68,7 @@ namespace avk * @param aTimeout (optional) Defines a timeout (in nanoseconds) after which the function returns regardless of the semaphore state. * @return Value of type vk::Result containing information about whether the wait operation succeeded, or the timeout has been triggered. */ - static vk::Result wait_until_signaled(const std::vector &aSemaphores, const std::vector &aTimestamps, bool aWaitOnAll = true, std::optional aTimeout = {}); + static vk::Result wait_until_signaled(const std::span> aSemaphores, const std::span &aTimestamps, bool aWaitOnAll = true, std::optional aTimeout = {}); /** @brief Waits on host until the condition specified with the parameters is met. * @param aDevice The logical device owning all referenced timeline semaphores. diff --git a/src/avk.cpp b/src/avk.cpp index d7c5137..a18da81 100644 --- a/src/avk.cpp +++ b/src/avk.cpp @@ -11,8 +11,6 @@ #endif #endif -#define _SILENCE_CXX20_CISCO646_REMOVED_WARNING - namespace avk { #pragma region root definitions @@ -7133,14 +7131,12 @@ namespace avk semaphore root::create_timeline_semaphore(uint64_t aPayload, std::function aAlterConfigBeforeCreation) { - return create_semaphore(device(), dispatch_loader_core(), [otherAlterations = move(aAlterConfigBeforeCreation), aPayload](semaphore_t& aSem) { - auto typeInfo = std::make_unique(); - typeInfo->semaphoreType = vk::SemaphoreType::eTimeline; - typeInfo->initialValue = aPayload; + auto typeInfo = std::make_unique(); + typeInfo->semaphoreType = vk::SemaphoreType::eTimeline; + typeInfo->initialValue = aPayload; + return create_semaphore(device(), dispatch_loader_core(), [otherAlterations = move(aAlterConfigBeforeCreation), &typeInfo](semaphore_t& aSem) { aSem.create_info().pNext = typeInfo.get(); - aSem.set_custom_deleter([aTypeInfo = move(typeInfo)]() { /* Do nothing ... this lambda just keeps the typeInfo struct alive */ }); - // maybe extend any_owning_resource_t and use handle_lifetime_of instead? if (otherAlterations) { otherAlterations(aSem); @@ -7173,28 +7169,28 @@ namespace avk } vk::Result semaphore_t::wait_until_signaled(uint64_t aRequiredValue, std::optional aTimeout) const { - return wait_until_signaled({ this }, {aRequiredValue} , true, aTimeout); // maybe avoid unnecessary vector construction by just creating SemaphoreWaitInfo in this function + std::vector> semaphores{ *this }; + return wait_until_signaled(semaphores, std::span(&aRequiredValue, 1), true, aTimeout); } - vk::Result semaphore_t::wait_until_signaled(const std::vector& aSemaphores, const std::vector& aTimestamps, bool aWaitOnAll, std::optional aTimeout) { + vk::Result semaphore_t::wait_until_signaled(const std::span> aSemaphores, const std::span& aTimestamps, bool aWaitOnAll, std::optional aTimeout) { assert(aSemaphores.size() == aTimestamps.size()); if (aSemaphores.size() == 0) { return vk::Result::eSuccess; } - std::vector semaphores; - std::transform(aSemaphores.begin(), aSemaphores.end(), std::back_inserter(semaphores), [](const semaphore_t* s) {return &s->mSemaphore.get(); }); + std::vector semaphores; + std::transform(aSemaphores.begin(), aSemaphores.end(), std::back_inserter(semaphores), [](const semaphore_t& s) {return s.mSemaphore.get(); }); - vk::SemaphoreWaitInfo info{}; - info.sType = vk::StructureType::eSemaphoreWaitInfo; - info.pNext = NULL; - info.flags = aWaitOnAll ? vk::SemaphoreWaitFlags() : vk::SemaphoreWaitFlagBits::eAny; - info.semaphoreCount = uint32_t(semaphores.size()); - info.pSemaphores = *(semaphores.data()); - info.pValues = aTimestamps.data(); + vk::SemaphoreWaitInfo info{ + aWaitOnAll ? vk::SemaphoreWaitFlags() : vk::SemaphoreWaitFlagBits::eAny, + static_cast(semaphores.size()), + semaphores.data(), + aTimestamps.data() + }; // assume all semapores use the same device - return wait_until_signaled(aSemaphores.front()->mSemaphore.getOwner(), info, aTimeout); + return wait_until_signaled(aSemaphores.front().get().mSemaphore.getOwner(), info, aTimeout); } vk::Result semaphore_t::wait_until_signaled(const vk::Device& aDevice, const vk::SemaphoreWaitInfo& aInfo, std::optional aTimeout) {