| Flutter Impeller |

capabilities_gles.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/backend/gles/capabilities_gles.h"
6
7 #include "impeller/core/formats.h"
8 #include "impeller/renderer/backend/gles/proc_table_gles.h"
9
10 namespace impeller {
11
12 // https://registry.khronos.org/OpenGL/extensions/EXT/EXT_shader_framebuffer_fetch.txt
13 static const constexpr char* kFramebufferFetchExt =
14 "GL_EXT_shader_framebuffer_fetch";
15
16 static const constexpr char* kTextureBorderClampExt =
17 "GL_EXT_texture_border_clamp";
18 static const constexpr char* kNvidiaTextureBorderClampExt =
19 "GL_NV_texture_border_clamp";
20
21 // https://www.khronos.org/registry/OpenGL/extensions/EXT/EXT_multisampled_render_to_texture.txt
22 static const constexpr char* kMultisampledRenderToTextureExt =
23 "GL_EXT_multisampled_render_to_texture";
24
25 // https://registry.khronos.org/OpenGL/extensions/EXT/EXT_multisampled_render_to_texture2.txt
26 static const constexpr char* kMultisampledRenderToTexture2Ext =
27 "GL_EXT_multisampled_render_to_texture2";
28
29 CapabilitiesGLES::CapabilitiesGLES(const ProcTableGLES& gl) {
30 {
31 GLint value = 0;
32 gl.GetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &value);
33 max_combined_texture_image_units = value;
34 }
35
36 {
37 GLint value = 0;
38 gl.GetIntegerv(GL_MAX_CUBE_MAP_TEXTURE_SIZE, &value);
39 max_cube_map_texture_size = value;
40 }
41
42 auto const desc = gl.GetDescription();
43
44 if (desc->IsES()) {
45 GLint value = 0;
46 gl.GetIntegerv(GL_MAX_FRAGMENT_UNIFORM_VECTORS, &value);
47 max_fragment_uniform_vectors = value;
48 }
49
50 {
51 GLint value = 0;
52 gl.GetIntegerv(GL_MAX_RENDERBUFFER_SIZE, &value);
53 max_renderbuffer_size = value;
54 }
55
56 {
57 GLint value = 0;
58 gl.GetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &value);
59 max_texture_image_units = value;
60 }
61
62 {
63 GLint value = 0;
64 gl.GetIntegerv(GL_MAX_TEXTURE_SIZE, &value);
65 max_texture_size = ISize{value, value};
66 }
67
68 if (desc->IsES()) {
69 GLint value = 0;
70 gl.GetIntegerv(GL_MAX_VARYING_VECTORS, &value);
71 max_varying_vectors = value;
72 }
73
74 {
75 GLint value = 0;
76 gl.GetIntegerv(GL_MAX_VERTEX_ATTRIBS, &value);
77 max_vertex_attribs = value;
78 }
79
80 {
81 GLint value = 0;
82 gl.GetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &value);
83 max_vertex_texture_image_units = value;
84 }
85
86 if (desc->IsES()) {
87 GLint value = 0;
88 gl.GetIntegerv(GL_MAX_VERTEX_UNIFORM_VECTORS, &value);
89 max_vertex_uniform_vectors = value;
90 }
91
92 {
93 GLint values[2] = {};
94 gl.GetIntegerv(GL_MAX_VIEWPORT_DIMS, values);
95 max_viewport_dims = ISize{values[0], values[1]};
96 }
97
98 {
99 GLint value = 0;
100 gl.GetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS, &value);
101 num_compressed_texture_formats = value;
102 }
103
104 if (desc->IsES()) {
105 GLint value = 0;
106 gl.GetIntegerv(GL_NUM_SHADER_BINARY_FORMATS, &value);
107 num_shader_binary_formats = value;
108 }
109
110 if (desc->IsES()) {
111 default_glyph_atlas_format_ = PixelFormat::kA8UNormInt;
112 } else {
113 default_glyph_atlas_format_ = PixelFormat::kR8UNormInt;
114 }
115
116 if (desc->GetGlVersion().major_version >= 3) {
117 supports_texture_to_texture_blits_ = true;
118 }
119
120 supports_framebuffer_fetch_ = desc->HasExtension(kFramebufferFetchExt);
121
122 if (desc->HasExtension(kTextureBorderClampExt) ||
123 desc->HasExtension(kNvidiaTextureBorderClampExt)) {
124 supports_decal_sampler_address_mode_ = true;
125 }
126
127 if (desc->HasExtension(kMultisampledRenderToTextureExt)) {
128 supports_implicit_msaa_ = true;
129
130 if (desc->HasExtension(kMultisampledRenderToTexture2Ext)) {
131 // We hard-code 4x MSAA, so let's make sure it's supported.
132 GLint value = 0;
133 gl.GetIntegerv(GL_MAX_SAMPLES_EXT, &value);
134 supports_offscreen_msaa_ = value >= 4;
135 }
136 } else if (desc->GetGlVersion().major_version >= 3 && desc->IsES()) {
137 GLint value = 0;
138 gl.GetIntegerv(GL_MAX_SAMPLES, &value);
139 supports_offscreen_msaa_ = value >= 4;
140 }
141 is_es_ = desc->IsES();
142 is_angle_ = desc->IsANGLE();
143 }
144
145 bool CapabilitiesGLES::IsES() const {
146 return is_es_;
147 }
148
149 size_t CapabilitiesGLES::GetMaxTextureUnits(ShaderStage stage) const {
150 switch (stage) {
151 case ShaderStage::kVertex:
152 return max_vertex_texture_image_units;
153 case ShaderStage::kFragment:
154 return max_texture_image_units;
155 case ShaderStage::kUnknown:
156 case ShaderStage::kCompute:
157 return 0u;
158 }
159 FML_UNREACHABLE();
160 }
161
162 bool CapabilitiesGLES::SupportsOffscreenMSAA() const {
163 return supports_offscreen_msaa_;
164 }
165
166 bool CapabilitiesGLES::SupportsImplicitResolvingMSAA() const {
167 return supports_implicit_msaa_;
168 }
169
170 bool CapabilitiesGLES::SupportsSSBO() const {
171 return false;
172 }
173
174 bool CapabilitiesGLES::SupportsTextureToTextureBlits() const {
175 return supports_texture_to_texture_blits_;
176 }
177
178 bool CapabilitiesGLES::SupportsFramebufferFetch() const {
179 return supports_framebuffer_fetch_;
180 }
181
182 bool CapabilitiesGLES::SupportsCompute() const {
183 return false;
184 }
185
186 bool CapabilitiesGLES::SupportsComputeSubgroups() const {
187 return false;
188 }
189
190 bool CapabilitiesGLES::SupportsReadFromResolve() const {
191 return false;
192 }
193
194 bool CapabilitiesGLES::SupportsDecalSamplerAddressMode() const {
195 return supports_decal_sampler_address_mode_;
196 }
197
198 bool CapabilitiesGLES::SupportsDeviceTransientTextures() const {
199 return false;
200 }
201
202 bool CapabilitiesGLES::SupportsTriangleFan() const {
203 return true;
204 }
205
206 PixelFormat CapabilitiesGLES::GetDefaultColorFormat() const {
207 return PixelFormat::kR8G8B8A8UNormInt;
208 }
209
210 PixelFormat CapabilitiesGLES::GetDefaultStencilFormat() const {
211 return PixelFormat::kS8UInt;
212 }
213
214 PixelFormat CapabilitiesGLES::GetDefaultDepthStencilFormat() const {
215 return PixelFormat::kD24UnormS8Uint;
216 }
217
218 bool CapabilitiesGLES::IsANGLE() const {
219 return is_angle_;
220 }
221
222 bool CapabilitiesGLES::SupportsPrimitiveRestart() const {
223 return false;
224 }
225
226 bool CapabilitiesGLES::SupportsExtendedRangeFormats() const {
227 return false;
228 }
229
230 PixelFormat CapabilitiesGLES::GetDefaultGlyphAtlasFormat() const {
231 return default_glyph_atlas_format_;
232 }
233
234 ISize CapabilitiesGLES::GetMaximumRenderPassAttachmentSize() const {
235 return max_texture_size;
236 }
237
238 size_t CapabilitiesGLES::GetMinimumUniformAlignment() const {
239 return 256;
240 }
241
242 } // namespace impeller
capabilities_gles.h
impeller::CapabilitiesGLES::IsES
bool IsES() const
Whether this is an ES GL variant or (if false) desktop GL.
Definition: capabilities_gles.cc:145
impeller::CapabilitiesGLES::SupportsImplicitResolvingMSAA
bool SupportsImplicitResolvingMSAA() const override
Whether the context backend supports multisampled rendering to the on-screen surface without requirin...
Definition: capabilities_gles.cc:166
impeller::CapabilitiesGLES::GetDefaultDepthStencilFormat
PixelFormat GetDefaultDepthStencilFormat() const override
Returns a supported PixelFormat for textures that store both a stencil and depth component....
Definition: capabilities_gles.cc:214
impeller::CapabilitiesGLES::max_vertex_uniform_vectors
size_t max_vertex_uniform_vectors
Definition: capabilities_gles.h:65
impeller::CapabilitiesGLES::GetDefaultColorFormat
PixelFormat GetDefaultColorFormat() const override
Returns a supported PixelFormat for textures that store 4-channel colors (red/green/blue/alpha).
Definition: capabilities_gles.cc:206
impeller::CapabilitiesGLES::SupportsSSBO
bool SupportsSSBO() const override
Whether the context backend supports binding Shader Storage Buffer Objects (SSBOs) to pipelines.
Definition: capabilities_gles.cc:170
impeller::CapabilitiesGLES::max_fragment_uniform_vectors
size_t max_fragment_uniform_vectors
Definition: capabilities_gles.h:44
impeller::CapabilitiesGLES::SupportsTextureToTextureBlits
bool SupportsTextureToTextureBlits() const override
Whether the context backend supports blitting from one texture region to another texture region (via ...
Definition: capabilities_gles.cc:174
impeller::CapabilitiesGLES::GetMaximumRenderPassAttachmentSize
ISize GetMaximumRenderPassAttachmentSize() const override
Return the maximum size of a render pass attachment.
Definition: capabilities_gles.cc:234
impeller::CapabilitiesGLES::CapabilitiesGLES
CapabilitiesGLES(const ProcTableGLES &gl)
Definition: capabilities_gles.cc:29
impeller::CapabilitiesGLES::max_viewport_dims
ISize max_viewport_dims
Definition: capabilities_gles.h:68
impeller::CapabilitiesGLES::max_renderbuffer_size
size_t max_renderbuffer_size
Definition: capabilities_gles.h:47
impeller::CapabilitiesGLES::SupportsPrimitiveRestart
bool SupportsPrimitiveRestart() const override
Whether primitive restart is supported.
Definition: capabilities_gles.cc:222
impeller::CapabilitiesGLES::GetMaxTextureUnits
size_t GetMaxTextureUnits(ShaderStage stage) const
Definition: capabilities_gles.cc:149
impeller::CapabilitiesGLES::IsANGLE
bool IsANGLE() const
Definition: capabilities_gles.cc:218
impeller::CapabilitiesGLES::max_cube_map_texture_size
size_t max_cube_map_texture_size
Definition: capabilities_gles.h:41
impeller::CapabilitiesGLES::max_vertex_texture_image_units
size_t max_vertex_texture_image_units
Definition: capabilities_gles.h:62
impeller::CapabilitiesGLES::SupportsTriangleFan
bool SupportsTriangleFan() const override
Whether the primitive type TriangleFan is supported by the backend.
Definition: capabilities_gles.cc:202
impeller::CapabilitiesGLES::num_shader_binary_formats
size_t num_shader_binary_formats
Definition: capabilities_gles.h:74
impeller::CapabilitiesGLES::max_combined_texture_image_units
size_t max_combined_texture_image_units
Definition: capabilities_gles.h:38
impeller::CapabilitiesGLES::SupportsOffscreenMSAA
bool SupportsOffscreenMSAA() const override
Whether the context backend supports attaching offscreen MSAA color/stencil textures.
Definition: capabilities_gles.cc:162
impeller::CapabilitiesGLES::GetMinimumUniformAlignment
size_t GetMinimumUniformAlignment() const override
The minimum alignment of uniform value offsets in bytes.
Definition: capabilities_gles.cc:238
impeller::CapabilitiesGLES::GetDefaultStencilFormat
PixelFormat GetDefaultStencilFormat() const override
Returns a supported PixelFormat for textures that store stencil information. May include a depth chan...
Definition: capabilities_gles.cc:210
impeller::CapabilitiesGLES::SupportsReadFromResolve
bool SupportsReadFromResolve() const override
Whether the context backend supports binding the current RenderPass attachments. This is supported if...
Definition: capabilities_gles.cc:190
impeller::CapabilitiesGLES::SupportsDeviceTransientTextures
bool SupportsDeviceTransientTextures() const override
Whether the context backend supports allocating StorageMode::kDeviceTransient (aka "memoryless") text...
Definition: capabilities_gles.cc:198
impeller::CapabilitiesGLES::SupportsDecalSamplerAddressMode
bool SupportsDecalSamplerAddressMode() const override
Whether the context backend supports SamplerAddressMode::Decal.
Definition: capabilities_gles.cc:194
impeller::CapabilitiesGLES::max_texture_image_units
size_t max_texture_image_units
Definition: capabilities_gles.h:50
impeller::CapabilitiesGLES::GetDefaultGlyphAtlasFormat
PixelFormat GetDefaultGlyphAtlasFormat() const override
Returns the default pixel format for the alpha bitmap glyph atlas.
Definition: capabilities_gles.cc:230
impeller::CapabilitiesGLES::max_texture_size
ISize max_texture_size
Definition: capabilities_gles.h:53
impeller::CapabilitiesGLES::max_vertex_attribs
size_t max_vertex_attribs
Definition: capabilities_gles.h:59
impeller::CapabilitiesGLES::SupportsExtendedRangeFormats
bool SupportsExtendedRangeFormats() const override
Whether the XR formats are supported on this device.
Definition: capabilities_gles.cc:226
impeller::CapabilitiesGLES::SupportsCompute
bool SupportsCompute() const override
Whether the context backend supports ComputePass.
Definition: capabilities_gles.cc:182
impeller::CapabilitiesGLES::max_varying_vectors
size_t max_varying_vectors
Definition: capabilities_gles.h:56
impeller::CapabilitiesGLES::SupportsComputeSubgroups
bool SupportsComputeSubgroups() const override
Whether the context backend supports configuring ComputePass command subgroups.
Definition: capabilities_gles.cc:186
impeller::CapabilitiesGLES::num_compressed_texture_formats
size_t num_compressed_texture_formats
Definition: capabilities_gles.h:71
impeller::CapabilitiesGLES::SupportsFramebufferFetch
bool SupportsFramebufferFetch() const override
Whether the context backend is able to support pipelines with shaders that read from the framebuffer ...
Definition: capabilities_gles.cc:178
impeller::ProcTableGLES
Definition: proc_table_gles.h:282
impeller::ProcTableGLES::GetDescription
const DescriptionGLES * GetDescription() const
Definition: proc_table_gles.cc:207
formats.h
value
int32_t value
Definition: dl_golden_unittests.cc:459
impeller
Definition: allocation.cc:12
impeller::kTextureBorderClampExt
static constexpr const char * kTextureBorderClampExt
Definition: capabilities_gles.cc:16
impeller::kMultisampledRenderToTexture2Ext
static constexpr const char * kMultisampledRenderToTexture2Ext
Definition: capabilities_gles.cc:26
impeller::kNvidiaTextureBorderClampExt
static constexpr const char * kNvidiaTextureBorderClampExt
Definition: capabilities_gles.cc:18
impeller::PixelFormat
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
Definition: formats.h:99
impeller::PixelFormat::kD24UnormS8Uint
@ kD24UnormS8Uint
impeller::PixelFormat::kR8UNormInt
@ kR8UNormInt
impeller::PixelFormat::kA8UNormInt
@ kA8UNormInt
impeller::PixelFormat::kS8UInt
@ kS8UInt
impeller::PixelFormat::kR8G8B8A8UNormInt
@ kR8G8B8A8UNormInt
impeller::ShaderStage
ShaderStage
Definition: shader_types.h:22
impeller::ShaderStage::kUnknown
@ kUnknown
impeller::ShaderStage::kCompute
@ kCompute
impeller::ShaderStage::kFragment
@ kFragment
impeller::ShaderStage::kVertex
@ kVertex
impeller::kFramebufferFetchExt
static constexpr const char * kFramebufferFetchExt
Definition: capabilities_gles.cc:13
impeller::kMultisampledRenderToTextureExt
static constexpr const char * kMultisampledRenderToTextureExt
Definition: capabilities_gles.cc:22
proc_table_gles.h
impeller::TSize
Definition: size.h:25