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(
Bytes{fixture->GetSize()},
false));
49 ::memset(junk_allocation->GetBuffer(), 127,
50 junk_allocation->GetLength().GetByteSize());
57 const std::shared_ptr<fml::Mapping> fixture =
58 flutter::testing::OpenFixtureAsMapping(
"ink_sparkle.frag.iplr");
60 ASSERT_GT(fixture->GetSize(), 0u);
64 ASSERT_TRUE(stage->IsValid());
65 switch (GetBackend()) {
69 ASSERT_EQ(stage->GetUniforms().size(), 17u);
71 auto uni = stage->GetUniform(
"u_color");
72 ASSERT_NE(uni,
nullptr);
73 EXPECT_EQ(uni->dimensions.rows, 4u);
74 EXPECT_EQ(uni->dimensions.cols, 1u);
75 EXPECT_EQ(uni->location, 0u);
79 auto uni = stage->GetUniform(
"u_alpha");
80 ASSERT_NE(uni,
nullptr);
81 EXPECT_EQ(uni->dimensions.rows, 1u);
82 EXPECT_EQ(uni->dimensions.cols, 1u);
83 EXPECT_EQ(uni->location, 1u);
87 auto uni = stage->GetUniform(
"u_sparkle_color");
88 ASSERT_NE(uni,
nullptr);
89 EXPECT_EQ(uni->dimensions.rows, 4u);
90 EXPECT_EQ(uni->dimensions.cols, 1u);
91 EXPECT_EQ(uni->location, 2u);
95 auto uni = stage->GetUniform(
"u_sparkle_alpha");
96 ASSERT_NE(uni,
nullptr);
97 EXPECT_EQ(uni->dimensions.rows, 1u);
98 EXPECT_EQ(uni->dimensions.cols, 1u);
99 EXPECT_EQ(uni->location, 3u);
103 auto uni = stage->GetUniform(
"u_blur");
104 ASSERT_NE(uni,
nullptr);
105 EXPECT_EQ(uni->dimensions.rows, 1u);
106 EXPECT_EQ(uni->dimensions.cols, 1u);
107 EXPECT_EQ(uni->location, 4u);
111 auto uni = stage->GetUniform(
"u_radius_scale");
112 ASSERT_NE(uni,
nullptr);
113 EXPECT_EQ(uni->dimensions.rows, 1u);
114 EXPECT_EQ(uni->dimensions.cols, 1u);
115 EXPECT_EQ(uni->location, 6u);
119 auto uni = stage->GetUniform(
"u_max_radius");
120 ASSERT_NE(uni,
nullptr);
121 EXPECT_EQ(uni->dimensions.rows, 1u);
122 EXPECT_EQ(uni->dimensions.cols, 1u);
123 EXPECT_EQ(uni->location, 7u);
127 auto uni = stage->GetUniform(
"u_resolution_scale");
128 ASSERT_NE(uni,
nullptr);
129 EXPECT_EQ(uni->dimensions.rows, 2u);
130 EXPECT_EQ(uni->dimensions.cols, 1u);
131 EXPECT_EQ(uni->location, 8u);
135 auto uni = stage->GetUniform(
"u_noise_scale");
136 ASSERT_NE(uni,
nullptr);
137 EXPECT_EQ(uni->dimensions.rows, 2u);
138 EXPECT_EQ(uni->dimensions.cols, 1u);
139 EXPECT_EQ(uni->location, 9u);
143 auto uni = stage->GetUniform(
"u_noise_phase");
144 ASSERT_NE(uni,
nullptr);
145 EXPECT_EQ(uni->dimensions.rows, 1u);
146 EXPECT_EQ(uni->dimensions.cols, 1u);
147 EXPECT_EQ(uni->location, 10u);
152 auto uni = stage->GetUniform(
"u_circle1");
153 ASSERT_NE(uni,
nullptr);
154 EXPECT_EQ(uni->dimensions.rows, 2u);
155 EXPECT_EQ(uni->dimensions.cols, 1u);
156 EXPECT_EQ(uni->location, 11u);
160 auto uni = stage->GetUniform(
"u_circle2");
161 ASSERT_NE(uni,
nullptr);
162 EXPECT_EQ(uni->dimensions.rows, 2u);
163 EXPECT_EQ(uni->dimensions.cols, 1u);
164 EXPECT_EQ(uni->location, 12u);
168 auto uni = stage->GetUniform(
"u_circle3");
169 ASSERT_NE(uni,
nullptr);
170 EXPECT_EQ(uni->dimensions.rows, 2u);
171 EXPECT_EQ(uni->dimensions.cols, 1u);
172 EXPECT_EQ(uni->location, 13u);
176 auto uni = stage->GetUniform(
"u_rotation1");
177 ASSERT_NE(uni,
nullptr);
178 EXPECT_EQ(uni->dimensions.rows, 2u);
179 EXPECT_EQ(uni->dimensions.cols, 1u);
180 EXPECT_EQ(uni->location, 14u);
184 auto uni = stage->GetUniform(
"u_rotation2");
185 ASSERT_NE(uni,
nullptr);
186 EXPECT_EQ(uni->dimensions.rows, 2u);
187 EXPECT_EQ(uni->dimensions.cols, 1u);
188 EXPECT_EQ(uni->location, 15u);
192 auto uni = stage->GetUniform(
"u_rotation3");
193 ASSERT_NE(uni,
nullptr);
194 EXPECT_EQ(uni->dimensions.rows, 2u);
195 EXPECT_EQ(uni->dimensions.cols, 1u);
196 EXPECT_EQ(uni->location, 16u);
202 EXPECT_EQ(stage->GetUniforms().size(), 1u);
206 EXPECT_EQ(uni->struct_float_count, 32u);
217 EXPECT_EQ(uni->GetSize(), 144u);
218 std::vector<uint8_t> layout(uni->GetSize() /
sizeof(
float), 1);
224 EXPECT_THAT(uni->struct_layout, ::testing::ElementsAreArray(layout));
232 GTEST_SKIP() <<
"Test only relevant for Vulkan";
234 const std::shared_ptr<fml::Mapping> fixture =
235 flutter::testing::OpenFixtureAsMapping(
236 "uniforms_and_sampler_1.frag.iplr");
237 ASSERT_TRUE(fixture);
238 ASSERT_GT(fixture->GetSize(), 0u);
242 EXPECT_EQ(stage->GetUniforms().size(), 2u);
247 EXPECT_EQ(uni->binding, 65u);
250 auto sampler_uniform = stage->GetUniform(
"u_texture");
252 EXPECT_EQ(sampler_uniform->binding, 64u);
257 GTEST_SKIP() <<
"Test only relevant for Vulkan";
259 const std::shared_ptr<fml::Mapping> fixture =
260 flutter::testing::OpenFixtureAsMapping(
261 "uniforms_and_sampler_2.frag.iplr");
262 ASSERT_TRUE(fixture);
263 ASSERT_GT(fixture->GetSize(), 0u);
267 EXPECT_EQ(stage->GetUniforms().size(), 2u);
272 EXPECT_EQ(uni->binding, 64u);
275 auto sampler_uniform = stage->GetUniform(
"u_texture");
277 EXPECT_EQ(sampler_uniform->binding, 65u);
281 const std::shared_ptr<fml::Mapping> fixture =
282 flutter::testing::OpenFixtureAsMapping(
"ink_sparkle.frag.iplr");
283 ASSERT_TRUE(fixture);
284 ASSERT_GT(fixture->GetSize(), 0u);
287 ASSERT_TRUE(stage->IsValid());
288 std::promise<bool> registration;
289 auto future = registration.get_future();
290 auto library = GetContext()->GetShaderLibrary();
291 library->RegisterFunction(
292 stage->GetEntrypoint(),
294 stage->GetCodeMapping(),
295 fml::MakeCopyable([reg = std::move(registration)](
bool result)
mutable {
296 reg.set_value(result);
298 ASSERT_TRUE(future.get());
302 ASSERT_NE(
function,
nullptr);
311 ASSERT_EQ(
function,
nullptr);
316 auto stages = OpenAssetAsRuntimeStage(
"ink_sparkle.frag.iplr");
320 ASSERT_NE(stage,
nullptr);
321 ASSERT_TRUE(RegisterStage(*stage));
322 auto library = GetContext()->GetShaderLibrary();
323 using VS = RuntimeEffectVertexShader;
325 desc.
SetLabel(
"Runtime Stage InkSparkle");
330 auto vertex_descriptor = std::make_shared<VertexDescriptor>();
331 vertex_descriptor->SetStageInputs(VS::kAllShaderStageInputs,
332 VS::kInterleavedBufferLayout);
334 std::array<DescriptorSetLayout, 2> descriptor_set_layouts = {
335 VS::kDescriptorSetLayouts[0],
342 vertex_descriptor->RegisterDescriptorSetLayouts(descriptor_set_layouts);
346 color0.
format = GetContext()->GetCapabilities()->GetDefaultColorFormat();
351 const auto stencil_fmt =
352 GetContext()->GetCapabilities()->GetDefaultStencilFormat();
354 auto pipeline = GetContext()->GetPipelineLibrary()->GetPipeline(desc).Get();
355 ASSERT_NE(pipeline,
nullptr);
359 auto stages = OpenAssetAsRuntimeStage(
"ink_sparkle.frag.iplr");
PipelineDescriptor & SetStencilPixelFormat(PixelFormat format)
PipelineDescriptor & SetVertexDescriptor(std::shared_ptr< VertexDescriptor > vertex_descriptor)
PipelineDescriptor & AddStageEntrypoint(std::shared_ptr< const ShaderFunction > function)
PipelineDescriptor & SetLabel(std::string_view label)
PipelineDescriptor & SetStencilAttachmentDescriptors(std::optional< StencilAttachmentDescriptor > front_and_back)
PipelineDescriptor & SetColorAttachmentDescriptor(size_t index, ColorAttachmentDescriptor desc)
static const char * kVulkanUBOName
static Map DecodeRuntimeStages(const std::shared_ptr< fml::Mapping > &payload)
TEST_P(AiksTest, DrawAtlasNoColor)
INSTANTIATE_PLAYGROUND_SUITE(AiksTest)
constexpr RuntimeStageBackend PlaygroundBackendToRuntimeStageBackend(PlaygroundBackend backend)
constexpr ShaderStage ToShaderStage(RuntimeShaderStage stage)
@ kEqual
Comparison test passes if new_value == current_value.
std::shared_ptr< fml::Mapping > CreateMappingFromAllocation(const std::shared_ptr< Allocation > &allocation)
Creates a mapping from allocation.
LinePipeline::VertexShader VS
Describe the color attachment that will be used with this pipeline.
CompareFunction stencil_compare