| Flutter Impeller |

Classes | Public Member Functions | List of all members
impeller::compiler::ShaderBundleData Class Reference

`#include <shader_bundle_data.h>`

## Classes
struct | ShaderUniformStruct
struct | ShaderUniformStructField
struct | ShaderUniformTexture

## Public Member Functions
| ShaderBundleData (std::string entrypoint, spv::ExecutionModel stage, TargetPlatform target_platform)
| ~ShaderBundleData ()
void | AddUniformStruct (ShaderUniformStruct uniform_struct)
void | AddUniformTexture (ShaderUniformTexture uniform_texture)
void | AddInputDescription (InputDescription input)
void | SetShaderData (std::shared_ptr< fml::Mapping > shader)
void | SetSkSLData (std::shared_ptr< fml::Mapping > sksl)
std::unique_ptr< fb::shaderbundle::BackendShaderT > | CreateFlatbuffer () const

## Detailed Description

Definition at line 18 of file shader_bundle_data.h.

## Constructor & Destructor Documentation

## ◆ ShaderBundleData()

impeller::compiler::ShaderBundleData::ShaderBundleData | ( | std::string | entrypoint,
|  | spv::ExecutionModel | stage,
|  | TargetPlatform | target_platform
| ) |  |

Definition at line 16 of file shader_bundle_data.cc.

19 : entrypoint_(std::move(entrypoint)),
20 stage_(stage),
21 target_platform_(target_platform) {}

## ◆ ~ShaderBundleData()

impeller::compiler::ShaderBundleData::~ShaderBundleData | ( |  | ) |
| default

## Member Function Documentation

## ◆ AddInputDescription()

void impeller::compiler::ShaderBundleData::AddInputDescription | ( | InputDescription | input | ) |

Definition at line 33 of file shader_bundle_data.cc.

33 {
34 inputs_.emplace_back(std::move(input));
35 }

## ◆ AddUniformStruct()

void impeller::compiler::ShaderBundleData::AddUniformStruct | ( | ShaderUniformStruct | uniform_struct | ) |

Definition at line 25 of file shader_bundle_data.cc.

25 {
26 uniform_structs_.emplace_back(std::move(uniform_struct));
27 }

## ◆ AddUniformTexture()

void impeller::compiler::ShaderBundleData::AddUniformTexture | ( | ShaderUniformTexture | uniform_texture | ) |

Definition at line 29 of file shader_bundle_data.cc.

29 {
30 uniform_textures_.emplace_back(std::move(uniform_texture));
31 }

## ◆ CreateFlatbuffer()

std::unique_ptr< fb::shaderbundle::BackendShaderT > impeller::compiler::ShaderBundleData::CreateFlatbuffer | ( |  | ) | const

Definition at line 144 of file shader_bundle_data.cc.

144 {
145 auto shader_bundle = std::make_unique<fb::shaderbundle::BackendShaderT>();
146
147 // The high level object API is used here for writing to the buffer. This is
148 // just a convenience.
149 shader_bundle->entrypoint = entrypoint_;
150 const auto stage = ToStage(stage_);
151 if (!stage.has_value()) {
152 VALIDATION_LOG << "Invalid shader bundle.";
153 return nullptr;
154 }
155 shader_bundle->stage = stage.value();
156 // This field is ignored, so just set it to anything.
157 if (!shader_) {
158 VALIDATION_LOG << "No shader specified for shader bundle.";
159 return nullptr;
160 }
161 if (shader_->GetSize() > 0u) {
162 shader_bundle->shader = {shader_->GetMapping(),
163 shader_->GetMapping() + shader_->GetSize()};
164 }
165 for (const auto& uniform : uniform_structs_) {
166 auto desc = std::make_unique<fb::shaderbundle::ShaderUniformStructT>();
167
168 desc->name = uniform.name;
169 if (desc->name.empty()) {
170 VALIDATION_LOG << "Uniform name cannot be empty.";
171 return nullptr;
172 }
173 desc->ext_res_0 = uniform.ext_res_0;
174 desc->set = uniform.set;
175 desc->binding = uniform.binding;
176 desc->size_in_bytes = uniform.size_in_bytes;
177
178 for (const auto& field : uniform.fields) {
179 auto field_desc =
180 std::make_unique<fb::shaderbundle::ShaderUniformStructFieldT>();
181 field_desc->name = field.name;
182 auto type = ToUniformType(field.type);
183 if (!type.has_value()) {
184 VALIDATION_LOG << " Invalid shader type " << field.type << ".";
185 return nullptr;
186 }
187 field_desc->type = type.value();
188 field_desc->offset_in_bytes = field.offset_in_bytes;
189 field_desc->element_size_in_bytes = field.element_size_in_bytes;
190 field_desc->total_size_in_bytes = field.total_size_in_bytes;
191 field_desc->array_elements = field.array_elements.value_or(0);
192 desc->fields.push_back(std::move(field_desc));
193 }
194
195 shader_bundle->uniform_structs.emplace_back(std::move(desc));
196 }
197
198 for (const auto& texture : uniform_textures_) {
199 auto desc = std::make_unique<fb::shaderbundle::ShaderUniformTextureT>();
200 desc->name = texture.name;
201 if (desc->name.empty()) {
202 VALIDATION_LOG << "Uniform name cannot be empty.";
203 return nullptr;
204 }
205 desc->ext_res_0 = texture.ext_res_0;
206 desc->set = texture.set;
207 desc->binding = texture.binding;
208 shader_bundle->uniform_textures.emplace_back(std::move(desc));
209 }
210
211 for (const auto& input : inputs_) {
212 auto desc = std::make_unique<fb::shaderbundle::ShaderInputT>();
213
214 desc->name = input.name;
215
216 if (desc->name.empty()) {
217 VALIDATION_LOG << "Stage input name cannot be empty.";
218 return nullptr;
219 }
220 desc->location = input.location;
221 desc->set = input.set;
222 desc->binding = input.binding;
223 auto input_type = ToInputType(input.type);
224 if (!input_type.has_value()) {
225 VALIDATION_LOG << "Invalid uniform type for runtime stage.";
226 return nullptr;
227 }
228 desc->type = input_type.value();
229 desc->bit_width = input.bit_width;
230 desc->vec_size = input.vec_size;
231 desc->columns = input.columns;
232 desc->offset = input.offset;
233
234 shader_bundle->inputs.emplace_back(std::move(desc));
235 }
236
237 return shader_bundle;
238 }

References impeller::compiler::ToInputType(), impeller::compiler::ToStage(), impeller::compiler::ToUniformType(), type, and VALIDATION_LOG.

## ◆ SetShaderData()

void impeller::compiler::ShaderBundleData::SetShaderData | ( | std::shared_ptr< fml::Mapping > | shader | ) |

Definition at line 37 of file shader_bundle_data.cc.

37 {
38 shader_ = std::move(shader);
39 }

## ◆ SetSkSLData()

void impeller::compiler::ShaderBundleData::SetSkSLData | ( | std::shared_ptr< fml::Mapping > | sksl | ) |

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

- impeller/compiler/shader_bundle_data.h
- impeller/compiler/shader_bundle_data.cc

impeller::compiler::ToInputType
static std::optional< fb::InputDataType > ToInputType(spirv_cross::SPIRType::BaseType type)
Definition: runtime_stage_data.cc:95
impeller::compiler::ToStage
static std::optional< fb::Stage > ToStage(spv::ExecutionModel stage)
Definition: runtime_stage_data.cc:33
type
GLenum type
Definition: blit_command_gles.cc:126
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:73
impeller::compiler::ToUniformType
static std::optional< fb::UniformDataType > ToUniformType(spirv_cross::SPIRType::BaseType type)
Definition: runtime_stage_data.cc:61