Added initial async capability

This commit is contained in:
Alejandro Saucedo 2020-10-14 21:50:33 +01:00
parent 2f7fc45b2b
commit 8ec486b4ab
3 changed files with 130 additions and 12 deletions

View file

@ -118,38 +118,74 @@ Sequence::end()
bool
Sequence::eval()
{
SPDLOG_DEBUG("Kompute sequence compute recording EVAL");
SPDLOG_DEBUG("Kompute sequence EVAL BEGIN");
if (this->isRecording()) {
SPDLOG_WARN("Kompute Sequence eval called when still recording");
bool evalResult = this->evalAsync();
if (!evalResult) {
SPDLOG_DEBUG("Kompute sequence EVAL FAILURE");
return false;
}
evalResult = this->evalAwait();
SPDLOG_DEBUG("Kompute sequence EVAL SUCCESS");
return evalResult;
}
bool
Sequence::evalAsync()
{
if (this->isRecording()) {
SPDLOG_WARN("Kompute Sequence evalAsync called when still recording");
return false;
}
if (this->mEvalBusy) {
SPDLOG_WARN("Kompute Sequence evalAsync called when an eval async was called without successful wait");
return false;
}
this->mEvalBusy = true;
for (size_t i = 0; i < this->mOperations.size(); i++) {
this->mOperations[i]->preEval();
}
const vk::PipelineStageFlags waitStageMask =
vk::PipelineStageFlagBits::eTransfer;
vk::PipelineStageFlagBits::eTransfer & vk::PipelineStageFlagBits::eComputeShader;
vk::SubmitInfo submitInfo(
0, nullptr, &waitStageMask, 1, this->mCommandBuffer.get());
vk::Fence fence = this->mDevice->createFence(vk::FenceCreateInfo());
this->mFence = this->mDevice->createFence(vk::FenceCreateInfo());
SPDLOG_DEBUG(
"Kompute sequence submitting command buffer into compute queue");
this->mComputeQueue->submit(1, &submitInfo, fence);
this->mDevice->waitForFences(1, &fence, VK_TRUE, UINT64_MAX);
this->mDevice->destroy(fence);
this->mComputeQueue->submit(1, &submitInfo, this->mFence);
}
bool
Sequence::evalAwait(uint64_t waitFor)
{
if (!this->mEvalBusy) {
SPDLOG_WARN("Kompute Sequence evalAwait called without existing eval");
return false;
}
vk::Result result = this->mDevice->waitForFences(1, &this->mFence, VK_TRUE, waitFor);
this->mDevice->destroy(this->mFence);
if (result == vk::Result::eTimeout) {
SPDLOG_WARN("Kompute Sequence evalAwait timed out");
this->mEvalBusy = false;
return false;
}
for (size_t i = 0; i < this->mOperations.size(); i++) {
this->mOperations[i]->postEval();
}
SPDLOG_DEBUG("Kompute sequence EVAL success");
return true;
this->mEvalBusy = false;
}
bool