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.";
40 vk::Result lookup_result = cache.getOwner().getPipelineCacheData(
46 if (lookup_result != vk::Result::eSuccess &&
47 lookup_result != vk::Result::eIncomplete) {
53 std::memcpy(allocation->GetBuffer(), &header,
sizeof(header));
55 fml::NonOwnedMapping allocation_mapping(
58 allocation_mapping)) {
66 const fml::UniqueFD& cache_directory,
67 const VkPhysicalDeviceProperties& props) {
68 if (!cache_directory.is_valid()) {
71 std::shared_ptr<fml::FileMapping> on_disk_data =
81 std::memcpy(&on_disk_header,
82 on_disk_data->GetMapping(),
83 sizeof(on_disk_header)
86 if (!on_disk_header.IsCompatibleWith(current_header)) {
88 <<
"Persisted pipeline cache is not compatible with current "
89 "Vulkan context. Ignoring.";
93 if (on_disk_header.data_size == 0u) {
96 return std::make_unique<fml::NonOwnedMapping>(
97 on_disk_data->GetMapping() +
sizeof(on_disk_header),
98 on_disk_header.data_size, [on_disk_data](
auto,
auto) {});
104 const VkPhysicalDeviceProperties& props,
105 uint64_t p_data_size)
106 : driver_version(props.driverVersion),
107 vendor_id(props.vendorID),
108 device_id(props.deviceID),
109 data_size(p_data_size) {
110 std::memcpy(
uuid, props.pipelineCacheUUID, VK_UUID_SIZE);
121 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...
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...