Skip to content

Commit e8e074a

Browse files
committed
add support for custom parameter parsing - DescriptorRangeOffset
1 parent 75271b5 commit e8e074a

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
@@ -135,6 +135,7 @@ class RootSignatureParser {
135135
// Common parsing helpers
136136
bool ParseRegister(rs::Register *Reg);
137137
bool ParseUInt(uint32_t *X);
138+
bool ParseDescriptorRangeOffset(rs::DescriptorRangeOffset *X);
138139

139140
// Increment the token iterator if we have not reached the end.
140141
// 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
@@ -322,6 +322,7 @@ bool RootSignatureParser::ParseDescriptorTableClause() {
322322
llvm::SmallDenseMap<TokenKind, rs::ParamType> RefMap = {
323323
{TokenKind::kw_numDescriptors, &Clause.NumDescriptors},
324324
{TokenKind::kw_space, &Clause.Space},
325+
{TokenKind::kw_offset, &Clause.Offset},
325326
};
326327
if (ParseOptionalParams({RefMap}))
327328
return true;
@@ -345,6 +346,9 @@ bool RootSignatureParser::ParseParam(ParamType Ref) {
345346

346347
bool Error;
347348
std::visit(OverloadedMethods{[&](uint32_t *X) { Error = ParseUInt(X); },
349+
[&](DescriptorRangeOffset *X) {
350+
Error = ParseDescriptorRangeOffset(X);
351+
},
348352
}, Ref);
349353

350354
return Error;
@@ -378,6 +382,21 @@ bool RootSignatureParser::ParseOptionalParams(
378382
return false;
379383
}
380384

385+
bool RootSignatureParser::ParseDescriptorRangeOffset(DescriptorRangeOffset *X) {
386+
if (ConsumeExpectedToken(
387+
{TokenKind::int_literal, TokenKind::en_DescriptorRangeOffsetAppend}))
388+
return true;
389+
390+
// Edge case for the offset enum -> static value
391+
if (CurTok->Kind == TokenKind::en_DescriptorRangeOffsetAppend) {
392+
*X = DescriptorTableOffsetAppend;
393+
return false;
394+
}
395+
396+
*X = DescriptorRangeOffset(CurTok->NumLiteral.getInt().getExtValue());
397+
return false;
398+
}
399+
381400
bool RootSignatureParser::ParseUInt(uint32_t *X) {
382401
if (ConsumeExpectedToken(TokenKind::int_literal))
383402
return true;

clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseDTClausesTest) {
336336
const llvm::StringLiteral Source = R"cc(
337337
DescriptorTable(
338338
CBV(b0),
339-
SRV(t42, space = 3, numDescriptors = 4),
340-
Sampler(s987, space = 2),
339+
SRV(t42, space = 3, offset = 32, numDescriptors = 4),
340+
Sampler(s987, space = 2, offset = DESCRIPTOR_RANGE_OFFSET_APPEND),
341341
UAV(u987234)
342342
),
343343
DescriptorTable()
@@ -367,6 +367,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseDTClausesTest) {
367367
ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Register.Number, (uint32_t)0);
368368
ASSERT_EQ(std::get<DescriptorTableClause>(Elem).NumDescriptors, (uint32_t)1);
369369
ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Space, (uint32_t)0);
370+
ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Offset,
371+
DescriptorRangeOffset(DescriptorTableOffsetAppend));
370372

371373
Elem = Elements[1];
372374
ASSERT_TRUE(std::holds_alternative<DescriptorTableClause>(Elem));
@@ -377,6 +379,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseDTClausesTest) {
377379
(uint32_t)42);
378380
ASSERT_EQ(std::get<DescriptorTableClause>(Elem).NumDescriptors, (uint32_t)4);
379381
ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Space, (uint32_t)3);
382+
ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Offset,
383+
DescriptorRangeOffset(32));
380384

381385
Elem = Elements[2];
382386
ASSERT_TRUE(std::holds_alternative<DescriptorTableClause>(Elem));
@@ -387,6 +391,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseDTClausesTest) {
387391
(uint32_t)987);
388392
ASSERT_EQ(std::get<DescriptorTableClause>(Elem).NumDescriptors, (uint32_t)1);
389393
ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Space, (uint32_t)2);
394+
ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Offset,
395+
DescriptorRangeOffset(DescriptorTableOffsetAppend));
390396

391397
Elem = Elements[3];
392398
ASSERT_TRUE(std::holds_alternative<DescriptorTableClause>(Elem));
@@ -397,6 +403,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseDTClausesTest) {
397403
(uint32_t)987234);
398404
ASSERT_EQ(std::get<DescriptorTableClause>(Elem).NumDescriptors, (uint32_t)1);
399405
ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Space, (uint32_t)0);
406+
ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Offset,
407+
DescriptorRangeOffset(DescriptorTableOffsetAppend));
400408

401409
Elem = Elements[4];
402410
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)