36 return CI->getZExtValue();
43 return CI->getValueAPF().convertToFloat();
50 if (NodeText ==
nullptr)
60 "ShaderVisibility", *Val);
71template <
class... Ts>
struct OverloadedVisit : Ts... {
72 using Ts::operator()...;
74template <
class... Ts> OverloadedVisit(Ts...) -> OverloadedVisit<Ts...>;
79 const auto Visitor = OverloadedVisit{
81 return BuildRootFlags(Flags);
84 return BuildRootConstants(Constants);
87 return BuildRootDescriptor(Descriptor);
90 return BuildDescriptorTableClause(
Clause);
93 return BuildDescriptorTable(Table);
96 return BuildStaticSampler(Sampler);
101 MDNode *ElementMD = std::visit(Visitor, Element);
102 assert(ElementMD !=
nullptr &&
103 "Root Element must be initialized and validated");
104 GeneratedMetadata.push_back(ElementMD);
132MDNode *MetadataBuilder::BuildRootDescriptor(
const RootDescriptor &Descriptor) {
135 assert(!ResName.
empty() &&
"Provided an invalid Resource Class");
136 SmallString<7>
Name({
"Root", ResName});
149MDNode *MetadataBuilder::BuildDescriptorTable(
const DescriptorTable &Table) {
160 assert(Table.NumClauses <= GeneratedMetadata.size() &&
161 "Table expected all owned clauses to be generated already");
163 TableOperands.
append(GeneratedMetadata.end() - Table.NumClauses,
164 GeneratedMetadata.end());
166 GeneratedMetadata.pop_back_n(Table.NumClauses);
171MDNode *MetadataBuilder::BuildDescriptorTableClause(
175 assert(!ResName.
empty() &&
"Provided an invalid Resource Class");
187MDNode *MetadataBuilder::BuildStaticSampler(
const StaticSampler &Sampler) {
217Error MetadataParser::parseRootFlags(mcdxbc::RootSignatureDesc &RSD,
218 MDNode *RootFlagNode) {
230Error MetadataParser::parseRootConstants(mcdxbc::RootSignatureDesc &RSD,
231 MDNode *RootConstantNode) {
235 Expected<dxbc::ShaderVisibility> Visibility =
238 return Error(std::move(
E));
257 *Visibility, Constants);
262Error MetadataParser::parseRootDescriptors(
263 mcdxbc::RootSignatureDesc &RSD, MDNode *RootDescriptorNode,
268 "parseRootDescriptors should only be called with RootDescriptor "
274 switch (ElementKind) {
276 Type = dxbc::RootParameterType::SRV;
279 Type = dxbc::RootParameterType::UAV;
282 Type = dxbc::RootParameterType::CBV;
289 Expected<dxbc::ShaderVisibility> Visibility =
292 return Error(std::move(
E));
294 mcdxbc::RootDescriptor Descriptor;
312 Descriptor.
Flags = *Val;
320Error MetadataParser::parseDescriptorRange(mcdxbc::DescriptorTable &Table,
321 MDNode *RangeDescriptorNode) {
325 dxbc::RTS0::v2::DescriptorRange
Range;
327 std::optional<StringRef> ElementText =
330 if (!ElementText.has_value())
334 StringSwitch<uint32_t>(*ElementText)
338 .Case(
"Sampler",
to_underlying(dxbc::DescriptorRangeType::Sampler))
341 if (
Range.RangeType == ~0U)
343 RangeDescriptorNode);
346 Range.NumDescriptors = *Val;
349 RangeDescriptorNode);
352 Range.BaseShaderRegister = *Val;
357 Range.RegisterSpace = *Val;
362 Range.OffsetInDescriptorsFromTableStart = *Val;
365 "OffsetInDescriptorsFromTableStart");
376Error MetadataParser::parseDescriptorTable(mcdxbc::RootSignatureDesc &RSD,
377 MDNode *DescriptorTableNode) {
378 const unsigned int NumOperands = DescriptorTableNode->
getNumOperands();
382 Expected<dxbc::ShaderVisibility> Visibility =
385 return Error(std::move(
E));
387 mcdxbc::DescriptorTable Table;
389 for (
unsigned int I = 2;
I < NumOperands;
I++) {
391 if (Element ==
nullptr)
393 "Missing Root Element Metadata Node.", DescriptorTableNode);
395 if (
auto Err = parseDescriptorRange(Table, Element))
404Error MetadataParser::parseStaticSampler(mcdxbc::RootSignatureDesc &RSD,
405 MDNode *StaticSamplerNode) {
409 dxbc::RTS0::v1::StaticSampler
Sampler;
471 Sampler.ShaderVisibility = *Val;
479Error MetadataParser::parseRootSignatureElement(mcdxbc::RootSignatureDesc &RSD,
482 if (!ElementText.has_value())
486 StringSwitch<RootSignatureElementKind>(*ElementText)
496 switch (ElementKind) {
499 return parseRootFlags(RSD, Element);
501 return parseRootConstants(RSD, Element);
505 return parseRootDescriptors(RSD, Element, ElementKind);
507 return parseDescriptorTable(RSD, Element);
509 return parseStaticSampler(RSD, Element);
518Error MetadataParser::validateRootSignature(
519 const mcdxbc::RootSignatureDesc &RSD) {
524 make_error<RootSignatureValidationError<uint32_t>>(
531 make_error<RootSignatureValidationError<uint32_t>>(
532 "RootFlags", RSD.
Flags));
538 case dxbc::RootParameterType::Constants32Bit:
541 case dxbc::RootParameterType::CBV:
542 case dxbc::RootParameterType::UAV:
543 case dxbc::RootParameterType::SRV: {
544 const mcdxbc::RootDescriptor &Descriptor =
549 make_error<RootSignatureValidationError<uint32_t>>(
555 make_error<RootSignatureValidationError<uint32_t>>(
563 make_error<RootSignatureValidationError<uint32_t>>(
564 "RootDescriptorFlag", Descriptor.
Flags));
568 case dxbc::RootParameterType::DescriptorTable: {
569 const mcdxbc::DescriptorTable &Table =
571 for (
const dxbc::RTS0::v2::DescriptorRange &
Range : Table) {
575 make_error<RootSignatureValidationError<uint32_t>>(
576 "RangeType",
Range.RangeType));
581 make_error<RootSignatureValidationError<uint32_t>>(
582 "RegisterSpace",
Range.RegisterSpace));
587 make_error<RootSignatureValidationError<uint32_t>>(
588 "NumDescriptors",
Range.NumDescriptors));
594 make_error<RootSignatureValidationError<uint32_t>>(
595 "DescriptorFlag",
Range.Flags));
602 for (
const dxbc::RTS0::v1::StaticSampler &Sampler : RSD.
StaticSamplers) {
606 make_error<RootSignatureValidationError<uint32_t>>(
612 make_error<RootSignatureValidationError<uint32_t>>(
613 "AddressU",
Sampler.AddressU));
618 make_error<RootSignatureValidationError<uint32_t>>(
619 "AddressV",
Sampler.AddressV));
624 make_error<RootSignatureValidationError<uint32_t>>(
625 "AddressW",
Sampler.AddressW));
628 DeferredErrs =
joinErrors(std::move(DeferredErrs),
629 make_error<RootSignatureValidationError<float>>(
630 "MipLODBias",
Sampler.MipLODBias));
635 make_error<RootSignatureValidationError<uint32_t>>(
636 "MaxAnisotropy",
Sampler.MaxAnisotropy));
641 make_error<RootSignatureValidationError<uint32_t>>(
642 "ComparisonFunc",
Sampler.ComparisonFunc));
647 make_error<RootSignatureValidationError<uint32_t>>(
648 "BorderColor",
Sampler.BorderColor));
651 DeferredErrs =
joinErrors(std::move(DeferredErrs),
652 make_error<RootSignatureValidationError<float>>(
656 DeferredErrs =
joinErrors(std::move(DeferredErrs),
657 make_error<RootSignatureValidationError<float>>(
663 make_error<RootSignatureValidationError<uint32_t>>(
664 "ShaderRegister",
Sampler.ShaderRegister));
669 make_error<RootSignatureValidationError<uint32_t>>(
670 "RegisterSpace",
Sampler.RegisterSpace));
675 make_error<RootSignatureValidationError<uint32_t>>(
676 "ShaderVisibility",
Sampler.ShaderVisibility));
682Expected<mcdxbc::RootSignatureDesc>
687 for (
const auto &Operand : Root->operands()) {
689 if (Element ==
nullptr)
692 "Missing Root Element Metadata Node.",
nullptr));
694 if (
auto Err = parseRootSignatureElement(RSD, Element))
695 DeferredErrs =
joinErrors(std::move(DeferredErrs), std::move(Err));
698 if (
auto Err = validateRootSignature(RSD))
699 DeferredErrs =
joinErrors(std::move(DeferredErrs), std::move(Err));
702 return std::move(DeferredErrs);
704 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)
constexpr bool empty() const
empty - Check if the string is empty.
static LLVM_ABI Type * getFloatTy(LLVMContext &C)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
bool isValidShaderVisibility(uint32_t V)
LLVM_ABI StringRef getResourceClassName(ResourceClass RC)
LLVM_ABI bool verifyAddress(uint32_t Address)
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 verifyComparisonFunc(uint32_t ComparisonFunc)
static Expected< dxbc::ShaderVisibility > extractShaderVisibility(MDNode *Node, unsigned int OpId)
LLVM_ABI bool verifySamplerFilter(uint32_t Value)
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)
LLVM_ABI bool verifyBorderColor(uint32_t BorderColor)
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 verifyDescriptorRangeFlag(uint32_t Version, uint32_t Type, uint32_t FlagsVal)
LLVM_ABI bool verifyMaxAnisotropy(uint32_t MaxAnisotropy)
LLVM_ABI bool verifyRangeType(uint32_t Type)
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< dxbc::RTS0::v2::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< dxbc::RTS0::v1::StaticSampler > StaticSamplers
mcdxbc::RootParametersContainer ParametersContainer