Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
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].
 
const DescriptionGLESGetDescription () 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 307 of file proc_table_gles.h.

Member Typedef Documentation

◆ Resolver

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

Definition at line 309 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
103
104 description_ = std::make_unique<DescriptionGLES>(*this);
105
106 if (!description_->IsValid()) {
107 return;
108 }
109
110 if (description_->IsES()) {
112 } else {
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))) {
127 }
128
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 if (!description_->HasExtension("GL_EXT_instanced_arrays")) {
150 VertexAttribDivisorEXT.Reset();
151 }
152
153 if (!description_->HasExtension("GL_EXT_draw_instanced")) {
154 DrawArraysInstancedEXT.Reset();
155 DrawElementsInstancedEXT.Reset();
156 }
157
158 capabilities_ = std::make_shared<CapabilitiesGLES>(*this);
159
160 is_valid_ = true;
161}
ProcTableGLES::Resolver WrappedResolver(const ProcTableGLES::Resolver &resolver)
#define IMPELLER_PROC(proc_ivar)
#define FOR_EACH_IMPELLER_EXT_PROC(PROC)
#define FOR_EACH_IMPELLER_GLES3_PROC(PROC)
#define FOR_EACH_IMPELLER_DESKTOP_ONLY_PROC(PROC)
#define IP_ENABLE_GLES_LABELING
Enable to allow GLES to push/pop labels for usage in GPU traces.
#define FOR_EACH_IMPELLER_ES_ONLY_PROC(PROC)
#define FOR_EACH_IMPELLER_PROC(PROC)
#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 459 of file proc_table_gles.cc.

459 {
460#ifdef IMPELLER_DEBUG
461 return CheckFramebufferStatus(target);
462#endif
463 return GL_FRAMEBUFFER_COMPLETE;
464};
uint32_t * target

References target.

◆ ComputeShaderWithDefines()

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

Definition at line 193 of file proc_table_gles.cc.

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

References fml::Mapping::GetMapping(), fml::Mapping::GetSize(), i, and VALIDATION_LOG.

Referenced by ShaderSourceMapping().

◆ DescribeCurrentFramebuffer()

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

Definition at line 286 of file proc_table_gles.cc.

286 {
287 GLint framebuffer = GL_NONE;
288 GetIntegerv(GL_FRAMEBUFFER_BINDING, &framebuffer);
289 if (framebuffer == GL_NONE) {
290 return "The default framebuffer (FBO0) was bound.";
291 }
292 if (IsFramebuffer(framebuffer) == GL_FALSE) {
293 return std::format(
294 "The framebuffer binding ({}) was not a valid framebuffer.",
295 framebuffer);
296 }
297
298 GLenum status = CheckFramebufferStatus(GL_FRAMEBUFFER);
299 std::stringstream stream;
300 stream << "FBO "
301 << ((framebuffer == GL_NONE) ? "(Default)"
302 : std::to_string(framebuffer))
303 << ": " << FramebufferStatusToString(status) << std::endl;
305 stream << "Framebuffer is complete." << std::endl;
306 } else {
307 stream << "Framebuffer is incomplete." << std::endl;
308 }
309 stream << "Description: " << std::endl;
310 stream << "Color Attachment: "
311 << DescribeFramebufferAttachment(*this, GL_COLOR_ATTACHMENT0)
312 << std::endl;
313 stream << "Depth Attachment: "
314 << DescribeFramebufferAttachment(*this, GL_DEPTH_ATTACHMENT)
315 << std::endl;
316 stream << "Stencil Attachment: "
317 << DescribeFramebufferAttachment(*this, GL_STENCIL_ATTACHMENT)
318 << std::endl;
319 return stream.str();
320}
bool IsCurrentFramebufferComplete() const
static const char * FramebufferStatusToString(GLenum status)
static std::string DescribeFramebufferAttachment(const ProcTableGLES &gl, GLenum attachment)
Definition ref_ptr.h:261

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

◆ FOR_EACH_IMPELLER_DESKTOP_ONLY_PROC()

impeller::ProcTableGLES::FOR_EACH_IMPELLER_DESKTOP_ONLY_PROC ( IMPELLER_PROC  )

◆ FOR_EACH_IMPELLER_ES_ONLY_PROC()

impeller::ProcTableGLES::FOR_EACH_IMPELLER_ES_ONLY_PROC ( IMPELLER_PROC  )

◆ FOR_EACH_IMPELLER_EXT_PROC()

impeller::ProcTableGLES::FOR_EACH_IMPELLER_EXT_PROC ( IMPELLER_PROC  )

◆ FOR_EACH_IMPELLER_GLES3_PROC()

impeller::ProcTableGLES::FOR_EACH_IMPELLER_GLES3_PROC ( IMPELLER_PROC  )

◆ FOR_EACH_IMPELLER_PROC()

impeller::ProcTableGLES::FOR_EACH_IMPELLER_PROC ( IMPELLER_PROC  )

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

435 {
436 GLint length = 0;
437 GetProgramiv(program, GL_INFO_LOG_LENGTH, &length);
438 if (length <= 0) {
439 return "";
440 }
441
442 length = std::min<GLint>(length, 1024);
443 Allocation allocation;
444 if (!allocation.Truncate(Bytes{length}, false)) {
445 return "";
446 }
447 GetProgramInfoLog(program, // program
448 length, // max length
449 &length, // length written (excluding NULL terminator)
450 reinterpret_cast<GLchar*>(allocation.GetBuffer()) // buffer
451 );
452 if (length <= 0) {
453 return "";
454 }
455 return std::string{reinterpret_cast<const char*>(allocation.GetBuffer()),
456 static_cast<size_t>(length)};
457}
size_t length
AllocationSize< 1u > Bytes

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

◆ IsCurrentFramebufferComplete()

bool impeller::ProcTableGLES::IsCurrentFramebufferComplete ( ) const

Definition at line 322 of file proc_table_gles.cc.

322 {
323 GLint framebuffer = GL_NONE;
324 GetIntegerv(GL_FRAMEBUFFER_BINDING, &framebuffer);
325 if (IsFramebuffer(framebuffer) == GL_FALSE) {
326 // The default framebuffer is always complete.
327 return true;
328 }
329 GLenum status = CheckFramebufferStatus(GL_FRAMEBUFFER);
330 return status == GL_FRAMEBUFFER_COMPLETE;
331}

Referenced by DescribeCurrentFramebuffer().

◆ IsValid()

bool impeller::ProcTableGLES::IsValid ( ) const

Definition at line 165 of file proc_table_gles.cc.

165 {
166 return is_valid_;
167}

◆ PopDebugGroup()

void impeller::ProcTableGLES::PopDebugGroup ( ) const

Definition at line 425 of file proc_table_gles.cc.

425 {
426#ifdef IMPELLER_DEBUG
427 if (debug_label_max_length_ <= 0) {
428 return;
429 }
430
431 PopDebugGroupKHR();
432#endif // IMPELLER_DEBUG
433}

◆ PushDebugGroup()

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

Definition at line 408 of file proc_table_gles.cc.

408 {
409#ifdef IMPELLER_DEBUG
410 if (debug_label_max_length_ <= 0) {
411 return;
412 }
413
414 UniqueID id;
415 const auto label_length =
416 std::min<GLsizei>(debug_label_max_length_ - 1, label.size());
417 PushDebugGroupKHR(GL_DEBUG_SOURCE_APPLICATION_KHR, // source
418 static_cast<GLuint>(id.id), // id
419 label_length, // length
420 label.data() // message
421 );
422#endif // IMPELLER_DEBUG
423}
const uintptr_t id

References id.

◆ SetDebugLabel()

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

Definition at line 385 of file proc_table_gles.cc.

387 {
388 if (!SupportsDebugLabels()) {
389 return true;
390 }
391 if (!ResourceIsLive(*this, type, name)) {
392 return false;
393 }
394 const auto identifier = ToDebugIdentifier(type);
395 const auto label_length =
396 std::min<GLsizei>(debug_label_max_length_ - 1, label.size());
397 if (!identifier.has_value()) {
398 return true;
399 }
400 ObjectLabelKHR(identifier.value(), // identifier
401 name, // name
402 label_length, // length
403 label.data() // label
404 );
405 return true;
406}
const char * name
Definition fuchsia.cc:50
static std::optional< GLenum > ToDebugIdentifier(DebugResourceType type)
static bool ResourceIsLive(const ProcTableGLES &gl, DebugResourceType type, GLint name)
impeller::ShaderType type

References name, 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 169 of file proc_table_gles.cc.

172 {
173 if (defines.empty()) {
174 const GLchar* sources[] = {
175 reinterpret_cast<const GLchar*>(mapping.GetMapping())};
176 const GLint lengths[] = {static_cast<GLint>(mapping.GetSize())};
177 ShaderSource(shader, 1u, sources, lengths);
178 return;
179 }
180 const auto& shader_source = ComputeShaderWithDefines(mapping, defines);
181 if (!shader_source.has_value()) {
182 VALIDATION_LOG << "Failed to append constant data to shader";
183 return;
184 }
185
186 const GLchar* sources[] = {
187 reinterpret_cast<const GLchar*>(shader_source->c_str())};
188 const GLint lengths[] = {static_cast<GLint>(shader_source->size())};
189 ShaderSource(shader, 1u, sources, lengths);
190}
std::optional< std::string > ComputeShaderWithDefines(const fml::Mapping &mapping, const std::vector< Scalar > &defines) const

References ComputeShaderWithDefines(), fml::Mapping::GetMapping(), fml::Mapping::GetSize(), and VALIDATION_LOG.

◆ SupportsDebugLabels()

bool impeller::ProcTableGLES::SupportsDebugLabels ( ) const

Definition at line 375 of file proc_table_gles.cc.

375 {
376 if (debug_label_max_length_ <= 0) {
377 return false;
378 }
379 if (!ObjectLabelKHR.IsAvailable()) {
380 return false;
381 }
382 return true;
383}

Referenced by SetDebugLabel().


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