Skip to content

Commit 17dbe9f

Browse files
committed
refactoring to use dxil::ResourceClass for range type
1 parent e065a82 commit 17dbe9f

File tree

12 files changed

+17
-88
lines changed

12 files changed

+17
-88
lines changed

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,20 +1241,6 @@ bool SemaHLSL::handleRootSignatureElements(
12411241
<< /*version minor*/ VersionEnum;
12421242
};
12431243

1244-
auto toDescriptorRangeType = [](llvm::dxil::ResourceClass Type) {
1245-
switch (Type) {
1246-
case llvm::dxil::ResourceClass::SRV:
1247-
return llvm::dxbc::DescriptorRangeType::SRV;
1248-
case llvm::dxil::ResourceClass::UAV:
1249-
return llvm::dxbc::DescriptorRangeType::UAV;
1250-
case llvm::dxil::ResourceClass::CBuffer:
1251-
return llvm::dxbc::DescriptorRangeType::CBV;
1252-
case llvm::dxil::ResourceClass::Sampler:
1253-
return llvm::dxbc::DescriptorRangeType::Sampler;
1254-
}
1255-
llvm_unreachable("Unhandled Resource Class");
1256-
};
1257-
12581244
// Iterate through the elements and do basic validations
12591245
for (const hlsl::RootSignatureElement &RootSigElem : Elements) {
12601246
SourceLocation Loc = RootSigElem.getLocation();
@@ -1297,8 +1283,8 @@ bool SemaHLSL::handleRootSignatureElements(
12971283
ReportError(Loc, 1, 0xfffffffe);
12981284
}
12991285

1300-
if (!llvm::hlsl::rootsig::verifyDescriptorRangeFlag(
1301-
Version, toDescriptorRangeType(Clause->Type), Clause->Flags))
1286+
if (!llvm::hlsl::rootsig::verifyDescriptorRangeFlag(Version, Clause->Type,
1287+
Clause->Flags))
13021288
ReportFlagError(Loc);
13031289
}
13041290
}

llvm/include/llvm/BinaryFormat/DXContainer.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -209,14 +209,8 @@ inline bool isValidParameterType(uint32_t V) {
209209
return false;
210210
}
211211

212-
#define DESCRIPTOR_RANGE(Val, Enum) \
213-
case Val: \
214-
return true;
215212
inline bool isValidRangeType(uint32_t V) {
216-
switch (V) {
217-
#include "DXContainerConstants.def"
218-
}
219-
return false;
213+
return V <= llvm::to_underlying(dxil::ResourceClass::Sampler);
220214
}
221215

222216
#define SHADER_VISIBILITY(Val, Enum) Enum = Val,

llvm/include/llvm/BinaryFormat/DXContainerConstants.def

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,6 @@ DESCRIPTOR_RANGE_FLAG(0x10000, DescriptorsStaticKeepingBufferBoundsChecks, DESCR
104104
#undef DESCRIPTOR_RANGE_FLAG
105105
#endif // DESCRIPTOR_RANGE_FLAG
106106

107-
// DESCRIPTOR_RANGE(value, name).
108-
#ifdef DESCRIPTOR_RANGE
109-
110-
DESCRIPTOR_RANGE(0, SRV)
111-
DESCRIPTOR_RANGE(1, UAV)
112-
DESCRIPTOR_RANGE(2, CBV)
113-
DESCRIPTOR_RANGE(3, Sampler)
114-
#undef DESCRIPTOR_RANGE
115-
#endif // DESCRIPTOR_RANGE
116-
117107
#ifdef ROOT_PARAMETER
118108

119109
ROOT_PARAMETER(0, DescriptorTable)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ 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);
3333
LLVM_ABI bool verifyDescriptorRangeFlag(uint32_t Version,
34-
dxbc::DescriptorRangeType Type,
34+
dxil::ResourceClass Type,
3535
dxbc::DescriptorRangeFlags FlagsVal);
3636
LLVM_ABI bool verifyNumDescriptors(uint32_t NumDescriptors);
3737
LLVM_ABI bool verifySamplerFilter(uint32_t Value);

llvm/include/llvm/MC/DXContainerRootSignature.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ struct RootDescriptor {
3232
};
3333

3434
struct DescriptorRange {
35-
dxbc::DescriptorRangeType RangeType;
35+
dxil::ResourceClass RangeType;
3636
uint32_t NumDescriptors;
3737
uint32_t BaseShaderRegister;
3838
uint32_t RegisterSpace;

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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -331,13 +331,13 @@ Error MetadataParser::parseDescriptorRange(mcdxbc::DescriptorTable &Table,
331331
return make_error<InvalidRSMetadataFormat>("Descriptor Range");
332332

333333
if (*ElementText == "CBV")
334-
Range.RangeType = dxbc::DescriptorRangeType::CBV;
334+
Range.RangeType = dxil::ResourceClass::CBuffer;
335335
else if (*ElementText == "SRV")
336-
Range.RangeType = dxbc::DescriptorRangeType::SRV;
336+
Range.RangeType = dxil::ResourceClass::SRV;
337337
else if (*ElementText == "UAV")
338-
Range.RangeType = dxbc::DescriptorRangeType::UAV;
338+
Range.RangeType = dxil::ResourceClass::UAV;
339339
else if (*ElementText == "Sampler")
340-
Range.RangeType = dxbc::DescriptorRangeType::Sampler;
340+
Range.RangeType = dxil::ResourceClass::Sampler;
341341
else
342342
return make_error<GenericRSMetadataError>("Invalid Descriptor Range type.",
343343
RangeDescriptorNode);

llvm/lib/Frontend/HLSL/RootSignatureValidations.cpp

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,23 +51,11 @@ bool verifyRootDescriptorFlag(uint32_t Version, uint32_t FlagsVal) {
5151
return (Flags | DataFlags) == DataFlags;
5252
}
5353

54-
bool verifyRangeType(uint32_t Type) {
55-
switch (Type) {
56-
case llvm::to_underlying(dxbc::DescriptorRangeType::CBV):
57-
case llvm::to_underlying(dxbc::DescriptorRangeType::SRV):
58-
case llvm::to_underlying(dxbc::DescriptorRangeType::UAV):
59-
case llvm::to_underlying(dxbc::DescriptorRangeType::Sampler):
60-
return true;
61-
};
62-
63-
return false;
64-
}
65-
66-
bool verifyDescriptorRangeFlag(uint32_t Version, dxbc::DescriptorRangeType Type,
54+
bool verifyDescriptorRangeFlag(uint32_t Version, dxil::ResourceClass Type,
6755
dxbc::DescriptorRangeFlags Flags) {
6856
using FlagT = dxbc::DescriptorRangeFlags;
6957

70-
const bool IsSampler = (Type == dxbc::DescriptorRangeType::Sampler);
58+
const bool IsSampler = (Type == dxil::ResourceClass::Sampler);
7159

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

llvm/lib/MC/DXContainerRootSignature.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ void RootSignatureDesc::write(raw_ostream &OS) const {
137137
llvm::endianness::little);
138138
rewriteOffsetToCurrentByte(BOS, writePlaceholder(BOS));
139139
for (const auto &Range : Table) {
140-
support::endian::write(BOS, Range.RangeType, llvm::endianness::little);
140+
support::endian::write(BOS, (uint32_t)Range.RangeType,
141+
llvm::endianness::little);
141142
support::endian::write(BOS, Range.NumDescriptors,
142143
llvm::endianness::little);
143144
support::endian::write(BOS, Range.BaseShaderRegister,

llvm/lib/ObjectYAML/DXContainerEmitter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ Error DXContainerWriter::writeParts(raw_ostream &OS) {
316316
assert(dxbc::isValidRangeType(R.RangeType) &&
317317
"Invalid Descriptor Range Type");
318318
mcdxbc::DescriptorRange Range;
319-
Range.RangeType = dxbc::DescriptorRangeType(R.RangeType);
319+
Range.RangeType = dxil::ResourceClass(R.RangeType);
320320
Range.NumDescriptors = R.NumDescriptors;
321321
Range.BaseShaderRegister = R.BaseShaderRegister;
322322
Range.RegisterSpace = R.RegisterSpace;

0 commit comments

Comments
 (0)