Skip to content

Commit

Permalink
move wait_on_signal overload for multiple semaphores to class root
Browse files Browse the repository at this point in the history
remove wait_unitl_signal overload that requires manual construction of vk::SemaphoreWaitInfo
  • Loading branch information
MoritzRoth committed Aug 20, 2023
1 parent 38379d1 commit a5c9355
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 44 deletions.
9 changes: 9 additions & 0 deletions include/avk/avk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,15 @@ namespace avk
* @return The created semaphore.
*/
semaphore create_timeline_semaphore(uint64_t aPayload = 0, std::function<void(semaphore_t&)> aAlterConfigBeforeCreation = {});

/**
* @brief Waits on host until the condition specified with the parameters is met.
* @param aSemaphoreValueInfos Span of semaphore_value_info structs, each containing a semaphore and a payload value to wait on. All semaphores are required to be owned by the same logical device.
* @param aWaitOnAll (optional) If true, waits until ALL semaphores have reached their target timestamps. If false, waits until ANY semaphore has reached its target timestamp.
* @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(std::span<avk::semaphore_value_info> aSemaphoreValueInfos, bool aWaitOnAll = true, std::optional<uint64_t> aTimeout = {});
#pragma endregion

#pragma region shader
Expand Down
16 changes: 0 additions & 16 deletions include/avk/semaphore.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,6 @@ namespace avk
*/
void wait_until_signaled(uint64_t aSignalValue, std::optional<uint64_t> aTimeout = {}) const;

///** @brief Waits on host until the condition specified with the parameters is met.
//* @param aSemaphores Vector of timeline semaphores that should be waited on. All semaphores are required to be owned by the same logical device.
//* @param aTimestamps Vector of payload values to wait on. Is required to have the same size as aSemaphores. The n-th value in aTimestamps corresponds to the n-th entry in aSemaphores.
//* @param aWaitOnAll (optional) If true, waits until ALL semaphores have reached their target timestamps. If false, waits until ANY semaphore has reached its target timestamp.
//* @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(std::span<avk::semaphore_signal_info> aSignalInfos, bool aWaitOnAll, std::optional<uint64_t> aTimeout, bool aWaitOnAll = true, std::optional<uint64_t> aTimeout = {});

/** @brief Waits on host until the condition specified with the parameters is met.
* @param aInfo Struct containing all relevant information about the wait operation.
* @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.
*/
void wait_until_signaled(const vk::SemaphoreWaitInfo& aInfo, std::optional<uint64_t> aTimeout = {}) const;

private:
// The semaphore config struct:
vk::SemaphoreCreateInfo mCreateInfo;
Expand Down
53 changes: 25 additions & 28 deletions src/avk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7144,6 +7144,30 @@ namespace avk
});
}

vk::Result root::wait_until_signaled(std::span<avk::semaphore_value_info> aSemaphoreValueInfos, bool aWaitOnAll, std::optional<uint64_t> aTimeout) {
if (aSemaphoreValueInfos.empty()) {
return vk::Result::eSuccess;
}

const vk::Device& device = aSemaphoreValueInfos.front().mSignalSemaphore->mSemaphore.getOwner();
std::vector<vk::Semaphore> semHandles;
std::vector<uint64_t> timestampValues;
for (const auto& svi : aSemaphoreValueInfos) {
assert(device == svi.mSignalSemaphore->mSemaphore.getOwner());
semHandles.push_back(svi.mSignalSemaphore->handle());
timestampValues.push_back(svi.mValue);
}

vk::SemaphoreWaitInfo info(
aWaitOnAll ? vk::SemaphoreWaitFlags{} : vk::SemaphoreWaitFlagBits::eAny,
static_cast<uint32_t>(semHandles.size()),
semHandles.data(),
timestampValues.data()
);

return device.waitSemaphores(info, aTimeout.value_or(UINT64_MAX));
}

semaphore_t& semaphore_t::handle_lifetime_of(any_owning_resource_t aResource)
{
mLifetimeHandledResources.push_back(std::move(aResource));
Expand Down Expand Up @@ -7171,34 +7195,7 @@ namespace avk
handle_addr(),
&aSignalValue
};
wait_until_signaled(info, aTimeout);
}

//vk::Result semaphore_t::wait_until_signaled(std::span<semaphore_signal_info> aSignalInfos, bool aWaitOnAll, std::optional<uint64_t> aTimeout) {
// if (aSemaphores.size() == 0) {
// return vk::Result::eSuccess;
// }

// std::vector<vk::Semaphore> semHandles;
// std::vector<uint64_t> timestampValues;
// for (const auto& ssi : aSignalInfos) {
// semHandles.push_back(ssi.mSignalSemaphore->handle());
// timestampValues.push_back(ssi.mValue);
// }

// vk::SemaphoreWaitInfo info{
// aWaitOnAll ? vk::SemaphoreWaitFlags{} : vk::SemaphoreWaitFlagBits::eAny,
// static_cast<uint32_t>(semHandles.size()),
// semHandles.data(),
// timestampValues.data()
// };

// // assume all semapores use the same device
// return wait_until_signaled(aSemaphores.front().get().mSemaphore.getOwner(), info, aTimeout);
//}

void semaphore_t::wait_until_signaled(const vk::SemaphoreWaitInfo& aInfo, std::optional<uint64_t> aTimeout) const {
mSemaphore.getOwner().waitSemaphores(aInfo, aTimeout.value_or(UINT64_MAX));
mSemaphore.getOwner().waitSemaphores(info, aTimeout.value_or(UINT64_MAX));
}

#pragma endregion
Expand Down

0 comments on commit a5c9355

Please sign in to comment.