Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
allocator_vk_unittests.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "flutter/testing/testing.h" // IWYU pragma: keep
6#include "gtest/gtest.h"
11#include "vulkan/vulkan_enums.hpp"
12
13namespace impeller {
14namespace testing {
15
16TEST(AllocatorVKTest, ToVKImageUsageFlags) {
21 /*supports_memoryless_textures=*/true),
22 vk::ImageUsageFlagBits::eInputAttachment |
23 vk::ImageUsageFlagBits::eColorAttachment |
24 vk::ImageUsageFlagBits::eTransientAttachment);
25
30 /*supports_memoryless_textures=*/true),
31 vk::ImageUsageFlagBits::eDepthStencilAttachment |
32 vk::ImageUsageFlagBits::eTransientAttachment);
33}
34
35TEST(AllocatorVKTest, MemoryTypeSelectionSingleHeap) {
36 vk::PhysicalDeviceMemoryProperties properties;
37 properties.memoryTypeCount = 1;
38 properties.memoryHeapCount = 1;
39 properties.memoryTypes[0].heapIndex = 0;
40 properties.memoryTypes[0].propertyFlags =
41 vk::MemoryPropertyFlagBits::eDeviceLocal;
42 properties.memoryHeaps[0].size = 1024 * 1024 * 1024;
43 properties.memoryHeaps[0].flags = vk::MemoryHeapFlagBits::eDeviceLocal;
44
45 EXPECT_EQ(AllocatorVK::FindMemoryTypeIndex(1, properties), 0);
46 EXPECT_EQ(AllocatorVK::FindMemoryTypeIndex(2, properties), -1);
47 EXPECT_EQ(AllocatorVK::FindMemoryTypeIndex(3, properties), 0);
48}
49
50TEST(AllocatorVKTest, MemoryTypeSelectionTwoHeap) {
51 vk::PhysicalDeviceMemoryProperties properties;
52 properties.memoryTypeCount = 2;
53 properties.memoryHeapCount = 2;
54 properties.memoryTypes[0].heapIndex = 0;
55 properties.memoryTypes[0].propertyFlags =
56 vk::MemoryPropertyFlagBits::eHostVisible;
57 properties.memoryHeaps[0].size = 1024 * 1024 * 1024;
58 properties.memoryHeaps[0].flags = vk::MemoryHeapFlagBits::eDeviceLocal;
59
60 properties.memoryTypes[1].heapIndex = 1;
61 properties.memoryTypes[1].propertyFlags =
62 vk::MemoryPropertyFlagBits::eDeviceLocal;
63 properties.memoryHeaps[1].size = 1024 * 1024 * 1024;
64 properties.memoryHeaps[1].flags = vk::MemoryHeapFlagBits::eDeviceLocal;
65
66 // First fails because this only looks for eDeviceLocal.
67 EXPECT_EQ(AllocatorVK::FindMemoryTypeIndex(1, properties), -1);
68 EXPECT_EQ(AllocatorVK::FindMemoryTypeIndex(2, properties), 1);
69 EXPECT_EQ(AllocatorVK::FindMemoryTypeIndex(3, properties), 1);
70 EXPECT_EQ(AllocatorVK::FindMemoryTypeIndex(4, properties), -1);
71}
72
73#ifdef IMPELLER_DEBUG
74
75TEST(AllocatorVKTest, RecreateSwapchainWhenSizeChanges) {
76 auto const context = MockVulkanContextBuilder().Build();
77 auto allocator = context->GetResourceAllocator();
78
79 EXPECT_EQ(
80 reinterpret_cast<AllocatorVK*>(allocator.get())->DebugGetHeapUsage(), 0u);
81
82 allocator->CreateBuffer(DeviceBufferDescriptor{
84 .size = 1024,
85 });
86
87 // Usage increases beyond the size of the allocated buffer since VMA will
88 // first allocate large blocks of memory and then suballocate small memory
89 // allocations.
90 EXPECT_EQ(
91 reinterpret_cast<AllocatorVK*>(allocator.get())->DebugGetHeapUsage(),
92 16u);
93}
94
95#endif // IMPELLER_DEBUG
96
97} // namespace testing
98} // namespace impeller
#define TEST(S, s, D, expected)
static int32_t FindMemoryTypeIndex(uint32_t memory_type_bits_requirement, vk::PhysicalDeviceMemoryProperties &memory_properties)
Select a matching memory type for the given [memory_type_bits_requirement], or -1 if none is found.
static vk::ImageUsageFlags ToVKImageUsageFlags(PixelFormat format, TextureUsageMask usage, StorageMode mode, bool supports_memoryless_textures)
size_t DebugGetHeapUsage() const