MCPcopy Create free account
hub / github.com/SFML/SFML / setupDescriptorSets

Method setupDescriptorSets

examples/vulkan/Vulkan.cpp:2159–2222  ·  view source on GitHub ↗

Set up our descriptor sets

Source from the content-addressed store, hash-verified

2157
2158 // Set up our descriptor sets
2159 void setupDescriptorSets()
2160 {
2161 // Allocate a descriptor set for each frame in flight
2162 std::vector<VkDescriptorSetLayout> descriptorSetLayouts(swapchainImages.size(), descriptorSetLayout);
2163
2164 VkDescriptorSetAllocateInfo descriptorSetAllocateInfo = VkDescriptorSetAllocateInfo();
2165 descriptorSetAllocateInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2166 descriptorSetAllocateInfo.descriptorPool = descriptorPool;
2167 descriptorSetAllocateInfo.descriptorSetCount = static_cast<std::uint32_t>(swapchainImages.size());
2168 descriptorSetAllocateInfo.pSetLayouts = descriptorSetLayouts.data();
2169
2170 descriptorSets.resize(swapchainImages.size());
2171
2172 if (vkAllocateDescriptorSets(device, &descriptorSetAllocateInfo, descriptorSets.data()) != VK_SUCCESS)
2173 {
2174 descriptorSets.clear();
2175
2176 vulkanAvailable = false;
2177 return;
2178 }
2179
2180 // For every descriptor set, set up the bindings to our uniform buffer and texture sampler
2181 for (std::size_t i = 0; i < descriptorSets.size(); ++i)
2182 {
2183 std::array<VkWriteDescriptorSet, 2> writeDescriptorSets{};
2184
2185 // Uniform buffer binding information
2186 VkDescriptorBufferInfo descriptorBufferInfo = VkDescriptorBufferInfo();
2187 descriptorBufferInfo.buffer = uniformBuffers[i];
2188 descriptorBufferInfo.offset = 0;
2189 descriptorBufferInfo.range = sizeof(Matrix) * 3;
2190
2191 writeDescriptorSets[0] = VkWriteDescriptorSet();
2192 writeDescriptorSets[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
2193 writeDescriptorSets[0].dstSet = descriptorSets[i];
2194 writeDescriptorSets[0].dstBinding = 0;
2195 writeDescriptorSets[0].dstArrayElement = 0;
2196 writeDescriptorSets[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2197 writeDescriptorSets[0].descriptorCount = 1;
2198 writeDescriptorSets[0].pBufferInfo = &descriptorBufferInfo;
2199
2200 // Texture sampler binding information
2201 VkDescriptorImageInfo descriptorImageInfo = VkDescriptorImageInfo();
2202 descriptorImageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
2203 descriptorImageInfo.imageView = textureImageView;
2204 descriptorImageInfo.sampler = textureSampler;
2205
2206 writeDescriptorSets[1] = VkWriteDescriptorSet();
2207 writeDescriptorSets[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
2208 writeDescriptorSets[1].dstSet = descriptorSets[i];
2209 writeDescriptorSets[1].dstBinding = 1;
2210 writeDescriptorSets[1].dstArrayElement = 0;
2211 writeDescriptorSets[1].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
2212 writeDescriptorSets[1].descriptorCount = 1;
2213 writeDescriptorSets[1].pImageInfo = &descriptorImageInfo;
2214
2215 // Update the descriptor set
2216 vkUpdateDescriptorSets(device,

Callers

nothing calls this directly

Calls 6

resizeMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected