8 #include "flutter/fml/make_copyable.h"
9 #include "flutter/testing/testing.h"
10 #include "gmock/gmock.h"
11 #include "gtest/gtest.h"
16 #include "impeller/entity/runtime_effect.vert.h"
22 #include "impeller/runtime_stage/runtime_stage_flatbuffers.h"
24 #include "runtime_stage_types_flatbuffers.h"
25 #include "third_party/abseil-cpp/absl/status/status_matchers.h"
34 const std::shared_ptr<fml::Mapping> fixture =
35 flutter::testing::OpenFixtureAsMapping(
"ink_sparkle.frag.iplr");
37 ASSERT_GT(fixture->GetSize(), 0u);
39 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(
77 "all_supported_uniforms.frag.iplr");
79 ASSERT_GT(fixture->GetSize(), 0u);
81 ABSL_ASSERT_OK(stages);
85 switch (GetBackend()) {
91 ASSERT_EQ(stage->GetUniforms().size(), 14u);
94 auto uni = stage->GetUniform(
"uFloat");
95 ASSERT_NE(uni,
nullptr);
96 EXPECT_EQ(uni->dimensions.rows, 1u);
97 EXPECT_EQ(uni->dimensions.cols, 1u);
98 EXPECT_EQ(uni->location, 0u);
100 EXPECT_TRUE(uni->padding_layout.empty());
104 auto uni = stage->GetUniform(
"uVec2");
105 ASSERT_NE(uni,
nullptr);
106 EXPECT_EQ(uni->dimensions.rows, 2u);
107 EXPECT_EQ(uni->dimensions.cols, 1u);
108 EXPECT_EQ(uni->location, 1u);
110 EXPECT_TRUE(uni->padding_layout.empty());
114 auto uni = stage->GetUniform(
"uVec3");
115 ASSERT_NE(uni,
nullptr);
116 EXPECT_EQ(uni->dimensions.rows, 3u);
117 EXPECT_EQ(uni->dimensions.cols, 1u);
118 EXPECT_EQ(uni->location, 2u);
120 auto padding = uni->padding_layout;
134 auto uni = stage->GetUniform(
"uVec4");
135 ASSERT_NE(uni,
nullptr);
136 EXPECT_EQ(uni->dimensions.rows, 4u);
137 EXPECT_EQ(uni->dimensions.cols, 1u);
138 EXPECT_EQ(uni->location, 3u);
140 EXPECT_TRUE(uni->padding_layout.empty());
144 auto uni = stage->GetUniform(
"uMat2");
145 ASSERT_NE(uni,
nullptr);
146 EXPECT_EQ(uni->dimensions.rows, 2u);
147 EXPECT_EQ(uni->dimensions.cols, 2u);
148 EXPECT_EQ(uni->location, 4u);
150 EXPECT_TRUE(uni->padding_layout.empty());
154 auto uni = stage->GetUniform(
"uMat3");
155 ASSERT_NE(uni,
nullptr);
156 EXPECT_EQ(uni->dimensions.rows, 3u);
157 EXPECT_EQ(uni->dimensions.cols, 3u);
158 EXPECT_EQ(uni->location, 5u);
163 auto uni = stage->GetUniform(
"uMat4");
164 ASSERT_NE(uni,
nullptr);
165 EXPECT_EQ(uni->dimensions.rows, 4u);
166 EXPECT_EQ(uni->dimensions.cols, 4u);
167 EXPECT_EQ(uni->location, 6u);
169 EXPECT_TRUE(uni->padding_layout.empty());
173 auto uni = stage->GetUniform(
"uFloatArray");
174 ASSERT_NE(uni,
nullptr);
175 EXPECT_EQ(uni->dimensions.rows, 1u);
176 EXPECT_EQ(uni->dimensions.cols, 1u);
177 EXPECT_EQ(uni->location, 7u);
179 EXPECT_TRUE(uni->padding_layout.empty());
182 auto uni = stage->GetUniform(
"uVec2Array");
183 ASSERT_NE(uni,
nullptr);
184 EXPECT_EQ(uni->dimensions.rows, 2u);
185 EXPECT_EQ(uni->dimensions.cols, 1u);
186 EXPECT_EQ(uni->location, 9u);
188 EXPECT_TRUE(uni->padding_layout.empty());
192 auto uni = stage->GetUniform(
"uVec3Array");
193 ASSERT_NE(uni,
nullptr);
194 EXPECT_EQ(uni->dimensions.rows, 3u);
195 EXPECT_EQ(uni->dimensions.cols, 1u);
196 EXPECT_EQ(uni->location, 11u);
201 auto uni = stage->GetUniform(
"uVec4Array");
202 ASSERT_NE(uni,
nullptr);
203 EXPECT_EQ(uni->dimensions.rows, 4u);
204 EXPECT_EQ(uni->dimensions.cols, 1u);
205 EXPECT_EQ(uni->location, 13u);
207 EXPECT_TRUE(uni->padding_layout.empty());
211 auto uni = stage->GetUniform(
"uMat2Array");
212 ASSERT_NE(uni,
nullptr);
213 EXPECT_EQ(uni->dimensions.rows, 2u);
214 EXPECT_EQ(uni->dimensions.cols, 2u);
215 EXPECT_EQ(uni->location, 15u);
217 EXPECT_TRUE(uni->padding_layout.empty());
221 auto uni = stage->GetUniform(
"uMat3Array");
222 ASSERT_NE(uni,
nullptr);
223 EXPECT_EQ(uni->dimensions.rows, 3u);
224 EXPECT_EQ(uni->dimensions.cols, 3u);
225 EXPECT_EQ(uni->location, 17u);
230 auto uni = stage->GetUniform(
"uMat4Array");
231 ASSERT_NE(uni,
nullptr);
232 EXPECT_EQ(uni->dimensions.rows, 4u);
233 EXPECT_EQ(uni->dimensions.cols, 4u);
234 EXPECT_EQ(uni->location, 19u);
236 EXPECT_TRUE(uni->padding_layout.empty());
241 EXPECT_EQ(stage->GetUniforms().size(), 1u);
249 std::vector<RuntimePaddingType> layout(uni->
GetGPUSize() /
sizeof(
float),
311 EXPECT_THAT(uni->
padding_layout, ::testing::ElementsAreArray(layout));
313 std::vector<std::pair<std::string, unsigned int>> expected_uniforms = {
314 {
"uFloat", 4}, {
"uVec2", 8}, {
"uVec3", 12},
315 {
"uVec4", 16}, {
"uMat2", 16}, {
"uMat3", 36},
316 {
"uMat4", 64}, {
"uFloatArray", 8}, {
"uVec2Array", 16},
317 {
"uVec3Array", 24}, {
"uVec4Array", 32}, {
"uMat2Array", 32},
318 {
"uMat3Array", 72}, {
"uMat4Array", 128}};
320 ASSERT_EQ(uni->
struct_fields.size(), expected_uniforms.size());
322 for (
size_t i = 0; i < expected_uniforms.size(); ++i) {
324 const auto& expected = expected_uniforms[i];
326 EXPECT_EQ(element.name, expected.first) <<
"index: " << i;
327 EXPECT_EQ(element.byte_size, expected.second) <<
"index: " << i;
336 GTEST_SKIP() <<
"Test only relevant for Vulkan";
338 const std::shared_ptr<fml::Mapping> fixture =
339 flutter::testing::OpenFixtureAsMapping(
340 "uniforms_and_sampler_1.frag.iplr");
341 ASSERT_TRUE(fixture);
342 ASSERT_GT(fixture->GetSize(), 0u);
344 ABSL_ASSERT_OK(stages);
347 EXPECT_EQ(stage->GetUniforms().size(), 2u);
352 EXPECT_EQ(uni->binding, 65u);
355 auto sampler_uniform = stage->GetUniform(
"u_texture");
357 EXPECT_EQ(sampler_uniform->binding, 64u);
362 GTEST_SKIP() <<
"Test only relevant for Vulkan";
364 const std::shared_ptr<fml::Mapping> fixture =
365 flutter::testing::OpenFixtureAsMapping(
366 "uniforms_and_sampler_2.frag.iplr");
367 ASSERT_TRUE(fixture);
368 ASSERT_GT(fixture->GetSize(), 0u);
370 ABSL_ASSERT_OK(stages);
373 EXPECT_EQ(stage->GetUniforms().size(), 2u);
378 EXPECT_EQ(uni->binding, 64u);
381 auto sampler_uniform = stage->GetUniform(
"u_texture");
383 EXPECT_EQ(sampler_uniform->binding, 65u);
387 const std::shared_ptr<fml::Mapping> fixture =
388 flutter::testing::OpenFixtureAsMapping(
"ink_sparkle.frag.iplr");
389 ASSERT_TRUE(fixture);
390 ASSERT_GT(fixture->GetSize(), 0u);
392 ABSL_ASSERT_OK(stages);
395 std::promise<bool> registration;
396 auto future = registration.get_future();
397 auto library = GetContext()->GetShaderLibrary();
398 library->RegisterFunction(
399 stage->GetEntrypoint(),
401 stage->GetCodeMapping(),
402 fml::MakeCopyable([reg = std::move(registration)](
bool result)
mutable {
403 reg.set_value(result);
405 ASSERT_TRUE(future.get());
409 ASSERT_NE(
function,
nullptr);
418 ASSERT_EQ(
function,
nullptr);
423 auto stages_result = OpenAssetAsRuntimeStage(
"ink_sparkle.frag.iplr");
424 ABSL_ASSERT_OK(stages_result);
428 ASSERT_NE(stage,
nullptr);
429 ASSERT_TRUE(RegisterStage(*stage));
430 auto library = GetContext()->GetShaderLibrary();
431 using VS = RuntimeEffectVertexShader;
433 desc.
SetLabel(
"Runtime Stage InkSparkle");
438 auto vertex_descriptor = std::make_shared<VertexDescriptor>();
439 vertex_descriptor->SetStageInputs(VS::kAllShaderStageInputs,
440 VS::kInterleavedBufferLayout);
442 std::array<DescriptorSetLayout, 2> descriptor_set_layouts = {
443 VS::kDescriptorSetLayouts[0],
450 vertex_descriptor->RegisterDescriptorSetLayouts(descriptor_set_layouts);
454 color0.
format = GetContext()->GetCapabilities()->GetDefaultColorFormat();
459 const auto stencil_fmt =
460 GetContext()->GetCapabilities()->GetDefaultStencilFormat();
462 auto pipeline = GetContext()->GetPipelineLibrary()->GetPipeline(desc).Get();
463 ASSERT_NE(pipeline,
nullptr);
467 auto stages_result = OpenAssetAsRuntimeStage(
"ink_sparkle.frag.iplr");
468 ABSL_ASSERT_OK(stages_result);
469 auto stages = stages_result.value();
478 OpenAssetAsRuntimeStage(
"runtime_stage_simple_no_sksl.frag.iplr");
479 ABSL_ASSERT_OK(stages_result);
480 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)
Vector2 padding
The halo padding in source space.
static std::optional< RuntimeStageBackend > GetRuntimeStageBackend(TargetPlatform target_platform)
TEST_P(AiksTest, DrawAtlasNoColor)
INSTANTIATE_PLAYGROUND_SUITE(AiksTest)
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