| 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 18 of file pipeline_cache_vk.cc.

21 : caps_(std::move(caps)),
22 device_holder_(device_holder),
23 cache_directory_(std::move(cache_directory)) {
24 if (!caps_ || !device_holder->GetDevice()) {
25 return;
26 }
27
28 const auto& vk_caps = CapabilitiesVK::Cast(*caps_);
29
30 auto existing_cache_data = PipelineCacheDataRetrieve(
31 cache_directory_, vk_caps.GetPhysicalDeviceProperties());
32
33 vk::PipelineCacheCreateInfo cache_info;
34 if (existing_cache_data) {
35 cache_info.initialDataSize = existing_cache_data->GetSize();
36 cache_info.pInitialData = existing_cache_data->GetMapping();
37 }
38
39 auto [result, existing_cache] =
40 device_holder->GetDevice().createPipelineCacheUnique(cache_info);
41
42 if (result == vk::Result::eSuccess) {
43 cache_ = std::move(existing_cache);
44 } else {
45 // Even though we perform consistency checks because we don't trust the
46 // driver, the driver may have additional information that may cause it to
47 // reject the cache too.
48 FML_LOG(INFO) << "Existing pipeline cache was invalid: "
49 << vk::to_string(result) << ". Starting with a fresh cache.";
50 cache_info.pInitialData = nullptr;
51 cache_info.initialDataSize = 0u;
52 auto [result2, new_cache] =
53 device_holder->GetDevice().createPipelineCacheUnique(cache_info);
54 if (result2 == vk::Result::eSuccess) {
55 cache_ = std::move(new_cache);
56 } else {
57 VALIDATION_LOG << "Could not create new pipeline cache: "
58 << vk::to_string(result2);
59 }
60 }
61
62 is_valid_ = !!cache_;
63 }
impeller::BackendCast< CapabilitiesVK, Capabilities >::Cast
static CapabilitiesVK & Cast(Capabilities &base)
Definition: backend_cast.h:13
impeller::PipelineCacheDataRetrieve
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...
Definition: pipeline_cache_data_vk.cc:62
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:91

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

## ◆ ~PipelineCacheVK()

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

Definition at line 65 of file pipeline_cache_vk.cc.

65 {
66 std::shared_ptr<DeviceHolderVK> device_holder = device_holder_.lock();
67 if (device_holder) {
68 cache_.reset();
69 } else {
70 cache_.release();
71 }
72 }

## Member Function Documentation

## ◆ CreatePipeline() [1/2]

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

Definition at line 94 of file pipeline_cache_vk.cc.

95 {
96 std::shared_ptr<DeviceHolderVK> strong_device = device_holder_.lock();
97 if (!strong_device) {
98 return {};
99 }
100
101 auto [result, pipeline] =
102 strong_device->GetDevice().createComputePipelineUnique(*cache_, info);
103 if (result != vk::Result::eSuccess) {
104 VALIDATION_LOG << "Could not create compute pipeline: "
105 << vk::to_string(result);
106 }
107 return std::move(pipeline);
108 }

References VALIDATION_LOG.

## ◆ CreatePipeline() [2/2]

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

Definition at line 78 of file pipeline_cache_vk.cc.

79 {
80 std::shared_ptr<DeviceHolderVK> strong_device = device_holder_.lock();
81 if (!strong_device) {
82 return {};
83 }
84
85 auto [result, pipeline] =
86 strong_device->GetDevice().createGraphicsPipelineUnique(*cache_, info);
87 if (result != vk::Result::eSuccess) {
88 VALIDATION_LOG << "Could not create graphics pipeline: "
89 << vk::to_string(result);
90 }
91 return std::move(pipeline);
92 }

References VALIDATION_LOG.

## ◆ GetCapabilities()

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

Definition at line 121 of file pipeline_cache_vk.cc.

121 {
122 return CapabilitiesVK::Cast(caps_.get());
123 }

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

## ◆ IsValid()

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

Definition at line 74 of file pipeline_cache_vk.cc.

74 {
75 return is_valid_;
76 }

## ◆ PersistCacheToDisk()

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

Definition at line 110 of file pipeline_cache_vk.cc.

110 {
111 if (!is_valid_) {
112 return;
113 }
114 const auto& vk_caps = CapabilitiesVK::Cast(*caps_);
115 PipelineCacheDataPersist(cache_directory_, //
116 vk_caps.GetPhysicalDeviceProperties(), //
117 cache_ //
118 );
119 }
impeller::PipelineCacheDataPersist
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...
Definition: pipeline_cache_data_vk.cc:16

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

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