From 15c2319ab6a6162d86738edb8279b4b5ed1c1f8e Mon Sep 17 00:00:00 2001 From: PancakeTAS Date: Mon, 30 Jun 2025 00:33:02 +0200 Subject: [PATCH] more utility functions and cleanup --- include/core/buffer.hpp | 4 +++- include/core/commandbuffer.hpp | 4 +++- include/core/commandpool.hpp | 2 ++ include/core/descriptorpool.hpp | 2 ++ include/core/descriptorset.hpp | 22 ++++++++++++++-------- include/core/fence.hpp | 2 ++ include/core/image.hpp | 10 +++++++--- include/core/pipeline.hpp | 2 ++ include/core/sampler.hpp | 2 ++ include/core/semaphore.hpp | 2 ++ include/core/shadermodule.hpp | 4 +++- src/core/commandbuffer.cpp | 2 +- src/core/descriptorset.cpp | 6 +++--- src/core/pipeline.cpp | 2 +- 14 files changed, 47 insertions(+), 19 deletions(-) diff --git a/include/core/buffer.hpp b/include/core/buffer.hpp index 5012501..e0a1bc9 100644 --- a/include/core/buffer.hpp +++ b/include/core/buffer.hpp @@ -16,6 +16,8 @@ namespace Vulkan::Core { /// class Buffer { public: + Buffer() noexcept = default; + /// /// Create the buffer. /// @@ -48,7 +50,7 @@ namespace Vulkan::Core { std::shared_ptr buffer; std::shared_ptr memory; - size_t size; + size_t size{}; }; } diff --git a/include/core/commandbuffer.hpp b/include/core/commandbuffer.hpp index 67f1c4e..f028435 100644 --- a/include/core/commandbuffer.hpp +++ b/include/core/commandbuffer.hpp @@ -35,6 +35,8 @@ namespace Vulkan::Core { /// class CommandBuffer { public: + CommandBuffer() noexcept = default; + /// /// Create the command buffer. /// @@ -62,7 +64,7 @@ namespace Vulkan::Core { /// /// @throws std::logic_error if the command buffer is not in Recording state /// - void dispatch(uint32_t x, uint32_t y, uint32_t z); + void dispatch(uint32_t x, uint32_t y, uint32_t z) const; /// /// End recording commands in the command buffer. diff --git a/include/core/commandpool.hpp b/include/core/commandpool.hpp index 7470d86..247b717 100644 --- a/include/core/commandpool.hpp +++ b/include/core/commandpool.hpp @@ -16,6 +16,8 @@ namespace Vulkan::Core { /// class CommandPool { public: + CommandPool() noexcept = default; + /// /// Create the command pool. /// diff --git a/include/core/descriptorpool.hpp b/include/core/descriptorpool.hpp index 2227a66..0db8018 100644 --- a/include/core/descriptorpool.hpp +++ b/include/core/descriptorpool.hpp @@ -16,6 +16,8 @@ namespace Vulkan::Core { /// class DescriptorPool { public: + DescriptorPool() noexcept = default; + /// /// Create the descriptor pool. /// diff --git a/include/core/descriptorset.hpp b/include/core/descriptorset.hpp index 89c33f7..6ca32f3 100644 --- a/include/core/descriptorset.hpp +++ b/include/core/descriptorset.hpp @@ -12,7 +12,6 @@ #include -#include #include namespace Vulkan::Core { @@ -26,6 +25,8 @@ namespace Vulkan::Core { /// class DescriptorSet { public: + DescriptorSet() noexcept = default; + /// /// Create the descriptor set. /// @@ -36,13 +37,7 @@ namespace Vulkan::Core { /// @throws ls::vulkan_error if object creation fails. /// DescriptorSet(const Device& device, - DescriptorPool pool, const ShaderModule& shaderModule); - - using ResourceList = std::variant< - std::pair&>, - std::pair&>, - std::pair&> - >; + const DescriptorPool& pool, const ShaderModule& shaderModule); /// /// Update the descriptor set with resources. @@ -91,6 +86,17 @@ namespace Vulkan::Core { DescriptorSetUpdateBuilder& add(VkDescriptorType type, const std::vector& buffers) { for (const auto& buffer : buffers) this->add(type, buffer); return *this; } + /// Add an array of resources + template + DescriptorSetUpdateBuilder& add(VkDescriptorType type, const std::array& images) { + for (const auto& image : images) this->add(type, image); return *this; } + template + DescriptorSetUpdateBuilder& add(VkDescriptorType type, const std::array& samplers) { + for (const auto& sampler : samplers) this->add(type, sampler); return *this; } + template + DescriptorSetUpdateBuilder& add(VkDescriptorType type, const std::array& buffers) { + for (const auto& buffer : buffers) this->add(type, buffer); return *this; } + /// Finish building the descriptor set update. void build() const; private: diff --git a/include/core/fence.hpp b/include/core/fence.hpp index e12fe06..c7cf82a 100644 --- a/include/core/fence.hpp +++ b/include/core/fence.hpp @@ -16,6 +16,8 @@ namespace Vulkan::Core { /// class Fence { public: + Fence() noexcept = default; + /// /// Create the fence. /// diff --git a/include/core/image.hpp b/include/core/image.hpp index 775e492..7e7871f 100644 --- a/include/core/image.hpp +++ b/include/core/image.hpp @@ -16,6 +16,8 @@ namespace Vulkan::Core { /// class Image { public: + Image() noexcept = default; + /// /// Create the image. /// @@ -32,6 +34,8 @@ namespace Vulkan::Core { /// Get the Vulkan handle. [[nodiscard]] auto handle() const { return *this->image; } + /// Get the Vulkan device memory handle. + [[nodiscard]] auto getMemory() const { return *this->memory; } /// Get the Vulkan image view handle. [[nodiscard]] auto getView() const { return *this->view; } /// Get the extent of the image. @@ -52,9 +56,9 @@ namespace Vulkan::Core { std::shared_ptr memory; std::shared_ptr view; - VkExtent2D extent; - VkFormat format; - VkImageAspectFlags aspectFlags; + VkExtent2D extent{}; + VkFormat format{}; + VkImageAspectFlags aspectFlags{}; }; } diff --git a/include/core/pipeline.hpp b/include/core/pipeline.hpp index b90fb94..88a32f3 100644 --- a/include/core/pipeline.hpp +++ b/include/core/pipeline.hpp @@ -18,6 +18,8 @@ namespace Vulkan::Core { /// class Pipeline { public: + Pipeline() noexcept = default; + /// /// Create a compute pipeline. /// diff --git a/include/core/sampler.hpp b/include/core/sampler.hpp index b1f9b55..f08817b 100644 --- a/include/core/sampler.hpp +++ b/include/core/sampler.hpp @@ -16,6 +16,8 @@ namespace Vulkan::Core { /// class Sampler { public: + Sampler() noexcept = default; + /// /// Create the sampler. /// diff --git a/include/core/semaphore.hpp b/include/core/semaphore.hpp index 30168b2..41fa7e5 100644 --- a/include/core/semaphore.hpp +++ b/include/core/semaphore.hpp @@ -17,6 +17,8 @@ namespace Vulkan::Core { /// class Semaphore { public: + Semaphore() noexcept = default; + /// /// Create the semaphore. /// diff --git a/include/core/shadermodule.hpp b/include/core/shadermodule.hpp index fcfcf5b..de1f0da 100644 --- a/include/core/shadermodule.hpp +++ b/include/core/shadermodule.hpp @@ -19,6 +19,8 @@ namespace Vulkan::Core { /// class ShaderModule { public: + ShaderModule() noexcept = default; + /// /// Create the shader module. /// @@ -35,7 +37,7 @@ namespace Vulkan::Core { /// Get the Vulkan handle. [[nodiscard]] auto handle() const { return *this->shaderModule; } /// Get the descriptor set layout. - [[nodiscard]] auto getDescriptorSetLayout() const { return *this->descriptorSetLayout; } + [[nodiscard]] auto getLayout() const { return *this->descriptorSetLayout; } /// Trivially copyable, moveable and destructible ShaderModule(const ShaderModule&) noexcept = default; diff --git a/src/core/commandbuffer.cpp b/src/core/commandbuffer.cpp index 5affc4e..6136538 100644 --- a/src/core/commandbuffer.cpp +++ b/src/core/commandbuffer.cpp @@ -41,7 +41,7 @@ void CommandBuffer::begin() { *this->state = CommandBufferState::Recording; } -void CommandBuffer::dispatch(uint32_t x, uint32_t y, uint32_t z) { +void CommandBuffer::dispatch(uint32_t x, uint32_t y, uint32_t z) const { if (*this->state != CommandBufferState::Recording) throw std::logic_error("Command buffer is not in Recording state"); diff --git a/src/core/descriptorset.cpp b/src/core/descriptorset.cpp index de752c0..49e839f 100644 --- a/src/core/descriptorset.cpp +++ b/src/core/descriptorset.cpp @@ -4,9 +4,9 @@ using namespace Vulkan::Core; DescriptorSet::DescriptorSet(const Device& device, - DescriptorPool pool, const ShaderModule& shaderModule) { + const DescriptorPool& pool, const ShaderModule& shaderModule) { // create descriptor set - VkDescriptorSetLayout layout = shaderModule.getDescriptorSetLayout(); + VkDescriptorSetLayout layout = shaderModule.getLayout(); const VkDescriptorSetAllocateInfo desc{ .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO, .descriptorPool = pool.handle(), @@ -21,7 +21,7 @@ DescriptorSet::DescriptorSet(const Device& device, /// store set in shared ptr this->descriptorSet = std::shared_ptr( new VkDescriptorSet(descriptorSetHandle), - [dev = device.handle(), pool = std::move(pool)](VkDescriptorSet* setHandle) { + [dev = device.handle(), pool = pool](VkDescriptorSet* setHandle) { vkFreeDescriptorSets(dev, pool.handle(), 1, setHandle); } ); diff --git a/src/core/pipeline.cpp b/src/core/pipeline.cpp index e20b040..00a8274 100644 --- a/src/core/pipeline.cpp +++ b/src/core/pipeline.cpp @@ -5,7 +5,7 @@ using namespace Vulkan::Core; Pipeline::Pipeline(const Device& device, const ShaderModule& shader) { // create pipeline layout - VkDescriptorSetLayout shaderLayout = shader.getDescriptorSetLayout(); + VkDescriptorSetLayout shaderLayout = shader.getLayout(); const VkPipelineLayoutCreateInfo layoutDesc{ .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, .setLayoutCount = 1,