156 const std::shared_ptr<const spirv_cross::ParsedIR>& ir,
157 const std::shared_ptr<fml::Mapping>& shader_data,
175 struct StructDefinition {
177 size_t byte_length = 0u;
178 std::vector<StructMember> members;
181 struct BindPrototypeArgument {
182 std::string type_name;
183 std::string argument_name;
186 struct BindPrototype {
188 std::string return_type;
189 std::string docstring;
190 std::string descriptor_type =
"";
191 std::vector<BindPrototypeArgument>
args;
194 const Options options_;
195 const std::shared_ptr<const spirv_cross::ParsedIR> ir_;
196 const std::shared_ptr<fml::Mapping> shader_data_;
197 const CompilerBackend compiler_;
198 std::unique_ptr<const nlohmann::json> template_arguments_;
199 std::shared_ptr<fml::Mapping> reflection_header_;
200 std::shared_ptr<fml::Mapping> reflection_cc_;
201 std::shared_ptr<RuntimeStageData::Shader> runtime_stage_shader_;
202 std::shared_ptr<ShaderBundleData> shader_bundle_data_;
203 bool is_valid_ =
false;
205 std::optional<nlohmann::json> GenerateTemplateArguments()
const;
207 std::shared_ptr<fml::Mapping> GenerateReflectionHeader()
const;
209 std::shared_ptr<fml::Mapping> GenerateReflectionCC()
const;
211 std::shared_ptr<RuntimeStageData::Shader> GenerateRuntimeStageData()
const;
213 std::shared_ptr<ShaderBundleData> GenerateShaderBundleData()
const;
215 std::shared_ptr<fml::Mapping> InflateTemplate(std::string_view tmpl)
const;
217 std::optional<nlohmann::json::object_t> ReflectResource(
218 const spirv_cross::Resource& resource,
219 std::optional<size_t>
offset)
const;
221 std::optional<nlohmann::json::array_t> ReflectResources(
222 const spirv_cross::SmallVector<spirv_cross::Resource>& resources,
223 bool compute_offsets =
false)
const;
225 std::vector<size_t> ComputeOffsets(
226 const spirv_cross::SmallVector<spirv_cross::Resource>& resources)
const;
228 std::optional<size_t> GetOffset(spirv_cross::ID
id,
229 const std::vector<size_t>& offsets)
const;
231 std::optional<nlohmann::json::object_t> ReflectType(
232 const spirv_cross::TypeID& type_id)
const;
234 nlohmann::json::object_t EmitStructDefinition(
235 std::optional<Reflector::StructDefinition> struc)
const;
237 std::optional<StructDefinition> ReflectStructDefinition(
238 const spirv_cross::TypeID& type_id)
const;
240 std::vector<BindPrototype> ReflectBindPrototypes(
241 const spirv_cross::ShaderResources& resources,
242 spv::ExecutionModel execution_model)
const;
244 nlohmann::json::array_t EmitBindPrototypes(
245 const spirv_cross::ShaderResources& resources,
246 spv::ExecutionModel execution_model)
const;
248 std::optional<StructDefinition> ReflectPerVertexStructDefinition(
249 const spirv_cross::SmallVector<spirv_cross::Resource>& stage_inputs)
252 std::optional<std::string> GetMemberNameAtIndexIfExists(
253 const spirv_cross::SPIRType& parent_type,
256 std::string GetMemberNameAtIndex(
const spirv_cross::SPIRType& parent_type,
258 std::string suffix =
"")
const;
260 std::vector<StructMember> ReadStructMembers(
261 const spirv_cross::TypeID& type_id)
const;
263 std::optional<uint32_t> GetArrayElements(
264 const spirv_cross::SPIRType&
type)
const;
266 template <u
int32_t Size>
267 uint32_t GetArrayStride(
const spirv_cross::SPIRType& struct_type,
268 const spirv_cross::SPIRType& member_type,
269 uint32_t index)
const {
270 auto element_count = GetArrayElements(member_type).value_or(1);
271 if (element_count <= 1) {
274 return compiler_->type_struct_member_array_stride(struct_type, index);
279 Reflector& operator=(
const Reflector&) =
delete;