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
6
7#include <format>
8#include <sstream>
9
12
13namespace impeller {
14
16 switch (action) {
19 return false;
22 return true;
23 }
24}
25
26bool 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
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) {
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 ==
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) {
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 }
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
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
118std::string AttachmentToString(const Attachment& attachment) {
119 std::stringstream stream;
120 if (attachment.texture) {
121 stream << "Texture=("
123 attachment.texture->GetTextureDescriptor())
124 << "),";
125 }
126 if (attachment.resolve_texture) {
127 stream << "ResolveTexture=("
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
137std::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
144std::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
151std::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
std::string TextureDescriptorToString(const TextureDescriptor &desc)
std::string DepthAttachmentToString(const DepthAttachment &depth)
Definition formats.cc:144
std::string ColorAttachmentToString(const ColorAttachment &color)
Definition formats.cc:137
std::string StencilAttachmentToString(const StencilAttachment &stencil)
Definition formats.cc:151
std::string TextureUsageMaskToString(TextureUsageMask mask)
Definition formats.cc:95
std::string AttachmentToString(const Attachment &attachment)
Definition formats.cc:118
constexpr const char * LoadActionToString(LoadAction action)
Definition formats.h:403
constexpr const char * StoreActionToString(StoreAction action)
Definition formats.h:414
constexpr bool StoreActionNeedsResolveTexture(StoreAction action)
Definition formats.cc:15
constexpr const char * TextureUsageToString(TextureUsage usage)
Definition formats.h:498
std::shared_ptr< Texture > resolve_texture
Definition formats.h:910
bool IsValid() const
Definition formats.cc:26
LoadAction load_action
Definition formats.h:911
std::shared_ptr< Texture > texture
Definition formats.h:909
StoreAction store_action
Definition formats.h:912
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...
#define VALIDATION_LOG
Definition validation.h:91