Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //===- llvm/MC/DXContainerPSVInfo.h - DXContainer PSVInfo -*- 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 #ifndef LLVM_MC_DXCONTAINERPSVINFO_H
0010 #define LLVM_MC_DXCONTAINERPSVINFO_H
0011 
0012 #include "llvm/ADT/ArrayRef.h"
0013 #include "llvm/ADT/SmallVector.h"
0014 #include "llvm/ADT/StringRef.h"
0015 #include "llvm/BinaryFormat/DXContainer.h"
0016 #include "llvm/MC/StringTableBuilder.h"
0017 #include "llvm/TargetParser/Triple.h"
0018 
0019 #include <array>
0020 #include <numeric>
0021 #include <stdint.h>
0022 
0023 namespace llvm {
0024 
0025 class raw_ostream;
0026 
0027 namespace mcdxbc {
0028 
0029 struct PSVSignatureElement {
0030   StringRef Name;
0031   SmallVector<uint32_t> Indices;
0032   uint8_t StartRow;
0033   uint8_t Cols;
0034   uint8_t StartCol;
0035   bool Allocated;
0036   dxbc::PSV::SemanticKind Kind;
0037   dxbc::PSV::ComponentType Type;
0038   dxbc::PSV::InterpolationMode Mode;
0039   uint8_t DynamicMask;
0040   uint8_t Stream;
0041 };
0042 
0043 // This data structure is a helper for reading and writing PSV RuntimeInfo data.
0044 // It is implemented in the BinaryFormat library so that it can be used by both
0045 // the MC layer and Object tools.
0046 // This structure is used to represent the extracted data in an inspectable and
0047 // modifiable format, and can be used to serialize the data back into valid PSV
0048 // RuntimeInfo.
0049 struct PSVRuntimeInfo {
0050   PSVRuntimeInfo() : DXConStrTabBuilder(StringTableBuilder::DXContainer) {
0051     memset((void *)&BaseData, 0, sizeof(dxbc::PSV::v3::RuntimeInfo));
0052   }
0053   bool IsFinalized = false;
0054   dxbc::PSV::v3::RuntimeInfo BaseData;
0055   SmallVector<dxbc::PSV::v2::ResourceBindInfo> Resources;
0056   SmallVector<PSVSignatureElement> InputElements;
0057   SmallVector<PSVSignatureElement> OutputElements;
0058   SmallVector<PSVSignatureElement> PatchOrPrimElements;
0059 
0060   // TODO: Make this interface user-friendly.
0061   // The interface here is bad, and we'll want to change this in the future. We
0062   // probably will want to build out these mask vectors as vectors of bools and
0063   // have this utility object convert them to the bit masks. I don't want to
0064   // over-engineer this API now since we don't know what the data coming in to
0065   // feed it will look like, so I kept it extremely simple for the immediate use
0066   // case.
0067   std::array<SmallVector<uint32_t>, 4> OutputVectorMasks;
0068   SmallVector<uint32_t> PatchOrPrimMasks;
0069   std::array<SmallVector<uint32_t>, 4> InputOutputMap;
0070   SmallVector<uint32_t> InputPatchMap;
0071   SmallVector<uint32_t> PatchOutputMap;
0072   llvm::StringRef EntryName;
0073 
0074   // Serialize PSVInfo into the provided raw_ostream. The version field
0075   // specifies the data version to encode, the default value specifies encoding
0076   // the highest supported version.
0077   void write(raw_ostream &OS,
0078              uint32_t Version = std::numeric_limits<uint32_t>::max()) const;
0079 
0080   void finalize(Triple::EnvironmentType Stage);
0081 
0082 private:
0083   SmallVector<uint32_t, 64> IndexBuffer;
0084   SmallVector<llvm::dxbc::PSV::v0::SignatureElement, 32> SignatureElements;
0085   StringTableBuilder DXConStrTabBuilder;
0086 };
0087 
0088 class Signature {
0089   struct Parameter {
0090     uint32_t Stream;
0091     StringRef Name;
0092     uint32_t Index;
0093     dxbc::D3DSystemValue SystemValue;
0094     dxbc::SigComponentType CompType;
0095     uint32_t Register;
0096     uint8_t Mask;
0097     uint8_t ExclusiveMask;
0098     dxbc::SigMinPrecision MinPrecision;
0099   };
0100 
0101   SmallVector<Parameter> Params;
0102 
0103 public:
0104   void addParam(uint32_t Stream, StringRef Name, uint32_t Index,
0105                 dxbc::D3DSystemValue SystemValue,
0106                 dxbc::SigComponentType CompType, uint32_t Register,
0107                 uint8_t Mask, uint8_t ExclusiveMask,
0108                 dxbc::SigMinPrecision MinPrecision) {
0109     Params.push_back(Parameter{Stream, Name, Index, SystemValue, CompType,
0110                                Register, Mask, ExclusiveMask, MinPrecision});
0111   }
0112 
0113   void write(raw_ostream &OS);
0114 };
0115 
0116 } // namespace mcdxbc
0117 } // namespace llvm
0118 
0119 #endif // LLVM_MC_DXCONTAINERPSVINFO_H