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

Method PipelineLayout

framework/core/pipeline_layout.cpp:28–123  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26namespace vkb
27{
28PipelineLayout::PipelineLayout(vkb::core::DeviceC &device, const std::vector<ShaderModule *> &shader_modules) :
29 device{device},
30 shader_modules{shader_modules}
31{
32 // Collect and combine all the shader resources from each of the shader modules
33 // Collate them all into a map that is indexed by the name of the resource
34 for (auto *shader_module : shader_modules)
35 {
36 for (const auto &shader_resource : shader_module->get_resources())
37 {
38 std::string key = shader_resource.name;
39
40 // Since 'Input' and 'Output' resources can have the same name, we modify the key string
41 if (shader_resource.type == ShaderResourceType::Input || shader_resource.type == ShaderResourceType::Output)
42 {
43 key = std::to_string(shader_resource.stages) + "_" + key;
44 }
45
46 auto it = shader_resources.find(key);
47
48 if (it != shader_resources.end())
49 {
50 // Append stage flags if resource already exists
51 it->second.stages |= shader_resource.stages;
52 }
53 else
54 {
55 // Create a new entry in the map
56 shader_resources.emplace(key, shader_resource);
57 }
58 }
59 }
60
61 // Sift through the map of name indexed shader resources
62 // Separate them into their respective sets
63 for (auto &it : shader_resources)
64 {
65 auto &shader_resource = it.second;
66
67 // Find binding by set index in the map.
68 auto it2 = shader_sets.find(shader_resource.set);
69
70 if (it2 != shader_sets.end())
71 {
72 // Add resource to the found set index
73 it2->second.push_back(shader_resource);
74 }
75 else
76 {
77 // Create a new set index and with the first resource
78 shader_sets.emplace(shader_resource.set, std::vector<ShaderResource>{shader_resource});
79 }
80 }
81
82 // Create a descriptor set layout for each shader set in the shader modules
83 for (auto &shader_set_it : shader_sets)
84 {
85 descriptor_set_layouts.emplace_back(&device.get_resource_cache().request_descriptor_set_layout(shader_set_it.first, shader_modules, shader_set_it.second));

Callers

nothing calls this directly

Calls 6

to_u32Function · 0.85
endMethod · 0.80
sizeMethod · 0.80
to_stringFunction · 0.50
get_resourcesMethod · 0.45
get_handleMethod · 0.45

Tested by

no test coverage detected