5 #include "flutter/testing/testing.h"
6 #include "gtest/gtest.h"
14 #include "impeller/renderer/backend/vulkan/test/mock_vulkan.h"
15 #include "vulkan/vulkan_enums.hpp"
20 TEST(AllocatorVKTest, ToVKImageUsageFlags) {
26 vk::ImageUsageFlagBits::eInputAttachment |
27 vk::ImageUsageFlagBits::eColorAttachment |
28 vk::ImageUsageFlagBits::eTransientAttachment);
35 vk::ImageUsageFlagBits::eDepthStencilAttachment |
36 vk::ImageUsageFlagBits::eTransientAttachment);
39 TEST(AllocatorVKTest, MemoryTypeSelectionSingleHeap) {
40 vk::PhysicalDeviceMemoryProperties properties;
41 properties.memoryTypeCount = 1;
42 properties.memoryHeapCount = 1;
43 properties.memoryTypes[0].heapIndex = 0;
44 properties.memoryTypes[0].propertyFlags =
45 vk::MemoryPropertyFlagBits::eDeviceLocal;
46 properties.memoryHeaps[0].size = 1024 * 1024 * 1024;
47 properties.memoryHeaps[0].flags = vk::MemoryHeapFlagBits::eDeviceLocal;
54 TEST(AllocatorVKTest, MemoryTypeSelectionTwoHeap) {
55 vk::PhysicalDeviceMemoryProperties properties;
56 properties.memoryTypeCount = 2;
57 properties.memoryHeapCount = 2;
58 properties.memoryTypes[0].heapIndex = 0;
59 properties.memoryTypes[0].propertyFlags =
60 vk::MemoryPropertyFlagBits::eHostVisible;
61 properties.memoryHeaps[0].size = 1024 * 1024 * 1024;
62 properties.memoryHeaps[0].flags = vk::MemoryHeapFlagBits::eDeviceLocal;
64 properties.memoryTypes[1].heapIndex = 1;
65 properties.memoryTypes[1].propertyFlags =
66 vk::MemoryPropertyFlagBits::eDeviceLocal;
67 properties.memoryHeaps[1].size = 1024 * 1024 * 1024;
68 properties.memoryHeaps[1].flags = vk::MemoryHeapFlagBits::eDeviceLocal;
77 TEST(AllocatorVKTest, ImageResourceKeepsVulkanDeviceAlive) {
78 std::shared_ptr<Texture> texture;
79 std::weak_ptr<Allocator> weak_allocator;
81 auto const context = MockVulkanContextBuilder().Build();
82 weak_allocator = context->GetResourceAllocator();
83 auto allocator = context->GetResourceAllocator();
93 ASSERT_TRUE(weak_allocator.lock());
98 TEST(AllocatorVKTest, RecreateSwapchainWhenSizeChanges) {
99 auto const context = MockVulkanContextBuilder().Build();
100 auto allocator = context->GetResourceAllocator();
102 EXPECT_EQ(
reinterpret_cast<AllocatorVK*
>(allocator.get())
115 EXPECT_EQ(
reinterpret_cast<AllocatorVK*
>(allocator.get())
116 ->DebugGetHeapUsage()
constexpr uint64_t GetByteSize() const
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)
Bytes DebugGetHeapUsage() const override
TEST(AllocationSizeTest, CanCreateTypedAllocations)
AllocationSize< 1 '024u *1 '024u > MebiBytes
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...