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 ()
 
 RuntimeStage (RuntimeStage &&)
 
RuntimeStageoperator= (RuntimeStage &&)
 
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 absl::StatusOr< MapDecodeRuntimeStages (const std::shared_ptr< fml::Mapping > &payload)
 
static absl::StatusOr< RuntimeStageCreate (const fb::RuntimeStage *runtime_stage, const std::shared_ptr< fml::Mapping > &payload)
 

Static Public Attributes

static const char * kVulkanUBOName
 

Detailed Description

Definition at line 21 of file runtime_stage.h.

Member Typedef Documentation

◆ Map

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

Definition at line 25 of file runtime_stage.h.

Constructor & Destructor Documentation

◆ ~RuntimeStage()

impeller::RuntimeStage::~RuntimeStage ( )
default

◆ RuntimeStage()

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

Member Function Documentation

◆ Create()

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

Definition at line 51 of file runtime_stage.cc.

53  {
54  if (!runtime_stage) {
55  return absl::InvalidArgumentError("Runtime stage is null.");
56  }
57 
58  RuntimeStage stage(payload);
59  stage.stage_ = ToShaderStage(runtime_stage->stage());
60  stage.entrypoint_ = runtime_stage->entrypoint()->str();
61 
62  auto* uniforms = runtime_stage->uniforms();
63 
64  // Note: image bindings are screwy and will always have the same offset.
65  // track the binding of the UBO to determine where the image bindings go.
66  // This is only guaranteed to give us the correct bindings if there is a
67  // single sampler2D.
68  std::optional<size_t> ubo_id;
69  if (uniforms) {
70  for (auto i = uniforms->begin(), end = uniforms->end(); i != end; i++) {
71  RuntimeUniformDescription desc;
72  desc.name = i->name()->str();
73  desc.location = i->location();
74  desc.binding = i->binding();
75  desc.type = ToType(i->type());
76  if (desc.type == kStruct) {
77  ubo_id = desc.location;
78  desc.binding = desc.location;
79  }
80  desc.dimensions = RuntimeUniformDimensions{
81  static_cast<size_t>(i->rows()), static_cast<size_t>(i->columns())};
82  desc.bit_width = i->bit_width();
83  desc.array_elements = i->array_elements();
84  if (i->struct_layout()) {
85  for (const auto& byte_type : *i->struct_layout()) {
86  desc.struct_layout.push_back(static_cast<uint8_t>(byte_type));
87  }
88  }
89  desc.struct_float_count = i->struct_float_count();
90  stage.uniforms_.push_back(std::move(desc));
91  }
92  }
93 
94  stage.code_mapping_ = std::make_shared<fml::NonOwnedMapping>(
95  runtime_stage->shader()->data(), //
96  runtime_stage->shader()->size(), //
97  [payload = stage.payload_](auto, auto) {} //
98  );
99 
100  size_t binding = 64;
101  if (ubo_id.has_value() && ubo_id.value() == binding) {
102  binding++;
103  }
104  for (auto& uniform : stage.uniforms_) {
105  if (uniform.type == kSampledImage) {
106  uniform.binding = binding;
107  binding++;
108  if (ubo_id.has_value() && ubo_id.value() == binding) {
109  binding++;
110  }
111  }
112  }
113 
114  for (const auto& uniform : stage.GetUniforms()) {
115  if (uniform.type == kStruct) {
116  stage.descriptor_set_layouts_.push_back(DescriptorSetLayout{
117  static_cast<uint32_t>(uniform.location),
120  });
121  } else if (uniform.type == kSampledImage) {
122  stage.descriptor_set_layouts_.push_back(DescriptorSetLayout{
123  static_cast<uint32_t>(uniform.binding),
126  });
127  }
128  }
129 
130  return stage;
131 }
RuntimeStage(RuntimeStage &&)
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.

◆ DecodeRuntimeStages()

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

Definition at line 143 of file runtime_stage.cc.

144  {
145  if (payload == nullptr || !payload->GetMapping()) {
146  return absl::InvalidArgumentError("Payload is null or empty.");
147  }
148  if (!fb::RuntimeStagesBufferHasIdentifier(payload->GetMapping())) {
149  return absl::InvalidArgumentError(
150  "Payload does not have valid identifier.");
151  }
152 
153  auto raw_stages = fb::GetRuntimeStages(payload->GetMapping());
154  if (!raw_stages) {
155  return absl::InvalidArgumentError("Failed to get runtime stages.");
156  }
157 
158  const uint32_t version = raw_stages->format_version();
159  const auto expected =
160  static_cast<uint32_t>(fb::RuntimeStagesFormatVersion::kVersion);
161  if (version != expected) {
162  std::stringstream stream;
163  stream << "Unsupported runtime stages format version. Expected " << expected
164  << ", got " << version << ".";
165  return absl::InvalidArgumentError(stream.str());
166  }
167 
168  return Map{
170  RuntimeStageIfPresent(raw_stages->sksl(), payload)},
172  RuntimeStageIfPresent(raw_stages->metal(), payload)},
174  RuntimeStageIfPresent(raw_stages->opengles(), payload)},
176  RuntimeStageIfPresent(raw_stages->opengles3(), payload)},
178  RuntimeStageIfPresent(raw_stages->vulkan(), payload)},
179  };
180 }
std::map< RuntimeStageBackend, std::shared_ptr< RuntimeStage > > Map
Definition: runtime_stage.h:25

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 189 of file runtime_stage.cc.

189  {
190  return code_mapping_;
191 }

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

◆ GetDescriptorSetLayouts()

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

Definition at line 224 of file runtime_stage.cc.

225  {
226  return descriptor_set_layouts_;
227 }

◆ GetEntrypoint()

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

Definition at line 208 of file runtime_stage.cc.

208  {
209  return entrypoint_;
210 }

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

◆ GetShaderStage()

RuntimeShaderStage impeller::RuntimeStage::GetShaderStage ( ) const

Definition at line 212 of file runtime_stage.cc.

212  {
213  return stage_;
214 }

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

◆ GetUniform()

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

Definition at line 198 of file runtime_stage.cc.

199  {
200  for (const auto& uniform : uniforms_) {
201  if (uniform.name == name) {
202  return &uniform;
203  }
204  }
205  return nullptr;
206 }

◆ GetUniforms()

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

Definition at line 193 of file runtime_stage.cc.

194  {
195  return uniforms_;
196 }

Referenced by Create().

◆ IsDirty()

bool impeller::RuntimeStage::IsDirty ( ) const

Definition at line 216 of file runtime_stage.cc.

216  {
217  return is_dirty_;
218 }

◆ operator=()

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

◆ SetClean()

void impeller::RuntimeStage::SetClean ( )

Definition at line 220 of file runtime_stage.cc.

220  {
221  is_dirty_ = false;
222 }

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

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


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