Skip to content

Commit a4d77d7

Browse files
committed
Revert "removing binary format descriptor range dependency"
This reverts commit 8c143ba.
1 parent 8c143ba commit a4d77d7

File tree

12 files changed

+57
-82
lines changed

12 files changed

+57
-82
lines changed

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,34 +1268,11 @@ bool SemaHLSL::handleRootSignatureElements(
12681268
// value
12691269
ReportError(Loc, 1, 0xfffffffe);
12701270
}
1271-
switch (Clause->Type) {
12721271

1273-
case llvm::dxil::ResourceClass::SRV:
1274-
if (!llvm::hlsl::rootsig::verifyDescriptorRangeFlag(
1275-
Version, llvm::dxbc::DescriptorRangeType::SRV,
1276-
llvm::to_underlying(Clause->Flags)))
1277-
ReportFlagError(Loc);
1278-
break;
1279-
case llvm::dxil::ResourceClass::UAV:
1280-
if (!llvm::hlsl::rootsig::verifyDescriptorRangeFlag(
1281-
Version, llvm::dxbc::DescriptorRangeType::UAV,
1282-
llvm::to_underlying(Clause->Flags)))
1283-
ReportFlagError(Loc);
1284-
break;
1285-
case llvm::dxil::ResourceClass::CBuffer:
1286-
if (!llvm::hlsl::rootsig::verifyDescriptorRangeFlag(
1287-
Version, llvm::dxbc::DescriptorRangeType::CBV,
1288-
llvm::to_underlying(Clause->Flags)))
1289-
ReportFlagError(Loc);
1290-
break;
1291-
case llvm::dxil::ResourceClass::Sampler:
1292-
if (!llvm::hlsl::rootsig::verifyDescriptorRangeFlag(
1293-
Version, llvm::dxbc::DescriptorRangeType::Sampler,
1294-
llvm::to_underlying(Clause->Flags)))
1295-
ReportFlagError(Loc);
1296-
break;
1297-
break;
1298-
}
1272+
if (!llvm::hlsl::rootsig::verifyDescriptorRangeFlag(
1273+
Version, llvm::to_underlying(Clause->Type),
1274+
llvm::to_underlying(Clause->Flags)))
1275+
ReportFlagError(Loc);
12991276
}
13001277
}
13011278

llvm/include/llvm/BinaryFormat/DXContainer.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -209,16 +209,6 @@ inline bool isValidParameterType(uint32_t V) {
209209
return false;
210210
}
211211

212-
#define DESCRIPTOR_RANGE(Val, Enum) \
213-
case Val: \
214-
return true;
215-
inline bool isValidRangeType(uint32_t V) {
216-
switch (V) {
217-
#include "DXContainerConstants.def"
218-
}
219-
return false;
220-
}
221-
222212
#define SHADER_VISIBILITY(Val, Enum) Enum = Val,
223213
enum class ShaderVisibility : uint32_t {
224214
#include "DXContainerConstants.def"

llvm/include/llvm/Frontend/HLSL/RootSignatureValidations.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ LLVM_ABI bool verifyRegisterValue(uint32_t RegisterValue);
3030
LLVM_ABI bool verifyRegisterSpace(uint32_t RegisterSpace);
3131
LLVM_ABI bool verifyRootDescriptorFlag(uint32_t Version, uint32_t FlagsVal);
3232
LLVM_ABI bool verifyRangeType(uint32_t Type);
33-
LLVM_ABI bool verifyDescriptorRangeFlag(uint32_t Version,
34-
dxbc::DescriptorRangeType Type,
33+
LLVM_ABI bool verifyDescriptorRangeFlag(uint32_t Version, uint32_t Type,
3534
uint32_t FlagsVal);
3635
LLVM_ABI bool verifyNumDescriptors(uint32_t NumDescriptors);
3736
LLVM_ABI bool verifySamplerFilter(uint32_t Value);

llvm/include/llvm/MC/DXContainerRootSignature.h

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,6 @@ struct RootDescriptor {
3131
uint32_t Flags;
3232
};
3333

34-
struct DescriptorRange {
35-
dxbc::DescriptorRangeType RangeType;
36-
uint32_t NumDescriptors;
37-
uint32_t BaseShaderRegister;
38-
uint32_t RegisterSpace;
39-
uint32_t Flags;
40-
uint32_t OffsetInDescriptorsFromTableStart;
41-
};
42-
4334
struct RootParameterInfo {
4435
dxbc::RootParameterType Type;
4536
dxbc::ShaderVisibility Visibility;
@@ -51,11 +42,11 @@ struct RootParameterInfo {
5142
};
5243

5344
struct DescriptorTable {
54-
SmallVector<DescriptorRange> Ranges;
55-
SmallVector<DescriptorRange>::const_iterator begin() const {
45+
SmallVector<dxbc::RTS0::v2::DescriptorRange> Ranges;
46+
SmallVector<dxbc::RTS0::v2::DescriptorRange>::const_iterator begin() const {
5647
return Ranges.begin();
5748
}
58-
SmallVector<DescriptorRange>::const_iterator end() const {
49+
SmallVector<dxbc::RTS0::v2::DescriptorRange>::const_iterator end() const {
5950
return Ranges.end();
6051
}
6152
};

llvm/lib/BinaryFormat/DXContainer.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -149,16 +149,6 @@ ArrayRef<EnumEntry<RootParameterType>> dxbc::getRootParameterTypes() {
149149
return ArrayRef(RootParameterTypes);
150150
}
151151

152-
#define DESCRIPTOR_RANGE(Val, Enum) {#Enum, DescriptorRangeType::Enum},
153-
154-
static const EnumEntry<DescriptorRangeType> DescriptorRangeTypes[] = {
155-
#include "llvm/BinaryFormat/DXContainerConstants.def"
156-
};
157-
158-
ArrayRef<EnumEntry<DescriptorRangeType>> dxbc::getDescriptorRangeTypes() {
159-
return ArrayRef(DescriptorRangeTypes);
160-
}
161-
162152
#define SEMANTIC_KIND(Val, Enum) {#Enum, PSV::SemanticKind::Enum},
163153

164154
static const EnumEntry<PSV::SemanticKind> SemanticKindNames[] = {

llvm/lib/Frontend/HLSL/RootSignatureMetadata.cpp

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -325,19 +325,25 @@ Error MetadataParser::parseDescriptorRange(mcdxbc::DescriptorTable &Table,
325325
if (RangeDescriptorNode->getNumOperands() != 6)
326326
return make_error<InvalidRSMetadataFormat>("Descriptor Range");
327327

328-
mcdxbc::DescriptorRange Range;
328+
dxbc::RTS0::v2::DescriptorRange Range;
329329

330330
std::optional<StringRef> ElementText =
331331
extractMdStringValue(RangeDescriptorNode, 0);
332332

333333
if (!ElementText.has_value())
334334
return make_error<InvalidRSMetadataFormat>("Descriptor Range");
335335

336-
Range.RangeType = StringSwitch<dxbc::DescriptorRangeType>(*ElementText)
337-
.Case("CBV", dxbc::DescriptorRangeType::CBV)
338-
.Case("SRV", dxbc::DescriptorRangeType::SRV)
339-
.Case("UAV", dxbc::DescriptorRangeType::UAV)
340-
.Case("Sampler", dxbc::DescriptorRangeType::Sampler);
336+
Range.RangeType =
337+
StringSwitch<uint32_t>(*ElementText)
338+
.Case("CBV", to_underlying(dxbc::DescriptorRangeType::CBV))
339+
.Case("SRV", to_underlying(dxbc::DescriptorRangeType::SRV))
340+
.Case("UAV", to_underlying(dxbc::DescriptorRangeType::UAV))
341+
.Case("Sampler", to_underlying(dxbc::DescriptorRangeType::Sampler))
342+
.Default(~0U);
343+
344+
if (Range.RangeType == ~0U)
345+
return make_error<GenericRSMetadataError>("Invalid Descriptor Range type.",
346+
RangeDescriptorNode);
341347

342348
if (std::optional<uint32_t> Val = extractMdIntValue(RangeDescriptorNode, 1))
343349
Range.NumDescriptors = *Val;
@@ -565,7 +571,12 @@ Error MetadataParser::validateRootSignature(
565571
case dxbc::RootParameterType::DescriptorTable: {
566572
const mcdxbc::DescriptorTable &Table =
567573
RSD.ParametersContainer.getDescriptorTable(Info.Location);
568-
for (const mcdxbc::DescriptorRange &Range : Table) {
574+
for (const dxbc::RTS0::v2::DescriptorRange &Range : Table) {
575+
if (!hlsl::rootsig::verifyRangeType(Range.RangeType))
576+
DeferredErrs =
577+
joinErrors(std::move(DeferredErrs),
578+
make_error<RootSignatureValidationError<uint32_t>>(
579+
"RangeType", Range.RangeType));
569580

570581
if (!hlsl::rootsig::verifyRegisterSpace(Range.RegisterSpace))
571582
DeferredErrs =

llvm/lib/Frontend/HLSL/RootSignatureValidations.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,13 @@ bool verifyRangeType(uint32_t Type) {
6363
return false;
6464
}
6565

66-
bool verifyDescriptorRangeFlag(uint32_t Version, dxbc::DescriptorRangeType Type,
66+
bool verifyDescriptorRangeFlag(uint32_t Version, uint32_t Type,
6767
uint32_t FlagsVal) {
6868
using FlagT = dxbc::DescriptorRangeFlags;
6969
FlagT Flags = FlagT(FlagsVal);
7070

71-
const bool IsSampler = (Type == dxbc::DescriptorRangeType::Sampler);
71+
const bool IsSampler =
72+
(Type == llvm::to_underlying(dxbc::DescriptorRangeType::Sampler));
7273

7374
if (Version == 1) {
7475
// Since the metadata is unversioned, we expect to explicitly see the values

llvm/lib/ObjectYAML/DXContainerEmitter.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -315,10 +315,9 @@ void DXContainerWriter::writeParts(raw_ostream &OS) {
315315
P.RootSignature->Parameters.getOrInsertTable(L);
316316
mcdxbc::DescriptorTable Table;
317317
for (const auto &R : TableYaml.Ranges) {
318-
assert(dxbc::isValidRangeType(R.RangeType) &&
319-
"Invalid Descriptor Range Type");
320-
mcdxbc::DescriptorRange Range;
321-
Range.RangeType = dxbc::DescriptorRangeType(R.RangeType);
318+
319+
dxbc::RTS0::v2::DescriptorRange Range;
320+
Range.RangeType = R.RangeType;
322321
Range.NumDescriptors = R.NumDescriptors;
323322
Range.BaseShaderRegister = R.BaseShaderRegister;
324323
Range.RegisterSpace = R.RegisterSpace;

llvm/lib/Target/DirectX/DXILPostOptimizationValidation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ static void validateRootSignature(Module &M,
194194
const mcdxbc::DescriptorTable &Table =
195195
RSD.ParametersContainer.getDescriptorTable(ParamInfo.Location);
196196

197-
for (const mcdxbc::DescriptorRange &Range : Table.Ranges) {
197+
for (const dxbc::RTS0::v2::DescriptorRange &Range : Table.Ranges) {
198198
uint32_t UpperBound =
199199
Range.NumDescriptors == ~0U
200200
? Range.BaseShaderRegister

llvm/lib/Target/DirectX/DXILRootSignature.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,8 @@ PreservedAnalyses RootSignatureAnalysisPrinter::run(Module &M,
205205
RS.ParametersContainer.getDescriptorTable(Loc);
206206
OS << " NumRanges: " << Table.Ranges.size() << "\n";
207207

208-
for (const mcdxbc::DescriptorRange Range : Table) {
209-
OS << " - Range Type: "
210-
<< enumToStringRef(Range.RangeType,
211-
dxbc::getDescriptorRangeTypes())
212-
<< "\n"
208+
for (const dxbc::RTS0::v2::DescriptorRange Range : Table) {
209+
OS << " - Range Type: " << Range.RangeType << "\n"
213210
<< " Register Space: " << Range.RegisterSpace << "\n"
214211
<< " Base Shader Register: " << Range.BaseShaderRegister << "\n"
215212
<< " Num Descriptors: " << Range.NumDescriptors << "\n"

0 commit comments

Comments
 (0)