Skip to content

[HLSL][RootSignature] Add space, visibility enums to StaticSampler #140306

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: users/inbelic/pr-140305
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions clang/include/clang/Parse/ParseHLSLRootSignature.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ class RootSignatureParser {
std::optional<llvm::hlsl::rootsig::StaticBorderColor> BorderColor;
std::optional<float> MinLOD;
std::optional<float> MaxLOD;
std::optional<uint32_t> Space;
std::optional<llvm::hlsl::rootsig::ShaderVisibility> Visibility;
};
std::optional<ParsedStaticSamplerParams> parseStaticSamplerParams();

Expand Down
40 changes: 40 additions & 0 deletions clang/lib/Parse/ParseHLSLRootSignature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,12 @@ std::optional<StaticSampler> RootSignatureParser::parseStaticSampler() {
if (Params->MaxLOD.has_value())
Sampler.MaxLOD = Params->MaxLOD.value();

if (Params->Space.has_value())
Sampler.Space = Params->Space.value();

if (Params->Visibility.has_value())
Sampler.Visibility = Params->Visibility.value();

if (consumeExpectedToken(TokenKind::pu_r_paren,
diag::err_hlsl_unexpected_end_of_params,
/*param of=*/TokenKind::kw_StaticSampler))
Expand Down Expand Up @@ -866,6 +872,40 @@ RootSignatureParser::parseStaticSamplerParams() {
return std::nullopt;
Params.MaxLOD = MaxLOD;
}

// `space` `=` POS_INT
if (tryConsumeExpectedToken(TokenKind::kw_space)) {
if (Params.Space.has_value()) {
getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_repeat_param)
<< CurToken.TokKind;
return std::nullopt;
}

if (consumeExpectedToken(TokenKind::pu_equal))
return std::nullopt;

auto Space = parseUIntParam();
if (!Space.has_value())
return std::nullopt;
Params.Space = Space;
}

// `visibility` `=` SHADER_VISIBILITY
if (tryConsumeExpectedToken(TokenKind::kw_visibility)) {
if (Params.Visibility.has_value()) {
getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_repeat_param)
<< CurToken.TokKind;
return std::nullopt;
}

if (consumeExpectedToken(TokenKind::pu_equal))
return std::nullopt;

auto Visibility = parseShaderVisibility();
if (!Visibility.has_value())
return std::nullopt;
Params.Visibility = Visibility;
}
} while (tryConsumeExpectedToken(TokenKind::pu_comma));

return Params;
Expand Down
7 changes: 6 additions & 1 deletion clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseDTClausesTest) {
TEST_F(ParseHLSLRootSignatureTest, ValidParseStaticSamplerTest) {
const llvm::StringLiteral Source = R"cc(
StaticSampler(s0),
StaticSampler(s0, maxAnisotropy = 3,
StaticSampler(s0, maxAnisotropy = 3, space = 4,
visibility = SHADER_VISIBILITY_DOMAIN,
minLOD = 4.2f, mipLODBias = 0.23e+3,
addressW = TEXTURE_ADDRESS_CLAMP,
addressV = TEXTURE_ADDRESS_BORDER,
Expand Down Expand Up @@ -269,6 +270,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseStaticSamplerTest) {
StaticBorderColor::OpaqueWhite);
ASSERT_EQ(std::get<StaticSampler>(Elem).MinLOD, 0.f);
ASSERT_EQ(std::get<StaticSampler>(Elem).MaxLOD, 3.402823466e+38f);
ASSERT_EQ(std::get<StaticSampler>(Elem).Space, 0u);
ASSERT_EQ(std::get<StaticSampler>(Elem).Visibility, ShaderVisibility::All);

// Check values can be set as expected
Elem = Elements[1];
Expand All @@ -288,6 +291,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseStaticSamplerTest) {
StaticBorderColor::OpaqueBlackUint);
ASSERT_EQ(std::get<StaticSampler>(Elem).MinLOD, 4.2f);
ASSERT_EQ(std::get<StaticSampler>(Elem).MaxLOD, 9000.f);
ASSERT_EQ(std::get<StaticSampler>(Elem).Space, 4u);
ASSERT_EQ(std::get<StaticSampler>(Elem).Visibility, ShaderVisibility::Domain);

ASSERT_TRUE(Consumer->isSatisfied());
}
Expand Down
2 changes: 2 additions & 0 deletions llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ struct StaticSampler {
StaticBorderColor BorderColor = StaticBorderColor::OpaqueWhite;
float MinLOD = 0.f;
float MaxLOD = 3.402823466e+38f; // FLT_MAX
uint32_t Space = 0;
ShaderVisibility Visibility = ShaderVisibility::All;
};

/// Models RootElement : RootFlags | RootConstants | RootParam
Expand Down