36 return CI->getZExtValue();
43 return CI->getValueAPF().convertToFloat();
50 if (NodeText ==
nullptr)
55template <
typename T,
typename = std::enable_if_t<
57 std::is_same_v<std::underlying_type_t<T>,
uint32_t>>>
63 return static_cast<T>(*Val);
73template <
class... Ts>
struct OverloadedVisit : Ts... {
74 using Ts::operator()...;
76template <
class... Ts> OverloadedVisit(Ts...) -> OverloadedVisit<Ts...>;
81 const auto Visitor = OverloadedVisit{
83 return BuildRootFlags(Flags);
86 return BuildRootConstants(Constants);
89 return BuildRootDescriptor(Descriptor);
92 return BuildDescriptorTableClause(
Clause);
95 return BuildDescriptorTable(Table);
98 return BuildStaticSampler(Sampler);
103 MDNode *ElementMD = std::visit(Visitor, Element);
104 assert(ElementMD !=
nullptr &&
105 "Root Element must be initialized and validated");
106 GeneratedMetadata.push_back(ElementMD);
134MDNode *MetadataBuilder::BuildRootDescriptor(
const RootDescriptor &Descriptor) {
137 assert(!ResName.
empty() &&
"Provided an invalid Resource Class");
138 SmallString<7>
Name({
"Root", ResName});
151MDNode *MetadataBuilder::BuildDescriptorTable(
const DescriptorTable &Table) {
162 assert(Table.NumClauses <= GeneratedMetadata.size() &&
163 "Table expected all owned clauses to be generated already");
165 TableOperands.
append(GeneratedMetadata.end() - Table.NumClauses,
166 GeneratedMetadata.end());
168 GeneratedMetadata.pop_back_n(Table.NumClauses);
173MDNode *MetadataBuilder::BuildDescriptorTableClause(
177 assert(!ResName.
empty() &&
"Provided an invalid Resource Class");
189MDNode *MetadataBuilder::BuildStaticSampler(
const StaticSampler &Sampler) {
219Error MetadataParser::parseRootFlags(mcdxbc::RootSignatureDesc &RSD,
220 MDNode *RootFlagNode) {
232Error MetadataParser::parseRootConstants(mcdxbc::RootSignatureDesc &RSD,
233 MDNode *RootConstantNode) {
237 Expected<dxbc::ShaderVisibility> Visibility =
242 return Error(std::move(
E));
261 *Visibility, Constants);
266Error MetadataParser::parseRootDescriptors(
267 mcdxbc::RootSignatureDesc &RSD, MDNode *RootDescriptorNode,
272 "parseRootDescriptors should only be called with RootDescriptor "
278 switch (ElementKind) {
280 Type = dxbc::RootParameterType::SRV;
283 Type = dxbc::RootParameterType::UAV;
286 Type = dxbc::RootParameterType::CBV;
293 Expected<dxbc::ShaderVisibility> Visibility =
298 return Error(std::move(
E));
300 mcdxbc::RootDescriptor Descriptor;
318 Descriptor.
Flags = *Val;
326Error MetadataParser::parseDescriptorRange(mcdxbc::DescriptorTable &Table,
327 MDNode *RangeDescriptorNode) {
331 mcdxbc::DescriptorRange
Range;
333 std::optional<StringRef> ElementText =
336 if (!ElementText.has_value())
339 if (*ElementText ==
"CBV")
341 else if (*ElementText ==
"SRV")
343 else if (*ElementText ==
"UAV")
345 else if (*ElementText ==
"Sampler")
349 RangeDescriptorNode);
352 Range.NumDescriptors = *Val;
355 RangeDescriptorNode);
358 Range.BaseShaderRegister = *Val;
363 Range.RegisterSpace = *Val;
368 Range.OffsetInDescriptorsFromTableStart = *Val;
371 "OffsetInDescriptorsFromTableStart");
382Error MetadataParser::parseDescriptorTable(mcdxbc::RootSignatureDesc &RSD,
383 MDNode *DescriptorTableNode) {
384 const unsigned int NumOperands = DescriptorTableNode->
getNumOperands();
388 Expected<dxbc::ShaderVisibility> Visibility =
393 return Error(std::move(
E));
395 mcdxbc::DescriptorTable Table;
397 for (
unsigned int I = 2;
I < NumOperands;
I++) {
399 if (Element ==
nullptr)
401 "Missing Root Element Metadata Node.", DescriptorTableNode);
403 if (
auto Err = parseDescriptorRange(Table, Element))
412Error MetadataParser::parseStaticSampler(mcdxbc::RootSignatureDesc &RSD,
413 MDNode *StaticSamplerNode) {
421 if (
auto E =
Filter.takeError())
422 return Error(std::move(
E));
425 Expected<dxbc::TextureAddressMode> AddressU =
429 return Error(std::move(
E));
432 Expected<dxbc::TextureAddressMode> AddressV =
436 return Error(std::move(
E));
439 Expected<dxbc::TextureAddressMode> AddressW =
443 return Error(std::move(
E));
460 return Error(std::move(
E));
463 Expected<dxbc::StaticBorderColor> BorderColor =
467 return Error(std::move(
E));
468 Sampler.BorderColor = *BorderColor;
490 Expected<dxbc::ShaderVisibility> Visibility =
495 return Error(std::move(
E));
496 Sampler.ShaderVisibility = *Visibility;
502Error MetadataParser::parseRootSignatureElement(mcdxbc::RootSignatureDesc &RSD,
505 if (!ElementText.has_value())
509 StringSwitch<RootSignatureElementKind>(*ElementText)
519 switch (ElementKind) {
522 return parseRootFlags(RSD, Element);
524 return parseRootConstants(RSD, Element);
528 return parseRootDescriptors(RSD, Element, ElementKind);
530 return parseDescriptorTable(RSD, Element);
532 return parseStaticSampler(RSD, Element);
541Error MetadataParser::validateRootSignature(
542 const mcdxbc::RootSignatureDesc &RSD) {
547 make_error<RootSignatureValidationError<uint32_t>>(
554 make_error<RootSignatureValidationError<uint32_t>>(
555 "RootFlags", RSD.
Flags));
561 case dxbc::RootParameterType::Constants32Bit:
564 case dxbc::RootParameterType::CBV:
565 case dxbc::RootParameterType::UAV:
566 case dxbc::RootParameterType::SRV: {
567 const mcdxbc::RootDescriptor &Descriptor =
572 make_error<RootSignatureValidationError<uint32_t>>(
578 make_error<RootSignatureValidationError<uint32_t>>(
586 make_error<RootSignatureValidationError<uint32_t>>(
587 "RootDescriptorFlag", Descriptor.
Flags));
591 case dxbc::RootParameterType::DescriptorTable: {
592 const mcdxbc::DescriptorTable &Table =
594 for (
const mcdxbc::DescriptorRange &
Range : Table) {
598 make_error<RootSignatureValidationError<uint32_t>>(
599 "RegisterSpace",
Range.RegisterSpace));
604 make_error<RootSignatureValidationError<uint32_t>>(
605 "NumDescriptors",
Range.NumDescriptors));
612 make_error<RootSignatureValidationError<uint32_t>>(
613 "DescriptorFlag",
Range.Flags));
623 DeferredErrs =
joinErrors(std::move(DeferredErrs),
624 make_error<RootSignatureValidationError<float>>(
625 "MipLODBias",
Sampler.MipLODBias));
630 make_error<RootSignatureValidationError<uint32_t>>(
631 "MaxAnisotropy",
Sampler.MaxAnisotropy));
634 DeferredErrs =
joinErrors(std::move(DeferredErrs),
635 make_error<RootSignatureValidationError<float>>(
639 DeferredErrs =
joinErrors(std::move(DeferredErrs),
640 make_error<RootSignatureValidationError<float>>(
646 make_error<RootSignatureValidationError<uint32_t>>(
647 "ShaderRegister",
Sampler.ShaderRegister));
652 make_error<RootSignatureValidationError<uint32_t>>(
653 "RegisterSpace",
Sampler.RegisterSpace));
659Expected<mcdxbc::RootSignatureDesc>
664 for (
const auto &Operand : Root->operands()) {
666 if (Element ==
nullptr)
669 "Missing Root Element Metadata Node.",
nullptr));
671 if (
auto Err = parseRootSignatureElement(RSD, Element))
672 DeferredErrs =
joinErrors(std::move(DeferredErrs), std::move(Err));
675 if (
auto Err = validateRootSignature(RSD))
676 DeferredErrs =
joinErrors(std::move(DeferredErrs), std::move(Err));
679 return std::move(DeferredErrs);
681 return std::move(RSD);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Analysis containing CSE Info
mir Rename Register Operands
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
Error takeError()
Take ownership of the stored error.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
const MDOperand & getOperand(unsigned I) const
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
unsigned getNumOperands() const
Return number of MDNode operands.
LLVM_ABI StringRef getString() const
static LLVM_ABI MDString * get(LLVMContext &Context, StringRef Str)
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
void push_back(const T &Elt)
StringRef - Represent a constant reference to a string, i.e.
constexpr bool empty() const
empty - Check if the string is empty.
static LLVM_ABI Type * getFloatTy(LLVMContext &C)
An efficient, type-erasing, non-owning reference to a callable.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
bool isValidShaderVisibility(uint32_t V)
bool isValidSamplerFilter(uint32_t V)
bool isValidBorderColor(uint32_t V)
bool isValidComparisonFunc(uint32_t V)
bool isValidAddress(uint32_t V)
LLVM_ABI StringRef getResourceClassName(ResourceClass RC)
static std::optional< uint32_t > extractMdIntValue(MDNode *Node, unsigned int OpId)
LLVM_ABI bool verifyRootDescriptorFlag(uint32_t Version, uint32_t FlagsVal)
LLVM_ABI bool verifyRegisterSpace(uint32_t RegisterSpace)
LLVM_ABI bool verifyDescriptorRangeFlag(uint32_t Version, dxil::ResourceClass Type, dxbc::DescriptorRangeFlags FlagsVal)
LLVM_ABI bool verifyVersion(uint32_t Version)
static std::optional< StringRef > extractMdStringValue(MDNode *Node, unsigned int OpId)
LLVM_ABI bool verifyRootFlag(uint32_t Flags)
LLVM_ABI bool verifyLOD(float LOD)
Expected< T > extractEnumValue(MDNode *Node, unsigned int OpId, StringRef ErrText, llvm::function_ref< bool(uint32_t)> VerifyFn)
std::variant< dxbc::RootFlags, RootConstants, RootDescriptor, DescriptorTable, DescriptorTableClause, StaticSampler > RootElement
Models RootElement : RootFlags | RootConstants | RootParam | DescriptorTable | DescriptorTableClause ...
LLVM_ABI bool verifyMipLODBias(float MipLODBias)
LLVM_ABI bool verifyNumDescriptors(uint32_t NumDescriptors)
LLVM_ABI bool verifyMaxAnisotropy(uint32_t MaxAnisotropy)
LLVM_ABI bool verifyRegisterValue(uint32_t RegisterValue)
static std::optional< float > extractMdFloatValue(MDNode *Node, unsigned int OpId)
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > dyn_extract(Y &&MD)
Extract a Value from Metadata, if any.
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
FunctionAddr VTableAddr uintptr_t uintptr_t Version
Error joinErrors(Error E1, Error E2)
Concatenate errors.
constexpr std::underlying_type_t< Enum > to_underlying(Enum E)
Returns underlying integer value of an enum.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
IRBuilder(LLVMContext &, FolderTy, InserterTy, MDNode *, ArrayRef< OperandBundleDef >) -> IRBuilder< FolderTy, InserterTy >
SmallVector< DescriptorRange > Ranges
const RootDescriptor & getRootDescriptor(size_t Index) const
const DescriptorTable & getDescriptorTable(size_t Index) const
void addParameter(dxbc::RootParameterType Type, dxbc::ShaderVisibility Visibility, RootConstants Constant)
SmallVector< StaticSampler > StaticSamplers
mcdxbc::RootParametersContainer ParametersContainer