| 10 | namespace vulkan |
| 11 | { |
| 12 | void DescriptorSetGroup::Update(VkDevice device, std::vector<ParamDescriptor> const & descriptors) |
| 13 | { |
| 14 | size_t const writeDescriptorsCount = descriptors.size(); |
| 15 | CHECK_LESS_OR_EQUAL(writeDescriptorsCount, kMaxDescriptorSets, ()); |
| 16 | |
| 17 | std::array<uint32_t, kMaxDescriptorSets> ids = {}; |
| 18 | for (size_t i = 0; i < writeDescriptorsCount; ++i) |
| 19 | ids[i] = descriptors[i].m_id; |
| 20 | |
| 21 | if (m_updated && ids == m_ids) |
| 22 | return; |
| 23 | |
| 24 | m_ids = ids; |
| 25 | m_updated = true; |
| 26 | std::array<VkWriteDescriptorSet, kMaxDescriptorSets> writeDescriptorSets = {}; |
| 27 | for (size_t i = 0; i < writeDescriptorsCount; ++i) |
| 28 | { |
| 29 | writeDescriptorSets[i] = {}; |
| 30 | writeDescriptorSets[i].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 31 | writeDescriptorSets[i].dstSet = m_descriptorSet; |
| 32 | writeDescriptorSets[i].descriptorCount = 1; |
| 33 | if (descriptors[i].m_type == ParamDescriptor::Type::DynamicUniformBuffer) |
| 34 | { |
| 35 | writeDescriptorSets[i].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC; |
| 36 | writeDescriptorSets[i].dstBinding = 0; |
| 37 | writeDescriptorSets[i].pBufferInfo = &descriptors[i].m_bufferDescriptor; |
| 38 | } |
| 39 | else if (descriptors[i].m_type == ParamDescriptor::Type::Texture) |
| 40 | { |
| 41 | writeDescriptorSets[i].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 42 | writeDescriptorSets[i].dstBinding = static_cast<uint32_t>(descriptors[i].m_textureSlot); |
| 43 | writeDescriptorSets[i].pImageInfo = &descriptors[i].m_imageDescriptor; |
| 44 | } |
| 45 | else |
| 46 | { |
| 47 | CHECK(false, ("Unsupported param descriptor type.")); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | vkUpdateDescriptorSets(device, static_cast<uint32_t>(writeDescriptorsCount), writeDescriptorSets.data(), 0, nullptr); |
| 52 | } |
| 53 | |
| 54 | ParamDescriptorUpdater::ParamDescriptorUpdater(ref_ptr<VulkanObjectManager> objectManager) |
| 55 | : m_objectManager(std::move(objectManager)) |
no test coverage detected