| Flutter Impeller |

Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
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 &&)
RuntimeStage & | operator= (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 RuntimeUniformDescription * | GetUniform (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< Map > | DecodeRuntimeStages (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() [1/2]

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

Definition at line 102 of file runtime_stage.cc.

104 : payload_(payload) {
105 FML_DCHECK(runtime_stage);
106
107 stage_ = ToShaderStage(runtime_stage->stage());
108 entrypoint_ = runtime_stage->entrypoint()->str();
109
110 auto* uniforms = runtime_stage->uniforms();
111
112 // Note: image bindings are screwy and will always have the same offset.
113 // track the binding of the UBO to determine where the image bindings go.
114 // This is only guaranteed to give us the correct bindings if there is a
115 // single sampler2D.
116 std::optional<size_t> ubo_id;
117 if (uniforms) {
118 for (auto i = uniforms->begin(), end = uniforms->end(); i != end; i++) {
119 RuntimeUniformDescription desc;
120 desc.name = i->name()->str();
121 desc.location = i->location();
122 desc.binding = i->binding();
123 desc.type = ToType(i->type());
124 if (desc.type == kStruct) {
125 ubo_id = desc.location;
126 desc.binding = desc.location;
127 }
128 desc.dimensions = RuntimeUniformDimensions{
129 static_cast<size_t>(i->rows()), static_cast<size_t>(i->columns())};
130 desc.bit_width = i->bit_width();
131 desc.array_elements = i->array_elements();
132 if (i->struct_layout()) {
133 for (const auto& byte_type : *i->struct_layout()) {
134 desc.struct_layout.push_back(static_cast<uint8_t>(byte_type));
135 }
136 }
137 desc.struct_float_count = i->struct_float_count();
138 uniforms_.push_back(std::move(desc));
139 }
140 }
141
142 code_mapping_ = std::make_shared<fml::NonOwnedMapping>(
143 runtime_stage->shader()->data(), //
144 runtime_stage->shader()->size(), //
145 [payload = payload_](auto, auto) {} //
146 );
147
148 size_t binding = 64;
149 if (ubo_id.has_value() && ubo_id.value() == binding) {
150 binding++;
151 }
152 for (auto& uniform : uniforms_) {
153 if (uniform.type == kSampledImage) {
154 uniform.binding = binding;
155 binding++;
156 if (ubo_id.has_value() && ubo_id.value() == binding) {
157 binding++;
158 }
159 }
160 }
161
162 for (const auto& uniform : GetUniforms()) {
163 if (uniform.type == kStruct) {
164 descriptor_set_layouts_.push_back(DescriptorSetLayout{
165 static_cast<uint32_t>(uniform.location),
166 DescriptorType::kUniformBuffer,
167 ShaderStage::kFragment,
168 });
169 } else if (uniform.type == kSampledImage) {
170 descriptor_set_layouts_.push_back(DescriptorSetLayout{
171 static_cast<uint32_t>(uniform.binding),
172 DescriptorType::kSampledImage,
173 ShaderStage::kFragment,
174 });
175 }
176 }
177 is_valid_ = true;
178 }
impeller::RuntimeStage::GetUniforms
const std::vector< RuntimeUniformDescription > & GetUniforms() const
Definition: runtime_stage.cc:192
impeller::ToShaderStage
constexpr ShaderStage ToShaderStage(RuntimeShaderStage stage)
Definition: shader_types.h:29
impeller::ShaderStage::kFragment
@ kFragment
impeller::ToType
static RuntimeUniformType ToType(fb::UniformDataType type)
Definition: runtime_stage.cc:20
impeller::DescriptorType::kUniformBuffer
@ kUniformBuffer
impeller::DescriptorType::kSampledImage
@ kSampledImage
impeller::kSampledImage
@ kSampledImage
Definition: runtime_types.h:26
impeller::kStruct
@ kStruct
Definition: runtime_types.h:27
end
const size_t end
Definition: tessellator_libtess.cc:63

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()

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

Definition at line 63 of file runtime_stage.cc.

64 {
65 if (payload == nullptr || !payload->GetMapping()) {
66 return absl::InvalidArgumentError("Payload is null or empty.");
67 }
68 if (!fb::RuntimeStagesBufferHasIdentifier(payload->GetMapping())) {
69 return absl::InvalidArgumentError(
70 "Payload does not have valid identifier.");
71 }
72
73 auto raw_stages = fb::GetRuntimeStages(payload->GetMapping());
74 if (!raw_stages) {
75 return absl::InvalidArgumentError("Failed to get runtime stages.");
76 }
77
78 const uint32_t version = raw_stages->format_version();
79 const auto expected =
80 static_cast<uint32_t>(fb::RuntimeStagesFormatVersion::kVersion);
81 if (version != expected) {
82 std::stringstream stream;
83 stream << "Unsupported runtime stages format version. Expected " << expected
84 << ", got " << version << ".";
85 return absl::InvalidArgumentError(stream.str());
86 }
87
88 return Map{
89 {RuntimeStageBackend::kSkSL,
90 RuntimeStageIfPresent(raw_stages->sksl(), payload)},
91 {RuntimeStageBackend::kMetal,
92 RuntimeStageIfPresent(raw_stages->metal(), payload)},
93 {RuntimeStageBackend::kOpenGLES,
94 RuntimeStageIfPresent(raw_stages->opengles(), payload)},
95 {RuntimeStageBackend::kOpenGLES3,
96 RuntimeStageIfPresent(raw_stages->opengles3(), payload)},
97 {RuntimeStageBackend::kVulkan,
98 RuntimeStageIfPresent(raw_stages->vulkan(), payload)},
99 };
100 }
impeller::RuntimeStage::Map
std::map< RuntimeStageBackend, std::shared_ptr< RuntimeStage > > Map
Definition: runtime_stage.h:25
impeller::RuntimeStageBackend::kOpenGLES
@ kOpenGLES
impeller::RuntimeStageBackend::kMetal
@ kMetal
impeller::RuntimeStageBackend::kVulkan
@ kVulkan
impeller::RuntimeStageBackend::kSkSL
@ kSkSL
impeller::RuntimeStageBackend::kOpenGLES3
@ kOpenGLES3

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

188 {
189 return code_mapping_;
190 }

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

## ◆ GetDescriptorSetLayouts()

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

Definition at line 223 of file runtime_stage.cc.

224 {
225 return descriptor_set_layouts_;
226 }

## ◆ GetEntrypoint()

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

Definition at line 207 of file runtime_stage.cc.

207 {
208 return entrypoint_;
209 }

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

## ◆ GetShaderStage()

RuntimeShaderStage impeller::RuntimeStage::GetShaderStage | ( |  | ) | const

Definition at line 211 of file runtime_stage.cc.

211 {
212 return stage_;
213 }

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

## ◆ GetUniform()

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

Definition at line 197 of file runtime_stage.cc.

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

## ◆ GetUniforms()

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

Definition at line 192 of file runtime_stage.cc.

193 {
194 return uniforms_;
195 }

Referenced by RuntimeStage().

## ◆ IsDirty()

bool impeller::RuntimeStage::IsDirty | ( |  | ) | const

Definition at line 215 of file runtime_stage.cc.

215 {
216 return is_dirty_;
217 }

## ◆ IsValid()

bool impeller::RuntimeStage::IsValid | ( |  | ) | const

Definition at line 184 of file runtime_stage.cc.

184 {
185 return is_valid_;
186 }

## ◆ operator=()

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

## ◆ SetClean()

void impeller::RuntimeStage::SetClean | ( |  | ) |

Definition at line 219 of file runtime_stage.cc.

219 {
220 is_dirty_ = false;
221 }

## 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:

- impeller/runtime_stage/runtime_stage.h
- impeller/runtime_stage/runtime_stage.cc