| Flutter Impeller |

Classes | Public Member Functions | Static Public Attributes | List of all members
impeller::RenderTarget Class Referencefinal

`#include <render_target.h>`

## Classes
struct | AttachmentConfig
struct | AttachmentConfigMSAA

## Public Member Functions
| RenderTarget ()
| ~RenderTarget ()
bool | IsValid () const
void | SetupDepthStencilAttachments (const Context &context, Allocator &allocator, ISize size, bool msaa, const std::string &label="Offscreen", RenderTarget::AttachmentConfig stencil_attachment_config=RenderTarget::kDefaultStencilAttachmentConfig, const std::shared_ptr< Texture > &depth_stencil_texture=nullptr)
SampleCount | GetSampleCount () const
bool | HasColorAttachment (size_t index) const
ISize | GetRenderTargetSize () const
std::shared_ptr< Texture > | GetRenderTargetTexture () const
PixelFormat | GetRenderTargetPixelFormat () const
std::optional< ISize > | GetColorAttachmentSize (size_t index) const
RenderTarget & | SetColorAttachment (const ColorAttachment &attachment, size_t index)
RenderTarget & | SetDepthAttachment (std::optional< DepthAttachment > attachment)
RenderTarget & | SetStencilAttachment (std::optional< StencilAttachment > attachment)
size_t | GetMaxColorAttacmentBindIndex () const
const std::map< size_t, ColorAttachment > & | GetColorAttachments () const
const std::optional< DepthAttachment > & | GetDepthAttachment () const
const std::optional< StencilAttachment > & | GetStencilAttachment () const
size_t | GetTotalAttachmentCount () const
void | IterateAllAttachments (const std::function< bool(const Attachment &attachment)> &iterator) const
std::string | ToString () const
RenderTargetConfig | ToConfig () const

## Static Public Attributes
static constexpr AttachmentConfig | kDefaultColorAttachmentConfig
static constexpr AttachmentConfigMSAA | kDefaultColorAttachmentConfigMSAA
static constexpr AttachmentConfig | kDefaultStencilAttachmentConfig

## Detailed Description

Definition at line 38 of file render_target.h.

## Constructor & Destructor Documentation

## ◆ RenderTarget()

impeller::RenderTarget::RenderTarget | ( |  | ) |
| default

## ◆ ~RenderTarget()

impeller::RenderTarget::~RenderTarget | ( |  | ) |
| default

## Member Function Documentation

## ◆ GetColorAttachments()

const std::map< size_t, ColorAttachment > & impeller::RenderTarget::GetColorAttachments | ( |  | ) | const

Definition at line 198 of file render_target.cc.

199 {
200 return colors_;
201 }

Referenced by impeller::EntityPassTarget::Flip(), impeller::InlinePassContext::GetRenderPass(), impeller::GetVKClearValues(), impeller::ContextVK::InitializeCommonlyUsedShadersIfNeeded(), impeller::Playground::OpenPlaygroundHere(), impeller::testing::TEST_P(), ToConfig(), and impeller::ToMTLRenderPassDescriptor().

## ◆ GetColorAttachmentSize()

std::optional< ISize > impeller::RenderTarget::GetColorAttachmentSize | ( | size_t | index | ) | const

Definition at line 129 of file render_target.cc.

129 {
130 auto found = colors_.find(index);
131
132 if (found == colors_.end()) {
133 return std::nullopt;
134 }
135
136 return found->second.texture->GetSize();
137 }

Referenced by GetRenderTargetSize(), and impeller::Surface::Surface().

## ◆ GetDepthAttachment()

const std::optional< DepthAttachment > & impeller::RenderTarget::GetDepthAttachment | ( |  | ) | const

Definition at line 203 of file render_target.cc.

203 {
204 return depth_;
205 }

Referenced by impeller::InlinePassContext::GetRenderPass(), impeller::GetVKClearValues(), impeller::ContextVK::InitializeCommonlyUsedShadersIfNeeded(), impeller::testing::TEST_P(), and impeller::ToMTLRenderPassDescriptor().

## ◆ GetMaxColorAttacmentBindIndex()

size_t impeller::RenderTarget::GetMaxColorAttacmentBindIndex | ( |  | ) | const

Definition at line 161 of file render_target.cc.

161 {
162 size_t max = 0;
163 for (const auto& color : colors_) {
164 max = std::max(color.first, max);
165 }
166 return max;
167 }

References color.

## ◆ GetRenderTargetPixelFormat()

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

Definition at line 153 of file render_target.cc.

153 {
154 if (auto texture = GetRenderTargetTexture(); texture != nullptr) {
155 return texture->GetTextureDescriptor().format;
156 }
157
158 return PixelFormat::kUnknown;
159 }

References GetRenderTargetTexture(), and impeller::kUnknown.

## ◆ GetRenderTargetSize()

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

Definition at line 139 of file render_target.cc.

139 {
140 auto size = GetColorAttachmentSize(0u);
141 return size.has_value() ? size.value() : ISize{};
142 }

References GetColorAttachmentSize().

Referenced by impeller::RenderPass::AddCommand(), and impeller::Canvas::GetLocalCoverageLimit().

## ◆ GetRenderTargetTexture()

std::shared_ptr< Texture > impeller::RenderTarget::GetRenderTargetTexture | ( |  | ) | const

Definition at line 144 of file render_target.cc.

144 {
145 auto found = colors_.find(0u);
146 if (found == colors_.end()) {
147 return nullptr;
148 }
149 return found->second.resolve_texture ? found->second.resolve_texture
150 : found->second.texture;
151 }

Referenced by impeller::DisplayListToTexture(), impeller::InlinePassContext::EndPass(), GetRenderTargetPixelFormat(), impeller::InlinePassContext::GetTexture(), and impeller::ContentContext::MakeSubpass().

## ◆ GetSampleCount()

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

Definition at line 115 of file render_target.cc.

115 {
116 if (auto found = colors_.find(0u); found != colors_.end()) {
117 return found->second.texture->GetTextureDescriptor().sample_count;
118 }
119 return SampleCount::kCount1;
120 }

References impeller::kCount1.

## ◆ GetStencilAttachment()

const std::optional< StencilAttachment > & impeller::RenderTarget::GetStencilAttachment | ( |  | ) | const

Definition at line 207 of file render_target.cc.

208 {
209 return stencil_;
210 }

Referenced by impeller::InlinePassContext::GetRenderPass(), impeller::GetVKClearValues(), impeller::ContextVK::InitializeCommonlyUsedShadersIfNeeded(), and impeller::ToMTLRenderPassDescriptor().

## ◆ GetTotalAttachmentCount()

size_t impeller::RenderTarget::GetTotalAttachmentCount | ( |  | ) | const

Definition at line 212 of file render_target.cc.

212 {
213 size_t count = 0u;
214 for (const auto& [_, color] : colors_) {
215 if (color.texture) {
216 count++;
217 }
218 if (color.resolve_texture) {
219 count++;
220 }
221 }
222 if (depth_.has_value()) {
223 count++;
224 }
225 if (stencil_.has_value()) {
226 count++;
227 }
228 return count;
229 }

References color.

## ◆ HasColorAttachment()

bool impeller::RenderTarget::HasColorAttachment | ( | size_t | index | ) | const

Definition at line 122 of file render_target.cc.

122 {
123 if (auto found = colors_.find(index); found != colors_.end()) {
124 return true;
125 }
126 return false;
127 }

Referenced by IsValid().

## ◆ IsValid()

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

Definition at line 23 of file render_target.cc.

23 {
24 // Validate that there is a color attachment at zero index.
25 if (!HasColorAttachment(0u)) {
26 VALIDATION_LOG
27 << "Render target does not have color attachment at index 0.";
28 return false;
29 }
30
31 // Validate that all attachments are of the same size.
32 {
33 std::optional<ISize> size;
34 bool sizes_are_same = true;
35 auto iterator = [&](const Attachment& attachment) -> bool {
36 if (!size.has_value()) {
37 size = attachment.texture->GetSize();
38 }
39 if (size != attachment.texture->GetSize()) {
40 sizes_are_same = false;
41 return false;
42 }
43 return true;
44 };
45 IterateAllAttachments(iterator);
46 if (!sizes_are_same) {
47 VALIDATION_LOG
48 << "Sizes of all render target attachments are not the same.";
49 return false;
50 }
51 }
52
53 // Validate that all attachments are of the same type and sample counts.
54 {
55 std::optional<TextureType> texture_type;
56 std::optional<SampleCount> sample_count;
57 bool passes_type_validation = true;
58 auto iterator = [&](const Attachment& attachment) -> bool {
59 if (!texture_type.has_value() || !sample_count.has_value()) {
60 texture_type = attachment.texture->GetTextureDescriptor().type;
61 sample_count = attachment.texture->GetTextureDescriptor().sample_count;
62 }
63
64 if (texture_type != attachment.texture->GetTextureDescriptor().type) {
65 passes_type_validation = false;
66 VALIDATION_LOG << "Render target has incompatible texture types: "
67 << TextureTypeToString(texture_type.value()) << " != "
68 << TextureTypeToString(
69 attachment.texture->GetTextureDescriptor().type)
70 << " on target " << ToString();
71 return false;
72 }
73
74 if (sample_count !=
75 attachment.texture->GetTextureDescriptor().sample_count) {
76 passes_type_validation = false;
77 VALIDATION_LOG << "Render target (" << ToString()
78 << ") has incompatible sample counts.";
79
80 return false;
81 }
82
83 return true;
84 };
85 IterateAllAttachments(iterator);
86 if (!passes_type_validation) {
87 return false;
88 }
89 }
90
91 return true;
92 }

References HasColorAttachment(), IterateAllAttachments(), impeller::TextureTypeToString(), ToString(), and VALIDATION_LOG.

Referenced by impeller::RenderTargetCache::CreateOffscreen(), impeller::RenderTargetCache::CreateOffscreenMSAA(), impeller::EntityPassTarget::IsValid(), and impeller::testing::TEST_P().

## ◆ IterateAllAttachments()

void impeller::RenderTarget::IterateAllAttachments | ( | const std::function< bool(const Attachment &attachment)> & | iterator | ) | const

Definition at line 94 of file render_target.cc.

95 {
96 for (const auto& color : colors_) {
97 if (!iterator(color.second)) {
98 return;
99 }
100 }
101
102 if (depth_.has_value()) {
103 if (!iterator(depth_.value())) {
104 return;
105 }
106 }
107
108 if (stencil_.has_value()) {
109 if (!iterator(stencil_.value())) {
110 return;
111 }
112 }
113 }

References color.

Referenced by IsValid().

## ◆ SetColorAttachment()

RenderTarget & impeller::RenderTarget::SetColorAttachment | ( | const ColorAttachment & | attachment,
|  | size_t | index
| ) |  |

Definition at line 169 of file render_target.cc.

171 {
172 if (attachment.IsValid()) {
173 colors_[index] = attachment;
174 }
175 return *this;
176 }

References impeller::Attachment::IsValid().

Referenced by impeller::RenderTargetAllocator::CreateOffscreen(), impeller::RenderTargetAllocator::CreateOffscreenMSAA(), impeller::EntityPassTarget::Flip(), impeller::InlinePassContext::GetRenderPass(), impeller::Playground::OpenPlaygroundHere(), impeller::testing::TEST_P(), impeller::SurfaceGLES::WrapFBO(), and impeller::SurfaceVK::WrapSwapchainImage().

## ◆ SetDepthAttachment()

RenderTarget & impeller::RenderTarget::SetDepthAttachment | ( | std::optional< DepthAttachment > | attachment | ) |

Definition at line 178 of file render_target.cc.

179 {
180 if (!attachment.has_value()) {
181 depth_ = std::nullopt;
182 } else if (attachment->IsValid()) {
183 depth_ = std::move(attachment);
184 }
185 return *this;
186 }

Referenced by impeller::RenderTargetAllocator::CreateOffscreen(), impeller::RenderTargetAllocator::CreateOffscreenMSAA(), impeller::InlinePassContext::GetRenderPass(), impeller::Playground::OpenPlaygroundHere(), SetupDepthStencilAttachments(), and impeller::SurfaceGLES::WrapFBO().

## ◆ SetStencilAttachment()

RenderTarget & impeller::RenderTarget::SetStencilAttachment | ( | std::optional< StencilAttachment > | attachment | ) |

Definition at line 188 of file render_target.cc.

189 {
190 if (!attachment.has_value()) {
191 stencil_ = std::nullopt;
192 } else if (attachment->IsValid()) {
193 stencil_ = std::move(attachment);
194 }
195 return *this;
196 }

Referenced by impeller::RenderTargetAllocator::CreateOffscreen(), impeller::RenderTargetAllocator::CreateOffscreenMSAA(), impeller::InlinePassContext::GetRenderPass(), impeller::Playground::OpenPlaygroundHere(), SetupDepthStencilAttachments(), impeller::testing::TEST_P(), and impeller::SurfaceGLES::WrapFBO().

## ◆ SetupDepthStencilAttachments()

void impeller::RenderTarget::SetupDepthStencilAttachments | ( | const Context & | context,
|  | Allocator & | allocator,
|  | ISize | size,
|  | bool | msaa,
|  | const std::string & | label = `"Offscreen"`,
|  | RenderTarget::AttachmentConfig | stencil_attachment_config = `RenderTarget::kDefaultStencilAttachmentConfig`,
|  | const std::shared_ptr< Texture > & | depth_stencil_texture = `nullptr`
| ) |  |

Definition at line 413 of file render_target.cc.

420 {
421 std::shared_ptr<Texture> depth_stencil_texture;
422 if (existing_depth_stencil_texture) {
423 depth_stencil_texture = existing_depth_stencil_texture;
424 } else {
425 TextureDescriptor depth_stencil_texture_desc;
426 depth_stencil_texture_desc.storage_mode =
427 stencil_attachment_config.storage_mode;
428 if (msaa) {
429 depth_stencil_texture_desc.type = TextureType::kTexture2DMultisample;
430 depth_stencil_texture_desc.sample_count = SampleCount::kCount4;
431 }
432 depth_stencil_texture_desc.format =
433 context.GetCapabilities()->GetDefaultDepthStencilFormat();
434 depth_stencil_texture_desc.size = size;
435 depth_stencil_texture_desc.usage = TextureUsage::kRenderTarget;
436 depth_stencil_texture = allocator.CreateTexture(depth_stencil_texture_desc);
437 if (!depth_stencil_texture) {
438 return; // Error messages are handled by `Allocator::CreateTexture`.
439 }
440 }
441
442 DepthAttachment depth0;
443 depth0.load_action = stencil_attachment_config.load_action;
444 depth0.store_action = stencil_attachment_config.store_action;
445 depth0.clear_depth = 0u;
446 depth0.texture = depth_stencil_texture;
447
448 StencilAttachment stencil0;
449 stencil0.load_action = stencil_attachment_config.load_action;
450 stencil0.store_action = stencil_attachment_config.store_action;
451 stencil0.clear_stencil = 0u;
452 stencil0.texture = std::move(depth_stencil_texture);
453
454 stencil0.texture->SetLabel(
455 SPrintF("%s Depth+Stencil Texture", label.c_str()));
456 SetDepthAttachment(std::move(depth0));
457 SetStencilAttachment(std::move(stencil0));
458 }

References impeller::DepthAttachment::clear_depth, impeller::StencilAttachment::clear_stencil, impeller::Allocator::CreateTexture(), impeller::TextureDescriptor::format, impeller::Context::GetCapabilities(), impeller::kCount4, impeller::kRenderTarget, impeller::kTexture2DMultisample, impeller::RenderTarget::AttachmentConfig::load_action, impeller::Attachment::load_action, impeller::TextureDescriptor::sample_count, SetDepthAttachment(), SetStencilAttachment(), impeller::TextureDescriptor::size, impeller::SPrintF(), impeller::TextureDescriptor::storage_mode, impeller::RenderTarget::AttachmentConfig::storage_mode, impeller::RenderTarget::AttachmentConfig::store_action, impeller::Attachment::store_action, impeller::Attachment::texture, impeller::TextureDescriptor::type, and impeller::TextureDescriptor::usage.

Referenced by impeller::RenderTargetAllocator::CreateOffscreen(), impeller::RenderTargetAllocator::CreateOffscreenMSAA(), and impeller::SurfaceVK::WrapSwapchainImage().

## ◆ ToConfig()

RenderTargetConfig impeller::RenderTarget::ToConfig | ( |  | ) | const
| inline

Definition at line 125 of file render_target.h.

125 {
126 auto& color_attachment = GetColorAttachments().find(0)->second;
127 return RenderTargetConfig{
128 .size = color_attachment.texture->GetSize(),
129 .mip_count = color_attachment.texture->GetMipCount(),
130 .has_msaa = color_attachment.resolve_texture != nullptr,
131 .has_depth_stencil = depth_.has_value() && stencil_.has_value()};
132 }

References GetColorAttachments(), and impeller::RenderTargetConfig::size.

## ◆ ToString()

std::string impeller::RenderTarget::ToString | ( |  | ) | const

Definition at line 231 of file render_target.cc.

231 {
232 std::stringstream stream;
233
234 for (const auto& [index, color] : colors_) {
235 stream << SPrintF("Color[%zu]=(%s)", index,
236 ColorAttachmentToString(color).c_str());
237 }
238 if (depth_) {
239 stream << ",";
240 stream << SPrintF("Depth=(%s)",
241 DepthAttachmentToString(depth_.value()).c_str());
242 }
243 if (stencil_) {
244 stream << ",";
245 stream << SPrintF("Stencil=(%s)",
246 StencilAttachmentToString(stencil_.value()).c_str());
247 }
248 return stream.str();
249 }

References color, impeller::ColorAttachmentToString(), impeller::DepthAttachmentToString(), impeller::SPrintF(), and impeller::StencilAttachmentToString().

Referenced by IsValid().

## Member Data Documentation

## ◆ kDefaultColorAttachmentConfig

constexpr AttachmentConfig impeller::RenderTarget::kDefaultColorAttachmentConfig
| staticconstexpr

Initial value:
= {
.storage_mode = StorageMode::kDevicePrivate,
.load_action = LoadAction::kClear,
.store_action = StoreAction::kStore,
.clear_color = Color::BlackTransparent()}

Definition at line 55 of file render_target.h.

Referenced by impeller::ContentContext::MakeSubpass(), and impeller::testing::TEST_P().

## ◆ kDefaultColorAttachmentConfigMSAA

constexpr AttachmentConfigMSAA impeller::RenderTarget::kDefaultColorAttachmentConfigMSAA
| staticconstexpr

Initial value:
= {
.storage_mode = StorageMode::kDeviceTransient,
.resolve_storage_mode = StorageMode::kDevicePrivate,
.load_action = LoadAction::kClear,
.store_action = StoreAction::kMultisampleResolve,
.clear_color = Color::BlackTransparent()}

Definition at line 61 of file render_target.h.

Referenced by impeller::ContentContext::MakeSubpass().

## ◆ kDefaultStencilAttachmentConfig

constexpr AttachmentConfig impeller::RenderTarget::kDefaultStencilAttachmentConfig
| staticconstexpr

Initial value:
= {
.storage_mode = StorageMode::kDeviceTransient,
.load_action = LoadAction::kClear,
.store_action = StoreAction::kDontCare,
.clear_color = Color::BlackTransparent()}

Definition at line 68 of file render_target.h.

Referenced by impeller::ContentContext::MakeSubpass(), and impeller::SurfaceVK::WrapSwapchainImage().

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

- impeller/renderer/render_target.h
- impeller/renderer/render_target.cc

impeller::ISize
ISize64 ISize
Definition: size.h:140
impeller::StoreAction::kMultisampleResolve
@ kMultisampleResolve
impeller::StoreAction::kDontCare
@ kDontCare
impeller::RenderTarget::GetColorAttachmentSize
std::optional< ISize > GetColorAttachmentSize(size_t index) const
Definition: render_target.cc:129
impeller::TextureUsage::kRenderTarget
@ kRenderTarget
impeller::RenderTarget::GetColorAttachments
const std::map< size_t, ColorAttachment > & GetColorAttachments() const
Definition: render_target.cc:198
impeller::TextureType::kTexture2DMultisample
@ kTexture2DMultisample
impeller::LoadAction::kClear
@ kClear
impeller::StorageMode::kDeviceTransient
@ kDeviceTransient
impeller::RenderTarget::GetRenderTargetTexture
std::shared_ptr< Texture > GetRenderTargetTexture() const
Definition: render_target.cc:144
impeller::RenderTarget::IterateAllAttachments
void IterateAllAttachments(const std::function< bool(const Attachment &attachment)> &iterator) const
Definition: render_target.cc:94
impeller::SPrintF
std::string SPrintF(const char *format,...)
Definition: strings.cc:12
impeller::StorageMode::kDevicePrivate
@ kDevicePrivate
impeller::ColorAttachmentToString
std::string ColorAttachmentToString(const ColorAttachment &color)
Definition: formats.cc:123
impeller::StoreAction::kStore
@ kStore
impeller::PixelFormat::kUnknown
@ kUnknown
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:91
impeller::TextureTypeToString
constexpr const char * TextureTypeToString(TextureType type)
Definition: formats.h:269
impeller::RenderTarget::SetStencilAttachment
RenderTarget & SetStencilAttachment(std::optional< StencilAttachment > attachment)
Definition: render_target.cc:188
impeller::DepthAttachmentToString
std::string DepthAttachmentToString(const DepthAttachment &depth)
Definition: formats.cc:130
impeller::Color::BlackTransparent
static constexpr Color BlackTransparent()
Definition: color.h:269
impeller::SampleCount::kCount1
@ kCount1
impeller::SampleCount::kCount4
@ kCount4
color
DlColor color
Definition: dl_golden_blur_unittests.cc:24
impeller::RenderTarget::SetDepthAttachment
RenderTarget & SetDepthAttachment(std::optional< DepthAttachment > attachment)
Definition: render_target.cc:178
impeller::RenderTarget::HasColorAttachment
bool HasColorAttachment(size_t index) const
Definition: render_target.cc:122
impeller::StencilAttachmentToString
std::string StencilAttachmentToString(const StencilAttachment &stencil)
Definition: formats.cc:137
impeller::RenderTarget::ToString
std::string ToString() const
Definition: render_target.cc:231