Flutter Engine
 
Loading...
Searching...
No Matches
pipeline_library_gles_unittests.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "impeller/fixtures/spec_constant.frag.h"
6#include "impeller/fixtures/spec_constant.vert.h"
12
13namespace impeller::testing {
14
17
18// NOLINTBEGIN(bugprone-unchecked-optional-access)
19TEST_P(PipelineLibraryGLESTest, ProgramHandlesAreReused) {
20 using VS = SpecConstantVertexShader;
21 using FS = SpecConstantFragmentShader;
22 auto context = GetContext();
23 ASSERT_TRUE(context);
25 ASSERT_TRUE(desc.has_value());
26 auto pipeline = context->GetPipelineLibrary()->GetPipeline(desc).Get();
27 ASSERT_TRUE(pipeline && pipeline->IsValid());
28 auto new_desc = desc;
29 // Changing the sample counts should not result in a new program object.
30 new_desc->SetSampleCount(SampleCount::kCount4);
31 // Make sure we don't hit the top-level descriptor cache. This will cause
32 // caching irrespective of backends.
33 ASSERT_FALSE(desc->IsEqual(new_desc.value()));
34 auto new_pipeline =
35 context->GetPipelineLibrary()->GetPipeline(new_desc).Get();
36 ASSERT_TRUE(new_pipeline && new_pipeline->IsValid());
37 const auto& pipeline_gles = PipelineGLES::Cast(*pipeline);
38 const auto& new_pipeline_gles = PipelineGLES::Cast(*new_pipeline);
39 // The program handles should be live and equal.
40 ASSERT_FALSE(pipeline_gles.GetProgramHandle().IsDead());
41 ASSERT_FALSE(new_pipeline_gles.GetProgramHandle().IsDead());
42 ASSERT_EQ(pipeline_gles.GetProgramHandle().GetName().value(),
43 new_pipeline_gles.GetProgramHandle().GetName().value());
44}
45
46TEST_P(PipelineLibraryGLESTest, ChangingSpecConstantsCausesNewProgramObject) {
47 using VS = SpecConstantVertexShader;
48 using FS = SpecConstantFragmentShader;
49 auto context = GetContext();
50 ASSERT_TRUE(context);
52 ASSERT_TRUE(desc.has_value());
53 desc->SetSpecializationConstants({2.0f});
54 auto pipeline = context->GetPipelineLibrary()->GetPipeline(desc).Get();
55 ASSERT_TRUE(pipeline && pipeline->IsValid());
56 auto new_desc = desc;
57 // Changing the spec. constants should result in a new program object.
58 new_desc->SetSpecializationConstants({4.0f});
59 auto new_pipeline =
60 context->GetPipelineLibrary()->GetPipeline(new_desc).Get();
61 ASSERT_TRUE(new_pipeline && new_pipeline->IsValid());
62 const auto& pipeline_gles = PipelineGLES::Cast(*pipeline);
63 const auto& new_pipeline_gles = PipelineGLES::Cast(*new_pipeline);
64 // The program handles should be live and equal.
65 ASSERT_FALSE(pipeline_gles.GetProgramHandle().IsDead());
66 ASSERT_FALSE(new_pipeline_gles.GetProgramHandle().IsDead());
67 ASSERT_FALSE(pipeline_gles.GetProgramHandle().GetName().value() ==
68 new_pipeline_gles.GetProgramHandle().GetName().value());
69}
70
71TEST_P(PipelineLibraryGLESTest, ClearingPipelineWillAlsoClearProgramHandle) {
72 using VS = SpecConstantVertexShader;
73 using FS = SpecConstantFragmentShader;
74 std::shared_ptr<Context> context = GetContext();
75 std::optional<PipelineDescriptor> desc =
77
78 std::shared_ptr<Pipeline<PipelineDescriptor>> pipeline =
79 context->GetPipelineLibrary()->GetPipeline(desc).Get();
80 ASSERT_TRUE(pipeline && pipeline->IsValid());
81 const auto& pipeline_gles = PipelineGLES::Cast(*pipeline);
82 HandleGLES handle = pipeline_gles.GetProgramHandle();
83
84 // Clear the pipeline descriptor.
85 auto entrypoint =
86 pipeline->GetDescriptor().GetEntrypointForStage(ShaderStage::kFragment);
87 context->GetPipelineLibrary()->RemovePipelinesWithEntryPoint(entrypoint);
88
89 // Re-create the pipeline
90 std::shared_ptr<Pipeline<PipelineDescriptor>> pipeline_2 =
91 context->GetPipelineLibrary()->GetPipeline(desc).Get();
92 ASSERT_TRUE(pipeline && pipeline->IsValid());
93 const auto& pipeline_gles_2 = PipelineGLES::Cast(*pipeline_2);
94 HandleGLES handle_2 = pipeline_gles_2.GetProgramHandle();
95
96 EXPECT_FALSE(HandleGLES::Equal{}(handle, handle_2));
97}
98// NOLINTEND(bugprone-unchecked-optional-access)
99
100} // namespace impeller::testing
static PipelineGLES & Cast(Pipeline< PipelineDescriptor > &base)
Represents a handle to an underlying OpenGL object. Unlike OpenGL object handles, these handles can b...
Definition handle_gles.h:37
TEST_P(AiksTest, DrawAtlasNoColor)
LinePipeline::FragmentShader FS
LinePipeline::VertexShader VS
#define INSTANTIATE_OPENGLES_PLAYGROUND_SUITE(playground)
A comparer used to test the equality of two handles.
Definition handle_gles.h:68
static std::optional< PipelineDescriptor > MakeDefaultPipelineDescriptor(const Context &context, const std::vector< Scalar > &constants={})
Create a default pipeline descriptor using the combination reflected shader information....