Skip to content
Merged
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
3 changes: 3 additions & 0 deletions clang/include/clang/Lex/HLSLRootSignatureTokenKinds.def
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ KEYWORD(offset)

// StaticSampler Keywords:
KEYWORD(mipLODBias)
KEYWORD(maxAnisotropy)
KEYWORD(minLOD)
KEYWORD(maxLOD)

// Unbounded Enum:
UNBOUNDED_ENUM(unbounded, "unbounded")
Expand Down
3 changes: 3 additions & 0 deletions clang/include/clang/Parse/ParseHLSLRootSignature.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
60 changes: 60 additions & 0 deletions clang/lib/Parse/ParseHLSLRootSignature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,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))
Expand Down Expand Up @@ -682,6 +691,57 @@ RootSignatureParser::parseStaticSamplerParams() {
return std::nullopt;
Params.MipLODBias = 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;
Expand Down
2 changes: 1 addition & 1 deletion clang/unittests/Lex/LexHLSLRootSignatureTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ TEST_F(LexHLSLRootSignatureTest, ValidLexAllTokensTest) {
space visibility flags
numDescriptors offset

mipLODBias
mipLODBias maxAnisotropy minLOD maxLOD

unbounded
DESCRIPTOR_RANGE_OFFSET_APPEND
Expand Down
22 changes: 20 additions & 2 deletions clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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_FLOAT_EQ(std::get<StaticSampler>(Elem).MipLODBias, 0.f);
ASSERT_EQ(std::get<StaticSampler>(Elem).MaxAnisotropy, 16u);
ASSERT_FLOAT_EQ(std::get<StaticSampler>(Elem).MinLOD, 0.f);
ASSERT_FLOAT_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_FLOAT_EQ(std::get<StaticSampler>(Elem).MipLODBias, 230.f);
ASSERT_EQ(std::get<StaticSampler>(Elem).MaxAnisotropy, 3u);
ASSERT_FLOAT_EQ(std::get<StaticSampler>(Elem).MinLOD, 4.2f);
ASSERT_FLOAT_EQ(std::get<StaticSampler>(Elem).MaxLOD, 9000.f);

ASSERT_TRUE(Consumer->isSatisfied());
}
Expand Down
3 changes: 3 additions & 0 deletions llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ raw_ostream &operator<<(raw_ostream &OS, const DescriptorTableClause &Clause);
struct StaticSampler {
Register Reg;
float MipLODBias = 0.f;
uint32_t MaxAnisotropy = 16;
float MinLOD = 0.f;
float MaxLOD = std::numeric_limits<float>::max();
};

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