-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[HLSL][RootSiganture] Add parsing of new number params in StaticSampler #140291
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
inbelic
wants to merge
6
commits into
llvm:users/inbelic/pr-140181
Choose a base branch
from
inbelic:inbelic/rs-numbers-sampler
base: users/inbelic/pr-140181
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[HLSL][RootSiganture] Add parsing of new number params in StaticSampler #140291
inbelic
wants to merge
6
commits into
llvm:users/inbelic/pr-140181
from
inbelic:inbelic/rs-numbers-sampler
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-hlsl @llvm/pr-subscribers-clang Author: Finn Plummer (inbelic) Changes
Part 3 of #126574 Full diff: https://github.com/llvm/llvm-project/pull/140291.diff 6 Files Affected:
diff --git a/clang/include/clang/Lex/HLSLRootSignatureTokenKinds.def b/clang/include/clang/Lex/HLSLRootSignatureTokenKinds.def
index 5d16eaa5b72f6..7ca131349fed4 100644
--- a/clang/include/clang/Lex/HLSLRootSignatureTokenKinds.def
+++ b/clang/include/clang/Lex/HLSLRootSignatureTokenKinds.def
@@ -102,6 +102,9 @@ KEYWORD(offset)
// StaticSampler Keywords:
KEYWORD(mipLODBias)
+KEYWORD(maxAnisotropy)
+KEYWORD(minLOD)
+KEYWORD(maxLOD)
// Unbounded Enum:
UNBOUNDED_ENUM(unbounded, "unbounded")
diff --git a/clang/include/clang/Parse/ParseHLSLRootSignature.h b/clang/include/clang/Parse/ParseHLSLRootSignature.h
index c12b022a030ef..e62d5de948a44 100644
--- a/clang/include/clang/Parse/ParseHLSLRootSignature.h
+++ b/clang/include/clang/Parse/ParseHLSLRootSignature.h
@@ -112,6 +112,9 @@ class RootSignatureParser {
struct ParsedStaticSamplerParams {
std::optional<llvm::hlsl::rootsig::Register> Reg;
std::optional<float> MipLODBias;
+ std::optional<uint32_t> MaxAnisotropy;
+ std::optional<float> MinLOD;
+ std::optional<float> MaxLOD;
};
std::optional<ParsedStaticSamplerParams> parseStaticSamplerParams();
diff --git a/clang/lib/Parse/ParseHLSLRootSignature.cpp b/clang/lib/Parse/ParseHLSLRootSignature.cpp
index db2e922160062..04fe8d00f25cd 100644
--- a/clang/lib/Parse/ParseHLSLRootSignature.cpp
+++ b/clang/lib/Parse/ParseHLSLRootSignature.cpp
@@ -384,6 +384,15 @@ std::optional<StaticSampler> RootSignatureParser::parseStaticSampler() {
if (Params->MipLODBias.has_value())
Sampler.MipLODBias = Params->MipLODBias.value();
+ if (Params->MaxAnisotropy.has_value())
+ Sampler.MaxAnisotropy = Params->MaxAnisotropy.value();
+
+ if (Params->MinLOD.has_value())
+ Sampler.MinLOD = Params->MinLOD.value();
+
+ if (Params->MaxLOD.has_value())
+ Sampler.MaxLOD = Params->MaxLOD.value();
+
if (consumeExpectedToken(TokenKind::pu_r_paren,
diag::err_hlsl_unexpected_end_of_params,
/*param of=*/TokenKind::kw_StaticSampler))
@@ -686,6 +695,57 @@ RootSignatureParser::parseStaticSamplerParams() {
return std::nullopt;
Params.MipLODBias = (float)*MipLODBias;
}
+
+ // `maxAnisotropy` `=` POS_INT
+ if (tryConsumeExpectedToken(TokenKind::kw_maxAnisotropy)) {
+ if (Params.MaxAnisotropy.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 MaxAnisotropy = parseUIntParam();
+ if (!MaxAnisotropy.has_value())
+ return std::nullopt;
+ Params.MaxAnisotropy = MaxAnisotropy;
+ }
+
+ // `minLOD` `=` NUMBER
+ if (tryConsumeExpectedToken(TokenKind::kw_minLOD)) {
+ if (Params.MinLOD.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 MinLOD = parseFloatParam();
+ if (!MinLOD.has_value())
+ return std::nullopt;
+ Params.MinLOD = MinLOD;
+ }
+
+ // `maxLOD` `=` NUMBER
+ if (tryConsumeExpectedToken(TokenKind::kw_maxLOD)) {
+ if (Params.MaxLOD.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 MaxLOD = parseFloatParam();
+ if (!MaxLOD.has_value())
+ return std::nullopt;
+ Params.MaxLOD = MaxLOD;
+ }
} while (tryConsumeExpectedToken(TokenKind::pu_comma));
return Params;
diff --git a/clang/unittests/Lex/LexHLSLRootSignatureTest.cpp b/clang/unittests/Lex/LexHLSLRootSignatureTest.cpp
index b610b8f10f8da..575a97e75a05d 100644
--- a/clang/unittests/Lex/LexHLSLRootSignatureTest.cpp
+++ b/clang/unittests/Lex/LexHLSLRootSignatureTest.cpp
@@ -136,7 +136,7 @@ TEST_F(LexHLSLRootSignatureTest, ValidLexAllTokensTest) {
space visibility flags
numDescriptors offset
- mipLODBias
+ mipLODBias maxAnisotropy minLOD maxLOD
unbounded
DESCRIPTOR_RANGE_OFFSET_APPEND
diff --git a/clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp b/clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp
index 539232e0bf2c2..94e0464ddf03b 100644
--- a/clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp
+++ b/clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp
@@ -225,7 +225,11 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseDTClausesTest) {
TEST_F(ParseHLSLRootSignatureTest, ValidParseStaticSamplerTest) {
const llvm::StringLiteral Source = R"cc(
- StaticSampler(s0, mipLODBias = 0)
+ StaticSampler(s0),
+ StaticSampler(s0, maxAnisotropy = 3,
+ minLOD = 4.2f, mipLODBias = 0.23e+3,
+ maxLOD = 9000,
+ )
)cc";
TrivialModuleLoader ModLoader;
@@ -241,13 +245,27 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseStaticSamplerTest) {
ASSERT_FALSE(Parser.parse());
- ASSERT_EQ(Elements.size(), 1u);
+ ASSERT_EQ(Elements.size(), 2u);
+ // Check default values are as expected
RootElement Elem = Elements[0];
ASSERT_TRUE(std::holds_alternative<StaticSampler>(Elem));
ASSERT_EQ(std::get<StaticSampler>(Elem).Reg.ViewType, RegisterType::SReg);
ASSERT_EQ(std::get<StaticSampler>(Elem).Reg.Number, 0u);
ASSERT_EQ(std::get<StaticSampler>(Elem).MipLODBias, 0.f);
+ ASSERT_EQ(std::get<StaticSampler>(Elem).MaxAnisotropy, 16u);
+ ASSERT_EQ(std::get<StaticSampler>(Elem).MinLOD, 0.f);
+ ASSERT_EQ(std::get<StaticSampler>(Elem).MaxLOD, 3.402823466e+38f);
+
+ // Check values can be set as expected
+ Elem = Elements[1];
+ ASSERT_TRUE(std::holds_alternative<StaticSampler>(Elem));
+ ASSERT_EQ(std::get<StaticSampler>(Elem).Reg.ViewType, RegisterType::SReg);
+ ASSERT_EQ(std::get<StaticSampler>(Elem).Reg.Number, 0u);
+ ASSERT_EQ(std::get<StaticSampler>(Elem).MipLODBias, 230.f);
+ ASSERT_EQ(std::get<StaticSampler>(Elem).MaxAnisotropy, 3u);
+ ASSERT_EQ(std::get<StaticSampler>(Elem).MinLOD, 4.2f);
+ ASSERT_EQ(std::get<StaticSampler>(Elem).MaxLOD, 9000.f);
ASSERT_TRUE(Consumer->isSatisfied());
}
diff --git a/llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h b/llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h
index 6b4da48a302bc..8ee58b87f5e49 100644
--- a/llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h
+++ b/llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h
@@ -161,6 +161,9 @@ struct DescriptorTableClause {
struct StaticSampler {
Register Reg;
float MipLODBias = 0.f;
+ uint32_t MaxAnisotropy = 16;
+ float MinLOD = 0.f;
+ float MaxLOD = 3.402823466e+38f; // FLT_MAX
};
/// Models RootElement : RootFlags | RootConstants | RootParam
|
4 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
clang:frontend
Language frontend issues, e.g. anything involving "Sema"
clang
Clang issues not falling into any other category
HLSL
HLSL Language Support
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
maxAnisotropy
,minLOD
andmaxLOD
parseUInt
andparseFloat
respectivelyPart 3 of #126574