-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Timeline semaphore support #75
base: development
Are you sure you want to change the base?
Changes from all commits
a598186
f7924e7
ec44689
1fdce85
e42259e
f574c8e
1ccece9
e7c0aee
cde0731
a985b35
3e9b739
352ed57
7491e52
b713674
b00e8cb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1235,31 +1235,132 @@ namespace avk | |
#endif | ||
} | ||
|
||
/** Helper struct to specify a semaphore and a value for it. | ||
* This is used when waiting for / signaling timeline semaphores. | ||
* | ||
* Can be created in the following ways: | ||
* 1) sem = val | ||
* 2) sem >= val | ||
* | ||
* Case 1) makes sense when signaling semaphores, while case 2) makes sense when waiting for semaphores. | ||
*/ | ||
struct semaphore_value_info | ||
{ | ||
avk::resource_argument<avk::semaphore_t> mSemaphore; | ||
uint64_t mValue; | ||
}; | ||
|
||
inline auto operator>=(avk::resource_argument<avk::semaphore_t> aSemaphore, uint64_t aValue) -> semaphore_value_info { | ||
return semaphore_value_info{ std::move(aSemaphore), aValue }; | ||
} | ||
|
||
/** | ||
* @brief Info struct that defines blocking behavior on the gpu at specific pipeline stages for a specific semaphore | ||
* | ||
* Can be created in the following ways: | ||
* 1) sem >> pipelineFlags | ||
* 2) sem >= val >> pipelineFlags | ||
* 3) (sem >= val) >> pipelineFlags | ||
* | ||
* sem... the semaphore to wait for | ||
* val... which semaphore value to wait on (timeline semaphores only) | ||
* pipelineFlags... defines which pipeline stages should wait for the semaphore | ||
*/ | ||
struct semaphore_wait_info | ||
{ | ||
avk::resource_argument<avk::semaphore_t> mWaitSemaphore; | ||
avk::stage::pipeline_stage_flags mDstStage; | ||
uint64_t mValue; | ||
}; | ||
|
||
inline semaphore_wait_info operator>> (avk::resource_argument<avk::semaphore_t> a, avk::stage::pipeline_stage_flags b) | ||
inline auto operator>> (avk::resource_argument<avk::semaphore_t> aSemaphore, avk::stage::pipeline_stage_flags aStageFlags) -> semaphore_wait_info | ||
{ | ||
return semaphore_wait_info{ std::move(aSemaphore), aStageFlags, 0 }; | ||
} | ||
|
||
inline auto operator>> (semaphore_value_info aSemaphoreValueInfo, avk::stage::pipeline_stage_flags aStageFlags) -> semaphore_wait_info | ||
{ | ||
return semaphore_wait_info{ std::move(a), b }; | ||
return semaphore_wait_info{ std::move(aSemaphoreValueInfo.mSemaphore), aStageFlags, aSemaphoreValueInfo.mValue }; | ||
} | ||
|
||
/** | ||
* Allows `waitSemaphore >= waitValue >> pipelineStageFlags` without parentheses around `>=`. | ||
* Requires `operator>>(uint64_t, avk::stage::pipeline_stage_flags) -> semaphore_wait_info` to work | ||
* | ||
* Unwanted side effect: `waitValue >> pipelineStageFlags` compiles but produces an invalid semaphore_wait_info | ||
*/ | ||
inline auto operator>=(avk::resource_argument<avk::semaphore_t> aSemaphore, semaphore_wait_info aSemWaitInfo) -> semaphore_wait_info { | ||
aSemWaitInfo.mWaitSemaphore = std::move(aSemaphore); | ||
return aSemWaitInfo; | ||
} | ||
|
||
/** | ||
* Allows `waitSemaphore >= waitValue >> pipelineStageFlags` without parentheses around `>=` | ||
* Requires `operator>>(uint64_t, avk::stage::pipeline_stage_flags) -> semaphore_wait_info` to work | ||
* | ||
* Unwanted side effect: `waitValue >> pipelineStageFlags` compiles but produces an invalid semaphore_wait_info | ||
*/ | ||
inline auto operator>=(avk::owning_resource<avk::semaphore_t> aSemaphore, semaphore_wait_info aSemWaitInfo)->semaphore_wait_info { | ||
aSemWaitInfo.mWaitSemaphore = std::move(aSemaphore); | ||
return aSemWaitInfo; | ||
} | ||
} // namespace avk | ||
|
||
/** | ||
* Allows `waitSemaphore >= waitValue >> pipelineStageFlags` without parentheses around `>=` | ||
* Requires `operator>=(avk::resource_argument<avk::semaphore_t>, semaphore_wait_info) -> semaphore_wait_info` to work | ||
* | ||
* Unwanted side effect: `waitValue >> pipelineStageFlags` compiles but produces an invalid semaphore_wait_info | ||
* @note This operator overload is defined in global scope because it weirdly wasn't found by auto_vk_toolkit applications otherwise. | ||
*/ | ||
inline auto operator>>(uint64_t aValue, avk::stage::pipeline_stage_flags aStageFlags) -> avk::semaphore_wait_info { | ||
return avk::semaphore_wait_info{ avk::owning_resource<avk::semaphore_t>(), aStageFlags, aValue}; | ||
} | ||
|
||
namespace avk { | ||
Comment on lines
+1307
to
+1320
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When trying to use this operator overload from another solution (i.e. model_loader) the compiler ran into issues finding the function. |
||
|
||
/** | ||
* @brief Info struct that defines semaphore signaling bahavior after specific pipeline stages have concluded | ||
* | ||
* Can be created in the following ways: | ||
* 1) pipelineFlags >> sem | ||
* 2) pipelineFlags >> sem = val | ||
* 3) pipelineFlags >> (sem = val) | ||
* | ||
* pipelineFlags... defines which pipeline stages must be cleared before the semaphore may be signaled | ||
* sem... the semaphore to signal | ||
* val... the value to signal the semaphore to (timeline semaphores only) | ||
*/ | ||
struct semaphore_signal_info | ||
{ | ||
avk::stage::pipeline_stage_flags mSrcStage; | ||
avk::resource_argument<avk::semaphore_t> mSignalSemaphore; | ||
uint64_t mValue; | ||
|
||
/** | ||
* @brief Allows `pipelineFlags >> sem = val` | ||
* | ||
* Due to right associativity of operator= shouldn't cause unwanted side-effects. | ||
* | ||
* @note This does not cover the case `pipelineFlags >> (sem = val)`. | ||
* To allow this ^, explicit template specializations of owning_resource and resource_argument for semaphore_t are defined in semaphore.hpp | ||
* | ||
*/ | ||
auto operator=(uint64_t aValue) -> semaphore_signal_info& { | ||
mValue = aValue; | ||
return *this; | ||
} | ||
}; | ||
|
||
inline semaphore_signal_info operator>> (avk::stage::pipeline_stage_flags a, avk::resource_argument<avk::semaphore_t> b) | ||
inline auto operator>> (avk::stage::pipeline_stage_flags aStageFlags, avk::resource_argument<avk::semaphore_t> aSemaphore) -> semaphore_signal_info | ||
{ | ||
return semaphore_signal_info{ a, std::move(b) }; | ||
return semaphore_signal_info{ aStageFlags, std::move(aSemaphore), 0 }; | ||
} | ||
|
||
inline auto operator>> (avk::stage::pipeline_stage_flags aStageFlags, semaphore_value_info aSemaphoreValueInfo) -> semaphore_signal_info | ||
{ | ||
return semaphore_signal_info{ aStageFlags, std::move(aSemaphoreValueInfo.mSemaphore), aSemaphoreValueInfo.mValue }; | ||
} | ||
|
||
class recorded_command_buffer; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the expression below, the fixed operator precedence of C++ leads to an undesireable evaluation order:
sem >= val >> flags
sem >= (val >> flags)
Because of this I had to define
operator>>(uint64_t, avk::stage::pipeline_stage_flags)
which results in an incompletesemaphore_wait_info
that has to be completed withoperator>=
.