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 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>();
201 if (
desc->name.empty()) {
203 return nullptr;
204 }
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()) {
218 return nullptr;
219 }
220 desc->location = input.location;
221 desc->set = input.set;
222 desc->binding = input.binding;
224 if (!input_type.has_value()) {
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}
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)