9#include "flutter/fml/logging.h"
10#include "flutter/fml/trace_event.h"
51ShaderLibraryVK::ShaderLibraryVK(
52 std::weak_ptr<DeviceHolderVK> device_holder,
53 const std::vector<std::shared_ptr<fml::Mapping>>& shader_libraries_data)
54 : device_holder_(
std::move(device_holder)) {
57 auto iterator = [&](
auto type,
69 for (
const auto& library_data : shader_libraries_data) {
70 auto blob_library = ShaderArchive{library_data};
71 if (!blob_library.IsValid()) {
75 blob_library.IterateAllShaders(iterator);
79 VALIDATION_LOG <<
"Could not create shader modules for all shader blobs.";
85ShaderLibraryVK::~ShaderLibraryVK() =
default;
87bool ShaderLibraryVK::IsValid()
const {
93 std::string_view
name,
98 auto found = functions_.find(
key);
99 if (found != functions_.end()) {
100 return found->second;
106void ShaderLibraryVK::RegisterFunction(std::string
name,
108 std::shared_ptr<fml::Mapping>
code,
118 const uint32_t kSPIRVMagic = 0x07230203;
119 if (mapping.
GetSize() <
sizeof(kSPIRVMagic)) {
124 return magic == kSPIRVMagic;
127bool ShaderLibraryVK::RegisterFunction(
128 const std::string&
name,
130 const std::shared_ptr<fml::Mapping>&
code) {
140 vk::ShaderModuleCreateInfo shader_module_info;
142 shader_module_info.setPCode(
143 reinterpret_cast<const uint32_t*
>(
code->GetMapping()));
144 shader_module_info.setCodeSize(
code->GetSize());
146 auto device_holder = device_holder_.lock();
147 if (!device_holder) {
152 device_holder->GetDevice().createShaderModuleUnique(shader_module_info);
154 if (module.result != vk::Result::eSuccess) {
160 vk::UniqueShaderModule shader_module = std::move(module.value);
161 ContextVK::SetDebugName(device_holder->GetDevice(), *shader_module,
164 WriterLock lock(functions_mutex_);
165 functions_[ShaderKey{
name, stage}] = std::shared_ptr<ShaderFunctionVK>(
166 new ShaderFunctionVK(device_holder_,
170 std::move(shader_module)
177void ShaderLibraryVK::UnregisterFunction(std::string
name,
ShaderStage stage) {
178 WriterLock lock(functions_mutex_);
180 const auto key = ShaderKey{
name, stage};
182 auto found = functions_.find(
key);
183 if (found == functions_.end()) {
185 <<
" was not found, so it couldn't be unregistered.";
189 functions_.erase(found);
virtual const uint8_t * GetMapping() const =0
virtual size_t GetSize() const =0
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
#define FML_UNREACHABLE()
#define FML_DCHECK(condition)
FunctionPtr GetFunction(const Library &lib, const char *name)
DEF_SWITCHES_START aot vmservice shared library name
constexpr ShaderStage ToShaderStage(RuntimeShaderStage stage)
static bool IsMappingSPIRV(const fml::Mapping &mapping)
static std::string VKShaderNameToShaderKeyName(const std::string &name, ShaderStage stage)
static SkString to_string(int n)
#define TRACE_EVENT0(category_group, name)