Flutter Impeller
compute_pass.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_COMPUTE_PASS_H_
6 #define FLUTTER_IMPELLER_RENDERER_COMPUTE_PASS_H_
7 
8 #include <string>
9 
11 
12 namespace impeller {
13 
14 class HostBuffer;
15 class Allocator;
16 
17 //------------------------------------------------------------------------------
18 /// @brief Compute passes encode compute shader into the underlying command
19 /// buffer.
20 ///
21 /// @see `CommandBuffer`
22 ///
23 class ComputePass {
24  public:
25  virtual ~ComputePass();
26 
27  virtual bool IsValid() const = 0;
28 
29  void SetLabel(const std::string& label);
30 
31  void SetGridSize(const ISize& size);
32 
33  void SetThreadGroupSize(const ISize& size);
34 
36 
37  //----------------------------------------------------------------------------
38  /// @brief Record a command for subsequent encoding to the underlying
39  /// command buffer. No work is encoded into the command buffer at
40  /// this time.
41  ///
42  /// @param[in] command The command
43  ///
44  /// @return If the command was valid for subsequent commitment.
45  ///
46  bool AddCommand(ComputeCommand command);
47 
48  //----------------------------------------------------------------------------
49  /// @brief Encode the recorded commands to the underlying command buffer.
50  ///
51  /// @param transients_allocator The transients allocator.
52  ///
53  /// @return If the commands were encoded to the underlying command
54  /// buffer.
55  ///
56  bool EncodeCommands() const;
57 
58  protected:
59  const std::weak_ptr<const Context> context_;
60  std::vector<ComputeCommand> commands_;
61 
62  explicit ComputePass(std::weak_ptr<const Context> context);
63 
64  virtual void OnSetLabel(const std::string& label) = 0;
65 
66  virtual bool OnEncodeCommands(const Context& context,
67  const ISize& grid_size,
68  const ISize& thread_group_size) const = 0;
69 
70  private:
71  std::shared_ptr<HostBuffer> transients_buffer_;
72  ISize grid_size_ = ISize(32, 32);
73  ISize thread_group_size_ = ISize(32, 32);
74 
75  ComputePass(const ComputePass&) = delete;
76 
77  ComputePass& operator=(const ComputePass&) = delete;
78 };
79 
80 } // namespace impeller
81 
82 #endif // FLUTTER_IMPELLER_RENDERER_COMPUTE_PASS_H_
impeller::ComputePass::SetGridSize
void SetGridSize(const ISize &size)
Definition: compute_pass.cc:31
impeller::ComputePass::ComputePass
ComputePass(std::weak_ptr< const Context > context)
Definition: compute_pass.cc:14
impeller::HostBuffer
Definition: host_buffer.h:20
impeller::ComputePass::IsValid
virtual bool IsValid() const =0
impeller::ComputePass::commands_
std::vector< ComputeCommand > commands_
Definition: compute_pass.h:60
impeller::ComputePass::GetTransientsBuffer
HostBuffer & GetTransientsBuffer()
Definition: compute_pass.cc:19
impeller::ComputePass::EncodeCommands
bool EncodeCommands() const
Encode the recorded commands to the underlying command buffer.
Definition: compute_pass.cc:50
impeller::TSize< int64_t >
impeller::ComputePass::context_
const std::weak_ptr< const Context > context_
Definition: compute_pass.h:59
impeller::ComputePass::AddCommand
bool AddCommand(ComputeCommand command)
Record a command for subsequent encoding to the underlying command buffer. No work is encoded into th...
Definition: compute_pass.cc:39
impeller::ComputePass::OnSetLabel
virtual void OnSetLabel(const std::string &label)=0
impeller::ISize
TSize< int64_t > ISize
Definition: size.h:138
impeller::ComputeCommand
An object used to specify compute work to the GPU along with references to resources the GPU will use...
Definition: compute_command.h:36
impeller::ComputePass::SetLabel
void SetLabel(const std::string &label)
Definition: compute_pass.cc:23
impeller::Context
To do anything rendering related with Impeller, you need a context.
Definition: context.h:47
impeller::ComputePass::SetThreadGroupSize
void SetThreadGroupSize(const ISize &size)
Definition: compute_pass.cc:35
compute_command.h
impeller::ComputePass::~ComputePass
virtual ~ComputePass()
impeller::ComputePass::OnEncodeCommands
virtual bool OnEncodeCommands(const Context &context, const ISize &grid_size, const ISize &thread_group_size) const =0
impeller
Definition: aiks_context.cc:10
impeller::ComputePass
Compute passes encode compute shader into the underlying command buffer.
Definition: compute_pass.h:23