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"
24 #include "third_party/abseil-cpp/absl/status/status_matchers.h"
33 const std::shared_ptr<fml::Mapping> fixture =
34 flutter::testing::OpenFixtureAsMapping(
"ink_sparkle.frag.iplr");
36 ASSERT_GT(fixture->GetSize(), 0u);
38 ABSL_ASSERT_OK(stages);
46 flatbuffers::FlatBufferBuilder builder;
47 fb::RuntimeStagesBuilder stages_builder(builder);
48 stages_builder.add_format_version(0);
49 auto stages = stages_builder.Finish();
50 builder.Finish(stages, fb::RuntimeStagesIdentifier());
51 auto mapping = std::make_shared<fml::NonOwnedMapping>(
52 builder.GetBufferPointer(), builder.GetSize());
54 EXPECT_FALSE(runtime_stages.ok());
55 EXPECT_EQ(runtime_stages.status().code(), absl::StatusCode::kInvalidArgument);
60 const std::shared_ptr<fml::Mapping> fixture =
61 flutter::testing::OpenFixtureAsMapping(
"ink_sparkle.frag.iplr");
63 auto junk_allocation = std::make_shared<Allocation>();
64 ASSERT_TRUE(junk_allocation->Truncate(
Bytes{fixture->GetSize()},
false));
67 ::memset(junk_allocation->GetBuffer(), 127,
68 junk_allocation->GetLength().GetByteSize());
71 ASSERT_FALSE(stages.ok());
75 const std::shared_ptr<fml::Mapping> fixture =
76 flutter::testing::OpenFixtureAsMapping(
"ink_sparkle.frag.iplr");
78 ASSERT_GT(fixture->GetSize(), 0u);
80 ABSL_ASSERT_OK(stages);
85 switch (GetBackend()) {
89 ASSERT_EQ(stage->GetUniforms().size(), 17u);
91 auto uni = stage->GetUniform(
"u_color");
92 ASSERT_NE(uni,
nullptr);
93 EXPECT_EQ(uni->dimensions.rows, 4u);
94 EXPECT_EQ(uni->dimensions.cols, 1u);
95 EXPECT_EQ(uni->location, 0u);
99 auto uni = stage->GetUniform(
"u_alpha");
100 ASSERT_NE(uni,
nullptr);
101 EXPECT_EQ(uni->dimensions.rows, 1u);
102 EXPECT_EQ(uni->dimensions.cols, 1u);
103 EXPECT_EQ(uni->location, 1u);
107 auto uni = stage->GetUniform(
"u_sparkle_color");
108 ASSERT_NE(uni,
nullptr);
109 EXPECT_EQ(uni->dimensions.rows, 4u);
110 EXPECT_EQ(uni->dimensions.cols, 1u);
111 EXPECT_EQ(uni->location, 2u);
115 auto uni = stage->GetUniform(
"u_sparkle_alpha");
116 ASSERT_NE(uni,
nullptr);
117 EXPECT_EQ(uni->dimensions.rows, 1u);
118 EXPECT_EQ(uni->dimensions.cols, 1u);
119 EXPECT_EQ(uni->location, 3u);
123 auto uni = stage->GetUniform(
"u_blur");
124 ASSERT_NE(uni,
nullptr);
125 EXPECT_EQ(uni->dimensions.rows, 1u);
126 EXPECT_EQ(uni->dimensions.cols, 1u);
127 EXPECT_EQ(uni->location, 4u);
131 auto uni = stage->GetUniform(
"u_radius_scale");
132 ASSERT_NE(uni,
nullptr);
133 EXPECT_EQ(uni->dimensions.rows, 1u);
134 EXPECT_EQ(uni->dimensions.cols, 1u);
135 EXPECT_EQ(uni->location, 6u);
139 auto uni = stage->GetUniform(
"u_max_radius");
140 ASSERT_NE(uni,
nullptr);
141 EXPECT_EQ(uni->dimensions.rows, 1u);
142 EXPECT_EQ(uni->dimensions.cols, 1u);
143 EXPECT_EQ(uni->location, 7u);
147 auto uni = stage->GetUniform(
"u_resolution_scale");
148 ASSERT_NE(uni,
nullptr);
149 EXPECT_EQ(uni->dimensions.rows, 2u);
150 EXPECT_EQ(uni->dimensions.cols, 1u);
151 EXPECT_EQ(uni->location, 8u);
155 auto uni = stage->GetUniform(
"u_noise_scale");
156 ASSERT_NE(uni,
nullptr);
157 EXPECT_EQ(uni->dimensions.rows, 2u);
158 EXPECT_EQ(uni->dimensions.cols, 1u);
159 EXPECT_EQ(uni->location, 9u);
163 auto uni = stage->GetUniform(
"u_noise_phase");
164 ASSERT_NE(uni,
nullptr);
165 EXPECT_EQ(uni->dimensions.rows, 1u);
166 EXPECT_EQ(uni->dimensions.cols, 1u);
167 EXPECT_EQ(uni->location, 10u);
172 auto uni = stage->GetUniform(
"u_circle1");
173 ASSERT_NE(uni,
nullptr);
174 EXPECT_EQ(uni->dimensions.rows, 2u);
175 EXPECT_EQ(uni->dimensions.cols, 1u);
176 EXPECT_EQ(uni->location, 11u);
180 auto uni = stage->GetUniform(
"u_circle2");
181 ASSERT_NE(uni,
nullptr);
182 EXPECT_EQ(uni->dimensions.rows, 2u);
183 EXPECT_EQ(uni->dimensions.cols, 1u);
184 EXPECT_EQ(uni->location, 12u);
188 auto uni = stage->GetUniform(
"u_circle3");
189 ASSERT_NE(uni,
nullptr);
190 EXPECT_EQ(uni->dimensions.rows, 2u);
191 EXPECT_EQ(uni->dimensions.cols, 1u);
192 EXPECT_EQ(uni->location, 13u);
196 auto uni = stage->GetUniform(
"u_rotation1");
197 ASSERT_NE(uni,
nullptr);
198 EXPECT_EQ(uni->dimensions.rows, 2u);
199 EXPECT_EQ(uni->dimensions.cols, 1u);
200 EXPECT_EQ(uni->location, 14u);
204 auto uni = stage->GetUniform(
"u_rotation2");
205 ASSERT_NE(uni,
nullptr);
206 EXPECT_EQ(uni->dimensions.rows, 2u);
207 EXPECT_EQ(uni->dimensions.cols, 1u);
208 EXPECT_EQ(uni->location, 15u);
212 auto uni = stage->GetUniform(
"u_rotation3");
213 ASSERT_NE(uni,
nullptr);
214 EXPECT_EQ(uni->dimensions.rows, 2u);
215 EXPECT_EQ(uni->dimensions.cols, 1u);
216 EXPECT_EQ(uni->location, 16u);
222 EXPECT_EQ(stage->GetUniforms().size(), 1u);
226 EXPECT_EQ(uni->struct_float_count, 32u);
237 EXPECT_EQ(uni->GetSize(), 144u);
238 std::vector<uint8_t> layout(uni->GetSize() /
sizeof(
float), 1);
244 EXPECT_THAT(uni->struct_layout, ::testing::ElementsAreArray(layout));
252 GTEST_SKIP() <<
"Test only relevant for Vulkan";
254 const std::shared_ptr<fml::Mapping> fixture =
255 flutter::testing::OpenFixtureAsMapping(
256 "uniforms_and_sampler_1.frag.iplr");
257 ASSERT_TRUE(fixture);
258 ASSERT_GT(fixture->GetSize(), 0u);
260 ABSL_ASSERT_OK(stages);
264 EXPECT_EQ(stage->GetUniforms().size(), 2u);
269 EXPECT_EQ(uni->binding, 65u);
272 auto sampler_uniform = stage->GetUniform(
"u_texture");
274 EXPECT_EQ(sampler_uniform->binding, 64u);
279 GTEST_SKIP() <<
"Test only relevant for Vulkan";
281 const std::shared_ptr<fml::Mapping> fixture =
282 flutter::testing::OpenFixtureAsMapping(
283 "uniforms_and_sampler_2.frag.iplr");
284 ASSERT_TRUE(fixture);
285 ASSERT_GT(fixture->GetSize(), 0u);
287 ABSL_ASSERT_OK(stages);
291 EXPECT_EQ(stage->GetUniforms().size(), 2u);
296 EXPECT_EQ(uni->binding, 64u);
299 auto sampler_uniform = stage->GetUniform(
"u_texture");
301 EXPECT_EQ(sampler_uniform->binding, 65u);
305 const std::shared_ptr<fml::Mapping> fixture =
306 flutter::testing::OpenFixtureAsMapping(
"ink_sparkle.frag.iplr");
307 ASSERT_TRUE(fixture);
308 ASSERT_GT(fixture->GetSize(), 0u);
310 ABSL_ASSERT_OK(stages);
314 std::promise<bool> registration;
315 auto future = registration.get_future();
316 auto library = GetContext()->GetShaderLibrary();
317 library->RegisterFunction(
318 stage->GetEntrypoint(),
320 stage->GetCodeMapping(),
321 fml::MakeCopyable([reg = std::move(registration)](
bool result)
mutable {
322 reg.set_value(result);
324 ASSERT_TRUE(future.get());
328 ASSERT_NE(
function,
nullptr);
337 ASSERT_EQ(
function,
nullptr);
342 auto stages_result = OpenAssetAsRuntimeStage(
"ink_sparkle.frag.iplr");
343 ABSL_ASSERT_OK(stages_result);
349 ASSERT_NE(stage,
nullptr);
350 ASSERT_TRUE(RegisterStage(*stage));
351 auto library = GetContext()->GetShaderLibrary();
352 using VS = RuntimeEffectVertexShader;
354 desc.
SetLabel(
"Runtime Stage InkSparkle");
359 auto vertex_descriptor = std::make_shared<VertexDescriptor>();
360 vertex_descriptor->SetStageInputs(VS::kAllShaderStageInputs,
361 VS::kInterleavedBufferLayout);
363 std::array<DescriptorSetLayout, 2> descriptor_set_layouts = {
364 VS::kDescriptorSetLayouts[0],
371 vertex_descriptor->RegisterDescriptorSetLayouts(descriptor_set_layouts);
375 color0.
format = GetContext()->GetCapabilities()->GetDefaultColorFormat();
380 const auto stencil_fmt =
381 GetContext()->GetCapabilities()->GetDefaultStencilFormat();
383 auto pipeline = GetContext()->GetPipelineLibrary()->GetPipeline(desc).Get();
384 ASSERT_NE(pipeline,
nullptr);
388 auto stages_result = OpenAssetAsRuntimeStage(
"ink_sparkle.frag.iplr");
389 ABSL_ASSERT_OK(stages_result);
390 auto stages = stages_result.value();
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