| 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, std::string_view 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, std::string_view 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 149 of file render_target.h.

## Constructor & Destructor Documentation

## ◆ RenderTargetAllocator()

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

Definition at line 314 of file render_target.cc.

316 : 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,
|  | std::string_view | 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 322 of file render_target.cc.

330 {
331 if (size.IsEmpty()) {
332 return {};
333 }
334
335 RenderTarget target;
336
337 std::shared_ptr<Texture> color0_tex;
338 if (existing_color_texture) {
339 color0_tex = existing_color_texture;
340 } else {
341 PixelFormat pixel_format =
342 context.GetCapabilities()->GetDefaultColorFormat();
343 TextureDescriptor color0_tex_desc;
344 color0_tex_desc.storage_mode = color_attachment_config.storage_mode;
345 color0_tex_desc.format = pixel_format;
346 color0_tex_desc.size = size;
347 color0_tex_desc.mip_count = mip_count;
348 color0_tex_desc.usage =
349 TextureUsage::kRenderTarget | TextureUsage::kShaderRead;
350 color0_tex = allocator_->CreateTexture(color0_tex_desc);
351 if (!color0_tex) {
352 return {};
353 }
354 }
355 color0_tex->SetLabel(label, "Color Texture");
356
357 ColorAttachment color0;
358 color0.clear_color = color_attachment_config.clear_color;
359 color0.load_action = color_attachment_config.load_action;
360 color0.store_action = color_attachment_config.store_action;
361 color0.texture = color0_tex;
362 target.SetColorAttachment(color0, 0u);
363
364 if (stencil_attachment_config.has_value()) {
365 target.SetupDepthStencilAttachments(
366 context, *allocator_, size, false, label,
367 stencil_attachment_config.value(), existing_depth_stencil_texture);
368 } else {
369 target.SetStencilAttachment(std::nullopt);
370 target.SetDepthAttachment(std::nullopt);
371 }
372
373 return target;
374 }
impeller::PixelFormat
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
Definition: formats.h:99
impeller::TextureUsage::kRenderTarget
@ kRenderTarget
impeller::TextureUsage::kShaderRead
@ kShaderRead

References impeller::ColorAttachment::clear_color, impeller::RenderTarget::AttachmentConfig::clear_color, impeller::TextureDescriptor::format, impeller::Context::GetCapabilities(), impeller::TSize< T >::IsEmpty(), impeller::kRenderTarget, impeller::kShaderRead, impeller::Attachment::load_action, impeller::RenderTarget::AttachmentConfig::load_action, impeller::TextureDescriptor::mip_count, impeller::RenderTarget::SetColorAttachment(), impeller::RenderTarget::SetDepthAttachment(), impeller::RenderTarget::SetStencilAttachment(), impeller::RenderTarget::SetupDepthStencilAttachments(), impeller::TextureDescriptor::size, impeller::TextureDescriptor::storage_mode, impeller::RenderTarget::AttachmentConfig::storage_mode, impeller::Attachment::store_action, impeller::RenderTarget::AttachmentConfig::store_action, impeller::Attachment::texture, and impeller::TextureDescriptor::usage.

Referenced by impeller::RenderTargetCache::CreateOffscreen(), impeller::DisplayListToTexture(), and impeller::testing::TEST_P().

## ◆ CreateOffscreenMSAA()

RenderTarget impeller::RenderTargetAllocator::CreateOffscreenMSAA | ( | const Context & | context,
|  | ISize | size,
|  | int | mip_count,
|  | std::string_view | 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 376 of file render_target.cc.

385 {
386 if (size.IsEmpty()) {
387 return {};
388 }
389
390 RenderTarget target;
391 PixelFormat pixel_format = context.GetCapabilities()->GetDefaultColorFormat();
392
393 // Create MSAA color texture.
394 std::shared_ptr<Texture> color0_msaa_tex;
395 if (existing_color_msaa_texture) {
396 color0_msaa_tex = existing_color_msaa_texture;
397 } else {
398 TextureDescriptor color0_tex_desc;
399 color0_tex_desc.storage_mode = color_attachment_config.storage_mode;
400 color0_tex_desc.type = TextureType::kTexture2DMultisample;
401 color0_tex_desc.sample_count = SampleCount::kCount4;
402 color0_tex_desc.format = pixel_format;
403 color0_tex_desc.size = size;
404 color0_tex_desc.usage = TextureUsage::kRenderTarget;
405 if (context.GetCapabilities()->SupportsImplicitResolvingMSAA()) {
406 // See below ("SupportsImplicitResolvingMSAA") for more details.
407 color0_tex_desc.storage_mode = StorageMode::kDevicePrivate;
408 }
409 color0_msaa_tex = allocator_->CreateTexture(color0_tex_desc);
410 if (!color0_msaa_tex) {
411 VALIDATION_LOG << "Could not create multisample color texture.";
412 return {};
413 }
414 }
415 color0_msaa_tex->SetLabel(label, "Color Texture (Multisample)");
416
417 // Create color resolve texture.
418 std::shared_ptr<Texture> color0_resolve_tex;
419 if (existing_color_resolve_texture) {
420 color0_resolve_tex = existing_color_resolve_texture;
421 } else {
422 TextureDescriptor color0_resolve_tex_desc;
423 color0_resolve_tex_desc.storage_mode =
424 color_attachment_config.resolve_storage_mode;
425 color0_resolve_tex_desc.format = pixel_format;
426 color0_resolve_tex_desc.size = size;
427 color0_resolve_tex_desc.compression_type = CompressionType::kLossy;
428 color0_resolve_tex_desc.usage =
429 TextureUsage::kRenderTarget | TextureUsage::kShaderRead;
430 color0_resolve_tex_desc.mip_count = mip_count;
431 color0_resolve_tex = allocator_->CreateTexture(color0_resolve_tex_desc);
432 if (!color0_resolve_tex) {
433 VALIDATION_LOG << "Could not create color texture.";
434 return {};
435 }
436 }
437 color0_resolve_tex->SetLabel(label, "Color Texture");
438
439 // Color attachment.
440
441 ColorAttachment color0;
442 color0.clear_color = color_attachment_config.clear_color;
443 color0.load_action = color_attachment_config.load_action;
444 color0.store_action = color_attachment_config.store_action;
445 color0.texture = color0_msaa_tex;
446 color0.resolve_texture = color0_resolve_tex;
447
448 if (context.GetCapabilities()->SupportsImplicitResolvingMSAA()) {
449 // If implicit MSAA is supported, then the resolve texture is not needed
450 // because the multisample texture is automatically resolved. We instead
451 // provide a view of the multisample texture as the resolve texture (because
452 // the HAL does expect a resolve texture).
453 //
454 // In practice, this is used for GLES 2.0 EXT_multisampled_render_to_texture
455 // https://registry.khronos.org/OpenGL/extensions/EXT/EXT_multisampled_render_to_texture.txt
456 color0.resolve_texture = color0_msaa_tex;
457 }
458
459 target.SetColorAttachment(color0, 0u);
460
461 // Create MSAA stencil texture.
462
463 if (stencil_attachment_config.has_value()) {
464 target.SetupDepthStencilAttachments(context, *allocator_, size, true, label,
465 stencil_attachment_config.value(),
466 existing_depth_stencil_texture);
467 } else {
468 target.SetDepthAttachment(std::nullopt);
469 target.SetStencilAttachment(std::nullopt);
470 }
471
472 return target;
473 }
impeller::StorageMode::kDevicePrivate
@ kDevicePrivate
impeller::TextureType::kTexture2DMultisample
@ kTexture2DMultisample
impeller::CompressionType::kLossy
@ kLossy
impeller::SampleCount::kCount4
@ kCount4
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:91

References impeller::ColorAttachment::clear_color, impeller::RenderTarget::AttachmentConfigMSAA::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::Attachment::load_action, impeller::RenderTarget::AttachmentConfigMSAA::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::TextureDescriptor::storage_mode, impeller::RenderTarget::AttachmentConfigMSAA::storage_mode, impeller::Attachment::store_action, impeller::RenderTarget::AttachmentConfigMSAA::store_action, impeller::Attachment::texture, impeller::TextureDescriptor::type, impeller::TextureDescriptor::usage, and VALIDATION_LOG.

Referenced by impeller::RenderTargetCache::CreateOffscreenMSAA(), impeller::DisplayListToTexture(), 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 320 of file render_target.cc.

320 {}

## ◆ 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 318 of file render_target.cc.

318 {}

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

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