Fixed bug by assigning pointer to heap instead of stack

This commit is contained in:
Alejandro Saucedo 2020-08-17 07:07:23 +01:00
parent 441efcd8dd
commit 81d592e6e0
8 changed files with 58 additions and 35 deletions

View file

@ -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 \

View file

@ -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 <spdlog/spdlog.h>
#include "BaseOperator.hpp"

View file

@ -5,7 +5,6 @@
#include <vulkan/vulkan.h>
#include <vulkan/vulkan.hpp>
namespace kp {
class BaseOperator

View file

@ -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 <set>
#include <string>
#include <spdlog/spdlog.h>
#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<const char*> 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");
}

View file

@ -3,6 +3,11 @@
#include <vulkan/vulkan.h>
#include <vulkan/vulkan.hpp>
// SPDLOG_ACTIVE_LEVEL must be defined before spdlog.h import
#if DEBUG
#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_DEBUG
#endif
#include <spdlog/spdlog.h>
#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<T>(std::forward<TArgs>(args)...);
SPDLOG_DEBUG("Kompute Manager sequence end");
sq.end();
SPDLOG_DEBUG("Kompute Manager sequence eval");
sq.eval();
SPDLOG_DEBUG("Kompute Manager sequence done");
}

View file

@ -1,23 +1,23 @@
#include <string>
#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);
}
}

View file

@ -3,6 +3,13 @@
#include <vulkan/vulkan.h>
#include <vulkan/vulkan.hpp>
// SPDLOG_ACTIVE_LEVEL must be defined before spdlog.h import
#if DEBUG
#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_DEBUG
#endif
#include <spdlog/spdlog.h>
namespace kp {
class Sequence
@ -21,6 +28,7 @@ public:
template <typename T, typename...TArgs>
void record(TArgs&&... args) {
SPDLOG_DEBUG("Kompute Sequence record");
T op(this->mCommandBuffer);
op.init(std::forward<TArgs>(args)...);
op.record();

View file

@ -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;
}
}