170 const std::shared_ptr<const spirv_cross::ParsedIR>& ir,
171 const std::shared_ptr<fml::Mapping>& shader_data,
189 struct StructDefinition {
191 size_t byte_length = 0u;
192 std::vector<StructMember> members;
195 struct BindPrototypeArgument {
197 std::string argument_name;
200 struct BindPrototype {
202 std::string return_type;
203 std::string docstring;
204 std::string descriptor_type =
"";
205 std::vector<BindPrototypeArgument>
args;
208 const Options options_;
209 const std::shared_ptr<const spirv_cross::ParsedIR> ir_;
210 const std::shared_ptr<fml::Mapping> shader_data_;
211 const CompilerBackend compiler_;
212 std::unique_ptr<const nlohmann::json> template_arguments_;
213 std::shared_ptr<fml::Mapping> reflection_header_;
214 std::shared_ptr<fml::Mapping> reflection_cc_;
215 std::shared_ptr<RuntimeStageData::Shader> runtime_stage_shader_;
216 std::shared_ptr<ShaderBundleData> shader_bundle_data_;
217 bool is_valid_ =
false;
219 std::optional<nlohmann::json> GenerateTemplateArguments()
const;
221 std::shared_ptr<fml::Mapping> GenerateReflectionHeader()
const;
223 std::shared_ptr<fml::Mapping> GenerateReflectionCC()
const;
225 std::shared_ptr<RuntimeStageData::Shader> GenerateRuntimeStageData()
const;
227 std::shared_ptr<ShaderBundleData> GenerateShaderBundleData()
const;
229 std::shared_ptr<fml::Mapping> InflateTemplate(std::string_view tmpl)
const;
231 std::optional<nlohmann::json::object_t> ReflectResource(
232 const spirv_cross::Resource& resource,
233 std::optional<size_t> offset)
const;
235 std::optional<nlohmann::json::array_t> ReflectResources(
236 const spirv_cross::SmallVector<spirv_cross::Resource>& resources,
237 bool compute_offsets =
false)
const;
239 std::vector<size_t> ComputeOffsets(
240 const spirv_cross::SmallVector<spirv_cross::Resource>& resources)
const;
242 std::optional<size_t> GetOffset(spirv_cross::ID
id,
243 const std::vector<size_t>& offsets)
const;
245 std::optional<nlohmann::json::object_t> ReflectType(
246 const spirv_cross::TypeID& type_id)
const;
248 nlohmann::json::object_t EmitStructDefinition(
249 std::optional<Reflector::StructDefinition> struc)
const;
251 std::optional<StructDefinition> ReflectStructDefinition(
252 const spirv_cross::TypeID& type_id)
const;
254 std::vector<BindPrototype> ReflectBindPrototypes(
255 const spirv_cross::ShaderResources& resources,
256 spv::ExecutionModel execution_model)
const;
258 nlohmann::json::array_t EmitBindPrototypes(
259 const spirv_cross::ShaderResources& resources,
260 spv::ExecutionModel execution_model)
const;
262 std::optional<StructDefinition> ReflectPerVertexStructDefinition(
263 const spirv_cross::SmallVector<spirv_cross::Resource>& stage_inputs)
266 std::optional<std::string> GetMemberNameAtIndexIfExists(
267 const spirv_cross::SPIRType& parent_type,
270 std::string GetMemberNameAtIndex(
const spirv_cross::SPIRType& parent_type,
272 std::string suffix =
"")
const;
274 std::vector<StructMember> ReadStructMembers(
275 const spirv_cross::TypeID& type_id)
const;
277 std::optional<uint32_t> GetArrayElements(
278 const spirv_cross::SPIRType&
type)
const;
280 template <u
int32_t Size>
281 uint32_t GetArrayStride(
const spirv_cross::SPIRType& struct_type,
282 const spirv_cross::SPIRType& member_type,
283 uint32_t index)
const {
284 auto element_count = GetArrayElements(member_type).value_or(1);
285 if (element_count <= 1) {
288 return compiler_->type_struct_member_array_stride(struct_type, index);
293 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, UnderlyingType p_underlying_type=UnderlyingType::kOther)
Constructs a new StructMember.