5 #include "flutter/fml/build_config.h"
6 #include "flutter/fml/file.h"
7 #include "flutter/testing/testing.h"
13 #include "impeller/renderer/backend/vulkan/test/mock_vulkan.h"
17 TEST(PipelineCacheDataVKTest, CanTestHeaderCompatibility) {
21 EXPECT_EQ(a.
abi,
sizeof(
void*));
22 #ifdef FML_ARCH_CPU_64_BITS
24 #elif FML_ARCH_CPU_32_BITS
46 b.driver_version = 100;
70 for (
size_t i = 0; i < VK_UUID_SIZE; i++) {
71 b.uuid[i] = a.
uuid[i] + 1;
77 TEST(PipelineCacheDataVKTest, CanCreateFromDeviceProperties) {
78 vk::PhysicalDeviceProperties props;
79 std::array<uint8_t, 16> uuid{
80 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
82 props.pipelineCacheUUID = uuid;
85 props.driverVersion = 12;
87 EXPECT_EQ(uuid.size(), std::size(header.
uuid));
88 EXPECT_EQ(props.deviceID, header.
device_id);
89 EXPECT_EQ(props.vendorID, header.
vendor_id);
91 for (
size_t i = 0; i < uuid.size(); i++) {
92 EXPECT_EQ(header.
uuid[i], uuid.at(i));
96 TEST(PipelineCacheDataVKTest, WritesIncompleteCacheData) {
97 fml::ScopedTemporaryDirectory temp_dir;
98 auto context = MockVulkanContextBuilder().Build();
99 auto cache = context->GetDevice().createPipelineCacheUnique({});
103 temp_dir.fd(), caps.GetPhysicalDeviceProperties(), cache.value));
105 std::unique_ptr<fml::FileMapping> mapping = fml::FileMapping::CreateReadOnly(
106 temp_dir.fd(),
"flutter.impeller.vkcache");
107 ASSERT_TRUE(mapping);
109 ASSERT_GE(mapping->GetSize(),
sizeof(header));
110 std::memcpy(&header, mapping->GetMapping(),
sizeof(header));
111 ASSERT_EQ(mapping->GetSize(),
sizeof(header) + header.
data_size);
118 fml::ScopedTemporaryDirectory temp_dir;
120 const auto& context_vk =
ContextVK::Cast(*surface_context.GetParent());
124 auto cache = context_vk.GetDevice().createPipelineCacheUnique({});
125 ASSERT_EQ(cache.result, vk::Result::eSuccess);
126 ASSERT_FALSE(fml::FileExists(temp_dir.fd(),
"flutter.impeller.vkcache"));
128 temp_dir.fd(), caps.GetPhysicalDeviceProperties(), cache.value));
130 ASSERT_TRUE(fml::FileExists(temp_dir.fd(),
"flutter.impeller.vkcache"));
133 caps.GetPhysicalDeviceProperties());
134 ASSERT_NE(mapping,
nullptr);
137 vk::PipelineCacheHeaderVersionOne vk_cache_header;
138 ASSERT_GE(mapping->GetSize(),
sizeof(vk_cache_header));
139 std::memcpy(&vk_cache_header, mapping->GetMapping(),
sizeof(vk_cache_header));
140 ASSERT_EQ(vk_cache_header.headerVersion,
141 vk::PipelineCacheHeaderVersion::eOne);
145 IntegrityChecksArePerformedOnPersistedData) {
146 fml::ScopedTemporaryDirectory temp_dir;
148 const auto& context_vk =
ContextVK::Cast(*surface_context.GetParent());
152 auto cache = context_vk.GetDevice().createPipelineCacheUnique({});
153 ASSERT_EQ(cache.result, vk::Result::eSuccess);
154 ASSERT_FALSE(fml::FileExists(temp_dir.fd(),
"flutter.impeller.vkcache"));
156 temp_dir.fd(), caps.GetPhysicalDeviceProperties(), cache.value));
158 ASSERT_TRUE(fml::FileExists(temp_dir.fd(),
"flutter.impeller.vkcache"));
159 auto incompatible_caps = caps.GetPhysicalDeviceProperties();
161 incompatible_caps.driverVersion =
162 caps.GetPhysicalDeviceProperties().driverVersion + 1u;
164 ASSERT_EQ(mapping,
nullptr);
static CapabilitiesVK & Cast(Capabilities &base)
TEST(AllocationSizeTest, CanCreateTypedAllocations)
TEST_P(AiksTest, DrawAtlasNoColor)
INSTANTIATE_VULKAN_PLAYGROUND_SUITE(DriverInfoVKTest)
std::unique_ptr< fml::Mapping > PipelineCacheDataRetrieve(const fml::UniqueFD &cache_directory, const VkPhysicalDeviceProperties &props)
Retrieve the previously persisted pipeline cache data. This function provides integrity checks the Vu...
bool PipelineCacheDataPersist(const fml::UniqueFD &cache_directory, const VkPhysicalDeviceProperties &props, const vk::UniquePipelineCache &cache)
Persist the pipeline cache to a file in the given cache directory. This function performs integrity c...