1 //===- DXContainerYAML.h - DXContainer YAMLIO implementation ----*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 /// 9 /// \file 10 /// This file declares classes for handling the YAML representation 11 /// of DXContainer. 12 /// 13 //===----------------------------------------------------------------------===// 14 15 #ifndef LLVM_OBJECTYAML_DXCONTAINERYAML_H 16 #define LLVM_OBJECTYAML_DXCONTAINERYAML_H 17 18 #include "llvm/ADT/StringRef.h" 19 #include "llvm/ObjectYAML/YAML.h" 20 #include "llvm/Support/YAMLTraits.h" 21 #include <cstdint> 22 #include <string> 23 #include <vector> 24 25 namespace llvm { 26 namespace DXContainerYAML { 27 28 struct VersionTuple { 29 uint16_t Major; 30 uint16_t Minor; 31 }; 32 33 // The optional header fields are required in the binary and will be populated 34 // when reading from binary, but can be omitted in the YAML text because the 35 // emitter can calculate them. 36 struct FileHeader { 37 std::vector<llvm::yaml::Hex8> Hash; 38 VersionTuple Version; 39 Optional<uint32_t> FileSize; 40 uint32_t PartCount; 41 Optional<std::vector<uint32_t>> PartOffsets; 42 }; 43 44 struct DXILProgram { 45 uint8_t MajorVersion; 46 uint8_t MinorVersion; 47 uint16_t ShaderKind; 48 Optional<uint32_t> Size; 49 uint16_t DXILMajorVersion; 50 uint16_t DXILMinorVersion; 51 Optional<uint32_t> DXILOffset; 52 Optional<uint32_t> DXILSize; 53 Optional<std::vector<llvm::yaml::Hex8>> DXIL; 54 }; 55 56 struct Part { 57 std::string Name; 58 uint32_t Size; 59 Optional<DXILProgram> Program; 60 }; 61 62 struct Object { 63 FileHeader Header; 64 std::vector<Part> Parts; 65 }; 66 67 } // namespace DXContainerYAML 68 } // namespace llvm 69 70 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DXContainerYAML::Part) 71 namespace llvm { 72 73 class raw_ostream; 74 75 namespace yaml { 76 77 template <> struct MappingTraits<DXContainerYAML::VersionTuple> { 78 static void mapping(IO &IO, DXContainerYAML::VersionTuple &Version); 79 }; 80 81 template <> struct MappingTraits<DXContainerYAML::FileHeader> { 82 static void mapping(IO &IO, DXContainerYAML::FileHeader &Header); 83 }; 84 85 template <> struct MappingTraits<DXContainerYAML::DXILProgram> { 86 static void mapping(IO &IO, DXContainerYAML::DXILProgram &Program); 87 }; 88 89 template <> struct MappingTraits<DXContainerYAML::Part> { 90 static void mapping(IO &IO, DXContainerYAML::Part &Version); 91 }; 92 93 template <> struct MappingTraits<DXContainerYAML::Object> { 94 static void mapping(IO &IO, DXContainerYAML::Object &Obj); 95 }; 96 97 } // namespace yaml 98 99 } // namespace llvm 100 101 #endif // LLVM_OBJECTYAML_DXCONTAINERYAML_H 102