7 #include "flutter/fml/file.h"
14 "flutter.impeller.vkcache";
17 const VkPhysicalDeviceProperties& props,
18 const vk::UniquePipelineCache& cache) {
19 if (!cache_directory.is_valid()) {
22 size_t data_size = 0u;
23 if (cache.getOwner().getPipelineCacheData(*cache, &data_size,
nullptr) !=
24 vk::Result::eSuccess) {
28 if (data_size == 0u) {
31 auto allocation = std::make_shared<Allocation>();
32 if (!allocation->Truncate(
Bytes{sizeof(PipelineCacheHeaderVK) + data_size},
34 VALIDATION_LOG <<
"Could not allocate pipeline cache data staging buffer.";
38 std::memcpy(allocation->GetBuffer(), &header,
sizeof(header));
39 vk::Result lookup_result = cache.getOwner().getPipelineCacheData(
40 *cache, &data_size, allocation->GetBuffer() +
sizeof(header));
44 if (lookup_result != vk::Result::eSuccess &&
45 lookup_result != vk::Result::eIncomplete) {
51 if (!allocation_mapping) {
55 *allocation_mapping)) {
63 const fml::UniqueFD& cache_directory,
64 const VkPhysicalDeviceProperties& props) {
65 if (!cache_directory.is_valid()) {
68 std::shared_ptr<fml::FileMapping> on_disk_data =
78 std::memcpy(&on_disk_header,
79 on_disk_data->GetMapping(),
80 sizeof(on_disk_header)
83 if (!on_disk_header.IsCompatibleWith(current_header)) {
85 <<
"Persisted pipeline cache is not compatible with current "
86 "Vulkan context. Ignoring.";
90 if (on_disk_header.data_size == 0u) {
93 return std::make_unique<fml::NonOwnedMapping>(
94 on_disk_data->GetMapping() +
sizeof(on_disk_header),
95 on_disk_header.data_size, [on_disk_data](
auto,
auto) {});
101 const VkPhysicalDeviceProperties& props,
102 uint64_t p_data_size)
103 : driver_version(props.driverVersion),
104 vendor_id(props.vendorID),
105 device_id(props.deviceID),
106 data_size(p_data_size) {
107 std::memcpy(
uuid, props.pipelineCacheUUID, VK_UUID_SIZE);
118 std::memcmp(
uuid, o.
uuid, VK_UUID_SIZE) == 0;
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...
std::shared_ptr< fml::Mapping > CreateMappingFromAllocation(const std::shared_ptr< Allocation > &allocation)
Creates a mapping from allocation.
static constexpr const char * kPipelineCacheFileName
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...