Skip to content

Commit 80f2606

Browse files
committed
add parsing of borderColor
1 parent 60127c8 commit 80f2606

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
@@ -118,6 +118,7 @@ class RootSignatureParser {
118118
std::optional<float> MipLODBias;
119119
std::optional<uint32_t> MaxAnisotropy;
120120
std::optional<llvm::hlsl::rootsig::ComparisonFunc> ComparisonFunc;
121+
std::optional<llvm::hlsl::rootsig::StaticBorderColor> BorderColor;
121122
std::optional<float> MinLOD;
122123
std::optional<float> MaxLOD;
123124
};
@@ -134,6 +135,8 @@ class RootSignatureParser {
134135
std::optional<llvm::hlsl::rootsig::TextureAddressMode>
135136
parseTextureAddressMode();
136137
std::optional<llvm::hlsl::rootsig::ComparisonFunc> parseComparisonFunc();
138+
std::optional<llvm::hlsl::rootsig::StaticBorderColor>
139+
parseStaticBorderColor();
137140
std::optional<llvm::hlsl::rootsig::RootDescriptorFlags>
138141
parseRootDescriptorFlags();
139142
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
@@ -402,6 +402,9 @@ std::optional<StaticSampler> RootSignatureParser::parseStaticSampler() {
402402
if (Params->ComparisonFunc.has_value())
403403
Sampler.ComparisonFunc= Params->ComparisonFunc.value();
404404

405+
if (Params->BorderColor.has_value())
406+
Sampler.BorderColor= Params->BorderColor.value();
407+
405408
if (Params->MinLOD.has_value())
406409
Sampler.MinLOD = Params->MinLOD.value();
407410

@@ -814,6 +817,24 @@ RootSignatureParser::parseStaticSamplerParams() {
814817
Params.ComparisonFunc = ComparisonFunc;
815818
}
816819

820+
821+
// `borderColor` `=` STATIC_BORDER_COLOR
822+
if (tryConsumeExpectedToken(TokenKind::kw_borderColor)) {
823+
if (Params.BorderColor.has_value()) {
824+
getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_repeat_param)
825+
<< CurToken.TokKind;
826+
return std::nullopt;
827+
}
828+
829+
if (consumeExpectedToken(TokenKind::pu_equal))
830+
return std::nullopt;
831+
832+
auto BorderColor = parseStaticBorderColor();
833+
if (!BorderColor.has_value())
834+
return std::nullopt;
835+
Params.BorderColor = BorderColor;
836+
}
837+
817838
// `minLOD` `=` NUMBER
818839
if (tryConsumeExpectedToken(TokenKind::kw_minLOD)) {
819840
if (Params.MinLOD.has_value()) {
@@ -1027,6 +1048,32 @@ RootSignatureParser::parseComparisonFunc() {
10271048
return std::nullopt;
10281049
}
10291050

1051+
std::optional<llvm::hlsl::rootsig::StaticBorderColor>
1052+
RootSignatureParser::parseStaticBorderColor() {
1053+
assert(CurToken.TokKind == TokenKind::pu_equal &&
1054+
"Expects to only be invoked starting at given keyword");
1055+
1056+
TokenKind Expected[] = {
1057+
#define STATIC_BORDER_COLOR_ENUM(NAME, LIT) TokenKind::en_##NAME,
1058+
#include "clang/Lex/HLSLRootSignatureTokenKinds.def"
1059+
};
1060+
1061+
if (!tryConsumeExpectedToken(Expected))
1062+
return std::nullopt;
1063+
1064+
switch (CurToken.TokKind) {
1065+
#define STATIC_BORDER_COLOR_ENUM(NAME, LIT) \
1066+
case TokenKind::en_##NAME: \
1067+
return StaticBorderColor::NAME; \
1068+
break;
1069+
#include "clang/Lex/HLSLRootSignatureTokenKinds.def"
1070+
default:
1071+
llvm_unreachable("Switch for consumed enum token was not provided");
1072+
}
1073+
1074+
return std::nullopt;
1075+
}
1076+
10301077
std::optional<llvm::hlsl::rootsig::RootDescriptorFlags>
10311078
RootSignatureParser::parseRootDescriptorFlags() {
10321079
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
@@ -232,7 +232,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseStaticSamplerTest) {
232232
addressV = TEXTURE_ADDRESS_BORDER,
233233
filter = FILTER_MAXIMUM_MIN_POINT_MAG_LINEAR_MIP_POINT,
234234
maxLOD = 9000, addressU = TEXTURE_ADDRESS_MIRROR,
235-
comparisonFunc = COMPARISON_NOT_EQUAL
235+
comparisonFunc = COMPARISON_NOT_EQUAL,
236+
borderColor = STATIC_BORDER_COLOR_OPAQUE_BLACK_UINT
236237
)
237238
)cc";
238239

@@ -263,6 +264,7 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseStaticSamplerTest) {
263264
ASSERT_EQ(std::get<StaticSampler>(Elem).MipLODBias, 0.f);
264265
ASSERT_EQ(std::get<StaticSampler>(Elem).MaxAnisotropy, 16u);
265266
ASSERT_EQ(std::get<StaticSampler>(Elem).ComparisonFunc, ComparisonFunc::LessEqual);
267+
ASSERT_EQ(std::get<StaticSampler>(Elem).BorderColor, StaticBorderColor::OpaqueWhite);
266268
ASSERT_EQ(std::get<StaticSampler>(Elem).MinLOD, 0.f);
267269
ASSERT_EQ(std::get<StaticSampler>(Elem).MaxLOD, 3.402823466e+38f);
268270

@@ -280,6 +282,7 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseStaticSamplerTest) {
280282
ASSERT_EQ(std::get<StaticSampler>(Elem).MaxAnisotropy, 3u);
281283
ASSERT_EQ(std::get<StaticSampler>(Elem).ComparisonFunc,
282284
ComparisonFunc::NotEqual);
285+
ASSERT_EQ(std::get<StaticSampler>(Elem).BorderColor, StaticBorderColor::OpaqueBlackUint);
283286
ASSERT_EQ(std::get<StaticSampler>(Elem).MinLOD, 4.2f);
284287
ASSERT_EQ(std::get<StaticSampler>(Elem).MaxLOD, 9000.f);
285288

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,14 @@ enum class ComparisonFunc : unsigned {
134134
Always = 8
135135
};
136136

137+
enum class StaticBorderColor {
138+
TransparentBlack = 0,
139+
OpaqueBlack = 1,
140+
OpaqueWhite = 2,
141+
OpaqueBlackUint = 3,
142+
OpaqueWhiteUint = 4
143+
};
144+
137145
// Definitions of the in-memory data layout structures
138146

139147
// Models the different registers: bReg | tReg | uReg | sReg
@@ -225,6 +233,7 @@ struct StaticSampler {
225233
float MipLODBias = 0.f;
226234
uint32_t MaxAnisotropy = 16;
227235
ComparisonFunc ComparisonFunc = ComparisonFunc::LessEqual;
236+
StaticBorderColor BorderColor = StaticBorderColor::OpaqueWhite;
228237
float MinLOD = 0.f;
229238
float MaxLOD = 3.402823466e+38f; // FLT_MAX
230239
};

0 commit comments

Comments
 (0)