Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:21

0001 //===- DXContainerYAML.h - DXContainer YAMLIO implementation ----*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 ///
0009 /// \file
0010 /// This file declares classes for handling the YAML representation
0011 /// of DXContainer.
0012 ///
0013 //===----------------------------------------------------------------------===//
0014 
0015 #ifndef LLVM_OBJECTYAML_DXCONTAINERYAML_H
0016 #define LLVM_OBJECTYAML_DXCONTAINERYAML_H
0017 
0018 #include "llvm/ADT/StringRef.h"
0019 #include "llvm/BinaryFormat/DXContainer.h"
0020 #include "llvm/ObjectYAML/YAML.h"
0021 #include "llvm/Support/YAMLTraits.h"
0022 #include <array>
0023 #include <cstdint>
0024 #include <optional>
0025 #include <string>
0026 #include <vector>
0027 
0028 namespace llvm {
0029 namespace DXContainerYAML {
0030 
0031 struct VersionTuple {
0032   uint16_t Major;
0033   uint16_t Minor;
0034 };
0035 
0036 // The optional header fields are required in the binary and will be populated
0037 // when reading from binary, but can be omitted in the YAML text because the
0038 // emitter can calculate them.
0039 struct FileHeader {
0040   std::vector<llvm::yaml::Hex8> Hash;
0041   VersionTuple Version;
0042   std::optional<uint32_t> FileSize;
0043   uint32_t PartCount;
0044   std::optional<std::vector<uint32_t>> PartOffsets;
0045 };
0046 
0047 struct DXILProgram {
0048   uint8_t MajorVersion;
0049   uint8_t MinorVersion;
0050   uint16_t ShaderKind;
0051   std::optional<uint32_t> Size;
0052   uint16_t DXILMajorVersion;
0053   uint16_t DXILMinorVersion;
0054   std::optional<uint32_t> DXILOffset;
0055   std::optional<uint32_t> DXILSize;
0056   std::optional<std::vector<llvm::yaml::Hex8>> DXIL;
0057 };
0058 
0059 #define SHADER_FEATURE_FLAG(Num, DxilModuleNum, Val, Str) bool Val = false;
0060 struct ShaderFeatureFlags {
0061   ShaderFeatureFlags() = default;
0062   ShaderFeatureFlags(uint64_t FlagData);
0063   uint64_t getEncodedFlags();
0064 #include "llvm/BinaryFormat/DXContainerConstants.def"
0065 };
0066 
0067 struct ShaderHash {
0068   ShaderHash() = default;
0069   ShaderHash(const dxbc::ShaderHash &Data);
0070 
0071   bool IncludesSource;
0072   std::vector<llvm::yaml::Hex8> Digest;
0073 };
0074 
0075 using ResourceFlags = dxbc::PSV::ResourceFlags;
0076 using ResourceBindInfo = dxbc::PSV::v2::ResourceBindInfo;
0077 
0078 struct SignatureElement {
0079   SignatureElement() = default;
0080 
0081   SignatureElement(dxbc::PSV::v0::SignatureElement El, StringRef StringTable,
0082                    ArrayRef<uint32_t> IdxTable)
0083       : Name(StringTable.substr(El.NameOffset,
0084                                 StringTable.find('\0', El.NameOffset) -
0085                                     El.NameOffset)),
0086         Indices(IdxTable.slice(El.IndicesOffset, El.Rows)),
0087         StartRow(El.StartRow), Cols(El.Cols), StartCol(El.StartCol),
0088         Allocated(El.Allocated != 0), Kind(El.Kind), Type(El.Type),
0089         Mode(El.Mode), DynamicMask(El.DynamicMask), Stream(El.Stream) {}
0090   StringRef Name;
0091   SmallVector<uint32_t> Indices;
0092 
0093   uint8_t StartRow;
0094   uint8_t Cols;
0095   uint8_t StartCol;
0096   bool Allocated;
0097   dxbc::PSV::SemanticKind Kind;
0098 
0099   dxbc::PSV::ComponentType Type;
0100   dxbc::PSV::InterpolationMode Mode;
0101   llvm::yaml::Hex8 DynamicMask;
0102   uint8_t Stream;
0103 };
0104 
0105 struct PSVInfo {
0106   // The version field isn't actually encoded in the file, but it is inferred by
0107   // the size of data regions. We include it in the yaml because it simplifies
0108   // the format.
0109   uint32_t Version;
0110 
0111   dxbc::PSV::v3::RuntimeInfo Info;
0112   uint32_t ResourceStride;
0113   SmallVector<ResourceBindInfo> Resources;
0114   SmallVector<SignatureElement> SigInputElements;
0115   SmallVector<SignatureElement> SigOutputElements;
0116   SmallVector<SignatureElement> SigPatchOrPrimElements;
0117 
0118   using MaskVector = SmallVector<llvm::yaml::Hex32>;
0119   std::array<MaskVector, 4> OutputVectorMasks;
0120   MaskVector PatchOrPrimMasks;
0121   std::array<MaskVector, 4> InputOutputMap;
0122   MaskVector InputPatchMap;
0123   MaskVector PatchOutputMap;
0124 
0125   StringRef EntryName;
0126 
0127   void mapInfoForVersion(yaml::IO &IO);
0128 
0129   PSVInfo();
0130   PSVInfo(const dxbc::PSV::v0::RuntimeInfo *P, uint16_t Stage);
0131   PSVInfo(const dxbc::PSV::v1::RuntimeInfo *P);
0132   PSVInfo(const dxbc::PSV::v2::RuntimeInfo *P);
0133   PSVInfo(const dxbc::PSV::v3::RuntimeInfo *P, StringRef StringTable);
0134 };
0135 
0136 struct SignatureParameter {
0137   uint32_t Stream;
0138   std::string Name;
0139   uint32_t Index;
0140   dxbc::D3DSystemValue SystemValue;
0141   dxbc::SigComponentType CompType;
0142   uint32_t Register;
0143   uint8_t Mask;
0144   uint8_t ExclusiveMask;
0145   dxbc::SigMinPrecision MinPrecision;
0146 };
0147 
0148 struct Signature {
0149   llvm::SmallVector<SignatureParameter> Parameters;
0150 };
0151 
0152 struct Part {
0153   Part() = default;
0154   Part(std::string N, uint32_t S) : Name(N), Size(S) {}
0155   std::string Name;
0156   uint32_t Size;
0157   std::optional<DXILProgram> Program;
0158   std::optional<ShaderFeatureFlags> Flags;
0159   std::optional<ShaderHash> Hash;
0160   std::optional<PSVInfo> Info;
0161   std::optional<DXContainerYAML::Signature> Signature;
0162 };
0163 
0164 struct Object {
0165   FileHeader Header;
0166   std::vector<Part> Parts;
0167 };
0168 
0169 } // namespace DXContainerYAML
0170 } // namespace llvm
0171 
0172 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DXContainerYAML::Part)
0173 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DXContainerYAML::ResourceBindInfo)
0174 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DXContainerYAML::SignatureElement)
0175 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DXContainerYAML::PSVInfo::MaskVector)
0176 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DXContainerYAML::SignatureParameter)
0177 LLVM_YAML_DECLARE_ENUM_TRAITS(llvm::dxbc::PSV::SemanticKind)
0178 LLVM_YAML_DECLARE_ENUM_TRAITS(llvm::dxbc::PSV::ComponentType)
0179 LLVM_YAML_DECLARE_ENUM_TRAITS(llvm::dxbc::PSV::InterpolationMode)
0180 LLVM_YAML_DECLARE_ENUM_TRAITS(llvm::dxbc::PSV::ResourceType)
0181 LLVM_YAML_DECLARE_ENUM_TRAITS(llvm::dxbc::PSV::ResourceKind)
0182 LLVM_YAML_DECLARE_ENUM_TRAITS(llvm::dxbc::D3DSystemValue)
0183 LLVM_YAML_DECLARE_ENUM_TRAITS(llvm::dxbc::SigComponentType)
0184 LLVM_YAML_DECLARE_ENUM_TRAITS(llvm::dxbc::SigMinPrecision)
0185 
0186 namespace llvm {
0187 
0188 class raw_ostream;
0189 
0190 namespace yaml {
0191 
0192 template <> struct MappingTraits<DXContainerYAML::VersionTuple> {
0193   static void mapping(IO &IO, DXContainerYAML::VersionTuple &Version);
0194 };
0195 
0196 template <> struct MappingTraits<DXContainerYAML::FileHeader> {
0197   static void mapping(IO &IO, DXContainerYAML::FileHeader &Header);
0198 };
0199 
0200 template <> struct MappingTraits<DXContainerYAML::DXILProgram> {
0201   static void mapping(IO &IO, DXContainerYAML::DXILProgram &Program);
0202 };
0203 
0204 template <> struct MappingTraits<DXContainerYAML::ShaderFeatureFlags> {
0205   static void mapping(IO &IO, DXContainerYAML::ShaderFeatureFlags &Flags);
0206 };
0207 
0208 template <> struct MappingTraits<DXContainerYAML::ShaderHash> {
0209   static void mapping(IO &IO, DXContainerYAML::ShaderHash &Hash);
0210 };
0211 
0212 template <> struct MappingTraits<DXContainerYAML::PSVInfo> {
0213   static void mapping(IO &IO, DXContainerYAML::PSVInfo &PSV);
0214 };
0215 
0216 template <> struct MappingTraits<DXContainerYAML::Part> {
0217   static void mapping(IO &IO, DXContainerYAML::Part &Version);
0218 };
0219 
0220 template <> struct MappingTraits<DXContainerYAML::Object> {
0221   static void mapping(IO &IO, DXContainerYAML::Object &Obj);
0222 };
0223 
0224 template <> struct MappingTraits<DXContainerYAML::ResourceFlags> {
0225   static void mapping(IO &IO, DXContainerYAML::ResourceFlags &Flags);
0226 };
0227 
0228 template <> struct MappingTraits<DXContainerYAML::ResourceBindInfo> {
0229   static void mapping(IO &IO, DXContainerYAML::ResourceBindInfo &Res);
0230 };
0231 
0232 template <> struct MappingTraits<DXContainerYAML::SignatureElement> {
0233   static void mapping(IO &IO, llvm::DXContainerYAML::SignatureElement &El);
0234 };
0235 
0236 template <> struct MappingTraits<DXContainerYAML::SignatureParameter> {
0237   static void mapping(IO &IO, llvm::DXContainerYAML::SignatureParameter &El);
0238 };
0239 
0240 template <> struct MappingTraits<DXContainerYAML::Signature> {
0241   static void mapping(IO &IO, llvm::DXContainerYAML::Signature &El);
0242 };
0243 
0244 } // namespace yaml
0245 
0246 } // namespace llvm
0247 
0248 #endif // LLVM_OBJECTYAML_DXCONTAINERYAML_H