-
-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathpipeline_layout.hpp
More file actions
174 lines (147 loc) · 4.23 KB
/
Copy pathpipeline_layout.hpp
File metadata and controls
174 lines (147 loc) · 4.23 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/**
* @file liblava/block/pipeline_layout.hpp
* @brief Pipeline layout
* @authors Lava Block OÜ and contributors
* @copyright Copyright (c) 2018-present, MIT License
*/
#pragma once
#include "liblava/block/descriptor.hpp"
namespace lava {
/**
* @brief Pipeline layout
*/
struct pipeline_layout : entity {
/// Shared pointer to pipeline layout
using s_ptr = std::shared_ptr<pipeline_layout>;
/// List of pipeline layouts
using s_list = std::vector<s_ptr>;
/**
* @brief Make a new pipeline layout
* @return ptr Shared pointer to pipeline layout
*/
static s_ptr make() {
return std::make_shared<pipeline_layout>();
}
/**
* @see add_descriptor
*/
void add(descriptor::s_ptr const& descriptor) {
m_descriptors.push_back(descriptor);
}
/**
* @see add_push_constant_range
*/
void add(VkPushConstantRange const& range) {
m_push_constant_ranges.push_back(range);
}
/**
* @brief Add descriptor
* @param descriptor Descriptor
*/
void add_descriptor(descriptor::s_ptr const& descriptor) {
add(descriptor);
}
/**
* @brief Add push contant range
* @param range Push contant range
*/
void add_push_constant_range(VkPushConstantRange const& range) {
add(range);
}
/**
* @brief Clear descriptors
*/
void clear_descriptors() {
m_descriptors.clear();
}
/**
* @brief Clear push constant ranges
*/
void clear_ranges() {
m_push_constant_ranges.clear();
}
/**
* @brief Clear descriptors and push constant ranges
*/
void clear() {
clear_descriptors();
clear_ranges();
}
/**
* @brief Create a new pipeline layout
* @param device Vulkan device
* @return Create was successful or failed
*/
bool create(device::ptr device);
/**
* @brief Destroy the pipeline layout
*/
void destroy();
/**
* @brief Get the Vulkan pipeline layout
* @return VkPipelineLayout Pipeline layout
*/
VkPipelineLayout get() const {
return m_layout;
}
/**
* @brief Get the device
* @return device::ptr Vulkan device
*/
device::ptr get_device() {
return m_device;
}
/**
* @brief Get the descriptors
* @return descriptor::s_list const& List of descriptors
*/
descriptor::s_list const& get_descriptors() const {
return m_descriptors;
}
/**
* @brief Get the push constant ranges
* @return VkPushConstantRanges const& List of push constant ranges
*/
VkPushConstantRanges const& get_push_constant_ranges() const {
return m_push_constant_ranges;
}
/// List of offsets
using offset_list = std::vector<index>;
/**
* @brief Bind descriptor set
* @param cmd_buf Command buffer
* @param descriptor_set Descriptor set
* @param first_set Index to first descriptor set
* @param offsets List of offsets
* @param bind_point Pipeline bind point
*/
void bind_descriptor_set(VkCommandBuffer cmd_buf,
VkDescriptorSet descriptor_set,
index first_set = 0,
offset_list offsets = {},
VkPipelineBindPoint bind_point = VK_PIPELINE_BIND_POINT_GRAPHICS);
/**
* @see bind_descriptor_set
*/
void bind(VkCommandBuffer cmd_buf,
VkDescriptorSet descriptor_set,
index first_set = 0,
offset_list offsets = {},
VkPipelineBindPoint bind_point = VK_PIPELINE_BIND_POINT_GRAPHICS) {
bind_descriptor_set(cmd_buf,
descriptor_set,
first_set,
offsets,
bind_point);
}
private:
/// Vulkan device
device::ptr m_device = nullptr;
/// Pipeline layout
VkPipelineLayout m_layout = VK_NULL_HANDLE;
/// List of descriptors
descriptor::s_list m_descriptors;
/// List of push constant ranges
VkPushConstantRanges m_push_constant_ranges;
};
} // namespace lava