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

@ -1100,6 +1100,11 @@ class Sequence
*/ */
bool isInit(); bool isInit();
/**
* Destroys and frees the GPU resources which include the buffer and memory.
*/
void freeMemoryDestroyGPUResources();
/** /**
* Record function for operation to be added to the GPU queue in batch. This * Record function for operation to be added to the GPU queue in batch. This
* template requires classes to be derived from the OpBase class. This * template requires classes to be derived from the OpBase class. This

View file

@ -63,7 +63,7 @@ Manager::~Manager()
"managed sequences"); "managed sequences");
for (const std::pair<std::string, std::shared_ptr<Sequence>>& sqPair : for (const std::pair<std::string, std::shared_ptr<Sequence>>& sqPair :
this->mManagedSequences) { this->mManagedSequences) {
sqPair.second->~Sequence(); sqPair.second->freeMemoryDestroyGPUResources();
} }
this->mManagedSequences.clear(); this->mManagedSequences.clear();
} }

View file

@ -28,46 +28,13 @@ Sequence::~Sequence()
SPDLOG_DEBUG("Kompute Sequence Destructor started"); SPDLOG_DEBUG("Kompute Sequence Destructor started");
if (!this->mIsInit) { if (!this->mIsInit) {
SPDLOG_WARN("Kompute Sequence destructor called but sequence is not " SPDLOG_INFO("Kompute Sequence destructor called but sequence is not "
"initialized."); "initialized so no need to removing GPU resources.");
return; return;
} }
else {
if (!this->mDevice) { this->freeMemoryDestroyGPUResources();
SPDLOG_ERROR(
"Kompute Sequence destructor reached with null Device pointer");
this->mIsInit = false;
return;
} }
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 void
@ -234,6 +201,53 @@ Sequence::isInit()
return this->mIsInit; 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 void
Sequence::createCommandPool() Sequence::createCommandPool()
{ {

View file

@ -106,6 +106,11 @@ class Sequence
*/ */
bool isInit(); bool isInit();
/**
* Destroys and frees the GPU resources which include the buffer and memory.
*/
void freeMemoryDestroyGPUResources();
/** /**
* Record function for operation to be added to the GPU queue in batch. This * Record function for operation to be added to the GPU queue in batch. This
* template requires classes to be derived from the OpBase class. This * template requires classes to be derived from the OpBase class. This