7 #include "flutter/fml/make_copyable.h"
8 #include "flutter/testing/testing.h"
9 #include "gmock/gmock.h"
10 #include "gtest/gtest.h"
15 #include "impeller/entity/runtime_effect.vert.h"
30 const std::shared_ptr<fml::Mapping> fixture =
31 flutter::testing::OpenFixtureAsMapping(
"ink_sparkle.frag.iplr");
33 ASSERT_GT(fixture->GetSize(), 0u);
36 ASSERT_TRUE(stage->IsValid());
42 const std::shared_ptr<fml::Mapping> fixture =
43 flutter::testing::OpenFixtureAsMapping(
"ink_sparkle.frag.iplr");
45 auto junk_allocation = std::make_shared<Allocation>();
46 ASSERT_TRUE(junk_allocation->Truncate(fixture->GetSize(),
false));
49 ::memset(junk_allocation->GetBuffer(), 127, junk_allocation->GetLength());
56 const std::shared_ptr<fml::Mapping> fixture =
57 flutter::testing::OpenFixtureAsMapping(
"ink_sparkle.frag.iplr");
59 ASSERT_GT(fixture->GetSize(), 0u);
63 ASSERT_TRUE(stage->IsValid());
64 switch (GetBackend()) {
68 ASSERT_EQ(stage->GetUniforms().size(), 17u);
70 auto uni = stage->GetUniform(
"u_color");
71 ASSERT_NE(uni,
nullptr);
72 EXPECT_EQ(uni->dimensions.rows, 4u);
73 EXPECT_EQ(uni->dimensions.cols, 1u);
74 EXPECT_EQ(uni->location, 0u);
78 auto uni = stage->GetUniform(
"u_alpha");
79 ASSERT_NE(uni,
nullptr);
80 EXPECT_EQ(uni->dimensions.rows, 1u);
81 EXPECT_EQ(uni->dimensions.cols, 1u);
82 EXPECT_EQ(uni->location, 1u);
86 auto uni = stage->GetUniform(
"u_sparkle_color");
87 ASSERT_NE(uni,
nullptr);
88 EXPECT_EQ(uni->dimensions.rows, 4u);
89 EXPECT_EQ(uni->dimensions.cols, 1u);
90 EXPECT_EQ(uni->location, 2u);
94 auto uni = stage->GetUniform(
"u_sparkle_alpha");
95 ASSERT_NE(uni,
nullptr);
96 EXPECT_EQ(uni->dimensions.rows, 1u);
97 EXPECT_EQ(uni->dimensions.cols, 1u);
98 EXPECT_EQ(uni->location, 3u);
102 auto uni = stage->GetUniform(
"u_blur");
103 ASSERT_NE(uni,
nullptr);
104 EXPECT_EQ(uni->dimensions.rows, 1u);
105 EXPECT_EQ(uni->dimensions.cols, 1u);
106 EXPECT_EQ(uni->location, 4u);
110 auto uni = stage->GetUniform(
"u_radius_scale");
111 ASSERT_NE(uni,
nullptr);
112 EXPECT_EQ(uni->dimensions.rows, 1u);
113 EXPECT_EQ(uni->dimensions.cols, 1u);
114 EXPECT_EQ(uni->location, 6u);
118 auto uni = stage->GetUniform(
"u_max_radius");
119 ASSERT_NE(uni,
nullptr);
120 EXPECT_EQ(uni->dimensions.rows, 1u);
121 EXPECT_EQ(uni->dimensions.cols, 1u);
122 EXPECT_EQ(uni->location, 7u);
126 auto uni = stage->GetUniform(
"u_resolution_scale");
127 ASSERT_NE(uni,
nullptr);
128 EXPECT_EQ(uni->dimensions.rows, 2u);
129 EXPECT_EQ(uni->dimensions.cols, 1u);
130 EXPECT_EQ(uni->location, 8u);
134 auto uni = stage->GetUniform(
"u_noise_scale");
135 ASSERT_NE(uni,
nullptr);
136 EXPECT_EQ(uni->dimensions.rows, 2u);
137 EXPECT_EQ(uni->dimensions.cols, 1u);
138 EXPECT_EQ(uni->location, 9u);
142 auto uni = stage->GetUniform(
"u_noise_phase");
143 ASSERT_NE(uni,
nullptr);
144 EXPECT_EQ(uni->dimensions.rows, 1u);
145 EXPECT_EQ(uni->dimensions.cols, 1u);
146 EXPECT_EQ(uni->location, 10u);
151 auto uni = stage->GetUniform(
"u_circle1");
152 ASSERT_NE(uni,
nullptr);
153 EXPECT_EQ(uni->dimensions.rows, 2u);
154 EXPECT_EQ(uni->dimensions.cols, 1u);
155 EXPECT_EQ(uni->location, 11u);
159 auto uni = stage->GetUniform(
"u_circle2");
160 ASSERT_NE(uni,
nullptr);
161 EXPECT_EQ(uni->dimensions.rows, 2u);
162 EXPECT_EQ(uni->dimensions.cols, 1u);
163 EXPECT_EQ(uni->location, 12u);
167 auto uni = stage->GetUniform(
"u_circle3");
168 ASSERT_NE(uni,
nullptr);
169 EXPECT_EQ(uni->dimensions.rows, 2u);
170 EXPECT_EQ(uni->dimensions.cols, 1u);
171 EXPECT_EQ(uni->location, 13u);
175 auto uni = stage->GetUniform(
"u_rotation1");
176 ASSERT_NE(uni,
nullptr);
177 EXPECT_EQ(uni->dimensions.rows, 2u);
178 EXPECT_EQ(uni->dimensions.cols, 1u);
179 EXPECT_EQ(uni->location, 14u);
183 auto uni = stage->GetUniform(
"u_rotation2");
184 ASSERT_NE(uni,
nullptr);
185 EXPECT_EQ(uni->dimensions.rows, 2u);
186 EXPECT_EQ(uni->dimensions.cols, 1u);
187 EXPECT_EQ(uni->location, 15u);
191 auto uni = stage->GetUniform(
"u_rotation3");
192 ASSERT_NE(uni,
nullptr);
193 EXPECT_EQ(uni->dimensions.rows, 2u);
194 EXPECT_EQ(uni->dimensions.cols, 1u);
195 EXPECT_EQ(uni->location, 16u);
201 EXPECT_EQ(stage->GetUniforms().size(), 1u);
205 EXPECT_EQ(uni->struct_float_count, 32u);
216 EXPECT_EQ(uni->GetSize(), 144u);
217 std::vector<uint8_t> layout(uni->GetSize() /
sizeof(
float), 1);
223 EXPECT_THAT(uni->struct_layout, ::testing::ElementsAreArray(layout));
231 GTEST_SKIP() <<
"Test only relevant for Vulkan";
233 const std::shared_ptr<fml::Mapping> fixture =
234 flutter::testing::OpenFixtureAsMapping(
235 "uniforms_and_sampler_1.frag.iplr");
236 ASSERT_TRUE(fixture);
237 ASSERT_GT(fixture->GetSize(), 0u);
241 EXPECT_EQ(stage->GetUniforms().size(), 2u);
246 EXPECT_EQ(uni->binding, 65u);
249 auto sampler_uniform = stage->GetUniform(
"u_texture");
251 EXPECT_EQ(sampler_uniform->binding, 64u);
256 GTEST_SKIP() <<
"Test only relevant for Vulkan";
258 const std::shared_ptr<fml::Mapping> fixture =
259 flutter::testing::OpenFixtureAsMapping(
260 "uniforms_and_sampler_2.frag.iplr");
261 ASSERT_TRUE(fixture);
262 ASSERT_GT(fixture->GetSize(), 0u);
266 EXPECT_EQ(stage->GetUniforms().size(), 2u);
271 EXPECT_EQ(uni->binding, 64u);
274 auto sampler_uniform = stage->GetUniform(
"u_texture");
276 EXPECT_EQ(sampler_uniform->binding, 65u);
280 const std::shared_ptr<fml::Mapping> fixture =
281 flutter::testing::OpenFixtureAsMapping(
"ink_sparkle.frag.iplr");
282 ASSERT_TRUE(fixture);
283 ASSERT_GT(fixture->GetSize(), 0u);
286 ASSERT_TRUE(stage->IsValid());
287 std::promise<bool> registration;
288 auto future = registration.get_future();
289 auto library = GetContext()->GetShaderLibrary();
290 library->RegisterFunction(
291 stage->GetEntrypoint(),
293 stage->GetCodeMapping(),
294 fml::MakeCopyable([reg = std::move(registration)](
bool result)
mutable {
295 reg.set_value(result);
297 ASSERT_TRUE(future.get());
301 ASSERT_NE(
function,
nullptr);
310 ASSERT_EQ(
function,
nullptr);
315 auto stages = OpenAssetAsRuntimeStage(
"ink_sparkle.frag.iplr");
319 ASSERT_NE(stage,
nullptr);
320 ASSERT_TRUE(RegisterStage(*stage));
321 auto library = GetContext()->GetShaderLibrary();
322 using VS = RuntimeEffectVertexShader;
324 desc.
SetLabel(
"Runtime Stage InkSparkle");
329 auto vertex_descriptor = std::make_shared<VertexDescriptor>();
330 vertex_descriptor->SetStageInputs(VS::kAllShaderStageInputs,
331 VS::kInterleavedBufferLayout);
333 std::array<DescriptorSetLayout, 2> descriptor_set_layouts = {
334 VS::kDescriptorSetLayouts[0],
341 vertex_descriptor->RegisterDescriptorSetLayouts(descriptor_set_layouts);
345 color0.
format = GetContext()->GetCapabilities()->GetDefaultColorFormat();
350 const auto stencil_fmt =
351 GetContext()->GetCapabilities()->GetDefaultStencilFormat();
353 auto pipeline = GetContext()->GetPipelineLibrary()->GetPipeline(desc).Get();
354 ASSERT_NE(pipeline,
nullptr);
358 auto stages = OpenAssetAsRuntimeStage(
"ink_sparkle.frag.iplr");