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

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->padding_layout()) {
85 for (const auto& byte_type : *i->padding_layout()) {
87 switch (byte_type) {
88 case fb::PaddingType::kPadding:
90 break;
91 case fb::PaddingType::kFloat:
93 break;
94 }
95 desc.padding_layout.push_back(type);
96 }
97 }
98 if (i->struct_fields()) {
99 for (const auto& elem : *i->struct_fields()) {
100 desc.struct_fields.emplace_back(
101 StructField{.name = elem->name()->str(),
102 .byte_size = static_cast<size_t>(elem->byte_size())});
103 }
104 }
105 desc.struct_float_count = i->struct_float_count();
106 stage.uniforms_.push_back(std::move(desc));
107 }
108 }
109
110 stage.code_mapping_ = std::make_shared<fml::NonOwnedMapping>(
111 runtime_stage->shader()->data(), //
112 runtime_stage->shader()->size(), //
113 [payload = stage.payload_](auto, auto) {} //
114 );
115
116 size_t binding = 64;
117 if (ubo_id.has_value() && ubo_id.value() == binding) {
118 binding++;
119 }
120 for (auto& uniform : stage.uniforms_) {
121 if (uniform.type == kSampledImage) {
122 uniform.binding = binding;
123 binding++;
124 if (ubo_id.has_value() && ubo_id.value() == binding) {
125 binding++;
126 }
127 }
128 }
129
130 for (const auto& uniform : stage.GetUniforms()) {
131 if (uniform.type == kStruct) {
132 stage.descriptor_set_layouts_.push_back(DescriptorSetLayout{
133 static_cast<uint32_t>(uniform.location),
136 });
137 } else if (uniform.type == kSampledImage) {
138 stage.descriptor_set_layouts_.push_back(DescriptorSetLayout{
139 static_cast<uint32_t>(uniform.binding),
142 });
143 }
144 }
145
146 return stage;
147}
GLenum type
RuntimeStage(RuntimeStage &&)
const std::vector< RuntimeUniformDescription > & GetUniforms() const
constexpr ShaderStage ToShaderStage(RuntimeShaderStage stage)
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(), 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 159 of file runtime_stage.cc.

160 {
161 if (payload == nullptr || !payload->GetMapping()) {
162 return absl::InvalidArgumentError("Payload is null or empty.");
163 }
164 if (!fb::RuntimeStagesBufferHasIdentifier(payload->GetMapping())) {
165 return absl::InvalidArgumentError(
166 "Payload does not have valid identifier.");
167 }
168
169 auto raw_stages = fb::GetRuntimeStages(payload->GetMapping());
170 if (!raw_stages) {
171 return absl::InvalidArgumentError("Failed to get runtime stages.");
172 }
173
174 const uint32_t version = raw_stages->format_version();
175 const auto expected =
176 static_cast<uint32_t>(fb::RuntimeStagesFormatVersion::kVersion);
177 if (version != expected) {
178 std::stringstream stream;
179 stream << "Unsupported runtime stages format version. Expected " << expected
180 << ", got " << version << ".";
181 return absl::InvalidArgumentError(stream.str());
182 }
183
184 return Map{
186 RuntimeStageIfPresent(raw_stages->sksl(), payload)},
188 RuntimeStageIfPresent(raw_stages->metal(), payload)},
190 RuntimeStageIfPresent(raw_stages->opengles(), payload)},
192 RuntimeStageIfPresent(raw_stages->opengles3(), payload)},
194 RuntimeStageIfPresent(raw_stages->vulkan(), payload)},
195 };
196}
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(), and impeller::testing::TEST_P().

◆ GetCodeMapping()

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

Definition at line 205 of file runtime_stage.cc.

205 {
206 return code_mapping_;
207}

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

◆ GetDescriptorSetLayouts()

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

Definition at line 240 of file runtime_stage.cc.

241 {
242 return descriptor_set_layouts_;
243}

◆ GetEntrypoint()

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

Definition at line 224 of file runtime_stage.cc.

224 {
225 return entrypoint_;
226}

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

◆ GetShaderStage()

RuntimeShaderStage impeller::RuntimeStage::GetShaderStage ( ) const

Definition at line 228 of file runtime_stage.cc.

228 {
229 return stage_;
230}

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

◆ GetUniform()

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

Definition at line 214 of file runtime_stage.cc.

215 {
216 for (const auto& uniform : uniforms_) {
217 if (uniform.name == name) {
218 return &uniform;
219 }
220 }
221 return nullptr;
222}
const char * name
Definition fuchsia.cc:49

References name.

◆ GetUniforms()

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

Definition at line 209 of file runtime_stage.cc.

210 {
211 return uniforms_;
212}

Referenced by Create().

◆ IsDirty()

bool impeller::RuntimeStage::IsDirty ( ) const

Definition at line 232 of file runtime_stage.cc.

232 {
233 return is_dirty_;
234}

◆ operator=()

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

◆ SetClean()

void impeller::RuntimeStage::SetClean ( )

Definition at line 236 of file runtime_stage.cc.

236 {
237 is_dirty_ = false;
238}

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: