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