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();
/**
* 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
* template requires classes to be derived from the OpBase class. This

View File

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

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()
{

View File

@@ -106,6 +106,11 @@ class Sequence
*/
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
* template requires classes to be derived from the OpBase class. This