10 #include "flutter/fml/macros.h"
11 #include "flutter/fml/mapping.h"
14 #include "inja/inja.hpp"
15 #include "spirv_msl.hpp"
16 #include "spirv_parser.hpp"
32 std::string p_base_type,
37 std::optional<size_t> p_array_elements,
38 size_t p_element_padding)
59 std::shared_ptr<const spirv_cross::ParsedIR> ir,
60 std::shared_ptr<fml::Mapping> shader_data,
76 struct StructDefinition {
78 size_t byte_length = 0u;
79 std::vector<StructMember> members;
82 struct BindPrototypeArgument {
83 std::string type_name;
84 std::string argument_name;
87 struct BindPrototype {
89 std::string return_type;
90 std::string docstring;
91 std::vector<BindPrototypeArgument> args;
94 const Options options_;
95 const std::shared_ptr<const spirv_cross::ParsedIR> ir_;
96 const std::shared_ptr<fml::Mapping> shader_data_;
97 const std::shared_ptr<fml::Mapping> sksl_data_;
98 const CompilerBackend compiler_;
99 std::unique_ptr<const nlohmann::json> template_arguments_;
100 std::shared_ptr<fml::Mapping> reflection_header_;
101 std::shared_ptr<fml::Mapping> reflection_cc_;
102 std::shared_ptr<RuntimeStageData> runtime_stage_data_;
103 bool is_valid_ =
false;
105 std::optional<nlohmann::json> GenerateTemplateArguments()
const;
107 std::shared_ptr<fml::Mapping> GenerateReflectionHeader()
const;
109 std::shared_ptr<fml::Mapping> GenerateReflectionCC()
const;
111 std::shared_ptr<RuntimeStageData> GenerateRuntimeStageData()
const;
113 std::shared_ptr<fml::Mapping> InflateTemplate(std::string_view tmpl)
const;
115 std::optional<nlohmann::json::object_t> ReflectResource(
116 const spirv_cross::Resource& resource,
117 std::optional<size_t> offset)
const;
119 std::optional<nlohmann::json::array_t> ReflectResources(
120 const spirv_cross::SmallVector<spirv_cross::Resource>& resources,
121 bool compute_offsets =
false)
const;
123 std::vector<size_t> ComputeOffsets(
124 const spirv_cross::SmallVector<spirv_cross::Resource>& resources)
const;
126 std::optional<nlohmann::json::object_t> ReflectType(
127 const spirv_cross::TypeID& type_id)
const;
129 nlohmann::json::object_t EmitStructDefinition(
130 std::optional<Reflector::StructDefinition> struc)
const;
132 std::optional<StructDefinition> ReflectStructDefinition(
133 const spirv_cross::TypeID& type_id)
const;
135 std::vector<BindPrototype> ReflectBindPrototypes(
136 const spirv_cross::ShaderResources& resources,
137 spv::ExecutionModel execution_model)
const;
139 nlohmann::json::array_t EmitBindPrototypes(
140 const spirv_cross::ShaderResources& resources,
141 spv::ExecutionModel execution_model)
const;
143 std::optional<StructDefinition> ReflectPerVertexStructDefinition(
144 const spirv_cross::SmallVector<spirv_cross::Resource>& stage_inputs)
147 std::optional<std::string> GetMemberNameAtIndexIfExists(
148 const spirv_cross::SPIRType& parent_type,
151 std::string GetMemberNameAtIndex(
const spirv_cross::SPIRType& parent_type,
153 std::string suffix =
"")
const;
155 std::vector<StructMember> ReadStructMembers(
156 const spirv_cross::TypeID& type_id)
const;
158 std::optional<uint32_t> GetArrayElements(
159 const spirv_cross::SPIRType& type)
const;
161 template <u
int32_t Size>
162 uint32_t GetArrayStride(
const spirv_cross::SPIRType& struct_type,
163 const spirv_cross::SPIRType& member_type,
164 uint32_t index)
const {
165 auto element_count = GetArrayElements(member_type).value_or(1);
166 if (element_count <= 1) {
169 return compiler_->type_struct_member_array_stride(struct_type, index);