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