| Flutter Impeller |

pipeline_library.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_PIPELINE_LIBRARY_H_
6 #define FLUTTER_IMPELLER_RENDERER_PIPELINE_LIBRARY_H_
7
8 #include <optional>
9 #include <unordered_map>
10
11 #include "compute_pipeline_descriptor.h"
12 #include "impeller/base/thread.h"
13 #include "impeller/base/thread_safety.h"
14 #include "impeller/renderer/pipeline.h"
15 #include "impeller/renderer/pipeline_descriptor.h"
16
17 namespace impeller {
18
19 class Context;
20
21 using PipelineMap = std::unordered_map<PipelineDescriptor,
22 PipelineFuture<PipelineDescriptor>,
23 ComparableHash<PipelineDescriptor>,
24 ComparableEqual<PipelineDescriptor>>;
25
26 using ComputePipelineMap =
27 std::unordered_map<ComputePipelineDescriptor,
28 PipelineFuture<ComputePipelineDescriptor>,
29 ComparableHash<ComputePipelineDescriptor>,
30 ComparableEqual<ComputePipelineDescriptor>>;
31
32 class PipelineLibrary : public std::enable_shared_from_this<PipelineLibrary> {
33 public:
34 virtual ~PipelineLibrary();
35
36 PipelineFuture<PipelineDescriptor> GetPipeline(
37 std::optional<PipelineDescriptor> descriptor,
38 bool async = true);
39
40 PipelineFuture<ComputePipelineDescriptor> GetPipeline(
41 std::optional<ComputePipelineDescriptor> descriptor,
42 bool async = true);
43
44 virtual bool IsValid() const = 0;
45
46 //------------------------------------------------------------------------------
47 /// @brief Creates a pipeline.
48 ///
49 /// @param[in] descriptor The descriptor of the texture to create.
50 /// @param[in] async Whether to allow pipeline creation to be deferred.
51 /// If `false`, pipeline creation will block on the
52 /// current thread.
53 ///
54 /// @param[in] threadsafe Whether mutations to this texture should be
55 /// protected with a threadsafe barrier.
56 ///
57 /// This parameter only affects the OpenGLES rendering
58 /// backend.
59 ///
60 /// If any interaction with this texture (including
61 /// creation) will be done on a thread other than
62 /// where the OpenGLES context resides, then
63 /// `threadsafe`, must be set to `true`.
64 ///
65 virtual PipelineFuture<PipelineDescriptor> GetPipeline(
66 PipelineDescriptor descriptor,
67 bool async = true,
68 bool threadsafe = false) = 0;
69
70 virtual PipelineFuture<ComputePipelineDescriptor> GetPipeline(
71 ComputePipelineDescriptor descriptor,
72 bool async = true) = 0;
73
74 virtual bool HasPipeline(const PipelineDescriptor& descriptor) = 0;
75
76 virtual void RemovePipelinesWithEntryPoint(
77 std::shared_ptr<const ShaderFunction> function) = 0;
78
79 void LogPipelineUsage(const PipelineDescriptor& p);
80
81 void LogPipelineCreation(const PipelineDescriptor& p);
82
83 std::unordered_map<PipelineDescriptor,
84 int,
85 ComparableHash<PipelineDescriptor>,
86 ComparableEqual<PipelineDescriptor>>
87 GetPipelineUseCounts() const;
88
89 protected:
90 PipelineLibrary();
91
92 private:
93 PipelineLibrary(const PipelineLibrary&) = delete;
94
95 PipelineLibrary& operator=(const PipelineLibrary&) = delete;
96 #if FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG || \
97 FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_PROFILE
98 mutable RWMutex pipeline_use_counts_mutex_;
99
100 std::unordered_map<PipelineDescriptor,
101 int,
102 ComparableHash<PipelineDescriptor>,
103 ComparableEqual<PipelineDescriptor>>
104 pipeline_use_counts_ IPLR_GUARDED_BY(pipeline_use_counts_mutex_);
105
106 #endif
107 };
108
109 } // namespace impeller
110
111 #endif // FLUTTER_IMPELLER_RENDERER_PIPELINE_LIBRARY_H_
impeller::ComputePipelineDescriptor
Definition: compute_pipeline_descriptor.h:21
impeller::PipelineDescriptor
Definition: pipeline_descriptor.h:24
impeller::PipelineLibrary
Definition: pipeline_library.h:32
impeller::PipelineLibrary::PipelineLibrary
PipelineLibrary()
impeller::PipelineLibrary::HasPipeline
virtual bool HasPipeline(const PipelineDescriptor &descriptor)=0
impeller::PipelineLibrary::RemovePipelinesWithEntryPoint
virtual void RemovePipelinesWithEntryPoint(std::shared_ptr< const ShaderFunction > function)=0
impeller::PipelineLibrary::GetPipeline
virtual PipelineFuture< ComputePipelineDescriptor > GetPipeline(ComputePipelineDescriptor descriptor, bool async=true)=0
impeller::PipelineLibrary::LogPipelineUsage
void LogPipelineUsage(const PipelineDescriptor &p)
Definition: pipeline_library.cc:51
impeller::PipelineLibrary::GetPipeline
virtual PipelineFuture< PipelineDescriptor > GetPipeline(PipelineDescriptor descriptor, bool async=true, bool threadsafe=false)=0
Creates a pipeline.
impeller::PipelineLibrary::GetPipelineUseCounts
std::unordered_map< PipelineDescriptor, int, ComparableHash< PipelineDescriptor >, ComparableEqual< PipelineDescriptor > > GetPipelineUseCounts() const
Definition: pipeline_library.cc:63
impeller::PipelineLibrary::IsValid
virtual bool IsValid() const =0
impeller::PipelineLibrary::~PipelineLibrary
virtual ~PipelineLibrary()
impeller::PipelineLibrary::LogPipelineCreation
void LogPipelineCreation(const PipelineDescriptor &p)
Definition: pipeline_library.cc:41
impeller::PipelineLibrary::GetPipeline
PipelineFuture< PipelineDescriptor > GetPipeline(std::optional< PipelineDescriptor > descriptor, bool async=true)
Definition: pipeline_library.cc:17
compute_pipeline_descriptor.h
impeller
Definition: allocation.cc:12
impeller::ComputePipelineMap
std::unordered_map< ComputePipelineDescriptor, PipelineFuture< ComputePipelineDescriptor >, ComparableHash< ComputePipelineDescriptor >, ComparableEqual< ComputePipelineDescriptor > > ComputePipelineMap
Definition: pipeline_library.h:30
impeller::PipelineMap
std::unordered_map< PipelineDescriptor, PipelineFuture< PipelineDescriptor >, ComparableHash< PipelineDescriptor >, ComparableEqual< PipelineDescriptor > > PipelineMap
Definition: pipeline_library.h:24
pipeline.h
pipeline_descriptor.h
impeller::ComparableEqual
Definition: comparable.h:48
impeller::ComparableHash
Definition: comparable.h:39
impeller::PipelineFuture
Definition: pipeline.h:28
thread.h
thread_safety.h