1 //===- llvm/MC/DXContainerRootSignature.h - RootSignature -*- 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 #include "llvm/BinaryFormat/DXContainer.h" 10 #include <cstdint> 11 #include <limits> 12 13 namespace llvm { 14 15 class raw_ostream; 16 namespace mcdxbc { 17 18 struct RootParameterInfo { 19 dxbc::RTS0::v1::RootParameterHeader Header; 20 size_t Location; 21 22 RootParameterInfo() = default; 23 RootParameterInfoRootParameterInfo24 RootParameterInfo(dxbc::RTS0::v1::RootParameterHeader Header, size_t Location) 25 : Header(Header), Location(Location) {} 26 }; 27 28 struct DescriptorTable { 29 SmallVector<dxbc::RTS0::v2::DescriptorRange> Ranges; beginDescriptorTable30 SmallVector<dxbc::RTS0::v2::DescriptorRange>::const_iterator begin() const { 31 return Ranges.begin(); 32 } endDescriptorTable33 SmallVector<dxbc::RTS0::v2::DescriptorRange>::const_iterator end() const { 34 return Ranges.end(); 35 } 36 }; 37 38 struct RootParametersContainer { 39 SmallVector<RootParameterInfo> ParametersInfo; 40 41 SmallVector<dxbc::RTS0::v1::RootConstants> Constants; 42 SmallVector<dxbc::RTS0::v2::RootDescriptor> Descriptors; 43 SmallVector<DescriptorTable> Tables; 44 addInfoRootParametersContainer45 void addInfo(dxbc::RTS0::v1::RootParameterHeader Header, size_t Location) { 46 ParametersInfo.push_back(RootParameterInfo(Header, Location)); 47 } 48 addParameterRootParametersContainer49 void addParameter(dxbc::RTS0::v1::RootParameterHeader Header, 50 dxbc::RTS0::v1::RootConstants Constant) { 51 addInfo(Header, Constants.size()); 52 Constants.push_back(Constant); 53 } 54 addInvalidParameterRootParametersContainer55 void addInvalidParameter(dxbc::RTS0::v1::RootParameterHeader Header) { 56 addInfo(Header, -1); 57 } 58 addParameterRootParametersContainer59 void addParameter(dxbc::RTS0::v1::RootParameterHeader Header, 60 dxbc::RTS0::v2::RootDescriptor Descriptor) { 61 addInfo(Header, Descriptors.size()); 62 Descriptors.push_back(Descriptor); 63 } 64 addParameterRootParametersContainer65 void addParameter(dxbc::RTS0::v1::RootParameterHeader Header, 66 DescriptorTable Table) { 67 addInfo(Header, Tables.size()); 68 Tables.push_back(Table); 69 } 70 71 std::pair<uint32_t, uint32_t> getTypeAndLocForParameterRootParametersContainer72 getTypeAndLocForParameter(uint32_t Location) const { 73 const RootParameterInfo &Info = ParametersInfo[Location]; 74 return {Info.Header.ParameterType, Info.Location}; 75 } 76 getHeaderRootParametersContainer77 const dxbc::RTS0::v1::RootParameterHeader &getHeader(size_t Location) const { 78 const RootParameterInfo &Info = ParametersInfo[Location]; 79 return Info.Header; 80 } 81 getConstantRootParametersContainer82 const dxbc::RTS0::v1::RootConstants &getConstant(size_t Index) const { 83 return Constants[Index]; 84 } 85 getRootDescriptorRootParametersContainer86 const dxbc::RTS0::v2::RootDescriptor &getRootDescriptor(size_t Index) const { 87 return Descriptors[Index]; 88 } 89 getDescriptorTableRootParametersContainer90 const DescriptorTable &getDescriptorTable(size_t Index) const { 91 return Tables[Index]; 92 } 93 sizeRootParametersContainer94 size_t size() const { return ParametersInfo.size(); } 95 beginRootParametersContainer96 SmallVector<RootParameterInfo>::const_iterator begin() const { 97 return ParametersInfo.begin(); 98 } endRootParametersContainer99 SmallVector<RootParameterInfo>::const_iterator end() const { 100 return ParametersInfo.end(); 101 } 102 }; 103 struct RootSignatureDesc { 104 105 uint32_t Version = 2U; 106 uint32_t Flags = 0U; 107 uint32_t RootParameterOffset = 0U; 108 uint32_t StaticSamplersOffset = 0u; 109 uint32_t NumStaticSamplers = 0u; 110 mcdxbc::RootParametersContainer ParametersContainer; 111 SmallVector<dxbc::RTS0::v1::StaticSampler> StaticSamplers; 112 113 void write(raw_ostream &OS) const; 114 115 size_t getSize() const; 116 }; 117 } // namespace mcdxbc 118 } // namespace llvm 119