Skip to content

Commit d0eaf35

Browse files
committed
add basic float range validations
1 parent 603aeac commit d0eaf35

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,6 +1093,14 @@ bool SemaHLSL::handleRootSignatureElements(
10931093
<< LowerBound << UpperBound;
10941094
};
10951095

1096+
auto ReportFloatError = [this, &HadError](SourceLocation Loc,
1097+
float LowerBound,
1098+
float UpperBound) {
1099+
HadError = true;
1100+
this->Diag(Loc, diag::err_hlsl_invalid_rootsig_value)
1101+
<< std::to_string(LowerBound) << std::to_string(UpperBound);
1102+
};
1103+
10961104
auto VerifyRegister = [ReportError](SourceLocation Loc, uint32_t Register) {
10971105
if (!llvm::hlsl::rootsig::verifyRegisterValue(Register))
10981106
ReportError(Loc, 0, 0xfffffffe);
@@ -1126,6 +1134,8 @@ bool SemaHLSL::handleRootSignatureElements(
11261134

11271135
if (16 < Sampler->MaxAnisotropy)
11281136
ReportError(Loc, 0, 16);
1137+
if (!llvm::hlsl::rootsig::verifyMipLODBias(Sampler->MipLODBias))
1138+
ReportFloatError(Loc, -16.f, 15.99);
11291139
} else if (const auto *Clause =
11301140
std::get_if<llvm::hlsl::rootsig::DescriptorTableClause>(
11311141
&Elem)) {

clang/test/SemaHLSL/RootSignature-err.hlsl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ void basic_validation_3() {}
6666
[RootSignature("DescriptorTable(UAV(u0, numDescriptors = 0), Sampler(s0, numDescriptors = 0))")]
6767
void basic_validation_4() {}
6868

69-
// expected-error@+1 {{value must be in the range [0, 16]}}
69+
// expected-error@+2 {{value must be in the range [0, 16]}}
70+
// expected-error@+1 {{value must be in the range [-16.000000, 15.990000]}}
7071
[RootSignature("StaticSampler(s0, maxAnisotropy = 17, mipLODBias = -16.000001)")]
7172
void basic_validation_5() {}
73+
74+
// expected-error@+1 {{value must be in the range [-16.000000, 15.990000]}}
75+
[RootSignature("StaticSampler(s0, mipLODBias = 15.990001)")]
76+
void basic_validation_6() {}

0 commit comments

Comments
 (0)