| Flutter Impeller |

pipeline_library_gles.h
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 #ifndef FLUTTER_IMPELLER_RENDERER_BACKEND_GLES_PIPELINE_LIBRARY_GLES_H_
6 #define FLUTTER_IMPELLER_RENDERER_BACKEND_GLES_PIPELINE_LIBRARY_GLES_H_
7
8 #include <unordered_map>
9 #include <vector>
10
11 #include "flutter/fml/hash_combine.h"
12 #include "impeller/base/thread.h"
13 #include "impeller/renderer/backend/gles/reactor_gles.h"
14 #include "impeller/renderer/backend/gles/unique_handle_gles.h"
15 #include "impeller/renderer/pipeline_library.h"
16 #include "impeller/renderer/shader_function.h"
17
18 namespace impeller {
19
20 class ContextGLES;
21 class PipelineGLES;
22
23 class PipelineLibraryGLES final
24 : public PipelineLibrary,
25 public BackendCast<PipelineLibraryGLES, PipelineLibrary> {
26 public:
27 // |PipelineLibrary|
28 ~PipelineLibraryGLES() override;
29
30 PipelineLibraryGLES(const PipelineLibraryGLES&) = delete;
31
32 PipelineLibraryGLES& operator=(const PipelineLibraryGLES&) = delete;
33
34 private:
35 friend ContextGLES;
36
37 //----------------------------------------------------------------------------
38 /// @brief A subset of the items in a pipeline descriptor (and the items
39 /// they reference in shader libraries) whose dynamism requires a
40 /// program object re-compilation and link. In all other cases,
41 /// creating a pipeline variant reuses an existing (compatible)
42 /// program object.
43 ///
44 struct ProgramKey {
45 std::shared_ptr<const ShaderFunction> vertex_shader;
46 std::shared_ptr<const ShaderFunction> fragment_shader;
47 //--------------------------------------------------------------------------
48 /// Specialization constants used in the shaders affect defines used when
49 /// compiling and linking the program.
50 ///
51 std::vector<Scalar> specialization_constants;
52
53 ProgramKey(std::shared_ptr<const ShaderFunction> p_vertex_shader,
54 std::shared_ptr<const ShaderFunction> p_fragment_shader,
55 std::vector<Scalar> p_specialization_constants)
56 : vertex_shader(std::move(p_vertex_shader)),
57 fragment_shader(std::move(p_fragment_shader)),
58 specialization_constants(std::move(p_specialization_constants)) {}
59
60 struct Hash {
61 std::size_t operator()(const ProgramKey& key) const {
62 auto seed = fml::HashCombine();
63 if (key.vertex_shader) {
64 fml::HashCombineSeed(seed, key.vertex_shader->GetHash());
65 }
66 if (key.fragment_shader) {
67 fml::HashCombineSeed(seed, key.fragment_shader->GetHash());
68 }
69 for (const auto& constant : key.specialization_constants) {
70 fml::HashCombineSeed(seed, constant);
71 }
72 return seed;
73 }
74 };
75
76 struct Equal {
77 bool operator()(const ProgramKey& lhs, const ProgramKey& rhs) const {
78 return DeepComparePointer(lhs.vertex_shader, rhs.vertex_shader) &&
79 DeepComparePointer(lhs.fragment_shader, rhs.fragment_shader) &&
80 lhs.specialization_constants == rhs.specialization_constants;
81 }
82 };
83 };
84
85 using ProgramMap = std::unordered_map<ProgramKey,
86 std::shared_ptr<UniqueHandleGLES>,
87 ProgramKey::Hash,
88 ProgramKey::Equal>;
89
90 ReactorGLES::Ref reactor_;
91 PipelineMap pipelines_;
92 Mutex programs_mutex_;
93 ProgramMap programs_ IPLR_GUARDED_BY(programs_mutex_);
94
95 explicit PipelineLibraryGLES(ReactorGLES::Ref reactor);
96
97 // |PipelineLibrary|
98 bool IsValid() const override;
99
100 // |PipelineLibrary|
101 PipelineFuture<PipelineDescriptor> GetPipeline(PipelineDescriptor descriptor,
102 bool async) override;
103
104 // |PipelineLibrary|
105 PipelineFuture<ComputePipelineDescriptor> GetPipeline(
106 ComputePipelineDescriptor descriptor,
107 bool async) override;
108
109 // |PipelineLibrary|
110 bool HasPipeline(const PipelineDescriptor& descriptor) override;
111
112 // |PipelineLibrary|
113 void RemovePipelinesWithEntryPoint(
114 std::shared_ptr<const ShaderFunction> function) override;
115
116 const ReactorGLES::Ref& GetReactor() const;
117
118 static std::shared_ptr<PipelineGLES> CreatePipeline(
119 const std::weak_ptr<PipelineLibrary>& weak_library,
120 const PipelineDescriptor& desc,
121 const std::shared_ptr<const ShaderFunction>& vert_shader,
122 const std::shared_ptr<const ShaderFunction>& frag_shader);
123
124 std::shared_ptr<UniqueHandleGLES> GetProgramForKey(const ProgramKey& key);
125
126 void SetProgramForKey(const ProgramKey& key,
127 std::shared_ptr<UniqueHandleGLES> program);
128 };
129
130 } // namespace impeller
131
132 #endif // FLUTTER_IMPELLER_RENDERER_BACKEND_GLES_PIPELINE_LIBRARY_GLES_H_
impeller::PipelineDescriptor
Definition: pipeline_descriptor.h:24
impeller::ComputePipelineDescriptor
Definition: compute_pipeline_descriptor.h:20
impeller::DeepComparePointer
bool DeepComparePointer(const std::shared_ptr< ComparableType > &lhs, const std::shared_ptr< ComparableType > &rhs)
Definition: comparable.h:57
shader_function.h
impeller::PipelineLibraryGLES::ProgramKey::Equal::operator()
bool operator()(const ProgramKey &lhs, const ProgramKey &rhs) const
Definition: pipeline_library_gles.h:77
impeller::ReactorGLES::Ref
std::shared_ptr< ReactorGLES > Ref
Definition: reactor_gles.h:86
impeller::PipelineLibraryGLES::ProgramKey::Equal
Definition: pipeline_library_gles.h:76
impeller::PipelineLibraryGLES::ProgramKey::Hash
Definition: pipeline_library_gles.h:60
impeller::PipelineLibraryGLES::ProgramKey::Hash::operator()
std::size_t operator()(const ProgramKey &key) const
Definition: pipeline_library_gles.h:61
impeller::ContextGLES
Definition: context_gles.h:22
impeller::PipelineFuture
Definition: pipeline.h:25
impeller::PipelineLibrary
Definition: pipeline_library.h:29
impeller::PipelineLibraryGLES::PipelineLibraryGLES
PipelineLibraryGLES(const PipelineLibraryGLES &)=delete
impeller::PipelineMap
std::unordered_map< PipelineDescriptor, PipelineFuture< PipelineDescriptor >, ComparableHash< PipelineDescriptor >, ComparableEqual< PipelineDescriptor > > PipelineMap
Definition: pipeline_library.h:21
pipeline_library.h
reactor_gles.h
impeller::BackendCast
Definition: backend_cast.h:11
impeller::PipelineLibraryGLES::operator=
PipelineLibraryGLES & operator=(const PipelineLibraryGLES &)=delete
unique_handle_gles.h
thread.h
impeller::PipelineLibraryGLES::~PipelineLibraryGLES
~PipelineLibraryGLES() override
impeller
Definition: allocation.cc:12
impeller::PipelineLibraryGLES
Definition: pipeline_library_gles.h:23