180 {
181 if (payload == nullptr || !payload->GetMapping()) {
182 return nullptr;
183 }
184 if (!impeller::fb::shaderbundle::ShaderBundleBufferHasIdentifier(
185 payload->GetMapping())) {
186 return nullptr;
187 }
188 auto* bundle =
189 impeller::fb::shaderbundle::GetShaderBundle(payload->GetMapping());
190 if (!bundle) {
191 return nullptr;
192 }
193
195
196 for (const auto* bundled_shader : *bundle->shaders()) {
197 const impeller::fb::shaderbundle::BackendShader* backend_shader =
199 if (!backend_shader) {
201 << bundled_shader->name()->c_str() << "\" from bundle.";
202 continue;
203 }
204
205 auto code_mapping = std::make_shared<fml::NonOwnedMapping>(
206 backend_shader->shader()->data(),
207 backend_shader->shader()->size(),
208 [payload = payload](auto, auto) {}
209 );
210
211 std::vector<impeller::DescriptorSetLayout> descriptor_set_layouts;
212
213 std::unordered_map<std::string, Shader::UniformBinding> uniform_structs;
214 if (backend_shader->uniform_structs() != nullptr) {
215 for (const auto& uniform : *backend_shader->uniform_structs()) {
216 std::vector<impeller::ShaderStructMemberMetadata> members;
217 if (uniform->fields() != nullptr) {
218 for (const auto& struct_member : *uniform->fields()) {
221 .name = struct_member->name()->c_str(),
222 .offset = static_cast<size_t>(struct_member->offset_in_bytes()),
224 static_cast<size_t>(struct_member->element_size_in_bytes()),
225 .byte_length =
226 static_cast<size_t>(struct_member->total_size_in_bytes()),
227 .array_elements =
228 struct_member->array_elements() != 0
229 ? std::optional<size_t>(std::nullopt)
230 : static_cast<size_t>(struct_member->array_elements()),
231 });
232 }
233 }
234
235 uniform_structs[uniform->name()->str()] = Shader::UniformBinding{
236 .slot =
238 .
name = uniform->name()->c_str(),
239 .ext_res_0 = static_cast<size_t>(uniform->ext_res_0()),
240 .
set =
static_cast<size_t>(uniform->set()),
241 .binding = static_cast<size_t>(uniform->binding()),
242 },
243 .metadata =
245 .
name = uniform->name()->c_str(),
246 .members = members,
247 },
248 .size_in_bytes = static_cast<size_t>(uniform->size_in_bytes()),
249 };
250
252 static_cast<uint32_t>(uniform->binding()),
255 });
256 }
257 }
258
259 std::unordered_map<std::string, impeller::SampledImageSlot>
260 uniform_textures;
261 if (backend_shader->uniform_textures() != nullptr) {
262 for (const auto& uniform : *backend_shader->uniform_textures()) {
264 .
name = uniform->name()->c_str(),
265 .texture_index = static_cast<size_t>(uniform->ext_res_0()),
266 .
set =
static_cast<size_t>(uniform->set()),
267 .binding = static_cast<size_t>(uniform->binding()),
268 };
269
271 static_cast<uint32_t>(uniform->binding()),
274 });
275 }
276 }
277
278 std::vector<impeller::ShaderStageIOSlot>
inputs;
279 std::vector<impeller::ShaderStageBufferLayout> layouts;
280 if (backend_shader->stage() ==
281 impeller::fb::shaderbundle::ShaderStage::kVertex) {
282 auto inputs_fb = backend_shader->inputs();
283
284 inputs.reserve(inputs_fb->size());
285 size_t default_stride = 0;
286 for (const auto& input : *inputs_fb) {
288 slot.
name = input->name()->c_str();
290 slot.
set = input->set();
291 slot.
binding = input->binding();
295 slot.
columns = input->columns();
296 slot.
offset = input->offset();
297 inputs.emplace_back(slot);
298
299 default_stride +=
301 }
304 .binding = 0u,
305 }};
306 }
307
309 backend_shader->entrypoint()->str(),
310 ToShaderStage(backend_shader->stage()), std::move(code_mapping),
311 std::move(
inputs), std::move(layouts), std::move(uniform_structs),
312 std::move(uniform_textures), std::move(descriptor_set_layouts));
313 shader_map[bundled_shader->name()->str()] = std::move(shader);
314 }
315
316 return fml::MakeRefCounted<flutter::gpu::ShaderLibrary>(
317 std::move(payload), std::move(shader_map));
318}
std::unordered_map< std::string, fml::RefPtr< Shader > > ShaderMap
static fml::RefPtr< Shader > Make(std::string entrypoint, impeller::ShaderStage stage, std::shared_ptr< fml::Mapping > code_mapping, std::vector< impeller::ShaderStageIOSlot > inputs, std::vector< impeller::ShaderStageBufferLayout > layouts, std::unordered_map< std::string, UniformBinding > uniform_structs, std::unordered_map< std::string, impeller::SampledImageSlot > uniform_textures, std::vector< impeller::DescriptorSetLayout > descriptor_set_layouts)
static const impeller::fb::shaderbundle::BackendShader * GetShaderBackend(impeller::Context::BackendType backend_type, const impeller::fb::shaderbundle::Shader *shader)
static impeller::ShaderType FromUniformType(impeller::fb::shaderbundle::UniformDataType uniform_type)
static impeller::ShaderType FromInputType(impeller::fb::shaderbundle::InputDataType input_type)
static impeller::ShaderStage ToShaderStage(impeller::fb::shaderbundle::ShaderStage stage)
static size_t SizeOfInputType(impeller::fb::shaderbundle::InputDataType input_type)
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not set
Metadata required to bind a combined texture and sampler.
const char * name
The name of the uniform slot.