144 {
145 auto shader_bundle = std::make_unique<fb::shaderbundle::BackendShaderT>();
146
147
148
149 shader_bundle->entrypoint = entrypoint_;
150 const auto stage =
ToStage(stage_);
151 if (!stage.has_value()) {
153 return nullptr;
154 }
155 shader_bundle->stage = stage.value();
156
157 if (!shader_) {
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()) {
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;
183 if (!
type.has_value()) {
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 field_desc->vec_size = field.vec_size;
193 field_desc->columns = field.columns;
194 desc->fields.push_back(std::move(field_desc));
195 }
196
197 shader_bundle->uniform_structs.emplace_back(std::move(desc));
198 }
199
200 for (
const auto&
texture : uniform_textures_) {
201 auto desc = std::make_unique<fb::shaderbundle::ShaderUniformTextureT>();
203 if (desc->name.empty()) {
205 return nullptr;
206 }
207 desc->ext_res_0 =
texture.ext_res_0;
209 desc->binding =
texture.binding;
210 shader_bundle->uniform_textures.emplace_back(std::move(desc));
211 }
212
213 for (
const auto&
input : inputs_) {
214 auto desc = std::make_unique<fb::shaderbundle::ShaderInputT>();
215
216 desc->name =
input.name;
217
218 if (desc->name.empty()) {
220 return nullptr;
221 }
222 desc->location =
input.location;
223 desc->set =
input.set;
224 desc->binding =
input.binding;
226 if (!input_type.has_value()) {
228 return nullptr;
229 }
230 desc->type = input_type.value();
231 desc->bit_width =
input.bit_width;
232 desc->vec_size =
input.vec_size;
233 desc->columns =
input.columns;
234 desc->offset =
input.offset;
235
236 shader_bundle->inputs.emplace_back(std::move(desc));
237 }
238
239 return shader_bundle;
240}
static std::optional< fb::InputDataType > ToInputType(spirv_cross::SPIRType::BaseType type)
static std::optional< fb::UniformDataType > ToUniformType(spirv_cross::SPIRType::BaseType type)
static std::optional< fb::Stage > ToStage(spv::ExecutionModel stage)
impeller::ShaderType type