179 {
180 if (payload == nullptr || !payload->GetMapping()) {
181 return nullptr;
182 }
183 if (!impeller::fb::shaderbundle::ShaderBundleBufferHasIdentifier(
184 payload->GetMapping())) {
185 return nullptr;
186 }
187 auto* bundle =
188 impeller::fb::shaderbundle::GetShaderBundle(payload->GetMapping());
189 if (!bundle) {
190 return nullptr;
191 }
192
194
195 for (const auto* bundled_shader : *bundle->shaders()) {
196 const impeller::fb::shaderbundle::BackendShader* backend_shader =
198 if (!backend_shader) {
200 << bundled_shader->name()->c_str() << "\" from bundle.";
201 continue;
202 }
203
204 auto code_mapping = std::make_shared<fml::NonOwnedMapping>(
205 backend_shader->shader()->data(),
206 backend_shader->shader()->size(),
207 [payload = payload](auto, auto) {}
208 );
209
210 std::unordered_map<std::string, Shader::UniformBinding> uniform_structs;
211 if (backend_shader->uniform_structs() != nullptr) {
212 for (const auto& uniform : *backend_shader->uniform_structs()) {
213 std::vector<impeller::ShaderStructMemberMetadata> members;
214 if (uniform->fields() != nullptr) {
215 for (const auto& struct_member : *uniform->fields()) {
218 .name = struct_member->name()->c_str(),
219 .offset = static_cast<size_t>(struct_member->offset_in_bytes()),
221 static_cast<size_t>(struct_member->element_size_in_bytes()),
222 .byte_length =
223 static_cast<size_t>(struct_member->total_size_in_bytes()),
224 .array_elements =
225 struct_member->array_elements() != 0
226 ? std::optional<size_t>(std::nullopt)
227 : static_cast<size_t>(struct_member->array_elements()),
228 });
229 }
230 }
231
232 uniform_structs[uniform->name()->str()] = Shader::UniformBinding{
233 .slot =
235 .
name = uniform->name()->c_str(),
236 .ext_res_0 = static_cast<size_t>(uniform->ext_res_0()),
237 .set = static_cast<size_t>(uniform->set()),
238 .binding = static_cast<size_t>(uniform->binding()),
239 },
240 .metadata =
242 .
name = uniform->name()->c_str(),
243 .members = members,
244 },
245 .size_in_bytes = static_cast<size_t>(uniform->size_in_bytes()),
246 };
247 }
248 }
249
250 std::unordered_map<std::string, impeller::SampledImageSlot>
251 uniform_textures;
252 if (backend_shader->uniform_textures() != nullptr) {
253 for (const auto& uniform : *backend_shader->uniform_textures()) {
255 .
name = uniform->name()->c_str(),
256 .texture_index = static_cast<size_t>(uniform->ext_res_0()),
257 .set = static_cast<size_t>(uniform->set()),
258 .binding = static_cast<size_t>(uniform->binding()),
259 };
260 }
261 }
262
263 std::shared_ptr<impeller::VertexDescriptor> vertex_descriptor = nullptr;
264 if (backend_shader->stage() ==
265 impeller::fb::shaderbundle::ShaderStage::kVertex) {
266 vertex_descriptor = std::make_shared<impeller::VertexDescriptor>();
267 auto inputs_fb = backend_shader->inputs();
268
269 std::vector<impeller::ShaderStageIOSlot>
inputs;
270 inputs.reserve(inputs_fb->size());
271 size_t default_stride = 0;
272 for (const auto& input : *inputs_fb) {
274 slot.
name = input->name()->c_str();
276 slot.
set = input->set();
277 slot.
binding = input->binding();
281 slot.
columns = input->columns();
282 slot.
offset = input->offset();
283 inputs.emplace_back(slot);
284
285 default_stride +=
287 }
288 std::vector<impeller::ShaderStageBufferLayout> layouts = {
291 .binding = 0u,
292 }};
293
294 vertex_descriptor->SetStageInputs(inputs, layouts);
295 }
296
298 backend_shader->entrypoint()->str(),
299 ToShaderStage(backend_shader->stage()), std::move(code_mapping),
300 std::move(vertex_descriptor), std::move(uniform_structs),
301 std::move(uniform_textures));
302 shader_map[bundled_shader->name()->str()] = std::move(shader);
303 }
304
305 return fml::MakeRefCounted<flutter::gpu::ShaderLibrary>(
306 std::move(payload), std::move(shader_map));
307}
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::shared_ptr< impeller::VertexDescriptor > vertex_desc, std::unordered_map< std::string, UniformBinding > uniform_structs, std::unordered_map< std::string, impeller::SampledImageSlot > uniform_textures)
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
Metadata required to bind a combined texture and sampler.
const char * name
The name of the uniform slot.