//===- DXContainerYAML.h - DXContainer YAMLIO implementation ----*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// /// /// \file /// This file declares classes for handling the YAML representation /// of DXContainer. /// //===----------------------------------------------------------------------===// #ifndef LLVM_OBJECTYAML_DXCONTAINERYAML_H #define LLVM_OBJECTYAML_DXCONTAINERYAML_H #include "llvm/ADT/StringRef.h" #include "llvm/BinaryFormat/DXContainer.h" #include "llvm/ObjectYAML/YAML.h" #include "llvm/Support/YAMLTraits.h" #include #include #include #include namespace llvm { namespace DXContainerYAML { struct VersionTuple { uint16_t Major; uint16_t Minor; }; // The optional header fields are required in the binary and will be populated // when reading from binary, but can be omitted in the YAML text because the // emitter can calculate them. struct FileHeader { std::vector Hash; VersionTuple Version; std::optional FileSize; uint32_t PartCount; std::optional> PartOffsets; }; struct DXILProgram { uint8_t MajorVersion; uint8_t MinorVersion; uint16_t ShaderKind; std::optional Size; uint16_t DXILMajorVersion; uint16_t DXILMinorVersion; std::optional DXILOffset; std::optional DXILSize; std::optional> DXIL; }; #define SHADER_FLAG(Num, Val, Str) bool Val = false; struct ShaderFlags { ShaderFlags() = default; ShaderFlags(uint64_t FlagData); uint64_t getEncodedFlags(); #include "llvm/BinaryFormat/DXContainerConstants.def" }; struct ShaderHash { ShaderHash() = default; ShaderHash(const dxbc::ShaderHash &Data); bool IncludesSource; std::vector Digest; }; using ResourceBindInfo = dxbc::PSV::v2::ResourceBindInfo; struct PSVInfo { // The version field isn't actually encoded in the file, but it is inferred by // the size of data regions. We include it in the yaml because it simplifies // the format. uint32_t Version; dxbc::PSV::v2::RuntimeInfo Info; uint32_t ResourceStride; std::vector Resources; void mapInfoForVersion(yaml::IO &IO); PSVInfo(); PSVInfo(const dxbc::PSV::v0::RuntimeInfo *P, uint16_t Stage); PSVInfo(const dxbc::PSV::v1::RuntimeInfo *P); PSVInfo(const dxbc::PSV::v2::RuntimeInfo *P); }; struct Part { Part() = default; Part(std::string N, uint32_t S) : Name(N), Size(S) {} std::string Name; uint32_t Size; std::optional Program; std::optional Flags; std::optional Hash; std::optional Info; }; struct Object { FileHeader Header; std::vector Parts; }; } // namespace DXContainerYAML } // namespace llvm LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DXContainerYAML::Part) LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DXContainerYAML::ResourceBindInfo) namespace llvm { class raw_ostream; namespace yaml { template <> struct MappingTraits { static void mapping(IO &IO, DXContainerYAML::VersionTuple &Version); }; template <> struct MappingTraits { static void mapping(IO &IO, DXContainerYAML::FileHeader &Header); }; template <> struct MappingTraits { static void mapping(IO &IO, DXContainerYAML::DXILProgram &Program); }; template <> struct MappingTraits { static void mapping(IO &IO, DXContainerYAML::ShaderFlags &Flags); }; template <> struct MappingTraits { static void mapping(IO &IO, DXContainerYAML::ShaderHash &Hash); }; template <> struct MappingTraits { static void mapping(IO &IO, DXContainerYAML::PSVInfo &PSV); }; template <> struct MappingTraits { static void mapping(IO &IO, DXContainerYAML::Part &Version); }; template <> struct MappingTraits { static void mapping(IO &IO, DXContainerYAML::Object &Obj); }; template <> struct MappingTraits { static void mapping(IO &IO, DXContainerYAML::ResourceBindInfo &Res); }; } // namespace yaml } // namespace llvm #endif // LLVM_OBJECTYAML_DXCONTAINERYAML_H