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 GenericRSMetadataError : public ErrorInfo<GenericRSMetadataError> {
52public:
53 LLVM_ABI static char ID;
56
58 : Message(Message), MD(MD) {}
59
60 void log(raw_ostream &OS) const override {
61 OS << Message;
62 if (MD) {
63 OS << "\n";
64 MD->printTree(OS);
65 }
66 }
67
68 std::error_code convertToErrorCode() const override {
70 }
71};
72
73class InvalidRSMetadataFormat : public ErrorInfo<InvalidRSMetadataFormat> {
74public:
75 LLVM_ABI static char ID;
77
79
80 void log(raw_ostream &OS) const override {
81 OS << "Invalid format for " << ElementName;
82 }
83
84 std::error_code convertToErrorCode() const override {
86 }
87};
88
89class InvalidRSMetadataValue : public ErrorInfo<InvalidRSMetadataValue> {
90public:
91 LLVM_ABI static char ID;
93
95
96 void log(raw_ostream &OS) const override {
97 OS << "Invalid value for " << ParamName;
98 }
99
100 std::error_code convertToErrorCode() const override {
102 }
103};
104
106public:
108 : Ctx(Ctx), Elements(Elements) {}
109
110 /// Iterates through elements and dispatches onto the correct Build* method
111 ///
112 /// Accumulates the root signature and returns the Metadata node that is just
113 /// a list of all the elements
115
116private:
117 /// Define the various builders for the different metadata types
118 MDNode *BuildRootFlags(const dxbc::RootFlags &Flags);
119 MDNode *BuildRootConstants(const RootConstants &Constants);
120 MDNode *BuildRootDescriptor(const RootDescriptor &Descriptor);
121 MDNode *BuildDescriptorTable(const DescriptorTable &Table);
122 MDNode *BuildDescriptorTableClause(const DescriptorTableClause &Clause);
123 MDNode *BuildStaticSampler(const StaticSampler &Sampler);
124
126 ArrayRef<RootElement> Elements;
127 SmallVector<Metadata *> GeneratedMetadata;
128};
129
131 Error = 0,
132 RootFlags = 1,
133 RootConstants = 2,
134 SRV = 3,
135 UAV = 4,
136 CBV = 5,
137 DescriptorTable = 6,
139};
140
142public:
143 MetadataParser(MDNode *Root) : Root(Root) {}
144
147
148private:
149 llvm::Error parseRootFlags(mcdxbc::RootSignatureDesc &RSD,
150 MDNode *RootFlagNode);
151 llvm::Error parseRootConstants(mcdxbc::RootSignatureDesc &RSD,
152 MDNode *RootConstantNode);
153 llvm::Error parseRootDescriptors(mcdxbc::RootSignatureDesc &RSD,
154 MDNode *RootDescriptorNode,
155 RootSignatureElementKind ElementKind);
156 llvm::Error parseDescriptorRange(mcdxbc::DescriptorTable &Table,
157 MDNode *RangeDescriptorNode);
158 llvm::Error parseDescriptorTable(mcdxbc::RootSignatureDesc &RSD,
159 MDNode *DescriptorTableNode);
160 llvm::Error parseRootSignatureElement(mcdxbc::RootSignatureDesc &RSD,
161 MDNode *Element);
162 llvm::Error parseStaticSampler(mcdxbc::RootSignatureDesc &RSD,
163 MDNode *StaticSamplerNode);
164
165 llvm::Error validateRootSignature(const llvm::mcdxbc::RootSignatureDesc &RSD);
166
167 MDNode *Root;
168};
169
170} // namespace rootsig
171} // namespace hlsl
172} // namespace llvm
173
174#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...
dxil translate DXIL Translate Metadata
raw_pwrite_stream & OS
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:1077
LLVM_ABI void printTree(raw_ostream &OS, const Module *M=nullptr) const
Print in tree shape.
Definition: AsmWriter.cpp:5432
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1197
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
LLVM Value Representation.
Definition: Value.h:75
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)
RootSignatureValidationError(StringRef ParamName, T Value)
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.
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.
Definition: AddressRanges.h:18
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