improved docs

This commit is contained in:
Jorijn van der Graaf 2025-06-14 14:58:02 +02:00
commit dfe9b1abe9
16 changed files with 315 additions and 40 deletions

View file

@ -28,13 +28,31 @@ export module Crafter.Graphics:VulkanBuffer;
import :VulkanDevice;
namespace Crafter {
/**
* @brief VkBuffer holder.
* Stores a value and handles buffer mapping and lifetime management.
* @tparam T The value to store.
*/
export template <typename T>
class Buffer {
public:
T* value;
VkDescriptorBufferInfo descriptor;
VkBuffer buffer = VK_NULL_HANDLE;
VkDeviceMemory memory = VK_NULL_HANDLE;
public:
/**
* @brief Creates and initializes a Vulkan buffer with the specified usage and memory properties.
*
* This constructor allocates a buffer capable of holding `count` elements of type T.
* The buffer usage and memory property flags control how the buffer will be used
* and how its memory is managed.
*
* @param usageFlags Vulkan buffer usage flags that define allowed operations on the buffer
* (e.g., vertex buffer, index buffer, uniform buffer).
* @param memoryPropertyFlags Vulkan memory property flags specifying the desired memory
* properties (e.g., device local, host visible).
* @param count Number of elements to allocate space for in the buffer. The total buffer size
* will be `count * sizeof(T)`. Must be above 0.
*/
Buffer(VkBufferUsageFlags usageFlags, VkMemoryPropertyFlags memoryPropertyFlags, std::uint32_t count = 1) {
VkBufferCreateInfo bufferCreateInfo = vks::initializers::bufferCreateInfo(usageFlags, sizeof(T)*count);
VulkanDevice::CHECK_VK_RESULT(vkCreateBuffer(VulkanDevice::device, &bufferCreateInfo, nullptr, &buffer));
@ -66,6 +84,9 @@ namespace Crafter {
VulkanDevice::CHECK_VK_RESULT(vkBindBufferMemory(VulkanDevice::device, buffer, memory, 0));
VulkanDevice::CHECK_VK_RESULT(vkMapMemory(VulkanDevice::device, memory, 0, sizeof(T)*count, 0, reinterpret_cast<void**>(&value)));
}
/**
* @brief Frees all resources assosiacted with the buffer.
*/
~Buffer() {
vkUnmapMemory(VulkanDevice::device, memory);
vkDestroyBuffer(VulkanDevice::device, buffer, nullptr);
@ -75,5 +96,7 @@ namespace Crafter {
VkDeviceSize alignment = 0;
VkMemoryPropertyFlags memoryPropertyFlags;
VkBufferUsageFlags usageFlags;
VkBuffer buffer = VK_NULL_HANDLE;
VkDeviceMemory memory = VK_NULL_HANDLE;
};
}