Skip to content

Commit 90156db

Browse files
authored
Fix lerp throwing errors for half types (KhronosGroup#6293)
1 parent f1aa20b commit 90156db

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

source/opt/const_folding_rules.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1395,9 +1395,12 @@ ConstantFoldingRule FoldFMix() {
13951395
if (base_type->AsFloat()->width() == 32) {
13961396
one = const_mgr->GetConstant(base_type,
13971397
utils::FloatProxy<float>(1.0f).GetWords());
1398-
} else {
1398+
} else if (base_type->AsFloat()->width() == 64) {
13991399
one = const_mgr->GetConstant(base_type,
14001400
utils::FloatProxy<double>(1.0).GetWords());
1401+
} else {
1402+
// We won't support folding half types.
1403+
return nullptr;
14011404
}
14021405

14031406
if (is_vector) {

test/opt/fold_test.cpp

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ TEST_P(IntegerInstructionFoldingTest, Case) {
211211
#define UINT_0_ID 109
212212
#define INT_NULL_ID 110
213213
#define UINT_NULL_ID 111
214+
#define HALF_3_ID 112
214215
const std::string& Header() {
215216
static const std::string header = R"(OpCapability Shader
216217
OpCapability Float16
@@ -405,8 +406,11 @@ OpName %main "main"
405406
%v2double_2_0p5 = OpConstantComposite %v2double %double_2 %double_0p5
406407
%v2double_null = OpConstantNull %v2double
407408
%108 = OpConstant %half 0
409+
%half_0p5 = OpConstant %half 0.5
408410
%half_1 = OpConstant %half 1
409411
%half_2 = OpConstant %half 2
412+
%112 = OpConstant %half 3
413+
%half_null = OpConstantNull %half
410414
%half_0_1 = OpConstantComposite %v2half %108 %half_1
411415
%106 = OpConstantComposite %v4float %float_0 %float_0 %float_0 %float_0
412416
%v4float_0_0_0_0 = OpConstantComposite %v4float %float_0 %float_0 %float_0 %float_0
@@ -1683,7 +1687,7 @@ TEST_P(FloatVectorInstructionFoldingTest, Case) {
16831687
// clang-format off
16841688
INSTANTIATE_TEST_SUITE_P(TestCase, FloatVectorInstructionFoldingTest,
16851689
::testing::Values(
1686-
// Test case 0: FMix {2.0, 2.0}, {2.0, 3.0} {0.2,0.5}
1690+
// Test case 0: FMix {2.0, 3.0}, {0.0, 0.0} {0.2,0.5}
16871691
InstructionFoldingCase<std::vector<float>>(
16881692
Header() + "%main = OpFunction %void None %void_func\n" +
16891693
"%main_lab = OpLabel\n" +
@@ -4930,6 +4934,38 @@ INSTANTIATE_TEST_SUITE_P(FloatRedundantFoldingTest, GeneralInstructionFoldingTes
49304934
"%2 = OpMatrixTimesScalar %float_coop_matrix %undef_float_coop_matrix %float_3\n" +
49314935
"OpReturn\n" +
49324936
"OpFunctionEnd",
4937+
2, 0),
4938+
// Test case 32: Don't fold FMix half (1.0, 2.0, 0.5)
4939+
InstructionFoldingCase<uint32_t>(
4940+
Header() + "%main = OpFunction %void None %void_func\n" +
4941+
"%main_lab = OpLabel\n" +
4942+
"%2 = OpExtInst %half %1 FMix %half_1 %half_2 %half_0p5\n" +
4943+
"OpReturn\n" +
4944+
"OpFunctionEnd",
4945+
2, 0),
4946+
// Test case 33: Fold FMix half (3.0, 2.0, 0.0)
4947+
InstructionFoldingCase<uint32_t>(
4948+
Header() + "%main = OpFunction %void None %void_func\n" +
4949+
"%main_lab = OpLabel\n" +
4950+
"%2 = OpExtInst %half %1 FMix %112 %half_2 %108\n" +
4951+
"OpReturn\n" +
4952+
"OpFunctionEnd",
4953+
2, HALF_3_ID),
4954+
// Test case 34: Fold FMix half (3.0, 2.0, null)
4955+
InstructionFoldingCase<uint32_t>(
4956+
Header() + "%main = OpFunction %void None %void_func\n" +
4957+
"%main_lab = OpLabel\n" +
4958+
"%2 = OpExtInst %half %1 FMix %112 %half_2 %half_null\n" +
4959+
"OpReturn\n" +
4960+
"OpFunctionEnd",
4961+
2, HALF_3_ID),
4962+
// Test case 35: Don't fold FMix half (1.0, 2.0, 1.0)
4963+
InstructionFoldingCase<uint32_t>(
4964+
Header() + "%main = OpFunction %void None %void_func\n" +
4965+
"%main_lab = OpLabel\n" +
4966+
"%2 = OpExtInst %half %1 FMix %half_1 %half_2 %half_1\n" +
4967+
"OpReturn\n" +
4968+
"OpFunctionEnd",
49334969
2, 0)
49344970
));
49354971

0 commit comments

Comments
 (0)