Flutter Impeller
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, uint32_t entity_count, std::optional< RenderPassResult > collapsed_parent_pass=std::nullopt)
 
 ~InlinePassContext ()
 
bool IsValid () const
 
bool IsActive () const
 
std::shared_ptr< TextureGetTexture ()
 
bool EndPass ()
 
EntityPassTargetGetPassTarget () const
 
uint32_t GetPassCount () const
 
RenderPassResult GetRenderPass (uint32_t pass_depth)
 

Detailed Description

Definition at line 17 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,
uint32_t  entity_count,
std::optional< RenderPassResult collapsed_parent_pass = std::nullopt 
)

Definition at line 17 of file inline_pass_context.cc.

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

◆ ~InlinePassContext()

impeller::InlinePassContext::~InlinePassContext ( )

Definition at line 33 of file inline_pass_context.cc.

33  {
34  if (!is_collapsed_) {
35  EndPass();
36  }
37 }

References EndPass().

Member Function Documentation

◆ EndPass()

bool impeller::InlinePassContext::EndPass ( )

Definition at line 54 of file inline_pass_context.cc.

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

References IsActive(), and VALIDATION_LOG.

Referenced by ~InlinePassContext().

◆ GetPassCount()

uint32_t impeller::InlinePassContext::GetPassCount ( ) const

Definition at line 184 of file inline_pass_context.cc.

184  {
185  return pass_count_;
186 }

◆ GetPassTarget()

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

Definition at line 74 of file inline_pass_context.cc.

74  {
75  return pass_target_;
76 }

◆ 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 78 of file inline_pass_context.cc.

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

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::Allocation::NextPowerOfTwoSize(), impeller::InlinePassContext::RenderPassResult::pass, impeller::RenderTarget::SetColorAttachment(), impeller::RenderTarget::SetStencilAttachment(), and VALIDATION_LOG.

◆ GetTexture()

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

Definition at line 47 of file inline_pass_context.cc.

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

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

◆ IsActive()

bool impeller::InlinePassContext::IsActive ( ) const

Definition at line 43 of file inline_pass_context.cc.

43  {
44  return pass_ != nullptr;
45 }

Referenced by EndPass(), and GetRenderPass().

◆ IsValid()

bool impeller::InlinePassContext::IsValid ( ) const

Definition at line 39 of file inline_pass_context.cc.

39  {
40  return pass_target_.IsValid();
41 }

References impeller::EntityPassTarget::IsValid().

Referenced by GetTexture().


The documentation for this class was generated from the following files:
impeller::StoreAction::kMultisampleResolve
@ kMultisampleResolve
impeller::LoadAction::kLoad
@ kLoad
impeller::EntityPassTarget::IsValid
bool IsValid() const
Definition: entity_pass_target.cc:72
impeller::Allocation::NextPowerOfTwoSize
static uint32_t NextPowerOfTwoSize(uint32_t x)
Definition: allocation.cc:41
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:43
impeller::StoreAction::kStore
@ kStore
impeller::InlinePassContext::EndPass
bool EndPass()
Definition: inline_pass_context.cc:54
impeller::InlinePassContext::IsValid
bool IsValid() const
Definition: inline_pass_context.cc:39
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:67
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:68
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:20