| 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::shared_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)
virtual void | ReserveCommands (size_t command_count)
| Reserve [command_count] commands in the HAL command buffer. More...
virtual void | SetPipeline (const std::shared_ptr< Pipeline< PipelineDescriptor >> &pipeline)
| The pipeline to use for this command. More...
virtual void | SetCommandLabel (std::string_view label)
| The debugging label to use for the command. More...
virtual void | SetStencilReference (uint32_t value)
virtual void | SetBaseVertex (uint64_t value)
virtual void | SetViewport (Viewport viewport)
virtual void | SetScissor (IRect scissor)
virtual void | SetInstanceCount (size_t count)
virtual bool | SetVertexBuffer (VertexBuffer buffer)
| Specify the vertex and index buffer to use for this command. More...
virtual fml::Status | Draw ()
| Record the currently pending command. More...
virtual bool | BindResource (ShaderStage stage, DescriptorType type, const ShaderUniformSlot &slot, const ShaderMetadata &metadata, BufferView view) override
virtual bool | BindResource (ShaderStage stage, DescriptorType type, const ShaderUniformSlot &slot, const std::shared_ptr< const ShaderMetadata > &metadata, BufferView view)
virtual bool | BindResource (ShaderStage stage, DescriptorType type, const SampledImageSlot &slot, const ShaderMetadata &metadata, std::shared_ptr< const Texture > texture, const std::unique_ptr< const Sampler > &sampler) override
bool | EncodeCommands () const
| Encode the recorded commands to the underlying command buffer. More...
virtual 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 | HasDepthAttachment () const
| Whether the render target has a depth attachment. More...
bool | HasStencilAttachment () const
| Whether the render target has an stencil attachment. More...
Public Member Functions inherited from impeller::ResourceBinder
virtual | ~ResourceBinder ()=default

## Protected Member Functions
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...
| RenderPass (std::shared_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::shared_ptr< const Context > | context_
const SampleCount | sample_count_
const PixelFormat | pixel_format_
const bool | has_depth_attachment_
const bool | has_stencil_attachment_
const ISize | render_target_size_
const RenderTarget | render_target_
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 33 of file render_pass.h.

## Constructor & Destructor Documentation

## ◆ ~RenderPass()

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

Definition at line 21 of file render_pass.cc.

21 {}

## ◆ RenderPass()

impeller::RenderPass::RenderPass | ( | std::shared_ptr< const Context > | context,
|  | const RenderTarget & | target
| ) |  |
| protected

Definition at line 10 of file render_pass.cc.

12 : context_(std::move(context)),
13 sample_count_(target.GetSampleCount()),
14 pixel_format_(target.GetRenderTargetPixelFormat()),
15 has_depth_attachment_(target.GetDepthAttachment().has_value()),
16 has_stencil_attachment_(target.GetStencilAttachment().has_value()),
17 render_target_size_(target.GetRenderTargetSize()),
18 render_target_(target),
19 orthographic_(Matrix::MakeOrthographic(render_target_size_)) {}

## Member Function Documentation

## ◆ AddCommand()

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

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 58 of file render_pass.cc.

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

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

Referenced by Draw().

## ◆ BindResource() [1/3]

bool impeller::RenderPass::BindResource | ( | ShaderStage | stage,
|  | DescriptorType | type,
|  | const SampledImageSlot & | slot,
|  | const ShaderMetadata & | metadata,
|  | std::shared_ptr< const Texture > | texture,
|  | const std::unique_ptr< const Sampler > & | sampler
| ) |  |
| override virtual

Implements impeller::ResourceBinder.

Definition at line 156 of file render_pass.cc.

161 {
162 return pending_.BindResource(stage, type, slot, metadata, std::move(texture),
163 sampler);
164 }

References impeller::Command::BindResource(), and type.

## ◆ BindResource() [2/3]

bool impeller::RenderPass::BindResource | ( | ShaderStage | stage,
|  | DescriptorType | type,
|  | const ShaderUniformSlot & | slot,
|  | const ShaderMetadata & | metadata,
|  | BufferView | view
| ) |  |
| override virtual

Implements impeller::ResourceBinder.

Definition at line 138 of file render_pass.cc.

142 {
143 return pending_.BindResource(stage, type, slot, metadata, view);
144 }

References impeller::Command::BindResource(), and type.

Referenced by impeller::RuntimeEffectContents::Render().

## ◆ BindResource() [3/3]

bool impeller::RenderPass::BindResource | ( | ShaderStage | stage,
|  | DescriptorType | type,
|  | const ShaderUniformSlot & | slot,
|  | const std::shared_ptr< const ShaderMetadata > & | metadata,
|  | BufferView | view
| ) |  |
| virtual

Definition at line 146 of file render_pass.cc.

151 {
152 return pending_.BindResource(stage, type, slot, metadata, std::move(view));
153 }

References impeller::Command::BindResource(), and type.

## ◆ Draw()

fml::Status impeller::RenderPass::Draw | ( |  | ) |
| virtual

Record the currently pending command.

Definition at line 127 of file render_pass.cc.

127 {
128 auto result = AddCommand(std::move(pending_));
129 pending_ = Command{};
130 if (result) {
131 return fml::Status();
132 }
133 return fml::Status(fml::StatusCode::kInvalidArgument,
134 "Failed to encode command");
135 }

References AddCommand().

Referenced by impeller::ColorSourceContents::DrawGeometry(), impeller::scene::EncodeCommand(), ImGui_ImplImpeller_RenderDrawData(), impeller::ClipContents::Render(), impeller::SolidRRectBlurContents::Render(), impeller::VerticesSimpleBlendContents::Render(), impeller::AtlasContents::Render(), impeller::TextureContents::Render(), impeller::TextContents::Render(), impeller::ClipRestoreContents::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 84 of file render_pass.cc.

84 {
85 return OnEncodeCommands(*context_);
86 }

References context_, and OnEncodeCommands().

## ◆ GetCommands()

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

Accessor for the current Commands.

Visible for testing.

Definition at line 149 of file render_pass.h.

149 { return commands_; }

References commands_.

## ◆ GetContext()

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

Definition at line 88 of file render_pass.cc.

88 {
89 return context_;
90 }

References context_.

Referenced by ImGui_ImplImpeller_RenderDrawData().

## ◆ GetOrthographicTransform()

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

Definition at line 47 of file render_pass.cc.

47 {
48 return orthographic_;
49 }

References orthographic_.

Referenced by impeller::Entity::GetShaderTransform(), impeller::ClipContents::Render(), impeller::ClipRestoreContents::Render(), and impeller::testing::TEST_P().

## ◆ GetRenderTarget()

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

Definition at line 39 of file render_pass.cc.

39 {
40 return render_target_;
41 }

References render_target_.

Referenced by impeller::scene::Material::GetContextOptions().

## ◆ GetRenderTargetPixelFormat()

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

The pixel format of the attached render target.

Definition at line 27 of file render_pass.cc.

27 {
28 return pixel_format_;
29 }

References pixel_format_.

Referenced by impeller::OptionsFromPass().

## ◆ GetRenderTargetSize()

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

Definition at line 43 of file render_pass.cc.

43 {
44 return render_target_size_;
45 }

References render_target_size_.

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

## ◆ GetSampleCount()

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

The sample count of the attached render target.

Definition at line 23 of file render_pass.cc.

23 {
24 return sample_count_;
25 }

References sample_count_.

Referenced by impeller::OptionsFromPass().

## ◆ HasDepthAttachment()

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

Whether the render target has a depth attachment.

Definition at line 31 of file render_pass.cc.

31 {
32 return has_depth_attachment_;
33 }

References has_depth_attachment_.

Referenced by impeller::OptionsFromPass().

## ◆ HasStencilAttachment()

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

Whether the render target has an stencil attachment.

Definition at line 35 of file render_pass.cc.

35 {
36 return has_stencil_attachment_;
37 }

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()

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

Reserve [command_count] commands in the HAL command buffer.

Note: this is not the native command buffer.

Definition at line 52 of file render_pass.h.

52 {
53 commands_.reserve(command_count);
54 }

References commands_.

## ◆ SetBaseVertex()

void impeller::RenderPass::SetBaseVertex | ( | uint64_t | value | ) |
| virtual

Definition at line 107 of file render_pass.cc.

107 {
108 pending_.base_vertex = value;
109 }

References impeller::Command::base_vertex.

Referenced by ImGui_ImplImpeller_RenderDrawData().

## ◆ SetCommandLabel()

void impeller::RenderPass::SetCommandLabel | ( | std::string_view | label | ) |
| virtual

The debugging label to use for the command.

Definition at line 97 of file render_pass.cc.

97 {
98 #ifdef IMPELLER_DEBUG
99 pending_.label = std::string(label);
100 #endif // IMPELLER_DEBUG
101 }

Referenced by impeller::ColorSourceContents::DrawGeometry(), impeller::scene::EncodeCommand(), ImGui_ImplImpeller_RenderDrawData(), impeller::TiledTextureContents::Render(), impeller::SolidColorContents::Render(), impeller::ClipContents::Render(), impeller::SolidRRectBlurContents::Render(), impeller::VerticesSimpleBlendContents::Render(), impeller::AtlasContents::Render(), impeller::TextContents::Render(), impeller::TextureContents::Render(), impeller::ClipRestoreContents::Render(), and impeller::testing::TEST_P().

## ◆ SetInstanceCount()

void impeller::RenderPass::SetInstanceCount | ( | size_t | count | ) |
| virtual

The number of instances of the given set of vertices to render. Not all backends support rendering more than one instance at a time.

Warning
  Setting this to more than one will limit the availability of backends to use with this command.

Definition at line 119 of file render_pass.cc.

119 {
120 pending_.instance_count = count;
121 }

References impeller::Command::instance_count.

Referenced by impeller::testing::TEST_P().

## ◆ SetLabel()

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

Definition at line 51 of file render_pass.cc.

51 {
52 if (label.empty()) {
53 return;
54 }
55 OnSetLabel(std::move(label));
56 }

References OnSetLabel().

## ◆ SetPipeline()

void impeller::RenderPass::SetPipeline | ( | const std::shared_ptr< Pipeline< PipelineDescriptor >> & | pipeline | ) |
| virtual

The pipeline to use for this command.

Definition at line 92 of file render_pass.cc.

93 {
94 pending_.pipeline = pipeline;
95 }

References impeller::Command::pipeline.

Referenced by impeller::ColorSourceContents::DrawGeometry(), impeller::scene::EncodeCommand(), ImGui_ImplImpeller_RenderDrawData(), impeller::ClipContents::Render(), impeller::SolidRRectBlurContents::Render(), impeller::VerticesSimpleBlendContents::Render(), impeller::AtlasContents::Render(), impeller::TextureContents::Render(), impeller::TextContents::Render(), impeller::ClipRestoreContents::Render(), and impeller::testing::TEST_P().

## ◆ SetScissor()

void impeller::RenderPass::SetScissor | ( | IRect | scissor | ) |
| virtual

The scissor rect to use for clipping writes to the render target. The scissor rect must lie entirely within the render target. If unset, no scissor is applied.

Definition at line 115 of file render_pass.cc.

115 {
116 pending_.scissor = scissor;
117 }

References impeller::Command::scissor.

Referenced by ImGui_ImplImpeller_RenderDrawData(), and impeller::SetClipScissor().

## ◆ SetStencilReference()

void impeller::RenderPass::SetStencilReference | ( | uint32_t | value | ) |
| virtual

The reference value to use in stenciling operations. Stencil configuration is part of pipeline setup and can be read from the pipelines descriptor.

See also
  `Pipeline`
  `PipelineDescriptor`

Definition at line 103 of file render_pass.cc.

103 {
104 pending_.stencil_reference = value;
105 }

References impeller::Command::stencil_reference.

Referenced by impeller::ColorSourceContents::DrawGeometry(), impeller::scene::EncodeCommand(), impeller::ClipContents::Render(), and impeller::ClipRestoreContents::Render().

## ◆ SetVertexBuffer()

bool impeller::RenderPass::SetVertexBuffer | ( | VertexBuffer | buffer | ) |
| virtual

Specify the vertex and index buffer to use for this command.

Parameters

  [in] | buffer | The vertex and index buffer definition. If possible, this value should be moved and not copied.

Returns
  returns if the binding was updated.

Definition at line 123 of file render_pass.cc.

123 {
124 return pending_.BindVertices(std::move(buffer));
125 }

References impeller::Command::BindVertices().

Referenced by impeller::scene::CuboidGeometry::BindToCommand(), impeller::scene::UnskinnedVertexBufferGeometry::BindToCommand(), impeller::scene::SkinnedVertexBufferGeometry::BindToCommand(), impeller::ColorSourceContents::DrawGeometry(), ImGui_ImplImpeller_RenderDrawData(), impeller::ClipContents::Render(), impeller::SolidRRectBlurContents::Render(), impeller::VerticesSimpleBlendContents::Render(), impeller::AtlasContents::Render(), impeller::TextureContents::Render(), impeller::TextContents::Render(), impeller::ClipRestoreContents::Render(), and impeller::testing::TEST_P().

## ◆ SetViewport()

void impeller::RenderPass::SetViewport | ( | Viewport | viewport | ) |
| virtual

The viewport coordinates that the rasterizer linearly maps normalized device coordinates to. If unset, the viewport is the size of the render target with a zero origin, znear=0, and zfar=1.

Definition at line 111 of file render_pass.cc.

111 {
112 pending_.viewport = viewport;
113 }

References impeller::Command::viewport.

Referenced by ImGui_ImplImpeller_RenderDrawData().

## Member Data Documentation

## ◆ commands_

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

Definition at line 180 of file render_pass.h.

Referenced by AddCommand(), GetCommands(), and ReserveCommands().

## ◆ context_

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

Definition at line 168 of file render_pass.h.

Referenced by EncodeCommands(), and GetContext().

## ◆ has_depth_attachment_

const bool impeller::RenderPass::has_depth_attachment_
| protected

Definition at line 176 of file render_pass.h.

Referenced by HasDepthAttachment().

## ◆ has_stencil_attachment_

const bool impeller::RenderPass::has_stencil_attachment_
| protected

Definition at line 177 of file render_pass.h.

Referenced by HasStencilAttachment().

## ◆ orthographic_

const Matrix impeller::RenderPass::orthographic_
| protected

Definition at line 181 of file render_pass.h.

Referenced by GetOrthographicTransform().

## ◆ pixel_format_

const PixelFormat impeller::RenderPass::pixel_format_
| protected

Definition at line 175 of file render_pass.h.

Referenced by GetRenderTargetPixelFormat().

## ◆ render_target_

const RenderTarget impeller::RenderPass::render_target_
| protected

Definition at line 179 of file render_pass.h.

Referenced by AddCommand(), and GetRenderTarget().

## ◆ render_target_size_

const ISize impeller::RenderPass::render_target_size_
| protected

Definition at line 178 of file render_pass.h.

Referenced by GetRenderTargetSize().

## ◆ sample_count_

const SampleCount impeller::RenderPass::sample_count_
| protected

Definition at line 174 of file render_pass.h.

Referenced by GetSampleCount().

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

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

impeller::Command::scissor
std::optional< IRect > scissor
Definition: command.h:139
impeller::Command::viewport
std::optional< Viewport > viewport
Definition: command.h:133
impeller::RenderPass::has_depth_attachment_
const bool has_depth_attachment_
Definition: render_pass.h:176
impeller::Command::instance_count
size_t instance_count
Definition: command.h:147
impeller::Command::base_vertex
uint64_t base_vertex
Definition: command.h:126
impeller::RenderPass::pixel_format_
const PixelFormat pixel_format_
Definition: render_pass.h:175
impeller::RenderPass::OnEncodeCommands
virtual bool OnEncodeCommands(const Context &context) const =0
impeller::Command::BindVertices
bool BindVertices(VertexBuffer buffer)
Specify the vertex and index buffer to use for this command.
Definition: command.cc:15
type
GLenum type
Definition: blit_command_gles.cc:126
impeller::RenderPass::render_target_
const RenderTarget render_target_
Definition: render_pass.h:179
impeller::RenderPass::commands_
std::vector< Command > commands_
Definition: render_pass.h:180
impeller::RenderPass::render_target_size_
const ISize render_target_size_
Definition: render_pass.h:178
impeller::RenderTarget::GetRenderTargetSize
ISize GetRenderTargetSize() const
Definition: render_target.cc:139
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:73
impeller::Command::BindResource
bool BindResource(ShaderStage stage, DescriptorType type, const ShaderUniformSlot &slot, const ShaderMetadata &metadata, BufferView view) override
Definition: command.cc:25
impeller::Command::stencil_reference
uint32_t stencil_reference
Definition: command.h:122
impeller::TRect::MakeSize
constexpr static TRect MakeSize(const TSize< U > &size)
Definition: rect.h:146
impeller::Matrix::MakeOrthographic
static constexpr Matrix MakeOrthographic(TSize< T > size)
Definition: matrix.h:497
impeller::RenderPass::OnSetLabel
virtual void OnSetLabel(std::string label)=0
impeller::RenderPass::context_
const std::shared_ptr< const Context > context_
Definition: render_pass.h:168
impeller::Command::pipeline
std::shared_ptr< Pipeline< PipelineDescriptor > > pipeline
Definition: command.h:96
impeller::RenderPass::has_stencil_attachment_
const bool has_stencil_attachment_
Definition: render_pass.h:177
impeller::RenderPass::orthographic_
const Matrix orthographic_
Definition: render_pass.h:181
impeller::RenderPass::AddCommand
bool AddCommand(Command &&command)
Record a command for subsequent encoding to the underlying command buffer. No work is encoded into th...
Definition: render_pass.cc:58
impeller::RenderPass::sample_count_
const SampleCount sample_count_
Definition: render_pass.h:174