Flutter Engine
 
Loading...
Searching...
No Matches
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
17
18namespace impeller {
19
20class ContextGLES;
21class PipelineGLES;
22
24 : public PipelineLibrary,
25 public BackendCast<PipelineLibraryGLES, PipelineLibrary> {
26 public:
27 // |PipelineLibrary|
29
31
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 std::shared_ptr<ReactorGLES> reactor_;
91 PipelineMap pipelines_;
92 Mutex programs_mutex_;
93 ProgramMap programs_ IPLR_GUARDED_BY(programs_mutex_);
94
95 explicit PipelineLibraryGLES(std::shared_ptr<ReactorGLES> reactor);
96
97 // |PipelineLibrary|
98 bool IsValid() const override;
99
100 // |PipelineLibrary|
102 bool async,
103 bool threadsafe) override;
104
105 // |PipelineLibrary|
107 ComputePipelineDescriptor descriptor,
108 bool async) override;
109
110 // |PipelineLibrary|
111 bool HasPipeline(const PipelineDescriptor& descriptor) override;
112
113 // |PipelineLibrary|
114 void RemovePipelinesWithEntryPoint(
115 std::shared_ptr<const ShaderFunction> function) override;
116
117 const std::shared_ptr<ReactorGLES>& GetReactor() const;
118
119 static std::shared_ptr<PipelineGLES> CreatePipeline(
120 const std::weak_ptr<PipelineLibrary>& weak_library,
121 const PipelineDescriptor& desc,
122 const std::shared_ptr<const ShaderFunction>& vert_shader,
123 const std::shared_ptr<const ShaderFunction>& frag_shader,
124 bool threadsafe);
125
126 std::shared_ptr<UniqueHandleGLES> GetProgramForKey(const ProgramKey& key);
127
128 void SetProgramForKey(const ProgramKey& key,
129 std::shared_ptr<UniqueHandleGLES> program);
130};
131
132} // namespace impeller
133
134#endif // FLUTTER_IMPELLER_RENDERER_BACKEND_GLES_PIPELINE_LIBRARY_GLES_H_
PipelineLibraryGLES & operator=(const PipelineLibraryGLES &)=delete
PipelineLibraryGLES(const PipelineLibraryGLES &)=delete
constexpr std::size_t HashCombine()
constexpr void HashCombineSeed(std::size_t &seed, const Type &arg)
std::unordered_map< PipelineDescriptor, PipelineFuture< PipelineDescriptor >, ComparableHash< PipelineDescriptor >, ComparableEqual< PipelineDescriptor > > PipelineMap
bool DeepComparePointer(const std::shared_ptr< ComparableType > &lhs, const std::shared_ptr< ComparableType > &rhs)
Definition comparable.h:57
bool operator()(const ProgramKey &lhs, const ProgramKey &rhs) const
std::size_t operator()(const ProgramKey &key) const
#define IPLR_GUARDED_BY(x)