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 
12 #include "impeller/base/thread.h"
16 
17 namespace impeller {
18 
19 class Context;
20 
21 using PipelineMap = std::unordered_map<PipelineDescriptor,
25 
27  std::unordered_map<ComputePipelineDescriptor,
31 
32 class PipelineLibrary : public std::enable_shared_from_this<PipelineLibrary> {
33  public:
34  virtual ~PipelineLibrary();
35 
37  std::optional<PipelineDescriptor> descriptor,
38  bool async = true);
39 
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  ///
66  PipelineDescriptor descriptor,
67  bool async = true,
68  bool threadsafe = false) = 0;
69 
71  ComputePipelineDescriptor descriptor,
72  bool async = true) = 0;
73 
74  virtual bool HasPipeline(const PipelineDescriptor& descriptor) = 0;
75 
77  std::shared_ptr<const ShaderFunction> function) = 0;
78 
79  void LogPipelineUsage(const PipelineDescriptor& p);
80 
82 
83  std::unordered_map<PipelineDescriptor,
84  int,
87  GetPipelineUseCounts() const;
88 
89  protected:
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,
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_
virtual bool HasPipeline(const PipelineDescriptor &descriptor)=0
virtual void RemovePipelinesWithEntryPoint(std::shared_ptr< const ShaderFunction > function)=0
virtual PipelineFuture< ComputePipelineDescriptor > GetPipeline(ComputePipelineDescriptor descriptor, bool async=true)=0
void LogPipelineUsage(const PipelineDescriptor &p)
virtual PipelineFuture< PipelineDescriptor > GetPipeline(PipelineDescriptor descriptor, bool async=true, bool threadsafe=false)=0
Creates a pipeline.
std::unordered_map< PipelineDescriptor, int, ComparableHash< PipelineDescriptor >, ComparableEqual< PipelineDescriptor > > GetPipelineUseCounts() const
virtual bool IsValid() const =0
void LogPipelineCreation(const PipelineDescriptor &p)
PipelineFuture< PipelineDescriptor > GetPipeline(std::optional< PipelineDescriptor > descriptor, bool async=true)
std::unordered_map< ComputePipelineDescriptor, PipelineFuture< ComputePipelineDescriptor >, ComparableHash< ComputePipelineDescriptor >, ComparableEqual< ComputePipelineDescriptor > > ComputePipelineMap
std::unordered_map< PipelineDescriptor, PipelineFuture< PipelineDescriptor >, ComparableHash< PipelineDescriptor >, ComparableEqual< PipelineDescriptor > > PipelineMap