-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatic_ubo.h
More file actions
139 lines (111 loc) · 3.09 KB
/
static_ubo.h
File metadata and controls
139 lines (111 loc) · 3.09 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#pragma once
#include "otcv.h"
#include <cassert>
struct Std140AlignmentType {
enum class InlineType {
Vec4,
Vec3,
Vec2,
Float,
Uint,
Int,
Mat4,
Bool
};
Std140AlignmentType& add(InlineType type, const std::string& name, uint32_t array_count = 1);
Std140AlignmentType& add(Std140AlignmentType& custom_type, const std::string& name, uint32_t array_count = 1);
struct Range {
VkDeviceSize offset;
VkDeviceSize stride;
VkDeviceSize size;
};
std::vector<Range> _field_ranges;
std::map<std::string, size_t> _field_name_range_map; // maps name to _field_ranges index
std::map<std::string, InlineType> _field_name_inline_type_map;
std::map<std::string, Std140AlignmentType> _field_name_custom_type_map;
VkDeviceSize _total_size = 0;
};
struct Std430AlignmentType {
enum class InlineType {
Vec4,
Vec3,
Vec2,
Float,
Uint,
Int,
Mat4,
Bool
};
Std430AlignmentType& add(InlineType type, const std::string& name, uint32_t array_count = 1);
Std430AlignmentType& add(Std430AlignmentType& custom_type, const std::string& name, uint32_t array_count = 1);
struct Range {
VkDeviceSize offset;
VkDeviceSize stride;
VkDeviceSize size;
};
std::vector<Range> _field_ranges;
std::map<std::string, size_t> _field_name_range_map; // maps name to _field_ranges index
std::map<std::string, InlineType> _field_name_inline_type_map;
std::map<std::string, Std430AlignmentType> _field_name_custom_type_map;
VkDeviceSize _total_size = 0;
uint32_t _max_base_alignment = 0;
};
struct BufferObjectAccess {
BufferObjectAccess& operator[](const std::string& name) {
_path.push_back({ name, 0 });
return *this;
}
BufferObjectAccess& operator[](uint32_t id) {
assert(!_path.empty());
assert(!_path.back().field_name.empty());
_path.back().id = id;
return *this;
}
void clear() {
_path.clear();
}
struct Access {
std::string field_name;
uint32_t id;
};
std::vector<Access> _path;
};
typedef BufferObjectAccess StaticUBOAccess;
typedef BufferObjectAccess SSBOAccess;
struct StaticUBO {
StaticUBO(const Std140AlignmentType& layout);
~StaticUBO();
void set(StaticUBOAccess& access, const void* value);
otcv::Buffer* _buf;
Std140AlignmentType _layout;
};
struct StaticUBOArray {
StaticUBOArray(const Std140AlignmentType& layout, uint32_t n_ubos, uint32_t ubo_alignment);
~StaticUBOArray();
void set(uint32_t ubo_id, StaticUBOAccess& access, const void* value);
uint32_t _stride;
uint32_t _n_ubos;
otcv::Buffer* _buf;
Std140AlignmentType _layout;
};
struct SSBO {
SSBO(const Std430AlignmentType& layout, uint32_t n_ssbo, VkBufferUsageFlags additional_usage = 0);
~SSBO();
struct WriteContext {
uint32_t id;
struct AccessContext {
SSBOAccess acc;
const void* value;
};
std::vector<AccessContext> access_ctxs;
};
// should only be used for initializtion. As it idle waits for transfer to finish
// provide asyn version
void write(std::vector<WriteContext>& writes);
Std430AlignmentType::Range range_of(uint32_t id, SSBOAccess& acc);
uint32_t _stride;
uint32_t _n_ubos;
otcv::Buffer* _buf;
std::vector<uint8_t> _staging_buf;
Std430AlignmentType _layout;
};