MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ create_layout()

vk::DescriptorSetLayout MayaFlux::Core::VKDescriptorManager::create_layout ( vk::Device  device,
const DescriptorSetLayoutConfig config 
)

Create descriptor set layout from configuration.

Parameters
deviceLogical device
configLayout configuration (bindings)
Returns
Descriptor set layout handle, or null on failure

Layouts are cached - subsequent calls with identical configs return the same layout without recreation.

Example: DescriptorSetLayoutConfig config; config.add_storage_buffer(0); // layout(binding=0) buffer config.add_storage_buffer(1); // layout(binding=1) buffer auto layout = manager.create_layout(device, config);

Definition at line 123 of file VKDescriptorManager.cpp.

126{
127 if (config.bindings.empty()) {
129 "Creating descriptor set layout with no bindings");
130 }
131
132 size_t config_hash = hash_layout_config(config);
133 auto it = m_layout_cache.find(config_hash);
134 if (it != m_layout_cache.end()) {
136 "Reusing cached descriptor set layout (hash: 0x{:X})", config_hash);
137 return m_layouts[it->second];
138 }
139
140 std::vector<vk::DescriptorSetLayoutBinding> vk_bindings;
141 vk_bindings.reserve(config.bindings.size());
142
143 for (const auto& binding : config.bindings) {
144 vk::DescriptorSetLayoutBinding vk_binding;
145 vk_binding.binding = binding.binding;
146 vk_binding.descriptorType = binding.type;
147 vk_binding.descriptorCount = binding.count;
148 vk_binding.stageFlags = binding.stage_flags;
149 vk_binding.pImmutableSamplers = nullptr;
150
151 vk_bindings.push_back(vk_binding);
152 }
153
154 vk::DescriptorSetLayoutCreateInfo layout_info;
155 layout_info.bindingCount = static_cast<uint32_t>(vk_bindings.size());
156 layout_info.pBindings = vk_bindings.data();
157
158 vk::DescriptorSetLayout layout;
159 try {
160 layout = device.createDescriptorSetLayout(layout_info);
161 } catch (const vk::SystemError& e) {
163 "Failed to create descriptor set layout: {}", e.what());
164 return nullptr;
165 }
166
167 size_t layout_index = m_layouts.size();
168 m_layouts.push_back(layout);
169 m_layout_cache[config_hash] = layout_index;
170
172 "Created descriptor set layout ({} bindings, hash: 0x{:X})",
173 config.bindings.size(), config_hash);
174
175 return layout;
176}
#define MF_INFO(comp, ctx,...)
#define MF_ERROR(comp, ctx,...)
#define MF_WARN(comp, ctx,...)
#define MF_DEBUG(comp, ctx,...)
std::unordered_map< size_t, size_t > m_layout_cache
size_t hash_layout_config(const DescriptorSetLayoutConfig &config) const
Compute hash of descriptor set layout config.
std::vector< vk::DescriptorSetLayout > m_layouts
@ GraphicsBackend
Graphics/visual rendering backend (Vulkan, OpenGL)
@ Core
Core engine, backend, subsystems.

References MayaFlux::Core::DescriptorSetLayoutConfig::bindings, MayaFlux::Journal::Core, MayaFlux::Journal::GraphicsBackend, hash_layout_config(), m_layout_cache, m_layouts, MF_DEBUG, MF_ERROR, MF_INFO, and MF_WARN.

+ Here is the call graph for this function: