| Flutter Impeller |

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

a wrapper around the impeller [Allocator] instance that can be used to provide caching of allocated render target textures. More...

`#include <render_target.h>`

Inheritance diagram for impeller::RenderTargetAllocator:

## Public Member Functions
| RenderTargetAllocator (std::shared_ptr< Allocator > allocator)
virtual | ~RenderTargetAllocator ()=default
virtual RenderTarget | CreateOffscreen (const Context &context, ISize size, int mip_count, const std::string &label="Offscreen", RenderTarget::AttachmentConfig color_attachment_config=RenderTarget::kDefaultColorAttachmentConfig, std::optional< RenderTarget::AttachmentConfig > stencil_attachment_config=RenderTarget::kDefaultStencilAttachmentConfig, const std::shared_ptr< Texture > &existing_color_texture=nullptr, const std::shared_ptr< Texture > &existing_depth_stencil_texture=nullptr)
virtual RenderTarget | CreateOffscreenMSAA (const Context &context, ISize size, int mip_count, const std::string &label="Offscreen MSAA", RenderTarget::AttachmentConfigMSAA color_attachment_config=RenderTarget::kDefaultColorAttachmentConfigMSAA, std::optional< RenderTarget::AttachmentConfig > stencil_attachment_config=RenderTarget::kDefaultStencilAttachmentConfig, const std::shared_ptr< Texture > &existing_color_msaa_texture=nullptr, const std::shared_ptr< Texture > &existing_color_resolve_texture=nullptr, const std::shared_ptr< Texture > &existing_depth_stencil_texture=nullptr)
virtual void | Start ()
| Mark the beginning of a frame workload. More...
virtual void | End ()
| Mark the end of a frame workload. More...

## Detailed Description

a wrapper around the impeller [Allocator] instance that can be used to provide caching of allocated render target textures.

Definition at line 142 of file render_target.h.

## Constructor & Destructor Documentation

## ◆ RenderTargetAllocator()

impeller::RenderTargetAllocator::RenderTargetAllocator | ( | std::shared_ptr< Allocator > | allocator | ) |
| explicit

Definition at line 251 of file render_target.cc.

253 : allocator_(std::move(allocator)) {}

## ◆ ~RenderTargetAllocator()

virtual impeller::RenderTargetAllocator::~RenderTargetAllocator | ( |  | ) |
| virtual default

## Member Function Documentation

## ◆ CreateOffscreen()

RenderTarget impeller::RenderTargetAllocator::CreateOffscreen | ( | const Context & | context,
|  | ISize | size,
|  | int | mip_count,
|  | const std::string & | label = `"Offscreen"`,
|  | RenderTarget::AttachmentConfig | color_attachment_config = `RenderTarget::kDefaultColorAttachmentConfig`,
|  | std::optional< RenderTarget::AttachmentConfig > | stencil_attachment_config = `RenderTarget::kDefaultStencilAttachmentConfig`,
|  | const std::shared_ptr< Texture > & | existing_color_texture = `nullptr`,
|  | const std::shared_ptr< Texture > & | existing_depth_stencil_texture = `nullptr`
| ) |  |
| virtual

Reimplemented in impeller::RenderTargetCache.

Definition at line 259 of file render_target.cc.

267 {
268 if (size.IsEmpty()) {
269 return {};
270 }
271
272 RenderTarget target;
273
274 std::shared_ptr<Texture> color0_tex;
275 if (existing_color_texture) {
276 color0_tex = existing_color_texture;
277 } else {
278 PixelFormat pixel_format =
279 context.GetCapabilities()->GetDefaultColorFormat();
280 TextureDescriptor color0_tex_desc;
281 color0_tex_desc.storage_mode = color_attachment_config.storage_mode;
282 color0_tex_desc.format = pixel_format;
283 color0_tex_desc.size = size;
284 color0_tex_desc.mip_count = mip_count;
285 color0_tex_desc.usage =
286 TextureUsage::kRenderTarget | TextureUsage::kShaderRead;
287 color0_tex = allocator_->CreateTexture(color0_tex_desc);
288 if (!color0_tex) {
289 return {};
290 }
291 }
292 color0_tex->SetLabel(SPrintF("%s Color Texture", label.c_str()));
293
294 ColorAttachment color0;
295 color0.clear_color = color_attachment_config.clear_color;
296 color0.load_action = color_attachment_config.load_action;
297 color0.store_action = color_attachment_config.store_action;
298 color0.texture = color0_tex;
299 target.SetColorAttachment(color0, 0u);
300
301 if (stencil_attachment_config.has_value()) {
302 target.SetupDepthStencilAttachments(
303 context, *allocator_, size, false, label,
304 stencil_attachment_config.value(), existing_depth_stencil_texture);
305 } else {
306 target.SetStencilAttachment(std::nullopt);
307 target.SetDepthAttachment(std::nullopt);
308 }
309
310 return target;
311 }

References impeller::RenderTarget::AttachmentConfig::clear_color, impeller::ColorAttachment::clear_color, impeller::TextureDescriptor::format, impeller::Context::GetCapabilities(), impeller::TSize< T >::IsEmpty(), impeller::kRenderTarget, impeller::kShaderRead, impeller::RenderTarget::AttachmentConfig::load_action, impeller::Attachment::load_action, impeller::TextureDescriptor::mip_count, impeller::RenderTarget::SetColorAttachment(), impeller::RenderTarget::SetDepthAttachment(), impeller::RenderTarget::SetStencilAttachment(), impeller::RenderTarget::SetupDepthStencilAttachments(), 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, and impeller::TextureDescriptor::usage.

Referenced by impeller::RenderTargetCache::CreateOffscreen().

## ◆ CreateOffscreenMSAA()

RenderTarget impeller::RenderTargetAllocator::CreateOffscreenMSAA | ( | const Context & | context,
|  | ISize | size,
|  | int | mip_count,
|  | const std::string & | label = `"Offscreen MSAA"`,
|  | RenderTarget::AttachmentConfigMSAA | color_attachment_config = `RenderTarget::kDefaultColorAttachmentConfigMSAA`,
|  | std::optional< RenderTarget::AttachmentConfig > | stencil_attachment_config = `RenderTarget::kDefaultStencilAttachmentConfig`,
|  | const std::shared_ptr< Texture > & | existing_color_msaa_texture = `nullptr`,
|  | const std::shared_ptr< Texture > & | existing_color_resolve_texture = `nullptr`,
|  | const std::shared_ptr< Texture > & | existing_depth_stencil_texture = `nullptr`
| ) |  |
| virtual

Reimplemented in impeller::RenderTargetCache.

Definition at line 313 of file render_target.cc.

322 {
323 if (size.IsEmpty()) {
324 return {};
325 }
326
327 RenderTarget target;
328 PixelFormat pixel_format = context.GetCapabilities()->GetDefaultColorFormat();
329
330 // Create MSAA color texture.
331 std::shared_ptr<Texture> color0_msaa_tex;
332 if (existing_color_msaa_texture) {
333 color0_msaa_tex = existing_color_msaa_texture;
334 } else {
335 TextureDescriptor color0_tex_desc;
336 color0_tex_desc.storage_mode = color_attachment_config.storage_mode;
337 color0_tex_desc.type = TextureType::kTexture2DMultisample;
338 color0_tex_desc.sample_count = SampleCount::kCount4;
339 color0_tex_desc.format = pixel_format;
340 color0_tex_desc.size = size;
341 color0_tex_desc.usage = TextureUsage::kRenderTarget;
342 if (context.GetCapabilities()->SupportsImplicitResolvingMSAA()) {
343 // See below ("SupportsImplicitResolvingMSAA") for more details.
344 color0_tex_desc.storage_mode = StorageMode::kDevicePrivate;
345 }
346 color0_msaa_tex = allocator_->CreateTexture(color0_tex_desc);
347 if (!color0_msaa_tex) {
348 VALIDATION_LOG << "Could not create multisample color texture.";
349 return {};
350 }
351 }
352 color0_msaa_tex->SetLabel(
353 SPrintF("%s Color Texture (Multisample)", label.c_str()));
354
355 // Create color resolve texture.
356 std::shared_ptr<Texture> color0_resolve_tex;
357 if (existing_color_resolve_texture) {
358 color0_resolve_tex = existing_color_resolve_texture;
359 } else {
360 TextureDescriptor color0_resolve_tex_desc;
361 color0_resolve_tex_desc.storage_mode =
362 color_attachment_config.resolve_storage_mode;
363 color0_resolve_tex_desc.format = pixel_format;
364 color0_resolve_tex_desc.size = size;
365 color0_resolve_tex_desc.compression_type = CompressionType::kLossy;
366 color0_resolve_tex_desc.usage =
367 TextureUsage::kRenderTarget | TextureUsage::kShaderRead;
368 color0_resolve_tex_desc.mip_count = mip_count;
369 color0_resolve_tex = allocator_->CreateTexture(color0_resolve_tex_desc);
370 if (!color0_resolve_tex) {
371 VALIDATION_LOG << "Could not create color texture.";
372 return {};
373 }
374 }
375 color0_resolve_tex->SetLabel(SPrintF("%s Color Texture", label.c_str()));
376
377 // Color attachment.
378
379 ColorAttachment color0;
380 color0.clear_color = color_attachment_config.clear_color;
381 color0.load_action = color_attachment_config.load_action;
382 color0.store_action = color_attachment_config.store_action;
383 color0.texture = color0_msaa_tex;
384 color0.resolve_texture = color0_resolve_tex;
385
386 if (context.GetCapabilities()->SupportsImplicitResolvingMSAA()) {
387 // If implicit MSAA is supported, then the resolve texture is not needed
388 // because the multisample texture is automatically resolved. We instead
389 // provide a view of the multisample texture as the resolve texture (because
390 // the HAL does expect a resolve texture).
391 //
392 // In practice, this is used for GLES 2.0 EXT_multisampled_render_to_texture
393 // https://registry.khronos.org/OpenGL/extensions/EXT/EXT_multisampled_render_to_texture.txt
394 color0.resolve_texture = color0_msaa_tex;
395 }
396
397 target.SetColorAttachment(color0, 0u);
398
399 // Create MSAA stencil texture.
400
401 if (stencil_attachment_config.has_value()) {
402 target.SetupDepthStencilAttachments(context, *allocator_, size, true, label,
403 stencil_attachment_config.value(),
404 existing_depth_stencil_texture);
405 } else {
406 target.SetDepthAttachment(std::nullopt);
407 target.SetStencilAttachment(std::nullopt);
408 }
409
410 return target;
411 }

References impeller::RenderTarget::AttachmentConfigMSAA::clear_color, impeller::ColorAttachment::clear_color, impeller::TextureDescriptor::compression_type, impeller::TextureDescriptor::format, impeller::Context::GetCapabilities(), impeller::TSize< T >::IsEmpty(), impeller::kCount4, impeller::kDevicePrivate, impeller::kLossy, impeller::kRenderTarget, impeller::kShaderRead, impeller::kTexture2DMultisample, impeller::RenderTarget::AttachmentConfigMSAA::load_action, impeller::Attachment::load_action, impeller::TextureDescriptor::mip_count, impeller::RenderTarget::AttachmentConfigMSAA::resolve_storage_mode, impeller::Attachment::resolve_texture, impeller::TextureDescriptor::sample_count, impeller::RenderTarget::SetColorAttachment(), impeller::RenderTarget::SetDepthAttachment(), impeller::RenderTarget::SetStencilAttachment(), impeller::RenderTarget::SetupDepthStencilAttachments(), impeller::TextureDescriptor::size, impeller::SPrintF(), impeller::TextureDescriptor::storage_mode, impeller::RenderTarget::AttachmentConfigMSAA::storage_mode, impeller::RenderTarget::AttachmentConfigMSAA::store_action, impeller::Attachment::store_action, impeller::Attachment::texture, impeller::TextureDescriptor::type, impeller::TextureDescriptor::usage, and VALIDATION_LOG.

Referenced by impeller::RenderTargetCache::CreateOffscreenMSAA(), and impeller::ContextVK::InitializeCommonlyUsedShadersIfNeeded().

## ◆ End()

void impeller::RenderTargetAllocator::End | ( |  | ) |
| virtual

Mark the end of a frame workload.

       This may be used to deallocate any unused textures.

Reimplemented in impeller::RenderTargetCache.

Definition at line 257 of file render_target.cc.

257 {}

## ◆ Start()

void impeller::RenderTargetAllocator::Start | ( |  | ) |
| virtual

Mark the beginning of a frame workload.

      This may be used to reset any tracking state on whether or not a
      particular texture instance is still in use.

Reimplemented in impeller::RenderTargetCache.

Definition at line 255 of file render_target.cc.

255 {}

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

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

impeller::TextureUsage::kRenderTarget
@ kRenderTarget
impeller::PixelFormat
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
Definition: formats.h:100
impeller::TextureType::kTexture2DMultisample
@ kTexture2DMultisample
impeller::SPrintF
std::string SPrintF(const char *format,...)
Definition: strings.cc:12
impeller::StorageMode::kDevicePrivate
@ kDevicePrivate
impeller::CompressionType::kLossy
@ kLossy
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:73
impeller::TextureUsage::kShaderRead
@ kShaderRead
impeller::SampleCount::kCount4
@ kCount4