-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuniform_buffer.cppm
More file actions
64 lines (51 loc) · 2.07 KB
/
uniform_buffer.cppm
File metadata and controls
64 lines (51 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
module;
#include <vulkan/vulkan.h>
#include <span>
#include <array>
export module vk:uniform_buffer;
export import :types;
export import :utilities;
export import :command_buffer;
export import :buffer_streams;
export namespace vk {
inline namespace v1 {
/**
* @brief represents a vulkan uniform buffer
*
* Maps uniforms and gpu-specific resources
*/
class uniform_buffer {
public:
uniform_buffer() = default;
uniform_buffer(const VkDevice& p_device,
const uniform_params& p_uniform_info) : m_device(p_device), m_size_bytes(p_uniform_info.size_bytes) {
uint32_t property_flags = memory_property::host_visible_bit |
memory_property::host_coherent_bit;
buffer_parameters uniform_info = {
.device_size = m_size_bytes,
.physical_memory_properties =
p_uniform_info.phsyical_memory_properties,
.property_flags = (memory_property)property_flags,
.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
.debug_name = p_uniform_info.debug_name.c_str(),
.vkSetDebugUtilsObjectNameEXT = p_uniform_info.vkSetDebugUtilsObjectNameEXT
};
m_uniform_handle = buffer_stream(m_device, uniform_info);
}
[[nodiscard]] bool alive() const { return m_uniform_handle; }
void update(const void* p_data) {
m_uniform_handle.write(p_data, m_size_bytes);
}
operator VkBuffer() const { return m_uniform_handle; }
operator VkBuffer() { return m_uniform_handle; }
[[nodiscard]] uint32_t size_bytes() const { return m_size_bytes; }
void destroy() {
m_uniform_handle.destroy();
}
private:
uint32_t m_size_bytes = 0;
VkDevice m_device = nullptr;
buffer_stream m_uniform_handle{};
};
};
};