Flutter Engine
 
Loading...
Searching...
No Matches
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, std::string_view 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< TextureGetRenderTargetTexture () const
 
PixelFormat GetRenderTargetPixelFormat () const
 
std::optional< ISizeGetColorAttachmentSize (size_t index) const
 
RenderTargetSetColorAttachment (const ColorAttachment &attachment, size_t index)
 
ColorAttachment GetColorAttachment (size_t index) const
 Get the color attachment at [index].
 
RenderTargetSetDepthAttachment (std::optional< DepthAttachment > attachment)
 
RenderTargetSetStencilAttachment (std::optional< StencilAttachment > attachment)
 
size_t GetMaxColorAttacmentBindIndex () const
 
const std::optional< DepthAttachment > & GetDepthAttachment () const
 
const std::optional< StencilAttachment > & GetStencilAttachment () const
 
size_t GetTotalAttachmentCount () const
 
bool IterateAllColorAttachments (const std::function< bool(size_t index, const ColorAttachment &attachment)> &iterator) 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

◆ GetColorAttachment()

ColorAttachment impeller::RenderTarget::GetColorAttachment ( size_t  index) const

Get the color attachment at [index].

This function does not validate whether or not the attachment was previously defined and will return a default constructed attachment if none is set.

Definition at line 233 of file render_target.cc.

233 {
234 if (index == 0) {
235 if (color0_.has_value()) {
236 return color0_.value();
237 }
238 return ColorAttachment{};
239 }
240 std::map<size_t, ColorAttachment>::const_iterator it = colors_.find(index);
241 if (it != colors_.end()) {
242 return it->second;
243 }
244 return ColorAttachment{};
245}

Referenced by impeller::EntityPassTarget::Flip(), impeller::InlinePassContext::GetRenderPass(), impeller::Playground::OpenPlaygroundHere(), impeller::testing::TEST(), impeller::testing::TEST_P(), impeller::testing::TEST_P(), impeller::testing::TEST_P(), and impeller::testing::TEST_P().

◆ GetColorAttachmentSize()

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

Definition at line 155 of file render_target.cc.

155 {
156 if (index == 0u) {
157 if (color0_.has_value()) {
158 return color0_.value().texture->GetSize();
159 }
160 return std::nullopt;
161 }
162 auto found = colors_.find(index);
163
164 if (found == colors_.end()) {
165 return std::nullopt;
166 }
167
168 return found->second.texture->GetSize();
169}

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

◆ GetDepthAttachment()

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

◆ GetMaxColorAttacmentBindIndex()

size_t impeller::RenderTarget::GetMaxColorAttacmentBindIndex ( ) const

Definition at line 191 of file render_target.cc.

191 {
192 size_t max = 0;
193 for (const auto& color : colors_) {
194 max = std::max(color.first, max);
195 }
196 return max;
197}

◆ GetRenderTargetPixelFormat()

PixelFormat impeller::RenderTarget::GetRenderTargetPixelFormat ( ) const

Definition at line 183 of file render_target.cc.

183 {
184 if (auto texture = GetRenderTargetTexture(); texture != nullptr) {
185 return texture->GetTextureDescriptor().format;
186 }
187
189}
std::shared_ptr< Texture > GetRenderTargetTexture() const
FlTexture * texture

References GetRenderTargetTexture(), impeller::kUnknown, and texture.

◆ GetRenderTargetSize()

ISize impeller::RenderTarget::GetRenderTargetSize ( ) const

Definition at line 171 of file render_target.cc.

171 {
172 auto size = GetColorAttachmentSize(0u);
173 return size.has_value() ? size.value() : ISize{};
174}
std::optional< ISize > GetColorAttachmentSize(size_t index) const
it will be possible to load the file into Perfetto s trace viewer use test Running tests that layout and measure text will not yield consistent results across various platforms Enabling this option will make font resolution default to the Ahem test font on all disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
ISize64 ISize
Definition size.h:162

References GetColorAttachmentSize().

Referenced by impeller::Canvas::GetLocalCoverageLimit(), impeller::AiksPlayground::OpenPlaygroundHere(), and impeller::DlPlayground::OpenPlaygroundHere().

◆ GetRenderTargetTexture()

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

Definition at line 176 of file render_target.cc.

176 {
177 if (!color0_.has_value()) {
178 return nullptr;
179 }
180 return color0_->resolve_texture ? color0_->resolve_texture : color0_->texture;
181}

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

◆ GetSampleCount()

SampleCount impeller::RenderTarget::GetSampleCount ( ) const

Definition at line 138 of file render_target.cc.

138 {
139 if (color0_.has_value()) {
140 return color0_.value().texture->GetTextureDescriptor().sample_count;
141 }
143}

References impeller::kCount1.

◆ GetStencilAttachment()

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

◆ GetTotalAttachmentCount()

size_t impeller::RenderTarget::GetTotalAttachmentCount ( ) const

Definition at line 256 of file render_target.cc.

256 {
257 size_t count = 0u;
258 for (const auto& [_, color] : colors_) {
259 if (color.texture) {
260 count++;
261 }
262 if (color.resolve_texture) {
263 count++;
264 }
265 }
266 if (color0_.has_value()) {
267 count++;
268 }
269 if (depth_.has_value()) {
270 count++;
271 }
272 if (stencil_.has_value()) {
273 count++;
274 }
275 return count;
276}

◆ HasColorAttachment()

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

Definition at line 145 of file render_target.cc.

145 {
146 if (index == 0u) {
147 return color0_.has_value();
148 }
149 if (auto found = colors_.find(index); found != colors_.end()) {
150 return true;
151 }
152 return false;
153}

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

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 112 of file render_target.cc.

113 {
114 if (color0_.has_value()) {
115 if (!iterator(color0_.value())) {
116 return;
117 }
118 }
119 for (const auto& color : colors_) {
120 if (!iterator(color.second)) {
121 return;
122 }
123 }
124
125 if (depth_.has_value()) {
126 if (!iterator(depth_.value())) {
127 return;
128 }
129 }
130
131 if (stencil_.has_value()) {
132 if (!iterator(stencil_.value())) {
133 return;
134 }
135 }
136}

Referenced by IsValid().

◆ IterateAllColorAttachments()

bool impeller::RenderTarget::IterateAllColorAttachments ( const std::function< bool(size_t index, const ColorAttachment &attachment)> &  iterator) const

Definition at line 96 of file render_target.cc.

98 {
99 if (color0_.has_value()) {
100 if (!iterator(0, color0_.value())) {
101 return false;
102 }
103 }
104 for (const auto& [index, attachment] : colors_) {
105 if (!iterator(index, attachment)) {
106 return false;
107 }
108 }
109 return true;
110}

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

◆ SetColorAttachment()

◆ SetDepthAttachment()

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

Definition at line 213 of file render_target.cc.

214 {
215 if (!attachment.has_value()) {
216 depth_ = std::nullopt;
217 } else if (attachment->IsValid()) {
218 depth_ = std::move(attachment);
219 }
220 return *this;
221}

Referenced by impeller::InlinePassContext::GetRenderPass(), InternalFlutterGpu_RenderPass_SetDepthStencilAttachment(), MakeRenderTargetFromBackingStoreImpeller(), impeller::Playground::OpenPlaygroundHere(), SetupDepthStencilAttachments(), impeller::testing::TEST_P(), impeller::SurfaceGLES::WrapFBO(), and impeller::WrapTextureWithRenderTarget().

◆ SetStencilAttachment()

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

◆ SetupDepthStencilAttachments()

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

Definition at line 475 of file render_target.cc.

482 {
483 std::shared_ptr<Texture> depth_stencil_texture;
484 if (existing_depth_stencil_texture) {
485 depth_stencil_texture = existing_depth_stencil_texture;
486 } else {
487 TextureDescriptor depth_stencil_texture_desc;
488 depth_stencil_texture_desc.storage_mode =
489 stencil_attachment_config.storage_mode;
490 if (msaa) {
491 depth_stencil_texture_desc.type = TextureType::kTexture2DMultisample;
492 depth_stencil_texture_desc.sample_count = SampleCount::kCount4;
493 }
494 depth_stencil_texture_desc.format =
495 context.GetCapabilities()->GetDefaultDepthStencilFormat();
496 depth_stencil_texture_desc.size = size;
497 depth_stencil_texture_desc.usage = TextureUsage::kRenderTarget;
498 depth_stencil_texture = allocator.CreateTexture(depth_stencil_texture_desc);
499 if (!depth_stencil_texture) {
500 return; // Error messages are handled by `Allocator::CreateTexture`.
501 }
502 }
503
504 DepthAttachment depth0;
505 depth0.load_action = stencil_attachment_config.load_action;
506 depth0.store_action = stencil_attachment_config.store_action;
507 depth0.clear_depth = 0u;
508 depth0.texture = depth_stencil_texture;
509
510 StencilAttachment stencil0;
511 stencil0.load_action = stencil_attachment_config.load_action;
512 stencil0.store_action = stencil_attachment_config.store_action;
513 stencil0.clear_stencil = 0u;
514 stencil0.texture = std::move(depth_stencil_texture);
515 stencil0.texture->SetLabel(label, "Depth+Stencil Texture");
516
517 SetDepthAttachment(std::move(depth0));
518 SetStencilAttachment(std::move(stencil0));
519}
RenderTarget & SetDepthAttachment(std::optional< DepthAttachment > attachment)
RenderTarget & SetStencilAttachment(std::optional< StencilAttachment > attachment)

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::Attachment::load_action, impeller::RenderTarget::AttachmentConfig::load_action, impeller::TextureDescriptor::sample_count, SetDepthAttachment(), SetStencilAttachment(), impeller::TextureDescriptor::size, impeller::TextureDescriptor::storage_mode, impeller::RenderTarget::AttachmentConfig::storage_mode, impeller::Attachment::store_action, impeller::RenderTarget::AttachmentConfig::store_action, impeller::Attachment::texture, impeller::TextureDescriptor::type, and impeller::TextureDescriptor::usage.

Referenced by impeller::SurfaceVK::WrapSwapchainImage().

◆ ToConfig()

RenderTargetConfig impeller::RenderTarget::ToConfig ( ) const

Definition at line 302 of file render_target.cc.

302 {
303 if (!color0_.has_value()) {
304 return RenderTargetConfig{};
305 }
306 const auto& color_attachment = color0_.value();
307 return RenderTargetConfig{
308 .size = color_attachment.texture->GetSize(),
309 .mip_count = color_attachment.texture->GetMipCount(),
310 .has_msaa = color_attachment.resolve_texture != nullptr,
311 .has_depth_stencil = depth_.has_value() && stencil_.has_value()};
312}

References impeller::RenderTargetConfig::size.

◆ ToString()

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

Definition at line 278 of file render_target.cc.

278 {
279 std::stringstream stream;
280
281 if (color0_.has_value()) {
282 stream << std::format("Color[{}]=({})", 0,
283 ColorAttachmentToString(color0_.value()));
284 }
285 for (const auto& [index, color] : colors_) {
286 stream << std::format("Color[{}]=({})", index,
288 }
289 if (depth_) {
290 stream << ",";
291 stream << std::format("Depth=({})",
292 DepthAttachmentToString(depth_.value()));
293 }
294 if (stencil_) {
295 stream << ",";
296 stream << std::format("Stencil=({})",
297 StencilAttachmentToString(stencil_.value()));
298 }
299 return stream.str();
300}
std::string DepthAttachmentToString(const DepthAttachment &depth)
Definition formats.cc:130
std::string ColorAttachmentToString(const ColorAttachment &color)
Definition formats.cc:123
std::string StencilAttachmentToString(const StencilAttachment &stencil)
Definition formats.cc:137

References impeller::ColorAttachmentToString(), impeller::DepthAttachmentToString(), 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()}
static constexpr Color BlackTransparent()
Definition color.h:270

Definition at line 55 of file render_target.h.

55 {
56 .storage_mode = StorageMode::kDevicePrivate,
57 .load_action = LoadAction::kClear,
58 .store_action = StoreAction::kStore,
59 .clear_color = Color::BlackTransparent()};

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

◆ kDefaultColorAttachmentConfigMSAA

constexpr AttachmentConfigMSAA impeller::RenderTarget::kDefaultColorAttachmentConfigMSAA
staticconstexpr
Initial value:
= {
.resolve_storage_mode = StorageMode::kDevicePrivate,
.load_action = LoadAction::kClear,
.clear_color = Color::BlackTransparent()}

Definition at line 61 of file render_target.h.

61 {
62 .storage_mode = StorageMode::kDeviceTransient,
63 .resolve_storage_mode = StorageMode::kDevicePrivate,
64 .load_action = LoadAction::kClear,
66 .clear_color = Color::BlackTransparent()};

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

◆ kDefaultStencilAttachmentConfig

constexpr AttachmentConfig impeller::RenderTarget::kDefaultStencilAttachmentConfig
staticconstexpr
Initial value:
= {
.load_action = LoadAction::kClear,
.store_action = StoreAction::kDontCare,
.clear_color = Color::BlackTransparent()}

Definition at line 68 of file render_target.h.

68 {
69 .storage_mode = StorageMode::kDeviceTransient,
70 .load_action = LoadAction::kClear,
71 .store_action = StoreAction::kDontCare,
72 .clear_color = Color::BlackTransparent()};

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


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