1 //===- llvm/MC/DXContainerPSVInfo.h - DXContainer PSVInfo -*- 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 #ifndef LLVM_MC_DXCONTAINERPSVINFO_H 10 #define LLVM_MC_DXCONTAINERPSVINFO_H 11 12 #include "llvm/ADT/ArrayRef.h" 13 #include "llvm/ADT/SmallVector.h" 14 #include "llvm/ADT/StringRef.h" 15 #include "llvm/BinaryFormat/DXContainer.h" 16 #include "llvm/MC/StringTableBuilder.h" 17 #include "llvm/TargetParser/Triple.h" 18 19 #include <array> 20 #include <numeric> 21 #include <stdint.h> 22 23 namespace llvm { 24 25 class raw_ostream; 26 27 namespace mcdxbc { 28 29 struct PSVSignatureElement { 30 StringRef Name; 31 SmallVector<uint32_t> Indices; 32 uint8_t StartRow; 33 uint8_t Cols; 34 uint8_t StartCol; 35 bool Allocated; 36 dxbc::PSV::SemanticKind Kind; 37 dxbc::PSV::ComponentType Type; 38 dxbc::PSV::InterpolationMode Mode; 39 uint8_t DynamicMask; 40 uint8_t Stream; 41 }; 42 43 // This data structure is a helper for reading and writing PSV RuntimeInfo data. 44 // It is implemented in the BinaryFormat library so that it can be used by both 45 // the MC layer and Object tools. 46 // This structure is used to represent the extracted data in an inspectable and 47 // modifiable format, and can be used to serialize the data back into valid PSV 48 // RuntimeInfo. 49 struct PSVRuntimeInfo { PSVRuntimeInfoPSVRuntimeInfo50 PSVRuntimeInfo() : DXConStrTabBuilder(StringTableBuilder::DXContainer) { 51 memset((void *)&BaseData, 0, sizeof(dxbc::PSV::v3::RuntimeInfo)); 52 } 53 bool IsFinalized = false; 54 dxbc::PSV::v3::RuntimeInfo BaseData; 55 SmallVector<dxbc::PSV::v2::ResourceBindInfo> Resources; 56 SmallVector<PSVSignatureElement> InputElements; 57 SmallVector<PSVSignatureElement> OutputElements; 58 SmallVector<PSVSignatureElement> PatchOrPrimElements; 59 60 // TODO: Make this interface user-friendly. 61 // The interface here is bad, and we'll want to change this in the future. We 62 // probably will want to build out these mask vectors as vectors of bools and 63 // have this utility object convert them to the bit masks. I don't want to 64 // over-engineer this API now since we don't know what the data coming in to 65 // feed it will look like, so I kept it extremely simple for the immediate use 66 // case. 67 std::array<SmallVector<uint32_t>, 4> OutputVectorMasks; 68 SmallVector<uint32_t> PatchOrPrimMasks; 69 std::array<SmallVector<uint32_t>, 4> InputOutputMap; 70 SmallVector<uint32_t> InputPatchMap; 71 SmallVector<uint32_t> PatchOutputMap; 72 llvm::StringRef EntryName; 73 74 // Serialize PSVInfo into the provided raw_ostream. The version field 75 // specifies the data version to encode, the default value specifies encoding 76 // the highest supported version. 77 void write(raw_ostream &OS, 78 uint32_t Version = std::numeric_limits<uint32_t>::max()) const; 79 80 void finalize(Triple::EnvironmentType Stage); 81 82 private: 83 SmallVector<uint32_t, 64> IndexBuffer; 84 SmallVector<llvm::dxbc::PSV::v0::SignatureElement, 32> SignatureElements; 85 StringTableBuilder DXConStrTabBuilder; 86 }; 87 88 class Signature { 89 struct Parameter { 90 uint32_t Stream; 91 StringRef Name; 92 uint32_t Index; 93 dxbc::D3DSystemValue SystemValue; 94 dxbc::SigComponentType CompType; 95 uint32_t Register; 96 uint8_t Mask; 97 uint8_t ExclusiveMask; 98 dxbc::SigMinPrecision MinPrecision; 99 }; 100 101 SmallVector<Parameter> Params; 102 103 public: addParam(uint32_t Stream,StringRef Name,uint32_t Index,dxbc::D3DSystemValue SystemValue,dxbc::SigComponentType CompType,uint32_t Register,uint8_t Mask,uint8_t ExclusiveMask,dxbc::SigMinPrecision MinPrecision)104 void addParam(uint32_t Stream, StringRef Name, uint32_t Index, 105 dxbc::D3DSystemValue SystemValue, 106 dxbc::SigComponentType CompType, uint32_t Register, 107 uint8_t Mask, uint8_t ExclusiveMask, 108 dxbc::SigMinPrecision MinPrecision) { 109 Params.push_back(Parameter{Stream, Name, Index, SystemValue, CompType, 110 Register, Mask, ExclusiveMask, MinPrecision}); 111 } 112 113 void write(raw_ostream &OS); 114 }; 115 116 } // namespace mcdxbc 117 } // namespace llvm 118 119 #endif // LLVM_MC_DXCONTAINERPSVINFO_H 120