Flutter Impeller
impeller::SwapchainTransientsMTL Class Reference

A cache for the onscreen texture attachments used in surface_mtl. More...

#include <swapchain_transients_mtl.h>

Public Member Functions

 SwapchainTransientsMTL (const std::shared_ptr< Allocator > &allocator)
 
 ~SwapchainTransientsMTL ()
 
void SetSizeAndFormat (ISize size, PixelFormat format)
 Update the size and pixel format of the onscreens. More...
 
std::shared_ptr< TextureGetResolveTexture ()
 Retrieve the resolve texture, creating one if needed. More...
 
std::shared_ptr< TextureGetMSAATexture ()
 Retrieve the MSAA texture, creating one if needed. More...
 
std::shared_ptr< TextureGetDepthStencilTexture ()
 Retrieve the depth+stencil texture, creating one if needed. More...
 

Detailed Description

A cache for the onscreen texture attachments used in surface_mtl.

Typically the onscreen resolve texture is created from a Metal drawable and this cache is only used for the MSAA texture and the depth+stencil attachment. When partial repaint is active, this class also provides a cache for an offscreen resolve texture that is blitted to the real onscreen during present.

Definition at line 25 of file swapchain_transients_mtl.h.

Constructor & Destructor Documentation

◆ SwapchainTransientsMTL()

impeller::SwapchainTransientsMTL::SwapchainTransientsMTL ( const std::shared_ptr< Allocator > &  allocator)
explicit

Definition at line 12 of file swapchain_transients_mtl.mm.

14  : allocator_(allocator) {}

◆ ~SwapchainTransientsMTL()

impeller::SwapchainTransientsMTL::~SwapchainTransientsMTL ( )
default

Member Function Documentation

◆ GetDepthStencilTexture()

std::shared_ptr< Texture > impeller::SwapchainTransientsMTL::GetDepthStencilTexture ( )

Retrieve the depth+stencil texture, creating one if needed.

Definition at line 71 of file swapchain_transients_mtl.mm.

71  {
72  if (!depth_stencil_tex_) {
73  TextureDescriptor desc;
74  desc.size = size_;
75  desc.sample_count = SampleCount::kCount4;
76  desc.format = PixelFormat::kD32FloatS8UInt;
77  desc.storage_mode = StorageMode::kDeviceTransient;
78  desc.usage = TextureUsage::kRenderTarget;
80 
81  depth_stencil_tex_ = allocator_->CreateTexture(desc);
82  if (!depth_stencil_tex_) {
83  VALIDATION_LOG << "Failed to allocate depth-stencil texture.";
84  return nullptr;
85  }
86  depth_stencil_tex_->SetLabel("ImpellerOnscreenDepth+Stencil");
87  }
88 
89  return depth_stencil_tex_;
90 }
#define VALIDATION_LOG
Definition: validation.h:91

References impeller::TextureDescriptor::format, impeller::kCount4, impeller::kD32FloatS8UInt, impeller::kDeviceTransient, impeller::kRenderTarget, impeller::kTexture2DMultisample, impeller::TextureDescriptor::sample_count, impeller::TextureDescriptor::size, impeller::TextureDescriptor::storage_mode, impeller::TextureDescriptor::type, impeller::TextureDescriptor::usage, and VALIDATION_LOG.

◆ GetMSAATexture()

std::shared_ptr< Texture > impeller::SwapchainTransientsMTL::GetMSAATexture ( )

Retrieve the MSAA texture, creating one if needed.

Definition at line 50 of file swapchain_transients_mtl.mm.

50  {
51  if (!msaa_tex_) {
52  TextureDescriptor desc;
53  desc.size = size_;
54  desc.sample_count = SampleCount::kCount4;
55  desc.format = format_;
56  desc.storage_mode = StorageMode::kDeviceTransient;
57  desc.usage = TextureUsage::kRenderTarget;
59 
60  msaa_tex_ = allocator_->CreateTexture(desc);
61  if (!msaa_tex_) {
62  VALIDATION_LOG << "Failed to allocate MSAA texture.";
63  return nullptr;
64  }
65  msaa_tex_->SetLabel("ImpellerOnscreenMSAA");
66  }
67 
68  return msaa_tex_;
69 }

References impeller::TextureDescriptor::format, impeller::kCount4, impeller::kDeviceTransient, impeller::kRenderTarget, impeller::kTexture2DMultisample, impeller::TextureDescriptor::sample_count, impeller::TextureDescriptor::size, impeller::TextureDescriptor::storage_mode, impeller::TextureDescriptor::type, impeller::TextureDescriptor::usage, and VALIDATION_LOG.

◆ GetResolveTexture()

std::shared_ptr< Texture > impeller::SwapchainTransientsMTL::GetResolveTexture ( )

Retrieve the resolve texture, creating one if needed.

Definition at line 28 of file swapchain_transients_mtl.mm.

28  {
29  if (!resolve_tex_) {
30  TextureDescriptor desc;
31  desc.size = size_;
32  desc.sample_count = SampleCount::kCount1;
33  desc.format = format_;
34  desc.storage_mode = StorageMode::kDevicePrivate;
36  desc.compression_type = CompressionType::kLossy;
37  desc.type = TextureType::kTexture2D;
38 
39  resolve_tex_ = allocator_->CreateTexture(desc);
40  if (!resolve_tex_) {
41  VALIDATION_LOG << "Failed to allocate resolve texture.";
42  return nullptr;
43  }
44  resolve_tex_->SetLabel("ImpellerOnscreenResolve");
45  }
46 
47  return resolve_tex_;
48 }

References impeller::TextureDescriptor::compression_type, impeller::TextureDescriptor::format, impeller::kCount1, impeller::kDevicePrivate, impeller::kLossy, impeller::kRenderTarget, impeller::kShaderRead, impeller::kTexture2D, impeller::TextureDescriptor::sample_count, impeller::TextureDescriptor::size, impeller::TextureDescriptor::storage_mode, impeller::TextureDescriptor::type, impeller::TextureDescriptor::usage, and VALIDATION_LOG.

◆ SetSizeAndFormat()

void impeller::SwapchainTransientsMTL::SetSizeAndFormat ( ISize  size,
PixelFormat  format 
)

Update the size and pixel format of the onscreens.

Note: this will invalidate any cached textures if either property changes.

Definition at line 18 of file swapchain_transients_mtl.mm.

18  {
19  if (size != size_ || format != format_) {
20  resolve_tex_ = nullptr;
21  msaa_tex_ = nullptr;
22  depth_stencil_tex_ = nullptr;
23  }
24  size_ = size;
25  format_ = format;
26 }

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