Skip to content

Commit 20bec7f

Browse files
committed
add support for custom parameter parsing - DescriptorRangeOffset
1 parent 5545d2a commit 20bec7f

File tree

4 files changed

+38
-3
lines changed

4 files changed

+38
-3
lines changed

clang/include/clang/Parse/ParseHLSLRootSignature.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ class RootSignatureParser {
122122
// Common parsing helpers
123123
bool ParseRegister(rs::Register *Reg);
124124
bool ParseUInt(uint32_t *X);
125+
bool ParseDescriptorRangeOffset(rs::DescriptorRangeOffset *X);
125126

126127
// Increment the token iterator if we have not reached the end.
127128
// Return value denotes if we were already at the last token.

clang/lib/Parse/ParseHLSLRootSignature.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ bool RootSignatureParser::ParseDescriptorTableClause() {
329329
llvm::SmallDenseMap<TokenKind, rs::ParamType> RefMap = {
330330
{TokenKind::kw_numDescriptors, &Clause.NumDescriptors},
331331
{TokenKind::kw_space, &Clause.Space},
332+
{TokenKind::kw_offset, &Clause.Offset},
332333
};
333334
if (ParseOptionalParams({RefMap}))
334335
return true;
@@ -352,6 +353,9 @@ bool RootSignatureParser::ParseParam(ParamType Ref) {
352353

353354
bool Error;
354355
std::visit(OverloadedMethods{[&](uint32_t *X) { Error = ParseUInt(X); },
356+
[&](DescriptorRangeOffset *X) {
357+
Error = ParseDescriptorRangeOffset(X);
358+
},
355359
}, Ref);
356360

357361
return Error;
@@ -385,6 +389,21 @@ bool RootSignatureParser::ParseOptionalParams(
385389
return false;
386390
}
387391

392+
bool RootSignatureParser::ParseDescriptorRangeOffset(DescriptorRangeOffset *X) {
393+
if (ConsumeExpectedToken(
394+
{TokenKind::int_literal, TokenKind::en_DescriptorRangeOffsetAppend}))
395+
return true;
396+
397+
// Edge case for the offset enum -> static value
398+
if (CurTok->Kind == TokenKind::en_DescriptorRangeOffsetAppend) {
399+
*X = DescriptorTableOffsetAppend;
400+
return false;
401+
}
402+
403+
*X = DescriptorRangeOffset(CurTok->NumLiteral.getInt().getExtValue());
404+
return false;
405+
}
406+
388407
bool RootSignatureParser::ParseUInt(uint32_t *X) {
389408
if (ConsumeExpectedToken(TokenKind::int_literal))
390409
return true;

clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseDTClausesTest) {
309309
const llvm::StringLiteral Source = R"cc(
310310
DescriptorTable(
311311
CBV(b0),
312-
SRV(t42, space = 3, numDescriptors = 4),
313-
Sampler(s987, space = 2),
312+
SRV(t42, space = 3, offset = 32, numDescriptors = 4),
313+
Sampler(s987, space = 2, offset = DESCRIPTOR_RANGE_OFFSET_APPEND),
314314
UAV(u987234)
315315
),
316316
DescriptorTable()
@@ -340,6 +340,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseDTClausesTest) {
340340
ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Register.Number, (uint32_t)0);
341341
ASSERT_EQ(std::get<DescriptorTableClause>(Elem).NumDescriptors, (uint32_t)1);
342342
ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Space, (uint32_t)0);
343+
ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Offset,
344+
DescriptorRangeOffset(DescriptorTableOffsetAppend));
343345

344346
Elem = Elements[1];
345347
ASSERT_TRUE(std::holds_alternative<DescriptorTableClause>(Elem));
@@ -350,6 +352,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseDTClausesTest) {
350352
(uint32_t)42);
351353
ASSERT_EQ(std::get<DescriptorTableClause>(Elem).NumDescriptors, (uint32_t)4);
352354
ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Space, (uint32_t)3);
355+
ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Offset,
356+
DescriptorRangeOffset(32));
353357

354358
Elem = Elements[2];
355359
ASSERT_TRUE(std::holds_alternative<DescriptorTableClause>(Elem));
@@ -360,6 +364,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseDTClausesTest) {
360364
(uint32_t)987);
361365
ASSERT_EQ(std::get<DescriptorTableClause>(Elem).NumDescriptors, (uint32_t)1);
362366
ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Space, (uint32_t)2);
367+
ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Offset,
368+
DescriptorRangeOffset(DescriptorTableOffsetAppend));
363369

364370
Elem = Elements[3];
365371
ASSERT_TRUE(std::holds_alternative<DescriptorTableClause>(Elem));
@@ -370,6 +376,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseDTClausesTest) {
370376
(uint32_t)987234);
371377
ASSERT_EQ(std::get<DescriptorTableClause>(Elem).NumDescriptors, (uint32_t)1);
372378
ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Space, (uint32_t)0);
379+
ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Offset,
380+
DescriptorRangeOffset(DescriptorTableOffsetAppend));
373381

374382
Elem = Elements[4];
375383
ASSERT_TRUE(std::holds_alternative<DescriptorTable>(Elem));

llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ namespace llvm {
2121
namespace hlsl {
2222
namespace root_signature {
2323

24+
// Definition of the various enumerations and flags
25+
26+
enum class DescriptorRangeOffset : uint32_t;
27+
2428
// Definitions of the in-memory data layout structures
2529

2630
// Models the different registers: bReg | tReg | uReg | sReg
@@ -35,21 +39,24 @@ struct DescriptorTable {
3539
uint32_t NumClauses = 0; // The number of clauses in the table
3640
};
3741

42+
static const DescriptorRangeOffset DescriptorTableOffsetAppend =
43+
DescriptorRangeOffset(0xffffffff);
3844
// Models DTClause : CBV | SRV | UAV | Sampler, by collecting like parameters
3945
using ClauseType = llvm::dxil::ResourceClass;
4046
struct DescriptorTableClause {
4147
ClauseType Type;
4248
Register Register;
4349
uint32_t NumDescriptors = 1;
4450
uint32_t Space = 0;
51+
DescriptorRangeOffset Offset = DescriptorTableOffsetAppend;
4552
};
4653

4754
// Models RootElement : DescriptorTable | DescriptorTableClause
4855
using RootElement = std::variant<DescriptorTable, DescriptorTableClause>;
4956

5057
// Models a reference to all assignment parameter types that any RootElement
5158
// may have. Things of the form: Keyword = Param
52-
using ParamType = std::variant<uint32_t *>;
59+
using ParamType = std::variant<uint32_t *, DescriptorRangeOffset *>;
5360
} // namespace root_signature
5461
} // namespace hlsl
5562
} // namespace llvm

0 commit comments

Comments
 (0)