Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
buffer_bindings_gles_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" // IWYU pragma: keep
6#include "gtest/gtest.h"
12
13namespace impeller {
14namespace testing {
15
16using ::testing::_;
17
18TEST(BufferBindingsGLESTest, BindUniformData) {
19 BufferBindingsGLES bindings;
20 absl::flat_hash_map<std::string, GLint> uniform_bindings;
21 uniform_bindings["SHADERMETADATA.FOOBAR"] = 1;
22 bindings.SetUniformBindings(std::move(uniform_bindings));
23 auto mock_gles_impl = std::make_unique<MockGLESImpl>();
24
25 EXPECT_CALL(*mock_gles_impl, Uniform1fv(_, _, _)).Times(1);
26
27 std::shared_ptr<MockGLES> mock_gl = MockGLES::Init(std::move(mock_gles_impl));
28 std::vector<BufferResource> bound_buffers;
29 std::vector<TextureAndSampler> bound_textures;
30
31 ShaderMetadata shader_metadata = {
32 .name = "shader_metadata",
33 .members = {
35 .name = "foobar",
36 .offset = 0,
37 .size = sizeof(float),
38 .byte_length = sizeof(float),
39 .array_elements = std::nullopt,
40 .float_type = ShaderFloatType::kFloat}}};
41 std::shared_ptr<ReactorGLES> reactor;
42 auto backing_store = std::make_unique<Allocation>();
43 ASSERT_TRUE(backing_store->Truncate(Bytes{sizeof(float)}));
44 DeviceBufferGLES device_buffer(DeviceBufferDescriptor{.size = sizeof(float)},
45 reactor, std::move(backing_store));
46 BufferView buffer_view(&device_buffer, Range(0, sizeof(float)));
47 bound_buffers.push_back(BufferResource(&shader_metadata, buffer_view));
48
49 EXPECT_TRUE(bindings.BindUniformData(mock_gl->GetProcTable(), bound_textures,
50 bound_buffers, Range{0, 0},
51 Range{0, 1}));
52}
53
54TEST(BufferBindingsGLESTest, BindArrayData) {
55 BufferBindingsGLES bindings;
56 absl::flat_hash_map<std::string, GLint> uniform_bindings;
57 uniform_bindings["SHADERMETADATA.FOOBAR[0]"] = 1;
58 bindings.SetUniformBindings(std::move(uniform_bindings));
59 auto mock_gles_impl = std::make_unique<MockGLESImpl>();
60
61 EXPECT_CALL(*mock_gles_impl, Uniform1fv(_, _, _)).Times(1);
62
63 std::shared_ptr<MockGLES> mock_gl = MockGLES::Init(std::move(mock_gles_impl));
64 std::vector<BufferResource> bound_buffers;
65 std::vector<TextureAndSampler> bound_textures;
66
67 ShaderMetadata shader_metadata = {
68 .name = "shader_metadata",
69 .members = {
71 .name = "foobar",
72 .offset = 0,
73 .size = sizeof(float),
74 .byte_length = sizeof(float) * 4,
75 .array_elements = 4,
76 .float_type = ShaderFloatType::kFloat}}};
77 std::shared_ptr<ReactorGLES> reactor;
78 auto backing_store = std::make_unique<Allocation>();
79 ASSERT_TRUE(backing_store->Truncate(Bytes{sizeof(float) * 4}));
80 DeviceBufferGLES device_buffer(
81 DeviceBufferDescriptor{.size = sizeof(float) * 4}, reactor,
82 std::move(backing_store));
83 BufferView buffer_view(&device_buffer, Range(0, sizeof(float)));
84 bound_buffers.push_back(BufferResource(&shader_metadata, buffer_view));
85
86 EXPECT_TRUE(bindings.BindUniformData(mock_gl->GetProcTable(), bound_textures,
87 bound_buffers, Range{0, 0},
88 Range{0, 1}));
89}
90
91TEST(BufferBindingsGLESTest, BindUniformDataVerticesAndMatrices) {
92 BufferBindingsGLES bindings;
93 absl::flat_hash_map<std::string, GLint> uniform_bindings;
94 uniform_bindings["SHADERMETADATA.VEC2"] = 1;
95 uniform_bindings["SHADERMETADATA.VEC3"] = 2;
96 uniform_bindings["SHADERMETADATA.VEC4"] = 3;
97 uniform_bindings["SHADERMETADATA.MAT2"] = 4;
98 uniform_bindings["SHADERMETADATA.MAT3"] = 5;
99 uniform_bindings["SHADERMETADATA.MAT4"] = 6;
100 bindings.SetUniformBindings(std::move(uniform_bindings));
101 auto mock_gles_impl = std::make_unique<MockGLESImpl>();
102
103 EXPECT_CALL(*mock_gles_impl, Uniform2fv(1, 1, _)).Times(1);
104 EXPECT_CALL(*mock_gles_impl, Uniform3fv(2, 1, _)).Times(1);
105 EXPECT_CALL(*mock_gles_impl, Uniform4fv(3, 1, _)).Times(1);
106 EXPECT_CALL(*mock_gles_impl, UniformMatrix2fv(4, 1, GL_FALSE, _)).Times(1);
107 EXPECT_CALL(*mock_gles_impl, UniformMatrix3fv(5, 1, GL_FALSE, _)).Times(1);
108 EXPECT_CALL(*mock_gles_impl, UniformMatrix4fv(6, 1, GL_FALSE, _)).Times(1);
109
110 std::shared_ptr<MockGLES> mock_gl = MockGLES::Init(std::move(mock_gles_impl));
111 std::vector<BufferResource> bound_buffers;
112 std::vector<TextureAndSampler> bound_textures;
113
114 auto make_metadata = [](ShaderFloatType float_type, const char* name,
115 size_t size) {
117 .name = name,
118 .offset = 0,
119 .size = size,
120 .byte_length = size,
121 .array_elements = std::nullopt,
122 .float_type = float_type};
123 };
124
125 ShaderMetadata shader_metadata = {
126 .name = "shader_metadata",
127 .members = {
128 make_metadata(ShaderFloatType::kVec2, "vec2", sizeof(Vector2)),
129 make_metadata(ShaderFloatType::kVec3, "vec3", sizeof(Vector3)),
130 make_metadata(ShaderFloatType::kVec4, "vec4", sizeof(Vector4)),
131 make_metadata(ShaderFloatType::kMat2, "mat2", sizeof(float) * 4),
132 make_metadata(ShaderFloatType::kMat3, "mat3", sizeof(float) * 9),
133 make_metadata(ShaderFloatType::kMat4, "mat4", sizeof(Matrix)),
134 }};
135
136 std::shared_ptr<ReactorGLES> reactor;
137 auto backing_store = std::make_unique<Allocation>();
138 ASSERT_TRUE(backing_store->Truncate(Bytes{1024})); // Plenty of space
139 DeviceBufferGLES device_buffer(DeviceBufferDescriptor{.size = 1024}, reactor,
140 std::move(backing_store));
141 BufferView buffer_view(&device_buffer, Range(0, 1024));
142 bound_buffers.push_back(BufferResource(&shader_metadata, buffer_view));
143
144 EXPECT_TRUE(bindings.BindUniformData(mock_gl->GetProcTable(), bound_textures,
145 bound_buffers, Range{0, 0},
146 Range{0, 1}));
147}
148
149// Regression guard: a float uniform that arrives at the GLES backend without
150// `float_type` populated must be rejected rather than silently dispatched to
151// the wrong glUniform call. This is the fault mode that motivated the schema
152// extension; if a future change forgets to populate `float_type` (in the
153// shader bundle loader, runtime effects, or anywhere else), this test
154// catches it at unit-test time instead of at runtime.
155TEST(BufferBindingsGLESTest, BindUniformFailsWithoutFloatType) {
156 BufferBindingsGLES bindings;
157 absl::flat_hash_map<std::string, GLint> uniform_bindings;
158 uniform_bindings["SHADERMETADATA.FOOBAR"] = 1;
159 bindings.SetUniformBindings(std::move(uniform_bindings));
160 auto mock_gles_impl = std::make_unique<MockGLESImpl>();
161 std::shared_ptr<MockGLES> mock_gl = MockGLES::Init(std::move(mock_gles_impl));
162 std::vector<BufferResource> bound_buffers;
163 std::vector<TextureAndSampler> bound_textures;
164
165 ShaderMetadata shader_metadata = {
166 .name = "shader_metadata",
168 .name = "foobar",
169 .offset = 0,
170 .size = sizeof(float),
171 .byte_length = sizeof(float),
172 .array_elements = std::nullopt,
173 .float_type = std::nullopt}}};
174 std::shared_ptr<ReactorGLES> reactor;
175 auto backing_store = std::make_unique<Allocation>();
176 ASSERT_TRUE(backing_store->Truncate(Bytes{sizeof(float)}));
177 DeviceBufferGLES device_buffer(DeviceBufferDescriptor{.size = sizeof(float)},
178 reactor, std::move(backing_store));
179 BufferView buffer_view(&device_buffer, Range(0, sizeof(float)));
180 bound_buffers.push_back(BufferResource(&shader_metadata, buffer_view));
181
182 EXPECT_FALSE(bindings.BindUniformData(mock_gl->GetProcTable(), bound_textures,
183 bound_buffers, Range{0, 0},
184 Range{0, 1}));
185}
186
187} // namespace testing
188} // namespace impeller
Sets up stage bindings for single draw call in the OpenGLES backend.
bool BindUniformData(const ProcTableGLES &gl, const std::vector< TextureAndSampler > &bound_textures, const std::vector< BufferResource > &bound_buffers, Range texture_range, Range buffer_range)
static std::shared_ptr< MockGLES > Init(std::unique_ptr< MockGLESImpl > impl, const std::optional< std::vector< const char * > > &extensions=std::nullopt, const char *version_string="OpenGL ES 3.0")
Definition mock_gles.cc:360
TEST(FrameTimingsRecorderTest, RecordVsync)
it will be possible to load the file into Perfetto s trace viewer use test Running tests that layout and measure text will not yield consistent results across various platforms Enabling this option will make font resolution default to the Ahem test font on all disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
DEF_SWITCHES_START aot vmservice shared library name
Definition switch_defs.h:27
Resource< BufferView > BufferResource
Definition command.h:55
A 4x4 matrix using column-major storage.
Definition matrix.h:37