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

Method DescriptorSetLayout

framework/core/descriptor_set_layout.cpp:99–191  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

97} // namespace
98
99DescriptorSetLayout::DescriptorSetLayout(vkb::core::DeviceC &device,
100 const uint32_t set_index,
101 const std::vector<ShaderModule *> &shader_modules,
102 const std::vector<ShaderResource> &resource_set) :
103 device{device},
104 set_index{set_index},
105 shader_modules{shader_modules}
106{
107 // NOTE: `shader_modules` is passed in mainly for hashing their handles in `request_resource`.
108 // This way, different pipelines (with different shaders / shader variants) will get
109 // different descriptor set layouts (incl. appropriate name -> binding lookups)
110
111 for (auto &resource : resource_set)
112 {
113 // Skip shader resources whitout a binding point
114 if (resource.type == ShaderResourceType::Input ||
115 resource.type == ShaderResourceType::Output ||
116 resource.type == ShaderResourceType::PushConstant ||
117 resource.type == ShaderResourceType::SpecializationConstant)
118 {
119 continue;
120 }
121
122 // Convert from ShaderResourceType to VkDescriptorType.
123 auto descriptor_type = find_descriptor_type(resource.type, resource.mode == ShaderResourceMode::Dynamic);
124
125 if (resource.mode == ShaderResourceMode::UpdateAfterBind)
126 {
127 binding_flags.push_back(VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT_EXT);
128 }
129 else
130 {
131 // When creating a descriptor set layout, if we give a structure to create_info.pNext, each binding needs to have a binding flag
132 // (pBindings[i] uses the flags in pBindingFlags[i])
133 // Adding 0 ensures the bindings that dont use any flags are mapped correctly.
134 binding_flags.push_back(0);
135 }
136
137 // Convert ShaderResource to VkDescriptorSetLayoutBinding
138 VkDescriptorSetLayoutBinding layout_binding{};
139
140 layout_binding.binding = resource.binding;
141 layout_binding.descriptorCount = resource.array_size;
142 layout_binding.descriptorType = descriptor_type;
143 layout_binding.stageFlags = static_cast<VkShaderStageFlags>(resource.stages);
144
145 bindings.push_back(layout_binding);
146
147 // Store mapping between binding and the binding point
148 bindings_lookup.emplace(resource.binding, layout_binding);
149
150 binding_flags_lookup.emplace(resource.binding, binding_flags.back());
151
152 resources_lookup.emplace(resource.name, resource.binding);
153 }
154
155 VkDescriptorSetLayoutCreateInfo create_info{VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO};
156 create_info.flags = 0;

Callers

nothing calls this directly

Calls 6

find_descriptor_typeFunction · 0.85
to_u32Function · 0.85
validate_flagsFunction · 0.85
sizeMethod · 0.80
endMethod · 0.80
get_handleMethod · 0.45

Tested by

no test coverage detected