Flutter Impeller
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 <sstream>
8 
11 #include "impeller/core/texture.h"
12 
13 namespace impeller {
14 
16  switch (action) {
19  return false;
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 
33  if (!resolve_texture || !resolve_texture->IsValid()) {
34  VALIDATION_LOG << "Store action needs resolve but no valid resolve "
35  "texture specified.";
36  return false;
37  }
38  }
39 
40  if (resolve_texture) {
43  VALIDATION_LOG << "A resolve texture was specified, but the store action "
44  "doesn't include multisample resolve.";
45  return false;
46  }
47 
48  if (texture->GetTextureDescriptor().storage_mode ==
52  << "The multisample texture cannot be transient when "
53  "specifying the StoreAndMultisampleResolve StoreAction.";
54  }
55  }
56 
57  auto storage_mode = resolve_texture
58  ? resolve_texture->GetTextureDescriptor().storage_mode
59  : texture->GetTextureDescriptor().storage_mode;
60 
61  if (storage_mode == StorageMode::kDeviceTransient) {
63  VALIDATION_LOG << "The LoadAction cannot be Load when attaching a device "
64  "transient " +
65  std::string(resolve_texture ? "resolve texture."
66  : "texture.");
67  return false;
68  }
70  VALIDATION_LOG << "The StoreAction must be DontCare when attaching a "
71  "device transient " +
72  std::string(resolve_texture ? "resolve texture."
73  : "texture.");
74  return false;
75  }
76  }
77 
78  return true;
79 }
80 
82  std::vector<TextureUsage> usages;
83  if (mask & TextureUsage::kShaderRead) {
84  usages.push_back(TextureUsage::kShaderRead);
85  }
86  if (mask & TextureUsage::kShaderWrite) {
87  usages.push_back(TextureUsage::kShaderWrite);
88  }
89  if (mask & TextureUsage::kRenderTarget) {
90  usages.push_back(TextureUsage::kRenderTarget);
91  }
92  std::stringstream stream;
93  stream << "{ ";
94  for (size_t i = 0; i < usages.size(); i++) {
95  stream << TextureUsageToString(usages[i]);
96  if (i != usages.size() - 1u) {
97  stream << ", ";
98  }
99  }
100  stream << " }";
101  return stream.str();
102 }
103 
104 std::string AttachmentToString(const Attachment& attachment) {
105  std::stringstream stream;
106  if (attachment.texture) {
107  stream << "Texture=("
109  attachment.texture->GetTextureDescriptor())
110  << "),";
111  }
112  if (attachment.resolve_texture) {
113  stream << "ResolveTexture=("
115  attachment.resolve_texture->GetTextureDescriptor())
116  << "),";
117  }
118  stream << "LoadAction=" << LoadActionToString(attachment.load_action) << ",";
119  stream << "StoreAction=" << StoreActionToString(attachment.store_action);
120  return stream.str();
121 }
122 
123 std::string ColorAttachmentToString(const ColorAttachment& color) {
124  std::stringstream stream;
125  stream << AttachmentToString(color) << ",";
126  stream << "ClearColor=(" << ColorToString(color.clear_color) << ")";
127  return stream.str();
128 }
129 
130 std::string DepthAttachmentToString(const DepthAttachment& depth) {
131  std::stringstream stream;
132  stream << AttachmentToString(depth) << ",";
133  stream << "ClearDepth=" << SPrintF("%.2f", depth.clear_depth);
134  return stream.str();
135 }
136 
137 std::string StencilAttachmentToString(const StencilAttachment& stencil) {
138  std::stringstream stream;
139  stream << AttachmentToString(stencil) << ",";
140  stream << "ClearStencil=" << stencil.clear_stencil;
141  return stream.str();
142 }
143 
144 } // namespace impeller
impeller::StoreAction::kMultisampleResolve
@ kMultisampleResolve
impeller::LoadAction::kLoad
@ kLoad
impeller::TextureUsage::kShaderWrite
@ kShaderWrite
impeller::StoreAction
StoreAction
Definition: formats.h:209
impeller::StoreAction::kStoreAndMultisampleResolve
@ kStoreAndMultisampleResolve
impeller::ColorToString
std::string ColorToString(const Color &color)
Definition: color.cc:410
impeller::Attachment::store_action
StoreAction store_action
Definition: formats.h:642
impeller::ColorAttachment
Definition: formats.h:647
impeller::LoadActionToString
constexpr const char * LoadActionToString(LoadAction action)
Definition: formats.h:216
formats.h
impeller::StoreAction::kDontCare
@ kDontCare
impeller::TextureDescriptorToString
std::string TextureDescriptorToString(const TextureDescriptor &desc)
Definition: texture_descriptor.cc:11
impeller::TextureUsage::kRenderTarget
@ kRenderTarget
validation.h
impeller::Mask< TextureUsage >
impeller::StencilAttachment
Definition: formats.h:655
impeller::StorageMode::kDeviceTransient
@ kDeviceTransient
impeller::ColorAttachment::clear_color
Color clear_color
Definition: formats.h:648
impeller::Attachment::texture
std::shared_ptr< Texture > texture
Definition: formats.h:639
impeller::SPrintF
std::string SPrintF(const char *format,...)
Definition: strings.cc:12
impeller::AttachmentToString
std::string AttachmentToString(const Attachment &attachment)
Definition: formats.cc:104
impeller::ColorAttachmentToString
std::string ColorAttachmentToString(const ColorAttachment &color)
Definition: formats.cc:123
impeller::Attachment
Definition: formats.h:638
impeller::StoreAction::kStore
@ kStore
impeller::StencilAttachment::clear_stencil
uint32_t clear_stencil
Definition: formats.h:656
strings.h
impeller::TextureUsageMaskToString
std::string TextureUsageMaskToString(TextureUsageMask mask)
Definition: formats.cc:81
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:73
impeller::Attachment::resolve_texture
std::shared_ptr< Texture > resolve_texture
Definition: formats.h:640
impeller::DepthAttachmentToString
std::string DepthAttachmentToString(const DepthAttachment &depth)
Definition: formats.cc:130
impeller::Attachment::load_action
LoadAction load_action
Definition: formats.h:641
impeller::TextureUsage::kShaderRead
@ kShaderRead
texture.h
impeller::Attachment::IsValid
bool IsValid() const
Definition: formats.cc:26
impeller::DepthAttachment::clear_depth
double clear_depth
Definition: formats.h:652
impeller::StoreActionToString
constexpr const char * StoreActionToString(StoreAction action)
Definition: formats.h:227
impeller::DepthAttachment
Definition: formats.h:651
impeller::StoreActionNeedsResolveTexture
constexpr bool StoreActionNeedsResolveTexture(StoreAction action)
Definition: formats.cc:15
impeller::TextureUsageToString
constexpr const char * TextureUsageToString(TextureUsage usage)
Definition: formats.h:311
impeller
Definition: aiks_blur_unittests.cc:20
impeller::StencilAttachmentToString
std::string StencilAttachmentToString(const StencilAttachment &stencil)
Definition: formats.cc:137