MCPcopy Create free account
hub / github.com/KhronosGroup/Vulkan-Samples / prepare

Method prepare

framework/core/descriptor_set.cpp:58–147  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

56}
57
58void DescriptorSet::prepare()
59{
60 // We don't want to prepare twice during the life cycle of a Descriptor Set
61 if (!write_descriptor_sets.empty())
62 {
63 LOGW("Trying to prepare a descriptor set that has already been prepared, skipping.");
64 return;
65 }
66
67 // Iterate over all buffer bindings
68 for (auto &binding_it : buffer_infos)
69 {
70 auto binding_index = binding_it.first;
71 auto &buffer_bindings = binding_it.second;
72
73 if (auto binding_info = descriptor_set_layout.get_layout_binding(binding_index))
74 {
75 // Iterate over all binding buffers in array
76 for (auto &element_it : buffer_bindings)
77 {
78 auto &buffer_info = element_it.second;
79
80 size_t uniform_buffer_range_limit = device.get_gpu().get_properties().limits.maxUniformBufferRange;
81 size_t storage_buffer_range_limit = device.get_gpu().get_properties().limits.maxStorageBufferRange;
82
83 size_t buffer_range_limit = static_cast<size_t>(buffer_info.range);
84
85 if ((binding_info->descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER || binding_info->descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) && buffer_range_limit > uniform_buffer_range_limit)
86 {
87 LOGE("Set {} binding {} cannot be updated: buffer size {} exceeds the uniform buffer range limit {}", descriptor_set_layout.get_index(), binding_index, buffer_info.range, uniform_buffer_range_limit);
88 buffer_range_limit = uniform_buffer_range_limit;
89 }
90 else if ((binding_info->descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER || binding_info->descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC) && buffer_range_limit > storage_buffer_range_limit)
91 {
92 LOGE("Set {} binding {} cannot be updated: buffer size {} exceeds the storage buffer range limit {}", descriptor_set_layout.get_index(), binding_index, buffer_info.range, storage_buffer_range_limit);
93 buffer_range_limit = storage_buffer_range_limit;
94 }
95
96 // Clip the buffers range to the limit if one exists as otherwise we will receive a Vulkan validation error
97 buffer_info.range = buffer_range_limit;
98
99 VkWriteDescriptorSet write_descriptor_set{VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET};
100
101 write_descriptor_set.dstBinding = binding_index;
102 write_descriptor_set.descriptorType = binding_info->descriptorType;
103 write_descriptor_set.pBufferInfo = &buffer_info;
104 write_descriptor_set.dstSet = handle;
105 write_descriptor_set.dstArrayElement = element_it.first;
106 write_descriptor_set.descriptorCount = 1;
107
108 write_descriptor_sets.push_back(write_descriptor_set);
109 }
110 }
111 else
112 {
113 LOGE("Shader layout set does not use buffer binding at #{}", binding_index);
114 }
115 }

Callers

nothing calls this directly

Calls 3

emptyMethod · 0.80
get_layout_bindingMethod · 0.45
get_indexMethod · 0.45

Tested by

no test coverage detected