Commit f919b866 by Krzysztof Kosiński

Implement EGL_KHR_get_all_proc_addresses.

This also improves GetProcAddress performance by using binary search instead of linear search. Fixes bug b/20110899 Change-Id: I6c58e17f0580904338e4d806e310cccbec398f28 Reviewed-on: https://swiftshader-review.googlesource.com/15748Tested-by: 's avatarKrzysztof Kosiński <krzysio@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent 423377e7
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "Main/libX11.hpp" #include "Main/libX11.hpp"
#endif #endif
#include <algorithm>
#include <string.h> #include <string.h>
using namespace egl; using namespace egl;
...@@ -174,6 +175,7 @@ const char *QueryString(EGLDisplay dpy, EGLint name) ...@@ -174,6 +175,7 @@ const char *QueryString(EGLDisplay dpy, EGLint name)
if(dpy == EGL_NO_DISPLAY && name == EGL_EXTENSIONS) if(dpy == EGL_NO_DISPLAY && name == EGL_EXTENSIONS)
{ {
return success( return success(
"EGL_KHR_client_get_all_proc_addresses "
#if defined(__linux__) && !defined(__ANDROID__) #if defined(__linux__) && !defined(__ANDROID__)
"EGL_KHR_platform_gbm " "EGL_KHR_platform_gbm "
"EGL_KHR_platform_x11 " "EGL_KHR_platform_x11 "
...@@ -195,6 +197,7 @@ const char *QueryString(EGLDisplay dpy, EGLint name) ...@@ -195,6 +197,7 @@ const char *QueryString(EGLDisplay dpy, EGLint name)
return success("OpenGL_ES"); return success("OpenGL_ES");
case EGL_EXTENSIONS: case EGL_EXTENSIONS:
return success("EGL_KHR_create_context " return success("EGL_KHR_create_context "
"EGL_KHR_get_all_proc_addresses "
"EGL_KHR_gl_texture_2D_image " "EGL_KHR_gl_texture_2D_image "
"EGL_KHR_gl_texture_cubemap_image " "EGL_KHR_gl_texture_cubemap_image "
"EGL_KHR_gl_renderbuffer_image " "EGL_KHR_gl_renderbuffer_image "
...@@ -1241,34 +1244,85 @@ __eglMustCastToProperFunctionPointerType GetProcAddress(const char *procname) ...@@ -1241,34 +1244,85 @@ __eglMustCastToProperFunctionPointerType GetProcAddress(const char *procname)
{ {
TRACE("(const char *procname = \"%s\")", procname); TRACE("(const char *procname = \"%s\")", procname);
struct Extension struct Function
{ {
const char *name; const char *name;
__eglMustCastToProperFunctionPointerType address; __eglMustCastToProperFunctionPointerType address;
}; };
static const Extension eglExtensions[] = struct CompareFunctor
{ {
#define EXTENSION(name) {#name, (__eglMustCastToProperFunctionPointerType)name} bool operator()(const Function &a, const Function &b) const
{
EXTENSION(eglCreateImageKHR), return strcmp(a.name, b.name) < 0;
EXTENSION(eglDestroyImageKHR), }
EXTENSION(eglGetPlatformDisplayEXT), };
EXTENSION(eglCreatePlatformWindowSurfaceEXT),
EXTENSION(eglCreatePlatformPixmapSurfaceEXT),
EXTENSION(eglCreateSyncKHR),
EXTENSION(eglDestroySyncKHR),
EXTENSION(eglClientWaitSyncKHR),
EXTENSION(eglGetSyncAttribKHR),
#undef EXTENSION // This array must be kept sorted with respect to strcmp(), so that binary search works correctly.
// The Unix command "LC_COLLATE=C sort" will generate the correct order.
static const Function eglFunctions[] =
{
#define FUNCTION(name) {#name, (__eglMustCastToProperFunctionPointerType)name}
FUNCTION(eglBindAPI),
FUNCTION(eglBindTexImage),
FUNCTION(eglChooseConfig),
FUNCTION(eglClientWaitSyncKHR),
FUNCTION(eglCopyBuffers),
FUNCTION(eglCreateContext),
FUNCTION(eglCreateImageKHR),
FUNCTION(eglCreatePbufferFromClientBuffer),
FUNCTION(eglCreatePbufferSurface),
FUNCTION(eglCreatePixmapSurface),
FUNCTION(eglCreatePlatformPixmapSurfaceEXT),
FUNCTION(eglCreatePlatformWindowSurfaceEXT),
FUNCTION(eglCreateSyncKHR),
FUNCTION(eglCreateWindowSurface),
FUNCTION(eglDestroyContext),
FUNCTION(eglDestroyImageKHR),
FUNCTION(eglDestroySurface),
FUNCTION(eglDestroySyncKHR),
FUNCTION(eglGetConfigAttrib),
FUNCTION(eglGetConfigs),
FUNCTION(eglGetCurrentContext),
FUNCTION(eglGetCurrentDisplay),
FUNCTION(eglGetCurrentSurface),
FUNCTION(eglGetDisplay),
FUNCTION(eglGetError),
FUNCTION(eglGetPlatformDisplayEXT),
FUNCTION(eglGetProcAddress),
FUNCTION(eglGetSyncAttribKHR),
FUNCTION(eglInitialize),
FUNCTION(eglMakeCurrent),
FUNCTION(eglQueryAPI),
FUNCTION(eglQueryContext),
FUNCTION(eglQueryString),
FUNCTION(eglQuerySurface),
FUNCTION(eglReleaseTexImage),
FUNCTION(eglReleaseThread),
FUNCTION(eglSurfaceAttrib),
FUNCTION(eglSwapBuffers),
FUNCTION(eglSwapInterval),
FUNCTION(eglTerminate),
FUNCTION(eglWaitClient),
FUNCTION(eglWaitGL),
FUNCTION(eglWaitNative),
#undef FUNCTION
}; };
for(unsigned int ext = 0; ext < sizeof(eglExtensions) / sizeof(Extension); ext++) static const size_t numFunctions = sizeof eglFunctions / sizeof(Function);
static const Function *const eglFunctionsEnd = eglFunctions + numFunctions;
Function needle;
needle.name = procname;
if(procname && strncmp("egl", procname, 3) == 0)
{ {
if(strcmp(procname, eglExtensions[ext].name) == 0) const Function *result = std::lower_bound(eglFunctions, eglFunctionsEnd, needle, CompareFunctor());
if (result != eglFunctionsEnd && strcmp(procname, result->name) == 0)
{ {
return success((__eglMustCastToProperFunctionPointerType)eglExtensions[ext].address); return success((__eglMustCastToProperFunctionPointerType)result->address);
} }
} }
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include <GLES/gl.h> #include <GLES/gl.h>
#include <GLES/glext.h> #include <GLES/glext.h>
#include <algorithm>
#include <limits> #include <limits>
namespace es1 namespace es1
...@@ -4727,46 +4728,215 @@ void DrawTexfvOES(const GLfloat *coords) ...@@ -4727,46 +4728,215 @@ void DrawTexfvOES(const GLfloat *coords)
extern "C" __eglMustCastToProperFunctionPointerType es1GetProcAddress(const char *procname) extern "C" __eglMustCastToProperFunctionPointerType es1GetProcAddress(const char *procname)
{ {
struct Extension struct Function
{ {
const char *name; const char *name;
__eglMustCastToProperFunctionPointerType address; __eglMustCastToProperFunctionPointerType address;
}; };
static const Extension glExtensions[] = struct CompareFunctor
{ {
#define EXTENSION(name) {#name, (__eglMustCastToProperFunctionPointerType)name} bool operator()(const Function &a, const Function &b) const
{
EXTENSION(glEGLImageTargetTexture2DOES), return strcmp(a.name, b.name) < 0;
EXTENSION(glEGLImageTargetRenderbufferStorageOES), }
EXTENSION(glIsRenderbufferOES),
EXTENSION(glBindRenderbufferOES),
EXTENSION(glDeleteRenderbuffersOES),
EXTENSION(glGenRenderbuffersOES),
EXTENSION(glRenderbufferStorageOES),
EXTENSION(glGetRenderbufferParameterivOES),
EXTENSION(glIsFramebufferOES),
EXTENSION(glBindFramebufferOES),
EXTENSION(glDeleteFramebuffersOES),
EXTENSION(glGenFramebuffersOES),
EXTENSION(glCheckFramebufferStatusOES),
EXTENSION(glFramebufferRenderbufferOES),
EXTENSION(glFramebufferTexture2DOES),
EXTENSION(glGetFramebufferAttachmentParameterivOES),
EXTENSION(glGenerateMipmapOES),
EXTENSION(glBlendEquationOES),
EXTENSION(glBlendEquationSeparateOES),
EXTENSION(glBlendFuncSeparateOES),
EXTENSION(glPointSizePointerOES),
#undef EXTENSION
}; };
for(unsigned int ext = 0; ext < sizeof(glExtensions) / sizeof(Extension); ext++) // This array must be kept sorted with respect to strcmp(), so that binary search works correctly.
// The Unix command "LC_COLLATE=C sort" will generate the correct order.
static const Function glFunctions[] =
{
#define FUNCTION(name) {#name, (__eglMustCastToProperFunctionPointerType)name}
FUNCTION(glActiveTexture),
FUNCTION(glAlphaFunc),
FUNCTION(glAlphaFuncx),
FUNCTION(glBindBuffer),
FUNCTION(glBindFramebufferOES),
FUNCTION(glBindRenderbufferOES),
FUNCTION(glBindTexture),
FUNCTION(glBlendEquationOES),
FUNCTION(glBlendEquationSeparateOES),
FUNCTION(glBlendFunc),
FUNCTION(glBlendFuncSeparateOES),
FUNCTION(glBufferData),
FUNCTION(glBufferSubData),
FUNCTION(glCheckFramebufferStatusOES),
FUNCTION(glClear),
FUNCTION(glClearColor),
FUNCTION(glClearColorx),
FUNCTION(glClearDepthf),
FUNCTION(glClearDepthx),
FUNCTION(glClearStencil),
FUNCTION(glClientActiveTexture),
FUNCTION(glClipPlanef),
FUNCTION(glClipPlanex),
FUNCTION(glColor4f),
FUNCTION(glColor4ub),
FUNCTION(glColor4x),
FUNCTION(glColorMask),
FUNCTION(glColorPointer),
FUNCTION(glCompressedTexImage2D),
FUNCTION(glCompressedTexSubImage2D),
FUNCTION(glCopyTexImage2D),
FUNCTION(glCopyTexSubImage2D),
FUNCTION(glCullFace),
FUNCTION(glDeleteBuffers),
FUNCTION(glDeleteFramebuffersOES),
FUNCTION(glDeleteRenderbuffersOES),
FUNCTION(glDeleteTextures),
FUNCTION(glDepthFunc),
FUNCTION(glDepthMask),
FUNCTION(glDepthRangef),
FUNCTION(glDepthRangex),
FUNCTION(glDisable),
FUNCTION(glDisableClientState),
FUNCTION(glDrawArrays),
FUNCTION(glDrawElements),
FUNCTION(glDrawTexfOES),
FUNCTION(glDrawTexfvOES),
FUNCTION(glDrawTexiOES),
FUNCTION(glDrawTexivOES),
FUNCTION(glDrawTexsOES),
FUNCTION(glDrawTexsvOES),
FUNCTION(glDrawTexxOES),
FUNCTION(glDrawTexxvOES),
FUNCTION(glEGLImageTargetRenderbufferStorageOES),
FUNCTION(glEGLImageTargetTexture2DOES),
FUNCTION(glEnable),
FUNCTION(glEnableClientState),
FUNCTION(glFinish),
FUNCTION(glFlush),
FUNCTION(glFogf),
FUNCTION(glFogfv),
FUNCTION(glFogx),
FUNCTION(glFogxv),
FUNCTION(glFramebufferRenderbufferOES),
FUNCTION(glFramebufferTexture2DOES),
FUNCTION(glFrontFace),
FUNCTION(glFrustumf),
FUNCTION(glFrustumx),
FUNCTION(glGenBuffers),
FUNCTION(glGenFramebuffersOES),
FUNCTION(glGenRenderbuffersOES),
FUNCTION(glGenTextures),
FUNCTION(glGenerateMipmapOES),
FUNCTION(glGetBooleanv),
FUNCTION(glGetBufferParameteriv),
FUNCTION(glGetClipPlanef),
FUNCTION(glGetClipPlanex),
FUNCTION(glGetError),
FUNCTION(glGetFixedv),
FUNCTION(glGetFloatv),
FUNCTION(glGetFramebufferAttachmentParameterivOES),
FUNCTION(glGetIntegerv),
FUNCTION(glGetLightfv),
FUNCTION(glGetLightxv),
FUNCTION(glGetMaterialfv),
FUNCTION(glGetMaterialxv),
FUNCTION(glGetPointerv),
FUNCTION(glGetRenderbufferParameterivOES),
FUNCTION(glGetString),
FUNCTION(glGetTexEnvfv),
FUNCTION(glGetTexEnviv),
FUNCTION(glGetTexEnvxv),
FUNCTION(glGetTexParameterfv),
FUNCTION(glGetTexParameteriv),
FUNCTION(glGetTexParameterxv),
FUNCTION(glHint),
FUNCTION(glIsBuffer),
FUNCTION(glIsEnabled),
FUNCTION(glIsFramebufferOES),
FUNCTION(glIsRenderbufferOES),
FUNCTION(glIsTexture),
FUNCTION(glLightModelf),
FUNCTION(glLightModelfv),
FUNCTION(glLightModelx),
FUNCTION(glLightModelxv),
FUNCTION(glLightf),
FUNCTION(glLightfv),
FUNCTION(glLightx),
FUNCTION(glLightxv),
FUNCTION(glLineWidth),
FUNCTION(glLineWidthx),
FUNCTION(glLoadIdentity),
FUNCTION(glLoadMatrixf),
FUNCTION(glLoadMatrixx),
FUNCTION(glLogicOp),
FUNCTION(glMaterialf),
FUNCTION(glMaterialfv),
FUNCTION(glMaterialx),
FUNCTION(glMaterialxv),
FUNCTION(glMatrixMode),
FUNCTION(glMultMatrixf),
FUNCTION(glMultMatrixx),
FUNCTION(glMultiTexCoord4f),
FUNCTION(glMultiTexCoord4x),
FUNCTION(glNormal3f),
FUNCTION(glNormal3x),
FUNCTION(glNormalPointer),
FUNCTION(glOrthof),
FUNCTION(glOrthox),
FUNCTION(glPixelStorei),
FUNCTION(glPointParameterf),
FUNCTION(glPointParameterfv),
FUNCTION(glPointParameterx),
FUNCTION(glPointParameterxv),
FUNCTION(glPointSize),
FUNCTION(glPointSizePointerOES),
FUNCTION(glPointSizex),
FUNCTION(glPolygonOffset),
FUNCTION(glPolygonOffsetx),
FUNCTION(glPopMatrix),
FUNCTION(glPushMatrix),
FUNCTION(glReadPixels),
FUNCTION(glRenderbufferStorageOES),
FUNCTION(glRotatef),
FUNCTION(glRotatex),
FUNCTION(glSampleCoverage),
FUNCTION(glSampleCoveragex),
FUNCTION(glScalef),
FUNCTION(glScalex),
FUNCTION(glScissor),
FUNCTION(glShadeModel),
FUNCTION(glStencilFunc),
FUNCTION(glStencilMask),
FUNCTION(glStencilOp),
FUNCTION(glTexCoordPointer),
FUNCTION(glTexEnvf),
FUNCTION(glTexEnvfv),
FUNCTION(glTexEnvi),
FUNCTION(glTexEnviv),
FUNCTION(glTexEnvx),
FUNCTION(glTexEnvxv),
FUNCTION(glTexImage2D),
FUNCTION(glTexParameterf),
FUNCTION(glTexParameterfv),
FUNCTION(glTexParameteri),
FUNCTION(glTexParameteriv),
FUNCTION(glTexParameterx),
FUNCTION(glTexParameterxv),
FUNCTION(glTexSubImage2D),
FUNCTION(glTranslatef),
FUNCTION(glTranslatex),
FUNCTION(glVertexPointer),
FUNCTION(glViewport),
#undef FUNCTION
};
static const size_t numFunctions = sizeof glFunctions / sizeof(Function);
static const Function *const glFunctionsEnd = glFunctions + numFunctions;
Function needle;
needle.name = procname;
if(procname && strncmp("gl", procname, 2) == 0)
{ {
if(strcmp(procname, glExtensions[ext].name) == 0) const Function *result = std::lower_bound(glFunctions, glFunctionsEnd, needle, CompareFunctor());
if(result != glFunctionsEnd && strcmp(procname, result->name) == 0)
{ {
return (__eglMustCastToProperFunctionPointerType)glExtensions[ext].address; return (__eglMustCastToProperFunctionPointerType)result->address;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment