From e8b0cac2c721c7082bb3585e4e1104fd20cfa3d1 Mon Sep 17 00:00:00 2001 From: Alejandro Saucedo Date: Mon, 17 Aug 2020 07:38:00 +0100 Subject: [PATCH] Refactored to use shared pointers --- src/Manager.cpp | 12 ++++++------ src/Manager.hpp | 6 +++--- src/Sequence.cpp | 15 +++++++-------- src/Sequence.hpp | 10 +++++----- 4 files changed, 21 insertions(+), 22 deletions(-) diff --git a/src/Manager.cpp b/src/Manager.cpp index 5103e35be..c850213b8 100644 --- a/src/Manager.cpp +++ b/src/Manager.cpp @@ -119,8 +119,8 @@ void Manager::createInstance() { } #endif - this->mInstance = new vk::Instance(); - vk::createInstance(&computeInstanceCreateInfo, nullptr, this->mInstance); + this->mInstance = std::make_shared(); + vk::createInstance(&computeInstanceCreateInfo, nullptr, this->mInstance.get()); SPDLOG_DEBUG("Kompute Manager Instance Created"); #if DEBUG @@ -199,12 +199,12 @@ void Manager::createDevice() { 1, // Number of deviceQueueCreateInfo &deviceQueueCreateInfo); - this->mDevice = new vk::Device(); - physicalDevice.createDevice(&deviceCreateInfo, nullptr, this->mDevice); + this->mDevice = std::make_shared(); + physicalDevice.createDevice(&deviceCreateInfo, nullptr, this->mDevice.get()); SPDLOG_DEBUG("Kompute Manager device created"); - this->mComputeQueue = new vk::Queue(); - this->mDevice->getQueue(this->mComputeQueueFamilyIndex, 0, this->mComputeQueue); + this->mComputeQueue = std::make_shared(); + this->mDevice->getQueue(this->mComputeQueueFamilyIndex, 0, this->mComputeQueue.get()); SPDLOG_DEBUG("Kompute Manager compute queue obtained"); } diff --git a/src/Manager.hpp b/src/Manager.hpp index 7db6b592a..569a0fef3 100644 --- a/src/Manager.hpp +++ b/src/Manager.hpp @@ -41,13 +41,13 @@ public: private: - vk::Instance* mInstance = nullptr; + std::shared_ptr mInstance = nullptr; bool mFreeInstance = false; uint32_t mPhysicalDeviceIndex = -1; - vk::Device* mDevice = nullptr; + std::shared_ptr mDevice = nullptr; bool mFreeDevice = false; uint32_t mComputeQueueFamilyIndex = -1; - vk::Queue* mComputeQueue = nullptr; + std::shared_ptr mComputeQueue = nullptr; #if DEBUG vk::DebugReportCallbackEXT mDebugReportCallback; diff --git a/src/Sequence.cpp b/src/Sequence.cpp index f2bc2ba36..fa1e66e89 100644 --- a/src/Sequence.cpp +++ b/src/Sequence.cpp @@ -8,7 +8,7 @@ Sequence::Sequence() SPDLOG_DEBUG("Kompute Sequence base constructor"); } -Sequence::Sequence(vk::Device* device, vk::Queue* computeQueue, uint32_t queueIndex) +Sequence::Sequence(std::shared_ptr device, std::shared_ptr computeQueue, uint32_t queueIndex) { SPDLOG_DEBUG("Kompute Sequence Constructor with existing device & queue"); @@ -114,12 +114,10 @@ void Sequence::createCommandPool() { this->mFreeCommandPool = true; - spdlog::info("cmdpoolinfo"); vk::CommandPoolCreateInfo commandPoolInfo(vk::CommandPoolCreateFlags(), this->mQueueIndex); - spdlog::info("about to create"); - this->mCommandPool = new vk::CommandPool(); - this->mDevice->createCommandPool(&commandPoolInfo, nullptr, this->mCommandPool); - spdlog::info("created"); + this->mCommandPool = std::make_shared(); + this->mDevice->createCommandPool(&commandPoolInfo, nullptr, this->mCommandPool.get()); + SPDLOG_DEBUG("Kompute Manager Command Pool Created"); } void Sequence::createCommandBuffer() { @@ -135,8 +133,9 @@ void Sequence::createCommandBuffer() { vk::CommandBufferAllocateInfo commandBufferAllocateInfo(*this->mCommandPool, vk::CommandBufferLevel::ePrimary, 1); - this->mCommandBuffer = new vk::CommandBuffer(); - this->mDevice->allocateCommandBuffers(&commandBufferAllocateInfo, this->mCommandBuffer); + this->mCommandBuffer = std::make_shared(); + this->mDevice->allocateCommandBuffers(&commandBufferAllocateInfo, this->mCommandBuffer.get()); + SPDLOG_DEBUG("Kompute Manager Command Buffer Created"); } } diff --git a/src/Sequence.hpp b/src/Sequence.hpp index afee29fa5..e88894864 100644 --- a/src/Sequence.hpp +++ b/src/Sequence.hpp @@ -18,7 +18,7 @@ private: public: Sequence(); - Sequence(vk::Device* device, vk::Queue* computeQueue, uint32_t queueIndex); + Sequence(std::shared_ptr device, std::shared_ptr computeQueue, uint32_t queueIndex); ~Sequence(); // Record command functions @@ -36,12 +36,12 @@ public: private: - vk::Device* mDevice = nullptr; - vk::Queue* mComputeQueue = nullptr; + std::shared_ptr mDevice = nullptr; + std::shared_ptr mComputeQueue = nullptr; uint32_t mQueueIndex = -1; - vk::CommandPool* mCommandPool = nullptr; + std::shared_ptr mCommandPool = nullptr; bool mFreeCommandPool = false; - vk::CommandBuffer* mCommandBuffer = nullptr; + std::shared_ptr mCommandBuffer = nullptr; bool mFreeCommandBuffer = false; // Record state