Skip to content

Commit 182c817

Browse files
committed
removing binary format descriptor range dependency
1 parent 19ec1c3 commit 182c817

File tree

12 files changed

+82
-57
lines changed

12 files changed

+82
-57
lines changed

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,11 +1282,34 @@ bool SemaHLSL::handleRootSignatureElements(
12821282
// value
12831283
ReportError(Loc, 1, 0xfffffffe);
12841284
}
1285+
switch (Clause->Type) {
12851286

1286-
if (!llvm::hlsl::rootsig::verifyDescriptorRangeFlag(
1287-
Version, llvm::to_underlying(Clause->Type),
1288-
llvm::to_underlying(Clause->Flags)))
1289-
ReportFlagError(Loc);
1287+
case llvm::dxil::ResourceClass::SRV:
1288+
if (!llvm::hlsl::rootsig::verifyDescriptorRangeFlag(
1289+
Version, llvm::dxbc::DescriptorRangeType::SRV,
1290+
llvm::to_underlying(Clause->Flags)))
1291+
ReportFlagError(Loc);
1292+
break;
1293+
case llvm::dxil::ResourceClass::UAV:
1294+
if (!llvm::hlsl::rootsig::verifyDescriptorRangeFlag(
1295+
Version, llvm::dxbc::DescriptorRangeType::UAV,
1296+
llvm::to_underlying(Clause->Flags)))
1297+
ReportFlagError(Loc);
1298+
break;
1299+
case llvm::dxil::ResourceClass::CBuffer:
1300+
if (!llvm::hlsl::rootsig::verifyDescriptorRangeFlag(
1301+
Version, llvm::dxbc::DescriptorRangeType::CBV,
1302+
llvm::to_underlying(Clause->Flags)))
1303+
ReportFlagError(Loc);
1304+
break;
1305+
case llvm::dxil::ResourceClass::Sampler:
1306+
if (!llvm::hlsl::rootsig::verifyDescriptorRangeFlag(
1307+
Version, llvm::dxbc::DescriptorRangeType::Sampler,
1308+
llvm::to_underlying(Clause->Flags)))
1309+
ReportFlagError(Loc);
1310+
break;
1311+
break;
1312+
}
12901313
}
12911314
}
12921315

llvm/include/llvm/BinaryFormat/DXContainer.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,16 @@ 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+
212222
#define SHADER_VISIBILITY(Val, Enum) Enum = Val,
213223
enum class ShaderVisibility : uint32_t {
214224
#include "DXContainerConstants.def"

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ 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, uint32_t Type,
33+
LLVM_ABI bool verifyDescriptorRangeFlag(uint32_t Version,
34+
dxbc::DescriptorRangeType Type,
3435
uint32_t FlagsVal);
3536
LLVM_ABI bool verifyNumDescriptors(uint32_t NumDescriptors);
3637
LLVM_ABI bool verifySamplerFilter(uint32_t Value);

llvm/include/llvm/MC/DXContainerRootSignature.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ 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+
3443
struct RootParameterInfo {
3544
dxbc::RootParameterType Type;
3645
dxbc::ShaderVisibility Visibility;
@@ -42,11 +51,11 @@ struct RootParameterInfo {
4251
};
4352

4453
struct DescriptorTable {
45-
SmallVector<dxbc::RTS0::v2::DescriptorRange> Ranges;
46-
SmallVector<dxbc::RTS0::v2::DescriptorRange>::const_iterator begin() const {
54+
SmallVector<DescriptorRange> Ranges;
55+
SmallVector<DescriptorRange>::const_iterator begin() const {
4756
return Ranges.begin();
4857
}
49-
SmallVector<dxbc::RTS0::v2::DescriptorRange>::const_iterator end() const {
58+
SmallVector<DescriptorRange>::const_iterator end() const {
5059
return Ranges.end();
5160
}
5261
};

llvm/lib/BinaryFormat/DXContainer.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,16 @@ 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+
152162
#define SEMANTIC_KIND(Val, Enum) {#Enum, PSV::SemanticKind::Enum},
153163

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

llvm/lib/Frontend/HLSL/RootSignatureMetadata.cpp

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

325-
dxbc::RTS0::v2::DescriptorRange Range;
325+
mcdxbc::DescriptorRange Range;
326326

327327
std::optional<StringRef> ElementText =
328328
extractMdStringValue(RangeDescriptorNode, 0);
329329

330330
if (!ElementText.has_value())
331331
return make_error<InvalidRSMetadataFormat>("Descriptor Range");
332332

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

345339
if (std::optional<uint32_t> Val = extractMdIntValue(RangeDescriptorNode, 1))
346340
Range.NumDescriptors = *Val;
@@ -568,12 +562,7 @@ Error MetadataParser::validateRootSignature(
568562
case dxbc::RootParameterType::DescriptorTable: {
569563
const mcdxbc::DescriptorTable &Table =
570564
RSD.ParametersContainer.getDescriptorTable(Info.Location);
571-
for (const dxbc::RTS0::v2::DescriptorRange &Range : Table) {
572-
if (!hlsl::rootsig::verifyRangeType(Range.RangeType))
573-
DeferredErrs =
574-
joinErrors(std::move(DeferredErrs),
575-
make_error<RootSignatureValidationError<uint32_t>>(
576-
"RangeType", Range.RangeType));
565+
for (const mcdxbc::DescriptorRange &Range : Table) {
577566

578567
if (!hlsl::rootsig::verifyRegisterSpace(Range.RegisterSpace))
579568
DeferredErrs =

llvm/lib/Frontend/HLSL/RootSignatureValidations.cpp

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

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

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

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

llvm/lib/ObjectYAML/DXContainerEmitter.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,10 @@ Error DXContainerWriter::writeParts(raw_ostream &OS) {
313313
P.RootSignature->Parameters.getOrInsertTable(L);
314314
mcdxbc::DescriptorTable Table;
315315
for (const auto &R : TableYaml.Ranges) {
316-
317-
dxbc::RTS0::v2::DescriptorRange Range;
318-
Range.RangeType = R.RangeType;
316+
assert(dxbc::isValidRangeType(R.RangeType) &&
317+
"Invalid Descriptor Range Type");
318+
mcdxbc::DescriptorRange Range;
319+
Range.RangeType = dxbc::DescriptorRangeType(R.RangeType);
319320
Range.NumDescriptors = R.NumDescriptors;
320321
Range.BaseShaderRegister = R.BaseShaderRegister;
321322
Range.RegisterSpace = R.RegisterSpace;

llvm/lib/Target/DirectX/DXILPostOptimizationValidation.cpp

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

208-
for (const dxbc::RTS0::v2::DescriptorRange &Range : Table.Ranges) {
208+
for (const mcdxbc::DescriptorRange &Range : Table.Ranges) {
209209
uint32_t UpperBound =
210210
Range.NumDescriptors == ~0U
211211
? Range.BaseShaderRegister

llvm/lib/Target/DirectX/DXILRootSignature.cpp

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

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

0 commit comments

Comments
 (0)