Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
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
19
20namespace impeller {
21
22class ContextGLES;
23class PipelineGLES;
24
26 : public PipelineLibrary,
27 public BackendCast<PipelineLibraryGLES, PipelineLibrary> {
28 public:
29 // |PipelineLibrary|
31
33
35
36 private:
37 friend ContextGLES;
38
39 //----------------------------------------------------------------------------
40 /// @brief A subset of the items in a pipeline descriptor (and the items
41 /// they reference in shader libraries) whose dynamism requires a
42 /// program object re-compilation and link. In all other cases,
43 /// creating a pipeline variant reuses an existing (compatible)
44 /// program object.
45 ///
46 struct ProgramKey {
47 std::shared_ptr<const ShaderFunction> vertex_shader;
48 std::shared_ptr<const ShaderFunction> fragment_shader;
49 //--------------------------------------------------------------------------
50 /// Specialization constants used in the shaders affect defines used when
51 /// compiling and linking the program.
52 ///
53 std::vector<Scalar> specialization_constants;
54
55 ProgramKey(std::shared_ptr<const ShaderFunction> p_vertex_shader,
56 std::shared_ptr<const ShaderFunction> p_fragment_shader,
57 std::vector<Scalar> p_specialization_constants)
58 : vertex_shader(std::move(p_vertex_shader)),
59 fragment_shader(std::move(p_fragment_shader)),
60 specialization_constants(std::move(p_specialization_constants)) {}
61
62 struct Hash {
63 std::size_t operator()(const ProgramKey& key) const {
64 auto seed = fml::HashCombine();
65 if (key.vertex_shader) {
66 fml::HashCombineSeed(seed, key.vertex_shader->GetHash());
67 }
68 if (key.fragment_shader) {
69 fml::HashCombineSeed(seed, key.fragment_shader->GetHash());
70 }
71 for (const auto& constant : key.specialization_constants) {
72 fml::HashCombineSeed(seed, constant);
73 }
74 return seed;
75 }
76 };
77
78 struct Equal {
79 bool operator()(const ProgramKey& lhs, const ProgramKey& rhs) const {
80 return DeepComparePointer(lhs.vertex_shader, rhs.vertex_shader) &&
81 DeepComparePointer(lhs.fragment_shader, rhs.fragment_shader) &&
82 lhs.specialization_constants == rhs.specialization_constants;
83 }
84 };
85 };
86
87 using ProgramMap = std::unordered_map<ProgramKey,
88 std::shared_ptr<UniqueHandleGLES>,
89 ProgramKey::Hash,
90 ProgramKey::Equal>;
91
92 std::shared_ptr<ReactorGLES> reactor_;
93 PipelineMap pipelines_;
94 Mutex programs_mutex_;
95 ProgramMap programs_ IPLR_GUARDED_BY(programs_mutex_);
96 std::shared_ptr<PipelineCompileQueueGLES> compile_queue_;
97
98 explicit PipelineLibraryGLES(
99 std::shared_ptr<ReactorGLES> reactor,
100 std::shared_ptr<fml::BasicTaskRunner> io_task_runner);
101
102 // |PipelineLibrary|
103 bool IsValid() const override;
104
105 // |PipelineLibrary|
107 bool async,
108 bool threadsafe) override;
109
110 // |PipelineLibrary|
112 ComputePipelineDescriptor descriptor,
113 bool async) override;
114
115 // |PipelineLibrary|
116 bool HasPipeline(const PipelineDescriptor& descriptor) override;
117
118 // |PipelineLibrary|
119 void RemovePipelinesWithEntryPoint(
120 std::shared_ptr<const ShaderFunction> function) override;
121
122 const std::shared_ptr<ReactorGLES>& GetReactor() const;
123
124 static std::shared_ptr<PipelineGLES> CreatePipeline(
125 const std::weak_ptr<PipelineLibrary>& weak_library,
126 const PipelineDescriptor& desc,
127 const std::shared_ptr<const ShaderFunction>& vert_shader,
128 const std::shared_ptr<const ShaderFunction>& frag_shader,
129 bool threadsafe);
130
131 std::shared_ptr<UniqueHandleGLES> GetProgramForKey(const ProgramKey& key);
132
133 void SetProgramForKey(const ProgramKey& key,
134 std::shared_ptr<UniqueHandleGLES> program);
135 // |PipelineLibrary|
136 PipelineCompileQueue* GetPipelineCompileQueue() const override;
137};
138
139} // namespace impeller
140
141#endif // FLUTTER_IMPELLER_RENDERER_BACKEND_GLES_PIPELINE_LIBRARY_GLES_H_
A task queue designed for managing compilation of pipeline state objects.
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:55
std::shared_ptr< ReactorGLES > reactor
bool operator()(const ProgramKey &lhs, const ProgramKey &rhs) const
std::size_t operator()(const ProgramKey &key) const
#define IPLR_GUARDED_BY(x)