@@ -293,79 +293,92 @@ std::shared_ptr<fml::Mapping> RuntimeStageData::CreateJsonMapping() const {
293
293
json_string->size (), [json_string](auto , auto ) {});
294
294
}
295
295
296
- std::unique_ptr<fb::RuntimeStagesT> RuntimeStageData::CreateFlatbuffer () const {
297
- // The high level object API is used here for writing to the buffer. This is
298
- // just a convenience.
299
- auto runtime_stages = std::make_unique<fb::RuntimeStagesT>();
296
+ std::unique_ptr<fb::RuntimeStageT> RuntimeStageData::CreateStageFlatbuffer (
297
+ impeller::RuntimeStageBackend backend) const {
298
+ auto kvp = data_.find (backend);
299
+ if (kvp == data_.end ()) {
300
+ return nullptr ;
301
+ }
300
302
301
- for (const auto & kvp : data_) {
302
- auto runtime_stage = std::make_unique<fb::RuntimeStageT>();
303
- runtime_stage->entrypoint = kvp.second ->entrypoint ;
304
- const auto stage = ToStage (kvp.second ->stage );
305
- if (!stage.has_value ()) {
306
- VALIDATION_LOG << " Invalid runtime stage." ;
303
+ auto runtime_stage = std::make_unique<fb::RuntimeStageT>();
304
+ runtime_stage->entrypoint = kvp->second ->entrypoint ;
305
+ const auto stage = ToStage (kvp->second ->stage );
306
+ if (!stage.has_value ()) {
307
+ VALIDATION_LOG << " Invalid runtime stage." ;
308
+ return nullptr ;
309
+ }
310
+ runtime_stage->stage = stage.value ();
311
+ if (!kvp->second ->shader ) {
312
+ VALIDATION_LOG << " No shader specified for runtime stage." ;
313
+ return nullptr ;
314
+ }
315
+ if (kvp->second ->shader ->GetSize () > 0u ) {
316
+ runtime_stage->shader = {
317
+ kvp->second ->shader ->GetMapping (),
318
+ kvp->second ->shader ->GetMapping () + kvp->second ->shader ->GetSize ()};
319
+ }
320
+ for (const auto & uniform : kvp->second ->uniforms ) {
321
+ auto desc = std::make_unique<fb::UniformDescriptionT>();
322
+
323
+ desc->name = uniform.name ;
324
+ if (desc->name .empty ()) {
325
+ VALIDATION_LOG << " Uniform name cannot be empty." ;
307
326
return nullptr ;
308
327
}
309
- runtime_stage->stage = stage.value ();
310
- if (!kvp.second ->shader ) {
311
- VALIDATION_LOG << " No shader specified for runtime stage." ;
328
+ desc->location = uniform.location ;
329
+ desc->rows = uniform.rows ;
330
+ desc->columns = uniform.columns ;
331
+ auto uniform_type = ToUniformType (uniform.type );
332
+ if (!uniform_type.has_value ()) {
333
+ VALIDATION_LOG << " Invalid uniform type for runtime stage." ;
312
334
return nullptr ;
313
335
}
314
- if (kvp. second -> shader -> GetSize () > 0u ) {
315
- runtime_stage-> shader = {
316
- kvp. second -> shader -> GetMapping (),
317
- kvp. second -> shader -> GetMapping () + kvp. second -> shader -> GetSize ()} ;
336
+ desc-> type = uniform_type. value ();
337
+ desc-> bit_width = uniform. bit_width ;
338
+ if (uniform. array_elements . has_value ()) {
339
+ desc-> array_elements = uniform. array_elements . value () ;
318
340
}
319
- for (const auto & uniform : kvp.second ->uniforms ) {
320
- auto desc = std::make_unique<fb::UniformDescriptionT>();
321
341
322
- desc->name = uniform.name ;
323
- if (desc->name .empty ()) {
324
- VALIDATION_LOG << " Uniform name cannot be empty." ;
325
- return nullptr ;
326
- }
327
- desc->location = uniform.location ;
328
- desc->rows = uniform.rows ;
329
- desc->columns = uniform.columns ;
330
- auto uniform_type = ToUniformType (uniform.type );
331
- if (!uniform_type.has_value ()) {
332
- VALIDATION_LOG << " Invalid uniform type for runtime stage." ;
333
- return nullptr ;
334
- }
335
- desc->type = uniform_type.value ();
336
- desc->bit_width = uniform.bit_width ;
337
- if (uniform.array_elements .has_value ()) {
338
- desc->array_elements = uniform.array_elements .value ();
339
- }
342
+ runtime_stage->uniforms .emplace_back (std::move (desc));
343
+ }
344
+
345
+ for (const auto & input : kvp->second ->inputs ) {
346
+ auto desc = std::make_unique<fb::StageInputT>();
347
+
348
+ desc->name = input.name ;
340
349
341
- runtime_stage->uniforms .emplace_back (std::move (desc));
350
+ if (desc->name .empty ()) {
351
+ VALIDATION_LOG << " Stage input name cannot be empty." ;
352
+ return nullptr ;
353
+ }
354
+ desc->location = input.location ;
355
+ desc->set = input.set ;
356
+ desc->binding = input.binding ;
357
+ auto input_type = ToInputType (input.type );
358
+ if (!input_type.has_value ()) {
359
+ VALIDATION_LOG << " Invalid uniform type for runtime stage." ;
360
+ return nullptr ;
342
361
}
362
+ desc->type = input_type.value ();
363
+ desc->bit_width = input.bit_width ;
364
+ desc->vec_size = input.vec_size ;
365
+ desc->columns = input.columns ;
366
+ desc->offset = input.offset ;
343
367
344
- for ( const auto & input : kvp. second ->inputs ) {
345
- auto desc = std::make_unique<fb::StageInputT>();
368
+ runtime_stage ->inputs . emplace_back ( std::move (desc));
369
+ }
346
370
347
- desc->name = input.name ;
371
+ return runtime_stage;
372
+ }
348
373
349
- if (desc->name .empty ()) {
350
- VALIDATION_LOG << " Stage input name cannot be empty." ;
351
- return nullptr ;
352
- }
353
- desc->location = input.location ;
354
- desc->set = input.set ;
355
- desc->binding = input.binding ;
356
- auto input_type = ToInputType (input.type );
357
- if (!input_type.has_value ()) {
358
- VALIDATION_LOG << " Invalid uniform type for runtime stage." ;
359
- return nullptr ;
360
- }
361
- desc->type = input_type.value ();
362
- desc->bit_width = input.bit_width ;
363
- desc->vec_size = input.vec_size ;
364
- desc->columns = input.columns ;
365
- desc->offset = input.offset ;
374
+ std::unique_ptr<fb::RuntimeStagesT>
375
+ RuntimeStageData::CreateMultiStageFlatbuffer () const {
376
+ // The high level object API is used here for writing to the buffer. This is
377
+ // just a convenience.
378
+ auto runtime_stages = std::make_unique<fb::RuntimeStagesT>();
366
379
367
- runtime_stage-> inputs . emplace_back ( std::move (desc));
368
- }
380
+ for ( const auto & kvp : data_) {
381
+ auto runtime_stage = CreateStageFlatbuffer (kvp. first );
369
382
switch (kvp.first ) {
370
383
case RuntimeStageBackend::kSkSL :
371
384
runtime_stages->sksl = std::move (runtime_stage);
@@ -385,7 +398,7 @@ std::unique_ptr<fb::RuntimeStagesT> RuntimeStageData::CreateFlatbuffer() const {
385
398
}
386
399
387
400
std::shared_ptr<fml::Mapping> RuntimeStageData::CreateMapping () const {
388
- auto runtime_stages = CreateFlatbuffer ();
401
+ auto runtime_stages = CreateMultiStageFlatbuffer ();
389
402
if (!runtime_stages) {
390
403
return nullptr ;
391
404
}
0 commit comments