Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions clang/lib/Sema/SemaHLSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

Expand Down
10 changes: 10 additions & 0 deletions llvm/include/llvm/BinaryFormat/DXContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion llvm/include/llvm/Frontend/HLSL/RootSignatureValidations.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 12 additions & 3 deletions llvm/include/llvm/MC/DXContainerRootSignature.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ struct RootDescriptor {
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::RootParameterType Type;
dxbc::ShaderVisibility Visibility;
Expand All @@ -42,11 +51,11 @@ struct RootParameterInfo {
};

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();
}
};
Expand Down
10 changes: 10 additions & 0 deletions llvm/lib/BinaryFormat/DXContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = {
Expand Down
25 changes: 7 additions & 18 deletions llvm/lib/Frontend/HLSL/RootSignatureMetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,25 +325,19 @@ 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);

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;
Expand Down Expand Up @@ -571,12 +565,7 @@ Error MetadataParser::validateRootSignature(
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 =
Expand Down
5 changes: 2 additions & 3 deletions llvm/lib/Frontend/HLSL/RootSignatureValidations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions llvm/lib/ObjectYAML/DXContainerEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,10 @@ void DXContainerWriter::writeParts(raw_ostream &OS) {
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;
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/DirectX/DXILPostOptimizationValidation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,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
Expand Down
7 changes: 5 additions & 2 deletions llvm/lib/Target/DirectX/DXILRootSignature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,11 @@ PreservedAnalyses RootSignatureAnalysisPrinter::run(Module &M,
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"
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
;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
Expand Down