| Flutter Impeller |

Classes | Public Member Functions | List of all members
impeller::InlinePassContext Class Reference

`#include <inline_pass_context.h>`

## Classes
struct | RenderPassResult

## Public Member Functions
| InlinePassContext (std::shared_ptr< Context > context, EntityPassTarget &pass_target, uint32_t pass_texture_reads, std::optional< RenderPassResult > collapsed_parent_pass=std::nullopt)
| ~InlinePassContext ()
bool | IsValid () const
bool | IsActive () const
std::shared_ptr< Texture > | GetTexture ()
bool | EndPass ()
EntityPassTarget & | GetPassTarget () const
uint32_t | GetPassCount () const
RenderPassResult | GetRenderPass (uint32_t pass_depth)

## Detailed Description

Definition at line 14 of file inline_pass_context.h.

## Constructor & Destructor Documentation

## ◆ InlinePassContext()

impeller::InlinePassContext::InlinePassContext | ( | std::shared_ptr< Context > | context,
|  | EntityPassTarget & | pass_target,
|  | uint32_t | pass_texture_reads,
|  | std::optional< RenderPassResult > | collapsed_parent_pass = `std::nullopt`
| ) |  |

Definition at line 17 of file inline_pass_context.cc.

22 : context_(std::move(context)),
23 pass_target_(pass_target),
24 total_pass_reads_(pass_texture_reads),
25 is_collapsed_(collapsed_parent_pass.has_value()) {
26 if (collapsed_parent_pass.has_value()) {
27 pass_ = collapsed_parent_pass.value().pass;
28 }
29 }

## ◆ ~InlinePassContext()

impeller::InlinePassContext::~InlinePassContext | ( |  | ) |

Definition at line 31 of file inline_pass_context.cc.

31 {
32 if (!is_collapsed_) {
33 EndPass();
34 }
35 }

References EndPass().

## Member Function Documentation

## ◆ EndPass()

bool impeller::InlinePassContext::EndPass | ( |  | ) |

Definition at line 52 of file inline_pass_context.cc.

52 {
53 if (!IsActive()) {
54 return true;
55 }
56
57 if (command_buffer_) {
58 if (!command_buffer_->SubmitCommandsAsync(std::move(pass_))) {
59 VALIDATION_LOG
60 << "Failed to encode and submit command buffer while ending "
61 "render pass.";
62 return false;
63 }
64 }
65
66 pass_ = nullptr;
67 command_buffer_ = nullptr;
68
69 return true;
70 }

References IsActive(), and VALIDATION_LOG.

Referenced by ~InlinePassContext().

## ◆ GetPassCount()

uint32_t impeller::InlinePassContext::GetPassCount | ( |  | ) | const

Definition at line 179 of file inline_pass_context.cc.

179 {
180 return pass_count_;
181 }

## ◆ GetPassTarget()

EntityPassTarget & impeller::InlinePassContext::GetPassTarget | ( |  | ) | const

Definition at line 72 of file inline_pass_context.cc.

72 {
73 return pass_target_;
74 }

## ◆ GetRenderPass()

InlinePassContext::RenderPassResult impeller::InlinePassContext::GetRenderPass | ( | uint32_t | pass_depth | ) |

Create a new render pass if one isn't active. This path will run the first time this method is called, but it'll also run if the pass has been previously ended via `EndPass`.

Definition at line 76 of file inline_pass_context.cc.

77 {
78 if (IsActive()) {
79 return {.pass = pass_};
80 }
81
82 /// Create a new render pass if one isn't active. This path will run the first
83 /// time this method is called, but it'll also run if the pass has been
84 /// previously ended via `EndPass`.
85
86 command_buffer_ = context_->CreateCommandBuffer();
87 if (!command_buffer_) {
88 VALIDATION_LOG << "Could not create command buffer.";
89 return {};
90 }
91
92 if (pass_target_.GetRenderTarget().GetColorAttachments().empty()) {
93 VALIDATION_LOG << "Color attachment unexpectedly missing from the "
94 "EntityPass render target.";
95 return {};
96 }
97
98 command_buffer_->SetLabel(
99 "EntityPass Command Buffer: Depth=" + std::to_string(pass_depth) +
100 " Count=" + std::to_string(pass_count_));
101
102 RenderPassResult result;
103 {
104 // If the pass target has a resolve texture, then we're using MSAA.
105 bool is_msaa = pass_target_.GetRenderTarget()
106 .GetColorAttachments()
107 .find(0)
108 ->second.resolve_texture != nullptr;
109 if (pass_count_ > 0 && is_msaa) {
110 result.backdrop_texture =
111 pass_target_.Flip(*context_->GetResourceAllocator());
112 if (!result.backdrop_texture) {
113 VALIDATION_LOG << "Could not flip the EntityPass render target.";
114 }
115 }
116 }
117
118 // Find the color attachment a second time, since the target may have just
119 // flipped.
120 auto color0 =
121 pass_target_.GetRenderTarget().GetColorAttachments().find(0)->second;
122 bool is_msaa = color0.resolve_texture != nullptr;
123
124 if (pass_count_ > 0) {
125 // When MSAA is being used, we end up overriding the entire backdrop by
126 // drawing the previous pass texture, and so we don't have to clear it and
127 // can use kDontCare.
128 color0.load_action = is_msaa ? LoadAction::kDontCare : LoadAction::kLoad;
129 } else {
130 color0.load_action = LoadAction::kClear;
131 }
132
133 color0.store_action =
134 is_msaa ? StoreAction::kMultisampleResolve : StoreAction::kStore;
135
136 auto stencil = pass_target_.GetRenderTarget().GetStencilAttachment();
137 if (!stencil.has_value()) {
138 VALIDATION_LOG << "Stencil attachment unexpectedly missing from the "
139 "EntityPass render target.";
140 return {};
141 }
142
143 // Only clear the stencil if this is the very first pass of the
144 // layer.
145 stencil->load_action =
146 pass_count_ > 0 ? LoadAction::kLoad : LoadAction::kClear;
147 // If we're on the last pass of the layer, there's no need to store the
148 // stencil because nothing needs to read it.
149 stencil->store_action = pass_count_ == total_pass_reads_
150 ? StoreAction::kDontCare
151 : StoreAction::kStore;
152 pass_target_.target_.SetStencilAttachment(stencil.value());
153
154 pass_target_.target_.SetColorAttachment(color0, 0);
155
156 pass_ = command_buffer_->CreateRenderPass(pass_target_.GetRenderTarget());
157 if (!pass_) {
158 VALIDATION_LOG << "Could not create render pass.";
159 return {};
160 }
161
162 pass_->SetLabel(
163 "EntityPass Render Pass: Depth=" + std::to_string(pass_depth) +
164 " Count=" + std::to_string(pass_count_));
165
166 result.pass = pass_;
167
168 if (!context_->GetCapabilities()->SupportsReadFromResolve() &&
169 result.backdrop_texture ==
170 result.pass->GetRenderTarget().GetRenderTargetTexture()) {
171 VALIDATION_LOG << "EntityPass backdrop restore configuration is not valid "
172 "for the current graphics backend.";
173 }
174
175 ++pass_count_;
176 return result;
177 }

References impeller::InlinePassContext::RenderPassResult::backdrop_texture, impeller::EntityPassTarget::Flip(), impeller::RenderTarget::GetColorAttachments(), impeller::EntityPassTarget::GetRenderTarget(), impeller::RenderTarget::GetStencilAttachment(), IsActive(), impeller::kClear, impeller::kDontCare, impeller::kLoad, impeller::kMultisampleResolve, impeller::kStore, impeller::InlinePassContext::RenderPassResult::pass, impeller::RenderTarget::SetColorAttachment(), impeller::RenderTarget::SetStencilAttachment(), and VALIDATION_LOG.

## ◆ GetTexture()

std::shared_ptr< Texture > impeller::InlinePassContext::GetTexture | ( |  | ) |

Definition at line 45 of file inline_pass_context.cc.

45 {
46 if (!IsValid()) {
47 return nullptr;
48 }
49 return pass_target_.GetRenderTarget().GetRenderTargetTexture();
50 }

References impeller::EntityPassTarget::GetRenderTarget(), impeller::RenderTarget::GetRenderTargetTexture(), and IsValid().

## ◆ IsActive()

bool impeller::InlinePassContext::IsActive | ( |  | ) | const

Definition at line 41 of file inline_pass_context.cc.

41 {
42 return pass_ != nullptr;
43 }

Referenced by EndPass(), and GetRenderPass().

## ◆ IsValid()

bool impeller::InlinePassContext::IsValid | ( |  | ) | const

Definition at line 37 of file inline_pass_context.cc.

37 {
38 return pass_target_.IsValid();
39 }

References impeller::EntityPassTarget::IsValid().

Referenced by GetTexture().

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

- impeller/entity/inline_pass_context.h
- impeller/entity/inline_pass_context.cc

impeller::StoreAction::kMultisampleResolve
@ kMultisampleResolve
impeller::LoadAction::kLoad
@ kLoad
impeller::EntityPassTarget::IsValid
bool IsValid() const
Definition: entity_pass_target.cc:61
impeller::RenderTarget::SetColorAttachment
RenderTarget & SetColorAttachment(const ColorAttachment &attachment, size_t index)
Definition: render_target.cc:180
impeller::StoreAction::kDontCare
@ kDontCare
impeller::RenderTarget::GetColorAttachments
const std::map< size_t, ColorAttachment > & GetColorAttachments() const
Definition: render_target.cc:209
impeller::LoadAction::kClear
@ kClear
impeller::RenderTarget::GetRenderTargetTexture
std::shared_ptr< Texture > GetRenderTargetTexture() const
Definition: render_target.cc:155
impeller::InlinePassContext::IsActive
bool IsActive() const
Definition: inline_pass_context.cc:41
impeller::StoreAction::kStore
@ kStore
impeller::InlinePassContext::EndPass
bool EndPass()
Definition: inline_pass_context.cc:52
impeller::InlinePassContext::IsValid
bool IsValid() const
Definition: inline_pass_context.cc:37
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:60
impeller::RenderTarget::SetStencilAttachment
RenderTarget & SetStencilAttachment(std::optional< StencilAttachment > attachment)
Definition: render_target.cc:199
impeller::LoadAction::kDontCare
@ kDontCare
impeller::RenderTarget::GetStencilAttachment
const std::optional< StencilAttachment > & GetStencilAttachment() const
Definition: render_target.cc:218
impeller::EntityPassTarget::GetRenderTarget
const RenderTarget & GetRenderTarget() const
Definition: entity_pass_target.cc:57
impeller::EntityPassTarget::Flip
std::shared_ptr< Texture > Flip(Allocator &allocator)
Flips the backdrop and returns a readable texture that can be bound/sampled to restore the previous p...
Definition: entity_pass_target.cc:18