Flutter Impeller
capabilities.h
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 #pragma once
6 
7 #include <memory>
8 
9 #include "flutter/fml/macros.h"
10 #include "impeller/core/formats.h"
11 
12 namespace impeller {
13 
14 class Capabilities {
15  public:
16  virtual ~Capabilities();
17 
18  /// @brief Whether the context backend supports attaching offscreen MSAA
19  /// color/stencil textures.
20  virtual bool SupportsOffscreenMSAA() const = 0;
21 
22  /// @brief Whether the context backend supports binding Shader Storage Buffer
23  /// Objects (SSBOs) to pipelines.
24  virtual bool SupportsSSBO() const = 0;
25 
26  /// @brief Whether the context backend supports blitting from a given
27  /// `DeviceBuffer` view to a texture region (via the relevant
28  /// `BlitPass::AddCopy` overloads).
29  virtual bool SupportsBufferToTextureBlits() const = 0;
30 
31  /// @brief Whether the context backend supports blitting from one texture
32  /// region to another texture region (via the relevant
33  /// `BlitPass::AddCopy` overloads).
34  virtual bool SupportsTextureToTextureBlits() const = 0;
35 
36  /// @brief Whether the context backend is able to support pipelines with
37  /// shaders that read from the framebuffer (i.e. pixels that have been
38  /// written by previous draw calls in the current render pass).
39  ///
40  /// Example of reading from the first color attachment in a GLSL
41  /// shader:
42  /// ```
43  /// uniform subpassInput subpass_input;
44  ///
45  /// out vec4 frag_color;
46  ///
47  /// void main() {
48  /// vec4 color = subpassLoad(subpass_input);
49  /// // Invert the colors drawn to the framebuffer.
50  /// frag_color = vec4(vec3(1) - color.rgb, color.a);
51  /// }
52  /// ```
53  virtual bool SupportsFramebufferFetch() const = 0;
54 
55  /// @brief Whether the context backend supports `ComputePass`.
56  virtual bool SupportsCompute() const = 0;
57 
58  /// @brief Whether the context backend supports configuring `ComputePass`
59  /// command subgroups.
60  virtual bool SupportsComputeSubgroups() const = 0;
61 
62  /// @brief Whether the context backend supports binding the on-screen surface
63  /// texture for shader reading.
64  virtual bool SupportsReadFromOnscreenTexture() const = 0;
65 
66  /// @brief Whether the context backend supports binding the current
67  /// `RenderPass` attachments. This is supported if the backend can
68  /// guarantee that attachment textures will not be mutated until the
69  /// render pass has fully completed.
70  ///
71  /// This is possible because many mobile graphics cards track
72  /// `RenderPass` attachment state in intermediary tile memory prior to
73  /// Storing the pass in the heap allocated attachments on DRAM.
74  /// Metal's hazard tracking and Vulkan's barriers are granular enough
75  /// to allow for safely accessing attachment textures prior to storage
76  /// in the same `RenderPass`.
77  virtual bool SupportsReadFromResolve() const = 0;
78 
79  /// @brief Whether the context backend supports `SamplerAddressMode::Decal`.
80  virtual bool SupportsDecalSamplerAddressMode() const = 0;
81 
82  /// @brief Whether the context backend supports allocating
83  /// `StorageMode::kDeviceTransient` (aka "memoryless") textures, which
84  /// are temporary textures kept in tile memory for the duration of the
85  /// `RenderPass` it's attached to.
86  ///
87  /// This feature is especially useful for MSAA and stencils.
88  virtual bool SupportsDeviceTransientTextures() const = 0;
89 
90  /// @brief Returns a supported `PixelFormat` for textures that store
91  /// 4-channel colors (red/green/blue/alpha).
92  virtual PixelFormat GetDefaultColorFormat() const = 0;
93 
94  /// @brief Returns a supported `PixelFormat` for textures that store stencil
95  /// information. May include a depth channel if a stencil-only format
96  /// is not available.
97  virtual PixelFormat GetDefaultStencilFormat() const = 0;
98 
99  /// @brief Returns a supported `PixelFormat` for textures that store both a
100  /// stencil and depth component. This will never return a depth-only
101  /// or stencil-only texture.
102  /// Returns `PixelFormat::kUnknown` if no suitable depth+stencil
103  /// format was found.
104  virtual PixelFormat GetDefaultDepthStencilFormat() const = 0;
105 
106  protected:
107  Capabilities();
108 
110 };
111 
113  public:
115 
117 
119 
121 
123 
125 
127 
129 
131 
133 
135 
137 
139 
141 
143 
145 
146  std::unique_ptr<Capabilities> Build();
147 
148  private:
149  bool supports_offscreen_msaa_ = false;
150  bool supports_ssbo_ = false;
151  bool supports_buffer_to_texture_blits_ = false;
152  bool supports_texture_to_texture_blits_ = false;
153  bool supports_framebuffer_fetch_ = false;
154  bool supports_compute_ = false;
155  bool supports_compute_subgroups_ = false;
156  bool supports_read_from_onscreen_texture_ = false;
157  bool supports_read_from_resolve_ = false;
158  bool supports_decal_sampler_address_mode_ = false;
159  bool supports_device_transient_textures_ = false;
160  std::optional<PixelFormat> default_color_format_ = std::nullopt;
161  std::optional<PixelFormat> default_stencil_format_ = std::nullopt;
162  std::optional<PixelFormat> default_depth_stencil_format_ = std::nullopt;
163 
164  FML_DISALLOW_COPY_AND_ASSIGN(CapabilitiesBuilder);
165 };
166 
167 } // namespace impeller
impeller::CapabilitiesBuilder::CapabilitiesBuilder
CapabilitiesBuilder()
impeller::CapabilitiesBuilder::Build
std::unique_ptr< Capabilities > Build()
Definition: capabilities.cc:220
impeller::Capabilities::SupportsReadFromResolve
virtual bool SupportsReadFromResolve() const =0
Whether the context backend supports binding the current RenderPass attachments. This is supported if...
impeller::Capabilities::SupportsOffscreenMSAA
virtual bool SupportsOffscreenMSAA() const =0
Whether the context backend supports attaching offscreen MSAA color/stencil textures.
impeller::Capabilities::SupportsDeviceTransientTextures
virtual bool SupportsDeviceTransientTextures() const =0
Whether the context backend supports allocating StorageMode::kDeviceTransient (aka "memoryless") text...
formats.h
impeller::CapabilitiesBuilder
Definition: capabilities.h:112
impeller::Capabilities
Definition: capabilities.h:14
impeller::CapabilitiesBuilder::SetSupportsSSBO
CapabilitiesBuilder & SetSupportsSSBO(bool value)
Definition: capabilities.cc:144
impeller::CapabilitiesBuilder::SetSupportsCompute
CapabilitiesBuilder & SetSupportsCompute(bool value)
Definition: capabilities.cc:167
impeller::CapabilitiesBuilder::SetDefaultDepthStencilFormat
CapabilitiesBuilder & SetDefaultDepthStencilFormat(PixelFormat value)
Definition: capabilities.cc:202
impeller::CapabilitiesBuilder::SetSupportsFramebufferFetch
CapabilitiesBuilder & SetSupportsFramebufferFetch(bool value)
Definition: capabilities.cc:161
impeller::CapabilitiesBuilder::~CapabilitiesBuilder
~CapabilitiesBuilder()
impeller::CapabilitiesBuilder::SetSupportsComputeSubgroups
CapabilitiesBuilder & SetSupportsComputeSubgroups(bool value)
Definition: capabilities.cc:172
impeller::Capabilities::SupportsReadFromOnscreenTexture
virtual bool SupportsReadFromOnscreenTexture() const =0
Whether the context backend supports binding the on-screen surface texture for shader reading.
impeller::Capabilities::SupportsBufferToTextureBlits
virtual bool SupportsBufferToTextureBlits() const =0
Whether the context backend supports blitting from a given DeviceBuffer view to a texture region (via...
impeller::Capabilities::Capabilities
Capabilities()
impeller::CapabilitiesBuilder::SetSupportsTextureToTextureBlits
CapabilitiesBuilder & SetSupportsTextureToTextureBlits(bool value)
Definition: capabilities.cc:155
impeller::Capabilities::FML_DISALLOW_COPY_AND_ASSIGN
FML_DISALLOW_COPY_AND_ASSIGN(Capabilities)
impeller::Capabilities::GetDefaultStencilFormat
virtual PixelFormat GetDefaultStencilFormat() const =0
Returns a supported PixelFormat for textures that store stencil information. May include a depth chan...
impeller::CapabilitiesBuilder::SetDefaultColorFormat
CapabilitiesBuilder & SetDefaultColorFormat(PixelFormat value)
Definition: capabilities.cc:190
impeller::CapabilitiesBuilder::SetDefaultStencilFormat
CapabilitiesBuilder & SetDefaultStencilFormat(PixelFormat value)
Definition: capabilities.cc:196
impeller::CapabilitiesBuilder::SetSupportsBufferToTextureBlits
CapabilitiesBuilder & SetSupportsBufferToTextureBlits(bool value)
Definition: capabilities.cc:149
impeller::Capabilities::~Capabilities
virtual ~Capabilities()
impeller::CapabilitiesBuilder::SetSupportsDecalSamplerAddressMode
CapabilitiesBuilder & SetSupportsDecalSamplerAddressMode(bool value)
Definition: capabilities.cc:208
impeller::Capabilities::SupportsComputeSubgroups
virtual bool SupportsComputeSubgroups() const =0
Whether the context backend supports configuring ComputePass command subgroups.
impeller::CapabilitiesBuilder::SetSupportsDeviceTransientTextures
CapabilitiesBuilder & SetSupportsDeviceTransientTextures(bool value)
Definition: capabilities.cc:214
impeller::PixelFormat
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
Definition: formats.h:94
impeller::Capabilities::GetDefaultColorFormat
virtual PixelFormat GetDefaultColorFormat() const =0
Returns a supported PixelFormat for textures that store 4-channel colors (red/green/blue/alpha).
impeller::Capabilities::SupportsDecalSamplerAddressMode
virtual bool SupportsDecalSamplerAddressMode() const =0
Whether the context backend supports SamplerAddressMode::Decal.
impeller::Capabilities::SupportsFramebufferFetch
virtual bool SupportsFramebufferFetch() const =0
Whether the context backend is able to support pipelines with shaders that read from the framebuffer ...
impeller::CapabilitiesBuilder::SetSupportsReadFromOnscreenTexture
CapabilitiesBuilder & SetSupportsReadFromOnscreenTexture(bool value)
Definition: capabilities.cc:178
impeller::Capabilities::SupportsSSBO
virtual bool SupportsSSBO() const =0
Whether the context backend supports binding Shader Storage Buffer Objects (SSBOs) to pipelines.
impeller
Definition: aiks_context.cc:10
impeller::CapabilitiesBuilder::SetSupportsReadFromResolve
CapabilitiesBuilder & SetSupportsReadFromResolve(bool value)
Definition: capabilities.cc:184
impeller::Capabilities::SupportsTextureToTextureBlits
virtual bool SupportsTextureToTextureBlits() const =0
Whether the context backend supports blitting from one texture region to another texture region (via ...
impeller::CapabilitiesBuilder::SetSupportsOffscreenMSAA
CapabilitiesBuilder & SetSupportsOffscreenMSAA(bool value)
Definition: capabilities.cc:139
impeller::Capabilities::GetDefaultDepthStencilFormat
virtual PixelFormat GetDefaultDepthStencilFormat() const =0
Returns a supported PixelFormat for textures that store both a stencil and depth component....
impeller::Capabilities::SupportsCompute
virtual bool SupportsCompute() const =0
Whether the context backend supports ComputePass.