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) {
226Error MetadataParser::parseRootFlags(mcdxbc::RootSignatureDesc &RSD,
227 MDNode *RootFlagNode) {
239Error MetadataParser::parseRootConstants(mcdxbc::RootSignatureDesc &RSD,
240 MDNode *RootConstantNode) {
244 Expected<dxbc::ShaderVisibility> Visibility =
249 return Error(std::move(
E));
268 *Visibility, Constants);
273Error MetadataParser::parseRootDescriptors(
274 mcdxbc::RootSignatureDesc &RSD, MDNode *RootDescriptorNode,
279 "parseRootDescriptors should only be called with RootDescriptor "
285 switch (ElementKind) {
287 Type = dxbc::RootParameterType::SRV;
290 Type = dxbc::RootParameterType::UAV;
293 Type = dxbc::RootParameterType::CBV;
300 Expected<dxbc::ShaderVisibility> Visibility =
305 return Error(std::move(
E));
307 mcdxbc::RootDescriptor Descriptor;
325 Descriptor.
Flags = *Val;
333Error MetadataParser::parseDescriptorRange(mcdxbc::DescriptorTable &Table,
334 MDNode *RangeDescriptorNode) {
338 mcdxbc::DescriptorRange
Range;
340 std::optional<StringRef> ElementText =
343 if (!ElementText.has_value())
346 if (*ElementText ==
"CBV")
348 else if (*ElementText ==
"SRV")
350 else if (*ElementText ==
"UAV")
352 else if (*ElementText ==
"Sampler")
356 RangeDescriptorNode);
359 Range.NumDescriptors = *Val;
362 RangeDescriptorNode);
365 Range.BaseShaderRegister = *Val;
370 Range.RegisterSpace = *Val;
375 Range.OffsetInDescriptorsFromTableStart = *Val;
378 "OffsetInDescriptorsFromTableStart");
389Error MetadataParser::parseDescriptorTable(mcdxbc::RootSignatureDesc &RSD,
390 MDNode *DescriptorTableNode) {
391 const unsigned int NumOperands = DescriptorTableNode->
getNumOperands();
395 Expected<dxbc::ShaderVisibility> Visibility =
400 return Error(std::move(
E));
402 mcdxbc::DescriptorTable Table;
404 for (
unsigned int I = 2;
I < NumOperands;
I++) {
406 if (Element ==
nullptr)
408 "Missing Root Element Metadata Node.", DescriptorTableNode);
410 if (
auto Err = parseDescriptorRange(Table, Element))
419Error MetadataParser::parseStaticSampler(mcdxbc::RootSignatureDesc &RSD,
420 MDNode *StaticSamplerNode) {
428 if (
auto E =
Filter.takeError())
429 return Error(std::move(
E));
432 Expected<dxbc::TextureAddressMode> AddressU =
436 return Error(std::move(
E));
439 Expected<dxbc::TextureAddressMode> AddressV =
443 return Error(std::move(
E));
446 Expected<dxbc::TextureAddressMode> AddressW =
450 return Error(std::move(
E));
467 return Error(std::move(
E));
470 Expected<dxbc::StaticBorderColor> BorderColor =
474 return Error(std::move(
E));
475 Sampler.BorderColor = *BorderColor;
497 Expected<dxbc::ShaderVisibility> Visibility =
502 return Error(std::move(
E));
503 Sampler.ShaderVisibility = *Visibility;
520Error MetadataParser::parseRootSignatureElement(mcdxbc::RootSignatureDesc &RSD,
523 if (!ElementText.has_value())
527 StringSwitch<RootSignatureElementKind>(*ElementText)
537 switch (ElementKind) {
540 return parseRootFlags(RSD, Element);
542 return parseRootConstants(RSD, Element);
546 return parseRootDescriptors(RSD, Element, ElementKind);
548 return parseDescriptorTable(RSD, Element);
550 return parseStaticSampler(RSD, Element);
567 CurrRC =
Range.RangeType;
576 bool IsPrevUnbound =
false;
579 if (
Range.NumDescriptors == 0)
583 Range.BaseShaderRegister,
Range.NumDescriptors);
594 if (IsPrevUnbound && IsAppending)
613Error MetadataParser::validateRootSignature(
619 make_error<RootSignatureValidationError<uint32_t>>(
626 make_error<RootSignatureValidationError<uint32_t>>(
627 "RootFlags", RSD.
Flags));
633 case dxbc::RootParameterType::Constants32Bit:
636 case dxbc::RootParameterType::CBV:
637 case dxbc::RootParameterType::UAV:
638 case dxbc::RootParameterType::SRV: {
644 make_error<RootSignatureValidationError<uint32_t>>(
650 make_error<RootSignatureValidationError<uint32_t>>(
658 make_error<RootSignatureValidationError<uint32_t>>(
659 "RootDescriptorFlag", Descriptor.
Flags));
663 case dxbc::RootParameterType::DescriptorTable: {
664 const mcdxbc::DescriptorTable &Table =
666 for (
const mcdxbc::DescriptorRange &
Range : Table) {
670 make_error<RootSignatureValidationError<uint32_t>>(
671 "RegisterSpace",
Range.RegisterSpace));
676 make_error<RootSignatureValidationError<uint32_t>>(
677 "NumDescriptors",
Range.NumDescriptors));
684 make_error<RootSignatureValidationError<uint32_t>>(
685 "DescriptorFlag",
Range.Flags));
689 DeferredErrs =
joinErrors(std::move(DeferredErrs), std::move(Err));
693 DeferredErrs =
joinErrors(std::move(DeferredErrs), std::move(Err));
703 DeferredErrs =
joinErrors(std::move(DeferredErrs),
704 make_error<RootSignatureValidationError<float>>(
705 "MipLODBias",
Sampler.MipLODBias));
710 make_error<RootSignatureValidationError<uint32_t>>(
711 "MaxAnisotropy",
Sampler.MaxAnisotropy));
714 DeferredErrs =
joinErrors(std::move(DeferredErrs),
715 make_error<RootSignatureValidationError<float>>(
719 DeferredErrs =
joinErrors(std::move(DeferredErrs),
720 make_error<RootSignatureValidationError<float>>(
726 make_error<RootSignatureValidationError<uint32_t>>(
727 "ShaderRegister",
Sampler.ShaderRegister));
732 make_error<RootSignatureValidationError<uint32_t>>(
733 "RegisterSpace",
Sampler.RegisterSpace));
738 make_error<RootSignatureValidationError<uint32_t>>(
739 "Static Sampler Flag",
Sampler.Flags));
745Expected<mcdxbc::RootSignatureDesc>
750 for (
const auto &Operand : Root->operands()) {
752 if (Element ==
nullptr)
755 "Missing Root Element Metadata Node.",
nullptr));
757 if (
auto Err = parseRootSignatureElement(RSD, Element))
758 DeferredErrs =
joinErrors(std::move(DeferredErrs), std::move(Err));
761 if (
auto Err = validateRootSignature(RSD))
762 DeferredErrs =
joinErrors(std::move(DeferredErrs), std::move(Err));
765 return std::move(DeferredErrs);
767 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