11#include "flutter/fml/mapping.h"
17 "flutter.impeller.vkcache";
25 std::shared_ptr<fml::Mapping>
data) {
30 std::unique_ptr<fml::Mapping>
data) {
36 const std::string& cache_file_name,
41 std::unique_ptr<fml::Mapping> mapping =
57 std::shared_ptr<DeviceHolderVK> device_holder,
59 : caps_(
std::move(caps)),
60 device_holder_(device_holder),
61 cache_directory_(
std::move(cache_directory)) {
62 if (!caps_ || !device_holder->GetDevice()) {
68 auto existing_cache_data =
71 vk::PipelineCacheCreateInfo cache_info;
72 if (existing_cache_data) {
73 cache_info.initialDataSize = existing_cache_data->GetSize();
74 cache_info.pInitialData = existing_cache_data->GetMapping();
77 auto [
result, existing_cache] =
78 device_holder->GetDevice().createPipelineCacheUnique(cache_info);
80 if (
result == vk::Result::eSuccess) {
81 cache_ = std::move(existing_cache);
86 FML_LOG(INFO) <<
"Existing pipeline cache was invalid: "
88 cache_info.pInitialData =
nullptr;
89 cache_info.initialDataSize = 0u;
90 auto [result2, new_cache] =
91 device_holder->GetDevice().createPipelineCacheUnique(cache_info);
92 if (result2 == vk::Result::eSuccess) {
93 cache_ = std::move(new_cache);
100 is_valid_ = !!cache_;
104 std::shared_ptr<DeviceHolderVK> device_holder = device_holder_.lock();
117 const vk::GraphicsPipelineCreateInfo&
info) {
118 std::shared_ptr<DeviceHolderVK> strong_device = device_holder_.lock();
119 if (!strong_device) {
124 strong_device->GetDevice().createGraphicsPipelineUnique(*cache_,
info);
125 if (
result != vk::Result::eSuccess) {
129 return std::move(pipeline);
133 const vk::ComputePipelineCreateInfo&
info) {
134 std::shared_ptr<DeviceHolderVK> strong_device = device_holder_.lock();
135 if (!strong_device) {
140 strong_device->GetDevice().createComputePipelineUnique(*cache_,
info);
141 if (
result != vk::Result::eSuccess) {
145 return std::move(pipeline);
148std::shared_ptr<fml::Mapping> PipelineCacheVK::CopyPipelineCacheData()
const {
149 std::shared_ptr<DeviceHolderVK> strong_device = device_holder_.lock();
150 if (!strong_device) {
158 strong_device->GetDevice().getPipelineCacheData(*cache_);
159 if (
result != vk::Result::eSuccess) {
160 VALIDATION_LOG <<
"Could not get pipeline cache data to persist.";
163 auto shared_data = std::make_shared<std::vector<uint8_t>>();
165 return std::make_shared<fml::NonOwnedMapping>(
166 shared_data->data(), shared_data->size(), [shared_data](
auto,
auto) {});
173 auto data = CopyPipelineCacheData();
181 <<
"Could not decorate pipeline cache with additional metadata.";
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
void swap(sk_sp< T > &a, sk_sp< T > &b)
static std::unique_ptr< FileMapping > CreateReadOnly(const std::string &path)
static CapabilitiesVK & Cast(Capabilities &base)
The Vulkan layers and extensions wrangler.
PipelineCacheVK(std::shared_ptr< const Capabilities > caps, std::shared_ptr< DeviceHolderVK > device_holder, fml::UniqueFD cache_directory)
vk::UniquePipeline CreatePipeline(const vk::GraphicsPipelineCreateInfo &info)
void PersistCacheToDisk() const
const CapabilitiesVK * GetCapabilities() const
#define FML_LOG(severity)
bool WriteAtomically(const fml::UniqueFD &base_directory, const char *file_name, const Mapping &mapping)
static std::unique_ptr< fml::Mapping > OpenCacheFile(const fml::UniqueFD &base_directory, const std::string &cache_file_name, const CapabilitiesVK &caps)
static std::unique_ptr< fml::Mapping > RemoveMetadataFromCache(std::unique_ptr< fml::Mapping > data)
static std::shared_ptr< fml::Mapping > DecorateCacheWithMetadata(std::shared_ptr< fml::Mapping > data)
static bool VerifyExistingCache(const fml::Mapping &mapping, const CapabilitiesVK &caps)
static constexpr const char * kPipelineCacheFileName
static SkString to_string(int n)
std::shared_ptr< const fml::Mapping > data