DXContainerYAML.h 3.6 KB

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