Skip to content

Commit 79bb0f6

Browse files
committed
add parsing of borderColor
1 parent 469c039 commit 79bb0f6

File tree

4 files changed

+63
-1
lines changed

4 files changed

+63
-1
lines changed

clang/include/clang/Parse/ParseHLSLRootSignature.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ class RootSignatureParser {
117117
std::optional<llvm::hlsl::rootsig::TextureAddressMode> AddressW;
118118
std::optional<uint32_t> MaxAnisotropy;
119119
std::optional<llvm::hlsl::rootsig::ComparisonFunc> ComparisonFunc;
120+
std::optional<llvm::hlsl::rootsig::StaticBorderColor> BorderColor;
120121
std::optional<float> MinLOD;
121122
std::optional<float> MaxLOD;
122123
};
@@ -132,6 +133,8 @@ class RootSignatureParser {
132133
std::optional<llvm::hlsl::rootsig::TextureAddressMode>
133134
parseTextureAddressMode();
134135
std::optional<llvm::hlsl::rootsig::ComparisonFunc> parseComparisonFunc();
136+
std::optional<llvm::hlsl::rootsig::StaticBorderColor>
137+
parseStaticBorderColor();
135138
std::optional<llvm::hlsl::rootsig::RootDescriptorFlags>
136139
parseRootDescriptorFlags();
137140
std::optional<llvm::hlsl::rootsig::DescriptorRangeFlags>

clang/lib/Parse/ParseHLSLRootSignature.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,9 @@ std::optional<StaticSampler> RootSignatureParser::parseStaticSampler() {
395395
if (Params->ComparisonFunc.has_value())
396396
Sampler.ComparisonFunc= Params->ComparisonFunc.value();
397397

398+
if (Params->BorderColor.has_value())
399+
Sampler.BorderColor= Params->BorderColor.value();
400+
398401
if (Params->MinLOD.has_value())
399402
Sampler.MinLOD = Params->MinLOD.value();
400403

@@ -790,6 +793,24 @@ RootSignatureParser::parseStaticSamplerParams() {
790793
Params.ComparisonFunc = ComparisonFunc;
791794
}
792795

796+
797+
// `borderColor` `=` STATIC_BORDER_COLOR
798+
if (tryConsumeExpectedToken(TokenKind::kw_borderColor)) {
799+
if (Params.BorderColor.has_value()) {
800+
getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_repeat_param)
801+
<< CurToken.TokKind;
802+
return std::nullopt;
803+
}
804+
805+
if (consumeExpectedToken(TokenKind::pu_equal))
806+
return std::nullopt;
807+
808+
auto BorderColor = parseStaticBorderColor();
809+
if (!BorderColor.has_value())
810+
return std::nullopt;
811+
Params.BorderColor = BorderColor;
812+
}
813+
793814
// `minLOD` `=` NUMBER
794815
if (tryConsumeExpectedToken(TokenKind::kw_minLOD)) {
795816
if (Params.MinLOD.has_value()) {
@@ -982,6 +1003,32 @@ RootSignatureParser::parseComparisonFunc() {
9821003
return std::nullopt;
9831004
}
9841005

1006+
std::optional<llvm::hlsl::rootsig::StaticBorderColor>
1007+
RootSignatureParser::parseStaticBorderColor() {
1008+
assert(CurToken.TokKind == TokenKind::pu_equal &&
1009+
"Expects to only be invoked starting at given keyword");
1010+
1011+
TokenKind Expected[] = {
1012+
#define STATIC_BORDER_COLOR_ENUM(NAME, LIT) TokenKind::en_##NAME,
1013+
#include "clang/Lex/HLSLRootSignatureTokenKinds.def"
1014+
};
1015+
1016+
if (!tryConsumeExpectedToken(Expected))
1017+
return std::nullopt;
1018+
1019+
switch (CurToken.TokKind) {
1020+
#define STATIC_BORDER_COLOR_ENUM(NAME, LIT) \
1021+
case TokenKind::en_##NAME: \
1022+
return StaticBorderColor::NAME; \
1023+
break;
1024+
#include "clang/Lex/HLSLRootSignatureTokenKinds.def"
1025+
default:
1026+
llvm_unreachable("Switch for consumed enum token was not provided");
1027+
}
1028+
1029+
return std::nullopt;
1030+
}
1031+
9851032
std::optional<llvm::hlsl::rootsig::RootDescriptorFlags>
9861033
RootSignatureParser::parseRootDescriptorFlags() {
9871034
assert(CurToken.TokKind == TokenKind::pu_equal &&

clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseStaticSamplerTest) {
231231
addressW = TEXTURE_ADDRESS_CLAMP,
232232
addressV = TEXTURE_ADDRESS_BORDER,
233233
maxLOD = 9000, addressU = TEXTURE_ADDRESS_MIRROR,
234-
comparisonFunc = COMPARISON_NOT_EQUAL
234+
comparisonFunc = COMPARISON_NOT_EQUAL,
235+
borderColor = STATIC_BORDER_COLOR_OPAQUE_BLACK_UINT
235236
)
236237
)cc";
237238

@@ -261,6 +262,7 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseStaticSamplerTest) {
261262
ASSERT_FLOAT_EQ(std::get<StaticSampler>(Elem).MipLODBias, 0.f);
262263
ASSERT_EQ(std::get<StaticSampler>(Elem).MaxAnisotropy, 16u);
263264
ASSERT_EQ(std::get<StaticSampler>(Elem).ComparisonFunc, ComparisonFunc::LessEqual);
265+
ASSERT_EQ(std::get<StaticSampler>(Elem).BorderColor, StaticBorderColor::OpaqueWhite);
264266
ASSERT_FLOAT_EQ(std::get<StaticSampler>(Elem).MinLOD, 0.f);
265267
ASSERT_FLOAT_EQ(std::get<StaticSampler>(Elem).MaxLOD, 3.402823466e+38f);
266268

@@ -276,6 +278,7 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseStaticSamplerTest) {
276278
ASSERT_EQ(std::get<StaticSampler>(Elem).MaxAnisotropy, 3u);
277279
ASSERT_EQ(std::get<StaticSampler>(Elem).ComparisonFunc,
278280
ComparisonFunc::NotEqual);
281+
ASSERT_EQ(std::get<StaticSampler>(Elem).BorderColor, StaticBorderColor::OpaqueBlackUint);
279282
ASSERT_FLOAT_EQ(std::get<StaticSampler>(Elem).MinLOD, 4.2f);
280283
ASSERT_FLOAT_EQ(std::get<StaticSampler>(Elem).MaxLOD, 9000.f);
281284

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,14 @@ enum class ComparisonFunc : unsigned {
9595
Always = 8
9696
};
9797

98+
enum class StaticBorderColor {
99+
TransparentBlack = 0,
100+
OpaqueBlack = 1,
101+
OpaqueWhite = 2,
102+
OpaqueBlackUint = 3,
103+
OpaqueWhiteUint = 4
104+
};
105+
98106
// Definitions of the in-memory data layout structures
99107

100108
// Models the different registers: bReg | tReg | uReg | sReg
@@ -182,6 +190,7 @@ struct StaticSampler {
182190
float MipLODBias = 0.f;
183191
uint32_t MaxAnisotropy = 16;
184192
ComparisonFunc ComparisonFunc = ComparisonFunc::LessEqual;
193+
StaticBorderColor BorderColor = StaticBorderColor::OpaqueWhite;
185194
float MinLOD = 0.f;
186195
float MaxLOD = std::numeric_limits<float>::max();
187196
};

0 commit comments

Comments
 (0)