Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 88 additions & 21 deletions llvm/include/llvm/Frontend/HLSL/RootSignatureMetadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include "llvm/Frontend/HLSL/HLSLRootSignature.h"
#include "llvm/IR/Constants.h"
#include "llvm/MC/DXContainerRootSignature.h"
#include "llvm/IR/Constants.h"
#include "llvm/MC/DXContainerRootSignature.h"

namespace llvm {
class LLVMContext;
Expand All @@ -26,6 +28,73 @@ class Metadata;
namespace hlsl {
namespace rootsig {

template <typename T>
class RootSignatureValidationError
: public ErrorInfo<RootSignatureValidationError<T>> {
public:
static char ID;
std::string ParamName;
T Value;

RootSignatureValidationError(StringRef ParamName, T Value)
: ParamName(ParamName.str()), Value(Value) {}

void log(raw_ostream &OS) const override {
OS << "Invalid value for " << ParamName << ": " << Value;
}

std::error_code convertToErrorCode() const override {
return llvm::inconvertibleErrorCode();
}
};

class GenericRSMetadataError : public ErrorInfo<GenericRSMetadataError> {
public:
static char ID;
std::string Message;

GenericRSMetadataError(Twine Message) : Message(Message.str()) {}

void log(raw_ostream &OS) const override { OS << Message; }

std::error_code convertToErrorCode() const override {
return llvm::inconvertibleErrorCode();
}
};

class InvalidRSMetadataFormat : public ErrorInfo<InvalidRSMetadataFormat> {
public:
static char ID;
std::string ElementName;

InvalidRSMetadataFormat(StringRef ElementName)
: ElementName(ElementName.str()) {}

void log(raw_ostream &OS) const override {
OS << "Invalid format for " << ElementName;
}

std::error_code convertToErrorCode() const override {
return llvm::inconvertibleErrorCode();
}
};

class InvalidRSMetadataValue : public ErrorInfo<InvalidRSMetadataValue> {
public:
static char ID;
std::string ParamName;

InvalidRSMetadataValue(StringRef ParamName) : ParamName(ParamName.str()) {}

void log(raw_ostream &OS) const override {
OS << "Invalid value for " << ParamName;
}

std::error_code convertToErrorCode() const override {
return llvm::inconvertibleErrorCode();
}
};

class MetadataBuilder {
public:
MetadataBuilder(llvm::LLVMContext &Ctx, ArrayRef<RootElement> Elements)
Expand Down Expand Up @@ -66,29 +135,27 @@ class MetadataParser {
public:
MetadataParser(MDNode *Root) : Root(Root) {}

LLVM_ABI bool ParseRootSignature(LLVMContext *Ctx,
mcdxbc::RootSignatureDesc &RSD);
LLVM_ABI llvm::Expected<llvm::mcdxbc::RootSignatureDesc>
ParseRootSignature(uint32_t Version);

private:
bool parseRootFlags(LLVMContext *Ctx, mcdxbc::RootSignatureDesc &RSD,
MDNode *RootFlagNode);
bool parseRootConstants(LLVMContext *Ctx, mcdxbc::RootSignatureDesc &RSD,
MDNode *RootConstantNode);
bool parseRootDescriptors(LLVMContext *Ctx, mcdxbc::RootSignatureDesc &RSD,
MDNode *RootDescriptorNode,
RootSignatureElementKind ElementKind);
bool parseDescriptorRange(LLVMContext *Ctx, mcdxbc::DescriptorTable &Table,
MDNode *RangeDescriptorNode);
bool parseDescriptorTable(LLVMContext *Ctx, mcdxbc::RootSignatureDesc &RSD,
MDNode *DescriptorTableNode);
bool parseRootSignatureElement(LLVMContext *Ctx,
mcdxbc::RootSignatureDesc &RSD,
MDNode *Element);
bool parseStaticSampler(LLVMContext *Ctx, mcdxbc::RootSignatureDesc &RSD,
MDNode *StaticSamplerNode);

bool validateRootSignature(LLVMContext *Ctx,
const llvm::mcdxbc::RootSignatureDesc &RSD);
llvm::Error parseRootFlags(mcdxbc::RootSignatureDesc &RSD,
MDNode *RootFlagNode);
llvm::Error parseRootConstants(mcdxbc::RootSignatureDesc &RSD,
MDNode *RootConstantNode);
llvm::Error parseRootDescriptors(mcdxbc::RootSignatureDesc &RSD,
MDNode *RootDescriptorNode,
RootSignatureElementKind ElementKind);
llvm::Error parseDescriptorRange(mcdxbc::DescriptorTable &Table,
MDNode *RangeDescriptorNode);
llvm::Error parseDescriptorTable(mcdxbc::RootSignatureDesc &RSD,
MDNode *DescriptorTableNode);
llvm::Error parseRootSignatureElement(mcdxbc::RootSignatureDesc &RSD,
MDNode *Element);
llvm::Error parseStaticSampler(mcdxbc::RootSignatureDesc &RSD,
MDNode *StaticSamplerNode);

llvm::Error validateRootSignature(const llvm::mcdxbc::RootSignatureDesc &RSD);

MDNode *Root;
};
Expand Down
Loading
Loading