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
5
#include "
flutter/testing/testing.h
"
6
#include "
impeller/core/shader_types.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(),
33
VertexAttributeFormat::kFloat32
);
34
EXPECT_EQ(MakeSlot(
ShaderType::kFloat
, 32u, 2u).GetVertexAttributeFormat(),
35
VertexAttributeFormat::kFloat32x2
);
36
EXPECT_EQ(MakeSlot(
ShaderType::kFloat
, 32u, 3u).GetVertexAttributeFormat(),
37
VertexAttributeFormat::kFloat32x3
);
38
EXPECT_EQ(MakeSlot(
ShaderType::kFloat
, 32u, 4u).GetVertexAttributeFormat(),
39
VertexAttributeFormat::kFloat32x4
);
40
}
41
42
TEST
(ShaderTypesTest, VertexAttributeFormatHalfFloat) {
43
EXPECT_EQ(
44
MakeSlot(
ShaderType::kHalfFloat
, 16u, 1u).GetVertexAttributeFormat(),
45
VertexAttributeFormat::kFloat16
);
46
EXPECT_EQ(
47
MakeSlot(
ShaderType::kHalfFloat
, 16u, 4u).GetVertexAttributeFormat(),
48
VertexAttributeFormat::kFloat16x4
);
49
}
50
51
TEST
(ShaderTypesTest, VertexAttributeFormatIntegers) {
52
EXPECT_EQ(
53
MakeSlot(
ShaderType::kSignedByte
, 8u, 1u).GetVertexAttributeFormat(),
54
VertexAttributeFormat::kSInt8
);
55
EXPECT_EQ(
56
MakeSlot(
ShaderType::kUnsignedByte
, 8u, 4u).GetVertexAttributeFormat(),
57
VertexAttributeFormat::kUInt8x4
);
58
EXPECT_EQ(
59
MakeSlot(
ShaderType::kSignedShort
, 16u, 2u).GetVertexAttributeFormat(),
60
VertexAttributeFormat::kSInt16x2
);
61
EXPECT_EQ(
62
MakeSlot(
ShaderType::kUnsignedShort
, 16u, 3u).GetVertexAttributeFormat(),
63
VertexAttributeFormat::kUInt16x3
);
64
EXPECT_EQ(
65
MakeSlot(
ShaderType::kSignedInt
, 32u, 1u).GetVertexAttributeFormat(),
66
VertexAttributeFormat::kSInt32
);
67
EXPECT_EQ(
68
MakeSlot(
ShaderType::kUnsignedInt
, 32u, 4u).GetVertexAttributeFormat(),
69
VertexAttributeFormat::kUInt32x4
);
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(),
76
VertexAttributeFormat::kInvalid
);
77
}
78
79
TEST
(ShaderTypesTest, VertexAttributeFormatRejectsBadComponentCount) {
80
EXPECT_EQ(MakeSlot(
ShaderType::kFloat
, 32u, 0u).GetVertexAttributeFormat(),
81
VertexAttributeFormat::kInvalid
);
82
EXPECT_EQ(MakeSlot(
ShaderType::kFloat
, 32u, 5u).GetVertexAttributeFormat(),
83
VertexAttributeFormat::kInvalid
);
84
}
85
86
TEST
(ShaderTypesTest, VertexAttributeFormatRejectsBadBitWidth) {
87
EXPECT_EQ(MakeSlot(
ShaderType::kFloat
, 16u, 1u).GetVertexAttributeFormat(),
88
VertexAttributeFormat::kInvalid
);
89
EXPECT_EQ(
90
MakeSlot(
ShaderType::kSignedInt
, 16u, 1u).GetVertexAttributeFormat(),
91
VertexAttributeFormat::kInvalid
);
92
}
93
94
TEST
(ShaderTypesTest, VertexAttributeFormatRejectsUnsupportedScalarKinds) {
95
EXPECT_EQ(MakeSlot(
ShaderType::kBoolean
, 8u, 1u).GetVertexAttributeFormat(),
96
VertexAttributeFormat::kInvalid
);
97
EXPECT_EQ(MakeSlot(
ShaderType::kDouble
, 64u, 1u).GetVertexAttributeFormat(),
98
VertexAttributeFormat::kInvalid
);
99
EXPECT_EQ(
100
MakeSlot(
ShaderType::kSignedInt64
, 64u, 1u).GetVertexAttributeFormat(),
101
VertexAttributeFormat::kInvalid
);
102
}
103
104
}
// namespace testing
105
}
// namespace impeller
vec_size
uint32_t vec_size
Definition
compiler_unittests.cc:311
columns
uint32_t columns
Definition
compiler_unittests.cc:310
flutter::TEST
TEST(FrameTimingsRecorderTest, RecordVsync)
Definition
frame_timings_recorder_unittests.cc:22
impeller
Definition
texture.h:16
impeller::VertexAttributeFormat::kFloat32x2
@ kFloat32x2
impeller::VertexAttributeFormat::kFloat32x4
@ kFloat32x4
impeller::VertexAttributeFormat::kUInt16x3
@ kUInt16x3
impeller::VertexAttributeFormat::kSInt32
@ kSInt32
impeller::VertexAttributeFormat::kUInt8x4
@ kUInt8x4
impeller::VertexAttributeFormat::kSInt16x2
@ kSInt16x2
impeller::VertexAttributeFormat::kFloat16
@ kFloat16
impeller::VertexAttributeFormat::kFloat32
@ kFloat32
impeller::VertexAttributeFormat::kInvalid
@ kInvalid
impeller::VertexAttributeFormat::kFloat16x4
@ kFloat16x4
impeller::VertexAttributeFormat::kSInt8
@ kSInt8
impeller::VertexAttributeFormat::kUInt32x4
@ kUInt32x4
impeller::VertexAttributeFormat::kFloat32x3
@ kFloat32x3
impeller::ShaderType
ShaderType
Definition
shader_types.h:41
impeller::ShaderType::kSignedInt
@ kSignedInt
impeller::ShaderType::kSignedShort
@ kSignedShort
impeller::ShaderType::kSignedInt64
@ kSignedInt64
impeller::ShaderType::kHalfFloat
@ kHalfFloat
impeller::ShaderType::kUnsignedByte
@ kUnsignedByte
impeller::ShaderType::kBoolean
@ kBoolean
impeller::ShaderType::kSignedByte
@ kSignedByte
impeller::ShaderType::kDouble
@ kDouble
impeller::ShaderType::kFloat
@ kFloat
impeller::ShaderType::kUnsignedShort
@ kUnsignedShort
impeller::ShaderType::kUnsignedInt
@ kUnsignedInt
type
impeller::ShaderType type
Definition
render_pipeline.cc:64
bit_width
size_t bit_width
Definition
render_pipeline.cc:65
shader_types.h
testing.h
impeller
core
shader_types_unittests.cc
Generated on Sun Jul 5 2026 07:45:14 for Flutter Engine Uber Docs by
1.9.8