Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
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 ()
 
void SetLibraryId (std::string library_id)
 
const std::string & GetLibraryId () const
 

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

69 {
70 if (!runtime_stage) {
71 return absl::InvalidArgumentError("Runtime stage is null.");
72 }
73
74 RuntimeStage stage(payload);
75 stage.stage_ = ToShaderStage(runtime_stage->stage());
76 stage.entrypoint_ = runtime_stage->entrypoint()->str();
77 stage.library_id_ = MakeFallbackLibraryId();
78
79 auto* uniforms = runtime_stage->uniforms();
80
81 // Note: image bindings are screwy and will always have the same offset.
82 // track the binding of the UBO to determine where the image bindings go.
83 // This is only guaranteed to give us the correct bindings if there is a
84 // single sampler2D.
85 std::optional<size_t> ubo_id;
86 if (uniforms) {
87 for (auto i = uniforms->begin(), end = uniforms->end(); i != end; i++) {
88 RuntimeUniformDescription desc;
89 desc.name = i->name()->str();
90 desc.location = i->location();
91 desc.binding = i->binding();
92 desc.type = ToType(i->type());
93 if (desc.type == kStruct) {
94 ubo_id = desc.location;
95 desc.binding = desc.location;
96 }
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->padding_layout()) {
102 for (const auto& byte_type : *i->padding_layout()) {
104 switch (byte_type) {
105 case fb::PaddingType::kPadding:
107 break;
108 case fb::PaddingType::kFloat:
110 break;
111 }
112 desc.padding_layout.push_back(type);
113 }
114 }
115 if (i->struct_fields()) {
116 for (const auto& elem : *i->struct_fields()) {
117 desc.struct_fields.emplace_back(
118 StructField{.name = elem->name()->str(),
119 .byte_size = static_cast<size_t>(elem->byte_size())});
120 }
121 }
122 desc.struct_float_count = i->struct_float_count();
123 stage.uniforms_.push_back(std::move(desc));
124 }
125 }
126
127 stage.code_mapping_ = std::make_shared<fml::NonOwnedMapping>(
128 runtime_stage->shader()->data(), //
129 runtime_stage->shader()->size(), //
130 [payload = stage.payload_](auto, auto) {} //
131 );
132
133 size_t binding = 64;
134 if (ubo_id.has_value() && ubo_id.value() == binding) {
135 binding++;
136 }
137 for (auto& uniform : stage.uniforms_) {
138 if (uniform.type == kSampledImage) {
139 uniform.binding = binding;
140 binding++;
141 if (ubo_id.has_value() && ubo_id.value() == binding) {
142 binding++;
143 }
144 }
145 }
146
147 for (const auto& uniform : stage.GetUniforms()) {
148 if (uniform.type == kStruct) {
149 stage.descriptor_set_layouts_.push_back(DescriptorSetLayout{
150 static_cast<uint32_t>(uniform.location),
153 });
154 } else if (uniform.type == kSampledImage) {
155 stage.descriptor_set_layouts_.push_back(DescriptorSetLayout{
156 static_cast<uint32_t>(uniform.binding),
159 });
160 }
161 }
162
163 return stage;
164}
RuntimeStage(RuntimeStage &&)
const std::vector< RuntimeUniformDescription > & GetUniforms() const
constexpr ShaderStage ToShaderStage(RuntimeShaderStage stage)
static RuntimeUniformType ToType(fb::UniformDataType type)
impeller::ShaderType type
const size_t end

References impeller::RuntimeUniformDescription::array_elements, impeller::RuntimeUniformDescription::binding, impeller::RuntimeUniformDescription::bit_width, impeller::RuntimeUniformDescription::dimensions, end, GetUniforms(), i, impeller::kFloat, impeller::kFragment, impeller::kPadding, impeller::kSampledImage, impeller::kStruct, impeller::kUniformBuffer, impeller::RuntimeUniformDescription::location, impeller::StructField::name, impeller::RuntimeUniformDescription::name, impeller::RuntimeUniformDescription::padding_layout, impeller::RuntimeUniformDescription::struct_fields, impeller::RuntimeUniformDescription::struct_float_count, impeller::ToShaderStage(), impeller::ToType(), impeller::RuntimeUniformDescription::type, and type.

◆ DecodeRuntimeStages()

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

Definition at line 176 of file runtime_stage.cc.

177 {
178 if (payload == nullptr || !payload->GetMapping()) {
179 return absl::InvalidArgumentError("Payload is null or empty.");
180 }
181 if (!fb::RuntimeStagesBufferHasIdentifier(payload->GetMapping())) {
182 return absl::InvalidArgumentError(
183 "Payload does not have valid identifier.");
184 }
185
186 auto raw_stages = fb::GetRuntimeStages(payload->GetMapping());
187 if (!raw_stages) {
188 return absl::InvalidArgumentError("Failed to get runtime stages.");
189 }
190
191 const uint32_t version = raw_stages->format_version();
192 const auto expected =
193 static_cast<uint32_t>(fb::RuntimeStagesFormatVersion::kVersion);
194 if (version != expected) {
195 std::stringstream stream;
196 stream << "Unsupported runtime stages format version. Expected " << expected
197 << ", got " << version << ".";
198 return absl::InvalidArgumentError(stream.str());
199 }
200
201 return Map{
203 RuntimeStageIfPresent(raw_stages->sksl(), payload)},
205 RuntimeStageIfPresent(raw_stages->metal(), payload)},
207 RuntimeStageIfPresent(raw_stages->opengles(), payload)},
209 RuntimeStageIfPresent(raw_stages->opengles3(), payload)},
211 RuntimeStageIfPresent(raw_stages->vulkan(), payload)},
212 };
213}
std::map< RuntimeStageBackend, std::shared_ptr< RuntimeStage > > Map

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

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

◆ GetCodeMapping()

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

Definition at line 222 of file runtime_stage.cc.

222 {
223 return code_mapping_;
224}

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

◆ GetDescriptorSetLayouts()

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

Definition at line 265 of file runtime_stage.cc.

266 {
267 return descriptor_set_layouts_;
268}

◆ GetEntrypoint()

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

Definition at line 241 of file runtime_stage.cc.

241 {
242 return entrypoint_;
243}

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

◆ GetLibraryId()

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

Definition at line 261 of file runtime_stage.cc.

261 {
262 return library_id_;
263}

◆ GetShaderStage()

RuntimeShaderStage impeller::RuntimeStage::GetShaderStage ( ) const

Definition at line 245 of file runtime_stage.cc.

245 {
246 return stage_;
247}

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

◆ GetUniform()

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

Definition at line 231 of file runtime_stage.cc.

232 {
233 for (const auto& uniform : uniforms_) {
234 if (uniform.name == name) {
235 return &uniform;
236 }
237 }
238 return nullptr;
239}
const char * name
Definition fuchsia.cc:50

References name.

◆ GetUniforms()

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

Definition at line 226 of file runtime_stage.cc.

227 {
228 return uniforms_;
229}

Referenced by Create().

◆ IsDirty()

bool impeller::RuntimeStage::IsDirty ( ) const

Definition at line 249 of file runtime_stage.cc.

249 {
250 return is_dirty_;
251}

◆ operator=()

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

◆ SetClean()

void impeller::RuntimeStage::SetClean ( )

Definition at line 253 of file runtime_stage.cc.

253 {
254 is_dirty_ = false;
255}

◆ SetLibraryId()

void impeller::RuntimeStage::SetLibraryId ( std::string  library_id)

Stable per-source identifier used to namespace this stage's entrypoint in the shared shader registry, so that user-supplied runtime shaders cannot collide with engine-internal shaders or with shaders from other asset paths. Defaults to a process-unique fallback assigned at decode time. Should be overwritten with a stable id (typically the asset path the stage was loaded from) so that hot reload of the same asset continues to evict and replace the same registry slot.

Definition at line 257 of file runtime_stage.cc.

257 {
258 library_id_ = std::move(library_id);
259}

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(), impeller::testing::TEST_P(), and impeller::testing::TEST_P().


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