Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
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
6
9
10namespace impeller {
11
12// https://registry.khronos.org/OpenGL/extensions/EXT/EXT_shader_framebuffer_fetch.txt
13static const constexpr char* kFramebufferFetchExt =
14 "GL_EXT_shader_framebuffer_fetch";
15
16static const constexpr char* kTextureBorderClampExt =
17 "GL_EXT_texture_border_clamp";
18static 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
22static 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
26static const constexpr char* kMultisampledRenderToTexture2Ext =
27 "GL_EXT_multisampled_render_to_texture2";
28
29// https://registry.khronos.org/OpenGL/extensions/OES/OES_element_index_uint.txt
30static const constexpr char* kElementIndexUintExt = "GL_OES_element_index_uint";
31
32// The BC family spans three separate OpenGL ES extensions: S3TC (BC1-BC3),
33// RGTC (BC5), and BPTC (BC7). All three are required to report kBC support.
34// https://registry.khronos.org/OpenGL/extensions/EXT/EXT_texture_compression_s3tc.txt
35static const constexpr char* kTextureCompressionS3TCExt =
36 "GL_EXT_texture_compression_s3tc";
37// https://registry.khronos.org/OpenGL/extensions/EXT/EXT_texture_compression_rgtc.txt
38static const constexpr char* kTextureCompressionRGTCExt =
39 "GL_EXT_texture_compression_rgtc";
40// https://registry.khronos.org/OpenGL/extensions/EXT/EXT_texture_compression_bptc.txt
41static const constexpr char* kTextureCompressionBPTCExt =
42 "GL_EXT_texture_compression_bptc";
43
44// https://registry.khronos.org/OpenGL/extensions/KHR/KHR_texture_compression_astc_hdr.txt
45static const constexpr char* kTextureCompressionAstcLdrExt =
46 "GL_KHR_texture_compression_astc_ldr";
47// https://registry.khronos.org/OpenGL/extensions/OES/OES_texture_compression_astc.txt
48static const constexpr char* kTextureCompressionAstcOesExt =
49 "GL_OES_texture_compression_astc";
50// https://registry.khronos.org/OpenGL/extensions/KHR/KHR_texture_compression_astc_hdr.txt
51static const constexpr char* kTextureCompressionAstcHdrExt =
52 "GL_KHR_texture_compression_astc_hdr";
53
54// https://registry.khronos.org/OpenGL/extensions/APPLE/APPLE_texture_max_level.txt
55static const constexpr char* kAppleTextureMaxLevelExt =
56 "GL_APPLE_texture_max_level";
57
59 {
60 GLint value = 0;
61 gl.GetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &value);
63 }
64
65 {
66 GLint value = 0;
67 gl.GetIntegerv(GL_MAX_CUBE_MAP_TEXTURE_SIZE, &value);
69 }
70
71 auto const desc = gl.GetDescription();
72
73 if (desc->IsES()) {
74 GLint value = 0;
75 gl.GetIntegerv(GL_MAX_FRAGMENT_UNIFORM_VECTORS, &value);
77 }
78
79 {
80 GLint value = 0;
81 gl.GetIntegerv(GL_MAX_RENDERBUFFER_SIZE, &value);
83 }
84
85 {
86 GLint value = 0;
87 gl.GetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &value);
89 }
90
91 {
92 GLint value = 0;
93 gl.GetIntegerv(GL_MAX_TEXTURE_SIZE, &value);
95 }
96
97 if (desc->IsES()) {
98 GLint value = 0;
99 gl.GetIntegerv(GL_MAX_VARYING_VECTORS, &value);
101 }
102
103 {
104 GLint value = 0;
105 gl.GetIntegerv(GL_MAX_VERTEX_ATTRIBS, &value);
107 }
108
109 {
110 GLint value = 0;
111 gl.GetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &value);
113 }
114
115 if (desc->IsES()) {
116 GLint value = 0;
117 gl.GetIntegerv(GL_MAX_VERTEX_UNIFORM_VECTORS, &value);
119 }
120
121 {
122 GLint values[2] = {};
123 gl.GetIntegerv(GL_MAX_VIEWPORT_DIMS, values);
124 max_viewport_dims = ISize{values[0], values[1]};
125 }
126
127 {
128 GLint value = 0;
129 gl.GetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS, &value);
131 }
132
133 if (desc->IsES()) {
134 GLint value = 0;
135 gl.GetIntegerv(GL_NUM_SHADER_BINARY_FORMATS, &value);
137 }
138
139 if (desc->IsES()) {
140 default_glyph_atlas_format_ = PixelFormat::kA8UNormInt;
141 } else {
142 default_glyph_atlas_format_ = PixelFormat::kR8UNormInt;
143 }
144
145 if (desc->GetGlVersion().major_version >= 3) {
146 supports_texture_to_texture_blits_ = true;
147 }
148
149 supports_framebuffer_fetch_ = desc->HasExtension(kFramebufferFetchExt);
150
151 if (desc->HasExtension(kTextureBorderClampExt) ||
152 desc->HasExtension(kNvidiaTextureBorderClampExt)) {
153 supports_decal_sampler_address_mode_ = true;
154 }
155
156 if (desc->HasExtension(kElementIndexUintExt)) {
157 supports_32bit_primitive_indices_ = true;
158 }
159
160 if (desc->HasExtension(kMultisampledRenderToTextureExt)) {
161 supports_implicit_msaa_ = true;
162
163 if (desc->HasExtension(kMultisampledRenderToTexture2Ext)) {
164 // We hard-code 4x MSAA, so let's make sure it's supported.
165 GLint value = 0;
166 gl.GetIntegerv(GL_MAX_SAMPLES_EXT, &value);
167 supports_offscreen_msaa_ = value >= 4;
168 }
169 } else if (desc->GetGlVersion().major_version >= 3 && desc->IsES()) {
170 GLint value = 0;
171 gl.GetIntegerv(GL_MAX_SAMPLES, &value);
172 supports_offscreen_msaa_ = value >= 4;
173 }
174 is_es_ = desc->IsES();
175 is_angle_ = desc->IsANGLE();
176
177 // ETC2 and EAC are mandatory in OpenGL ES 3.0. BC and ASTC are gated behind
178 // extensions and are not present on most mobile or desktop GLES. The whole BC
179 // family requires S3TC, RGTC, and BPTC to all be present.
180 supports_texture_compression_bc_ =
181 desc->HasExtension(kTextureCompressionS3TCExt) &&
182 desc->HasExtension(kTextureCompressionRGTCExt) &&
183 desc->HasExtension(kTextureCompressionBPTCExt);
184 // Either extension is sufficient: both expose the same LDR 2D ASTC internal
185 // formats this backend uses. KHR is the common one; OES is a superset that
186 // also adds HDR and 3D, which are not used here.
187 supports_texture_compression_astc_ =
188 desc->HasExtension(kTextureCompressionAstcLdrExt) ||
189 desc->HasExtension(kTextureCompressionAstcOesExt);
190 // HDR reuses the same internal formats as LDR, gated by a separate extension.
191 // The OES extension is a superset that also covers HDR.
192 supports_texture_compression_astc_hdr_ =
193 desc->HasExtension(kTextureCompressionAstcHdrExt) ||
194 desc->HasExtension(kTextureCompressionAstcOesExt);
195 supports_texture_compression_etc2_ =
196 desc->IsES() && desc->GetGlVersion().major_version >= 3;
197
198 // GL_TEXTURE_MAX_LEVEL is core on desktop GL and ES 3.0+, and available on
199 // ES 2.0 through GL_APPLE_texture_max_level.
200 supports_texture_max_level_ = !desc->IsES() ||
201 desc->GetGlVersion().major_version >= 3 ||
202 desc->HasExtension(kAppleTextureMaxLevelExt);
203}
204
206 return is_es_;
207}
208
210 // Rendering into a non-zero mip level is not yet supported on the GLES
211 // backend. The texture storage path allocates levels with mutable, lazily
212 // allocated glTexImage2D storage, which yields an incomplete framebuffer
213 // when a non-base mip level is attached. Until that is reworked, do not
214 // advertise the capability so callers fall back instead of failing to
215 // create the framebuffer. Rendering into a cube map face is unaffected.
216 return false;
217}
218
220 return supports_texture_max_level_;
221}
222
224 switch (stage) {
231 return 0u;
232 }
234}
235
237 return supports_offscreen_msaa_;
238}
239
241 return supports_implicit_msaa_;
242}
243
245 return false;
246}
247
249 return supports_texture_to_texture_blits_;
250}
251
253 return supports_framebuffer_fetch_;
254}
255
257 return false;
258}
259
261 return false;
262}
263
265 return false;
266}
267
269 return supports_decal_sampler_address_mode_;
270}
271
273 return false;
274}
275
277 return true;
278}
279
283
287
291
293 return is_angle_;
294}
295
297 return false;
298}
299
301 return supports_32bit_primitive_indices_;
302}
303
305 // Without GL_TEXTURE_MAX_LEVEL the sampled mip range cannot be bounded to
306 // the levels the texture declares, so a hand-uploaded chain is mipmap
307 // incomplete and samples as black.
308 return supports_texture_max_level_;
309}
310
312 return false;
313}
314
316 CompressedTextureFamily family) const {
317 switch (family) {
319 return supports_texture_compression_bc_;
321 return supports_texture_compression_etc2_;
323 return supports_texture_compression_astc_;
325 return supports_texture_compression_astc_hdr_;
326 }
327 return false;
328}
329
331 return default_glyph_atlas_format_;
332}
333
337
339 return 256;
340}
341
343#ifdef FML_OS_EMSCRIPTEN
344 // WebGL has special requirements here to keep indexes and other data
345 // separate. See
346 // https://registry.khronos.org/webgl/specs/latest/2.0/#BUFFER_OBJECT_BINDING
347 return true;
348#else
349 return false;
350#endif
351}
352
353} // namespace impeller
bool IsES() const
Whether this is an ES GL variant or (if false) desktop GL.
bool SupportsImplicitResolvingMSAA() const override
Whether the context backend supports multisampled rendering to the on-screen surface without requirin...
PixelFormat GetDefaultDepthStencilFormat() const override
Returns a supported PixelFormat for textures that store both a stencil and depth component....
PixelFormat GetDefaultColorFormat() const override
Returns a supported PixelFormat for textures that store 4-channel colors (red/green/blue/alpha).
bool SupportsSSBO() const override
Whether the context backend supports binding Shader Storage Buffer Objects (SSBOs) to pipelines.
bool SupportsTextureToTextureBlits() const override
Whether the context backend supports blitting from one texture region to another texture region (via ...
ISize GetMaximumRenderPassAttachmentSize() const override
Return the maximum size of a render pass attachment.
bool SupportsFramebufferRenderMipmap() const override
CapabilitiesGLES(const ProcTableGLES &gl)
bool SupportsPrimitiveRestart() const override
Whether primitive restart is supported.
size_t GetMaxTextureUnits(ShaderStage stage) const
bool NeedsPartitionedHostBuffer() const override
Whether the host buffer should use separate device buffers for indexes from other data.
bool SupportsTriangleFan() const override
Whether the primitive type TriangleFan is supported by the backend.
bool Supports32BitPrimitiveIndices() const override
Whether 32-bit values are supported in index buffers used to draw primitives.
bool SupportsTextureCompression(CompressedTextureFamily family) const override
Whether the given family of block-compressed texture formats is supported by this device....
bool SupportsTextureMaxLevel() const
Whether GL_TEXTURE_MAX_LEVEL can be set to bound a texture's sampled mip range. Core on desktop GL an...
bool SupportsOffscreenMSAA() const override
Whether the context backend supports attaching offscreen MSAA color/stencil textures.
size_t GetMinimumUniformAlignment() const override
The minimum alignment of uniform value offsets in bytes.
PixelFormat GetDefaultStencilFormat() const override
Returns a supported PixelFormat for textures that store stencil information. May include a depth chan...
bool SupportsReadFromResolve() const override
Whether the context backend supports binding the current RenderPass attachments. This is supported if...
bool SupportsDeviceTransientTextures() const override
Whether the context backend supports allocating StorageMode::kDeviceTransient (aka "memoryless") text...
bool SupportsDecalSamplerAddressMode() const override
Whether the context backend supports SamplerAddressMode::Decal.
PixelFormat GetDefaultGlyphAtlasFormat() const override
Returns the default pixel format for the alpha bitmap glyph atlas.
bool SupportsExtendedRangeFormats() const override
Whether the XR formats are supported on this device.
bool SupportsCompute() const override
Whether the context backend supports ComputePass.
bool SupportsManuallyMippedTextures() const override
Whether a texture whose mip levels were uploaded by hand (rather than produced by BlitPass::GenerateM...
bool SupportsComputeSubgroups() const override
Whether the context backend supports configuring ComputePass command subgroups.
bool SupportsFramebufferFetch() const override
Whether the context backend is able to support pipelines with shaders that read from the framebuffer ...
const DescriptionGLES * GetDescription() const
int32_t value
#define FML_UNREACHABLE()
Definition logging.h:128
static const constexpr char * kTextureCompressionAstcOesExt
static const constexpr char * kMultisampledRenderToTexture2Ext
static const constexpr char * kTextureCompressionAstcHdrExt
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
Definition formats.h:99
static const constexpr char * kMultisampledRenderToTextureExt
static const constexpr char * kTextureCompressionBPTCExt
static const constexpr char * kTextureCompressionAstcLdrExt
CompressedTextureFamily
The family of a block-compressed pixel format. GPUs support compressed formats on a per-family basis,...
Definition formats.h:146
@ kASTCHDR
ASTC HDR. A separate device feature from ASTC LDR.
@ kBC
S3TC, RGTC, and BPTC (BC1 through BC7). Desktop GPUs.
@ kETC2
ETC2 and EAC. Mobile, OpenGL ES 3.0, and WebGL2.
@ kASTC
ASTC LDR. Modern mobile and some desktop.
static const constexpr char * kTextureCompressionRGTCExt
static const constexpr char * kTextureCompressionS3TCExt
static const constexpr char * kTextureBorderClampExt
static const constexpr char * kNvidiaTextureBorderClampExt
static const constexpr char * kAppleTextureMaxLevelExt
static const constexpr char * kFramebufferFetchExt
static const constexpr char * kElementIndexUintExt