Skip to content

Commit f434cae

Browse files
committed
pre-req: add parsing of MipLODBias as an uint
- defines a float data member of StaticSampler that will be used to test functionality of parsing a float
1 parent f9fbe39 commit f434cae

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

clang/include/clang/Parse/ParseHLSLRootSignature.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ class RootSignatureParser {
111111

112112
struct ParsedStaticSamplerParams {
113113
std::optional<llvm::hlsl::rootsig::Register> Reg;
114+
std::optional<float> MipLODBias;
114115
};
115116
std::optional<ParsedStaticSamplerParams> parseStaticSamplerParams();
116117

clang/lib/Parse/ParseHLSLRootSignature.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,10 @@ std::optional<StaticSampler> RootSignatureParser::parseStaticSampler() {
378378

379379
Sampler.Reg = Params->Reg.value();
380380

381+
// Fill in optional values
382+
if (Params->MipLODBias.has_value())
383+
Sampler.MipLODBias = Params->MipLODBias.value();
384+
381385
if (consumeExpectedToken(TokenKind::pu_r_paren,
382386
diag::err_hlsl_unexpected_end_of_params,
383387
/*param of=*/TokenKind::kw_StaticSampler))
@@ -663,6 +667,23 @@ RootSignatureParser::parseStaticSamplerParams() {
663667
return std::nullopt;
664668
Params.Reg = Reg;
665669
}
670+
671+
// `mipLODBias` `=` NUMBER
672+
if (tryConsumeExpectedToken(TokenKind::kw_mipLODBias)) {
673+
if (Params.MipLODBias.has_value()) {
674+
getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_repeat_param)
675+
<< CurToken.TokKind;
676+
return std::nullopt;
677+
}
678+
679+
if (consumeExpectedToken(TokenKind::pu_equal))
680+
return std::nullopt;
681+
682+
auto MipLODBias = parseUIntParam();
683+
if (!MipLODBias.has_value())
684+
return std::nullopt;
685+
Params.MipLODBias = (float)*MipLODBias;
686+
}
666687
} while (tryConsumeExpectedToken(TokenKind::pu_comma));
667688

668689
return Params;

clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseDTClausesTest) {
225225

226226
TEST_F(ParseHLSLRootSignatureTest, ValidParseStaticSamplerTest) {
227227
const llvm::StringLiteral Source = R"cc(
228-
StaticSampler(s0)
228+
StaticSampler(s0, mipLODBias = 0)
229229
)cc";
230230

231231
TrivialModuleLoader ModLoader;
@@ -247,6 +247,7 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseStaticSamplerTest) {
247247
ASSERT_TRUE(std::holds_alternative<StaticSampler>(Elem));
248248
ASSERT_EQ(std::get<StaticSampler>(Elem).Reg.ViewType, RegisterType::SReg);
249249
ASSERT_EQ(std::get<StaticSampler>(Elem).Reg.Number, 0u);
250+
ASSERT_EQ(std::get<StaticSampler>(Elem).MipLODBias, 0u);
250251

251252
ASSERT_TRUE(Consumer->isSatisfied());
252253
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ struct DescriptorTableClause {
160160

161161
struct StaticSampler {
162162
Register Reg;
163+
float MipLODBias = 0.f;
163164
};
164165

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

0 commit comments

Comments
 (0)