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::vector< DescriptorSetLayout > & GetDescriptorSetLayouts () 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 20 of file runtime_stage.h.

Member Typedef Documentation

◆ Map

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

Definition at line 24 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 86 of file runtime_stage.cc.

88  : payload_(payload) {
89  FML_DCHECK(runtime_stage);
90 
91  stage_ = ToShaderStage(runtime_stage->stage());
92  entrypoint_ = runtime_stage->entrypoint()->str();
93 
94  auto* uniforms = runtime_stage->uniforms();
95 
96  // Note: image bindings are screwy and will always have the same offset.
97  // track the binding of the UBO to determine where the image bindings go.
98  // This is only guaranteed to give us the correct bindings if there is a
99  // single sampler2D.
100  std::optional<size_t> ubo_id;
101  if (uniforms) {
102  for (auto i = uniforms->begin(), end = uniforms->end(); i != end; i++) {
103  RuntimeUniformDescription desc;
104  desc.name = i->name()->str();
105  desc.location = i->location();
106  desc.binding = i->binding();
107  desc.type = ToType(i->type());
108  if (desc.type == kStruct) {
109  ubo_id = desc.location;
110  desc.binding = desc.location;
111  }
112  desc.dimensions = RuntimeUniformDimensions{
113  static_cast<size_t>(i->rows()), static_cast<size_t>(i->columns())};
114  desc.bit_width = i->bit_width();
115  desc.array_elements = i->array_elements();
116  if (i->struct_layout()) {
117  for (const auto& byte_type : *i->struct_layout()) {
118  desc.struct_layout.push_back(static_cast<uint8_t>(byte_type));
119  }
120  }
121  desc.struct_float_count = i->struct_float_count();
122  uniforms_.push_back(std::move(desc));
123  }
124  }
125 
126  code_mapping_ = std::make_shared<fml::NonOwnedMapping>(
127  runtime_stage->shader()->data(), //
128  runtime_stage->shader()->size(), //
129  [payload = payload_](auto, auto) {} //
130  );
131 
132  size_t binding = 64;
133  if (ubo_id.has_value() && ubo_id.value() == binding) {
134  binding++;
135  }
136  for (auto& uniform : uniforms_) {
137  if (uniform.type == kSampledImage) {
138  uniform.binding = binding;
139  binding++;
140  if (ubo_id.has_value() && ubo_id.value() == binding) {
141  binding++;
142  }
143  }
144  }
145 
146  for (const auto& uniform : GetUniforms()) {
147  if (uniform.type == kStruct) {
148  descriptor_set_layouts_.push_back(DescriptorSetLayout{
149  static_cast<uint32_t>(uniform.location),
152  });
153  } else if (uniform.type == kSampledImage) {
154  descriptor_set_layouts_.push_back(DescriptorSetLayout{
155  static_cast<uint32_t>(uniform.binding),
158  });
159  }
160  }
161  is_valid_ = true;
162 }
const std::vector< RuntimeUniformDescription > & GetUniforms() const
constexpr ShaderStage ToShaderStage(RuntimeShaderStage stage)
Definition: shader_types.h:29
static RuntimeUniformType ToType(fb::UniformDataType type)
const size_t end

References impeller::RuntimeUniformDescription::array_elements, impeller::RuntimeUniformDescription::binding, impeller::RuntimeUniformDescription::bit_width, impeller::RuntimeUniformDescription::dimensions, end, GetUniforms(), impeller::kFragment, impeller::kSampledImage, impeller::kStruct, impeller::kUniformBuffer, 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 62 of file runtime_stage.cc.

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

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

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

◆ GetCodeMapping()

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

Definition at line 172 of file runtime_stage.cc.

172  {
173  return code_mapping_;
174 }

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

◆ GetDescriptorSetLayouts()

const std::vector< DescriptorSetLayout > & impeller::RuntimeStage::GetDescriptorSetLayouts ( ) const

Definition at line 207 of file runtime_stage.cc.

208  {
209  return descriptor_set_layouts_;
210 }

◆ GetEntrypoint()

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

Definition at line 191 of file runtime_stage.cc.

191  {
192  return entrypoint_;
193 }

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

◆ GetShaderStage()

RuntimeShaderStage impeller::RuntimeStage::GetShaderStage ( ) const

Definition at line 195 of file runtime_stage.cc.

195  {
196  return stage_;
197 }

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

◆ GetUniform()

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

Definition at line 181 of file runtime_stage.cc.

182  {
183  for (const auto& uniform : uniforms_) {
184  if (uniform.name == name) {
185  return &uniform;
186  }
187  }
188  return nullptr;
189 }

◆ GetUniforms()

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

Definition at line 176 of file runtime_stage.cc.

177  {
178  return uniforms_;
179 }

Referenced by RuntimeStage().

◆ IsDirty()

bool impeller::RuntimeStage::IsDirty ( ) const

Definition at line 199 of file runtime_stage.cc.

199  {
200  return is_dirty_;
201 }

◆ IsValid()

bool impeller::RuntimeStage::IsValid ( ) const

Definition at line 168 of file runtime_stage.cc.

168  {
169  return is_valid_;
170 }

◆ operator=()

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

◆ SetClean()

void impeller::RuntimeStage::SetClean ( )

Definition at line 203 of file runtime_stage.cc.

203  {
204  is_dirty_ = false;
205 }

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 22 of file runtime_stage.h.

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


The documentation for this class was generated from the following files: