| 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
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 281 of file proc_table_gles.h.

## Member Typedef Documentation

## ◆ Resolver

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

Definition at line 283 of file proc_table_gles.h.

## Constructor & Destructor Documentation

## ◆ ProcTableGLES() [1/2]

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

Definition at line 74 of file proc_table_gles.cc.

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

## ◆ ComputeShaderWithDefines()

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

Definition at line 179 of file proc_table_gles.cc.

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

References VALIDATION_LOG.

Referenced by ShaderSourceMapping().

## ◆ DescribeCurrentFramebuffer()

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

Definition at line 272 of file proc_table_gles.cc.

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

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

## ◆ 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 207 of file proc_table_gles.cc.

208 {
209 return capabilities_;
210 }

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

## ◆ GetDescription()

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

Definition at line 203 of file proc_table_gles.cc.

203 {
204 return description_.get();
205 }

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

## ◆ GetProgramInfoLogString()

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

Definition at line 420 of file proc_table_gles.cc.

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

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

## ◆ IsCurrentFramebufferComplete()

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

Definition at line 307 of file proc_table_gles.cc.

307 {
308 GLint framebuffer = GL_NONE;
309 GetIntegerv(GL_FRAMEBUFFER_BINDING, &framebuffer);
310 if (IsFramebuffer(framebuffer) == GL_FALSE) {
311 // The default framebuffer is always complete.
312 return true;
313 }
314 GLenum status = CheckFramebufferStatus(GL_FRAMEBUFFER);
315 return status == GL_FRAMEBUFFER_COMPLETE;
316 }

Referenced by DescribeCurrentFramebuffer().

## ◆ IsValid()

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

Definition at line 151 of file proc_table_gles.cc.

151 {
152 return is_valid_;
153 }

## ◆ PopDebugGroup()

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

Definition at line 410 of file proc_table_gles.cc.

410 {
411 #ifdef IMPELLER_DEBUG
412 if (debug_label_max_length_ <= 0) {
413 return;
414 }
415
416 PopDebugGroupKHR();
417 #endif // IMPELLER_DEBUG
418 }

## ◆ PushDebugGroup()

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

Definition at line 393 of file proc_table_gles.cc.

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

Referenced by impeller::EncodeCommandsInReactor().

## ◆ SetDebugLabel()

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

Definition at line 370 of file proc_table_gles.cc.

372 {
373 if (!SupportsDebugLabels()) {
374 return true;
375 }
376 if (!ResourceIsLive(*this, type, name)) {
377 return false;
378 }
379 const auto identifier = ToDebugIdentifier(type);
380 const auto label_length =
381 std::min<GLsizei>(debug_label_max_length_ - 1, label.size());
382 if (!identifier.has_value()) {
383 return true;
384 }
385 ObjectLabelKHR(identifier.value(), // identifier
386 name, // name
387 label_length, // length
388 label.data() // label
389 );
390 return true;
391 }
type
GLenum type
Definition: blit_command_gles.cc:151
impeller::ProcTableGLES::SupportsDebugLabels
bool SupportsDebugLabels() const
Definition: proc_table_gles.cc:360
impeller::ToDebugIdentifier
static std::optional< GLenum > ToDebugIdentifier(DebugResourceType type)
Definition: proc_table_gles.cc:318
impeller::ResourceIsLive
static bool ResourceIsLive(const ProcTableGLES &gl, DebugResourceType type, GLint name)
Definition: proc_table_gles.cc:338

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 155 of file proc_table_gles.cc.

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

References ComputeShaderWithDefines(), and VALIDATION_LOG.

## ◆ SupportsDebugLabels()

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

Definition at line 360 of file proc_table_gles.cc.

360 {
361 if (debug_label_max_length_ <= 0) {
362 return false;
363 }
364 if (!ObjectLabelKHR.IsAvailable()) {
365 return false;
366 }
367 return true;
368 }

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