| 203 | } |
| 204 | |
| 205 | DescriptorSetGroup VulkanObjectManager::CreateDescriptorSetGroup(ref_ptr<VulkanGpuProgram> program) |
| 206 | { |
| 207 | CHECK(std::this_thread::get_id() == m_renderers[ThreadType::Frontend], ()); |
| 208 | |
| 209 | DescriptorSetGroup s; |
| 210 | VkDescriptorSetLayout layout = program->GetDescriptorSetLayout(); |
| 211 | VkDescriptorSetAllocateInfo allocInfo = {}; |
| 212 | |
| 213 | // Find a pool with available sets. |
| 214 | uint32_t poolIndex = 0; |
| 215 | while (poolIndex <= m_descriptorPools.size()) |
| 216 | { |
| 217 | // No such a pool, create one. |
| 218 | if (poolIndex == m_descriptorPools.size()) |
| 219 | CreateDescriptorPool(); |
| 220 | |
| 221 | // No available sets in the pool, try next one. |
| 222 | if (m_descriptorPools[poolIndex].m_availableSetsCount == 0) |
| 223 | { |
| 224 | poolIndex++; |
| 225 | continue; |
| 226 | } |
| 227 | |
| 228 | // Allocate a descriptor set. |
| 229 | allocInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 230 | allocInfo.descriptorPool = m_descriptorPools[poolIndex].m_pool; |
| 231 | s.m_descriptorPoolIndex = poolIndex; |
| 232 | allocInfo.pSetLayouts = &layout; |
| 233 | allocInfo.descriptorSetCount = 1; |
| 234 | |
| 235 | // Decrease the available sets count. |
| 236 | m_descriptorPools[poolIndex].m_availableSetsCount--; |
| 237 | |
| 238 | auto const r = vkAllocateDescriptorSets(m_device, &allocInfo, &s.m_descriptorSet); |
| 239 | if (r == VK_ERROR_FRAGMENTED_POOL || r == VK_ERROR_OUT_OF_POOL_MEMORY) |
| 240 | { |
| 241 | poolIndex++; |
| 242 | m_descriptorPools[poolIndex].m_availableSetsCount++; |
| 243 | } |
| 244 | else if (r != VK_SUCCESS) |
| 245 | { |
| 246 | CHECK_VK_CALL(r); |
| 247 | } |
| 248 | else |
| 249 | { |
| 250 | break; |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | TRACE_COUNTER("[drape][vulkan] Descriptor pools", static_cast<int64_t>(m_descriptorPools.size())); |
| 255 | #ifdef ENABLE_TRACE |
| 256 | int64_t usedDescriptorsSets = 0; |
| 257 | for (auto const & pool : m_descriptorPools) |
| 258 | usedDescriptorsSets += (kMaxDescriptorsSetCount - pool.m_availableSetsCount); |
| 259 | TRACE_COUNTER("[drape][vulkan] Descriptor sets", usedDescriptorsSets); |
| 260 | #endif |
| 261 | |
| 262 | return s; |
no test coverage detected