31 std::stringstream stream;
35 stream <<
"_unknown_";
41 stream <<
"_fragment_";
44 stream <<
"_compute_";
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) {
71 if (!blob_library.ok()) {
73 << blob_library.status().ToString();
76 blob_library->IterateAllShaders(iterator);
80 VALIDATION_LOG <<
"Could not create shader modules for all shader blobs.";
86ShaderLibraryVK::~ShaderLibraryVK() =
default;
88bool ShaderLibraryVK::IsValid()
const {
93std::shared_ptr<const ShaderFunction> ShaderLibraryVK::GetFunction(
94 std::string_view
name,
99 auto found = functions_.find(
key);
100 if (found != functions_.end()) {
101 return found->second;
107void ShaderLibraryVK::RegisterFunction(std::string
name,
109 std::shared_ptr<fml::Mapping> code,
111 const auto result = RegisterFunction(
name, stage, code);
119 const uint32_t kSPIRVMagic = 0x07230203;
120 if (mapping.
GetSize() <
sizeof(kSPIRVMagic)) {
124 ::memcpy(&magic, mapping.
GetMapping(),
sizeof(magic));
125 return magic == kSPIRVMagic;
128bool ShaderLibraryVK::RegisterFunction(
129 const std::string&
name,
131 const std::shared_ptr<fml::Mapping>& code) {
141 vk::ShaderModuleCreateInfo shader_module_info;
143 shader_module_info.setPCode(
144 reinterpret_cast<const uint32_t*
>(code->GetMapping()));
145 shader_module_info.setCodeSize(code->GetSize());
147 auto device_holder = device_holder_.lock();
148 if (!device_holder) {
153 device_holder->GetDevice().createShaderModuleUnique(shader_module_info);
155 if (module.result != vk::Result::eSuccess) {
157 << vk::to_string(module.result);
161 vk::UniqueShaderModule shader_module = std::move(module.value);
162 ContextVK::SetDebugName(device_holder->GetDevice(), *shader_module,
165 WriterLock lock(functions_mutex_);
166 functions_[ShaderKey{
name, stage}] = std::shared_ptr<ShaderFunctionVK>(
167 new ShaderFunctionVK(device_holder_,
171 std::move(shader_module)
178void ShaderLibraryVK::UnregisterFunction(std::string
name, ShaderStage stage) {
179 WriterLock lock(functions_mutex_);
181 const auto key = ShaderKey{
name, stage};
183 auto found = functions_.find(
key);
184 if (found == functions_.end()) {
186 <<
" was not found, so it couldn't be unregistered.";
190 functions_.erase(found);
virtual const uint8_t * GetMapping() const =0
virtual size_t GetSize() const =0
static absl::StatusOr< ShaderArchive > Create(std::shared_ptr< fml::Mapping > payload)
FlutterDesktopBinaryReply callback
#define FML_UNREACHABLE()
#define FML_DCHECK(condition)
constexpr ShaderStage ToShaderStage(RuntimeShaderStage stage)
static bool IsMappingSPIRV(const fml::Mapping &mapping)
static std::string VKShaderNameToShaderKeyName(const std::string &name, ShaderStage stage)
#define TRACE_EVENT0(category_group, name)