Skip to content

Commit 0996bfc

Browse files
authored
[HLSL][RootSignature] Add space, visibility enums to StaticSampler (llvm#140306)
- adds the `space` and `visibility` parameters to StaticSampler - adds basic unit tests to demonstrate setting functionality Part 7 and Resolves llvm#126574
1 parent 9cdd33d commit 0996bfc

File tree

4 files changed

+50
-1
lines changed

4 files changed

+50
-1
lines changed

clang/include/clang/Parse/ParseHLSLRootSignature.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ class RootSignatureParser {
120120
std::optional<llvm::hlsl::rootsig::StaticBorderColor> BorderColor;
121121
std::optional<float> MinLOD;
122122
std::optional<float> MaxLOD;
123+
std::optional<uint32_t> Space;
124+
std::optional<llvm::hlsl::rootsig::ShaderVisibility> Visibility;
123125
};
124126
std::optional<ParsedStaticSamplerParams> parseStaticSamplerParams();
125127

clang/lib/Parse/ParseHLSLRootSignature.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,12 @@ std::optional<StaticSampler> RootSignatureParser::parseStaticSampler() {
404404
if (Params->MaxLOD.has_value())
405405
Sampler.MaxLOD = Params->MaxLOD.value();
406406

407+
if (Params->Space.has_value())
408+
Sampler.Space = Params->Space.value();
409+
410+
if (Params->Visibility.has_value())
411+
Sampler.Visibility = Params->Visibility.value();
412+
407413
if (consumeExpectedToken(TokenKind::pu_r_paren,
408414
diag::err_hlsl_unexpected_end_of_params,
409415
/*param of=*/TokenKind::kw_StaticSampler))
@@ -842,6 +848,40 @@ RootSignatureParser::parseStaticSamplerParams() {
842848
return std::nullopt;
843849
Params.MaxLOD = MaxLOD;
844850
}
851+
852+
// `space` `=` POS_INT
853+
if (tryConsumeExpectedToken(TokenKind::kw_space)) {
854+
if (Params.Space.has_value()) {
855+
getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_repeat_param)
856+
<< CurToken.TokKind;
857+
return std::nullopt;
858+
}
859+
860+
if (consumeExpectedToken(TokenKind::pu_equal))
861+
return std::nullopt;
862+
863+
auto Space = parseUIntParam();
864+
if (!Space.has_value())
865+
return std::nullopt;
866+
Params.Space = Space;
867+
}
868+
869+
// `visibility` `=` SHADER_VISIBILITY
870+
if (tryConsumeExpectedToken(TokenKind::kw_visibility)) {
871+
if (Params.Visibility.has_value()) {
872+
getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_repeat_param)
873+
<< CurToken.TokKind;
874+
return std::nullopt;
875+
}
876+
877+
if (consumeExpectedToken(TokenKind::pu_equal))
878+
return std::nullopt;
879+
880+
auto Visibility = parseShaderVisibility();
881+
if (!Visibility.has_value())
882+
return std::nullopt;
883+
Params.Visibility = Visibility;
884+
}
845885
} while (tryConsumeExpectedToken(TokenKind::pu_comma));
846886

847887
return Params;

clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseDTClausesTest) {
226226
TEST_F(ParseHLSLRootSignatureTest, ValidParseStaticSamplerTest) {
227227
const llvm::StringLiteral Source = R"cc(
228228
StaticSampler(s0),
229-
StaticSampler(s0, maxAnisotropy = 3,
229+
StaticSampler(s0, maxAnisotropy = 3, space = 4,
230+
visibility = SHADER_VISIBILITY_DOMAIN,
230231
minLOD = 4.2f, mipLODBias = 0.23e+3,
231232
addressW = TEXTURE_ADDRESS_CLAMP,
232233
addressV = TEXTURE_ADDRESS_BORDER,
@@ -266,6 +267,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseStaticSamplerTest) {
266267
StaticBorderColor::OpaqueWhite);
267268
ASSERT_FLOAT_EQ(std::get<StaticSampler>(Elem).MinLOD, 0.f);
268269
ASSERT_FLOAT_EQ(std::get<StaticSampler>(Elem).MaxLOD, 3.402823466e+38f);
270+
ASSERT_EQ(std::get<StaticSampler>(Elem).Space, 0u);
271+
ASSERT_EQ(std::get<StaticSampler>(Elem).Visibility, ShaderVisibility::All);
269272

270273
// Check values can be set as expected
271274
Elem = Elements[1];
@@ -282,6 +285,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseStaticSamplerTest) {
282285
StaticBorderColor::OpaqueBlackUint);
283286
ASSERT_FLOAT_EQ(std::get<StaticSampler>(Elem).MinLOD, 4.2f);
284287
ASSERT_FLOAT_EQ(std::get<StaticSampler>(Elem).MaxLOD, 9000.f);
288+
ASSERT_EQ(std::get<StaticSampler>(Elem).Space, 4u);
289+
ASSERT_EQ(std::get<StaticSampler>(Elem).Visibility, ShaderVisibility::Domain);
285290

286291
ASSERT_TRUE(Consumer->isSatisfied());
287292
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ struct StaticSampler {
193193
StaticBorderColor BorderColor = StaticBorderColor::OpaqueWhite;
194194
float MinLOD = 0.f;
195195
float MaxLOD = std::numeric_limits<float>::max();
196+
uint32_t Space = 0;
197+
ShaderVisibility Visibility = ShaderVisibility::All;
196198
};
197199

198200
/// Models RootElement : RootFlags | RootConstants | RootParam

0 commit comments

Comments
 (0)