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 #pragma once
6 
7 #include <string>
8 #include <variant>
9 
11 #include "impeller/core/texture.h"
13 
14 namespace impeller {
15 
16 class HostBuffer;
17 class Allocator;
18 
19 //------------------------------------------------------------------------------
20 /// @brief Compute passes encode compute shader into the underlying command
21 /// buffer.
22 ///
23 /// @see `CommandBuffer`
24 ///
25 class ComputePass {
26  public:
27  virtual ~ComputePass();
28 
29  virtual bool IsValid() const = 0;
30 
31  void SetLabel(const std::string& label);
32 
33  void SetGridSize(const ISize& size);
34 
35  void SetThreadGroupSize(const ISize& size);
36 
38 
39  //----------------------------------------------------------------------------
40  /// @brief Record a command for subsequent encoding to the underlying
41  /// command buffer. No work is encoded into the command buffer at
42  /// this time.
43  ///
44  /// @param[in] command The command
45  ///
46  /// @return If the command was valid for subsequent commitment.
47  ///
48  bool AddCommand(ComputeCommand command);
49 
50  //----------------------------------------------------------------------------
51  /// @brief Encode the recorded commands to the underlying command buffer.
52  ///
53  /// @param transients_allocator The transients allocator.
54  ///
55  /// @return If the commands were encoded to the underlying command
56  /// buffer.
57  ///
58  bool EncodeCommands() const;
59 
60  protected:
61  const std::weak_ptr<const Context> context_;
62  std::vector<ComputeCommand> commands_;
63 
64  explicit ComputePass(std::weak_ptr<const Context> context);
65 
66  virtual void OnSetLabel(const std::string& label) = 0;
67 
68  virtual bool OnEncodeCommands(const Context& context,
69  const ISize& grid_size,
70  const ISize& thread_group_size) const = 0;
71 
72  private:
73  std::shared_ptr<HostBuffer> transients_buffer_;
74  ISize grid_size_ = ISize(32, 32);
75  ISize thread_group_size_ = ISize(32, 32);
76 
77  FML_DISALLOW_COPY_AND_ASSIGN(ComputePass);
78 };
79 
80 } // namespace impeller
impeller::ComputePass::SetGridSize
void SetGridSize(const ISize &size)
Definition: compute_pass.cc:31
device_buffer.h
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:62
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:61
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:136
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:43
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
texture.h
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:25