[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Add space, visibility enums to StaticSampler (PR #140306)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Fri May 16 14:00:24 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-hlsl
Author: Finn Plummer (inbelic)
<details>
<summary>Changes</summary>
- adds the `space` and `visibility` parameters to StaticSampler
- adds basic unit tests to demonstrate setting functionality
Part 7 and Resolves https://github.com/llvm/llvm-project/issues/126574
---
Full diff: https://github.com/llvm/llvm-project/pull/140306.diff
4 Files Affected:
- (modified) clang/include/clang/Parse/ParseHLSLRootSignature.h (+2)
- (modified) clang/lib/Parse/ParseHLSLRootSignature.cpp (+40)
- (modified) clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp (+6-1)
- (modified) llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h (+2)
``````````diff
diff --git a/clang/include/clang/Parse/ParseHLSLRootSignature.h b/clang/include/clang/Parse/ParseHLSLRootSignature.h
index 21df9d0da4a53..34d59d7fb66f4 100644
--- a/clang/include/clang/Parse/ParseHLSLRootSignature.h
+++ b/clang/include/clang/Parse/ParseHLSLRootSignature.h
@@ -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();
diff --git a/clang/lib/Parse/ParseHLSLRootSignature.cpp b/clang/lib/Parse/ParseHLSLRootSignature.cpp
index 07bd10d00dfad..bd0f9abb5ff1b 100644
--- a/clang/lib/Parse/ParseHLSLRootSignature.cpp
+++ b/clang/lib/Parse/ParseHLSLRootSignature.cpp
@@ -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))
@@ -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;
diff --git a/clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp b/clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp
index 6343d9feb4411..3eede0dbed61b 100644
--- a/clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp
+++ b/clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp
@@ -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,
@@ -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];
@@ -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());
}
diff --git a/llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h b/llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h
index 025e96ec93c2a..ee65722e68556 100644
--- a/llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h
+++ b/llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h
@@ -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
``````````
</details>
https://github.com/llvm/llvm-project/pull/140306
More information about the llvm-branch-commits
mailing list