Added function in sequence freeMemoryDestroyGPUResources to de-init

This commit is contained in:
Alejandro Saucedo 2020-11-03 08:59:32 +00:00
parent b636a80d06
commit 5fbb4ce6f6
4 changed files with 62 additions and 38 deletions

View file

@ -28,46 +28,13 @@ Sequence::~Sequence()
SPDLOG_DEBUG("Kompute Sequence Destructor started");
if (!this->mIsInit) {
SPDLOG_WARN("Kompute Sequence destructor called but sequence is not "
"initialized.");
SPDLOG_INFO("Kompute Sequence destructor called but sequence is not "
"initialized so no need to removing GPU resources.");
return;
}
if (!this->mDevice) {
SPDLOG_ERROR(
"Kompute Sequence destructor reached with null Device pointer");
this->mIsInit = false;
return;
else {
this->freeMemoryDestroyGPUResources();
}
if (this->mFreeCommandBuffer) {
SPDLOG_INFO("Freeing CommandBuffer");
if (!this->mCommandBuffer) {
SPDLOG_ERROR("Kompute Sequence destructor reached with null "
"CommandPool pointer");
this->mIsInit = false;
return;
}
this->mDevice->freeCommandBuffers(
*this->mCommandPool, 1, this->mCommandBuffer.get());
SPDLOG_DEBUG("Kompute Sequence Freed CommandBuffer");
}
if (this->mFreeCommandPool) {
SPDLOG_INFO("Destroying CommandPool");
if (this->mCommandPool == nullptr) {
SPDLOG_ERROR("Kompute Sequence destructor reached with null "
"CommandPool pointer");
this->mIsInit = false;
return;
}
this->mDevice->destroy(
*this->mCommandPool,
(vk::Optional<const vk::AllocationCallbacks>)nullptr);
SPDLOG_DEBUG("Kompute Sequence Destroyed CommandPool");
}
this->mIsInit = false;
}
void
@ -234,6 +201,53 @@ Sequence::isInit()
return this->mIsInit;
}
void
Sequence::freeMemoryDestroyGPUResources()
{
if (!this->mIsInit) {
SPDLOG_ERROR("Kompute Sequence freeMemoryDestroyGPUResources called "
"but Sequence is not initialized so there's no relevant GPU resources.");
return;
}
if (!this->mDevice) {
SPDLOG_ERROR(
"Kompute Sequence freeMemoryDestroyGPUResources called with null Device pointer");
this->mIsInit = false;
return;
}
if (this->mFreeCommandBuffer) {
SPDLOG_INFO("Freeing CommandBuffer");
if (!this->mCommandBuffer) {
SPDLOG_ERROR("Kompute Sequence freeMemoryDestroyGPUResources called with null "
"CommandPool pointer");
this->mIsInit = false;
return;
}
this->mDevice->freeCommandBuffers(
*this->mCommandPool, 1, this->mCommandBuffer.get());
SPDLOG_DEBUG("Kompute Sequence Freed CommandBuffer");
}
if (this->mFreeCommandPool) {
SPDLOG_INFO("Destroying CommandPool");
if (this->mCommandPool == nullptr) {
SPDLOG_ERROR("Kompute Sequence freeMemoryDestroyGPUResources called with null "
"CommandPool pointer");
this->mIsInit = false;
return;
}
this->mDevice->destroy(
*this->mCommandPool,
(vk::Optional<const vk::AllocationCallbacks>)nullptr);
SPDLOG_DEBUG("Kompute Sequence Destroyed CommandPool");
}
this->mIsInit = false;
}
void
Sequence::createCommandPool()
{