Flutter Engine
The Flutter Engine
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 &&)
 
RuntimeStageoperator= (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 RuntimeUniformDescriptionGetUniform (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 83 of file runtime_stage.cc.

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

◆ GetCodeMapping()

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

Definition at line 169 of file runtime_stage.cc.

169 {
170 return code_mapping_;
171}

◆ GetDescriptorSetLayouts()

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

Definition at line 204 of file runtime_stage.cc.

205 {
206 return descriptor_set_layouts_;
207}

◆ GetEntrypoint()

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

Definition at line 188 of file runtime_stage.cc.

188 {
189 return entrypoint_;
190}

◆ GetShaderStage()

RuntimeShaderStage impeller::RuntimeStage::GetShaderStage ( ) const

Definition at line 192 of file runtime_stage.cc.

192 {
193 return stage_;
194}

◆ GetUniform()

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

Definition at line 178 of file runtime_stage.cc.

179 {
180 for (const auto& uniform : uniforms_) {
181 if (uniform.name == name) {
182 return &uniform;
183 }
184 }
185 return nullptr;
186}
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32

◆ GetUniforms()

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

Definition at line 173 of file runtime_stage.cc.

174 {
175 return uniforms_;
176}

◆ IsDirty()

bool impeller::RuntimeStage::IsDirty ( ) const

Definition at line 196 of file runtime_stage.cc.

196 {
197 return is_dirty_;
198}

◆ IsValid()

bool impeller::RuntimeStage::IsValid ( ) const

Definition at line 165 of file runtime_stage.cc.

165 {
166 return is_valid_;
167}

◆ operator=()

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

◆ SetClean()

void impeller::RuntimeStage::SetClean ( )

Definition at line 200 of file runtime_stage.cc.

200 {
201 is_dirty_ = false;
202}

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.


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