Hymn to Beauty
C++ 3D Engine
VulkanBufferAllocator.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "../Interface/BufferAllocator.hpp"
4#include <vulkan/vulkan.h>
5
6namespace Video {
7
8class VulkanRenderer;
9
11class VulkanRawBuffer : public RawBuffer {
12 public:
14
22 VulkanRawBuffer(VulkanRenderer& vulkanRenderer, VkDevice device, VkPhysicalDevice physicalDevice, Buffer::BufferUsage bufferUsage, bool temporary, unsigned int size);
23
25 ~VulkanRawBuffer() final;
26
27 void Write(uint32_t offset, uint32_t size, const void* data) final;
28
30
33 VkBuffer GetBuffer() const;
34
36
39 VkDeviceMemory GetDeviceMemory() const;
40
41 private:
42 VulkanRenderer& vulkanRenderer;
43 VkDevice device;
44 VkPhysicalDevice physicalDevice;
45 VkBuffer buffer;
46 VkDeviceMemory deviceMemory;
47 bool temporary;
48};
49
52 public:
54
61 VulkanBufferAllocator(VulkanRenderer& vulkanRenderer, VkDevice device, VkPhysicalDevice physicalDevice, uint32_t frames, uint32_t nonCoherentAtomSize);
62
65
66 private:
67 VulkanBufferAllocator(const VulkanBufferAllocator& other) = delete;
68
69 uint32_t GetAlignment(Buffer::BufferUsage bufferUsage) final;
70 RawBuffer* Allocate(Buffer::BufferUsage bufferUsage, bool temporary, unsigned int size) final;
71 Buffer* CreateBufferObject(Buffer::BufferUsage bufferUsage, const BufferAllocation& allocation) final;
72
73 uint32_t CalculateAlignment(Buffer::BufferUsage bufferUsage, uint32_t nonCoherentAtomSize);
74
75 VulkanRenderer& vulkanRenderer;
76 VkDevice device;
77 VkPhysicalDevice physicalDevice;
78
79 uint32_t alignments[static_cast<uint32_t>(Buffer::BufferUsage::COUNT)];
80};
81
82}
Responsible for allocating buffers.
Definition: BufferAllocator.hpp:51
A buffer containing GPU accessible data.
Definition: Buffer.hpp:8
BufferUsage
How the buffer is going to be used.
Definition: Buffer.hpp:11
@ COUNT
The number of different buffer usages.
A large buffer from which buffers are sub-allocated.
Definition: BufferAllocator.hpp:21
Vulkan implementation of BufferAllocator.
Definition: VulkanBufferAllocator.hpp:51
~VulkanBufferAllocator() final
Destructor.
Definition: VulkanBufferAllocator.cpp:115
VulkanBufferAllocator(VulkanRenderer &vulkanRenderer, VkDevice device, VkPhysicalDevice physicalDevice, uint32_t frames, uint32_t nonCoherentAtomSize)
Create a new buffer allocator.
Definition: VulkanBufferAllocator.cpp:106
Vulkan implementation of RawBuffer.
Definition: VulkanBufferAllocator.hpp:11
VulkanRawBuffer(VulkanRenderer &vulkanRenderer, VkDevice device, VkPhysicalDevice physicalDevice, Buffer::BufferUsage bufferUsage, bool temporary, unsigned int size)
Create new raw buffer used to satisfy allocations.
Definition: VulkanBufferAllocator.cpp:37
void Write(uint32_t offset, uint32_t size, const void *data) final
Write data to buffer.
Definition: VulkanBufferAllocator.cpp:57
VkBuffer GetBuffer() const
Get the internal Vulkan buffer.
Definition: VulkanBufferAllocator.cpp:98
~VulkanRawBuffer() final
Destructor.
Definition: VulkanBufferAllocator.cpp:52
VkDeviceMemory GetDeviceMemory() const
Get the device memory.
Definition: VulkanBufferAllocator.cpp:102
Low-level renderer implementing Vulkan.
Definition: VulkanRenderer.hpp:24
Definition: Editor.hpp:18
An allocation.
Definition: BufferAllocator.hpp:36