104 std::map<uint32_t, std::set<uint32_t>> usedBindings;
105 std::map<uint32_t, std::map<std::string, uint32_t>> resourceBindings;
106 std::map<uint32_t, std::vector<vk::DescriptorSetLayoutBinding>> setBindings;
112 auto constBufferLocations = shaderBinary.constBufferLocations();
113 auto constBufferLayouts = shaderBinary.constBufferLayout();
115 for (
const auto& [name, location] : constBufferLocations)
117 uint32_t set = location.first;
118 uint32_t binding = location.second;
120 if (resourceBindings[set].find(name) != resourceBindings[set].end()) {
124 resourceBindings[set][name] = binding;
125 usedBindings[set].insert(binding);
127 auto layoutIt = constBufferLayouts.find(name);
128 if (layoutIt == constBufferLayouts.end()) {
135 vk::DescriptorSetLayoutBinding layoutBinding(
137 vk::DescriptorType::eUniformBuffer,
143 setBindings[set].push_back(layoutBinding);
146 auto textureLocations = shaderBinary.textureLocations();
147 auto textureLayouts = shaderBinary.textureLayout();
149 for (
const auto& [name, location] : textureLocations)
151 uint32_t set = location.first;
152 uint32_t binding = location.second;
154 if (resourceBindings[set].find(name) != resourceBindings[set].end()) {
158 if (usedBindings[set].find(binding) != usedBindings[set].end()) {
160 while (usedBindings[set].find(binding) != usedBindings[set].end()) {
165 resourceBindings[set][name] = binding;
166 usedBindings[set].insert(binding);
168 auto layoutIt = textureLayouts.find(name);
169 if (layoutIt == textureLayouts.end()) {
176 vk::DescriptorSetLayoutBinding layoutBinding(
178 vk::DescriptorType::eSampledImage,
184 setBindings[set].push_back(layoutBinding);
187 auto samplerLocations = shaderBinary.samplerLocations();
188 auto samplerLayouts = shaderBinary.samplerLayout();
190 for (
const auto& [name, location] : samplerLocations)
192 uint32_t set = location.first;
193 uint32_t binding = location.second;
195 if (resourceBindings[set].find(name) != resourceBindings[set].end()) {
199 if (usedBindings[set].find(binding) != usedBindings[set].end()) {
201 while (usedBindings[set].find(binding) != usedBindings[set].end()) {
206 resourceBindings[set][name] = binding;
207 usedBindings[set].insert(binding);
209 auto layoutIt = samplerLayouts.find(name);
210 if (layoutIt == samplerLayouts.end()) {
217 vk::DescriptorSetLayoutBinding layoutBinding(
219 vk::DescriptorType::eSampler,
225 setBindings[set].push_back(layoutBinding);
233 auto constBufferLocations = shaderBinary.constBufferLocations();
234 auto constBufferLayouts = shaderBinary.constBufferLayout();
236 for (
const auto& [name, location] : constBufferLocations)
238 uint32_t set = location.first;
239 uint32_t binding = location.second;
241 if (resourceBindings[set].find(name) != resourceBindings[set].end()) {
245 if (usedBindings[set].find(binding) != usedBindings[set].end()) {
247 while (usedBindings[set].find(binding) != usedBindings[set].end()) {
252 resourceBindings[set][name] = binding;
253 usedBindings[set].insert(binding);
255 auto layoutIt = constBufferLayouts.find(name);
256 if (layoutIt == constBufferLayouts.end()) {
263 vk::DescriptorSetLayoutBinding layoutBinding(
265 vk::DescriptorType::eUniformBuffer,
271 setBindings[set].push_back(layoutBinding);
274 auto textureLocations = shaderBinary.textureLocations();
275 auto textureLayouts = shaderBinary.textureLayout();
277 for (
const auto& [name, location] : textureLocations)
279 uint32_t set = location.first;
280 uint32_t binding = location.second;
282 if (resourceBindings[set].find(name) != resourceBindings[set].end()) {
286 if (usedBindings[set].find(binding) != usedBindings[set].end()) {
288 while (usedBindings[set].find(binding) != usedBindings[set].end()) {
293 resourceBindings[set][name] = binding;
294 usedBindings[set].insert(binding);
296 auto layoutIt = textureLayouts.find(name);
297 if (layoutIt == textureLayouts.end()) {
304 vk::DescriptorSetLayoutBinding layoutBinding(
306 vk::DescriptorType::eSampledImage,
312 setBindings[set].push_back(layoutBinding);
315 auto samplerLocations = shaderBinary.samplerLocations();
316 auto samplerLayouts = shaderBinary.samplerLayout();
318 for (
const auto& [name, location] : samplerLocations)
320 uint32_t set = location.first;
321 uint32_t binding = location.second;
323 if (resourceBindings[set].find(name) != resourceBindings[set].end()) {
327 if (usedBindings[set].find(binding) != usedBindings[set].end()) {
329 while (usedBindings[set].find(binding) != usedBindings[set].end()) {
334 resourceBindings[set][name] = binding;
335 usedBindings[set].insert(binding);
337 auto layoutIt = samplerLayouts.find(name);
338 if (layoutIt == samplerLayouts.end()) {
345 vk::DescriptorSetLayoutBinding layoutBinding(
347 vk::DescriptorType::eSampler,
353 setBindings[set].push_back(layoutBinding);
358 for (
const auto& [set, bindings] : setBindings) {
359 vk::DescriptorSetLayoutCreateInfo layoutInfo(
360 vk::DescriptorSetLayoutCreateFlags(),
361 static_cast<uint32_t
>(bindings.size()),
367 }
catch (
const vk::SystemError& e) {
368 throw std::runtime_error(
"Failed to create descriptor set layout: " + std::string(e.what()));
376 maxSet = std::max(maxSet, set);
379 vk::DescriptorSetLayoutCreateInfo emptyLayoutInfo(
380 vk::DescriptorSetLayoutCreateFlags(),
384 vk::DescriptorSetLayout emptyLayout;
386 emptyLayout =
m_ctx->getDevice().createDescriptorSetLayout(emptyLayoutInfo);
387 }
catch (
const vk::SystemError& e) {
388 throw std::runtime_error(
"Failed to create empty descriptor set layout: " + std::string(e.what()));
400 vk::PipelineLayoutCreateInfo pipelineLayoutInfo(
401 vk::PipelineLayoutCreateFlags(),
410 }
catch (
const vk::SystemError& e) {
411 throw std::runtime_error(
"Failed to create pipeline layout: " + std::string(e.what()));