Flutter Impeller
compute_pass.cc
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 
6 #include <memory>
7 
11 
12 namespace impeller {
13 
14 ComputePass::ComputePass(std::weak_ptr<const Context> context)
15  : context_(std::move(context)), transients_buffer_(HostBuffer::Create()) {}
16 
17 ComputePass::~ComputePass() = default;
18 
20  return *transients_buffer_;
21 }
22 
23 void ComputePass::SetLabel(const std::string& label) {
24  if (label.empty()) {
25  return;
26  }
27  transients_buffer_->SetLabel(SPrintF("%s Transients", label.c_str()));
28  OnSetLabel(label);
29 }
30 
31 void ComputePass::SetGridSize(const ISize& size) {
32  grid_size_ = size;
33 }
34 
36  thread_group_size_ = size;
37 }
38 
40  if (!command) {
42  << "Attempted to add an invalid command to the compute pass.";
43  return false;
44  }
45 
46  commands_.emplace_back(std::move(command));
47  return true;
48 }
49 
51  if (grid_size_.IsEmpty() || thread_group_size_.IsEmpty()) {
52  FML_DLOG(WARNING) << "Attempted to encode a compute pass with an empty "
53  "grid or thread group size.";
54  return false;
55  }
56  auto context = context_.lock();
57  // The context could have been collected in the meantime.
58  if (!context) {
59  return false;
60  }
61  return OnEncodeCommands(*context, grid_size_, thread_group_size_);
62 }
63 
64 } // namespace impeller
host_buffer.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::commands_
std::vector< ComputeCommand > commands_
Definition: compute_pass.h:62
impeller::ComputePass::GetTransientsBuffer
HostBuffer & GetTransientsBuffer()
Definition: compute_pass.cc:19
validation.h
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::SPrintF
std::string SPrintF(const char *format,...)
Definition: strings.cc:12
impeller::ComputePass::context_
const std::weak_ptr< const Context > context_
Definition: compute_pass.h:61
strings.h
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
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:60
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
std
Definition: comparable.h:98
impeller::ComputePass::SetThreadGroupSize
void SetThreadGroupSize(const ISize &size)
Definition: compute_pass.cc:35
impeller::ComputePass::~ComputePass
virtual ~ComputePass()
impeller::TSize::IsEmpty
constexpr bool IsEmpty() const
Definition: size.h:105
impeller::ComputePass::OnEncodeCommands
virtual bool OnEncodeCommands(const Context &context, const ISize &grid_size, const ISize &thread_group_size) const =0
compute_pass.h
impeller
Definition: aiks_context.cc:10