DXContainerYAML.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. //===- DXContainerYAML.cpp - DXContainer YAMLIO implementation ------------===//
  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. // This file defines classes for handling the YAML representation of
  10. // DXContainerYAML.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #include "llvm/ObjectYAML/DXContainerYAML.h"
  14. #include "llvm/BinaryFormat/DXContainer.h"
  15. namespace llvm {
  16. // This assert is duplicated here to leave a breadcrumb of the places that need
  17. // to be updated if flags grow past 64-bits.
  18. static_assert((uint64_t)dxbc::FeatureFlags::NextUnusedBit <= 1ull << 63,
  19. "Shader flag bits exceed enum size.");
  20. DXContainerYAML::ShaderFlags::ShaderFlags(uint64_t FlagData) {
  21. #define SHADER_FLAG(Num, Val, Str) \
  22. Val = (FlagData & (uint64_t)dxbc::FeatureFlags::Val) > 0;
  23. #include "llvm/BinaryFormat/DXContainerConstants.def"
  24. }
  25. uint64_t DXContainerYAML::ShaderFlags::getEncodedFlags() {
  26. uint64_t Flag = 0;
  27. #define SHADER_FLAG(Num, Val, Str) \
  28. if (Val) \
  29. Flag |= (uint64_t)dxbc::FeatureFlags::Val;
  30. #include "llvm/BinaryFormat/DXContainerConstants.def"
  31. return Flag;
  32. }
  33. DXContainerYAML::ShaderHash::ShaderHash(const dxbc::ShaderHash &Data)
  34. : IncludesSource((Data.Flags & static_cast<uint32_t>(
  35. dxbc::HashFlags::IncludesSource)) != 0),
  36. Digest(16, 0) {
  37. memcpy(Digest.data(), &Data.Digest[0], 16);
  38. }
  39. namespace yaml {
  40. void MappingTraits<DXContainerYAML::VersionTuple>::mapping(
  41. IO &IO, DXContainerYAML::VersionTuple &Version) {
  42. IO.mapRequired("Major", Version.Major);
  43. IO.mapRequired("Minor", Version.Minor);
  44. }
  45. void MappingTraits<DXContainerYAML::FileHeader>::mapping(
  46. IO &IO, DXContainerYAML::FileHeader &Header) {
  47. IO.mapRequired("Hash", Header.Hash);
  48. IO.mapRequired("Version", Header.Version);
  49. IO.mapOptional("FileSize", Header.FileSize);
  50. IO.mapRequired("PartCount", Header.PartCount);
  51. IO.mapOptional("PartOffsets", Header.PartOffsets);
  52. }
  53. void MappingTraits<DXContainerYAML::DXILProgram>::mapping(
  54. IO &IO, DXContainerYAML::DXILProgram &Program) {
  55. IO.mapRequired("MajorVersion", Program.MajorVersion);
  56. IO.mapRequired("MinorVersion", Program.MinorVersion);
  57. IO.mapRequired("ShaderKind", Program.ShaderKind);
  58. IO.mapOptional("Size", Program.Size);
  59. IO.mapRequired("DXILMajorVersion", Program.DXILMajorVersion);
  60. IO.mapRequired("DXILMinorVersion", Program.DXILMinorVersion);
  61. IO.mapOptional("DXILSize", Program.DXILSize);
  62. IO.mapOptional("DXIL", Program.DXIL);
  63. }
  64. void MappingTraits<DXContainerYAML::ShaderFlags>::mapping(
  65. IO &IO, DXContainerYAML::ShaderFlags &Flags) {
  66. #define SHADER_FLAG(Num, Val, Str) IO.mapRequired(#Val, Flags.Val);
  67. #include "llvm/BinaryFormat/DXContainerConstants.def"
  68. }
  69. void MappingTraits<DXContainerYAML::ShaderHash>::mapping(
  70. IO &IO, DXContainerYAML::ShaderHash &Hash) {
  71. IO.mapRequired("IncludesSource", Hash.IncludesSource);
  72. IO.mapRequired("Digest", Hash.Digest);
  73. }
  74. void MappingTraits<DXContainerYAML::Part>::mapping(IO &IO,
  75. DXContainerYAML::Part &P) {
  76. IO.mapRequired("Name", P.Name);
  77. IO.mapRequired("Size", P.Size);
  78. IO.mapOptional("Program", P.Program);
  79. IO.mapOptional("Flags", P.Flags);
  80. IO.mapOptional("Hash", P.Hash);
  81. }
  82. void MappingTraits<DXContainerYAML::Object>::mapping(
  83. IO &IO, DXContainerYAML::Object &Obj) {
  84. IO.mapTag("!dxcontainer", true);
  85. IO.mapRequired("Header", Obj.Header);
  86. IO.mapRequired("Parts", Obj.Parts);
  87. }
  88. } // namespace yaml
  89. } // namespace llvm