| Flutter Impeller |

capabilities.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
5 #include "impeller/renderer/capabilities.h"
6 #include "impeller/core/formats.h"
7
8 namespace impeller {
9
10 Capabilities::Capabilities() = default;
11
12 Capabilities::~Capabilities() = default;
13
14 class StandardCapabilities final : public Capabilities {
15 public:
16 // |Capabilities|
17 ~StandardCapabilities() override = default;
18
19 // |Capabilities|
20 bool SupportsOffscreenMSAA() const override {
21 return supports_offscreen_msaa_;
22 }
23
24 // |Capabilities|
25 bool SupportsImplicitResolvingMSAA() const override { return false; }
26
27 // |Capabilities|
28 bool SupportsSSBO() const override { return supports_ssbo_; }
29
30 // |Capabilities|
31 bool SupportsTextureToTextureBlits() const override {
32 return supports_texture_to_texture_blits_;
33 }
34
35 // |Capabilities|
36 bool SupportsFramebufferFetch() const override {
37 return supports_framebuffer_fetch_;
38 }
39
40 // |Capabilities|
41 bool SupportsCompute() const override { return supports_compute_; }
42
43 // |Capabilities|
44 bool SupportsComputeSubgroups() const override {
45 return supports_compute_subgroups_;
46 }
47
48 // |Capabilities|
49 bool SupportsReadFromResolve() const override {
50 return supports_read_from_resolve_;
51 }
52
53 // |Capabilities|
54 bool SupportsDecalSamplerAddressMode() const override {
55 return supports_decal_sampler_address_mode_;
56 }
57
58 // |Capabilities|
59 bool SupportsTriangleFan() const override { return supports_triangle_fan_; }
60
61 // |Capabilities|
62 PixelFormat GetDefaultColorFormat() const override {
63 return default_color_format_;
64 }
65
66 // |Capabilities|
67 PixelFormat GetDefaultStencilFormat() const override {
68 return default_stencil_format_;
69 }
70
71 // |Capabilities|
72 PixelFormat GetDefaultDepthStencilFormat() const override {
73 return default_depth_stencil_format_;
74 }
75
76 // |Capabilities|
77 bool SupportsDeviceTransientTextures() const override {
78 return supports_device_transient_textures_;
79 }
80
81 // |Capabilities|
82 PixelFormat GetDefaultGlyphAtlasFormat() const override {
83 return default_glyph_atlas_format_;
84 }
85
86 // |Capabilities|
87 ISize GetMaximumRenderPassAttachmentSize() const override {
88 return default_maximum_render_pass_attachment_size_;
89 }
90
91 // |Capabilities|
92 bool SupportsPrimitiveRestart() const override { return true; }
93
94 // |Capabilities|
95 bool SupportsExtendedRangeFormats() const override {
96 return supports_extended_range_formats_;
97 }
98
99 // |Capabilities|
100 size_t GetMinimumUniformAlignment() const override {
101 return minimum_uniform_alignment_;
102 }
103
104 private:
105 StandardCapabilities(bool supports_offscreen_msaa,
106 bool supports_ssbo,
107 bool supports_texture_to_texture_blits,
108 bool supports_framebuffer_fetch,
109 bool supports_compute,
110 bool supports_compute_subgroups,
111 bool supports_read_from_resolve,
112 bool supports_decal_sampler_address_mode,
113 bool supports_device_transient_textures,
114 bool supports_triangle_fan,
115 bool supports_extended_range_formats,
116 PixelFormat default_color_format,
117 PixelFormat default_stencil_format,
118 PixelFormat default_depth_stencil_format,
119 PixelFormat default_glyph_atlas_format,
120 ISize default_maximum_render_pass_attachment_size,
121 size_t minimum_uniform_alignment)
122 : supports_offscreen_msaa_(supports_offscreen_msaa),
123 supports_ssbo_(supports_ssbo),
124 supports_texture_to_texture_blits_(supports_texture_to_texture_blits),
125 supports_framebuffer_fetch_(supports_framebuffer_fetch),
126 supports_compute_(supports_compute),
127 supports_compute_subgroups_(supports_compute_subgroups),
128 supports_read_from_resolve_(supports_read_from_resolve),
129 supports_decal_sampler_address_mode_(
130 supports_decal_sampler_address_mode),
131 supports_device_transient_textures_(supports_device_transient_textures),
132 supports_triangle_fan_(supports_triangle_fan),
133 supports_extended_range_formats_(supports_extended_range_formats),
134 default_color_format_(default_color_format),
135 default_stencil_format_(default_stencil_format),
136 default_depth_stencil_format_(default_depth_stencil_format),
137 default_glyph_atlas_format_(default_glyph_atlas_format),
138 default_maximum_render_pass_attachment_size_(
139 default_maximum_render_pass_attachment_size),
140 minimum_uniform_alignment_(minimum_uniform_alignment) {}
141
142 friend class CapabilitiesBuilder;
143
144 bool supports_offscreen_msaa_ = false;
145 bool supports_ssbo_ = false;
146 bool supports_texture_to_texture_blits_ = false;
147 bool supports_framebuffer_fetch_ = false;
148 bool supports_compute_ = false;
149 bool supports_compute_subgroups_ = false;
150 bool supports_read_from_resolve_ = false;
151 bool supports_decal_sampler_address_mode_ = false;
152 bool supports_device_transient_textures_ = false;
153 bool supports_triangle_fan_ = false;
154 bool supports_extended_range_formats_ = false;
155 PixelFormat default_color_format_ = PixelFormat::kUnknown;
156 PixelFormat default_stencil_format_ = PixelFormat::kUnknown;
157 PixelFormat default_depth_stencil_format_ = PixelFormat::kUnknown;
158 PixelFormat default_glyph_atlas_format_ = PixelFormat::kUnknown;
159 ISize default_maximum_render_pass_attachment_size_ = ISize(1, 1);
160 size_t minimum_uniform_alignment_ = 256;
161
162 StandardCapabilities(const StandardCapabilities&) = delete;
163
164 StandardCapabilities& operator=(const StandardCapabilities&) = delete;
165 };
166
167 CapabilitiesBuilder::CapabilitiesBuilder() = default;
168
169 CapabilitiesBuilder::~CapabilitiesBuilder() = default;
170
171 CapabilitiesBuilder& CapabilitiesBuilder::SetSupportsOffscreenMSAA(bool value) {
172 supports_offscreen_msaa_ = value;
173 return *this;
174 }
175
176 CapabilitiesBuilder& CapabilitiesBuilder::SetSupportsSSBO(bool value) {
177 supports_ssbo_ = value;
178 return *this;
179 }
180
181 CapabilitiesBuilder& CapabilitiesBuilder::SetSupportsTextureToTextureBlits(
182 bool value) {
183 supports_texture_to_texture_blits_ = value;
184 return *this;
185 }
186
187 CapabilitiesBuilder& CapabilitiesBuilder::SetSupportsFramebufferFetch(
188 bool value) {
189 supports_framebuffer_fetch_ = value;
190 return *this;
191 }
192
193 CapabilitiesBuilder& CapabilitiesBuilder::SetSupportsCompute(bool value) {
194 supports_compute_ = value;
195 return *this;
196 }
197
198 CapabilitiesBuilder& CapabilitiesBuilder::SetSupportsComputeSubgroups(
199 bool value) {
200 supports_compute_subgroups_ = value;
201 return *this;
202 }
203
204 CapabilitiesBuilder& CapabilitiesBuilder::SetDefaultColorFormat(
205 PixelFormat value) {
206 default_color_format_ = value;
207 return *this;
208 }
209
210 CapabilitiesBuilder& CapabilitiesBuilder::SetDefaultStencilFormat(
211 PixelFormat value) {
212 default_stencil_format_ = value;
213 return *this;
214 }
215
216 CapabilitiesBuilder& CapabilitiesBuilder::SetDefaultDepthStencilFormat(
217 PixelFormat value) {
218 default_depth_stencil_format_ = value;
219 return *this;
220 }
221
222 CapabilitiesBuilder& CapabilitiesBuilder::SetSupportsReadFromResolve(
223 bool read_from_resolve) {
224 supports_read_from_resolve_ = read_from_resolve;
225 return *this;
226 }
227
228 CapabilitiesBuilder& CapabilitiesBuilder::SetSupportsDecalSamplerAddressMode(
229 bool value) {
230 supports_decal_sampler_address_mode_ = value;
231 return *this;
232 }
233
234 CapabilitiesBuilder& CapabilitiesBuilder::SetSupportsDeviceTransientTextures(
235 bool value) {
236 supports_device_transient_textures_ = value;
237 return *this;
238 }
239
240 CapabilitiesBuilder& CapabilitiesBuilder::SetDefaultGlyphAtlasFormat(
241 PixelFormat value) {
242 default_glyph_atlas_format_ = value;
243 return *this;
244 }
245
246 CapabilitiesBuilder& CapabilitiesBuilder::SetSupportsTriangleFan(bool value) {
247 supports_triangle_fan_ = value;
248 return *this;
249 }
250
251 CapabilitiesBuilder& CapabilitiesBuilder::SetMaximumRenderPassAttachmentSize(
252 ISize size) {
253 default_maximum_render_pass_attachment_size_ = size;
254 return *this;
255 }
256
257 CapabilitiesBuilder& CapabilitiesBuilder::SetSupportsExtendedRangeFormats(
258 bool value) {
259 supports_extended_range_formats_ = value;
260 return *this;
261 }
262
263 CapabilitiesBuilder& CapabilitiesBuilder::SetMinimumUniformAlignment(
264 size_t value) {
265 minimum_uniform_alignment_ = value;
266 return *this;
267 }
268
269 std::unique_ptr<Capabilities> CapabilitiesBuilder::Build() {
270 // NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks)
271 return std::unique_ptr<StandardCapabilities>(new StandardCapabilities( //
272 supports_offscreen_msaa_, //
273 supports_ssbo_, //
274 supports_texture_to_texture_blits_, //
275 supports_framebuffer_fetch_, //
276 supports_compute_, //
277 supports_compute_subgroups_, //
278 supports_read_from_resolve_, //
279 supports_decal_sampler_address_mode_, //
280 supports_device_transient_textures_, //
281 supports_triangle_fan_, //
282 supports_extended_range_formats_, //
283 default_color_format_.value_or(PixelFormat::kUnknown), //
284 default_stencil_format_.value_or(PixelFormat::kUnknown), //
285 default_depth_stencil_format_.value_or(PixelFormat::kUnknown), //
286 default_glyph_atlas_format_.value_or(PixelFormat::kUnknown), //
287 default_maximum_render_pass_attachment_size_.value_or(ISize{1, 1}), //
288 minimum_uniform_alignment_ //
289 ));
290 }
291
292 } // namespace impeller
capabilities.h
impeller::CapabilitiesBuilder
Definition: capabilities.h:137
impeller::CapabilitiesBuilder::SetDefaultColorFormat
CapabilitiesBuilder & SetDefaultColorFormat(PixelFormat value)
Definition: capabilities.cc:204
impeller::CapabilitiesBuilder::SetSupportsComputeSubgroups
CapabilitiesBuilder & SetSupportsComputeSubgroups(bool value)
Definition: capabilities.cc:198
impeller::CapabilitiesBuilder::SetMinimumUniformAlignment
CapabilitiesBuilder & SetMinimumUniformAlignment(size_t value)
Definition: capabilities.cc:263
impeller::CapabilitiesBuilder::SetSupportsTextureToTextureBlits
CapabilitiesBuilder & SetSupportsTextureToTextureBlits(bool value)
Definition: capabilities.cc:181
impeller::CapabilitiesBuilder::SetDefaultStencilFormat
CapabilitiesBuilder & SetDefaultStencilFormat(PixelFormat value)
Definition: capabilities.cc:210
impeller::CapabilitiesBuilder::CapabilitiesBuilder
CapabilitiesBuilder()
impeller::CapabilitiesBuilder::SetSupportsDeviceTransientTextures
CapabilitiesBuilder & SetSupportsDeviceTransientTextures(bool value)
Definition: capabilities.cc:234
impeller::CapabilitiesBuilder::SetSupportsTriangleFan
CapabilitiesBuilder & SetSupportsTriangleFan(bool value)
Definition: capabilities.cc:246
impeller::CapabilitiesBuilder::~CapabilitiesBuilder
~CapabilitiesBuilder()
impeller::CapabilitiesBuilder::SetSupportsFramebufferFetch
CapabilitiesBuilder & SetSupportsFramebufferFetch(bool value)
Definition: capabilities.cc:187
impeller::CapabilitiesBuilder::SetSupportsDecalSamplerAddressMode
CapabilitiesBuilder & SetSupportsDecalSamplerAddressMode(bool value)
Definition: capabilities.cc:228
impeller::CapabilitiesBuilder::SetSupportsOffscreenMSAA
CapabilitiesBuilder & SetSupportsOffscreenMSAA(bool value)
Definition: capabilities.cc:171
impeller::CapabilitiesBuilder::SetSupportsSSBO
CapabilitiesBuilder & SetSupportsSSBO(bool value)
Definition: capabilities.cc:176
impeller::CapabilitiesBuilder::SetMaximumRenderPassAttachmentSize
CapabilitiesBuilder & SetMaximumRenderPassAttachmentSize(ISize size)
Definition: capabilities.cc:251
impeller::CapabilitiesBuilder::SetSupportsExtendedRangeFormats
CapabilitiesBuilder & SetSupportsExtendedRangeFormats(bool value)
Definition: capabilities.cc:257
impeller::CapabilitiesBuilder::SetDefaultGlyphAtlasFormat
CapabilitiesBuilder & SetDefaultGlyphAtlasFormat(PixelFormat value)
Definition: capabilities.cc:240
impeller::CapabilitiesBuilder::SetSupportsCompute
CapabilitiesBuilder & SetSupportsCompute(bool value)
Definition: capabilities.cc:193
impeller::CapabilitiesBuilder::Build
std::unique_ptr< Capabilities > Build()
Definition: capabilities.cc:269
impeller::CapabilitiesBuilder::SetDefaultDepthStencilFormat
CapabilitiesBuilder & SetDefaultDepthStencilFormat(PixelFormat value)
Definition: capabilities.cc:216
impeller::CapabilitiesBuilder::SetSupportsReadFromResolve
CapabilitiesBuilder & SetSupportsReadFromResolve(bool value)
Definition: capabilities.cc:222
impeller::Capabilities
Definition: capabilities.h:14
impeller::Capabilities::Capabilities
Capabilities()
impeller::Capabilities::~Capabilities
virtual ~Capabilities()
impeller::StandardCapabilities
Definition: capabilities.cc:14
impeller::StandardCapabilities::~StandardCapabilities
~StandardCapabilities() override=default
impeller::StandardCapabilities::SupportsReadFromResolve
bool SupportsReadFromResolve() const override
Whether the context backend supports binding the current RenderPass attachments. This is supported if...
Definition: capabilities.cc:49
impeller::StandardCapabilities::GetDefaultDepthStencilFormat
PixelFormat GetDefaultDepthStencilFormat() const override
Returns a supported PixelFormat for textures that store both a stencil and depth component....
Definition: capabilities.cc:72
impeller::StandardCapabilities::SupportsComputeSubgroups
bool SupportsComputeSubgroups() const override
Whether the context backend supports configuring ComputePass command subgroups.
Definition: capabilities.cc:44
impeller::StandardCapabilities::SupportsOffscreenMSAA
bool SupportsOffscreenMSAA() const override
Whether the context backend supports attaching offscreen MSAA color/stencil textures.
Definition: capabilities.cc:20
impeller::StandardCapabilities::GetMaximumRenderPassAttachmentSize
ISize GetMaximumRenderPassAttachmentSize() const override
Return the maximum size of a render pass attachment.
Definition: capabilities.cc:87
impeller::StandardCapabilities::SupportsTextureToTextureBlits
bool SupportsTextureToTextureBlits() const override
Whether the context backend supports blitting from one texture region to another texture region (via ...
Definition: capabilities.cc:31
impeller::StandardCapabilities::SupportsFramebufferFetch
bool SupportsFramebufferFetch() const override
Whether the context backend is able to support pipelines with shaders that read from the framebuffer ...
Definition: capabilities.cc:36
impeller::StandardCapabilities::GetDefaultGlyphAtlasFormat
PixelFormat GetDefaultGlyphAtlasFormat() const override
Returns the default pixel format for the alpha bitmap glyph atlas.
Definition: capabilities.cc:82
impeller::StandardCapabilities::GetDefaultStencilFormat
PixelFormat GetDefaultStencilFormat() const override
Returns a supported PixelFormat for textures that store stencil information. May include a depth chan...
Definition: capabilities.cc:67
impeller::StandardCapabilities::SupportsCompute
bool SupportsCompute() const override
Whether the context backend supports ComputePass.
Definition: capabilities.cc:41
impeller::StandardCapabilities::GetMinimumUniformAlignment
size_t GetMinimumUniformAlignment() const override
The minimum alignment of uniform value offsets in bytes.
Definition: capabilities.cc:100
impeller::StandardCapabilities::SupportsSSBO
bool SupportsSSBO() const override
Whether the context backend supports binding Shader Storage Buffer Objects (SSBOs) to pipelines.
Definition: capabilities.cc:28
impeller::StandardCapabilities::SupportsDeviceTransientTextures
bool SupportsDeviceTransientTextures() const override
Whether the context backend supports allocating StorageMode::kDeviceTransient (aka "memoryless") text...
Definition: capabilities.cc:77
impeller::StandardCapabilities::SupportsImplicitResolvingMSAA
bool SupportsImplicitResolvingMSAA() const override
Whether the context backend supports multisampled rendering to the on-screen surface without requirin...
Definition: capabilities.cc:25
impeller::StandardCapabilities::SupportsPrimitiveRestart
bool SupportsPrimitiveRestart() const override
Whether primitive restart is supported.
Definition: capabilities.cc:92
impeller::StandardCapabilities::GetDefaultColorFormat
PixelFormat GetDefaultColorFormat() const override
Returns a supported PixelFormat for textures that store 4-channel colors (red/green/blue/alpha).
Definition: capabilities.cc:62
impeller::StandardCapabilities::SupportsExtendedRangeFormats
bool SupportsExtendedRangeFormats() const override
Whether the XR formats are supported on this device.
Definition: capabilities.cc:95
impeller::StandardCapabilities::SupportsTriangleFan
bool SupportsTriangleFan() const override
Whether the primitive type TriangleFan is supported by the backend.
Definition: capabilities.cc:59
impeller::StandardCapabilities::SupportsDecalSamplerAddressMode
bool SupportsDecalSamplerAddressMode() const override
Whether the context backend supports SamplerAddressMode::Decal.
Definition: capabilities.cc:54
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::PixelFormat::kUnknown
@ kUnknown
impeller::ISize
ISize64 ISize
Definition: size.h:162
impeller::TSize
Definition: size.h:25