41 return CI->getZExtValue();
48 return CI->getValueAPF().convertToFloat();
55 if (NodeText ==
nullptr)
60template <
typename T,
typename = std::enable_if_t<
62 std::is_same_v<std::underlying_type_t<T>,
uint32_t>>>
69 return static_cast<T>(*Val);
79template <
class... Ts>
struct OverloadedVisit : Ts... {
80 using Ts::operator()...;
82template <
class... Ts> OverloadedVisit(Ts...) -> OverloadedVisit<Ts...>;
87 const auto Visitor = OverloadedVisit{
89 return BuildRootFlags(Flags);
92 return BuildRootConstants(Constants);
95 return BuildRootDescriptor(Descriptor);
98 return BuildDescriptorTableClause(
Clause);
101 return BuildDescriptorTable(Table);
104 return BuildStaticSampler(Sampler);
109 MDNode *ElementMD = std::visit(Visitor, Element);
110 assert(ElementMD !=
nullptr &&
111 "Root Element must be initialized and validated");
112 GeneratedMetadata.push_back(ElementMD);
140MDNode *MetadataBuilder::BuildRootDescriptor(
const RootDescriptor &Descriptor) {
143 assert(!ResName.
empty() &&
"Provided an invalid Resource Class");
144 SmallString<7>
Name({
"Root", ResName});
157MDNode *MetadataBuilder::BuildDescriptorTable(
const DescriptorTable &Table) {
168 assert(Table.NumClauses <= GeneratedMetadata.size() &&
169 "Table expected all owned clauses to be generated already");
171 TableOperands.
append(GeneratedMetadata.end() - Table.NumClauses,
172 GeneratedMetadata.end());
174 GeneratedMetadata.pop_back_n(Table.NumClauses);
179MDNode *MetadataBuilder::BuildDescriptorTableClause(
183 assert(!ResName.
empty() &&
"Provided an invalid Resource Class");
195MDNode *MetadataBuilder::BuildStaticSampler(
const StaticSampler &Sampler) {
225Error MetadataParser::parseRootFlags(mcdxbc::RootSignatureDesc &RSD,
226 MDNode *RootFlagNode) {
238Error MetadataParser::parseRootConstants(mcdxbc::RootSignatureDesc &RSD,
239 MDNode *RootConstantNode) {
243 Expected<dxbc::ShaderVisibility> Visibility =
248 return Error(std::move(
E));
267 *Visibility, Constants);
272Error MetadataParser::parseRootDescriptors(
273 mcdxbc::RootSignatureDesc &RSD, MDNode *RootDescriptorNode,
278 "parseRootDescriptors should only be called with RootDescriptor "
284 switch (ElementKind) {
286 Type = dxbc::RootParameterType::SRV;
289 Type = dxbc::RootParameterType::UAV;
292 Type = dxbc::RootParameterType::CBV;
299 Expected<dxbc::ShaderVisibility> Visibility =
304 return Error(std::move(
E));
306 mcdxbc::RootDescriptor Descriptor;
324 Descriptor.
Flags = *Val;
332Error MetadataParser::parseDescriptorRange(mcdxbc::DescriptorTable &Table,
333 MDNode *RangeDescriptorNode) {
337 mcdxbc::DescriptorRange
Range;
339 std::optional<StringRef> ElementText =
342 if (!ElementText.has_value())
345 if (*ElementText ==
"CBV")
347 else if (*ElementText ==
"SRV")
349 else if (*ElementText ==
"UAV")
351 else if (*ElementText ==
"Sampler")
355 RangeDescriptorNode);
358 Range.NumDescriptors = *Val;
361 RangeDescriptorNode);
364 Range.BaseShaderRegister = *Val;
369 Range.RegisterSpace = *Val;
374 Range.OffsetInDescriptorsFromTableStart = *Val;
377 "OffsetInDescriptorsFromTableStart");
388Error MetadataParser::parseDescriptorTable(mcdxbc::RootSignatureDesc &RSD,
389 MDNode *DescriptorTableNode) {
390 const unsigned int NumOperands = DescriptorTableNode->
getNumOperands();
394 Expected<dxbc::ShaderVisibility> Visibility =
399 return Error(std::move(
E));
401 mcdxbc::DescriptorTable Table;
403 for (
unsigned int I = 2;
I < NumOperands;
I++) {
405 if (Element ==
nullptr)
407 "Missing Root Element Metadata Node.", DescriptorTableNode);
409 if (
auto Err = parseDescriptorRange(Table, Element))
418Error MetadataParser::parseStaticSampler(mcdxbc::RootSignatureDesc &RSD,
419 MDNode *StaticSamplerNode) {
427 if (
auto E =
Filter.takeError())
428 return Error(std::move(
E));
431 Expected<dxbc::TextureAddressMode> AddressU =
435 return Error(std::move(
E));
438 Expected<dxbc::TextureAddressMode> AddressV =
442 return Error(std::move(
E));
445 Expected<dxbc::TextureAddressMode> AddressW =
449 return Error(std::move(
E));
466 return Error(std::move(
E));
469 Expected<dxbc::StaticBorderColor> BorderColor =
473 return Error(std::move(
E));
474 Sampler.BorderColor = *BorderColor;
496 Expected<dxbc::ShaderVisibility> Visibility =
501 return Error(std::move(
E));
502 Sampler.ShaderVisibility = *Visibility;
508Error MetadataParser::parseRootSignatureElement(mcdxbc::RootSignatureDesc &RSD,
511 if (!ElementText.has_value())
515 StringSwitch<RootSignatureElementKind>(*ElementText)
525 switch (ElementKind) {
528 return parseRootFlags(RSD, Element);
530 return parseRootConstants(RSD, Element);
534 return parseRootDescriptors(RSD, Element, ElementKind);
536 return parseDescriptorTable(RSD, Element);
538 return parseStaticSampler(RSD, Element);
555 CurrRC =
Range.RangeType;
564 bool IsPrevUnbound =
false;
567 if (
Range.NumDescriptors == 0)
571 Range.BaseShaderRegister,
Range.NumDescriptors);
582 if (IsPrevUnbound && IsAppending)
601Error MetadataParser::validateRootSignature(
607 make_error<RootSignatureValidationError<uint32_t>>(
614 make_error<RootSignatureValidationError<uint32_t>>(
615 "RootFlags", RSD.
Flags));
621 case dxbc::RootParameterType::Constants32Bit:
624 case dxbc::RootParameterType::CBV:
625 case dxbc::RootParameterType::UAV:
626 case dxbc::RootParameterType::SRV: {
632 make_error<RootSignatureValidationError<uint32_t>>(
638 make_error<RootSignatureValidationError<uint32_t>>(
646 make_error<RootSignatureValidationError<uint32_t>>(
647 "RootDescriptorFlag", Descriptor.
Flags));
651 case dxbc::RootParameterType::DescriptorTable: {
652 const mcdxbc::DescriptorTable &Table =
654 for (
const mcdxbc::DescriptorRange &
Range : Table) {
658 make_error<RootSignatureValidationError<uint32_t>>(
659 "RegisterSpace",
Range.RegisterSpace));
664 make_error<RootSignatureValidationError<uint32_t>>(
665 "NumDescriptors",
Range.NumDescriptors));
672 make_error<RootSignatureValidationError<uint32_t>>(
673 "DescriptorFlag",
Range.Flags));
677 DeferredErrs =
joinErrors(std::move(DeferredErrs), std::move(Err));
681 DeferredErrs =
joinErrors(std::move(DeferredErrs), std::move(Err));
691 DeferredErrs =
joinErrors(std::move(DeferredErrs),
692 make_error<RootSignatureValidationError<float>>(
693 "MipLODBias",
Sampler.MipLODBias));
698 make_error<RootSignatureValidationError<uint32_t>>(
699 "MaxAnisotropy",
Sampler.MaxAnisotropy));
702 DeferredErrs =
joinErrors(std::move(DeferredErrs),
703 make_error<RootSignatureValidationError<float>>(
707 DeferredErrs =
joinErrors(std::move(DeferredErrs),
708 make_error<RootSignatureValidationError<float>>(
714 make_error<RootSignatureValidationError<uint32_t>>(
715 "ShaderRegister",
Sampler.ShaderRegister));
720 make_error<RootSignatureValidationError<uint32_t>>(
721 "RegisterSpace",
Sampler.RegisterSpace));
726 make_error<RootSignatureValidationError<uint32_t>>(
727 "Static Sampler Flag",
Sampler.Flags));
733Expected<mcdxbc::RootSignatureDesc>
738 for (
const auto &Operand : Root->operands()) {
740 if (Element ==
nullptr)
743 "Missing Root Element Metadata Node.",
nullptr));
745 if (
auto Err = parseRootSignatureElement(RSD, Element))
746 DeferredErrs =
joinErrors(std::move(DeferredErrs), std::move(Err));
749 if (
auto Err = validateRootSignature(RSD))
750 DeferredErrs =
joinErrors(std::move(DeferredErrs), std::move(Err));
753 return std::move(DeferredErrs);
755 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))
Lightweight error class with error context and mandatory checking.
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 uint64_t computeRangeBound(uint64_t Offset, uint32_t Size)
static const uint32_t NumDescriptorsUnbounded
static Error validateDescriptorTableRegisterOverflow(const mcdxbc::DescriptorTable &Table, uint32_t Location)
LLVM_ABI bool verifyStaticSamplerFlags(uint32_t Version, uint32_t FlagsNumber)
LLVM_ABI bool verifyRegisterSpace(uint32_t RegisterSpace)
static const uint32_t DescriptorTableOffsetAppend
LLVM_ABI bool verifyDescriptorRangeFlag(uint32_t Version, dxil::ResourceClass Type, dxbc::DescriptorRangeFlags FlagsVal)
static Error validateDescriptorTableSamplerMixin(const mcdxbc::DescriptorTable &Table, uint32_t Location)
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)
std::variant< dxbc::RootFlags, RootConstants, RootDescriptor, DescriptorTable, DescriptorTableClause, StaticSampler > RootElement
Models RootElement : RootFlags | RootConstants | RootParam | DescriptorTable | DescriptorTableClause ...
LLVM_ABI bool verifyNoOverflowedOffset(uint64_t Offset)
LLVM_ABI bool verifyMipLODBias(float MipLODBias)
LLVM_ABI bool verifyNumDescriptors(uint32_t NumDescriptors)
LLVM_ABI bool verifyMaxAnisotropy(uint32_t MaxAnisotropy)
static Expected< T > extractEnumValue(MDNode *Node, unsigned int OpId, StringRef ErrText, llvm::function_ref< bool(uint32_t)> VerifyFn)
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