7 #include "flutter/fml/trace_event.h"
14 const std::weak_ptr<const DeviceHolder>& device_holder)
15 : device_holder_(device_holder) {
16 FML_DCHECK(device_holder.lock());
21 static vk::UniqueDescriptorPool
CreatePool(
const vk::Device& device,
22 uint32_t pool_count) {
23 TRACE_EVENT0(
"impeller",
"CreateDescriptorPool");
24 std::vector<vk::DescriptorPoolSize> pools = {
25 {vk::DescriptorType::eCombinedImageSampler, pool_count},
26 {vk::DescriptorType::eUniformBuffer, pool_count},
27 {vk::DescriptorType::eStorageBuffer, pool_count}};
29 vk::DescriptorPoolCreateInfo pool_info;
30 pool_info.setMaxSets(pools.size() * pool_count);
31 pool_info.setPoolSizes(pools);
33 auto [result, pool] = device.createDescriptorPoolUnique(pool_info);
34 if (result != vk::Result::eSuccess) {
37 return std::move(pool);
41 const vk::DescriptorSetLayout& layout,
42 size_t command_count) {
44 pool_size_ = command_count;
50 const vk::DescriptorSetLayout& layout) {
51 auto pool = GetDescriptorPool();
55 vk::DescriptorSetAllocateInfo set_info;
56 set_info.setDescriptorPool(pool.value());
57 set_info.setSetLayouts(layout);
58 std::shared_ptr<const DeviceHolder> strong_device = device_holder_.lock();
63 strong_device->GetDevice().allocateDescriptorSets(set_info);
64 if (result == vk::Result::eErrorOutOfPoolMemory) {
67 if (result != vk::Result::eSuccess) {
69 << vk::to_string(result);
75 std::optional<vk::DescriptorPool> DescriptorPoolVK::GetDescriptorPool() {
77 return GrowPool() ? GetDescriptorPool() :
std::nullopt;
79 return *pools_.back();
82 bool DescriptorPoolVK::GrowPool() {
84 std::shared_ptr<const DeviceHolder> strong_device = device_holder_.lock();
88 auto new_pool =
CreatePool(strong_device->GetDevice(), new_pool_size);
92 pool_size_ = new_pool_size;
93 pools_.push(std::move(new_pool));