4#include <vulkan/vulkan.h>
17 template<std::same_as<VkMemoryPropertyFlagBits>... P>
23 VkMemoryRequirements memRequirements;
60 template<std::same_as< VkMemoryPropertyFlagBits>... P>
63 VkPhysicalDeviceMemoryProperties memProperties;
64 vkGetPhysicalDeviceMemoryProperties(+realGpu, &memProperties);
65 auto requiredMemoryPropertiesMask = (requiredMemoryProperties | ...);
68 for (uint32_t i = 0; i < memProperties.memoryTypeCount; i++) {
69 if ((suitableTypesBitmask & (1 << i)) && (memProperties.memoryTypes[i].propertyFlags & requiredMemoryPropertiesMask) == requiredMemoryPropertiesMask) {
83 VkBufferCreateInfo bufferInfo{};
84 bufferInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
85 bufferInfo.size =
size;
86 bufferInfo.usage = usage;
87 bufferInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
90 if (VkResult result = vkCreateBuffer(+
virtualGpu, &bufferInfo,
nullptr, &
buffer); result != VK_SUCCESS) {
98 VkMemoryAllocateInfo allocInfo{};
99 allocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
100 allocInfo.allocationSize = sizeToAllocate;
101 allocInfo.memoryTypeIndex = memoryIndex;
103 if (VkResult result = vkAllocateMemory(+
virtualGpu, &allocInfo,
nullptr, &
bufferMemory); result != VK_SUCCESS) {
const VkBuffer & operator+() const
Definition: Buffer.h:49
Buffer(Buffer &&)=default
Buffer(const LogicalDevice &virtualGpu, const PhysicalDevice &realGpu, size_t size, int usage, P... requiredMemoryProperties)
Definition: Buffer.h:18
VkDeviceMemory & getBufferMemory()
Definition: Buffer.h:54
Buffer & operator=(const Buffer &)=delete
~Buffer()
Definition: Buffer.h:43
const size_t size
Definition: Buffer.h:112
const LogicalDevice & virtualGpu
Definition: Buffer.h:111
static uint32_t findSuitableMemoryIndex(const PhysicalDevice &realGpu, uint32_t suitableTypesBitmask, P... requiredMemoryProperties)
Definition: Buffer.h:61
Buffer & operator=(Buffer &&)=default
Buffer(const Buffer &)=delete
VkDeviceMemory bufferMemory
Definition: Buffer.h:110
void createBuffer(const LogicalDevice &virtualGpu, size_t size, int usage)
Definition: Buffer.h:81
VkBuffer buffer
Definition: Buffer.h:109
void allocateMemory(uint32_t memoryIndex, VkDeviceSize sizeToAllocate)
Definition: Buffer.h:97
A logical device is an abstraction of the physical GPU which we can mainly use to send commands.
Definition: LogicalDevice.h:15
Represents the GPU (or any other device) that will be used with Vulkan to perform computer graphics.
Definition: PhysicalDevice.h:17
Generic runtime exception thrown by Vulkan-related functions.
Definition: VulkanException.h:13