Flutter Impeller
shader_types_unittests.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "flutter/testing/testing.h"
7 
8 namespace impeller {
9 namespace testing {
10 namespace {
11 
12 // Builds a vertex input slot with the fields that drive the format derivation.
13 ShaderStageIOSlot MakeSlot(ShaderType type,
14  size_t bit_width,
15  size_t vec_size,
16  size_t columns = 1u) {
17  return ShaderStageIOSlot{
18  "test", // name
19  0u, // location
20  0u, // set
21  0u, // binding
22  type, // type
23  bit_width, vec_size, columns,
24  0u, // offset
25  false, // relaxed_precision
26  };
27 }
28 
29 } // namespace
30 
31 TEST(ShaderTypesTest, VertexAttributeFormatFloat32) {
32  EXPECT_EQ(MakeSlot(ShaderType::kFloat, 32u, 1u).GetVertexAttributeFormat(),
34  EXPECT_EQ(MakeSlot(ShaderType::kFloat, 32u, 2u).GetVertexAttributeFormat(),
36  EXPECT_EQ(MakeSlot(ShaderType::kFloat, 32u, 3u).GetVertexAttributeFormat(),
38  EXPECT_EQ(MakeSlot(ShaderType::kFloat, 32u, 4u).GetVertexAttributeFormat(),
40 }
41 
42 TEST(ShaderTypesTest, VertexAttributeFormatHalfFloat) {
43  EXPECT_EQ(
44  MakeSlot(ShaderType::kHalfFloat, 16u, 1u).GetVertexAttributeFormat(),
46  EXPECT_EQ(
47  MakeSlot(ShaderType::kHalfFloat, 16u, 4u).GetVertexAttributeFormat(),
49 }
50 
51 TEST(ShaderTypesTest, VertexAttributeFormatIntegers) {
52  EXPECT_EQ(
53  MakeSlot(ShaderType::kSignedByte, 8u, 1u).GetVertexAttributeFormat(),
55  EXPECT_EQ(
56  MakeSlot(ShaderType::kUnsignedByte, 8u, 4u).GetVertexAttributeFormat(),
58  EXPECT_EQ(
59  MakeSlot(ShaderType::kSignedShort, 16u, 2u).GetVertexAttributeFormat(),
61  EXPECT_EQ(
62  MakeSlot(ShaderType::kUnsignedShort, 16u, 3u).GetVertexAttributeFormat(),
64  EXPECT_EQ(
65  MakeSlot(ShaderType::kSignedInt, 32u, 1u).GetVertexAttributeFormat(),
67  EXPECT_EQ(
68  MakeSlot(ShaderType::kUnsignedInt, 32u, 4u).GetVertexAttributeFormat(),
70 }
71 
72 TEST(ShaderTypesTest, VertexAttributeFormatRejectsMatrices) {
73  // Columns greater than one is a matrix input, which is unsupported.
74  EXPECT_EQ(MakeSlot(ShaderType::kFloat, 32u, 4u, /*columns=*/4u)
75  .GetVertexAttributeFormat(),
77 }
78 
79 TEST(ShaderTypesTest, VertexAttributeFormatRejectsBadComponentCount) {
80  EXPECT_EQ(MakeSlot(ShaderType::kFloat, 32u, 0u).GetVertexAttributeFormat(),
82  EXPECT_EQ(MakeSlot(ShaderType::kFloat, 32u, 5u).GetVertexAttributeFormat(),
84 }
85 
86 TEST(ShaderTypesTest, VertexAttributeFormatRejectsBadBitWidth) {
87  EXPECT_EQ(MakeSlot(ShaderType::kFloat, 16u, 1u).GetVertexAttributeFormat(),
89  EXPECT_EQ(
90  MakeSlot(ShaderType::kSignedInt, 16u, 1u).GetVertexAttributeFormat(),
92 }
93 
94 TEST(ShaderTypesTest, VertexAttributeFormatRejectsUnsupportedScalarKinds) {
95  EXPECT_EQ(MakeSlot(ShaderType::kBoolean, 8u, 1u).GetVertexAttributeFormat(),
97  EXPECT_EQ(MakeSlot(ShaderType::kDouble, 64u, 1u).GetVertexAttributeFormat(),
99  EXPECT_EQ(
100  MakeSlot(ShaderType::kSignedInt64, 64u, 1u).GetVertexAttributeFormat(),
102 }
103 
104 } // namespace testing
105 } // namespace impeller
uint32_t vec_size
uint32_t columns
TEST(AllocationSizeTest, CanCreateTypedAllocations)