21#include <system_error>
27static_assert((uint64_t)dxbc::FeatureFlags::NextUnusedBit <= 1ull << 63,
28 "Shader flag bits exceed enum size.");
31#define SHADER_FEATURE_FLAG(Num, DxilModuleNum, Val, Str) \
32 Val = (FlagData & (uint64_t)dxbc::FeatureFlags::Val) > 0;
33#include "llvm/BinaryFormat/DXContainerConstants.def"
46 auto Table = *TableOrErr;
56 for (
const auto &R : Table.Ranges) {
59 R.OffsetInDescriptorsFromTableStart;
65 "Invalid value for descriptor range type");
67 if constexpr (std::is_same_v<T, dxbc::RTS0::v2::DescriptorRange>) {
69#define DESCRIPTOR_RANGE_FLAG(Num, Enum, Flag) \
71 (R.Flags & llvm::to_underlying(dxbc::DescriptorRangeFlags::Enum)) != 0;
72#include "llvm/BinaryFormat/DXContainerConstants.def"
74 TableYaml.
Ranges.push_back(NewR);
98 "Invalid value for parameter type");
101 Header.Offset = PH.ParameterOffset;
105 "Invalid value for shader visibility");
110 Data.getParameter(PH);
121 auto Constants = *ConstantsOrErr;
130 }
else if (
auto *RDV =
136 auto Descriptor = *DescriptorOrErr;
145#define ROOT_DESCRIPTOR_FLAG(Num, Enum, Flag) \
146 YamlDescriptor.Enum = \
147 (Descriptor.Flags & \
148 llvm::to_underlying(dxbc::RootDescriptorFlags::Enum)) > 0;
149#include "llvm/BinaryFormat/DXContainerConstants.def"
151 }
else if (
auto *DTV =
155 Header, RootSigDesc, DTV))
159 Header, RootSigDesc, DTV))
166 for (
const auto &S :
Data.samplers()) {
169 "Invalid value for static sampler filter");
173 "Invalid value for static sampler AddressU");
177 "Invalid value for static sampler AddressV");
181 "Invalid value for static sampler AddressW");
185 std::errc::invalid_argument,
186 "Invalid value for static sampler ComparisonFunc");
190 "Invalid value for static sampler BorderColor");
194 std::errc::invalid_argument,
195 "Invalid value for static sampler ShaderVisibility");
213#define STATIC_SAMPLER_FLAG(Num, Enum, Flag) \
214 NewS.Enum = (S.Flags & llvm::to_underlying(dxbc::StaticSamplerFlags::Enum));
215#include "llvm/BinaryFormat/DXContainerConstants.def"
220#define ROOT_SIGNATURE_FLAG(Num, Val) \
221 RootSigDesc.Val = (Flags & llvm::to_underlying(dxbc::RootFlags::Val)) > 0;
222#include "llvm/BinaryFormat/DXContainerConstants.def"
228#define ROOT_DESCRIPTOR_FLAG(Num, Enum, Flag) \
230 Flags |= (uint32_t)dxbc::RootDescriptorFlags::Enum;
231#include "llvm/BinaryFormat/DXContainerConstants.def"
237#define ROOT_SIGNATURE_FLAG(Num, Val) \
239 Flag |= (uint32_t)dxbc::RootFlags::Val;
240#include "llvm/BinaryFormat/DXContainerConstants.def"
246#define DESCRIPTOR_RANGE_FLAG(Num, Enum, Flag) \
248 Flags |= (uint32_t)dxbc::DescriptorRangeFlags::Enum;
249#include "llvm/BinaryFormat/DXContainerConstants.def"
255#define STATIC_SAMPLER_FLAG(Num, Enum, Flag) \
257 Flags |= (uint32_t)dxbc::StaticSamplerFlags::Enum;
258#include "llvm/BinaryFormat/DXContainerConstants.def"
264#define SHADER_FEATURE_FLAG(Num, DxilModuleNum, Val, Str) \
266 Flag |= (uint64_t)dxbc::FeatureFlags::Val;
267#include "llvm/BinaryFormat/DXContainerConstants.def"
288 assert(Stage < std::numeric_limits<uint8_t>::max() &&
289 "Stage should be a very small number");
312 P->EntryNameOffset)) {
348#define SHADER_FEATURE_FLAG(Num, DxilModuleNum, Val, Str) \
349 IO.mapRequired(#Val, Flags.Val);
350#include "llvm/BinaryFormat/DXContainerConstants.def"
434#define ROOT_SIGNATURE_FLAG(Num, Val) IO.mapOptional(#Val, S.Val, false);
435#include "llvm/BinaryFormat/DXContainerConstants.def"
443 if (R.NumDescriptors == UINT_MAX) {
449 int32_t TmpNumDesc = 0;
451 R.NumDescriptors =
static_cast<uint32_t>(TmpNumDesc);
457 R.OffsetInDescriptorsFromTableStart);
458#define DESCRIPTOR_RANGE_FLAG(Num, Enum, Flag) \
459 IO.mapOptional(#Flag, R.Enum, false);
460#include "llvm/BinaryFormat/DXContainerConstants.def"
477 switch (L.Header.Type) {
478 case dxbc::RootParameterType::Constants32Bit: {
484 case dxbc::RootParameterType::CBV:
485 case dxbc::RootParameterType::SRV:
486 case dxbc::RootParameterType::UAV: {
492 case dxbc::RootParameterType::DescriptorTable: {
512#define ROOT_DESCRIPTOR_FLAG(Num, Enum, Flag) \
513 IO.mapOptional(#Flag, D.Enum, false);
514#include "llvm/BinaryFormat/DXContainerConstants.def"
533#define STATIC_SAMPLER_FLAG(Num, Enum, Flag) \
534 IO.mapOptional(#Flag, S.Enum, false);
535#include "llvm/BinaryFormat/DXContainerConstants.def"
580#define RESOURCE_FLAG(FlagIndex, Enum) IO.mapRequired(#Enum, Flags.Bits.Enum);
581#include "llvm/BinaryFormat/DXContainerConstants.def"
626void ScalarEnumerationTraits<dxbc::PSV::ComponentType>::enumeration(
629 IO.enumCase(
Value,
E.Name,
E.Value);
632void ScalarEnumerationTraits<dxbc::PSV::InterpolationMode>::enumeration(
633 IO &IO, dxbc::PSV::InterpolationMode &Value) {
634 for (
const auto &
E : dxbc::PSV::getInterpolationModes())
635 IO.enumCase(Value,
E.Name,
E.Value);
638void ScalarEnumerationTraits<dxbc::PSV::ResourceType>::enumeration(
639 IO &IO, dxbc::PSV::ResourceType &
Value) {
640 for (
const auto &
E : dxbc::PSV::getResourceTypes())
641 IO.enumCase(
Value,
E.Name,
E.Value);
644void ScalarEnumerationTraits<dxbc::PSV::ResourceKind>::enumeration(
645 IO &IO, dxbc::PSV::ResourceKind &
Value) {
646 for (
const auto &
E : dxbc::PSV::getResourceKinds())
647 IO.enumCase(
Value,
E.Name,
E.Value);
650void ScalarEnumerationTraits<dxbc::D3DSystemValue>::enumeration(
651 IO &IO, dxbc::D3DSystemValue &
Value) {
652 for (
const auto &
E : dxbc::getD3DSystemValues())
653 IO.enumCase(
Value,
E.Name,
E.Value);
656void ScalarEnumerationTraits<dxbc::SigMinPrecision>::enumeration(
657 IO &IO, dxbc::SigMinPrecision &
Value) {
658 for (
const auto &
E : dxbc::getSigMinPrecisions())
659 IO.enumCase(
Value,
E.Name,
E.Value);
662void ScalarEnumerationTraits<dxbc::SigComponentType>::enumeration(
663 IO &IO, dxbc::SigComponentType &
Value) {
664 for (
const auto &
E : dxbc::getSigComponentTypes())
665 IO.enumCase(
Value,
E.Name,
E.Value);
668void ScalarEnumerationTraits<dxbc::RootParameterType>::enumeration(
669 IO &IO, dxbc::RootParameterType &
Value) {
670 for (
const auto &
E : dxbc::getRootParameterTypes())
671 IO.enumCase(
Value,
E.Name,
E.Value);
674void ScalarEnumerationTraits<dxil::ResourceClass>::enumeration(
675 IO &IO, dxil::ResourceClass &
Value) {
676 const EnumEntry<dxil::ResourceClass> ResourceClasses[] = {
677 {
"CBuffer", dxil::ResourceClass::CBuffer},
678 {
"SRV", dxil::ResourceClass::SRV},
679 {
"UAV", dxil::ResourceClass::UAV},
680 {
"Sampler", dxil::ResourceClass::Sampler},
683 for (
const auto &
E : ResourceClasses)
684 IO.enumCase(
Value,
E.Name,
E.Value);
687void ScalarEnumerationTraits<dxbc::SamplerFilter>::enumeration(
688 IO &IO, dxbc::SamplerFilter &
Value) {
689 for (
const auto &
E : dxbc::getSamplerFilters())
690 IO.enumCase(
Value,
E.Name,
E.Value);
693void ScalarEnumerationTraits<dxbc::StaticBorderColor>::enumeration(
694 IO &IO, dxbc::StaticBorderColor &
Value) {
695 for (
const auto &
E : dxbc::getStaticBorderColors())
696 IO.enumCase(
Value,
E.Name,
E.Value);
699void ScalarEnumerationTraits<dxbc::TextureAddressMode>::enumeration(
700 IO &IO, dxbc::TextureAddressMode &
Value) {
701 for (
const auto &
E : dxbc::getTextureAddressModes())
702 IO.enumCase(
Value,
E.Name,
E.Value);
705void ScalarEnumerationTraits<dxbc::ShaderVisibility>::enumeration(
706 IO &IO, dxbc::ShaderVisibility &
Value) {
707 for (
const auto &
E : dxbc::getShaderVisibility())
708 IO.enumCase(
Value,
E.Name,
E.Value);
711void ScalarEnumerationTraits<dxbc::ComparisonFunc>::enumeration(
712 IO &IO, dxbc::ComparisonFunc &
Value) {
713 for (
const auto &
E : dxbc::getComparisonFuncs())
714 IO.enumCase(
Value,
E.Name,
E.Value);
754 IO.
mapRequired(
"GroupSharedBytesDependentOnViewID",
782 Info.GeomData.SigPatchConstOrPrimVectors);
785 IO.
mapRequired(
"SigPrimVectors",
Info.GeomData.MeshInfo.SigPrimVectors);
787 Info.GeomData.MeshInfo.MeshOutputTopology);
813 for (
auto Param : Sig)
815 Param.Stream, Sig.
getName(Param.NameOffset).
str(), Param.Index,
816 Param.SystemValue, Param.CompType, Param.Register, Param.Mask,
817 Param.ExclusiveMask, Param.MinPrecision});
821Expected<std::unique_ptr<DXContainerYAML::Object>>
823 std::unique_ptr<DXContainerYAML::Object> Obj =
824 std::make_unique<DXContainerYAML::Object>();
827 Obj->Header.Hash.push_back(Byte);
833 Obj->Header.PartOffsets = std::vector<uint32_t>();
834 for (
const auto P : Container) {
835 Obj->Header.PartOffsets->push_back(
P.Offset);
836 Obj->Parts.push_back(
841 case dxbc::PartType::DXIL:
842 case dxbc::PartType::ILDB: {
843 std::optional<object::DXContainer::DXILData> DXIL =
845 assert(DXIL &&
"Since we are iterating and found a DXIL/ILDB part, "
846 "this should never not have a value");
848 DXIL->first.getMajorVersion(),
849 DXIL->first.getMinorVersion(),
850 DXIL->first.ShaderKind,
852 DXIL->first.Bitcode.MajorVersion,
853 DXIL->first.Bitcode.MinorVersion,
854 DXIL->first.Bitcode.Offset,
855 DXIL->first.Bitcode.Size,
856 std::vector<llvm::yaml::Hex8>(
857 DXIL->second, DXIL->second + DXIL->first.Bitcode.Size)};
860 case dxbc::PartType::ILDN: {
862 assert(
DebugName &&
"Since we are iterating and found a ILDN part, this "
863 "should never not have a value");
869 case dxbc::PartType::SFI0: {
872 if (Flags && *Flags > 0)
876 case dxbc::PartType::HASH: {
877 std::optional<dxbc::ShaderHash> Hash = Container.
getShaderHash();
878 if (Hash && Hash->isPopulated())
882 case dxbc::PartType::PSV0: {
887 std::get_if<dxbc::PSV::v0::RuntimeInfo>(&
PSVInfo->getInfo())) {
888 std::optional<uint16_t> ShaderKind = Container.
getShaderKind();
892 }
else if (
const auto *
P = std::get_if<dxbc::PSV::v1::RuntimeInfo>(
895 else if (
const auto *
P =
896 std::get_if<dxbc::PSV::v2::RuntimeInfo>(&
PSVInfo->getInfo()))
898 else if (
const auto *
P =
899 std::get_if<dxbc::PSV::v3::RuntimeInfo>(&
PSVInfo->getInfo()))
901 NewPart.
Info->ResourceStride =
PSVInfo->getResourceStride();
902 NewPart.
Info->RuntimeInfoSize =
PSVInfo->getSize();
903 if (
PSVInfo->getVersion() > 0) {
906 while (Pos < ST.size()) {
907 size_t End = ST.find(
'\0', Pos);
911 NewPart.
Info->StringTable.push_back(
912 {ST.slice(Pos, End),
static_cast<uint32_t>(Pos)});
916 for (
auto Res :
PSVInfo->getResources())
917 NewPart.
Info->Resources.push_back(Res);
919 for (
auto El :
PSVInfo->getSigInputElements())
920 NewPart.
Info->SigInputElements.push_back(
923 PSVInfo->getSemanticIndexTable()));
924 for (
auto El :
PSVInfo->getSigOutputElements())
925 NewPart.
Info->SigOutputElements.push_back(
928 PSVInfo->getSemanticIndexTable()));
929 for (
auto El :
PSVInfo->getSigPatchOrPrimElements())
930 NewPart.
Info->SigPatchOrPrimElements.push_back(
933 PSVInfo->getSemanticIndexTable()));
936 for (
int I = 0;
I < 4; ++
I)
937 for (
auto Mask :
PSVInfo->getOutputVectorMasks(
I))
938 NewPart.
Info->OutputVectorMasks[
I].push_back(Mask);
939 for (
auto Mask :
PSVInfo->getPatchOrPrimMasks())
940 NewPart.
Info->PatchOrPrimMasks.push_back(Mask);
943 for (
int I = 0;
I < 4; ++
I)
944 for (
auto Mask :
PSVInfo->getInputOutputMap(
I))
945 NewPart.
Info->InputOutputMap[
I].push_back(Mask);
947 for (
auto Mask :
PSVInfo->getInputPatchMap())
948 NewPart.
Info->InputPatchMap.push_back(Mask);
950 for (
auto Mask :
PSVInfo->getPatchOutputMap())
951 NewPart.
Info->PatchOutputMap.push_back(Mask);
955 case dxbc::PartType::ISG1:
958 case dxbc::PartType::OSG1:
961 case dxbc::PartType::PSG1:
966 case dxbc::PartType::RTS0: {
967 std::optional<object::DirectX::RootSignature> RS =
969 if (RS.has_value()) {
970 auto RootSigDescOrErr =
972 if (
Error E = RootSigDescOrErr.takeError())
978 case dxbc::PartType::VERS: {
979 std::optional<mcdxbc::CompilerVersion>
Version =
981 assert(
Version &&
"Since we are iterating and found a VERS part, this "
982 "should never not have a value");
985 !!(
Version->Parameters.Flags & dxbc::CompilerVersionFlags::Debug),
986 !!(
Version->Parameters.Flags & dxbc::CompilerVersionFlags::Internal),
987 Version->Parameters.CommitCount,
989 Version->CustomVersionString.str()});
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file declares classes for handling the YAML representation of DXContainer.
This file contains library features backported from future STL versions.
This file defines the make_scope_exit function, which executes user-defined cleanup logic at scope ex...
static StringRef substr(StringRef Str, uint64_t Len)
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.
reference get()
Returns a reference to the stored T value.
Represent a mutable reference to an array (0 or more elements consecutively in memory),...
Represent a constant reference to a string, i.e.
static constexpr size_t npos
std::string str() const
Get the contents as an std::string.
LLVM Value Representation.
const std::optional< DXILData > & getDXIL(bool Debug) const
std::optional< uint64_t > getShaderFeatureFlags() const
const std::optional< DirectX::PSVRuntimeInfo > & getPSVInfo() const
const std::optional< mcdxbc::CompilerVersion > & getCompilerVersionInfo() const
std::optional< uint16_t > getShaderKind() const
const dxbc::Header & getHeader() const
const DirectX::Signature & getInputSignature() const
std::optional< DirectX::RootSignature > getRootSignature() const
const std::optional< mcdxbc::DebugName > getDebugName() const
std::optional< dxbc::ShaderHash > getShaderHash() const
const DirectX::Signature & getOutputSignature() const
const DirectX::Signature & getPatchConstantSignature() const
StringRef getName(uint32_t Offset) const
virtual bool outputting() const =0
virtual bool mapTag(StringRef Tag, bool Default=false)=0
void enumCase(T &Val, StringRef Str, const T ConstVal)
void mapOptional(StringRef Key, T &Val)
void * getContext() const
void mapRequired(StringRef Key, T &Val)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
LLVM_ABI Expected< std::unique_ptr< DXContainerYAML::Object > > fromDXContainer(object::DXContainer &DXC)
dxbc::PSV::ResourceFlags ResourceFlags
dxbc::PSV::v2::ResourceBindInfo ResourceBindInfo
LLVM_ABI ArrayRef< EnumEntry< ComponentType > > getComponentTypes()
LLVM_ABI ArrayRef< EnumEntry< SemanticKind > > getSemanticKinds()
bool isValidShaderVisibility(uint32_t V)
LLVM_ABI PartType parsePartType(StringRef S)
bool isValidSamplerFilter(uint32_t V)
Triple::EnvironmentType getShaderStage(uint32_t Kind)
bool isDebugProgramPart(PartType PT)
bool isValidBorderColor(uint32_t V)
bool isValidComparisonFunc(uint32_t V)
LLVM_ABI_FOR_TEST bool isValidParameterType(uint32_t V)
bool isValidAddress(uint32_t V)
bool isValidRangeType(uint32_t V)
This is an optimization pass for GlobalISel generic memory operations.
auto find(R &&Range, const T &Val)
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly.
static DXContainerYAML::Signature dumpSignature(const object::DirectX::Signature &Sig)
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
FunctionAddr VTableAddr uintptr_t uintptr_t Version
static llvm::Error readDescriptorRanges(DXContainerYAML::RootParameterHeaderYaml &Header, DXContainerYAML::RootSignatureYamlDesc &RootSigDesc, object::DirectX::DescriptorTableView *DTV)
FunctionAddr VTableAddr uintptr_t uintptr_t Data
std::optional< std::string > CommitSha
std::optional< uint16_t > Major
std::optional< uint16_t > Minor
std::optional< uint32_t > ContentSizeInBytes
std::optional< uint32_t > CommitCount
std::optional< std::string > CustomVersionString
std::optional< bool > IsValidated
std::optional< bool > IsDebugBuild
uint16_t DXILMajorVersion
std::optional< uint32_t > Size
uint16_t DXILMinorVersion
std::optional< std::vector< llvm::yaml::Hex8 > > DXIL
std::optional< uint32_t > DXILSize
std::optional< uint16_t > NameLength
std::optional< uint16_t > Flags
uint32_t OffsetInDescriptorsFromTableStart
uint32_t BaseShaderRegister
LLVM_ABI uint32_t getEncodedFlags() const
dxil::ResourceClass RangeType
SmallVector< DescriptorRangeYaml > Ranges
std::array< MaskVector, 4 > InputOutputMap
MaskVector PatchOutputMap
SmallVector< StringTableEntry > StringTable
SmallVector< SignatureElement > SigOutputElements
MaskVector PatchOrPrimMasks
SmallVector< SignatureElement > SigPatchOrPrimElements
SmallVector< ResourceBindInfo > Resources
SmallVector< SignatureElement > SigInputElements
LLVM_ABI void mapInfoForVersion(yaml::IO &IO)
dxbc::PSV::v3::RuntimeInfo Info
std::array< MaskVector, 4 > OutputVectorMasks
std::optional< PSVInfo > Info
std::optional< DXContainerYAML::RootSignatureYamlDesc > RootSignature
std::optional< DXILProgram > Program
std::optional< DXContainerYAML::Signature > Signature
std::optional< ShaderHash > Hash
std::optional< DXContainerYAML::CompilerVersion > CompilerVersion
std::optional< DXContainerYAML::DebugName > DebugName
std::optional< ShaderFeatureFlags > Flags
LLVM_ABI uint32_t getEncodedFlags() const
RootDescriptorYaml & getOrInsertDescriptor(RootParameterLocationYaml &ParamDesc)
SmallVector< RootParameterLocationYaml > Locations
RootConstantsYaml & getOrInsertConstants(RootParameterLocationYaml &ParamDesc)
void insertLocation(RootParameterLocationYaml &Location)
DescriptorTableYaml & getOrInsertTable(RootParameterLocationYaml &ParamDesc)
uint32_t NumRootParameters
uint32_t NumStaticSamplers
SmallVector< StaticSamplerYamlDesc > StaticSamplers
std::optional< uint32_t > RootParametersOffset
RootSignatureYamlDesc()=default
LLVM_ABI uint32_t getEncodedFlags()
static LLVM_ABI llvm::Expected< DXContainerYAML::RootSignatureYamlDesc > create(const object::DirectX::RootSignature &Data)
RootParameterYamlDesc Parameters
std::optional< uint32_t > StaticSamplersOffset
ShaderFeatureFlags()=default
LLVM_ABI uint64_t getEncodedFlags()
std::vector< llvm::yaml::Hex8 > Digest
dxbc::PSV::ComponentType Type
dxbc::PSV::InterpolationMode Mode
llvm::yaml::Hex8 DynamicMask
dxbc::PSV::SemanticKind Kind
SmallVector< uint32_t > Indices
dxbc::SigComponentType CompType
dxbc::SigMinPrecision MinPrecision
dxbc::D3DSystemValue SystemValue
llvm::SmallVector< SignatureParameter > Parameters
dxbc::StaticBorderColor BorderColor
dxbc::ShaderVisibility ShaderVisibility
dxbc::TextureAddressMode AddressU
dxbc::SamplerFilter Filter
dxbc::ComparisonFunc ComparisonFunc
dxbc::TextureAddressMode AddressV
LLVM_ABI uint32_t getEncodedFlags() const
dxbc::TextureAddressMode AddressW
uint32_t PayloadSizeInBytes
uint32_t InputControlPointCount
uint32_t TessellatorDomain
uint8_t OutputPositionPresent
uint8_t OutputPositionPresent
uint32_t OutputStreamMask
uint32_t TessellatorOutputPrimitive
uint32_t OutputControlPointCount
uint32_t InputControlPointCount
uint32_t TessellatorDomain
uint32_t PayloadSizeInBytes
uint16_t MaxOutputVertices
uint16_t MaxOutputPrimitives
uint32_t GroupSharedBytesDependentOnViewID
uint32_t GroupSharedBytesUsed
uint8_t OutputPositionPresent
llvm::Expected< DescriptorTable< T > > read()
This class is similar to MappingTraits<T> but allows you to pass in additional context for each map o...
This class should be specialized by any type that needs to be converted to/from a YAML mapping.
This class should be specialized by any integral type that converts to/from a YAML scalar where there...