From 81d592e6e0dc719cc8313555d4bbd7c4bc82a3aa Mon Sep 17 00:00:00 2001 From: Alejandro Saucedo Date: Mon, 17 Aug 2020 07:07:23 +0100 Subject: [PATCH] Fixed bug by assigning pointer to heap instead of stack --- Makefile | 5 +++-- src/BaseOperator.cpp | 5 +++++ src/BaseOperator.hpp | 1 - src/Manager.cpp | 26 ++++++++------------------ src/Manager.hpp | 10 ++++++++++ src/Sequence.cpp | 29 ++++++++++++++++++----------- src/Sequence.hpp | 8 ++++++++ src/main.cpp | 9 ++++++--- 8 files changed, 58 insertions(+), 35 deletions(-) diff --git a/Makefile b/Makefile index 60c5ba661..6583f0b55 100644 --- a/Makefile +++ b/Makefile @@ -14,9 +14,9 @@ SCMP=/c/VulkanSDK/1.2.141.2/Bin32/glslangValidator.exe build: build_shaders $(CC) \ - -Wall \ + -g -fexceptions -fPIC \ src/* \ - -std=c++17 \ + -std=c++14 \ -DDEBUG=1 \ -I"./external/" \ -I"./src/" \ @@ -27,6 +27,7 @@ build: build_shaders build_linux: g++ \ + -g -shared-libgcc \ -Wall \ src/* \ -std=c++17 \ diff --git a/src/BaseOperator.cpp b/src/BaseOperator.cpp index ff4b94f4f..9bea5929b 100644 --- a/src/BaseOperator.cpp +++ b/src/BaseOperator.cpp @@ -1,4 +1,9 @@ +// SPDLOG_ACTIVE_LEVEL must be defined before spdlog.h import +#if DEBUG +#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_DEBUG +#endif + #include #include "BaseOperator.hpp" diff --git a/src/BaseOperator.hpp b/src/BaseOperator.hpp index a9335b506..32d54963b 100644 --- a/src/BaseOperator.hpp +++ b/src/BaseOperator.hpp @@ -5,7 +5,6 @@ #include #include - namespace kp { class BaseOperator diff --git a/src/Manager.cpp b/src/Manager.cpp index b417f3749..5103e35be 100644 --- a/src/Manager.cpp +++ b/src/Manager.cpp @@ -1,17 +1,7 @@ -#if defined(_WIN32) -#pragma comment(linker, "/subsystem:console") -#endif - -// SPDLOG_ACTIVE_LEVEL must be defined before spdlog.h import -#if DEBUG -#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_DEBUG -#endif #include #include -#include - #include "Manager.hpp" namespace kp { @@ -80,8 +70,8 @@ void Manager::createInstance() { this->mFreeInstance = true; vk::ApplicationInfo applicationInfo; - applicationInfo.pApplicationName = "Vulkan compute"; - applicationInfo.pEngineName = "VulkanCompute"; + applicationInfo.pApplicationName = "Vulkan Kompute"; + applicationInfo.pEngineName = "VulkanKompute"; applicationInfo.apiVersion = VK_API_VERSION_1_2; std::vector applicationExtensions; @@ -129,8 +119,8 @@ void Manager::createInstance() { } #endif - vk::Instance instance = vk::createInstance(computeInstanceCreateInfo); - this->mInstance = &instance; + this->mInstance = new vk::Instance(); + vk::createInstance(&computeInstanceCreateInfo, nullptr, this->mInstance); SPDLOG_DEBUG("Kompute Manager Instance Created"); #if DEBUG @@ -209,12 +199,12 @@ void Manager::createDevice() { 1, // Number of deviceQueueCreateInfo &deviceQueueCreateInfo); - vk::Device device = physicalDevice.createDevice(deviceCreateInfo); - this->mDevice = &device; + this->mDevice = new vk::Device(); + physicalDevice.createDevice(&deviceCreateInfo, nullptr, this->mDevice); SPDLOG_DEBUG("Kompute Manager device created"); - vk::Queue computeQueue = this->mDevice->getQueue(this->mComputeQueueFamilyIndex, 0); - this->mComputeQueue = &computeQueue; + this->mComputeQueue = new vk::Queue(); + this->mDevice->getQueue(this->mComputeQueueFamilyIndex, 0, this->mComputeQueue); SPDLOG_DEBUG("Kompute Manager compute queue obtained"); } diff --git a/src/Manager.hpp b/src/Manager.hpp index 0f573b78c..7db6b592a 100644 --- a/src/Manager.hpp +++ b/src/Manager.hpp @@ -3,6 +3,11 @@ #include #include +// SPDLOG_ACTIVE_LEVEL must be defined before spdlog.h import +#if DEBUG +#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_DEBUG +#endif + #include #include "Sequence.hpp" @@ -23,10 +28,15 @@ public: void eval(TArgs&&... args) { SPDLOG_DEBUG("Kompute Manager eval triggered"); Sequence sq(this->mDevice, this->mComputeQueue, this->mComputeQueueFamilyIndex); + SPDLOG_DEBUG("Kompute Manager created sequence"); sq.begin(); + SPDLOG_DEBUG("Kompute Manager sequence begin"); sq.record(std::forward(args)...); + SPDLOG_DEBUG("Kompute Manager sequence end"); sq.end(); + SPDLOG_DEBUG("Kompute Manager sequence eval"); sq.eval(); + SPDLOG_DEBUG("Kompute Manager sequence done"); } diff --git a/src/Sequence.cpp b/src/Sequence.cpp index a2d6cdf54..f2bc2ba36 100644 --- a/src/Sequence.cpp +++ b/src/Sequence.cpp @@ -1,23 +1,23 @@ -#include - -#include "spdlog/spdlog.h" - #include "Sequence.hpp" namespace kp { Sequence::Sequence() { - // TODO: Create device, queue, etc + SPDLOG_DEBUG("Kompute Sequence base constructor"); } Sequence::Sequence(vk::Device* device, vk::Queue* computeQueue, uint32_t queueIndex) { - SPDLOG_DEBUG("Kompute Sequence Created with existing device & queue"); + SPDLOG_DEBUG("Kompute Sequence Constructor with existing device & queue"); + this->mDevice = device; this->mComputeQueue = computeQueue; this->mQueueIndex = queueIndex; + + this->createCommandPool(); + this->createCommandBuffer(); } Sequence::~Sequence() { @@ -103,15 +103,23 @@ void Sequence::eval() { void Sequence::createCommandPool() { SPDLOG_DEBUG("Kompute Sequence creating command pool"); + if (this->mDevice == nullptr) { + spdlog::info("cmdpoolinfo"); + throw std::runtime_error("Kompute Sequence device is null"); + } if (this->mQueueIndex < 0) { + spdlog::info("Queue index {}", this->mQueueIndex); throw std::runtime_error("Kompute Sequence queue index not provided"); } this->mFreeCommandPool = true; + spdlog::info("cmdpoolinfo"); vk::CommandPoolCreateInfo commandPoolInfo(vk::CommandPoolCreateFlags(), this->mQueueIndex); - vk::CommandPool commandPool = this->mDevice->createCommandPool(commandPoolInfo); - this->mCommandPool = &commandPool; + spdlog::info("about to create"); + this->mCommandPool = new vk::CommandPool(); + this->mDevice->createCommandPool(&commandPoolInfo, nullptr, this->mCommandPool); + spdlog::info("created"); } void Sequence::createCommandBuffer() { @@ -127,9 +135,8 @@ void Sequence::createCommandBuffer() { vk::CommandBufferAllocateInfo commandBufferAllocateInfo(*this->mCommandPool, vk::CommandBufferLevel::ePrimary, 1); - vk::CommandBuffer commandBuffer; - this->mDevice->allocateCommandBuffers(&commandBufferAllocateInfo, &commandBuffer); - this->mCommandBuffer = &commandBuffer; + this->mCommandBuffer = new vk::CommandBuffer(); + this->mDevice->allocateCommandBuffers(&commandBufferAllocateInfo, this->mCommandBuffer); } } diff --git a/src/Sequence.hpp b/src/Sequence.hpp index 7bc861aff..afee29fa5 100644 --- a/src/Sequence.hpp +++ b/src/Sequence.hpp @@ -3,6 +3,13 @@ #include #include +// SPDLOG_ACTIVE_LEVEL must be defined before spdlog.h import +#if DEBUG +#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_DEBUG +#endif + +#include + namespace kp { class Sequence @@ -21,6 +28,7 @@ public: template void record(TArgs&&... args) { + SPDLOG_DEBUG("Kompute Sequence record"); T op(this->mCommandBuffer); op.init(std::forward(args)...); op.record(); diff --git a/src/main.cpp b/src/main.cpp index 8efc08b9f..98e71e304 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -612,9 +612,9 @@ main() #endif try { - //VulkanCompute* vulkanExample = new VulkanCompute(); - //spdlog::info("Finished."); - //delete (vulkanExample); + VulkanCompute* vulkanExample = new VulkanCompute(); + spdlog::info("Finished."); + delete (vulkanExample); // Run Kompute spdlog::info("Creating manager"); @@ -626,5 +626,8 @@ main() } catch (const std::exception& exc) { spdlog::error(exc.what()); return 1; + } catch (...) { + spdlog::error("Uncaught exception"); + return 1; } }