LLVM 22.0.0git
HLSLRootSignature.cpp
Go to the documentation of this file.
1//===- HLSLRootSignature.cpp - HLSL Root Signature helpers ----------------===//
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/// \file This file contains helpers for working with HLSL Root Signatures.
10///
11//===----------------------------------------------------------------------===//
12
16
17namespace llvm {
18namespace hlsl {
19namespace rootsig {
20
21template <typename T>
23 ArrayRef<EnumEntry<T>> Flags) {
24 bool FlagSet = false;
25 unsigned Remaining = llvm::to_underlying(Value);
26 while (Remaining) {
27 unsigned Bit = 1u << llvm::countr_zero(Remaining);
28 if (Remaining & Bit) {
29 if (FlagSet)
30 OS << " | ";
31
32 StringRef MaybeFlag = enumToStringRef(T(Bit), Flags);
33 if (!MaybeFlag.empty())
34 OS << MaybeFlag;
35 else
36 OS << "invalid: " << Bit;
37
38 FlagSet = true;
39 }
40 Remaining &= ~Bit;
41 }
42
43 if (!FlagSet)
44 OS << "None";
45 return OS;
46}
47
49 {"b", RegisterType::BReg},
50 {"t", RegisterType::TReg},
51 {"u", RegisterType::UReg},
52 {"s", RegisterType::SReg},
53};
54
57
58 return OS;
59}
60
62 const llvm::dxbc::ShaderVisibility &Visibility) {
64
65 return OS;
66}
67
71
72 return OS;
73}
74
78
79 return OS;
80}
81
83 const dxbc::ComparisonFunc &CompFunc) {
85
86 return OS;
87}
88
90 const dxbc::StaticBorderColor &BorderColor) {
92
93 return OS;
94}
95
99 return OS;
100}
101
103 const dxbc::RootDescriptorFlags &Flags) {
105
106 return OS;
107}
108
112
113 return OS;
114}
115
117 OS << "RootFlags(";
119 OS << ")";
120
121 return OS;
122}
123
125 OS << "RootConstants(num32BitConstants = " << Constants.Num32BitConstants
126 << ", " << Constants.Reg << ", space = " << Constants.Space
127 << ", visibility = " << Constants.Visibility << ")";
128
129 return OS;
130}
131
133 OS << "DescriptorTable(numClauses = " << Table.NumClauses
134 << ", visibility = " << Table.Visibility << ")";
135
136 return OS;
137}
138
140 OS << Clause.Type << "(" << Clause.Reg << ", numDescriptors = ";
141 if (Clause.NumDescriptors == NumDescriptorsUnbounded)
142 OS << "unbounded";
143 else
144 OS << Clause.NumDescriptors;
145 OS << ", space = " << Clause.Space << ", offset = ";
147 OS << "DescriptorTableOffsetAppend";
148 else
149 OS << Clause.Offset;
150 OS << ", flags = " << Clause.Flags << ")";
151
152 return OS;
153}
154
156 OS << "Root" << Descriptor.Type << "(" << Descriptor.Reg
157 << ", space = " << Descriptor.Space
158 << ", visibility = " << Descriptor.Visibility
159 << ", flags = " << Descriptor.Flags << ")";
160
161 return OS;
162}
163
165 OS << "StaticSampler(" << Sampler.Reg << ", filter = " << Sampler.Filter
166 << ", addressU = " << Sampler.AddressU
167 << ", addressV = " << Sampler.AddressV
168 << ", addressW = " << Sampler.AddressW
169 << ", mipLODBias = " << Sampler.MipLODBias
170 << ", maxAnisotropy = " << Sampler.MaxAnisotropy
171 << ", comparisonFunc = " << Sampler.CompFunc
172 << ", borderColor = " << Sampler.BorderColor
173 << ", minLOD = " << Sampler.MinLOD << ", maxLOD = " << Sampler.MaxLOD
174 << ", space = " << Sampler.Space << ", visibility = " << Sampler.Visibility
175 << ")";
176 return OS;
177}
178
179namespace {
180
181// We use the OverloadVisit with std::visit to ensure the compiler catches if a
182// new RootElement variant type is added but it's operator<< isn't handled.
183template <class... Ts> struct OverloadedVisit : Ts... {
184 using Ts::operator()...;
185};
186template <class... Ts> OverloadedVisit(Ts...) -> OverloadedVisit<Ts...>;
187
188} // namespace
189
191 const auto Visitor = OverloadedVisit{
192 [&OS](const dxbc::RootFlags &Flags) { OS << Flags; },
193 [&OS](const RootConstants &Constants) { OS << Constants; },
194 [&OS](const RootDescriptor &Descriptor) { OS << Descriptor; },
195 [&OS](const DescriptorTableClause &Clause) { OS << Clause; },
196 [&OS](const DescriptorTable &Table) { OS << Table; },
197 [&OS](const StaticSampler &Sampler) { OS << Sampler; },
198 };
199 std::visit(Visitor, Element);
200 return OS;
201}
202
204 OS << " RootElements{";
205 bool First = true;
206 for (const RootElement &Element : Elements) {
207 if (!First)
208 OS << ",";
209 OS << " " << Element;
210 First = false;
211 }
212 OS << "}";
213}
214
215} // namespace rootsig
216} // namespace hlsl
217} // namespace llvm
Register Reg
#define T
raw_pwrite_stream & OS
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
constexpr bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:151
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
LLVM Value Representation.
Definition: Value.h:75
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
LLVM_ABI ArrayRef< EnumEntry< ComparisonFunc > > getComparisonFuncs()
LLVM_ABI ArrayRef< EnumEntry< ShaderVisibility > > getShaderVisibility()
Definition: DXContainer.cpp:98
LLVM_ABI ArrayRef< EnumEntry< RootFlags > > getRootFlags()
Definition: DXContainer.cpp:68
LLVM_ABI ArrayRef< EnumEntry< DescriptorRangeFlags > > getDescriptorRangeFlags()
Definition: DXContainer.cpp:88
LLVM_ABI ArrayRef< EnumEntry< SamplerFilter > > getSamplerFilters()
LLVM_ABI ArrayRef< EnumEntry< StaticBorderColor > > getStaticBorderColors()
LLVM_ABI ArrayRef< EnumEntry< TextureAddressMode > > getTextureAddressModes()
LLVM_ABI ArrayRef< EnumEntry< RootDescriptorFlags > > getRootDescriptorFlags()
Definition: DXContainer.cpp:78
LLVM_ABI StringRef getResourceClassName(ResourceClass RC)
Definition: DXILABI.cpp:21
ResourceClass
Definition: DXILABI.h:26
static const uint32_t NumDescriptorsUnbounded
std::variant< dxbc::RootFlags, RootConstants, RootDescriptor, DescriptorTable, DescriptorTableClause, StaticSampler > RootElement
Models RootElement : RootFlags | RootConstants | RootParam | DescriptorTable | DescriptorTableClause ...
static const uint32_t DescriptorTableOffsetAppend
static const EnumEntry< RegisterType > RegisterNames[]
LLVM_ABI void dumpRootElements(raw_ostream &OS, ArrayRef< RootElement > Elements)
static raw_ostream & printFlags(raw_ostream &OS, const T Value, ArrayRef< EnumEntry< T > > Flags)
LLVM_ABI raw_ostream & operator<<(raw_ostream &OS, const dxbc::RootFlags &Flags)
The following contains the serialization interface for root elements.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
int countr_zero(T Val)
Count number of 0's from the least significant bit to the most stopping at the first 1.
Definition: bit.h:157
constexpr std::underlying_type_t< Enum > to_underlying(Enum E)
Returns underlying integer value of an enum.
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
StringRef enumToStringRef(T Value, ArrayRef< EnumEntry< TEnum > > EnumValues)
Retrieves the Value's enum name.
dxbc::RootDescriptorFlags Flags