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