Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
Loading...
Searching...
No Matches
formats.cc
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/core/formats.h
"
6
7
#include <format>
8
#include <sstream>
9
10
#include "
impeller/base/validation.h
"
11
#include "
impeller/core/texture.h
"
12
13
namespace
impeller
{
14
15
constexpr
bool
StoreActionNeedsResolveTexture
(
StoreAction
action
) {
16
switch
(
action
) {
17
case
StoreAction::kDontCare
:
18
case
StoreAction::kStore
:
19
return
false
;
20
case
StoreAction::kMultisampleResolve
:
21
case
StoreAction::kStoreAndMultisampleResolve
:
22
return
true
;
23
}
24
}
25
26
bool
Attachment::IsValid
()
const
{
27
if
(!
texture
|| !
texture
->IsValid()) {
28
VALIDATION_LOG
<<
"Attachment has no texture."
;
29
return
false
;
30
}
31
32
const
TextureDescriptor
& desc =
texture
->GetTextureDescriptor();
33
if
(
mip_level
>= desc.
mip_count
) {
34
VALIDATION_LOG
<<
"Attachment mip_level "
<<
mip_level
35
<<
" is out of range; the texture has "
<< desc.
mip_count
36
<<
" mip levels."
;
37
return
false
;
38
}
39
const
uint32_t slice_count = desc.
type
==
TextureType::kTextureCube
? 6u : 1u;
40
if
(
slice
>= slice_count) {
41
VALIDATION_LOG
<<
"Attachment slice "
<<
slice
42
<<
" is out of range for the texture type."
;
43
return
false
;
44
}
45
46
if
(
StoreActionNeedsResolveTexture
(
store_action
)) {
47
if
(!
resolve_texture
|| !
resolve_texture
->IsValid()) {
48
VALIDATION_LOG
<<
"Store action needs resolve but no valid resolve "
49
"texture specified."
;
50
return
false
;
51
}
52
}
53
54
if
(
resolve_texture
) {
55
if
(
store_action
!=
StoreAction::kMultisampleResolve
&&
56
store_action
!=
StoreAction::kStoreAndMultisampleResolve
) {
57
VALIDATION_LOG
<<
"A resolve texture was specified, but the store action "
58
"doesn't include multisample resolve."
;
59
return
false
;
60
}
61
62
if
(
texture
->GetTextureDescriptor().storage_mode ==
63
StorageMode::kDeviceTransient
&&
64
store_action
==
StoreAction::kStoreAndMultisampleResolve
) {
65
VALIDATION_LOG
66
<<
"The multisample texture cannot be transient when "
67
"specifying the StoreAndMultisampleResolve StoreAction."
;
68
}
69
}
70
71
auto
storage_mode =
resolve_texture
72
?
resolve_texture
->GetTextureDescriptor().storage_mode
73
:
texture
->GetTextureDescriptor().storage_mode;
74
75
if
(storage_mode ==
StorageMode::kDeviceTransient
) {
76
if
(
load_action
==
LoadAction::kLoad
) {
77
VALIDATION_LOG
<<
"The LoadAction cannot be Load when attaching a device "
78
"transient "
+
79
std::string(
resolve_texture
?
"resolve texture."
80
:
"texture."
);
81
return
false
;
82
}
83
if
(
store_action
!=
StoreAction::kDontCare
) {
84
VALIDATION_LOG
<<
"The StoreAction must be DontCare when attaching a "
85
"device transient "
+
86
std::string(
resolve_texture
?
"resolve texture."
87
:
"texture."
);
88
return
false
;
89
}
90
}
91
92
return
true
;
93
}
94
95
std::string
TextureUsageMaskToString
(
TextureUsageMask
mask) {
96
std::vector<TextureUsage> usages;
97
if
(mask &
TextureUsage::kShaderRead
) {
98
usages.push_back(
TextureUsage::kShaderRead
);
99
}
100
if
(mask &
TextureUsage::kShaderWrite
) {
101
usages.push_back(
TextureUsage::kShaderWrite
);
102
}
103
if
(mask &
TextureUsage::kRenderTarget
) {
104
usages.push_back(
TextureUsage::kRenderTarget
);
105
}
106
std::stringstream stream;
107
stream <<
"{ "
;
108
for
(
size_t
i
= 0;
i
< usages.size();
i
++) {
109
stream <<
TextureUsageToString
(usages[
i
]);
110
if
(
i
!= usages.size() - 1u) {
111
stream <<
", "
;
112
}
113
}
114
stream <<
" }"
;
115
return
stream.str();
116
}
117
118
std::string
AttachmentToString
(
const
Attachment
& attachment) {
119
std::stringstream stream;
120
if
(attachment.
texture
) {
121
stream <<
"Texture=("
122
<<
TextureDescriptorToString
(
123
attachment.
texture
->GetTextureDescriptor())
124
<<
"),"
;
125
}
126
if
(attachment.
resolve_texture
) {
127
stream <<
"ResolveTexture=("
128
<<
TextureDescriptorToString
(
129
attachment.
resolve_texture
->GetTextureDescriptor())
130
<<
"),"
;
131
}
132
stream <<
"LoadAction="
<<
LoadActionToString
(attachment.
load_action
) <<
","
;
133
stream <<
"StoreAction="
<<
StoreActionToString
(attachment.
store_action
);
134
return
stream.str();
135
}
136
137
std::string
ColorAttachmentToString
(
const
ColorAttachment
& color) {
138
std::stringstream stream;
139
stream <<
AttachmentToString
(color) <<
","
;
140
stream <<
"ClearColor="
<< color.
clear_color
;
141
return
stream.str();
142
}
143
144
std::string
DepthAttachmentToString
(
const
DepthAttachment
& depth) {
145
std::stringstream stream;
146
stream <<
AttachmentToString
(depth) <<
","
;
147
stream << std::format(
"ClearDepth={:.2f}"
, depth.
clear_depth
);
148
return
stream.str();
149
}
150
151
std::string
StencilAttachmentToString
(
const
StencilAttachment
& stencil) {
152
std::stringstream stream;
153
stream <<
AttachmentToString
(stencil) <<
","
;
154
stream << std::format(
"ClearStencil={}"
, stencil.
clear_stencil
);
155
return
stream.str();
156
}
157
158
}
// namespace impeller
i
int i
Definition
fl_socket_accessible.cc:18
formats.h
texture.h
action
int action
Definition
keyboard_key_handler_unittests.cc:116
impeller
Definition
texture.h:16
impeller::TextureDescriptorToString
std::string TextureDescriptorToString(const TextureDescriptor &desc)
Definition
texture_descriptor.cc:11
impeller::DepthAttachmentToString
std::string DepthAttachmentToString(const DepthAttachment &depth)
Definition
formats.cc:144
impeller::ColorAttachmentToString
std::string ColorAttachmentToString(const ColorAttachment &color)
Definition
formats.cc:137
impeller::StencilAttachmentToString
std::string StencilAttachmentToString(const StencilAttachment &stencil)
Definition
formats.cc:151
impeller::TextureUsageMaskToString
std::string TextureUsageMaskToString(TextureUsageMask mask)
Definition
formats.cc:95
impeller::StorageMode::kDeviceTransient
@ kDeviceTransient
impeller::AttachmentToString
std::string AttachmentToString(const Attachment &attachment)
Definition
formats.cc:118
impeller::LoadActionToString
constexpr const char * LoadActionToString(LoadAction action)
Definition
formats.h:403
impeller::StoreActionToString
constexpr const char * StoreActionToString(StoreAction action)
Definition
formats.h:414
impeller::TextureType::kTextureCube
@ kTextureCube
impeller::LoadAction::kLoad
@ kLoad
impeller::StoreAction
StoreAction
Definition
formats.h:396
impeller::StoreAction::kStore
@ kStore
impeller::StoreAction::kDontCare
@ kDontCare
impeller::StoreAction::kStoreAndMultisampleResolve
@ kStoreAndMultisampleResolve
impeller::StoreAction::kMultisampleResolve
@ kMultisampleResolve
impeller::StoreActionNeedsResolveTexture
constexpr bool StoreActionNeedsResolveTexture(StoreAction action)
Definition
formats.cc:15
impeller::TextureUsageToString
constexpr const char * TextureUsageToString(TextureUsage usage)
Definition
formats.h:498
impeller::TextureUsage::kRenderTarget
@ kRenderTarget
impeller::TextureUsage::kShaderWrite
@ kShaderWrite
impeller::TextureUsage::kShaderRead
@ kShaderRead
impeller::Attachment
Definition
formats.h:908
impeller::Attachment::mip_level
uint32_t mip_level
Definition
formats.h:915
impeller::Attachment::resolve_texture
std::shared_ptr< Texture > resolve_texture
Definition
formats.h:910
impeller::Attachment::IsValid
bool IsValid() const
Definition
formats.cc:26
impeller::Attachment::load_action
LoadAction load_action
Definition
formats.h:911
impeller::Attachment::texture
std::shared_ptr< Texture > texture
Definition
formats.h:909
impeller::Attachment::slice
uint32_t slice
Definition
formats.h:918
impeller::Attachment::store_action
StoreAction store_action
Definition
formats.h:912
impeller::ColorAttachment
Definition
formats.h:923
impeller::ColorAttachment::clear_color
Color clear_color
Definition
formats.h:924
impeller::DepthAttachment
Definition
formats.h:927
impeller::DepthAttachment::clear_depth
double clear_depth
Definition
formats.h:928
impeller::Mask< TextureUsage >
impeller::StencilAttachment
Definition
formats.h:931
impeller::StencilAttachment::clear_stencil
uint32_t clear_stencil
Definition
formats.h:932
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::type
TextureType type
Definition
texture_descriptor.h:40
impeller::TextureDescriptor::mip_count
size_t mip_count
Definition
texture_descriptor.h:43
validation.h
VALIDATION_LOG
#define VALIDATION_LOG
Definition
validation.h:91
impeller
core
formats.cc
Generated on Mon Jun 15 2026 06:26:21 for Flutter Engine Uber Docs by
1.9.8