Flutter Impeller
impeller::RuntimeStage Class Reference

#include <runtime_stage.h>

Public Types

using Map = std::map< RuntimeStageBackend, std::shared_ptr< RuntimeStage > >
 

Public Member Functions

 RuntimeStage (const fb::RuntimeStage *runtime_stage, const std::shared_ptr< fml::Mapping > &payload)
 
 ~RuntimeStage ()
 
 RuntimeStage (RuntimeStage &&)
 
RuntimeStageoperator= (RuntimeStage &&)
 
bool IsValid () const
 
RuntimeShaderStage GetShaderStage () const
 
const std::vector< RuntimeUniformDescription > & GetUniforms () const
 
const std::string & GetEntrypoint () const
 
const RuntimeUniformDescriptionGetUniform (const std::string &name) const
 
const std::shared_ptr< fml::Mapping > & GetCodeMapping () const
 
bool IsDirty () const
 
void SetClean ()
 

Static Public Member Functions

static Map DecodeRuntimeStages (const std::shared_ptr< fml::Mapping > &payload)
 

Static Public Attributes

static const char * kVulkanUBOName
 

Detailed Description

Definition at line 19 of file runtime_stage.h.

Member Typedef Documentation

◆ Map

using impeller::RuntimeStage::Map = std::map<RuntimeStageBackend, std::shared_ptr<RuntimeStage> >

Definition at line 23 of file runtime_stage.h.

Constructor & Destructor Documentation

◆ RuntimeStage() [1/2]

impeller::RuntimeStage::RuntimeStage ( const fb::RuntimeStage *  runtime_stage,
const std::shared_ptr< fml::Mapping > &  payload 
)

Definition at line 82 of file runtime_stage.cc.

84  : payload_(payload) {
85  FML_DCHECK(runtime_stage);
86 
87  stage_ = ToShaderStage(runtime_stage->stage());
88  entrypoint_ = runtime_stage->entrypoint()->str();
89 
90  auto* uniforms = runtime_stage->uniforms();
91  if (uniforms) {
92  for (auto i = uniforms->begin(), end = uniforms->end(); i != end; i++) {
93  RuntimeUniformDescription desc;
94  desc.name = i->name()->str();
95  desc.location = i->location();
96  desc.type = ToType(i->type());
97  desc.dimensions = RuntimeUniformDimensions{
98  static_cast<size_t>(i->rows()), static_cast<size_t>(i->columns())};
99  desc.bit_width = i->bit_width();
100  desc.array_elements = i->array_elements();
101  if (i->struct_layout()) {
102  for (const auto& byte_type : *i->struct_layout()) {
103  desc.struct_layout.push_back(static_cast<uint8_t>(byte_type));
104  }
105  }
106  desc.struct_float_count = i->struct_float_count();
107  uniforms_.emplace_back(std::move(desc));
108  }
109  }
110 
111  code_mapping_ = std::make_shared<fml::NonOwnedMapping>(
112  runtime_stage->shader()->data(), //
113  runtime_stage->shader()->size(), //
114  [payload = payload_](auto, auto) {} //
115  );
116 
117  is_valid_ = true;
118 }

References impeller::RuntimeUniformDescription::array_elements, impeller::RuntimeUniformDescription::bit_width, impeller::RuntimeUniformDescription::dimensions, impeller::RuntimeUniformDescription::location, impeller::RuntimeUniformDescription::name, impeller::RuntimeUniformDescription::struct_float_count, impeller::RuntimeUniformDescription::struct_layout, impeller::ToShaderStage(), impeller::ToType(), and impeller::RuntimeUniformDescription::type.

◆ ~RuntimeStage()

impeller::RuntimeStage::~RuntimeStage ( )
default

◆ RuntimeStage() [2/2]

impeller::RuntimeStage::RuntimeStage ( RuntimeStage &&  )
default

Member Function Documentation

◆ DecodeRuntimeStages()

RuntimeStage::Map impeller::RuntimeStage::DecodeRuntimeStages ( const std::shared_ptr< fml::Mapping > &  payload)
static

Definition at line 60 of file runtime_stage.cc.

61  {
62  if (payload == nullptr || !payload->GetMapping()) {
63  return {};
64  }
65  if (!fb::RuntimeStagesBufferHasIdentifier(payload->GetMapping())) {
66  return {};
67  }
68 
69  auto raw_stages = fb::GetRuntimeStages(payload->GetMapping());
70  return {
72  RuntimeStageIfPresent(raw_stages->sksl(), payload)},
74  RuntimeStageIfPresent(raw_stages->metal(), payload)},
76  RuntimeStageIfPresent(raw_stages->opengles(), payload)},
78  RuntimeStageIfPresent(raw_stages->vulkan(), payload)},
79  };
80 }

References impeller::kMetal, impeller::kOpenGLES, impeller::kSkSL, and impeller::kVulkan.

Referenced by impeller::PlaygroundTest::OpenAssetAsRuntimeStage(), impeller::GoldenPlaygroundTest::OpenAssetAsRuntimeStage(), and impeller::testing::TEST_P().

◆ GetCodeMapping()

const std::shared_ptr< fml::Mapping > & impeller::RuntimeStage::GetCodeMapping ( ) const

Definition at line 128 of file runtime_stage.cc.

128  {
129  return code_mapping_;
130 }

Referenced by impeller::RuntimeStagePlayground::RegisterStage().

◆ GetEntrypoint()

const std::string & impeller::RuntimeStage::GetEntrypoint ( ) const

Definition at line 147 of file runtime_stage.cc.

147  {
148  return entrypoint_;
149 }

Referenced by impeller::RuntimeStagePlayground::RegisterStage().

◆ GetShaderStage()

RuntimeShaderStage impeller::RuntimeStage::GetShaderStage ( ) const

Definition at line 151 of file runtime_stage.cc.

151  {
152  return stage_;
153 }

Referenced by impeller::RuntimeStagePlayground::RegisterStage().

◆ GetUniform()

const RuntimeUniformDescription * impeller::RuntimeStage::GetUniform ( const std::string &  name) const

Definition at line 137 of file runtime_stage.cc.

138  {
139  for (const auto& uniform : uniforms_) {
140  if (uniform.name == name) {
141  return &uniform;
142  }
143  }
144  return nullptr;
145 }

◆ GetUniforms()

const std::vector< RuntimeUniformDescription > & impeller::RuntimeStage::GetUniforms ( ) const

Definition at line 132 of file runtime_stage.cc.

133  {
134  return uniforms_;
135 }

◆ IsDirty()

bool impeller::RuntimeStage::IsDirty ( ) const

Definition at line 155 of file runtime_stage.cc.

155  {
156  return is_dirty_;
157 }

◆ IsValid()

bool impeller::RuntimeStage::IsValid ( ) const

Definition at line 124 of file runtime_stage.cc.

124  {
125  return is_valid_;
126 }

◆ operator=()

RuntimeStage & impeller::RuntimeStage::operator= ( RuntimeStage &&  )
default

◆ SetClean()

void impeller::RuntimeStage::SetClean ( )

Definition at line 159 of file runtime_stage.cc.

159  {
160  is_dirty_ = false;
161 }

Member Data Documentation

◆ kVulkanUBOName

const char * impeller::RuntimeStage::kVulkanUBOName
static
Initial value:
=
"_RESERVED_IDENTIFIER_FIXUP_gl_DefaultUniformBlock"

The generated name from GLSLang/shaderc for the UBO containing non-opaque uniforms specified in the user-written runtime effect shader.

Vulkan does not allow non-opaque uniforms outside of a UBO.

Definition at line 21 of file runtime_stage.h.

Referenced by impeller::testing::TEST_P().


The documentation for this class was generated from the following files:
impeller::ToType
static RuntimeUniformType ToType(fb::UniformDataType type)
Definition: runtime_stage.cc:18
impeller::RuntimeStageBackend::kVulkan
@ kVulkan
impeller::ToShaderStage
constexpr ShaderStage ToShaderStage(RuntimeShaderStage stage)
Definition: shader_types.h:29
impeller::RuntimeStageBackend::kOpenGLES
@ kOpenGLES
impeller::RuntimeStageBackend::kSkSL
@ kSkSL
impeller::RuntimeStageBackend::kMetal
@ kMetal