90 std::map<uint32_t, std::set<uint32_t>> usedBindings;
91 std::map<uint32_t, std::map<std::string, uint32_t>> resourceBindings;
92 std::map<uint32_t, std::vector<vk::DescriptorSetLayoutBinding>> setBindings;
98 auto constBufferLocations = shaderBinary.constBufferLocations();
99 auto constBufferLayouts = shaderBinary.constBufferLayout();
101 for (
const auto& [name, location] : constBufferLocations)
103 uint32_t set = location.first;
104 uint32_t binding = location.second;
106 if (resourceBindings[set].find(name) != resourceBindings[set].end()) {
110 resourceBindings[set][name] = binding;
111 usedBindings[set].insert(binding);
113 auto layoutIt = constBufferLayouts.find(name);
114 if (layoutIt == constBufferLayouts.end()) {
121 vk::DescriptorSetLayoutBinding layoutBinding(
123 vk::DescriptorType::eUniformBuffer,
129 setBindings[set].push_back(layoutBinding);
132 auto textureLocations = shaderBinary.textureLocations();
133 auto textureLayouts = shaderBinary.textureLayout();
135 for (
const auto& [name, location] : textureLocations)
137 uint32_t set = location.first;
138 uint32_t binding = location.second;
140 if (resourceBindings[set].find(name) != resourceBindings[set].end()) {
144 if (usedBindings[set].find(binding) != usedBindings[set].end()) {
146 while (usedBindings[set].find(binding) != usedBindings[set].end()) {
151 resourceBindings[set][name] = binding;
152 usedBindings[set].insert(binding);
154 auto layoutIt = textureLayouts.find(name);
155 if (layoutIt == textureLayouts.end()) {
162 vk::DescriptorSetLayoutBinding layoutBinding(
164 vk::DescriptorType::eSampledImage,
170 setBindings[set].push_back(layoutBinding);
173 auto samplerLocations = shaderBinary.samplerLocations();
174 auto samplerLayouts = shaderBinary.samplerLayout();
176 for (
const auto& [name, location] : samplerLocations)
178 uint32_t set = location.first;
179 uint32_t binding = location.second;
181 if (resourceBindings[set].find(name) != resourceBindings[set].end()) {
185 if (usedBindings[set].find(binding) != usedBindings[set].end()) {
187 while (usedBindings[set].find(binding) != usedBindings[set].end()) {
192 resourceBindings[set][name] = binding;
193 usedBindings[set].insert(binding);
195 auto layoutIt = samplerLayouts.find(name);
196 if (layoutIt == samplerLayouts.end()) {
203 vk::DescriptorSetLayoutBinding layoutBinding(
205 vk::DescriptorType::eSampler,
211 setBindings[set].push_back(layoutBinding);
219 auto constBufferLocations = shaderBinary.constBufferLocations();
220 auto constBufferLayouts = shaderBinary.constBufferLayout();
222 for (
const auto& [name, location] : constBufferLocations)
224 uint32_t set = location.first;
225 uint32_t binding = location.second;
227 if (resourceBindings[set].find(name) != resourceBindings[set].end()) {
231 if (usedBindings[set].find(binding) != usedBindings[set].end()) {
233 while (usedBindings[set].find(binding) != usedBindings[set].end()) {
238 resourceBindings[set][name] = binding;
239 usedBindings[set].insert(binding);
241 auto layoutIt = constBufferLayouts.find(name);
242 if (layoutIt == constBufferLayouts.end()) {
249 vk::DescriptorSetLayoutBinding layoutBinding(
251 vk::DescriptorType::eUniformBuffer,
257 setBindings[set].push_back(layoutBinding);
260 auto textureLocations = shaderBinary.textureLocations();
261 auto textureLayouts = shaderBinary.textureLayout();
263 for (
const auto& [name, location] : textureLocations)
265 uint32_t set = location.first;
266 uint32_t binding = location.second;
268 if (resourceBindings[set].find(name) != resourceBindings[set].end()) {
272 if (usedBindings[set].find(binding) != usedBindings[set].end()) {
274 while (usedBindings[set].find(binding) != usedBindings[set].end()) {
279 resourceBindings[set][name] = binding;
280 usedBindings[set].insert(binding);
282 auto layoutIt = textureLayouts.find(name);
283 if (layoutIt == textureLayouts.end()) {
290 vk::DescriptorSetLayoutBinding layoutBinding(
292 vk::DescriptorType::eSampledImage,
298 setBindings[set].push_back(layoutBinding);
301 auto samplerLocations = shaderBinary.samplerLocations();
302 auto samplerLayouts = shaderBinary.samplerLayout();
304 for (
const auto& [name, location] : samplerLocations)
306 uint32_t set = location.first;
307 uint32_t binding = location.second;
309 if (resourceBindings[set].find(name) != resourceBindings[set].end()) {
313 if (usedBindings[set].find(binding) != usedBindings[set].end()) {
315 while (usedBindings[set].find(binding) != usedBindings[set].end()) {
320 resourceBindings[set][name] = binding;
321 usedBindings[set].insert(binding);
323 auto layoutIt = samplerLayouts.find(name);
324 if (layoutIt == samplerLayouts.end()) {
331 vk::DescriptorSetLayoutBinding layoutBinding(
333 vk::DescriptorType::eSampler,
339 setBindings[set].push_back(layoutBinding);
344 for (
const auto& [set, bindings] : setBindings) {
345 vk::DescriptorSetLayoutCreateInfo layoutInfo(
346 vk::DescriptorSetLayoutCreateFlags(),
347 static_cast<uint32_t
>(bindings.size()),
353 }
catch (
const vk::SystemError& e) {
354 throw std::runtime_error(
"Failed to create descriptor set layout: " + std::string(e.what()));
362 maxSet = std::max(maxSet, set);
365 vk::DescriptorSetLayoutCreateInfo emptyLayoutInfo(
366 vk::DescriptorSetLayoutCreateFlags(),
370 vk::DescriptorSetLayout emptyLayout;
372 emptyLayout =
m_ctx->getDevice().createDescriptorSetLayout(emptyLayoutInfo);
373 }
catch (
const vk::SystemError& e) {
374 throw std::runtime_error(
"Failed to create empty descriptor set layout: " + std::string(e.what()));
386 vk::PipelineLayoutCreateInfo pipelineLayoutInfo(
387 vk::PipelineLayoutCreateFlags(),
396 }
catch (
const vk::SystemError& e) {
397 throw std::runtime_error(
"Failed to create pipeline layout: " + std::string(e.what()));