| Flutter Impeller |

Public Types | Public Member Functions | List of all members
impeller::ProcTableGLES Class Reference

`#include <proc_table_gles.h>`

## Public Types
using | Resolver = std::function< void *(const char *function_name)>

## Public Member Functions
| ProcTableGLES (Resolver resolver)
| ProcTableGLES (ProcTableGLES &&other)=default
| ~ProcTableGLES ()
| FOR_EACH_IMPELLER_PROC (IMPELLER_PROC)
| FOR_EACH_IMPELLER_ES_ONLY_PROC (IMPELLER_PROC)
| FOR_EACH_IMPELLER_DESKTOP_ONLY_PROC (IMPELLER_PROC)
| FOR_EACH_IMPELLER_GLES3_PROC (IMPELLER_PROC)
| FOR_EACH_IMPELLER_EXT_PROC (IMPELLER_PROC)
bool | IsValid () const
void | ShaderSourceMapping (GLuint shader, const fml::Mapping &mapping, const std::vector< Scalar > &defines={}) const
| Set the source for the attached [shader]. More...
const DescriptionGLES * | GetDescription () const
const std::shared_ptr< const CapabilitiesGLES > & | GetCapabilities () const
std::string | DescribeCurrentFramebuffer () const
std::string | GetProgramInfoLogString (GLuint program) const
GLenum | CheckFramebufferStatusDebug (GLenum target) const
bool | IsCurrentFramebufferComplete () const
bool | SupportsDebugLabels () const
bool | SetDebugLabel (DebugResourceType type, GLint name, std::string_view label) const
void | PushDebugGroup (const std::string &string) const
void | PopDebugGroup () const
std::optional< std::string > | ComputeShaderWithDefines (const fml::Mapping &mapping, const std::vector< Scalar > &defines) const

## Detailed Description

Definition at line 283 of file proc_table_gles.h.

## Member Typedef Documentation

## ◆ Resolver

using impeller::ProcTableGLES::Resolver = std::function<void*(const char* function_name)>

Definition at line 285 of file proc_table_gles.h.

## Constructor & Destructor Documentation

## ◆ ProcTableGLES() [1/2]

impeller::ProcTableGLES::ProcTableGLES | ( | Resolver | resolver | ) |
| explicit

Definition at line 75 of file proc_table_gles.cc.

76 {
77 // The reason this constructor has anywhere near enough code to tip off
78 // `google-readability-function-size` is the proc macros, so ignore the lint.
79
80 if (!resolver) {
81 return;
82 }
83
84 resolver = WrappedResolver(resolver);
85
86 auto error_fn = reinterpret_cast<PFNGLGETERRORPROC>(resolver("glGetError"));
87 if (!error_fn) {
88 VALIDATION_LOG << "Could not resolve " << "glGetError";
89 return;
90 }
91
92 #define IMPELLER_PROC(proc_ivar) \
93 if (auto fn_ptr = resolver(proc_ivar.name.data())) { \
94 proc_ivar.function = \
95 reinterpret_cast<decltype(proc_ivar.function)>(fn_ptr); \
96 proc_ivar.error_fn = error_fn; \
97 } else { \
98 VALIDATION_LOG << "Could not resolve " << proc_ivar.name; \
99 return; \
100 }
101
102 FOR_EACH_IMPELLER_PROC(IMPELLER_PROC);
103
104 description_ = std::make_unique<DescriptionGLES>(*this);
105
106 if (!description_->IsValid()) {
107 return;
108 }
109
110 if (description_->IsES()) {
111 FOR_EACH_IMPELLER_ES_ONLY_PROC(IMPELLER_PROC);
112 } else {
113 FOR_EACH_IMPELLER_DESKTOP_ONLY_PROC(IMPELLER_PROC);
114 }
115
116 #undef IMPELLER_PROC
117
118 #define IMPELLER_PROC(proc_ivar) \
119 if (auto fn_ptr = resolver(proc_ivar.name.data())) { \
120 proc_ivar.function = \
121 reinterpret_cast<decltype(proc_ivar.function)>(fn_ptr); \
122 proc_ivar.error_fn = error_fn; \
123 }
124
125 if (description_->GetGlVersion().IsAtLeast(Version(3))) {
126 FOR_EACH_IMPELLER_GLES3_PROC(IMPELLER_PROC);
127 }
128
129 FOR_EACH_IMPELLER_EXT_PROC(IMPELLER_PROC);
130
131 #undef IMPELLER_PROC
132
133 if (!IP_ENABLE_GLES_LABELING || !description_->HasDebugExtension()) {
134 PushDebugGroupKHR.Reset();
135 PopDebugGroupKHR.Reset();
136 ObjectLabelKHR.Reset();
137 } else {
138 GetIntegerv(GL_MAX_LABEL_LENGTH_KHR, &debug_label_max_length_);
139 }
140
141 if (!description_->HasExtension("GL_EXT_discard_framebuffer")) {
142 DiscardFramebufferEXT.Reset();
143 }
144
145 if (!description_->HasExtension("GL_ANGLE_framebuffer_blit")) {
146 BlitFramebufferANGLE.Reset();
147 }
148
149 capabilities_ = std::make_shared<CapabilitiesGLES>(*this);
150
151 is_valid_ = true;
152 }
impeller::ProcTableGLES::FOR_EACH_IMPELLER_ES_ONLY_PROC
FOR_EACH_IMPELLER_ES_ONLY_PROC(IMPELLER_PROC)
impeller::ProcTableGLES::FOR_EACH_IMPELLER_GLES3_PROC
FOR_EACH_IMPELLER_GLES3_PROC(IMPELLER_PROC)
impeller::ProcTableGLES::FOR_EACH_IMPELLER_DESKTOP_ONLY_PROC
FOR_EACH_IMPELLER_DESKTOP_ONLY_PROC(IMPELLER_PROC)
impeller::ProcTableGLES::FOR_EACH_IMPELLER_PROC
FOR_EACH_IMPELLER_PROC(IMPELLER_PROC)
impeller::ProcTableGLES::FOR_EACH_IMPELLER_EXT_PROC
FOR_EACH_IMPELLER_EXT_PROC(IMPELLER_PROC)
impeller::WrappedResolver
ProcTableGLES::Resolver WrappedResolver(const ProcTableGLES::Resolver &resolver)
Definition: proc_table_gles.cc:53
IMPELLER_PROC
#define IMPELLER_PROC(proc_ivar)
IP_ENABLE_GLES_LABELING
#define IP_ENABLE_GLES_LABELING
Enable to allow GLES to push/pop labels for usage in GPU traces.
Definition: proc_table_gles.h:20
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:91

References FOR_EACH_IMPELLER_DESKTOP_ONLY_PROC(), FOR_EACH_IMPELLER_ES_ONLY_PROC(), FOR_EACH_IMPELLER_EXT_PROC(), FOR_EACH_IMPELLER_GLES3_PROC(), FOR_EACH_IMPELLER_PROC(), IMPELLER_PROC, IP_ENABLE_GLES_LABELING, VALIDATION_LOG, and impeller::WrappedResolver().

## ◆ ProcTableGLES() [2/2]

impeller::ProcTableGLES::ProcTableGLES | ( | ProcTableGLES && | other | ) |
| default

## ◆ ~ProcTableGLES()

impeller::ProcTableGLES::~ProcTableGLES | ( |  | ) |
| default

## Member Function Documentation

## ◆ CheckFramebufferStatusDebug()

GLenum impeller::ProcTableGLES::CheckFramebufferStatusDebug | ( | GLenum | target | ) | const

Definition at line 450 of file proc_table_gles.cc.

450 {
451 #ifdef IMPELLER_DEBUG
452 return CheckFramebufferStatus(target);
453 #endif
454 return GL_FRAMEBUFFER_COMPLETE;
455 };

## ◆ ComputeShaderWithDefines()

std::optional< std::string > impeller::ProcTableGLES::ComputeShaderWithDefines | ( | const fml::Mapping & | mapping,
|  | const std::vector< Scalar > & | defines
| ) |  | const

Definition at line 184 of file proc_table_gles.cc.

186 {
187 std::string shader_source = std::string{
188 reinterpret_cast<const char*>(mapping.GetMapping()), mapping.GetSize()};
189
190 // Look for the first newline after the '#version' header, which impellerc
191 // will always emit as the first line of a compiled shader.
192 size_t index = shader_source.find('\n');
193 if (index == std::string::npos) {
194 VALIDATION_LOG << "Failed to append constant data to shader";
195 return std::nullopt;
196 }
197
198 std::stringstream ss;
199 ss << std::fixed;
200 for (auto i = 0u; i < defines.size(); i++) {
201 ss << "#define SPIRV_CROSS_CONSTANT_ID_" << i << " " << defines[i] << '\n';
202 }
203 auto define_string = ss.str();
204 shader_source.insert(index + 1, define_string);
205 return shader_source;
206 }

References VALIDATION_LOG.

Referenced by ShaderSourceMapping().

## ◆ DescribeCurrentFramebuffer()

std::string impeller::ProcTableGLES::DescribeCurrentFramebuffer | ( |  | ) | const

Definition at line 277 of file proc_table_gles.cc.

277 {
278 GLint framebuffer = GL_NONE;
279 GetIntegerv(GL_FRAMEBUFFER_BINDING, &framebuffer);
280 if (framebuffer == GL_NONE) {
281 return "The default framebuffer (FBO0) was bound.";
282 }
283 if (IsFramebuffer(framebuffer) == GL_FALSE) {
284 return std::format(
285 "The framebuffer binding ({}) was not a valid framebuffer.",
286 framebuffer);
287 }
288
289 GLenum status = CheckFramebufferStatus(GL_FRAMEBUFFER);
290 std::stringstream stream;
291 stream << "FBO "
292 << ((framebuffer == GL_NONE) ? "(Default)"
293 : std::to_string(framebuffer))
294 << ": " << FramebufferStatusToString(status) << std::endl;
295 if (IsCurrentFramebufferComplete()) {
296 stream << "Framebuffer is complete." << std::endl;
297 } else {
298 stream << "Framebuffer is incomplete." << std::endl;
299 }
300 stream << "Description: " << std::endl;
301 stream << "Color Attachment: "
302 << DescribeFramebufferAttachment(*this, GL_COLOR_ATTACHMENT0)
303 << std::endl;
304 stream << "Depth Attachment: "
305 << DescribeFramebufferAttachment(*this, GL_DEPTH_ATTACHMENT)
306 << std::endl;
307 stream << "Stencil Attachment: "
308 << DescribeFramebufferAttachment(*this, GL_STENCIL_ATTACHMENT)
309 << std::endl;
310 return stream.str();
311 }
impeller::ProcTableGLES::IsCurrentFramebufferComplete
bool IsCurrentFramebufferComplete() const
Definition: proc_table_gles.cc:313
impeller::FramebufferStatusToString
static const char * FramebufferStatusToString(GLenum status)
Definition: proc_table_gles.cc:217
impeller::DescribeFramebufferAttachment
static std::string DescribeFramebufferAttachment(const ProcTableGLES &gl, GLenum attachment)
Definition: proc_table_gles.cc:251

References impeller::DescribeFramebufferAttachment(), impeller::FramebufferStatusToString(), and IsCurrentFramebufferComplete().

## ◆ FOR_EACH_IMPELLER_DESKTOP_ONLY_PROC()

impeller::ProcTableGLES::FOR_EACH_IMPELLER_DESKTOP_ONLY_PROC | ( | IMPELLER_PROC |  | ) |

Referenced by ProcTableGLES().

## ◆ FOR_EACH_IMPELLER_ES_ONLY_PROC()

impeller::ProcTableGLES::FOR_EACH_IMPELLER_ES_ONLY_PROC | ( | IMPELLER_PROC |  | ) |

Referenced by ProcTableGLES().

## ◆ FOR_EACH_IMPELLER_EXT_PROC()

impeller::ProcTableGLES::FOR_EACH_IMPELLER_EXT_PROC | ( | IMPELLER_PROC |  | ) |

Referenced by ProcTableGLES().

## ◆ FOR_EACH_IMPELLER_GLES3_PROC()

impeller::ProcTableGLES::FOR_EACH_IMPELLER_GLES3_PROC | ( | IMPELLER_PROC |  | ) |

Referenced by ProcTableGLES().

## ◆ FOR_EACH_IMPELLER_PROC()

impeller::ProcTableGLES::FOR_EACH_IMPELLER_PROC | ( | IMPELLER_PROC |  | ) |

Referenced by ProcTableGLES().

## ◆ GetCapabilities()

const std::shared_ptr< const CapabilitiesGLES > & impeller::ProcTableGLES::GetCapabilities | ( |  | ) | const

Definition at line 212 of file proc_table_gles.cc.

213 {
214 return capabilities_;
215 }

Referenced by impeller::BufferBindingsGLES::BindVertexAttributes(), impeller::SamplerGLES::ConfigureBoundTexture(), and impeller::BufferBindingsGLES::UnbindVertexAttributes().

## ◆ GetDescription()

const DescriptionGLES * impeller::ProcTableGLES::GetDescription | ( |  | ) | const

Definition at line 208 of file proc_table_gles.cc.

208 {
209 return description_.get();
210 }

Referenced by impeller::CapabilitiesGLES::CapabilitiesGLES(), impeller::GPUTracerGLES::GPUTracerGLES(), and impeller::BufferBindingsGLES::ReadUniformsBindings().

## ◆ GetProgramInfoLogString()

std::string impeller::ProcTableGLES::GetProgramInfoLogString | ( | GLuint | program | ) | const

Definition at line 426 of file proc_table_gles.cc.

426 {
427 GLint length = 0;
428 GetProgramiv(program, GL_INFO_LOG_LENGTH, &length);
429 if (length <= 0) {
430 return "";
431 }
432
433 length = std::min<GLint>(length, 1024);
434 Allocation allocation;
435 if (!allocation.Truncate(Bytes{length}, false)) {
436 return "";
437 }
438 GetProgramInfoLog(program, // program
439 length, // max length
440 &length, // length written (excluding NULL terminator)
441 reinterpret_cast<GLchar*>(allocation.GetBuffer()) // buffer
442 );
443 if (length <= 0) {
444 return "";
445 }
446 return std::string{reinterpret_cast<const char*>(allocation.GetBuffer()),
447 static_cast<size_t>(length)};
448 }
impeller::Bytes
AllocationSize< 1u > Bytes
Definition: allocation_size.h:129

References impeller::Allocation::GetBuffer(), and impeller::Allocation::Truncate().

## ◆ IsCurrentFramebufferComplete()

bool impeller::ProcTableGLES::IsCurrentFramebufferComplete | ( |  | ) | const

Definition at line 313 of file proc_table_gles.cc.

313 {
314 GLint framebuffer = GL_NONE;
315 GetIntegerv(GL_FRAMEBUFFER_BINDING, &framebuffer);
316 if (IsFramebuffer(framebuffer) == GL_FALSE) {
317 // The default framebuffer is always complete.
318 return true;
319 }
320 GLenum status = CheckFramebufferStatus(GL_FRAMEBUFFER);
321 return status == GL_FRAMEBUFFER_COMPLETE;
322 }

Referenced by DescribeCurrentFramebuffer().

## ◆ IsValid()

bool impeller::ProcTableGLES::IsValid | ( |  | ) | const

Definition at line 156 of file proc_table_gles.cc.

156 {
157 return is_valid_;
158 }

## ◆ PopDebugGroup()

void impeller::ProcTableGLES::PopDebugGroup | ( |  | ) | const

Definition at line 416 of file proc_table_gles.cc.

416 {
417 #ifdef IMPELLER_DEBUG
418 if (debug_label_max_length_ <= 0) {
419 return;
420 }
421
422 PopDebugGroupKHR();
423 #endif // IMPELLER_DEBUG
424 }

## ◆ PushDebugGroup()

void impeller::ProcTableGLES::PushDebugGroup | ( | const std::string & | string | ) | const

Definition at line 399 of file proc_table_gles.cc.

399 {
400 #ifdef IMPELLER_DEBUG
401 if (debug_label_max_length_ <= 0) {
402 return;
403 }
404
405 UniqueID id;
406 const auto label_length =
407 std::min<GLsizei>(debug_label_max_length_ - 1, label.size());
408 PushDebugGroupKHR(GL_DEBUG_SOURCE_APPLICATION_KHR, // source
409 static_cast<GLuint>(id.id), // id
410 label_length, // length
411 label.data() // message
412 );
413 #endif // IMPELLER_DEBUG
414 }

Referenced by impeller::EncodeCommandsInReactor().

## ◆ SetDebugLabel()

bool impeller::ProcTableGLES::SetDebugLabel | ( | DebugResourceType | type,
|  | GLint | name,
|  | std::string_view | label
| ) |  | const

Definition at line 376 of file proc_table_gles.cc.

378 {
379 if (!SupportsDebugLabels()) {
380 return true;
381 }
382 if (!ResourceIsLive(*this, type, name)) {
383 return false;
384 }
385 const auto identifier = ToDebugIdentifier(type);
386 const auto label_length =
387 std::min<GLsizei>(debug_label_max_length_ - 1, label.size());
388 if (!identifier.has_value()) {
389 return true;
390 }
391 ObjectLabelKHR(identifier.value(), // identifier
392 name, // name
393 label_length, // length
394 label.data() // label
395 );
396 return true;
397 }
type
GLenum type
Definition: blit_command_gles.cc:153
impeller::ProcTableGLES::SupportsDebugLabels
bool SupportsDebugLabels() const
Definition: proc_table_gles.cc:366
impeller::ToDebugIdentifier
static std::optional< GLenum > ToDebugIdentifier(DebugResourceType type)
Definition: proc_table_gles.cc:324
impeller::ResourceIsLive
static bool ResourceIsLive(const ProcTableGLES &gl, DebugResourceType type, GLint name)
Definition: proc_table_gles.cc:344

References impeller::ResourceIsLive(), SupportsDebugLabels(), impeller::ToDebugIdentifier(), and type.

## ◆ ShaderSourceMapping()

void impeller::ProcTableGLES::ShaderSourceMapping | ( | GLuint | shader,
|  | const fml::Mapping & | mapping,
|  | const std::vector< Scalar > & | defines = `{}`
| ) |  | const

Set the source for the attached [shader].

Optionally, [defines] may contain a string value that will be append to the shader source after the version marker. This can be used to support static specialization. For example, setting "#define Foo 1".

Definition at line 160 of file proc_table_gles.cc.

163 {
164 if (defines.empty()) {
165 const GLchar* sources[] = {
166 reinterpret_cast<const GLchar*>(mapping.GetMapping())};
167 const GLint lengths[] = {static_cast<GLint>(mapping.GetSize())};
168 ShaderSource(shader, 1u, sources, lengths);
169 return;
170 }
171 const auto& shader_source = ComputeShaderWithDefines(mapping, defines);
172 if (!shader_source.has_value()) {
173 VALIDATION_LOG << "Failed to append constant data to shader";
174 return;
175 }
176
177 const GLchar* sources[] = {
178 reinterpret_cast<const GLchar*>(shader_source->c_str())};
179 const GLint lengths[] = {static_cast<GLint>(shader_source->size())};
180 ShaderSource(shader, 1u, sources, lengths);
181 }
impeller::ProcTableGLES::ComputeShaderWithDefines
std::optional< std::string > ComputeShaderWithDefines(const fml::Mapping &mapping, const std::vector< Scalar > &defines) const
Definition: proc_table_gles.cc:184

References ComputeShaderWithDefines(), and VALIDATION_LOG.

## ◆ SupportsDebugLabels()

bool impeller::ProcTableGLES::SupportsDebugLabels | ( |  | ) | const

Definition at line 366 of file proc_table_gles.cc.

366 {
367 if (debug_label_max_length_ <= 0) {
368 return false;
369 }
370 if (!ObjectLabelKHR.IsAvailable()) {
371 return false;
372 }
373 return true;
374 }

Referenced by SetDebugLabel().

The documentation for this class was generated from the following files:

- impeller/renderer/backend/gles/proc_table_gles.h
- impeller/renderer/backend/gles/proc_table_gles.cc