Refactored to use shared pointers

This commit is contained in:
Alejandro Saucedo 2020-08-17 07:38:00 +01:00
parent 81d592e6e0
commit e8b0cac2c7
4 changed files with 21 additions and 22 deletions

View file

@ -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::Instance>();
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<vk::Device>();
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<vk::Queue>();
this->mDevice->getQueue(this->mComputeQueueFamilyIndex, 0, this->mComputeQueue.get());
SPDLOG_DEBUG("Kompute Manager compute queue obtained");
}

View file

@ -41,13 +41,13 @@ public:
private:
vk::Instance* mInstance = nullptr;
std::shared_ptr<vk::Instance> mInstance = nullptr;
bool mFreeInstance = false;
uint32_t mPhysicalDeviceIndex = -1;
vk::Device* mDevice = nullptr;
std::shared_ptr<vk::Device> mDevice = nullptr;
bool mFreeDevice = false;
uint32_t mComputeQueueFamilyIndex = -1;
vk::Queue* mComputeQueue = nullptr;
std::shared_ptr<vk::Queue> mComputeQueue = nullptr;
#if DEBUG
vk::DebugReportCallbackEXT mDebugReportCallback;

View file

@ -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<vk::Device> device, std::shared_ptr<vk::Queue> 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<vk::CommandPool>();
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<vk::CommandBuffer>();
this->mDevice->allocateCommandBuffers(&commandBufferAllocateInfo, this->mCommandBuffer.get());
SPDLOG_DEBUG("Kompute Manager Command Buffer Created");
}
}

View file

@ -18,7 +18,7 @@ private:
public:
Sequence();
Sequence(vk::Device* device, vk::Queue* computeQueue, uint32_t queueIndex);
Sequence(std::shared_ptr<vk::Device> device, std::shared_ptr<vk::Queue> 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<vk::Device> mDevice = nullptr;
std::shared_ptr<vk::Queue> mComputeQueue = nullptr;
uint32_t mQueueIndex = -1;
vk::CommandPool* mCommandPool = nullptr;
std::shared_ptr<vk::CommandPool> mCommandPool = nullptr;
bool mFreeCommandPool = false;
vk::CommandBuffer* mCommandBuffer = nullptr;
std::shared_ptr<vk::CommandBuffer> mCommandBuffer = nullptr;
bool mFreeCommandBuffer = false;
// Record state