LLVM 23.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
17
18namespace llvm {
19namespace hlsl {
20namespace rootsig {
21
22template <typename T>
24 ArrayRef<EnumEntry<T>> Flags) {
25 bool FlagSet = false;
26 unsigned Remaining = llvm::to_underlying(Value);
27 while (Remaining) {
28 unsigned Bit = 1u << llvm::countr_zero(Remaining);
29 if (Remaining & Bit) {
30 if (FlagSet)
31 OS << " | ";
32
33 StringRef MaybeFlag = enumToStringRef(T(Bit), Flags);
34 if (!MaybeFlag.empty())
35 OS << MaybeFlag;
36 else
37 OS << "invalid: " << Bit;
38
39 FlagSet = true;
40 }
41 Remaining &= ~Bit;
42 }
43
44 if (!FlagSet)
45 OS << "None";
46 return OS;
47}
48
50 {"b", RegisterType::BReg},
51 {"t", RegisterType::TReg},
52 {"u", RegisterType::UReg},
53 {"s", RegisterType::SReg},
54};
55
57 OS << enumToStringRef(Reg.ViewType, ArrayRef(RegisterNames)) << Reg.Number;
58
59 return OS;
60}
61
63 const llvm::dxbc::ShaderVisibility &Visibility) {
64 OS << enumToStringRef(Visibility, dxbc::getShaderVisibility());
65
66 return OS;
67}
68
75
82
84 const dxbc::ComparisonFunc &CompFunc) {
86
87 return OS;
88}
89
91 const dxbc::StaticBorderColor &BorderColor) {
92 OS << enumToStringRef(BorderColor, dxbc::getStaticBorderColors());
93
94 return OS;
95}
96
100 return OS;
101}
102
104 const dxbc::RootDescriptorFlags &Flags) {
106
107 return OS;
108}
109
113
114 return OS;
115}
116
118 const llvm::dxbc::StaticSamplerFlags &Flags) {
120
121 return OS;
122}
123
125 OS << "RootFlags(";
126 printFlags(OS, Flags, dxbc::getRootFlags());
127 OS << ")";
128
129 return OS;
130}
131
133 OS << "RootConstants(num32BitConstants = " << Constants.Num32BitConstants
134 << ", " << Constants.Reg << ", space = " << Constants.Space
135 << ", visibility = " << Constants.Visibility << ")";
136
137 return OS;
138}
139
141 OS << "DescriptorTable(numClauses = " << Table.NumClauses
142 << ", visibility = " << Table.Visibility << ")";
143
144 return OS;
145}
146
148 OS << Clause.Type << "(" << Clause.Reg << ", numDescriptors = ";
149 if (Clause.NumDescriptors == NumDescriptorsUnbounded)
150 OS << "unbounded";
151 else
152 OS << Clause.NumDescriptors;
153 OS << ", space = " << Clause.Space << ", offset = ";
155 OS << "DescriptorTableOffsetAppend";
156 else
157 OS << Clause.Offset;
158 OS << ", flags = " << Clause.Flags << ")";
159
160 return OS;
161}
162
164 OS << "Root" << Descriptor.Type << "(" << Descriptor.Reg
165 << ", space = " << Descriptor.Space
166 << ", visibility = " << Descriptor.Visibility
167 << ", flags = " << Descriptor.Flags << ")";
168
169 return OS;
170}
171
173 OS << "StaticSampler(" << Sampler.Reg << ", filter = " << Sampler.Filter
174 << ", addressU = " << Sampler.AddressU
175 << ", addressV = " << Sampler.AddressV
176 << ", addressW = " << Sampler.AddressW
177 << ", mipLODBias = " << Sampler.MipLODBias
178 << ", maxAnisotropy = " << Sampler.MaxAnisotropy
179 << ", comparisonFunc = " << Sampler.CompFunc
180 << ", borderColor = " << Sampler.BorderColor
181 << ", minLOD = " << Sampler.MinLOD << ", maxLOD = " << Sampler.MaxLOD
182 << ", space = " << Sampler.Space << ", visibility = " << Sampler.Visibility
183 << ", flags = " << Sampler.Flags << ")";
184 return OS;
185}
186
187namespace {
188
189// We use the OverloadVisit with std::visit to ensure the compiler catches if a
190// new RootElement variant type is added but it's operator<< isn't handled.
191template <class... Ts> struct OverloadedVisit : Ts... {
192 using Ts::operator()...;
193};
194template <class... Ts> OverloadedVisit(Ts...) -> OverloadedVisit<Ts...>;
195
196} // namespace
197
199 const auto Visitor = OverloadedVisit{
200 [&OS](const dxbc::RootFlags &Flags) { OS << Flags; },
201 [&OS](const RootConstants &Constants) { OS << Constants; },
202 [&OS](const RootDescriptor &Descriptor) { OS << Descriptor; },
203 [&OS](const DescriptorTableClause &Clause) { OS << Clause; },
204 [&OS](const DescriptorTable &Table) { OS << Table; },
205 [&OS](const StaticSampler &Sampler) { OS << Sampler; },
206 };
207 std::visit(Visitor, Element);
208 return OS;
209}
210
212 OS << " RootElements" << interleaved(Elements, ", ", "{", "}");
213}
214
215} // namespace rootsig
216} // namespace hlsl
217} // namespace llvm
Register Reg
#define T
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
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.
Definition Types.h:26
InterleavedRange< Range > interleaved(const Range &R, StringRef Separator=", ", StringRef Prefix="", StringRef Suffix="")
Output range R as a sequence of interleaved elements.
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:202
constexpr std::underlying_type_t< Enum > to_underlying(Enum E)
Returns underlying integer value of an enum.
StringRef enumToStringRef(T Value, ArrayRef< EnumEntry< TEnum > > EnumValues)
Retrieves the Value's enum name.