| Flutter Impeller |

Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
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:

## Public Member Functions
virtual | ~RenderPass ()
const std::weak_ptr< const Context > & | GetContext () const
const RenderTarget & | GetRenderTarget () const
ISize | GetRenderTargetSize () const
const Matrix & | GetOrthographicTransform () const
virtual bool | IsValid () const =0
void | SetLabel (std::string label)
void | ReserveCommands (size_t command_count)
| Reserve [command_count] commands in the HAL command buffer. More...
HostBuffer & | GetTransientsBuffer ()
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...
SampleCount | GetSampleCount () const
| The sample count of the attached render target. More...
PixelFormat | GetRenderTargetPixelFormat () const
| The pixel format of the attached render target. More...
bool | HasStencilAttachment () const
| Whether the render target has an stencil attachment. More...

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

## Protected Attributes
const std::weak_ptr< const Context > | context_
const SampleCount | sample_count_
const PixelFormat | pixel_format_
const bool | has_stencil_attachment_
const ISize | render_target_size_
const RenderTarget | render_target_
std::shared_ptr< HostBuffer > | transients_buffer_
std::vector< Command > | commands_
const Matrix | orthographic_

## 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 29 of file render_pass.h.

## Constructor & Destructor Documentation

## ◆ ~RenderPass()

impeller::RenderPass::~RenderPass | ( |  | ) |
| virtual

Definition at line 24 of file render_pass.cc.

24 {
25 auto strong_context = context_.lock();
26 if (strong_context) {
27 strong_context->GetHostBufferPool().Recycle(transients_buffer_);
28 }
29 }

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 sample_count_(target.GetSampleCount()),
13 pixel_format_(target.GetRenderTargetPixelFormat()),
14 has_stencil_attachment_(target.GetStencilAttachment().has_value()),
15 render_target_size_(target.GetRenderTargetSize()),
16 render_target_(target),
17 transients_buffer_(),
18 orthographic_(Matrix::MakeOrthographic(render_target_size_)) {
19 auto strong_context = context_.lock();
20 FML_DCHECK(strong_context);
21 transients_buffer_ = strong_context->GetHostBufferPool().Grab();
22 }

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] | command | The command

Returns
  If the command was valid for subsequent commitment.

Definition at line 67 of file render_pass.cc.

67 {
68 if (!command.IsValid()) {
69 VALIDATION_LOG << "Attempted to add an invalid command to the render pass.";
70 return false;
71 }
72
73 if (command.scissor.has_value()) {
74 auto target_rect = IRect::MakeSize(render_target_.GetRenderTargetSize());
75 if (!target_rect.Contains(command.scissor.value())) {
76 VALIDATION_LOG << "Cannot apply a scissor that lies outside the bounds "
77 "of the render target.";
78 return false;
79 }
80 }
81
82 if (command.vertex_buffer.vertex_count == 0u ||
83 command.instance_count == 0u) {
84 // Essentially a no-op. Don't record the command but this is not necessary
85 // an error either.
86 return true;
87 }
88
89 commands_.emplace_back(std::move(command));
90 return true;
91 }

References commands_, impeller::RenderTarget::GetRenderTargetSize(), impeller::TRect< int64_t >::MakeSize(), render_target_, and VALIDATION_LOG.

Referenced by impeller::scene::EncodeCommand(), ImGui_ImplImpeller_RenderDrawData(), impeller::CheckerboardContents::Render(), impeller::RuntimeEffectContents::Render(), impeller::TiledTextureContents::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 93 of file render_pass.cc.

93 {
94 auto context = context_.lock();
95 // The context could have been collected in the meantime.
96 if (!context) {
97 return false;
98 }
99 return OnEncodeCommands(*context);
100 }

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 78 of file render_pass.h.

78 { return commands_; }

References commands_.

## ◆ GetContext()

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

Definition at line 102 of file render_pass.cc.

102 {
103 return context_;
104 }

References context_.

## ◆ GetOrthographicTransform()

const Matrix & impeller::RenderPass::GetOrthographicTransform | ( |  | ) | const

Definition at line 51 of file render_pass.cc.

51 {
52 return orthographic_;
53 }

References orthographic_.

Referenced by impeller::Geometry::ComputePositionGeometry(), impeller::Geometry::ComputePositionUVGeometry(), impeller::ComputeUVGeometryForRect(), impeller::VerticesGeometry::GetPositionBuffer(), impeller::VerticesGeometry::GetPositionColorBuffer(), impeller::VerticesGeometry::GetPositionUVBuffer(), impeller::ClipContents::Render(), impeller::SolidRRectBlurContents::Render(), impeller::TextContents::Render(), impeller::TextureContents::Render(), impeller::AtlasContents::Render(), impeller::ClipRestoreContents::Render(), impeller::AtlasTextureContents::Render(), impeller::AtlasColorContents::Render(), and impeller::testing::TEST_P().

## ◆ GetRenderTarget()

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

Definition at line 43 of file render_pass.cc.

43 {
44 return render_target_;
45 }

References render_target_.

Referenced by impeller::EncodeCommandsInReactor(), and impeller::scene::Material::GetContextOptions().

## ◆ GetRenderTargetPixelFormat()

PixelFormat impeller::RenderPass::GetRenderTargetPixelFormat | ( |  | ) | const

The pixel format of the attached render target.

Definition at line 35 of file render_pass.cc.

35 {
36 return pixel_format_;
37 }

References pixel_format_.

Referenced by impeller::OptionsFromPass().

## ◆ GetRenderTargetSize()

ISize impeller::RenderPass::GetRenderTargetSize | ( |  | ) | const

Definition at line 47 of file render_pass.cc.

47 {
48 return render_target_size_;
49 }

References render_target_size_.

Referenced by impeller::EncodeCommandsInReactor(), ImGui_ImplImpeller_RenderDrawData(), impeller::SceneContents::Render(), impeller::ClipContents::Render(), impeller::ClipRestoreContents::Render(), impeller::Entity::Render(), and impeller::testing::TEST_P().

## ◆ GetSampleCount()

SampleCount impeller::RenderPass::GetSampleCount | ( |  | ) | const

The sample count of the attached render target.

Definition at line 31 of file render_pass.cc.

31 {
32 return sample_count_;
33 }

References sample_count_.

Referenced by impeller::OptionsFromPass().

## ◆ GetTransientsBuffer()

HostBuffer & impeller::RenderPass::GetTransientsBuffer | ( |  | ) |

Definition at line 55 of file render_pass.cc.

55 {
56 return *transients_buffer_;
57 }

References transients_buffer_.

Referenced by impeller::Geometry::ComputePositionGeometry(), impeller::Geometry::ComputePositionUVGeometry(), impeller::ComputeUVGeometryForRect(), impeller::scene::EncodeCommand(), ImGui_ImplImpeller_RenderDrawData(), impeller::CheckerboardContents::Render(), impeller::RuntimeEffectContents::Render(), impeller::TiledTextureContents::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().

## ◆ HasStencilAttachment()

bool impeller::RenderPass::HasStencilAttachment | ( |  | ) | const

Whether the render target has an stencil attachment.

Definition at line 39 of file render_pass.cc.

39 {
40 return has_stencil_attachment_;
41 }

References has_stencil_attachment_.

Referenced by impeller::OptionsFromPass().

## ◆ IsValid()

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

## ◆ OnEncodeCommands()

virtual bool impeller::RenderPass::OnEncodeCommands | ( | const Context & | context | ) | const
| protected pure virtual

Referenced by EncodeCommands().

## ◆ OnSetLabel()

virtual void impeller::RenderPass::OnSetLabel | ( | std::string | label | ) |
| protected pure virtual

Referenced by SetLabel().

## ◆ ReserveCommands()

void impeller::RenderPass::ReserveCommands | ( | size_t | command_count | ) |
| inline

Reserve [command_count] commands in the HAL command buffer.

Note: this is not the native command buffer.

Definition at line 48 of file render_pass.h.

48 {
49 commands_.reserve(command_count);
50 }

References commands_.

## ◆ SetLabel()

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

Definition at line 59 of file render_pass.cc.

59 {
60 if (label.empty()) {
61 return;
62 }
63 transients_buffer_->SetLabel(SPrintF("%s Transients", label.c_str()));
64 OnSetLabel(std::move(label));
65 }

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

## Member Data Documentation

## ◆ commands_

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

Definition at line 105 of file render_pass.h.

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

## ◆ context_

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

Definition at line 93 of file render_pass.h.

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

## ◆ has_stencil_attachment_

const bool impeller::RenderPass::has_stencil_attachment_
| protected

Definition at line 101 of file render_pass.h.

Referenced by HasStencilAttachment().

## ◆ orthographic_

const Matrix impeller::RenderPass::orthographic_
| protected

Definition at line 106 of file render_pass.h.

Referenced by GetOrthographicTransform().

## ◆ pixel_format_

const PixelFormat impeller::RenderPass::pixel_format_
| protected

Definition at line 100 of file render_pass.h.

Referenced by GetRenderTargetPixelFormat().

## ◆ render_target_

const RenderTarget impeller::RenderPass::render_target_
| protected

Definition at line 103 of file render_pass.h.

Referenced by AddCommand(), and GetRenderTarget().

## ◆ render_target_size_

const ISize impeller::RenderPass::render_target_size_
| protected

Definition at line 102 of file render_pass.h.

Referenced by GetRenderTargetSize().

## ◆ sample_count_

const SampleCount impeller::RenderPass::sample_count_
| protected

Definition at line 99 of file render_pass.h.

Referenced by GetSampleCount().

## ◆ transients_buffer_

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

Definition at line 104 of file render_pass.h.

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

The documentation for this class was generated from the following files:

- impeller/renderer/render_pass.h
- impeller/renderer/render_pass.cc

impeller::RenderPass::pixel_format_
const PixelFormat pixel_format_
Definition: render_pass.h:100
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:103
impeller::RenderPass::commands_
std::vector< Command > commands_
Definition: render_pass.h:105
impeller::RenderPass::render_target_size_
const ISize render_target_size_
Definition: render_pass.h:102
impeller::RenderTarget::GetRenderTargetSize
ISize GetRenderTargetSize() const
Definition: render_target.cc:150
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:67
impeller::TRect< int64_t >::MakeSize
constexpr static TRect MakeSize(const TSize< U > &size)
Definition: rect.h:44
impeller::Matrix::MakeOrthographic
static constexpr Matrix MakeOrthographic(TSize< T > size)
Definition: matrix.h:459
impeller::RenderPass::OnSetLabel
virtual void OnSetLabel(std::string label)=0
impeller::RenderPass::has_stencil_attachment_
const bool has_stencil_attachment_
Definition: render_pass.h:101
impeller::RenderPass::orthographic_
const Matrix orthographic_
Definition: render_pass.h:106
impeller::RenderPass::context_
const std::weak_ptr< const Context > context_
Definition: render_pass.h:93
impeller::RenderPass::transients_buffer_
std::shared_ptr< HostBuffer > transients_buffer_
Definition: render_pass.h:104
impeller::RenderPass::sample_count_
const SampleCount sample_count_
Definition: render_pass.h:99