5 #include "flutter/testing/testing.h"
8 #include "impeller/renderer/backend/vulkan/test/mock_vulkan.h"
13 TEST(DescriptorPoolRecyclerVKTest, GetDescriptorPoolRecyclerCreatesNewPools) {
14 std::shared_ptr<ContextVK> context = MockVulkanContextBuilder().Build();
16 vk::UniqueDescriptorPool pool1 = context->GetDescriptorPoolRecycler()->Get();
17 vk::UniqueDescriptorPool pool2 = context->GetDescriptorPoolRecycler()->Get();
20 EXPECT_NE(pool1.get(), pool2.get());
25 TEST(DescriptorPoolRecyclerVKTest, ReclaimMakesDescriptorPoolAvailable) {
26 std::shared_ptr<ContextVK> context = MockVulkanContextBuilder().Build();
34 std::shared_ptr<DescriptorPoolVK> pool =
35 context->GetDescriptorPoolRecycler()->GetDescriptorPool();
38 std::shared_ptr<std::vector<std::string>> called =
39 GetMockVulkanFunctions(context->GetDevice());
41 std::count(called->begin(), called->end(),
"vkCreateDescriptorPool"), 1u);
46 TEST(DescriptorPoolRecyclerVKTest, ReclaimDropsDescriptorPoolIfSizeIsExceeded) {
47 std::shared_ptr<ContextVK> context = MockVulkanContextBuilder().Build();
51 std::vector<std::unique_ptr<DescriptorPoolVK>> pools;
52 for (
size_t i = 0u; i < 33; i++) {
53 std::unique_ptr<DescriptorPoolVK> pool =
54 std::make_unique<DescriptorPoolVK>(context);
55 pool->AllocateDescriptorSets({}, 0, *context);
56 pools.push_back(std::move(pool));
60 std::shared_ptr<std::vector<std::string>> called =
61 GetMockVulkanFunctions(context->GetDevice());
63 std::count(called->begin(), called->end(),
"vkCreateDescriptorPool"),
69 std::vector<std::shared_ptr<DescriptorPoolVK>> pools;
70 for (
size_t i = 0u; i < 33; i++) {
71 std::shared_ptr<DescriptorPoolVK> pool =
72 context->GetDescriptorPoolRecycler()->GetDescriptorPool();
73 pool->AllocateDescriptorSets({}, 0, *context);
74 pools.push_back(std::move(pool));
78 std::shared_ptr<std::vector<std::string>> called_twice =
79 GetMockVulkanFunctions(context->GetDevice());
82 std::count(called->begin(), called->end(),
"vkCreateDescriptorPool"),
88 TEST(DescriptorPoolRecyclerVKTest, MultipleCommandBuffersShareDescriptorPool) {
89 std::shared_ptr<ContextVK> context = MockVulkanContextBuilder().Build();
91 std::shared_ptr<CommandBuffer> cmd_buffer_1 = context->CreateCommandBuffer();
92 std::shared_ptr<CommandBuffer> cmd_buffer_2 = context->CreateCommandBuffer();
100 context->DisposeThreadLocalCachedResources();
102 std::shared_ptr<CommandBuffer> cmd_buffer_3 = context->CreateCommandBuffer();
110 TEST(DescriptorPoolRecyclerVKTest, DescriptorsAreRecycled) {
111 std::shared_ptr<ContextVK> context = MockVulkanContextBuilder().Build();
119 std::shared_ptr<DescriptorPoolVK> pool =
120 context->GetDescriptorPoolRecycler()->GetDescriptorPool();
121 pool->AllocateDescriptorSets({}, 0, *context);
123 std::shared_ptr<std::vector<std::string>> called =
124 GetMockVulkanFunctions(context->GetDevice());
126 std::count(called->begin(), called->end(),
"vkAllocateDescriptorSets"),
130 pool->AllocateDescriptorSets({}, 0, *context);
132 std::count(called->begin(), called->end(),
"vkAllocateDescriptorSets"),
static CommandBufferVK & Cast(CommandBuffer &base)
DescriptorPoolVK & GetDescriptorPool() const
A per-frame descriptor pool. Descriptors from this pool don't need to be freed individually....
fml::StatusOr< vk::DescriptorSet > AllocateDescriptorSets(const vk::DescriptorSetLayout &layout, PipelineKey pipeline_key, const ContextVK &context_vk)
TEST(AllocationSizeTest, CanCreateTypedAllocations)