LLVM 22.0.0git
RootSignatureMetadata.h
Go to the documentation of this file.
1//===- RootSignatureMetadata.h - 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 a library for working with HLSL Root Signatures and
10/// their metadata representation.
11///
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_FRONTEND_HLSL_ROOTSIGNATUREMETADATA_H
15#define LLVM_FRONTEND_HLSL_ROOTSIGNATUREMETADATA_H
16
17#include "llvm/ADT/StringRef.h"
19#include "llvm/IR/Constants.h"
22
23namespace llvm {
24class LLVMContext;
25class MDNode;
26class Metadata;
27
28namespace hlsl {
29namespace rootsig {
30
31template <typename T>
33 : public ErrorInfo<RootSignatureValidationError<T>> {
34public:
35 static char ID;
38
41
42 void log(raw_ostream &OS) const override {
43 OS << "Invalid value for " << ParamName << ": " << Value;
44 }
45
46 std::error_code convertToErrorCode() const override {
48 }
49};
50
51class OffsetAppendAfterOverflow : public ErrorInfo<OffsetAppendAfterOverflow> {
52public:
53 static char ID;
57
61
62 void log(raw_ostream &OS) const override {
63 OS << "Range " << getResourceClassName(Type) << "(register=" << Register
64 << ", space=" << Space << ") "
65 << "cannot be appended after an unbounded range ";
66 }
67
68 std::error_code convertToErrorCode() const override {
70 }
71};
72
74 : public ErrorInfo<ShaderRegisterOverflowError> {
75public:
76 static char ID;
80
84
85 void log(raw_ostream &OS) const override {
86 OS << "Overflow for shader register range: " << getResourceClassName(Type)
87 << "(register=" << Register << ", space=" << Space << ").";
88 }
89
90 std::error_code convertToErrorCode() const override {
92 }
93};
94
95class OffsetOverflowError : public ErrorInfo<OffsetOverflowError> {
96public:
97 static char ID;
101
105
106 void log(raw_ostream &OS) const override {
107 OS << "Offset overflow for descriptor range: " << getResourceClassName(Type)
108 << "(register=" << Register << ", space=" << Space << ").";
109 }
110
111 std::error_code convertToErrorCode() const override {
113 }
114};
115
116class TableSamplerMixinError : public ErrorInfo<TableSamplerMixinError> {
117public:
118 static char ID;
121
124
125 void log(raw_ostream &OS) const override {
126 OS << "Samplers cannot be mixed with other "
127 << "resource types in a descriptor table, " << getResourceClassName(Type)
128 << "(location=" << Location << ")";
129 }
130
131 std::error_code convertToErrorCode() const override {
133 }
134};
135
136class GenericRSMetadataError : public ErrorInfo<GenericRSMetadataError> {
137public:
138 LLVM_ABI static char ID;
141
144
145 void log(raw_ostream &OS) const override {
146 OS << Message;
147 if (MD) {
148 OS << "\n";
149 MD->printTree(OS);
150 }
151 }
152
153 std::error_code convertToErrorCode() const override {
155 }
156};
157
158class InvalidRSMetadataFormat : public ErrorInfo<InvalidRSMetadataFormat> {
159public:
160 LLVM_ABI static char ID;
162
164
165 void log(raw_ostream &OS) const override {
166 OS << "Invalid format for " << ElementName;
167 }
168
169 std::error_code convertToErrorCode() const override {
171 }
172};
173
174class InvalidRSMetadataValue : public ErrorInfo<InvalidRSMetadataValue> {
175public:
176 LLVM_ABI static char ID;
178
180
181 void log(raw_ostream &OS) const override {
182 OS << "Invalid value for " << ParamName;
183 }
184
185 std::error_code convertToErrorCode() const override {
187 }
188};
189
191public:
193 : Ctx(Ctx), Elements(Elements) {}
194
195 /// Iterates through elements and dispatches onto the correct Build* method
196 ///
197 /// Accumulates the root signature and returns the Metadata node that is just
198 /// a list of all the elements
200
201private:
202 /// Define the various builders for the different metadata types
203 MDNode *BuildRootFlags(const dxbc::RootFlags &Flags);
204 MDNode *BuildRootConstants(const RootConstants &Constants);
205 MDNode *BuildRootDescriptor(const RootDescriptor &Descriptor);
206 MDNode *BuildDescriptorTable(const DescriptorTable &Table);
207 MDNode *BuildDescriptorTableClause(const DescriptorTableClause &Clause);
208 MDNode *BuildStaticSampler(const StaticSampler &Sampler);
209
211 ArrayRef<RootElement> Elements;
212 SmallVector<Metadata *> GeneratedMetadata;
213};
214
225
227public:
228 MetadataParser(MDNode *Root) : Root(Root) {}
229
232
233private:
234 llvm::Error parseRootFlags(mcdxbc::RootSignatureDesc &RSD,
235 MDNode *RootFlagNode);
236 llvm::Error parseRootConstants(mcdxbc::RootSignatureDesc &RSD,
237 MDNode *RootConstantNode);
238 llvm::Error parseRootDescriptors(mcdxbc::RootSignatureDesc &RSD,
239 MDNode *RootDescriptorNode,
240 RootSignatureElementKind ElementKind);
241 llvm::Error parseDescriptorRange(mcdxbc::DescriptorTable &Table,
242 MDNode *RangeDescriptorNode);
243 llvm::Error parseDescriptorTable(mcdxbc::RootSignatureDesc &RSD,
244 MDNode *DescriptorTableNode);
245 llvm::Error parseRootSignatureElement(mcdxbc::RootSignatureDesc &RSD,
246 MDNode *Element);
247 llvm::Error parseStaticSampler(mcdxbc::RootSignatureDesc &RSD,
248 MDNode *StaticSamplerNode);
249
251
252 MDNode *Root;
253};
254
255} // namespace rootsig
256} // namespace hlsl
257} // namespace llvm
258
259#endif // LLVM_FRONTEND_HLSL_ROOTSIGNATUREMETADATA_H
#define LLVM_ABI
Definition Compiler.h:213
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static void validateRootSignature(Module &M, const mcdxbc::RootSignatureDesc &RSD, dxil::ModuleMetadataInfo &MMI, DXILResourceMap &DRM, DXILResourceTypeMap &DRTM)
#define T
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:41
Base class for user error types.
Definition Error.h:354
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
Tagged union holding either a T or a Error.
Definition Error.h:485
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:68
Metadata node.
Definition Metadata.h:1078
Root of the metadata hierarchy.
Definition Metadata.h:64
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
GenericRSMetadataError(StringRef Message, MDNode *MD)
void log(raw_ostream &OS) const override
Print an error message to an output stream.
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
void log(raw_ostream &OS) const override
Print an error message to an output stream.
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
void log(raw_ostream &OS) const override
Print an error message to an output stream.
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
LLVM_ABI MDNode * BuildRootSignature()
Iterates through elements and dispatches onto the correct Build* method.
MetadataBuilder(llvm::LLVMContext &Ctx, ArrayRef< RootElement > Elements)
LLVM_ABI llvm::Expected< llvm::mcdxbc::RootSignatureDesc > ParseRootSignature(uint32_t Version)
void log(raw_ostream &OS) const override
Print an error message to an output stream.
OffsetAppendAfterOverflow(dxil::ResourceClass Type, uint32_t Register, uint32_t Space)
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
OffsetOverflowError(dxil::ResourceClass Type, uint32_t Register, uint32_t Space)
void log(raw_ostream &OS) const override
Print an error message to an output stream.
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
void log(raw_ostream &OS) const override
Print an error message to an output stream.
void log(raw_ostream &OS) const override
Print an error message to an output stream.
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
ShaderRegisterOverflowError(dxil::ResourceClass Type, uint32_t Register, uint32_t Space)
void log(raw_ostream &OS) const override
Print an error message to an output stream.
TableSamplerMixinError(dxil::ResourceClass Type, uint32_t Location)
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition Error.cpp:98
FunctionAddr VTableAddr uintptr_t uintptr_t Version
Definition InstrProf.h:302