Compare commits
14 Commits
main
...
users/joao
Author | SHA1 | Date | |
---|---|---|---|
![]() |
8c143ba0ce | ||
![]() |
f3ecd8ae8c | ||
![]() |
8353fe0d0a | ||
![]() |
dc436d553b | ||
![]() |
fb248daeef | ||
![]() |
567a3d4efe | ||
![]() |
3b25b34cd9 | ||
![]() |
d38c00d09a | ||
![]() |
8eb82fdac3 | ||
![]() |
1d29111c4f | ||
![]() |
6539364fa7 | ||
![]() |
f6f2e61d5d | ||
![]() |
1690a9c04d | ||
![]() |
31ec5e50ff |
@ -1268,11 +1268,34 @@ bool SemaHLSL::handleRootSignatureElements(
|
||||
// value
|
||||
ReportError(Loc, 1, 0xfffffffe);
|
||||
}
|
||||
switch (Clause->Type) {
|
||||
|
||||
if (!llvm::hlsl::rootsig::verifyDescriptorRangeFlag(
|
||||
Version, llvm::to_underlying(Clause->Type),
|
||||
llvm::to_underlying(Clause->Flags)))
|
||||
ReportFlagError(Loc);
|
||||
case llvm::dxil::ResourceClass::SRV:
|
||||
if (!llvm::hlsl::rootsig::verifyDescriptorRangeFlag(
|
||||
Version, llvm::dxbc::DescriptorRangeType::SRV,
|
||||
llvm::to_underlying(Clause->Flags)))
|
||||
ReportFlagError(Loc);
|
||||
break;
|
||||
case llvm::dxil::ResourceClass::UAV:
|
||||
if (!llvm::hlsl::rootsig::verifyDescriptorRangeFlag(
|
||||
Version, llvm::dxbc::DescriptorRangeType::UAV,
|
||||
llvm::to_underlying(Clause->Flags)))
|
||||
ReportFlagError(Loc);
|
||||
break;
|
||||
case llvm::dxil::ResourceClass::CBuffer:
|
||||
if (!llvm::hlsl::rootsig::verifyDescriptorRangeFlag(
|
||||
Version, llvm::dxbc::DescriptorRangeType::CBV,
|
||||
llvm::to_underlying(Clause->Flags)))
|
||||
ReportFlagError(Loc);
|
||||
break;
|
||||
case llvm::dxil::ResourceClass::Sampler:
|
||||
if (!llvm::hlsl::rootsig::verifyDescriptorRangeFlag(
|
||||
Version, llvm::dxbc::DescriptorRangeType::Sampler,
|
||||
llvm::to_underlying(Clause->Flags)))
|
||||
ReportFlagError(Loc);
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -209,6 +209,16 @@ inline bool isValidParameterType(uint32_t V) {
|
||||
return false;
|
||||
}
|
||||
|
||||
#define DESCRIPTOR_RANGE(Val, Enum) \
|
||||
case Val: \
|
||||
return true;
|
||||
inline bool isValidRangeType(uint32_t V) {
|
||||
switch (V) {
|
||||
#include "DXContainerConstants.def"
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#define SHADER_VISIBILITY(Val, Enum) Enum = Val,
|
||||
enum class ShaderVisibility : uint32_t {
|
||||
#include "DXContainerConstants.def"
|
||||
|
@ -30,7 +30,8 @@ LLVM_ABI bool verifyRegisterValue(uint32_t RegisterValue);
|
||||
LLVM_ABI bool verifyRegisterSpace(uint32_t RegisterSpace);
|
||||
LLVM_ABI bool verifyRootDescriptorFlag(uint32_t Version, uint32_t FlagsVal);
|
||||
LLVM_ABI bool verifyRangeType(uint32_t Type);
|
||||
LLVM_ABI bool verifyDescriptorRangeFlag(uint32_t Version, uint32_t Type,
|
||||
LLVM_ABI bool verifyDescriptorRangeFlag(uint32_t Version,
|
||||
dxbc::DescriptorRangeType Type,
|
||||
uint32_t FlagsVal);
|
||||
LLVM_ABI bool verifyNumDescriptors(uint32_t NumDescriptors);
|
||||
LLVM_ABI bool verifySamplerFilter(uint32_t Value);
|
||||
|
@ -19,22 +19,43 @@ namespace llvm {
|
||||
class raw_ostream;
|
||||
namespace mcdxbc {
|
||||
|
||||
struct RootConstants {
|
||||
uint32_t ShaderRegister;
|
||||
uint32_t RegisterSpace;
|
||||
uint32_t Num32BitValues;
|
||||
};
|
||||
|
||||
struct RootDescriptor {
|
||||
uint32_t ShaderRegister;
|
||||
uint32_t RegisterSpace;
|
||||
uint32_t Flags;
|
||||
};
|
||||
|
||||
struct DescriptorRange {
|
||||
dxbc::DescriptorRangeType RangeType;
|
||||
uint32_t NumDescriptors;
|
||||
uint32_t BaseShaderRegister;
|
||||
uint32_t RegisterSpace;
|
||||
uint32_t Flags;
|
||||
uint32_t OffsetInDescriptorsFromTableStart;
|
||||
};
|
||||
|
||||
struct RootParameterInfo {
|
||||
dxbc::RTS0::v1::RootParameterHeader Header;
|
||||
dxbc::RootParameterType Type;
|
||||
dxbc::ShaderVisibility Visibility;
|
||||
size_t Location;
|
||||
|
||||
RootParameterInfo() = default;
|
||||
|
||||
RootParameterInfo(dxbc::RTS0::v1::RootParameterHeader Header, size_t Location)
|
||||
: Header(Header), Location(Location) {}
|
||||
RootParameterInfo(dxbc::RootParameterType Type,
|
||||
dxbc::ShaderVisibility Visibility, size_t Location)
|
||||
: Type(Type), Visibility(Visibility), Location(Location) {}
|
||||
};
|
||||
|
||||
struct DescriptorTable {
|
||||
SmallVector<dxbc::RTS0::v2::DescriptorRange> Ranges;
|
||||
SmallVector<dxbc::RTS0::v2::DescriptorRange>::const_iterator begin() const {
|
||||
SmallVector<DescriptorRange> Ranges;
|
||||
SmallVector<DescriptorRange>::const_iterator begin() const {
|
||||
return Ranges.begin();
|
||||
}
|
||||
SmallVector<dxbc::RTS0::v2::DescriptorRange>::const_iterator end() const {
|
||||
SmallVector<DescriptorRange>::const_iterator end() const {
|
||||
return Ranges.end();
|
||||
}
|
||||
};
|
||||
@ -42,52 +63,44 @@ struct DescriptorTable {
|
||||
struct RootParametersContainer {
|
||||
SmallVector<RootParameterInfo> ParametersInfo;
|
||||
|
||||
SmallVector<dxbc::RTS0::v1::RootConstants> Constants;
|
||||
SmallVector<dxbc::RTS0::v2::RootDescriptor> Descriptors;
|
||||
SmallVector<RootConstants> Constants;
|
||||
SmallVector<RootDescriptor> Descriptors;
|
||||
SmallVector<DescriptorTable> Tables;
|
||||
|
||||
void addInfo(dxbc::RTS0::v1::RootParameterHeader Header, size_t Location) {
|
||||
ParametersInfo.push_back(RootParameterInfo(Header, Location));
|
||||
void addInfo(dxbc::RootParameterType Type, dxbc::ShaderVisibility Visibility,
|
||||
size_t Location) {
|
||||
ParametersInfo.emplace_back(Type, Visibility, Location);
|
||||
}
|
||||
|
||||
void addParameter(dxbc::RTS0::v1::RootParameterHeader Header,
|
||||
dxbc::RTS0::v1::RootConstants Constant) {
|
||||
addInfo(Header, Constants.size());
|
||||
void addParameter(dxbc::RootParameterType Type,
|
||||
dxbc::ShaderVisibility Visibility, RootConstants Constant) {
|
||||
addInfo(Type, Visibility, Constants.size());
|
||||
Constants.push_back(Constant);
|
||||
}
|
||||
|
||||
void addInvalidParameter(dxbc::RTS0::v1::RootParameterHeader Header) {
|
||||
addInfo(Header, -1);
|
||||
}
|
||||
|
||||
void addParameter(dxbc::RTS0::v1::RootParameterHeader Header,
|
||||
dxbc::RTS0::v2::RootDescriptor Descriptor) {
|
||||
addInfo(Header, Descriptors.size());
|
||||
void addParameter(dxbc::RootParameterType Type,
|
||||
dxbc::ShaderVisibility Visibility,
|
||||
RootDescriptor Descriptor) {
|
||||
addInfo(Type, Visibility, Descriptors.size());
|
||||
Descriptors.push_back(Descriptor);
|
||||
}
|
||||
|
||||
void addParameter(dxbc::RTS0::v1::RootParameterHeader Header,
|
||||
DescriptorTable Table) {
|
||||
addInfo(Header, Tables.size());
|
||||
void addParameter(dxbc::RootParameterType Type,
|
||||
dxbc::ShaderVisibility Visibility, DescriptorTable Table) {
|
||||
addInfo(Type, Visibility, Tables.size());
|
||||
Tables.push_back(Table);
|
||||
}
|
||||
|
||||
std::pair<uint32_t, uint32_t>
|
||||
getTypeAndLocForParameter(uint32_t Location) const {
|
||||
const RootParameterInfo &getInfo(uint32_t Location) const {
|
||||
const RootParameterInfo &Info = ParametersInfo[Location];
|
||||
return {Info.Header.ParameterType, Info.Location};
|
||||
return Info;
|
||||
}
|
||||
|
||||
const dxbc::RTS0::v1::RootParameterHeader &getHeader(size_t Location) const {
|
||||
const RootParameterInfo &Info = ParametersInfo[Location];
|
||||
return Info.Header;
|
||||
}
|
||||
|
||||
const dxbc::RTS0::v1::RootConstants &getConstant(size_t Index) const {
|
||||
const RootConstants &getConstant(size_t Index) const {
|
||||
return Constants[Index];
|
||||
}
|
||||
|
||||
const dxbc::RTS0::v2::RootDescriptor &getRootDescriptor(size_t Index) const {
|
||||
const RootDescriptor &getRootDescriptor(size_t Index) const {
|
||||
return Descriptors[Index];
|
||||
}
|
||||
|
||||
|
@ -149,6 +149,16 @@ ArrayRef<EnumEntry<RootParameterType>> dxbc::getRootParameterTypes() {
|
||||
return ArrayRef(RootParameterTypes);
|
||||
}
|
||||
|
||||
#define DESCRIPTOR_RANGE(Val, Enum) {#Enum, DescriptorRangeType::Enum},
|
||||
|
||||
static const EnumEntry<DescriptorRangeType> DescriptorRangeTypes[] = {
|
||||
#include "llvm/BinaryFormat/DXContainerConstants.def"
|
||||
};
|
||||
|
||||
ArrayRef<EnumEntry<DescriptorRangeType>> dxbc::getDescriptorRangeTypes() {
|
||||
return ArrayRef(DescriptorRangeTypes);
|
||||
}
|
||||
|
||||
#define SEMANTIC_KIND(Val, Enum) {#Enum, PSV::SemanticKind::Enum},
|
||||
|
||||
static const EnumEntry<PSV::SemanticKind> SemanticKindNames[] = {
|
||||
|
@ -51,6 +51,17 @@ static std::optional<StringRef> extractMdStringValue(MDNode *Node,
|
||||
return NodeText->getString();
|
||||
}
|
||||
|
||||
static Expected<dxbc::ShaderVisibility>
|
||||
extractShaderVisibility(MDNode *Node, unsigned int OpId) {
|
||||
if (std::optional<uint32_t> Val = extractMdIntValue(Node, OpId)) {
|
||||
if (!dxbc::isValidShaderVisibility(*Val))
|
||||
return make_error<RootSignatureValidationError<uint32_t>>(
|
||||
"ShaderVisibility", *Val);
|
||||
return dxbc::ShaderVisibility(*Val);
|
||||
}
|
||||
return make_error<InvalidRSMetadataValue>("ShaderVisibility");
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
// We use the OverloadVisit with std::visit to ensure the compiler catches if a
|
||||
@ -224,17 +235,12 @@ Error MetadataParser::parseRootConstants(mcdxbc::RootSignatureDesc &RSD,
|
||||
if (RootConstantNode->getNumOperands() != 5)
|
||||
return make_error<InvalidRSMetadataFormat>("RootConstants Element");
|
||||
|
||||
dxbc::RTS0::v1::RootParameterHeader Header;
|
||||
// The parameter offset doesn't matter here - we recalculate it during
|
||||
// serialization Header.ParameterOffset = 0;
|
||||
Header.ParameterType = to_underlying(dxbc::RootParameterType::Constants32Bit);
|
||||
Expected<dxbc::ShaderVisibility> Visibility =
|
||||
extractShaderVisibility(RootConstantNode, 1);
|
||||
if (auto E = Visibility.takeError())
|
||||
return Error(std::move(E));
|
||||
|
||||
if (std::optional<uint32_t> Val = extractMdIntValue(RootConstantNode, 1))
|
||||
Header.ShaderVisibility = *Val;
|
||||
else
|
||||
return make_error<InvalidRSMetadataValue>("ShaderVisibility");
|
||||
|
||||
dxbc::RTS0::v1::RootConstants Constants;
|
||||
mcdxbc::RootConstants Constants;
|
||||
if (std::optional<uint32_t> Val = extractMdIntValue(RootConstantNode, 2))
|
||||
Constants.ShaderRegister = *Val;
|
||||
else
|
||||
@ -250,7 +256,8 @@ Error MetadataParser::parseRootConstants(mcdxbc::RootSignatureDesc &RSD,
|
||||
else
|
||||
return make_error<InvalidRSMetadataValue>("Num32BitValues");
|
||||
|
||||
RSD.ParametersContainer.addParameter(Header, Constants);
|
||||
RSD.ParametersContainer.addParameter(dxbc::RootParameterType::Constants32Bit,
|
||||
*Visibility, Constants);
|
||||
|
||||
return Error::success();
|
||||
}
|
||||
@ -266,28 +273,28 @@ Error MetadataParser::parseRootDescriptors(
|
||||
if (RootDescriptorNode->getNumOperands() != 5)
|
||||
return make_error<InvalidRSMetadataFormat>("Root Descriptor Element");
|
||||
|
||||
dxbc::RTS0::v1::RootParameterHeader Header;
|
||||
dxbc::RootParameterType Type;
|
||||
switch (ElementKind) {
|
||||
case RootSignatureElementKind::SRV:
|
||||
Header.ParameterType = to_underlying(dxbc::RootParameterType::SRV);
|
||||
Type = dxbc::RootParameterType::SRV;
|
||||
break;
|
||||
case RootSignatureElementKind::UAV:
|
||||
Header.ParameterType = to_underlying(dxbc::RootParameterType::UAV);
|
||||
Type = dxbc::RootParameterType::UAV;
|
||||
break;
|
||||
case RootSignatureElementKind::CBV:
|
||||
Header.ParameterType = to_underlying(dxbc::RootParameterType::CBV);
|
||||
Type = dxbc::RootParameterType::CBV;
|
||||
break;
|
||||
default:
|
||||
llvm_unreachable("invalid Root Descriptor kind");
|
||||
break;
|
||||
}
|
||||
|
||||
if (std::optional<uint32_t> Val = extractMdIntValue(RootDescriptorNode, 1))
|
||||
Header.ShaderVisibility = *Val;
|
||||
else
|
||||
return make_error<InvalidRSMetadataValue>("ShaderVisibility");
|
||||
Expected<dxbc::ShaderVisibility> Visibility =
|
||||
extractShaderVisibility(RootDescriptorNode, 1);
|
||||
if (auto E = Visibility.takeError())
|
||||
return Error(std::move(E));
|
||||
|
||||
dxbc::RTS0::v2::RootDescriptor Descriptor;
|
||||
mcdxbc::RootDescriptor Descriptor;
|
||||
if (std::optional<uint32_t> Val = extractMdIntValue(RootDescriptorNode, 2))
|
||||
Descriptor.ShaderRegister = *Val;
|
||||
else
|
||||
@ -299,7 +306,7 @@ Error MetadataParser::parseRootDescriptors(
|
||||
return make_error<InvalidRSMetadataValue>("RegisterSpace");
|
||||
|
||||
if (RSD.Version == 1) {
|
||||
RSD.ParametersContainer.addParameter(Header, Descriptor);
|
||||
RSD.ParametersContainer.addParameter(Type, *Visibility, Descriptor);
|
||||
return Error::success();
|
||||
}
|
||||
assert(RSD.Version > 1);
|
||||
@ -309,7 +316,7 @@ Error MetadataParser::parseRootDescriptors(
|
||||
else
|
||||
return make_error<InvalidRSMetadataValue>("Root Descriptor Flags");
|
||||
|
||||
RSD.ParametersContainer.addParameter(Header, Descriptor);
|
||||
RSD.ParametersContainer.addParameter(Type, *Visibility, Descriptor);
|
||||
return Error::success();
|
||||
}
|
||||
|
||||
@ -318,7 +325,7 @@ Error MetadataParser::parseDescriptorRange(mcdxbc::DescriptorTable &Table,
|
||||
if (RangeDescriptorNode->getNumOperands() != 6)
|
||||
return make_error<InvalidRSMetadataFormat>("Descriptor Range");
|
||||
|
||||
dxbc::RTS0::v2::DescriptorRange Range;
|
||||
mcdxbc::DescriptorRange Range;
|
||||
|
||||
std::optional<StringRef> ElementText =
|
||||
extractMdStringValue(RangeDescriptorNode, 0);
|
||||
@ -326,17 +333,11 @@ Error MetadataParser::parseDescriptorRange(mcdxbc::DescriptorTable &Table,
|
||||
if (!ElementText.has_value())
|
||||
return make_error<InvalidRSMetadataFormat>("Descriptor Range");
|
||||
|
||||
Range.RangeType =
|
||||
StringSwitch<uint32_t>(*ElementText)
|
||||
.Case("CBV", to_underlying(dxbc::DescriptorRangeType::CBV))
|
||||
.Case("SRV", to_underlying(dxbc::DescriptorRangeType::SRV))
|
||||
.Case("UAV", to_underlying(dxbc::DescriptorRangeType::UAV))
|
||||
.Case("Sampler", to_underlying(dxbc::DescriptorRangeType::Sampler))
|
||||
.Default(~0U);
|
||||
|
||||
if (Range.RangeType == ~0U)
|
||||
return make_error<GenericRSMetadataError>("Invalid Descriptor Range type.",
|
||||
RangeDescriptorNode);
|
||||
Range.RangeType = StringSwitch<dxbc::DescriptorRangeType>(*ElementText)
|
||||
.Case("CBV", dxbc::DescriptorRangeType::CBV)
|
||||
.Case("SRV", dxbc::DescriptorRangeType::SRV)
|
||||
.Case("UAV", dxbc::DescriptorRangeType::UAV)
|
||||
.Case("Sampler", dxbc::DescriptorRangeType::Sampler);
|
||||
|
||||
if (std::optional<uint32_t> Val = extractMdIntValue(RangeDescriptorNode, 1))
|
||||
Range.NumDescriptors = *Val;
|
||||
@ -375,15 +376,12 @@ Error MetadataParser::parseDescriptorTable(mcdxbc::RootSignatureDesc &RSD,
|
||||
if (NumOperands < 2)
|
||||
return make_error<InvalidRSMetadataFormat>("Descriptor Table");
|
||||
|
||||
dxbc::RTS0::v1::RootParameterHeader Header;
|
||||
if (std::optional<uint32_t> Val = extractMdIntValue(DescriptorTableNode, 1))
|
||||
Header.ShaderVisibility = *Val;
|
||||
else
|
||||
return make_error<InvalidRSMetadataValue>("ShaderVisibility");
|
||||
Expected<dxbc::ShaderVisibility> Visibility =
|
||||
extractShaderVisibility(DescriptorTableNode, 1);
|
||||
if (auto E = Visibility.takeError())
|
||||
return Error(std::move(E));
|
||||
|
||||
mcdxbc::DescriptorTable Table;
|
||||
Header.ParameterType =
|
||||
to_underlying(dxbc::RootParameterType::DescriptorTable);
|
||||
|
||||
for (unsigned int I = 2; I < NumOperands; I++) {
|
||||
MDNode *Element = dyn_cast<MDNode>(DescriptorTableNode->getOperand(I));
|
||||
@ -395,7 +393,8 @@ Error MetadataParser::parseDescriptorTable(mcdxbc::RootSignatureDesc &RSD,
|
||||
return Err;
|
||||
}
|
||||
|
||||
RSD.ParametersContainer.addParameter(Header, Table);
|
||||
RSD.ParametersContainer.addParameter(dxbc::RootParameterType::DescriptorTable,
|
||||
*Visibility, Table);
|
||||
return Error::success();
|
||||
}
|
||||
|
||||
@ -531,21 +530,15 @@ Error MetadataParser::validateRootSignature(
|
||||
}
|
||||
|
||||
for (const mcdxbc::RootParameterInfo &Info : RSD.ParametersContainer) {
|
||||
if (!dxbc::isValidShaderVisibility(Info.Header.ShaderVisibility))
|
||||
DeferredErrs =
|
||||
joinErrors(std::move(DeferredErrs),
|
||||
make_error<RootSignatureValidationError<uint32_t>>(
|
||||
"ShaderVisibility", Info.Header.ShaderVisibility));
|
||||
|
||||
assert(dxbc::isValidParameterType(Info.Header.ParameterType) &&
|
||||
"Invalid value for ParameterType");
|
||||
switch (Info.Type) {
|
||||
case dxbc::RootParameterType::Constants32Bit:
|
||||
break;
|
||||
|
||||
switch (Info.Header.ParameterType) {
|
||||
|
||||
case to_underlying(dxbc::RootParameterType::CBV):
|
||||
case to_underlying(dxbc::RootParameterType::UAV):
|
||||
case to_underlying(dxbc::RootParameterType::SRV): {
|
||||
const dxbc::RTS0::v2::RootDescriptor &Descriptor =
|
||||
case dxbc::RootParameterType::CBV:
|
||||
case dxbc::RootParameterType::UAV:
|
||||
case dxbc::RootParameterType::SRV: {
|
||||
const mcdxbc::RootDescriptor &Descriptor =
|
||||
RSD.ParametersContainer.getRootDescriptor(Info.Location);
|
||||
if (!hlsl::rootsig::verifyRegisterValue(Descriptor.ShaderRegister))
|
||||
DeferredErrs =
|
||||
@ -569,15 +562,10 @@ Error MetadataParser::validateRootSignature(
|
||||
}
|
||||
break;
|
||||
}
|
||||
case to_underlying(dxbc::RootParameterType::DescriptorTable): {
|
||||
case dxbc::RootParameterType::DescriptorTable: {
|
||||
const mcdxbc::DescriptorTable &Table =
|
||||
RSD.ParametersContainer.getDescriptorTable(Info.Location);
|
||||
for (const dxbc::RTS0::v2::DescriptorRange &Range : Table) {
|
||||
if (!hlsl::rootsig::verifyRangeType(Range.RangeType))
|
||||
DeferredErrs =
|
||||
joinErrors(std::move(DeferredErrs),
|
||||
make_error<RootSignatureValidationError<uint32_t>>(
|
||||
"RangeType", Range.RangeType));
|
||||
for (const mcdxbc::DescriptorRange &Range : Table) {
|
||||
|
||||
if (!hlsl::rootsig::verifyRegisterSpace(Range.RegisterSpace))
|
||||
DeferredErrs =
|
||||
|
@ -63,13 +63,12 @@ bool verifyRangeType(uint32_t Type) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool verifyDescriptorRangeFlag(uint32_t Version, uint32_t Type,
|
||||
bool verifyDescriptorRangeFlag(uint32_t Version, dxbc::DescriptorRangeType Type,
|
||||
uint32_t FlagsVal) {
|
||||
using FlagT = dxbc::DescriptorRangeFlags;
|
||||
FlagT Flags = FlagT(FlagsVal);
|
||||
|
||||
const bool IsSampler =
|
||||
(Type == llvm::to_underlying(dxbc::DescriptorRangeType::Sampler));
|
||||
const bool IsSampler = (Type == dxbc::DescriptorRangeType::Sampler);
|
||||
|
||||
if (Version == 1) {
|
||||
// Since the metadata is unversioned, we expect to explicitly see the values
|
||||
|
@ -35,20 +35,20 @@ size_t RootSignatureDesc::getSize() const {
|
||||
StaticSamplers.size() * sizeof(dxbc::RTS0::v1::StaticSampler);
|
||||
|
||||
for (const RootParameterInfo &I : ParametersContainer) {
|
||||
switch (I.Header.ParameterType) {
|
||||
case llvm::to_underlying(dxbc::RootParameterType::Constants32Bit):
|
||||
switch (I.Type) {
|
||||
case dxbc::RootParameterType::Constants32Bit:
|
||||
Size += sizeof(dxbc::RTS0::v1::RootConstants);
|
||||
break;
|
||||
case llvm::to_underlying(dxbc::RootParameterType::CBV):
|
||||
case llvm::to_underlying(dxbc::RootParameterType::SRV):
|
||||
case llvm::to_underlying(dxbc::RootParameterType::UAV):
|
||||
case dxbc::RootParameterType::CBV:
|
||||
case dxbc::RootParameterType::SRV:
|
||||
case dxbc::RootParameterType::UAV:
|
||||
if (Version == 1)
|
||||
Size += sizeof(dxbc::RTS0::v1::RootDescriptor);
|
||||
else
|
||||
Size += sizeof(dxbc::RTS0::v2::RootDescriptor);
|
||||
|
||||
break;
|
||||
case llvm::to_underlying(dxbc::RootParameterType::DescriptorTable):
|
||||
case dxbc::RootParameterType::DescriptorTable:
|
||||
const DescriptorTable &Table =
|
||||
ParametersContainer.getDescriptorTable(I.Location);
|
||||
|
||||
@ -84,11 +84,9 @@ void RootSignatureDesc::write(raw_ostream &OS) const {
|
||||
support::endian::write(BOS, Flags, llvm::endianness::little);
|
||||
|
||||
SmallVector<uint32_t> ParamsOffsets;
|
||||
for (const RootParameterInfo &P : ParametersContainer) {
|
||||
support::endian::write(BOS, P.Header.ParameterType,
|
||||
llvm::endianness::little);
|
||||
support::endian::write(BOS, P.Header.ShaderVisibility,
|
||||
llvm::endianness::little);
|
||||
for (const RootParameterInfo &I : ParametersContainer) {
|
||||
support::endian::write(BOS, I.Type, llvm::endianness::little);
|
||||
support::endian::write(BOS, I.Visibility, llvm::endianness::little);
|
||||
|
||||
ParamsOffsets.push_back(writePlaceholder(BOS));
|
||||
}
|
||||
@ -96,11 +94,11 @@ void RootSignatureDesc::write(raw_ostream &OS) const {
|
||||
assert(NumParameters == ParamsOffsets.size());
|
||||
for (size_t I = 0; I < NumParameters; ++I) {
|
||||
rewriteOffsetToCurrentByte(BOS, ParamsOffsets[I]);
|
||||
const auto &[Type, Loc] = ParametersContainer.getTypeAndLocForParameter(I);
|
||||
switch (Type) {
|
||||
case llvm::to_underlying(dxbc::RootParameterType::Constants32Bit): {
|
||||
const dxbc::RTS0::v1::RootConstants &Constants =
|
||||
ParametersContainer.getConstant(Loc);
|
||||
const auto Info = ParametersContainer.getInfo(I);
|
||||
switch (Info.Type) {
|
||||
case dxbc::RootParameterType::Constants32Bit: {
|
||||
const mcdxbc::RootConstants &Constants =
|
||||
ParametersContainer.getConstant(Info.Location);
|
||||
support::endian::write(BOS, Constants.ShaderRegister,
|
||||
llvm::endianness::little);
|
||||
support::endian::write(BOS, Constants.RegisterSpace,
|
||||
@ -109,11 +107,11 @@ void RootSignatureDesc::write(raw_ostream &OS) const {
|
||||
llvm::endianness::little);
|
||||
break;
|
||||
}
|
||||
case llvm::to_underlying(dxbc::RootParameterType::CBV):
|
||||
case llvm::to_underlying(dxbc::RootParameterType::SRV):
|
||||
case llvm::to_underlying(dxbc::RootParameterType::UAV): {
|
||||
const dxbc::RTS0::v2::RootDescriptor &Descriptor =
|
||||
ParametersContainer.getRootDescriptor(Loc);
|
||||
case dxbc::RootParameterType::CBV:
|
||||
case dxbc::RootParameterType::SRV:
|
||||
case dxbc::RootParameterType::UAV: {
|
||||
const mcdxbc::RootDescriptor &Descriptor =
|
||||
ParametersContainer.getRootDescriptor(Info.Location);
|
||||
|
||||
support::endian::write(BOS, Descriptor.ShaderRegister,
|
||||
llvm::endianness::little);
|
||||
@ -123,9 +121,9 @@ void RootSignatureDesc::write(raw_ostream &OS) const {
|
||||
support::endian::write(BOS, Descriptor.Flags, llvm::endianness::little);
|
||||
break;
|
||||
}
|
||||
case llvm::to_underlying(dxbc::RootParameterType::DescriptorTable): {
|
||||
case dxbc::RootParameterType::DescriptorTable: {
|
||||
const DescriptorTable &Table =
|
||||
ParametersContainer.getDescriptorTable(Loc);
|
||||
ParametersContainer.getDescriptorTable(Info.Location);
|
||||
support::endian::write(BOS, (uint32_t)Table.Ranges.size(),
|
||||
llvm::endianness::little);
|
||||
rewriteOffsetToCurrentByte(BOS, writePlaceholder(BOS));
|
||||
|
@ -275,42 +275,50 @@ void DXContainerWriter::writeParts(raw_ostream &OS) {
|
||||
|
||||
for (DXContainerYAML::RootParameterLocationYaml &L :
|
||||
P.RootSignature->Parameters.Locations) {
|
||||
dxbc::RTS0::v1::RootParameterHeader Header{L.Header.Type, L.Header.Visibility,
|
||||
L.Header.Offset};
|
||||
|
||||
switch (L.Header.Type) {
|
||||
case llvm::to_underlying(dxbc::RootParameterType::Constants32Bit): {
|
||||
assert(dxbc::isValidParameterType(L.Header.Type) &&
|
||||
"invalid DXContainer YAML");
|
||||
assert(dxbc::isValidShaderVisibility(L.Header.Visibility) &&
|
||||
"invalid DXContainer YAML");
|
||||
dxbc::RootParameterType Type = dxbc::RootParameterType(L.Header.Type);
|
||||
dxbc::ShaderVisibility Visibility =
|
||||
dxbc::ShaderVisibility(L.Header.Visibility);
|
||||
|
||||
switch (Type) {
|
||||
case dxbc::RootParameterType::Constants32Bit: {
|
||||
const DXContainerYAML::RootConstantsYaml &ConstantYaml =
|
||||
P.RootSignature->Parameters.getOrInsertConstants(L);
|
||||
dxbc::RTS0::v1::RootConstants Constants;
|
||||
mcdxbc::RootConstants Constants;
|
||||
|
||||
Constants.Num32BitValues = ConstantYaml.Num32BitValues;
|
||||
Constants.RegisterSpace = ConstantYaml.RegisterSpace;
|
||||
Constants.ShaderRegister = ConstantYaml.ShaderRegister;
|
||||
RS.ParametersContainer.addParameter(Header, Constants);
|
||||
RS.ParametersContainer.addParameter(Type, Visibility, Constants);
|
||||
break;
|
||||
}
|
||||
case llvm::to_underlying(dxbc::RootParameterType::CBV):
|
||||
case llvm::to_underlying(dxbc::RootParameterType::SRV):
|
||||
case llvm::to_underlying(dxbc::RootParameterType::UAV): {
|
||||
case dxbc::RootParameterType::CBV:
|
||||
case dxbc::RootParameterType::SRV:
|
||||
case dxbc::RootParameterType::UAV: {
|
||||
const DXContainerYAML::RootDescriptorYaml &DescriptorYaml =
|
||||
P.RootSignature->Parameters.getOrInsertDescriptor(L);
|
||||
|
||||
dxbc::RTS0::v2::RootDescriptor Descriptor;
|
||||
mcdxbc::RootDescriptor Descriptor;
|
||||
Descriptor.RegisterSpace = DescriptorYaml.RegisterSpace;
|
||||
Descriptor.ShaderRegister = DescriptorYaml.ShaderRegister;
|
||||
if (RS.Version > 1)
|
||||
Descriptor.Flags = DescriptorYaml.getEncodedFlags();
|
||||
RS.ParametersContainer.addParameter(Header, Descriptor);
|
||||
RS.ParametersContainer.addParameter(Type, Visibility, Descriptor);
|
||||
break;
|
||||
}
|
||||
case llvm::to_underlying(dxbc::RootParameterType::DescriptorTable): {
|
||||
case dxbc::RootParameterType::DescriptorTable: {
|
||||
const DXContainerYAML::DescriptorTableYaml &TableYaml =
|
||||
P.RootSignature->Parameters.getOrInsertTable(L);
|
||||
mcdxbc::DescriptorTable Table;
|
||||
for (const auto &R : TableYaml.Ranges) {
|
||||
|
||||
dxbc::RTS0::v2::DescriptorRange Range;
|
||||
Range.RangeType = R.RangeType;
|
||||
assert(dxbc::isValidRangeType(R.RangeType) &&
|
||||
"Invalid Descriptor Range Type");
|
||||
mcdxbc::DescriptorRange Range;
|
||||
Range.RangeType = dxbc::DescriptorRangeType(R.RangeType);
|
||||
Range.NumDescriptors = R.NumDescriptors;
|
||||
Range.BaseShaderRegister = R.BaseShaderRegister;
|
||||
Range.RegisterSpace = R.RegisterSpace;
|
||||
@ -320,14 +328,9 @@ void DXContainerWriter::writeParts(raw_ostream &OS) {
|
||||
Range.Flags = R.getEncodedFlags();
|
||||
Table.Ranges.push_back(Range);
|
||||
}
|
||||
RS.ParametersContainer.addParameter(Header, Table);
|
||||
RS.ParametersContainer.addParameter(Type, Visibility, Table);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
// Handling invalid parameter type edge case. We intentionally let
|
||||
// obj2yaml/yaml2obj parse and emit invalid dxcontainer data, in order
|
||||
// for that to be used as a testing tool more effectively.
|
||||
RS.ParametersContainer.addInvalidParameter(Header);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -164,15 +164,14 @@ static void validateRootSignature(Module &M,
|
||||
|
||||
for (const mcdxbc::RootParameterInfo &ParamInfo : RSD.ParametersContainer) {
|
||||
dxbc::ShaderVisibility ParamVisibility =
|
||||
static_cast<dxbc::ShaderVisibility>(ParamInfo.Header.ShaderVisibility);
|
||||
dxbc::ShaderVisibility(ParamInfo.Visibility);
|
||||
if (ParamVisibility != dxbc::ShaderVisibility::All &&
|
||||
ParamVisibility != Visibility)
|
||||
continue;
|
||||
dxbc::RootParameterType ParamType =
|
||||
static_cast<dxbc::RootParameterType>(ParamInfo.Header.ParameterType);
|
||||
dxbc::RootParameterType ParamType = dxbc::RootParameterType(ParamInfo.Type);
|
||||
switch (ParamType) {
|
||||
case dxbc::RootParameterType::Constants32Bit: {
|
||||
dxbc::RTS0::v1::RootConstants Const =
|
||||
mcdxbc::RootConstants Const =
|
||||
RSD.ParametersContainer.getConstant(ParamInfo.Location);
|
||||
Builder.trackBinding(dxil::ResourceClass::CBuffer, Const.RegisterSpace,
|
||||
Const.ShaderRegister, Const.ShaderRegister,
|
||||
@ -183,12 +182,11 @@ static void validateRootSignature(Module &M,
|
||||
case dxbc::RootParameterType::SRV:
|
||||
case dxbc::RootParameterType::UAV:
|
||||
case dxbc::RootParameterType::CBV: {
|
||||
dxbc::RTS0::v2::RootDescriptor Desc =
|
||||
mcdxbc::RootDescriptor Desc =
|
||||
RSD.ParametersContainer.getRootDescriptor(ParamInfo.Location);
|
||||
Builder.trackBinding(toResourceClass(static_cast<dxbc::RootParameterType>(
|
||||
ParamInfo.Header.ParameterType)),
|
||||
Desc.RegisterSpace, Desc.ShaderRegister,
|
||||
Desc.ShaderRegister, &ParamInfo);
|
||||
Builder.trackBinding(toResourceClass(ParamInfo.Type), Desc.RegisterSpace,
|
||||
Desc.ShaderRegister, Desc.ShaderRegister,
|
||||
&ParamInfo);
|
||||
|
||||
break;
|
||||
}
|
||||
@ -196,7 +194,7 @@ static void validateRootSignature(Module &M,
|
||||
const mcdxbc::DescriptorTable &Table =
|
||||
RSD.ParametersContainer.getDescriptorTable(ParamInfo.Location);
|
||||
|
||||
for (const dxbc::RTS0::v2::DescriptorRange &Range : Table.Ranges) {
|
||||
for (const mcdxbc::DescriptorRange &Range : Table.Ranges) {
|
||||
uint32_t UpperBound =
|
||||
Range.NumDescriptors == ~0U
|
||||
? Range.BaseShaderRegister
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include "llvm/Pass.h"
|
||||
#include "llvm/Support/Error.h"
|
||||
#include "llvm/Support/ErrorHandling.h"
|
||||
#include "llvm/Support/ScopedPrinter.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
#include <cstdint>
|
||||
|
||||
@ -171,27 +172,27 @@ PreservedAnalyses RootSignatureAnalysisPrinter::run(Module &M,
|
||||
<< "RootParametersOffset: " << RS.RootParameterOffset << "\n"
|
||||
<< "NumParameters: " << RS.ParametersContainer.size() << "\n";
|
||||
for (size_t I = 0; I < RS.ParametersContainer.size(); I++) {
|
||||
const auto &[Type, Loc] =
|
||||
RS.ParametersContainer.getTypeAndLocForParameter(I);
|
||||
const dxbc::RTS0::v1::RootParameterHeader Header =
|
||||
RS.ParametersContainer.getHeader(I);
|
||||
const auto &Info = RS.ParametersContainer.getInfo(I);
|
||||
|
||||
OS << "- Parameter Type: " << Type << "\n"
|
||||
<< " Shader Visibility: " << Header.ShaderVisibility << "\n";
|
||||
|
||||
switch (Type) {
|
||||
case llvm::to_underlying(dxbc::RootParameterType::Constants32Bit): {
|
||||
const dxbc::RTS0::v1::RootConstants &Constants =
|
||||
OS << "- Parameter Type: "
|
||||
<< enumToStringRef(Info.Type, dxbc::getRootParameterTypes()) << "\n"
|
||||
<< " Shader Visibility: "
|
||||
<< enumToStringRef(Info.Visibility, dxbc::getShaderVisibility())
|
||||
<< "\n";
|
||||
const uint32_t &Loc = Info.Location;
|
||||
switch (Info.Type) {
|
||||
case dxbc::RootParameterType::Constants32Bit: {
|
||||
const mcdxbc::RootConstants &Constants =
|
||||
RS.ParametersContainer.getConstant(Loc);
|
||||
OS << " Register Space: " << Constants.RegisterSpace << "\n"
|
||||
<< " Shader Register: " << Constants.ShaderRegister << "\n"
|
||||
<< " Num 32 Bit Values: " << Constants.Num32BitValues << "\n";
|
||||
break;
|
||||
}
|
||||
case llvm::to_underlying(dxbc::RootParameterType::CBV):
|
||||
case llvm::to_underlying(dxbc::RootParameterType::UAV):
|
||||
case llvm::to_underlying(dxbc::RootParameterType::SRV): {
|
||||
const dxbc::RTS0::v2::RootDescriptor &Descriptor =
|
||||
case dxbc::RootParameterType::CBV:
|
||||
case dxbc::RootParameterType::UAV:
|
||||
case dxbc::RootParameterType::SRV: {
|
||||
const mcdxbc::RootDescriptor &Descriptor =
|
||||
RS.ParametersContainer.getRootDescriptor(Loc);
|
||||
OS << " Register Space: " << Descriptor.RegisterSpace << "\n"
|
||||
<< " Shader Register: " << Descriptor.ShaderRegister << "\n";
|
||||
@ -199,13 +200,16 @@ PreservedAnalyses RootSignatureAnalysisPrinter::run(Module &M,
|
||||
OS << " Flags: " << Descriptor.Flags << "\n";
|
||||
break;
|
||||
}
|
||||
case llvm::to_underlying(dxbc::RootParameterType::DescriptorTable): {
|
||||
case dxbc::RootParameterType::DescriptorTable: {
|
||||
const mcdxbc::DescriptorTable &Table =
|
||||
RS.ParametersContainer.getDescriptorTable(Loc);
|
||||
OS << " NumRanges: " << Table.Ranges.size() << "\n";
|
||||
|
||||
for (const dxbc::RTS0::v2::DescriptorRange Range : Table) {
|
||||
OS << " - Range Type: " << Range.RangeType << "\n"
|
||||
for (const mcdxbc::DescriptorRange Range : Table) {
|
||||
OS << " - Range Type: "
|
||||
<< enumToStringRef(Range.RangeType,
|
||||
dxbc::getDescriptorRangeTypes())
|
||||
<< "\n"
|
||||
<< " Register Space: " << Range.RegisterSpace << "\n"
|
||||
<< " Base Shader Register: " << Range.BaseShaderRegister << "\n"
|
||||
<< " Num Descriptors: " << Range.NumDescriptors << "\n"
|
||||
|
@ -1,20 +0,0 @@
|
||||
; RUN: not opt -passes='print<dxil-root-signature>' %s -S -o - 2>&1 | FileCheck %s
|
||||
|
||||
target triple = "dxil-unknown-shadermodel6.0-compute"
|
||||
|
||||
; CHECK: error: Invalid Descriptor Range type
|
||||
; CHECK-NOT: Root Signature Definitions
|
||||
|
||||
define void @main() #0 {
|
||||
entry:
|
||||
ret void
|
||||
}
|
||||
attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
|
||||
|
||||
|
||||
!dx.rootsignatures = !{!2} ; list of function/root signature pairs
|
||||
!2 = !{ ptr @main, !3, i32 2 } ; function, root signature
|
||||
!3 = !{ !5 } ; list of root signature elements
|
||||
!5 = !{ !"DescriptorTable", i32 0, !6, !7 }
|
||||
!6 = !{ !"Invalid", i32 1, i32 0, i32 -1, i32 -1, i32 4 }
|
||||
!7 = !{ !"UAV", i32 5, i32 1, i32 10, i32 5, i32 2 }
|
@ -25,26 +25,26 @@ attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
|
||||
;CHECK-NEXT: Version: 2
|
||||
;CHECK-NEXT: RootParametersOffset: 24
|
||||
;CHECK-NEXT: NumParameters: 3
|
||||
;CHECK-NEXT: - Parameter Type: 1
|
||||
;CHECK-NEXT: Shader Visibility: 0
|
||||
;CHECK-NEXT: - Parameter Type: Constants32Bit
|
||||
;CHECK-NEXT: Shader Visibility: All
|
||||
;CHECK-NEXT: Register Space: 2
|
||||
;CHECK-NEXT: Shader Register: 1
|
||||
;CHECK-NEXT: Num 32 Bit Values: 3
|
||||
;CHECK-NEXT: - Parameter Type: 3
|
||||
;CHECK-NEXT: Shader Visibility: 1
|
||||
;CHECK-NEXT: - Parameter Type: SRV
|
||||
;CHECK-NEXT: Shader Visibility: Vertex
|
||||
;CHECK-NEXT: Register Space: 5
|
||||
;CHECK-NEXT: Shader Register: 4
|
||||
;CHECK-NEXT: Flags: 4
|
||||
;CHECK-NEXT: - Parameter Type: 0
|
||||
;CHECK-NEXT: Shader Visibility: 0
|
||||
;CHECK-NEXT: - Parameter Type: DescriptorTable
|
||||
;CHECK-NEXT: Shader Visibility: All
|
||||
;CHECK-NEXT: NumRanges: 2
|
||||
;CHECK-NEXT: - Range Type: 0
|
||||
;CHECK-NEXT: - Range Type: SRV
|
||||
;CHECK-NEXT: Register Space: 0
|
||||
;CHECK-NEXT: Base Shader Register: 1
|
||||
;CHECK-NEXT: Num Descriptors: 1
|
||||
;CHECK-NEXT: Offset In Descriptors From Table Start: 4294967295
|
||||
;CHECK-NEXT: Flags: 4
|
||||
;CHECK-NEXT: - Range Type: 1
|
||||
;CHECK-NEXT: - Range Type: UAV
|
||||
;CHECK-NEXT: Register Space: 10
|
||||
;CHECK-NEXT: Base Shader Register: 1
|
||||
;CHECK-NEXT: Num Descriptors: 5
|
||||
|
@ -1,29 +0,0 @@
|
||||
# RUN: yaml2obj %s -o %t
|
||||
# RUN: not obj2yaml 2>&1 %t | FileCheck %s -DFILE=%t
|
||||
|
||||
# CHECK: Error reading file: [[FILE]]: Invalid value for parameter type
|
||||
|
||||
|
||||
--- !dxcontainer
|
||||
Header:
|
||||
Hash: [ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||
0x0, 0x0, 0x0, 0x0, 0x0, 0x0 ]
|
||||
Version:
|
||||
Major: 1
|
||||
Minor: 0
|
||||
PartCount: 1
|
||||
PartOffsets: [ 60 ]
|
||||
Parts:
|
||||
- Name: RTS0
|
||||
Size: 80
|
||||
RootSignature:
|
||||
Version: 2
|
||||
NumRootParameters: 2
|
||||
RootParametersOffset: 24
|
||||
NumStaticSamplers: 0
|
||||
StaticSamplersOffset: 64
|
||||
Parameters:
|
||||
- ParameterType: 255 # INVALID
|
||||
ShaderVisibility: 2 # Hull
|
||||
AllowInputAssemblerInputLayout: true
|
||||
DenyGeometryShaderRootAccess: true
|
@ -1,33 +0,0 @@
|
||||
# RUN: yaml2obj %s -o %t
|
||||
# RUN: not obj2yaml 2>&1 %t | FileCheck %s -DFILE=%t
|
||||
|
||||
# CHECK: Error reading file: [[FILE]]: Invalid value for shader visibility
|
||||
|
||||
|
||||
--- !dxcontainer
|
||||
Header:
|
||||
Hash: [ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||
0x0, 0x0, 0x0, 0x0, 0x0, 0x0 ]
|
||||
Version:
|
||||
Major: 1
|
||||
Minor: 0
|
||||
PartCount: 1
|
||||
PartOffsets: [ 60 ]
|
||||
Parts:
|
||||
- Name: RTS0
|
||||
Size: 80
|
||||
RootSignature:
|
||||
Version: 2
|
||||
NumRootParameters: 2
|
||||
RootParametersOffset: 24
|
||||
NumStaticSamplers: 0
|
||||
StaticSamplersOffset: 64
|
||||
Parameters:
|
||||
- ParameterType: 1 # Constants32Bit
|
||||
ShaderVisibility: 255 # INVALID
|
||||
Constants:
|
||||
Num32BitValues: 21
|
||||
ShaderRegister: 22
|
||||
RegisterSpace: 23
|
||||
AllowInputAssemblerInputLayout: true
|
||||
DenyGeometryShaderRootAccess: true
|
Loading…
x
Reference in New Issue
Block a user