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"
21 #include "impeller/runtime_stage/runtime_stage_flatbuffers.h"
23 #include "runtime_stage_types_flatbuffers.h"
32 const std::shared_ptr<fml::Mapping> fixture =
33 flutter::testing::OpenFixtureAsMapping(
"ink_sparkle.frag.iplr");
35 ASSERT_GT(fixture->GetSize(), 0u);
37 ASSERT_TRUE(stages.ok());
40 ASSERT_TRUE(stage->IsValid());
45 flatbuffers::FlatBufferBuilder builder;
46 fb::RuntimeStagesBuilder stages_builder(builder);
47 stages_builder.add_format_version(0);
48 auto stages = stages_builder.Finish();
49 builder.Finish(stages, fb::RuntimeStagesIdentifier());
50 auto mapping = std::make_shared<fml::NonOwnedMapping>(
51 builder.GetBufferPointer(), builder.GetSize());
53 EXPECT_FALSE(runtime_stages.ok());
54 EXPECT_EQ(runtime_stages.status().code(), absl::StatusCode::kInvalidArgument);
59 const std::shared_ptr<fml::Mapping> fixture =
60 flutter::testing::OpenFixtureAsMapping(
"ink_sparkle.frag.iplr");
62 auto junk_allocation = std::make_shared<Allocation>();
63 ASSERT_TRUE(junk_allocation->Truncate(
Bytes{fixture->GetSize()},
false));
66 ::memset(junk_allocation->GetBuffer(), 127,
67 junk_allocation->GetLength().GetByteSize());
70 ASSERT_FALSE(stages.ok());
74 const std::shared_ptr<fml::Mapping> fixture =
75 flutter::testing::OpenFixtureAsMapping(
"ink_sparkle.frag.iplr");
77 ASSERT_GT(fixture->GetSize(), 0u);
79 ASSERT_TRUE(stages.ok());
83 ASSERT_TRUE(stage->IsValid());
84 switch (GetBackend()) {
88 ASSERT_EQ(stage->GetUniforms().size(), 17u);
90 auto uni = stage->GetUniform(
"u_color");
91 ASSERT_NE(uni,
nullptr);
92 EXPECT_EQ(uni->dimensions.rows, 4u);
93 EXPECT_EQ(uni->dimensions.cols, 1u);
94 EXPECT_EQ(uni->location, 0u);
98 auto uni = stage->GetUniform(
"u_alpha");
99 ASSERT_NE(uni,
nullptr);
100 EXPECT_EQ(uni->dimensions.rows, 1u);
101 EXPECT_EQ(uni->dimensions.cols, 1u);
102 EXPECT_EQ(uni->location, 1u);
106 auto uni = stage->GetUniform(
"u_sparkle_color");
107 ASSERT_NE(uni,
nullptr);
108 EXPECT_EQ(uni->dimensions.rows, 4u);
109 EXPECT_EQ(uni->dimensions.cols, 1u);
110 EXPECT_EQ(uni->location, 2u);
114 auto uni = stage->GetUniform(
"u_sparkle_alpha");
115 ASSERT_NE(uni,
nullptr);
116 EXPECT_EQ(uni->dimensions.rows, 1u);
117 EXPECT_EQ(uni->dimensions.cols, 1u);
118 EXPECT_EQ(uni->location, 3u);
122 auto uni = stage->GetUniform(
"u_blur");
123 ASSERT_NE(uni,
nullptr);
124 EXPECT_EQ(uni->dimensions.rows, 1u);
125 EXPECT_EQ(uni->dimensions.cols, 1u);
126 EXPECT_EQ(uni->location, 4u);
130 auto uni = stage->GetUniform(
"u_radius_scale");
131 ASSERT_NE(uni,
nullptr);
132 EXPECT_EQ(uni->dimensions.rows, 1u);
133 EXPECT_EQ(uni->dimensions.cols, 1u);
134 EXPECT_EQ(uni->location, 6u);
138 auto uni = stage->GetUniform(
"u_max_radius");
139 ASSERT_NE(uni,
nullptr);
140 EXPECT_EQ(uni->dimensions.rows, 1u);
141 EXPECT_EQ(uni->dimensions.cols, 1u);
142 EXPECT_EQ(uni->location, 7u);
146 auto uni = stage->GetUniform(
"u_resolution_scale");
147 ASSERT_NE(uni,
nullptr);
148 EXPECT_EQ(uni->dimensions.rows, 2u);
149 EXPECT_EQ(uni->dimensions.cols, 1u);
150 EXPECT_EQ(uni->location, 8u);
154 auto uni = stage->GetUniform(
"u_noise_scale");
155 ASSERT_NE(uni,
nullptr);
156 EXPECT_EQ(uni->dimensions.rows, 2u);
157 EXPECT_EQ(uni->dimensions.cols, 1u);
158 EXPECT_EQ(uni->location, 9u);
162 auto uni = stage->GetUniform(
"u_noise_phase");
163 ASSERT_NE(uni,
nullptr);
164 EXPECT_EQ(uni->dimensions.rows, 1u);
165 EXPECT_EQ(uni->dimensions.cols, 1u);
166 EXPECT_EQ(uni->location, 10u);
171 auto uni = stage->GetUniform(
"u_circle1");
172 ASSERT_NE(uni,
nullptr);
173 EXPECT_EQ(uni->dimensions.rows, 2u);
174 EXPECT_EQ(uni->dimensions.cols, 1u);
175 EXPECT_EQ(uni->location, 11u);
179 auto uni = stage->GetUniform(
"u_circle2");
180 ASSERT_NE(uni,
nullptr);
181 EXPECT_EQ(uni->dimensions.rows, 2u);
182 EXPECT_EQ(uni->dimensions.cols, 1u);
183 EXPECT_EQ(uni->location, 12u);
187 auto uni = stage->GetUniform(
"u_circle3");
188 ASSERT_NE(uni,
nullptr);
189 EXPECT_EQ(uni->dimensions.rows, 2u);
190 EXPECT_EQ(uni->dimensions.cols, 1u);
191 EXPECT_EQ(uni->location, 13u);
195 auto uni = stage->GetUniform(
"u_rotation1");
196 ASSERT_NE(uni,
nullptr);
197 EXPECT_EQ(uni->dimensions.rows, 2u);
198 EXPECT_EQ(uni->dimensions.cols, 1u);
199 EXPECT_EQ(uni->location, 14u);
203 auto uni = stage->GetUniform(
"u_rotation2");
204 ASSERT_NE(uni,
nullptr);
205 EXPECT_EQ(uni->dimensions.rows, 2u);
206 EXPECT_EQ(uni->dimensions.cols, 1u);
207 EXPECT_EQ(uni->location, 15u);
211 auto uni = stage->GetUniform(
"u_rotation3");
212 ASSERT_NE(uni,
nullptr);
213 EXPECT_EQ(uni->dimensions.rows, 2u);
214 EXPECT_EQ(uni->dimensions.cols, 1u);
215 EXPECT_EQ(uni->location, 16u);
221 EXPECT_EQ(stage->GetUniforms().size(), 1u);
225 EXPECT_EQ(uni->struct_float_count, 32u);
236 EXPECT_EQ(uni->GetSize(), 144u);
237 std::vector<uint8_t> layout(uni->GetSize() /
sizeof(
float), 1);
243 EXPECT_THAT(uni->struct_layout, ::testing::ElementsAreArray(layout));
251 GTEST_SKIP() <<
"Test only relevant for Vulkan";
253 const std::shared_ptr<fml::Mapping> fixture =
254 flutter::testing::OpenFixtureAsMapping(
255 "uniforms_and_sampler_1.frag.iplr");
256 ASSERT_TRUE(fixture);
257 ASSERT_GT(fixture->GetSize(), 0u);
259 ASSERT_TRUE(stages.ok());
263 EXPECT_EQ(stage->GetUniforms().size(), 2u);
268 EXPECT_EQ(uni->binding, 65u);
271 auto sampler_uniform = stage->GetUniform(
"u_texture");
273 EXPECT_EQ(sampler_uniform->binding, 64u);
278 GTEST_SKIP() <<
"Test only relevant for Vulkan";
280 const std::shared_ptr<fml::Mapping> fixture =
281 flutter::testing::OpenFixtureAsMapping(
282 "uniforms_and_sampler_2.frag.iplr");
283 ASSERT_TRUE(fixture);
284 ASSERT_GT(fixture->GetSize(), 0u);
286 ASSERT_TRUE(stages.ok());
290 EXPECT_EQ(stage->GetUniforms().size(), 2u);
295 EXPECT_EQ(uni->binding, 64u);
298 auto sampler_uniform = stage->GetUniform(
"u_texture");
300 EXPECT_EQ(sampler_uniform->binding, 65u);
304 const std::shared_ptr<fml::Mapping> fixture =
305 flutter::testing::OpenFixtureAsMapping(
"ink_sparkle.frag.iplr");
306 ASSERT_TRUE(fixture);
307 ASSERT_GT(fixture->GetSize(), 0u);
309 ASSERT_TRUE(stages.ok());
312 ASSERT_TRUE(stage->IsValid());
313 std::promise<bool> registration;
314 auto future = registration.get_future();
315 auto library = GetContext()->GetShaderLibrary();
316 library->RegisterFunction(
317 stage->GetEntrypoint(),
319 stage->GetCodeMapping(),
320 fml::MakeCopyable([reg = std::move(registration)](
bool result)
mutable {
321 reg.set_value(result);
323 ASSERT_TRUE(future.get());
327 ASSERT_NE(
function,
nullptr);
336 ASSERT_EQ(
function,
nullptr);
341 auto stages = OpenAssetAsRuntimeStage(
"ink_sparkle.frag.iplr");
345 ASSERT_NE(stage,
nullptr);
346 ASSERT_TRUE(RegisterStage(*stage));
347 auto library = GetContext()->GetShaderLibrary();
348 using VS = RuntimeEffectVertexShader;
350 desc.
SetLabel(
"Runtime Stage InkSparkle");
355 auto vertex_descriptor = std::make_shared<VertexDescriptor>();
356 vertex_descriptor->SetStageInputs(VS::kAllShaderStageInputs,
357 VS::kInterleavedBufferLayout);
359 std::array<DescriptorSetLayout, 2> descriptor_set_layouts = {
360 VS::kDescriptorSetLayouts[0],
367 vertex_descriptor->RegisterDescriptorSetLayouts(descriptor_set_layouts);
371 color0.
format = GetContext()->GetCapabilities()->GetDefaultColorFormat();
376 const auto stencil_fmt =
377 GetContext()->GetCapabilities()->GetDefaultStencilFormat();
379 auto pipeline = GetContext()->GetPipelineLibrary()->GetPipeline(desc).Get();
380 ASSERT_NE(pipeline,
nullptr);
384 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 absl::StatusOr< 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