MCPcopy Create free account
hub / github.com/Overv/VulkanTutorial / createDescriptorSets

Method createDescriptorSets

code/29_mipmapping.cpp:1199–1243  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1197 }
1198
1199 void createDescriptorSets() {
1200 std::vector<VkDescriptorSetLayout> layouts(MAX_FRAMES_IN_FLIGHT, descriptorSetLayout);
1201 VkDescriptorSetAllocateInfo allocInfo{};
1202 allocInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
1203 allocInfo.descriptorPool = descriptorPool;
1204 allocInfo.descriptorSetCount = static_cast<uint32_t>(MAX_FRAMES_IN_FLIGHT);
1205 allocInfo.pSetLayouts = layouts.data();
1206
1207 descriptorSets.resize(MAX_FRAMES_IN_FLIGHT);
1208 if (vkAllocateDescriptorSets(device, &allocInfo, descriptorSets.data()) != VK_SUCCESS) {
1209 throw std::runtime_error("failed to allocate descriptor sets!");
1210 }
1211
1212 for (size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++) {
1213 VkDescriptorBufferInfo bufferInfo{};
1214 bufferInfo.buffer = uniformBuffers[i];
1215 bufferInfo.offset = 0;
1216 bufferInfo.range = sizeof(UniformBufferObject);
1217
1218 VkDescriptorImageInfo imageInfo{};
1219 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
1220 imageInfo.imageView = textureImageView;
1221 imageInfo.sampler = textureSampler;
1222
1223 std::array<VkWriteDescriptorSet, 2> descriptorWrites{};
1224
1225 descriptorWrites[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1226 descriptorWrites[0].dstSet = descriptorSets[i];
1227 descriptorWrites[0].dstBinding = 0;
1228 descriptorWrites[0].dstArrayElement = 0;
1229 descriptorWrites[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1230 descriptorWrites[0].descriptorCount = 1;
1231 descriptorWrites[0].pBufferInfo = &bufferInfo;
1232
1233 descriptorWrites[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1234 descriptorWrites[1].dstSet = descriptorSets[i];
1235 descriptorWrites[1].dstBinding = 1;
1236 descriptorWrites[1].dstArrayElement = 0;
1237 descriptorWrites[1].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
1238 descriptorWrites[1].descriptorCount = 1;
1239 descriptorWrites[1].pImageInfo = &imageInfo;
1240
1241 vkUpdateDescriptorSets(device, static_cast<uint32_t>(descriptorWrites.size()), descriptorWrites.data(), 0, nullptr);
1242 }
1243 }
1244
1245 void createBuffer(VkDeviceSize size, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties, VkBuffer& buffer, VkDeviceMemory& bufferMemory) {
1246 VkBufferCreateInfo bufferInfo{};

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected