154 const std::shared_ptr<const spirv_cross::ParsedIR>& ir,
155 const std::shared_ptr<fml::Mapping>& shader_data,
173 struct StructDefinition {
175 size_t byte_length = 0u;
176 std::vector<StructMember> members;
179 struct BindPrototypeArgument {
180 std::string type_name;
181 std::string argument_name;
184 struct BindPrototype {
186 std::string return_type;
187 std::string docstring;
188 std::string descriptor_type =
"";
189 std::vector<BindPrototypeArgument>
args;
192 const Options options_;
193 const std::shared_ptr<const spirv_cross::ParsedIR> ir_;
194 const std::shared_ptr<fml::Mapping> shader_data_;
195 const CompilerBackend compiler_;
196 std::unique_ptr<const nlohmann::json> template_arguments_;
197 std::shared_ptr<fml::Mapping> reflection_header_;
198 std::shared_ptr<fml::Mapping> reflection_cc_;
199 std::shared_ptr<RuntimeStageData::Shader> runtime_stage_shader_;
200 std::shared_ptr<ShaderBundleData> shader_bundle_data_;
201 bool is_valid_ =
false;
203 std::optional<nlohmann::json> GenerateTemplateArguments()
const;
205 std::shared_ptr<fml::Mapping> GenerateReflectionHeader()
const;
207 std::shared_ptr<fml::Mapping> GenerateReflectionCC()
const;
209 std::shared_ptr<RuntimeStageData::Shader> GenerateRuntimeStageData()
const;
211 std::shared_ptr<ShaderBundleData> GenerateShaderBundleData()
const;
213 std::shared_ptr<fml::Mapping> InflateTemplate(std::string_view tmpl)
const;
215 std::optional<nlohmann::json::object_t> ReflectResource(
216 const spirv_cross::Resource& resource,
217 std::optional<size_t> offset)
const;
219 std::optional<nlohmann::json::array_t> ReflectResources(
220 const spirv_cross::SmallVector<spirv_cross::Resource>& resources,
221 bool compute_offsets =
false)
const;
223 std::vector<size_t> ComputeOffsets(
224 const spirv_cross::SmallVector<spirv_cross::Resource>& resources)
const;
226 std::optional<size_t> GetOffset(spirv_cross::ID
id,
227 const std::vector<size_t>& offsets)
const;
229 std::optional<nlohmann::json::object_t> ReflectType(
230 const spirv_cross::TypeID& type_id)
const;
232 nlohmann::json::object_t EmitStructDefinition(
233 std::optional<Reflector::StructDefinition> struc)
const;
235 std::optional<StructDefinition> ReflectStructDefinition(
236 const spirv_cross::TypeID& type_id)
const;
238 std::vector<BindPrototype> ReflectBindPrototypes(
239 const spirv_cross::ShaderResources& resources,
240 spv::ExecutionModel execution_model)
const;
242 nlohmann::json::array_t EmitBindPrototypes(
243 const spirv_cross::ShaderResources& resources,
244 spv::ExecutionModel execution_model)
const;
246 std::optional<StructDefinition> ReflectPerVertexStructDefinition(
247 const spirv_cross::SmallVector<spirv_cross::Resource>& stage_inputs)
250 std::optional<std::string> GetMemberNameAtIndexIfExists(
251 const spirv_cross::SPIRType& parent_type,
254 std::string GetMemberNameAtIndex(
const spirv_cross::SPIRType& parent_type,
256 std::string suffix =
"")
const;
258 std::vector<StructMember> ReadStructMembers(
259 const spirv_cross::TypeID& type_id)
const;
261 std::optional<uint32_t> GetArrayElements(
262 const spirv_cross::SPIRType&
type)
const;
264 template <u
int32_t Size>
265 uint32_t GetArrayStride(
const spirv_cross::SPIRType& struct_type,
266 const spirv_cross::SPIRType& member_type,
267 uint32_t index)
const {
268 auto element_count = GetArrayElements(member_type).value_or(1);
269 if (element_count <= 1) {
272 return compiler_->type_struct_member_array_stride(struct_type, index);
277 Reflector& operator=(
const Reflector&) =
delete;