Flutter Impeller
impeller::RenderPass Class Referenceabstract

Render passes encode render commands directed as one specific render target into an underlying command buffer. More...

#include <render_pass.h>

Inheritance diagram for impeller::RenderPass:
impeller::RenderPassGLES impeller::RenderPassMTL impeller::RenderPassVK

Public Member Functions

virtual ~RenderPass ()
 
const RenderTargetGetRenderTarget () const
 
ISize GetRenderTargetSize () const
 
virtual bool IsValid () const =0
 
void SetLabel (std::string label)
 
HostBufferGetTransientsBuffer ()
 
bool AddCommand (Command &&command)
 Record a command for subsequent encoding to the underlying command buffer. No work is encoded into the command buffer at this time. More...
 
bool EncodeCommands () const
 Encode the recorded commands to the underlying command buffer. More...
 
const std::vector< Command > & GetCommands () const
 Accessor for the current Commands. More...
 

Protected Member Functions

 RenderPass (std::weak_ptr< const Context > context, const RenderTarget &target)
 
const std::weak_ptr< const Context > & GetContext () const
 
virtual void OnSetLabel (std::string label)=0
 
virtual bool OnEncodeCommands (const Context &context) const =0
 

Protected Attributes

const std::weak_ptr< const Contextcontext_
 
const RenderTarget render_target_
 
std::shared_ptr< HostBuffertransients_buffer_
 
std::vector< Commandcommands_
 

Detailed Description

Render passes encode render commands directed as one specific render target into an underlying command buffer.

Render passes can be obtained from the command buffer in which the pass is meant to encode commands into.

See also
CommandBuffer

Definition at line 27 of file render_pass.h.

Constructor & Destructor Documentation

◆ ~RenderPass()

impeller::RenderPass::~RenderPass ( )
virtual

Definition at line 19 of file render_pass.cc.

19  {
20  auto strong_context = context_.lock();
21  if (strong_context) {
22  strong_context->GetHostBufferPool().Recycle(transients_buffer_);
23  }
24 }

References context_, and transients_buffer_.

◆ RenderPass()

impeller::RenderPass::RenderPass ( std::weak_ptr< const Context context,
const RenderTarget target 
)
protected

Definition at line 9 of file render_pass.cc.

11  : context_(std::move(context)),
12  render_target_(target),
14  auto strong_context = context_.lock();
15  FML_DCHECK(strong_context);
16  transients_buffer_ = strong_context->GetHostBufferPool().Grab();
17 }

References context_, and transients_buffer_.

Member Function Documentation

◆ AddCommand()

bool impeller::RenderPass::AddCommand ( Command &&  command)

Record a command for subsequent encoding to the underlying command buffer. No work is encoded into the command buffer at this time.

Parameters
[in]commandThe command
Returns
If the command was valid for subsequent commitment.

Definition at line 46 of file render_pass.cc.

46  {
47  if (!command) {
48  VALIDATION_LOG << "Attempted to add an invalid command to the render pass.";
49  return false;
50  }
51 
52  if (command.scissor.has_value()) {
53  auto target_rect = IRect({}, render_target_.GetRenderTargetSize());
54  if (!target_rect.Contains(command.scissor.value())) {
55  VALIDATION_LOG << "Cannot apply a scissor that lies outside the bounds "
56  "of the render target.";
57  return false;
58  }
59  }
60 
61  if (command.vertex_count == 0u) {
62  // Essentially a no-op. Don't record the command but this is not necessary
63  // an error either.
64  return true;
65  }
66 
67  if (command.instance_count == 0u) {
68  // Essentially a no-op. Don't record the command but this is not necessary
69  // an error either.
70  return true;
71  }
72 
73  commands_.emplace_back(std::move(command));
74  return true;
75 }

References commands_, impeller::RenderTarget::GetRenderTargetSize(), render_target_, and VALIDATION_LOG.

Referenced by impeller::scene::EncodeCommand(), ImGui_ImplImpeller_RenderDrawData(), impeller::CheckerboardContents::Render(), impeller::TiledTextureContents::Render(), impeller::RuntimeEffectContents::Render(), impeller::ClipContents::Render(), impeller::SolidRRectBlurContents::Render(), impeller::SolidColorContents::Render(), impeller::TextContents::Render(), impeller::TextureContents::Render(), impeller::VerticesColorContents::Render(), impeller::AtlasContents::Render(), impeller::ClipRestoreContents::Render(), impeller::VerticesUVContents::Render(), impeller::AtlasTextureContents::Render(), impeller::AtlasColorContents::Render(), and impeller::testing::TEST_P().

◆ EncodeCommands()

bool impeller::RenderPass::EncodeCommands ( ) const

Encode the recorded commands to the underlying command buffer.

Returns
If the commands were encoded to the underlying command buffer.

Definition at line 77 of file render_pass.cc.

77  {
78  auto context = context_.lock();
79  // The context could have been collected in the meantime.
80  if (!context) {
81  return false;
82  }
83  return OnEncodeCommands(*context);
84 }

References context_, and OnEncodeCommands().

◆ GetCommands()

const std::vector<Command>& impeller::RenderPass::GetCommands ( ) const
inline

Accessor for the current Commands.

Visible for testing.

Definition at line 65 of file render_pass.h.

65 { return commands_; }

References commands_.

◆ GetContext()

const std::weak_ptr< const Context > & impeller::RenderPass::GetContext ( ) const
protected

Definition at line 86 of file render_pass.cc.

86  {
87  return context_;
88 }

References context_.

◆ GetRenderTarget()

const RenderTarget & impeller::RenderPass::GetRenderTarget ( ) const

◆ GetRenderTargetSize()

◆ GetTransientsBuffer()

◆ IsValid()

virtual bool impeller::RenderPass::IsValid ( ) const
pure virtual

◆ OnEncodeCommands()

virtual bool impeller::RenderPass::OnEncodeCommands ( const Context context) const
protectedpure virtual

Referenced by EncodeCommands().

◆ OnSetLabel()

virtual void impeller::RenderPass::OnSetLabel ( std::string  label)
protectedpure virtual

Referenced by SetLabel().

◆ SetLabel()

void impeller::RenderPass::SetLabel ( std::string  label)

Definition at line 38 of file render_pass.cc.

38  {
39  if (label.empty()) {
40  return;
41  }
42  transients_buffer_->SetLabel(SPrintF("%s Transients", label.c_str()));
43  OnSetLabel(std::move(label));
44 }

References OnSetLabel(), impeller::SPrintF(), and transients_buffer_.

Member Data Documentation

◆ commands_

std::vector<Command> impeller::RenderPass::commands_
protected

Definition at line 71 of file render_pass.h.

Referenced by AddCommand(), impeller::EncodeCommandsInReactor(), and GetCommands().

◆ context_

const std::weak_ptr<const Context> impeller::RenderPass::context_
protected

Definition at line 68 of file render_pass.h.

Referenced by EncodeCommands(), GetContext(), RenderPass(), and ~RenderPass().

◆ render_target_

const RenderTarget impeller::RenderPass::render_target_
protected

Definition at line 69 of file render_pass.h.

Referenced by AddCommand(), GetRenderTarget(), and GetRenderTargetSize().

◆ transients_buffer_

std::shared_ptr<HostBuffer> impeller::RenderPass::transients_buffer_
protected

Definition at line 70 of file render_pass.h.

Referenced by GetTransientsBuffer(), RenderPass(), SetLabel(), and ~RenderPass().


The documentation for this class was generated from the following files:
impeller::SPrintF
std::string SPrintF(const char *format,...)
Definition: strings.cc:12
impeller::RenderPass::OnEncodeCommands
virtual bool OnEncodeCommands(const Context &context) const =0
impeller::RenderPass::render_target_
const RenderTarget render_target_
Definition: render_pass.h:69
impeller::IRect
TRect< int64_t > IRect
Definition: rect.h:307
impeller::RenderPass::commands_
std::vector< Command > commands_
Definition: render_pass.h:71
impeller::RenderTarget::GetRenderTargetSize
ISize GetRenderTargetSize() const
Definition: render_target.cc:150
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:60
impeller::RenderPass::OnSetLabel
virtual void OnSetLabel(std::string label)=0
impeller::RenderPass::context_
const std::weak_ptr< const Context > context_
Definition: render_pass.h:68
impeller::RenderPass::transients_buffer_
std::shared_ptr< HostBuffer > transients_buffer_
Definition: render_pass.h:70