diff --git a/.gitignore b/.gitignore index eb55056..0b4f101 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,6 @@ /.clangd /.cache /.ccls + +# private shaders +/shaders diff --git a/include/core/commandbuffer.hpp b/include/core/commandbuffer.hpp index b60c437..20a8105 100644 --- a/include/core/commandbuffer.hpp +++ b/include/core/commandbuffer.hpp @@ -4,6 +4,7 @@ #include "core/commandpool.hpp" #include "core/semaphore.hpp" #include "device.hpp" + #include #include diff --git a/include/core/shadermodule.hpp b/include/core/shadermodule.hpp index cdcf3f6..4ef8390 100644 --- a/include/core/shadermodule.hpp +++ b/include/core/shadermodule.hpp @@ -3,10 +3,10 @@ #include "device.hpp" -#include -#include #include +#include +#include #include namespace Vulkan::Core { diff --git a/src/core/commandbuffer.cpp b/src/core/commandbuffer.cpp index 15b4b8d..173b15a 100644 --- a/src/core/commandbuffer.cpp +++ b/src/core/commandbuffer.cpp @@ -1,5 +1,4 @@ #include "core/commandbuffer.hpp" -#include "core/semaphore.hpp" #include "utils/exceptions.hpp" using namespace Vulkan::Core; diff --git a/src/core/fence.cpp b/src/core/fence.cpp index b4d6610..25a515d 100644 --- a/src/core/fence.cpp +++ b/src/core/fence.cpp @@ -1,6 +1,5 @@ #include "core/fence.hpp" #include "utils/exceptions.hpp" -#include using namespace Vulkan::Core; @@ -29,7 +28,7 @@ Fence::Fence(const Device& device) { void Fence::reset() const { if (!this->isValid()) - throw std::runtime_error("Invalid fence"); + throw std::logic_error("Invalid fence"); VkFence fenceHandle = this->handle(); auto res = vkResetFences(this->device, 1, &fenceHandle); @@ -39,7 +38,7 @@ void Fence::reset() const { bool Fence::wait(uint64_t timeout) { if (!this->isValid()) - throw std::runtime_error("Invalid fence"); + throw std::logic_error("Invalid fence"); VkFence fenceHandle = this->handle(); auto res = vkWaitForFences(this->device, 1, &fenceHandle, VK_TRUE, timeout); diff --git a/src/core/semaphore.cpp b/src/core/semaphore.cpp index cc484a9..db4142b 100644 --- a/src/core/semaphore.cpp +++ b/src/core/semaphore.cpp @@ -35,7 +35,7 @@ Semaphore::Semaphore(const Device& device, std::optional initial) { void Semaphore::signal(uint64_t value) const { if (!this->isValid() || !this->isTimeline) - throw std::runtime_error("Invalid timeline semaphore"); + throw std::logic_error("Invalid timeline semaphore"); const VkSemaphoreSignalInfo signalInfo{ .sType = VK_STRUCTURE_TYPE_SEMAPHORE_SIGNAL_INFO, @@ -49,7 +49,7 @@ void Semaphore::signal(uint64_t value) const { bool Semaphore::wait(uint64_t value, uint64_t timeout) { if (!this->isValid() || !this->isTimeline) - throw std::runtime_error("Invalid timeline semaphore"); + throw std::logic_error("Invalid timeline semaphore"); VkSemaphore semaphore = this->handle(); const VkSemaphoreWaitInfo waitInfo{ diff --git a/src/core/shadermodule.cpp b/src/core/shadermodule.cpp index eb7ecb8..f7258d6 100644 --- a/src/core/shadermodule.cpp +++ b/src/core/shadermodule.cpp @@ -29,7 +29,7 @@ ShaderModule::ShaderModule(const Device& device, const std::string& path, const uint8_t* data_ptr = code.data(); const VkShaderModuleCreateInfo createInfo{ .sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO, - .codeSize = code.size() * sizeof(uint32_t), + .codeSize = code.size(), .pCode = reinterpret_cast(data_ptr) }; VkShaderModule shaderModuleHandle{}; diff --git a/src/device.cpp b/src/device.cpp index e854a93..d8e1bcf 100644 --- a/src/device.cpp +++ b/src/device.cpp @@ -52,6 +52,11 @@ Device::Device(const Instance& instance) { // create logical device const float queuePriority{1.0F}; // highest priority + const VkPhysicalDeviceVulkan12Features features{ + .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES, + .timelineSemaphore = VK_TRUE, + .vulkanMemoryModel = VK_TRUE, + }; const VkDeviceQueueCreateInfo computeQueueDesc{ .sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, .queueFamilyIndex = *computeFamilyIdx, @@ -60,6 +65,7 @@ Device::Device(const Instance& instance) { }; const VkDeviceCreateInfo deviceCreateInfo{ .sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, + .pNext = &features, .queueCreateInfoCount = 1, .pQueueCreateInfos = &computeQueueDesc }; diff --git a/src/instance.cpp b/src/instance.cpp index 96a6d68..3b829c9 100644 --- a/src/instance.cpp +++ b/src/instance.cpp @@ -21,7 +21,7 @@ Instance::Instance() { .applicationVersion = VK_MAKE_VERSION(0, 0, 1), .pEngineName = "lsfg-vk-base", .engineVersion = VK_MAKE_VERSION(0, 0, 1), - .apiVersion = VK_API_VERSION_1_4 + .apiVersion = VK_API_VERSION_1_3 }; const VkInstanceCreateInfo createInfo{ .sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, diff --git a/src/main.cpp b/src/main.cpp index 48c0f86..ca594f8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,12 +1,29 @@ +#include "core/shadermodule.hpp" #include "device.hpp" #include "instance.hpp" #include +#include int main() { const Vulkan::Instance instance; const Vulkan::Device device(instance); + const Vulkan::Core::ShaderModule computeShader(device, "shaders/downsample.spv", + { + VK_DESCRIPTOR_TYPE_SAMPLER, + VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, + VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, + VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, + VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, + VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, + VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, + VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, + VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, + VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER + } + ); + std::cerr << "Application finished" << '\n'; return 0; }