more utility functions and cleanup

This commit is contained in:
PancakeTAS 2025-06-30 00:33:02 +02:00
parent b463d71f69
commit 15c2319ab6
No known key found for this signature in database
14 changed files with 47 additions and 19 deletions

View file

@ -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<VkBuffer> buffer;
std::shared_ptr<VkDeviceMemory> memory;
size_t size;
size_t size{};
};
}

View file

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

View file

@ -16,6 +16,8 @@ namespace Vulkan::Core {
///
class CommandPool {
public:
CommandPool() noexcept = default;
///
/// Create the command pool.
///

View file

@ -16,6 +16,8 @@ namespace Vulkan::Core {
///
class DescriptorPool {
public:
DescriptorPool() noexcept = default;
///
/// Create the descriptor pool.
///

View file

@ -12,7 +12,6 @@
#include <vulkan/vulkan_core.h>
#include <variant>
#include <memory>
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<VkDescriptorType, const std::vector<Image>&>,
std::pair<VkDescriptorType, const std::vector<Sampler>&>,
std::pair<VkDescriptorType, const std::vector<Buffer>&>
>;
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<Buffer>& buffers) {
for (const auto& buffer : buffers) this->add(type, buffer); return *this; }
/// Add an array of resources
template<std::size_t N>
DescriptorSetUpdateBuilder& add(VkDescriptorType type, const std::array<Image, N>& images) {
for (const auto& image : images) this->add(type, image); return *this; }
template<std::size_t N>
DescriptorSetUpdateBuilder& add(VkDescriptorType type, const std::array<Sampler, N>& samplers) {
for (const auto& sampler : samplers) this->add(type, sampler); return *this; }
template<std::size_t N>
DescriptorSetUpdateBuilder& add(VkDescriptorType type, const std::array<Buffer, N>& buffers) {
for (const auto& buffer : buffers) this->add(type, buffer); return *this; }
/// Finish building the descriptor set update.
void build() const;
private:

View file

@ -16,6 +16,8 @@ namespace Vulkan::Core {
///
class Fence {
public:
Fence() noexcept = default;
///
/// Create the fence.
///

View file

@ -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<VkDeviceMemory> memory;
std::shared_ptr<VkImageView> view;
VkExtent2D extent;
VkFormat format;
VkImageAspectFlags aspectFlags;
VkExtent2D extent{};
VkFormat format{};
VkImageAspectFlags aspectFlags{};
};
}

View file

@ -18,6 +18,8 @@ namespace Vulkan::Core {
///
class Pipeline {
public:
Pipeline() noexcept = default;
///
/// Create a compute pipeline.
///

View file

@ -16,6 +16,8 @@ namespace Vulkan::Core {
///
class Sampler {
public:
Sampler() noexcept = default;
///
/// Create the sampler.
///

View file

@ -17,6 +17,8 @@ namespace Vulkan::Core {
///
class Semaphore {
public:
Semaphore() noexcept = default;
///
/// Create the semaphore.
///

View file

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

View file

@ -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");

View file

@ -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<VkDescriptorSet>(
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);
}
);

View file

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