190 const std::shared_ptr<const spirv_cross::ParsedIR>& ir,
191 const std::shared_ptr<fml::Mapping>& shader_data,
209 struct StructDefinition {
211 size_t byte_length = 0u;
212 std::vector<StructMember> members;
215 struct BindPrototypeArgument {
217 std::string argument_name;
220 struct BindPrototype {
222 std::string return_type;
223 std::string docstring;
224 std::string descriptor_type =
"";
225 std::vector<BindPrototypeArgument>
args;
228 const Options options_;
229 const std::shared_ptr<const spirv_cross::ParsedIR> ir_;
230 const std::shared_ptr<fml::Mapping> shader_data_;
231 const CompilerBackend compiler_;
232 std::unique_ptr<const nlohmann::json> template_arguments_;
233 std::shared_ptr<fml::Mapping> reflection_header_;
234 std::shared_ptr<fml::Mapping> reflection_cc_;
235 std::shared_ptr<RuntimeStageData::Shader> runtime_stage_shader_;
236 std::shared_ptr<ShaderBundleData> shader_bundle_data_;
237 bool is_valid_ =
false;
239 std::optional<nlohmann::json> GenerateTemplateArguments()
const;
241 std::shared_ptr<fml::Mapping> GenerateReflectionHeader()
const;
243 std::shared_ptr<fml::Mapping> GenerateReflectionCC()
const;
245 std::shared_ptr<RuntimeStageData::Shader> GenerateRuntimeStageData()
const;
247 std::shared_ptr<ShaderBundleData> GenerateShaderBundleData()
const;
249 std::shared_ptr<fml::Mapping> InflateTemplate(std::string_view tmpl)
const;
251 std::optional<nlohmann::json::object_t> ReflectResource(
252 const spirv_cross::Resource& resource,
253 std::optional<size_t> offset)
const;
255 std::optional<nlohmann::json::array_t> ReflectResources(
256 const spirv_cross::SmallVector<spirv_cross::Resource>& resources,
257 bool compute_offsets =
false)
const;
259 std::vector<size_t> ComputeOffsets(
260 const spirv_cross::SmallVector<spirv_cross::Resource>& resources)
const;
262 std::optional<size_t> GetOffset(spirv_cross::ID
id,
263 const std::vector<size_t>& offsets)
const;
265 std::optional<nlohmann::json::object_t> ReflectType(
266 const spirv_cross::TypeID& type_id)
const;
268 nlohmann::json::object_t EmitStructDefinition(
269 std::optional<Reflector::StructDefinition> struc)
const;
271 std::optional<StructDefinition> ReflectStructDefinition(
272 const spirv_cross::TypeID& type_id)
const;
274 std::vector<BindPrototype> ReflectBindPrototypes(
275 const spirv_cross::ShaderResources& resources,
276 spv::ExecutionModel execution_model)
const;
278 nlohmann::json::array_t EmitBindPrototypes(
279 const spirv_cross::ShaderResources& resources,
280 spv::ExecutionModel execution_model)
const;
282 std::optional<StructDefinition> ReflectPerVertexStructDefinition(
283 const spirv_cross::SmallVector<spirv_cross::Resource>& stage_inputs)
286 std::optional<std::string> GetMemberNameAtIndexIfExists(
287 const spirv_cross::SPIRType& parent_type,
290 std::string GetMemberNameAtIndex(
const spirv_cross::SPIRType& parent_type,
292 std::string suffix =
"")
const;
294 std::vector<StructMember> ReadStructMembers(
295 const spirv_cross::TypeID& type_id)
const;
297 std::optional<uint32_t> GetArrayElements(
298 const spirv_cross::SPIRType&
type)
const;
300 template <u
int32_t Size>
301 uint32_t GetArrayStride(
const spirv_cross::SPIRType& struct_type,
302 const spirv_cross::SPIRType& member_type,
303 uint32_t index)
const {
304 auto element_count = GetArrayElements(member_type).value_or(1);
305 if (element_count <= 1) {
308 return compiler_->type_struct_member_array_stride(struct_type, index);
313 Reflector& operator=(
const Reflector&) =
delete;
StructMember(std::string p_type, spirv_cross::SPIRType::BaseType p_base_type, std::string p_name, size_t p_offset, size_t p_size, size_t p_byte_length, std::optional< size_t > p_array_elements, size_t p_element_padding, std::optional< std::string > p_float_type=std::nullopt, size_t p_vec_size=0u, size_t p_columns=0u, UnderlyingType p_underlying_type=UnderlyingType::kOther)
Constructs a new StructMember.