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
56 OS << enumToStringRef(Reg.ViewType, ArrayRef(RegisterNames)) << Reg.Number;
57
58 return OS;
59}
60
62 const llvm::dxbc::ShaderVisibility &Visibility) {
63 OS << enumToStringRef(Visibility, dxbc::getShaderVisibility());
64
65 return OS;
66}
67
74
81
83 const dxbc::ComparisonFunc &CompFunc) {
85
86 return OS;
87}
88
90 const dxbc::StaticBorderColor &BorderColor) {
91 OS << enumToStringRef(BorderColor, dxbc::getStaticBorderColors());
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 const llvm::dxbc::StaticSamplerFlags &Flags) {
119
120 return OS;
121}
122
124 OS << "RootFlags(";
125 printFlags(OS, Flags, dxbc::getRootFlags());
126 OS << ")";
127
128 return OS;
129}
130
132 OS << "RootConstants(num32BitConstants = " << Constants.Num32BitConstants
133 << ", " << Constants.Reg << ", space = " << Constants.Space
134 << ", visibility = " << Constants.Visibility << ")";
135
136 return OS;
137}
138
140 OS << "DescriptorTable(numClauses = " << Table.NumClauses
141 << ", visibility = " << Table.Visibility << ")";
142
143 return OS;
144}
145
147 OS << Clause.Type << "(" << Clause.Reg << ", numDescriptors = ";
148 if (Clause.NumDescriptors == NumDescriptorsUnbounded)
149 OS << "unbounded";
150 else
151 OS << Clause.NumDescriptors;
152 OS << ", space = " << Clause.Space << ", offset = ";
154 OS << "DescriptorTableOffsetAppend";
155 else
156 OS << Clause.Offset;
157 OS << ", flags = " << Clause.Flags << ")";
158
159 return OS;
160}
161
163 OS << "Root" << Descriptor.Type << "(" << Descriptor.Reg
164 << ", space = " << Descriptor.Space
165 << ", visibility = " << Descriptor.Visibility
166 << ", flags = " << Descriptor.Flags << ")";
167
168 return OS;
169}
170
172 OS << "StaticSampler(" << Sampler.Reg << ", filter = " << Sampler.Filter
173 << ", addressU = " << Sampler.AddressU
174 << ", addressV = " << Sampler.AddressV
175 << ", addressW = " << Sampler.AddressW
176 << ", mipLODBias = " << Sampler.MipLODBias
177 << ", maxAnisotropy = " << Sampler.MaxAnisotropy
178 << ", comparisonFunc = " << Sampler.CompFunc
179 << ", borderColor = " << Sampler.BorderColor
180 << ", minLOD = " << Sampler.MinLOD << ", maxLOD = " << Sampler.MaxLOD
181 << ", space = " << Sampler.Space << ", visibility = " << Sampler.Visibility
182 << ", flags = " << Sampler.Flags << ")";
183 return OS;
184}
185
186namespace {
187
188// We use the OverloadVisit with std::visit to ensure the compiler catches if a
189// new RootElement variant type is added but it's operator<< isn't handled.
190template <class... Ts> struct OverloadedVisit : Ts... {
191 using Ts::operator()...;
192};
193template <class... Ts> OverloadedVisit(Ts...) -> OverloadedVisit<Ts...>;
194
195} // namespace
196
198 const auto Visitor = OverloadedVisit{
199 [&OS](const dxbc::RootFlags &Flags) { OS << Flags; },
200 [&OS](const RootConstants &Constants) { OS << Constants; },
201 [&OS](const RootDescriptor &Descriptor) { OS << Descriptor; },
202 [&OS](const DescriptorTableClause &Clause) { OS << Clause; },
203 [&OS](const DescriptorTable &Table) { OS << Table; },
204 [&OS](const StaticSampler &Sampler) { OS << Sampler; },
205 };
206 std::visit(Visitor, Element);
207 return OS;
208}
209
211 OS << " RootElements{";
212 bool First = true;
213 for (const RootElement &Element : Elements) {
214 if (!First)
215 OS << ",";
216 OS << " " << Element;
217 First = false;
218 }
219 OS << "}";
220}
221
222} // namespace rootsig
223} // namespace hlsl
224} // namespace llvm
Register Reg
#define T
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:143
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()
LLVM_ABI ArrayRef< EnumEntry< RootFlags > > getRootFlags()
LLVM_ABI ArrayRef< EnumEntry< DescriptorRangeFlags > > getDescriptorRangeFlags()
LLVM_ABI ArrayRef< EnumEntry< SamplerFilter > > getSamplerFilters()
LLVM_ABI ArrayRef< EnumEntry< StaticBorderColor > > getStaticBorderColors()
LLVM_ABI ArrayRef< EnumEntry< TextureAddressMode > > getTextureAddressModes()
LLVM_ABI ArrayRef< EnumEntry< StaticSamplerFlags > > getStaticSamplerFlags()
LLVM_ABI ArrayRef< EnumEntry< RootDescriptorFlags > > getRootDescriptorFlags()
LLVM_ABI StringRef getResourceClassName(ResourceClass RC)
Definition DXILABI.cpp:21
static const uint32_t NumDescriptorsUnbounded
static const uint32_t DescriptorTableOffsetAppend
static const EnumEntry< RegisterType > RegisterNames[]
LLVM_ABI void dumpRootElements(raw_ostream &OS, ArrayRef< RootElement > Elements)
std::variant< dxbc::RootFlags, RootConstants, RootDescriptor, DescriptorTable, DescriptorTableClause, StaticSampler > RootElement
Models RootElement : RootFlags | RootConstants | RootParam | DescriptorTable | DescriptorTableClause ...
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.
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:186
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.
Definition ModRef.h:71
StringRef enumToStringRef(T Value, ArrayRef< EnumEntry< TEnum > > EnumValues)
Retrieves the Value's enum name.