| 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 "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 multisampled rendering to
23 /// the on-screen surface without requiring an explicit resolve of
24 /// the MSAA color attachment.
25 virtual bool SupportsImplicitResolvingMSAA() const = 0;
26
27 /// @brief Whether the context backend supports binding Shader Storage Buffer
28 /// Objects (SSBOs) to pipelines.
29 virtual bool SupportsSSBO() 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 current
63 /// `RenderPass` attachments. This is supported if the backend can
64 /// guarantee that attachment textures will not be mutated until the
65 /// render pass has fully completed.
66 ///
67 /// This is possible because many mobile graphics cards track
68 /// `RenderPass` attachment state in intermediary tile memory prior to
69 /// Storing the pass in the heap allocated attachments on DRAM.
70 /// Metal's hazard tracking and Vulkan's barriers are granular enough
71 /// to allow for safely accessing attachment textures prior to storage
72 /// in the same `RenderPass`.
73 virtual bool SupportsReadFromResolve() const = 0;
74
75 /// @brief Whether the context backend supports `SamplerAddressMode::Decal`.
76 virtual bool SupportsDecalSamplerAddressMode() const = 0;
77
78 /// @brief Whether the context backend supports allocating
79 /// `StorageMode::kDeviceTransient` (aka "memoryless") textures, which
80 /// are temporary textures kept in tile memory for the duration of the
81 /// `RenderPass` it's attached to.
82 ///
83 /// This feature is especially useful for MSAA and stencils.
84 virtual bool SupportsDeviceTransientTextures() const = 0;
85
86 /// @brief Whether the primitive type TriangleFan is supported by the backend.
87 virtual bool SupportsTriangleFan() const = 0;
88
89 /// @brief Whether primitive restart is supported.
90 virtual bool SupportsPrimitiveRestart() const = 0;
91
92 /// @brief Whether 32-bit values are supported in index buffers used to draw
93 /// primitives.
94 virtual bool Supports32BitPrimitiveIndices() const = 0;
95
96 /// @brief Returns a supported `PixelFormat` for textures that store
97 /// 4-channel colors (red/green/blue/alpha).
98 virtual PixelFormat GetDefaultColorFormat() const = 0;
99
100 /// @brief Returns a supported `PixelFormat` for textures that store stencil
101 /// information. May include a depth channel if a stencil-only format
102 /// is not available.
103 virtual PixelFormat GetDefaultStencilFormat() const = 0;
104
105 /// @brief Returns a supported `PixelFormat` for textures that store both a
106 /// stencil and depth component. This will never return a depth-only
107 /// or stencil-only texture.
108 /// Returns `PixelFormat::kUnknown` if no suitable depth+stencil
109 /// format was found.
110 virtual PixelFormat GetDefaultDepthStencilFormat() const = 0;
111
112 /// @brief Returns the default pixel format for the alpha bitmap glyph atlas.
113 ///
114 /// Some backends may use Red channel while others use grey. This
115 /// should not have any impact
116 virtual PixelFormat GetDefaultGlyphAtlasFormat() const = 0;
117
118 /// @brief Return the maximum size of a render pass attachment.
119 ///
120 /// Note that this may be smaller than the maximum allocatable texture size.
121 virtual ISize GetMaximumRenderPassAttachmentSize() const = 0;
122
123 /// @brief Whether the XR formats are supported on this device.
124 ///
125 /// This is only ever true for iOS and macOS devices. We may need
126 /// to revisit this API when approaching wide gamut rendering for
127 /// Vulkan and GLES.
128 virtual bool SupportsExtendedRangeFormats() const = 0;
129
130 /// @brief The minimum alignment of uniform value offsets in bytes.
131 virtual size_t GetMinimumUniformAlignment() const = 0;
132
133 /// @brief The minimum alignment of storage buffer value offsets in bytes.
134 virtual size_t GetMinimumStorageBufferAlignment() const;
135
136 /// @brief Whether the host buffer should use separate device buffers
137 /// for indexes from other data.
138 virtual bool NeedsPartitionedHostBuffer() const = 0;
139
140 protected:
141 Capabilities();
142
143 Capabilities(const Capabilities&) = delete;
144
145 Capabilities& operator=(const Capabilities&) = delete;
146 };
147
148 class CapabilitiesBuilder {
149 public:
150 CapabilitiesBuilder();
151
152 ~CapabilitiesBuilder();
153
154 CapabilitiesBuilder& SetSupportsOffscreenMSAA(bool value);
155
156 CapabilitiesBuilder& SetSupportsSSBO(bool value);
157
158 CapabilitiesBuilder& SetSupportsTextureToTextureBlits(bool value);
159
160 CapabilitiesBuilder& SetSupportsFramebufferFetch(bool value);
161
162 CapabilitiesBuilder& SetSupportsCompute(bool value);
163
164 CapabilitiesBuilder& SetSupportsComputeSubgroups(bool value);
165
166 CapabilitiesBuilder& SetSupportsReadFromResolve(bool value);
167
168 CapabilitiesBuilder& SetDefaultColorFormat(PixelFormat value);
169
170 CapabilitiesBuilder& SetDefaultStencilFormat(PixelFormat value);
171
172 CapabilitiesBuilder& SetDefaultDepthStencilFormat(PixelFormat value);
173
174 CapabilitiesBuilder& SetSupportsDecalSamplerAddressMode(bool value);
175
176 CapabilitiesBuilder& SetSupportsDeviceTransientTextures(bool value);
177
178 CapabilitiesBuilder& SetSupportsExtendedRangeFormats(bool value);
179
180 CapabilitiesBuilder& SetDefaultGlyphAtlasFormat(PixelFormat value);
181
182 CapabilitiesBuilder& SetSupportsTriangleFan(bool value);
183
184 CapabilitiesBuilder& SetMaximumRenderPassAttachmentSize(ISize size);
185
186 CapabilitiesBuilder& SetMinimumUniformAlignment(size_t value);
187
188 CapabilitiesBuilder& SetNeedsPartitionedHostBuffer(bool value);
189
190 std::unique_ptr<Capabilities> Build();
191
192 private:
193 bool supports_offscreen_msaa_ = false;
194 bool supports_ssbo_ = false;
195 bool supports_texture_to_texture_blits_ = false;
196 bool supports_framebuffer_fetch_ = false;
197 bool supports_compute_ = false;
198 bool supports_compute_subgroups_ = false;
199 bool supports_read_from_resolve_ = false;
200 bool supports_decal_sampler_address_mode_ = false;
201 bool supports_device_transient_textures_ = false;
202 bool supports_triangle_fan_ = false;
203 bool supports_extended_range_formats_ = false;
204 bool needs_partitioned_host_buffer_ = false;
205 std::optional<PixelFormat> default_color_format_ = std::nullopt;
206 std::optional<PixelFormat> default_stencil_format_ = std::nullopt;
207 std::optional<PixelFormat> default_depth_stencil_format_ = std::nullopt;
208 std::optional<PixelFormat> default_glyph_atlas_format_ = std::nullopt;
209 std::optional<ISize> default_maximum_render_pass_attachment_size_ =
210 std::nullopt;
211 size_t minimum_uniform_alignment_ = 256;
212
213 CapabilitiesBuilder(const CapabilitiesBuilder&) = delete;
214
215 CapabilitiesBuilder& operator=(const CapabilitiesBuilder&) = delete;
216 };
217
218 } // namespace impeller
219
220 #endif // FLUTTER_IMPELLER_RENDERER_CAPABILITIES_H_
impeller::CapabilitiesBuilder
Definition: capabilities.h:148
impeller::CapabilitiesBuilder::SetDefaultColorFormat
CapabilitiesBuilder & SetDefaultColorFormat(PixelFormat value)
Definition: capabilities.cc:219
impeller::CapabilitiesBuilder::SetSupportsComputeSubgroups
CapabilitiesBuilder & SetSupportsComputeSubgroups(bool value)
Definition: capabilities.cc:213
impeller::CapabilitiesBuilder::SetMinimumUniformAlignment
CapabilitiesBuilder & SetMinimumUniformAlignment(size_t value)
Definition: capabilities.cc:278
impeller::CapabilitiesBuilder::SetSupportsTextureToTextureBlits
CapabilitiesBuilder & SetSupportsTextureToTextureBlits(bool value)
Definition: capabilities.cc:196
impeller::CapabilitiesBuilder::SetDefaultStencilFormat
CapabilitiesBuilder & SetDefaultStencilFormat(PixelFormat value)
Definition: capabilities.cc:225
impeller::CapabilitiesBuilder::CapabilitiesBuilder
CapabilitiesBuilder()
impeller::CapabilitiesBuilder::SetSupportsDeviceTransientTextures
CapabilitiesBuilder & SetSupportsDeviceTransientTextures(bool value)
Definition: capabilities.cc:249
impeller::CapabilitiesBuilder::SetSupportsTriangleFan
CapabilitiesBuilder & SetSupportsTriangleFan(bool value)
Definition: capabilities.cc:261
impeller::CapabilitiesBuilder::~CapabilitiesBuilder
~CapabilitiesBuilder()
impeller::CapabilitiesBuilder::SetNeedsPartitionedHostBuffer
CapabilitiesBuilder & SetNeedsPartitionedHostBuffer(bool value)
Definition: capabilities.cc:284
impeller::CapabilitiesBuilder::SetSupportsFramebufferFetch
CapabilitiesBuilder & SetSupportsFramebufferFetch(bool value)
Definition: capabilities.cc:202
impeller::CapabilitiesBuilder::SetSupportsDecalSamplerAddressMode
CapabilitiesBuilder & SetSupportsDecalSamplerAddressMode(bool value)
Definition: capabilities.cc:243
impeller::CapabilitiesBuilder::SetSupportsOffscreenMSAA
CapabilitiesBuilder & SetSupportsOffscreenMSAA(bool value)
Definition: capabilities.cc:186
impeller::CapabilitiesBuilder::SetSupportsSSBO
CapabilitiesBuilder & SetSupportsSSBO(bool value)
Definition: capabilities.cc:191
impeller::CapabilitiesBuilder::SetMaximumRenderPassAttachmentSize
CapabilitiesBuilder & SetMaximumRenderPassAttachmentSize(ISize size)
Definition: capabilities.cc:266
impeller::CapabilitiesBuilder::SetSupportsExtendedRangeFormats
CapabilitiesBuilder & SetSupportsExtendedRangeFormats(bool value)
Definition: capabilities.cc:272
impeller::CapabilitiesBuilder::SetDefaultGlyphAtlasFormat
CapabilitiesBuilder & SetDefaultGlyphAtlasFormat(PixelFormat value)
Definition: capabilities.cc:255
impeller::CapabilitiesBuilder::SetSupportsCompute
CapabilitiesBuilder & SetSupportsCompute(bool value)
Definition: capabilities.cc:208
impeller::CapabilitiesBuilder::Build
std::unique_ptr< Capabilities > Build()
Definition: capabilities.cc:290
impeller::CapabilitiesBuilder::SetDefaultDepthStencilFormat
CapabilitiesBuilder & SetDefaultDepthStencilFormat(PixelFormat value)
Definition: capabilities.cc:231
impeller::CapabilitiesBuilder::SetSupportsReadFromResolve
CapabilitiesBuilder & SetSupportsReadFromResolve(bool value)
Definition: capabilities.cc:237
impeller::Capabilities
Definition: capabilities.h:14
impeller::Capabilities::GetDefaultStencilFormat
virtual PixelFormat GetDefaultStencilFormat() const =0
Returns a supported PixelFormat for textures that store stencil information. May include a depth chan...
impeller::Capabilities::GetMinimumUniformAlignment
virtual size_t GetMinimumUniformAlignment() const =0
The minimum alignment of uniform value offsets in bytes.
impeller::Capabilities::Capabilities
Capabilities()
impeller::Capabilities::SupportsOffscreenMSAA
virtual bool SupportsOffscreenMSAA() const =0
Whether the context backend supports attaching offscreen MSAA color/stencil textures.
impeller::Capabilities::SupportsImplicitResolvingMSAA
virtual bool SupportsImplicitResolvingMSAA() const =0
Whether the context backend supports multisampled rendering to the on-screen surface without requirin...
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::SupportsDecalSamplerAddressMode
virtual bool SupportsDecalSamplerAddressMode() const =0
Whether the context backend supports SamplerAddressMode::Decal.
impeller::Capabilities::SupportsReadFromResolve
virtual bool SupportsReadFromResolve() const =0
Whether the context backend supports binding the current RenderPass attachments. This is supported if...
impeller::Capabilities::SupportsTriangleFan
virtual bool SupportsTriangleFan() const =0
Whether the primitive type TriangleFan is supported by the backend.
impeller::Capabilities::SupportsComputeSubgroups
virtual bool SupportsComputeSubgroups() const =0
Whether the context backend supports configuring ComputePass command subgroups.
impeller::Capabilities::NeedsPartitionedHostBuffer
virtual bool NeedsPartitionedHostBuffer() const =0
Whether the host buffer should use separate device buffers for indexes from other data.
impeller::Capabilities::Supports32BitPrimitiveIndices
virtual bool Supports32BitPrimitiveIndices() const =0
Whether 32-bit values are supported in index buffers used to draw primitives.
impeller::Capabilities::Capabilities
Capabilities(const Capabilities &)=delete
impeller::Capabilities::GetDefaultGlyphAtlasFormat
virtual PixelFormat GetDefaultGlyphAtlasFormat() const =0
Returns the default pixel format for the alpha bitmap glyph atlas.
impeller::Capabilities::SupportsPrimitiveRestart
virtual bool SupportsPrimitiveRestart() const =0
Whether primitive restart is supported.
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::~Capabilities
virtual ~Capabilities()
impeller::Capabilities::GetMaximumRenderPassAttachmentSize
virtual ISize GetMaximumRenderPassAttachmentSize() const =0
Return the maximum size of a render pass attachment.
impeller::Capabilities::SupportsDeviceTransientTextures
virtual bool SupportsDeviceTransientTextures() const =0
Whether the context backend supports allocating StorageMode::kDeviceTransient (aka "memoryless") text...
impeller::Capabilities::operator=
Capabilities & operator=(const Capabilities &)=delete
impeller::Capabilities::GetMinimumStorageBufferAlignment
virtual size_t GetMinimumStorageBufferAlignment() const
The minimum alignment of storage buffer value offsets in bytes.
Definition: capabilities.cc:14
impeller::Capabilities::SupportsCompute
virtual bool SupportsCompute() const =0
Whether the context backend supports ComputePass.
impeller::Capabilities::SupportsExtendedRangeFormats
virtual bool SupportsExtendedRangeFormats() const =0
Whether the XR formats are supported on this device.
impeller::Capabilities::SupportsSSBO
virtual bool SupportsSSBO() const =0
Whether the context backend supports binding Shader Storage Buffer Objects (SSBOs) to pipelines.
impeller::Capabilities::GetDefaultDepthStencilFormat
virtual PixelFormat GetDefaultDepthStencilFormat() const =0
Returns a supported PixelFormat for textures that store both a stencil and depth component....
impeller::Capabilities::SupportsTextureToTextureBlits
virtual bool SupportsTextureToTextureBlits() const =0
Whether the context backend supports blitting from one texture region to another texture region (via ...
formats.h
value
int32_t value
Definition: dl_golden_unittests.cc:459
impeller
Definition: allocation.cc:12
impeller::PixelFormat
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
Definition: formats.h:99
impeller::TSize
Definition: size.h:25