Flutter Impeller
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 DescriptionGLESGetDescription () 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 282 of file proc_table_gles.h.

Member Typedef Documentation

◆ Resolver

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

Definition at line 284 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 
102 
103  description_ = std::make_unique<DescriptionGLES>(*this);
104 
105  if (!description_->IsValid()) {
106  return;
107  }
108 
109  if (description_->IsES()) {
111  } else {
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))) {
126  }
127 
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  if (!description_->HasExtension("GL_ANGLE_framebuffer_blit")) {
145  BlitFramebufferANGLE.Reset();
146  }
147 
148  capabilities_ = std::make_shared<CapabilitiesGLES>(*this);
149 
150  is_valid_ = true;
151 }
FOR_EACH_IMPELLER_ES_ONLY_PROC(IMPELLER_PROC)
FOR_EACH_IMPELLER_GLES3_PROC(IMPELLER_PROC)
FOR_EACH_IMPELLER_DESKTOP_ONLY_PROC(IMPELLER_PROC)
FOR_EACH_IMPELLER_PROC(IMPELLER_PROC)
FOR_EACH_IMPELLER_EXT_PROC(IMPELLER_PROC)
ProcTableGLES::Resolver WrappedResolver(const ProcTableGLES::Resolver &resolver)
#define IMPELLER_PROC(proc_ivar)
#define IP_ENABLE_GLES_LABELING
Enable to allow GLES to push/pop labels for usage in GPU traces.
#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 183 of file proc_table_gles.cc.

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

References VALIDATION_LOG.

Referenced by ShaderSourceMapping().

◆ DescribeCurrentFramebuffer()

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

Definition at line 276 of file proc_table_gles.cc.

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

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

◆ GetDescription()

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

◆ GetProgramInfoLogString()

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

Definition at line 424 of file proc_table_gles.cc.

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

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

◆ IsCurrentFramebufferComplete()

bool impeller::ProcTableGLES::IsCurrentFramebufferComplete ( ) const

Definition at line 311 of file proc_table_gles.cc.

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

Referenced by DescribeCurrentFramebuffer().

◆ IsValid()

bool impeller::ProcTableGLES::IsValid ( ) const

Definition at line 155 of file proc_table_gles.cc.

155  {
156  return is_valid_;
157 }

◆ PopDebugGroup()

void impeller::ProcTableGLES::PopDebugGroup ( ) const

Definition at line 414 of file proc_table_gles.cc.

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

◆ PushDebugGroup()

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

Definition at line 397 of file proc_table_gles.cc.

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

Referenced by impeller::EncodeCommandsInReactor().

◆ SetDebugLabel()

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

Definition at line 374 of file proc_table_gles.cc.

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

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

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

References ComputeShaderWithDefines(), and VALIDATION_LOG.

◆ SupportsDebugLabels()

bool impeller::ProcTableGLES::SupportsDebugLabels ( ) const

Definition at line 364 of file proc_table_gles.cc.

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

Referenced by SetDebugLabel().


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