-
Notifications
You must be signed in to change notification settings - Fork 14.7k
[DirectX] Moving Root Signature Metadata Parsing in to Shared Root Signature Metadata lib #149221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,8 @@ | |
#define LLVM_FRONTEND_HLSL_ROOTSIGNATUREMETADATA_H | ||
|
||
#include "llvm/Frontend/HLSL/HLSLRootSignature.h" | ||
#include "llvm/IR/Constants.h" | ||
#include "llvm/MC/DXContainerRootSignature.h" | ||
|
||
namespace llvm { | ||
class LLVMContext; | ||
|
@@ -24,6 +26,96 @@ class Metadata; | |
namespace hlsl { | ||
namespace rootsig { | ||
|
||
inline std::optional<uint32_t> extractMdIntValue(MDNode *Node, | ||
unsigned int OpId) { | ||
if (auto *CI = | ||
mdconst::dyn_extract<ConstantInt>(Node->getOperand(OpId).get())) | ||
return CI->getZExtValue(); | ||
return std::nullopt; | ||
} | ||
|
||
inline std::optional<float> extractMdFloatValue(MDNode *Node, | ||
unsigned int OpId) { | ||
if (auto *CI = mdconst::dyn_extract<ConstantFP>(Node->getOperand(OpId).get())) | ||
return CI->getValueAPF().convertToFloat(); | ||
return std::nullopt; | ||
} | ||
|
||
inline std::optional<StringRef> extractMdStringValue(MDNode *Node, | ||
unsigned int OpId) { | ||
MDString *NodeText = dyn_cast<MDString>(Node->getOperand(OpId)); | ||
if (NodeText == nullptr) | ||
return std::nullopt; | ||
return NodeText->getString(); | ||
} | ||
|
||
template <typename T> | ||
class RootSignatureValidationError | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This all seems like new code? It might be a little easier to review if we have just an NFC code move and then a separate change to error handling |
||
: 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) | ||
|
@@ -49,6 +141,47 @@ class MetadataBuilder { | |
SmallVector<Metadata *> GeneratedMetadata; | ||
}; | ||
|
||
enum class RootSignatureElementKind { | ||
Error = 0, | ||
RootFlags = 1, | ||
RootConstants = 2, | ||
SRV = 3, | ||
UAV = 4, | ||
CBV = 5, | ||
DescriptorTable = 6, | ||
StaticSamplers = 7 | ||
}; | ||
|
||
class MetadataParser { | ||
public: | ||
MetadataParser(MDNode *Root) : Root(Root) {} | ||
|
||
/// Iterates through root signature and converts them into MapT | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Can we specify what MapT is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, this was a previous version, that I tried during development. |
||
LLVM_ABI llvm::Expected<llvm::mcdxbc::RootSignatureDesc> | ||
ParseRootSignature(uint32_t Version); | ||
|
||
private: | ||
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; | ||
}; | ||
|
||
} // namespace rootsig | ||
} // namespace hlsl | ||
} // namespace llvm | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there anything to prevent this from being static functions in the
.cpp
file?I don't think we want to expose this api.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is used to extract some metadata in
DXILRootSignature