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

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

References impeller::RuntimeUniformDescription::array_elements, impeller::RuntimeUniformDescription::binding, impeller::RuntimeUniformDescription::bit_width, impeller::RuntimeUniformDescription::dimensions, 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 61 of file runtime_stage.cc.

62 {
63 if (payload == nullptr || !payload->GetMapping()) {
64 return {};
65 }
66 if (!fb::RuntimeStagesBufferHasIdentifier(payload->GetMapping())) {
67 return {};
68 }
69
70 auto raw_stages = fb::GetRuntimeStages(payload->GetMapping());
71 return {
72 {RuntimeStageBackend::kSkSL,
73 RuntimeStageIfPresent(raw_stages->sksl(), payload)},
74 {RuntimeStageBackend::kMetal,
75 RuntimeStageIfPresent(raw_stages->metal(), payload)},
76 {RuntimeStageBackend::kOpenGLES,
77 RuntimeStageIfPresent(raw_stages->opengles(), payload)},
78 {RuntimeStageBackend::kOpenGLES3,
79 RuntimeStageIfPresent(raw_stages->opengles3(), payload)},
80 {RuntimeStageBackend::kVulkan,
81 RuntimeStageIfPresent(raw_stages->vulkan(), payload)},
82 };
83 }
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::GoldenPlaygroundTest::OpenAssetAsRuntimeStage(), impeller::PlaygroundTest::OpenAssetAsRuntimeStage(), and impeller::testing::TEST_P().

## ◆ GetCodeMapping()

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

Definition at line 171 of file runtime_stage.cc.

171 {
172 return code_mapping_;
173 }

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

## ◆ GetDescriptorSetLayouts()

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

Definition at line 206 of file runtime_stage.cc.

207 {
208 return descriptor_set_layouts_;
209 }

## ◆ GetEntrypoint()

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

Definition at line 190 of file runtime_stage.cc.

190 {
191 return entrypoint_;
192 }

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

## ◆ GetShaderStage()

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

Definition at line 194 of file runtime_stage.cc.

194 {
195 return stage_;
196 }

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

## ◆ GetUniform()

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

Definition at line 180 of file runtime_stage.cc.

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

## ◆ GetUniforms()

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

Definition at line 175 of file runtime_stage.cc.

176 {
177 return uniforms_;
178 }

Referenced by RuntimeStage().

## ◆ IsDirty()

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

Definition at line 198 of file runtime_stage.cc.

198 {
199 return is_dirty_;
200 }

## ◆ IsValid()

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

Definition at line 167 of file runtime_stage.cc.

167 {
168 return is_valid_;
169 }

## ◆ operator=()

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

## ◆ SetClean()

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

Definition at line 202 of file runtime_stage.cc.

202 {
203 is_dirty_ = false;
204 }

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

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