| Flutter Impeller |

Public Member Functions | List of all members
impeller::PipelineCacheVK Class Reference

`#include <pipeline_cache_vk.h>`

## Public Member Functions
| PipelineCacheVK (std::shared_ptr< const Capabilities > caps, std::shared_ptr< DeviceHolderVK > device_holder, fml::UniqueFD cache_directory)
| ~PipelineCacheVK ()
bool | IsValid () const
vk::UniquePipeline | CreatePipeline (const vk::GraphicsPipelineCreateInfo &info)
vk::UniquePipeline | CreatePipeline (const vk::ComputePipelineCreateInfo &info)
const CapabilitiesVK * | GetCapabilities () const
void | PersistCacheToDisk () const

## Detailed Description

Definition at line 14 of file pipeline_cache_vk.h.

## Constructor & Destructor Documentation

## ◆ PipelineCacheVK()

impeller::PipelineCacheVK::PipelineCacheVK | ( | std::shared_ptr< const Capabilities > | caps,
|  | std::shared_ptr< DeviceHolderVK > | device_holder,
|  | fml::UniqueFD | cache_directory
| ) |  |
| explicit

Definition at line 56 of file pipeline_cache_vk.cc.

59 : caps_(std::move(caps)),
60 device_holder_(device_holder),
61 cache_directory_(std::move(cache_directory)) {
62 if (!caps_ || !device_holder->GetDevice()) {
63 return;
64 }
65
66 const auto& vk_caps = CapabilitiesVK::Cast(*caps_);
67
68 auto existing_cache_data =
69 OpenCacheFile(cache_directory_, kPipelineCacheFileName, vk_caps);
70
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();
75 }
76
77 auto [result, existing_cache] =
78 device_holder->GetDevice().createPipelineCacheUnique(cache_info);
79
80 if (result == vk::Result::eSuccess) {
81 cache_ = std::move(existing_cache);
82 } else {
83 // Even though we perform consistency checks because we don't trust the
84 // driver, the driver may have additional information that may cause it to
85 // reject the cache too.
86 FML_LOG(INFO) << "Existing pipeline cache was invalid: "
87 << vk::to_string(result) << ". Starting with a fresh cache.";
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);
94 } else {
95 VALIDATION_LOG << "Could not create new pipeline cache: "
96 << vk::to_string(result2);
97 }
98 }
99
100 is_valid_ = !!cache_;
101 }

References impeller::BackendCast< CapabilitiesVK, Capabilities >::Cast(), impeller::kPipelineCacheFileName, impeller::OpenCacheFile(), and VALIDATION_LOG.

## ◆ ~PipelineCacheVK()

impeller::PipelineCacheVK::~PipelineCacheVK | ( |  | ) |

Definition at line 103 of file pipeline_cache_vk.cc.

103 {
104 std::shared_ptr<DeviceHolderVK> device_holder = device_holder_.lock();
105 if (device_holder) {
106 cache_.reset();
107 } else {
108 cache_.release();
109 }
110 }

## Member Function Documentation

## ◆ CreatePipeline() [1/2]

vk::UniquePipeline impeller::PipelineCacheVK::CreatePipeline | ( | const vk::ComputePipelineCreateInfo & | info | ) |

Definition at line 132 of file pipeline_cache_vk.cc.

133 {
134 std::shared_ptr<DeviceHolderVK> strong_device = device_holder_.lock();
135 if (!strong_device) {
136 return {};
137 }
138
139 auto [result, pipeline] =
140 strong_device->GetDevice().createComputePipelineUnique(*cache_, info);
141 if (result != vk::Result::eSuccess) {
142 VALIDATION_LOG << "Could not create compute pipeline: "
143 << vk::to_string(result);
144 }
145 return std::move(pipeline);
146 }

References VALIDATION_LOG.

## ◆ CreatePipeline() [2/2]

vk::UniquePipeline impeller::PipelineCacheVK::CreatePipeline | ( | const vk::GraphicsPipelineCreateInfo & | info | ) |

Definition at line 116 of file pipeline_cache_vk.cc.

117 {
118 std::shared_ptr<DeviceHolderVK> strong_device = device_holder_.lock();
119 if (!strong_device) {
120 return {};
121 }
122
123 auto [result, pipeline] =
124 strong_device->GetDevice().createGraphicsPipelineUnique(*cache_, info);
125 if (result != vk::Result::eSuccess) {
126 VALIDATION_LOG << "Could not create graphics pipeline: "
127 << vk::to_string(result);
128 }
129 return std::move(pipeline);
130 }

References VALIDATION_LOG.

## ◆ GetCapabilities()

const CapabilitiesVK * impeller::PipelineCacheVK::GetCapabilities | ( |  | ) | const

Definition at line 190 of file pipeline_cache_vk.cc.

190 {
191 return CapabilitiesVK::Cast(caps_.get());
192 }

References impeller::BackendCast< CapabilitiesVK, Capabilities >::Cast().

## ◆ IsValid()

bool impeller::PipelineCacheVK::IsValid | ( |  | ) | const

Definition at line 112 of file pipeline_cache_vk.cc.

112 {
113 return is_valid_;
114 }

## ◆ PersistCacheToDisk()

void impeller::PipelineCacheVK::PersistCacheToDisk | ( |  | ) | const

Definition at line 169 of file pipeline_cache_vk.cc.

169 {
170 if (!cache_directory_.is_valid()) {
171 return;
172 }
173 auto data = CopyPipelineCacheData();
174 if (!data) {
175 VALIDATION_LOG << "Could not copy pipeline cache data.";
176 return;
177 }
178 data = DecorateCacheWithMetadata(std::move(data));
179 if (!data) {
180 VALIDATION_LOG
181 << "Could not decorate pipeline cache with additional metadata.";
182 return;
183 }
184 if (!fml::WriteAtomically(cache_directory_, kPipelineCacheFileName, *data)) {
185 VALIDATION_LOG << "Could not persist pipeline cache to disk.";
186 return;
187 }
188 }

References data, impeller::DecorateCacheWithMetadata(), impeller::kPipelineCacheFileName, and VALIDATION_LOG.

The documentation for this class was generated from the following files:

- impeller/renderer/backend/vulkan/pipeline_cache_vk.h
- impeller/renderer/backend/vulkan/pipeline_cache_vk.cc

data
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63
impeller::kPipelineCacheFileName
static constexpr const char * kPipelineCacheFileName
Definition: pipeline_cache_vk.cc:16
impeller::OpenCacheFile
static std::unique_ptr< fml::Mapping > OpenCacheFile(const fml::UniqueFD &base_directory, const std::string &cache_file_name, const CapabilitiesVK &caps)
Definition: pipeline_cache_vk.cc:34
impeller::DecorateCacheWithMetadata
static std::shared_ptr< fml::Mapping > DecorateCacheWithMetadata(std::shared_ptr< fml::Mapping > data)
Definition: pipeline_cache_vk.cc:24
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:73
impeller::BackendCast< CapabilitiesVK, Capabilities >::Cast
static CapabilitiesVK & Cast(Capabilities &base)
Definition: backend_cast.h:13