Mandrill 2025.6.0
Loading...
Searching...
No Matches
Buffer.h
1#pragma once
2
3#include "Common.h"
4
5#include "Device.h"
6#include "Log.h"
7
8namespace Mandrill
9{
14 class Buffer
15 {
16 public:
17 MANDRILL_NON_COPYABLE(Buffer)
18
19
26 MANDRILL_API Buffer(ptr<Device> pDevice, VkDeviceSize size, VkBufferUsageFlags usage,
27 VkMemoryPropertyFlags properties);
28
32 MANDRILL_API ~Buffer();
33
42 MANDRILL_API void copyFromHost(const void* pData, VkDeviceSize size, VkDeviceSize offset = 0);
43
48 MANDRILL_API VkBuffer getBuffer() const
49 {
50 return mBuffer;
51 }
52
57 MANDRILL_API VkDeviceMemory getMemory() const
58 {
59 return mMemory;
60 }
61
66 MANDRILL_API VkBufferUsageFlags getUsage() const
67 {
68 return mUsage;
69 }
70
75 MANDRILL_API VkMemoryPropertyFlags getProperties() const
76 {
77 return mProperties;
78 }
79
84 MANDRILL_API VkDeviceAddress getDeviceAddress() const
85 {
86 VkBufferDeviceAddressInfo ai = {
87 .sType = VK_STRUCTURE_TYPE_BUFFER_DEVICE_ADDRESS_INFO,
88 .buffer = mBuffer,
89 };
90 return vkGetBufferDeviceAddress(mpDevice->getDevice(), &ai);
91 }
92
97 MANDRILL_API void* getHostMap() const
98 {
99 if (!(mProperties & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) {
100 Log::Error("Unable to access host map of buffer that is not host coherent.");
101 return nullptr;
102 }
103 return mpHostMap;
104 }
105
110 MANDRILL_API VkDeviceSize getSize() const
111 {
112 return mSize;
113 }
114
115 private:
116 ptr<Device> mpDevice;
117
118 VkBuffer mBuffer;
119 VkDeviceMemory mMemory;
120 VkBufferUsageFlags mUsage;
121 VkMemoryPropertyFlags mProperties;
122 VkDeviceSize mSize;
123 void* mpHostMap;
124 };
125} // namespace Mandrill
Buffer class for managing Vulkan buffers. This class handles the creation and destruction of buffers,...
Definition Buffer.h:15
MANDRILL_API void copyFromHost(const void *pData, VkDeviceSize size, VkDeviceSize offset=0)
Copy data from host to the buffer. If the buffer was not created to have host-coherent memory,...
Definition Buffer.cpp:61
MANDRILL_API VkBuffer getBuffer() const
Get the buffer handle.
Definition Buffer.h:48
MANDRILL_API VkDeviceAddress getDeviceAddress() const
Get the device address of the buffer.
Definition Buffer.h:84
MANDRILL_API VkBufferUsageFlags getUsage() const
Get the buffer usage flags.
Definition Buffer.h:66
MANDRILL_API ~Buffer()
Destructor for buffer.
Definition Buffer.cpp:48
MANDRILL_API VkMemoryPropertyFlags getProperties() const
Get the memory property flags.
Definition Buffer.h:75
MANDRILL_API VkDeviceSize getSize() const
Get the size of the buffer in bytes.
Definition Buffer.h:110
MANDRILL_API void * getHostMap() const
If the buffer memory is host-coherent, this returns the pointor to the memory.
Definition Buffer.h:97
MANDRILL_API VkDeviceMemory getMemory() const
Get the memory handle.
Definition Buffer.h:57