Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
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
7
8namespace impeller {
9namespace testing {
10namespace {
11
12// Builds a vertex input slot with the fields that drive the format derivation.
13ShaderStageIOSlot 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
24 0u, // offset
25 false, // relaxed_precision
26 };
27}
28
29} // namespace
30
31TEST(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
42TEST(ShaderTypesTest, VertexAttributeFormatHalfFloat) {
43 EXPECT_EQ(
44 MakeSlot(ShaderType::kHalfFloat, 16u, 1u).GetVertexAttributeFormat(),
46 EXPECT_EQ(
47 MakeSlot(ShaderType::kHalfFloat, 16u, 4u).GetVertexAttributeFormat(),
49}
50
51TEST(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
72TEST(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
79TEST(ShaderTypesTest, VertexAttributeFormatRejectsBadComponentCount) {
80 EXPECT_EQ(MakeSlot(ShaderType::kFloat, 32u, 0u).GetVertexAttributeFormat(),
82 EXPECT_EQ(MakeSlot(ShaderType::kFloat, 32u, 5u).GetVertexAttributeFormat(),
84}
85
86TEST(ShaderTypesTest, VertexAttributeFormatRejectsBadBitWidth) {
87 EXPECT_EQ(MakeSlot(ShaderType::kFloat, 16u, 1u).GetVertexAttributeFormat(),
89 EXPECT_EQ(
90 MakeSlot(ShaderType::kSignedInt, 16u, 1u).GetVertexAttributeFormat(),
92}
93
94TEST(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(FrameTimingsRecorderTest, RecordVsync)
impeller::ShaderType type
size_t bit_width