Flutter Impeller
swapchain_transients_mtl.mm
Go to the documentation of this file.
1
// Copyright 2013 The Flutter Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style license that can be
3
// found in the LICENSE file.
4
5
#include "
impeller/renderer/backend/metal/swapchain_transients_mtl.h
"
6
#include "
impeller/base/validation.h
"
7
#include "
impeller/core/formats.h
"
8
#include "
impeller/core/texture_descriptor.h
"
9
10
namespace
impeller
{
11
12
SwapchainTransientsMTL::SwapchainTransientsMTL
(
13
const
std::shared_ptr<Allocator>& allocator)
14
: allocator_(allocator) {}
15
16
SwapchainTransientsMTL::~SwapchainTransientsMTL
() =
default
;
17
18
void
SwapchainTransientsMTL::SetSizeAndFormat
(
ISize
size,
PixelFormat
format) {
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
}
27
28
std::shared_ptr<Texture>
SwapchainTransientsMTL::GetResolveTexture
() {
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
;
35
desc.
usage
=
TextureUsage::kShaderRead
|
TextureUsage::kRenderTarget
;
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
}
49
50
std::shared_ptr<Texture>
SwapchainTransientsMTL::GetMSAATexture
() {
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
;
58
desc.
type
=
TextureType::kTexture2DMultisample
;
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
}
70
71
std::shared_ptr<Texture>
SwapchainTransientsMTL::GetDepthStencilTexture
() {
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
;
79
desc.
type
=
TextureType::kTexture2DMultisample
;
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
}
91
92
}
// namespace impeller
impeller::SwapchainTransientsMTL::SwapchainTransientsMTL
SwapchainTransientsMTL(const std::shared_ptr< Allocator > &allocator)
Definition:
swapchain_transients_mtl.mm:12
impeller::SwapchainTransientsMTL::~SwapchainTransientsMTL
~SwapchainTransientsMTL()
impeller::SwapchainTransientsMTL::GetResolveTexture
std::shared_ptr< Texture > GetResolveTexture()
Retrieve the resolve texture, creating one if needed.
Definition:
swapchain_transients_mtl.mm:28
impeller::SwapchainTransientsMTL::SetSizeAndFormat
void SetSizeAndFormat(ISize size, PixelFormat format)
Update the size and pixel format of the onscreens.
Definition:
swapchain_transients_mtl.mm:18
impeller::SwapchainTransientsMTL::GetMSAATexture
std::shared_ptr< Texture > GetMSAATexture()
Retrieve the MSAA texture, creating one if needed.
Definition:
swapchain_transients_mtl.mm:50
impeller::SwapchainTransientsMTL::GetDepthStencilTexture
std::shared_ptr< Texture > GetDepthStencilTexture()
Retrieve the depth+stencil texture, creating one if needed.
Definition:
swapchain_transients_mtl.mm:71
formats.h
impeller
Definition:
allocation.cc:12
impeller::StorageMode::kDevicePrivate
@ kDevicePrivate
impeller::StorageMode::kDeviceTransient
@ kDeviceTransient
impeller::PixelFormat
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
Definition:
formats.h:99
impeller::PixelFormat::kD32FloatS8UInt
@ kD32FloatS8UInt
impeller::TextureType::kTexture2DMultisample
@ kTexture2DMultisample
impeller::TextureType::kTexture2D
@ kTexture2D
impeller::CompressionType::kLossy
@ kLossy
impeller::TextureUsage::kRenderTarget
@ kRenderTarget
impeller::TextureUsage::kShaderRead
@ kShaderRead
impeller::SampleCount::kCount4
@ kCount4
impeller::SampleCount::kCount1
@ kCount1
impeller::TSize
Definition:
size.h:25
impeller::TextureDescriptor
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...
Definition:
texture_descriptor.h:38
impeller::TextureDescriptor::usage
TextureUsageMask usage
Definition:
texture_descriptor.h:44
impeller::TextureDescriptor::compression_type
CompressionType compression_type
Definition:
texture_descriptor.h:46
impeller::TextureDescriptor::type
TextureType type
Definition:
texture_descriptor.h:40
impeller::TextureDescriptor::size
ISize size
Definition:
texture_descriptor.h:42
impeller::TextureDescriptor::storage_mode
StorageMode storage_mode
Definition:
texture_descriptor.h:39
impeller::TextureDescriptor::sample_count
SampleCount sample_count
Definition:
texture_descriptor.h:45
impeller::TextureDescriptor::format
PixelFormat format
Definition:
texture_descriptor.h:41
swapchain_transients_mtl.h
texture_descriptor.h
validation.h
VALIDATION_LOG
#define VALIDATION_LOG
Definition:
validation.h:91
impeller
renderer
backend
metal
swapchain_transients_mtl.mm
Generated by
1.9.1