Signed-off-by: Rob Clark <robdcl...@gmail.com> --- So, I think this is correct, but somehow with GLES I don't seem to get the shaders pre-compiled, so I don't get any output stats. So I suspect some fix is needed on the mesa side of things. Hints welcome, if anyone has some idea. It would be really useful to shader-db some GLES shaders since that gives me something I can compare to blob driver ;-)
run.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 69 insertions(+), 8 deletions(-) diff --git a/run.c b/run.c index 20a0a6a..2df42a6 100644 --- a/run.c +++ b/run.c @@ -57,8 +57,10 @@ struct context_info { }; enum shader_type { + TYPE_NONE, TYPE_CORE, TYPE_COMPAT, + TYPE_ES, TYPE_VP, TYPE_FP, }; @@ -100,6 +102,7 @@ extension_in_string(const char *haystack, const char *needle) static struct shader * get_shaders(const struct context_info *core, const struct context_info *compat, + const struct context_info *es, const char *text, size_t text_size, enum shader_type *type, unsigned *num_shaders, bool *use_separate_shader_objects, @@ -108,6 +111,7 @@ get_shaders(const struct context_info *core, const struct context_info *compat, static const char *req = "[require]"; static const char *gl_req = "\nGL >= "; static const char *glsl_req = "\nGLSL >= "; + static const char *glsl_es_req = "\nGLSL ES >= "; static const char *fp_req = "\nGL_ARB_fragment_program"; static const char *vp_req = "\nGL_ARB_vertex_program"; static const char *sso_req = "\nSSO ENABLED"; @@ -153,6 +157,18 @@ get_shaders(const struct context_info *core, const struct context_info *compat, } *type = TYPE_CORE; } + } else if (memcmp(text, glsl_es_req, strlen(glsl_es_req)) == 0) { + text += strlen(glsl_es_req); + long major = strtol(text, (char **)&text, 10); + long minor = strtol(text + 1, (char **)&text, 10); + long version = major * 100 + minor; + + if (unlikely(version > es->max_glsl_version)) { + fprintf(stderr, "SKIP: %s requires GLSL ES %ld\n", + shader_name, version); + return NULL; + } + *type = TYPE_ES; } else if (memcmp(text, fp_req, strlen(fp_req)) == 0) { *type = TYPE_FP; } else if (memcmp(text, vp_req, strlen(vp_req)) == 0) { @@ -360,9 +376,13 @@ static void addenv(const char *name, const char *value) static int get_glsl_version(void) { + const char *es_prefix = "OpenGL ES GLSL ES "; const char *ver = glGetString(GL_SHADING_LANGUAGE_VERSION); unsigned major = 0, minor = 0; + if (strstr(ver, es_prefix) == ver) + ver += strlen(es_prefix); + sscanf(ver, "%u.%u", &major, &minor); return major * 100 + minor; } @@ -507,9 +527,34 @@ main(int argc, char **argv) ret = -1; goto egl_terminate; } - eglBindAPI(EGL_OPENGL_API); - static struct context_info core = { 0 }, compat = { 0 }; + static struct context_info core = { 0 }, compat = { 0 }, es = { 0 }; + + static const EGLint es_attribs[] = { + EGL_CONTEXT_CLIENT_VERSION, 2, + EGL_NONE + }; + + eglBindAPI(EGL_OPENGL_ES_API); + + EGLContext es_ctx = eglCreateContext(egl_dpy, cfg, EGL_NO_CONTEXT, + es_attribs); + if (es_ctx != EGL_NO_CONTEXT && + eglMakeCurrent(egl_dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, es_ctx)) { + + es.extension_string = (char *)glGetString(GL_EXTENSIONS); + es.extension_string_len = strlen(es.extension_string); + + es.max_glsl_version = get_glsl_version(); + + if (!extension_in_string(es.extension_string, "GL_KHR_debug")) { + fprintf(stderr, "ERROR: Missing GL_KHR_debug\n"); + ret = -1; + goto egl_terminate; + } + } + + eglBindAPI(EGL_OPENGL_API); static const EGLint attribs[] = { EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR, @@ -647,7 +692,7 @@ main(int argc, char **argv) exit(-1); } - bool ctx_is_core = false; + enum shader_type current_type = TYPE_NONE; if (!eglMakeCurrent(egl_dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, compat_ctx)) { fprintf(stderr, "ERROR: eglMakeCurrent() failed\n"); @@ -688,7 +733,7 @@ main(int argc, char **argv) enum shader_type type; unsigned num_shaders; bool use_separate_shader_objects; - struct shader *shader = get_shaders(&core, &compat, + struct shader *shader = get_shaders(&core, &compat, &es, text, shader_test[i].filesize, &type, &num_shaders, &use_separate_shader_objects, @@ -697,15 +742,30 @@ main(int argc, char **argv) continue; } - if (ctx_is_core != (type == TYPE_CORE)) { + if (current_type != type) { + EGLContext ctx; + ctx_switches++; + + switch (type) { + case TYPE_ES: + ctx = es_ctx; + break; + case TYPE_CORE: + ctx = core_ctx; + break; + default: + ctx = compat_ctx; + break; + } + if (!eglMakeCurrent(egl_dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, - type == TYPE_CORE ? core_ctx : compat_ctx)) { + ctx)) { fprintf(stderr, "ERROR: eglMakeCurrent() failed\n"); continue; } } - ctx_is_core = type == TYPE_CORE; + current_type = type; /* If there's only one GLSL shader, mark it separable so * inputs and outputs aren't eliminated. @@ -731,7 +791,7 @@ main(int argc, char **argv) glDeleteProgram(prog); free(text); } - } else if (type == TYPE_CORE || type == TYPE_COMPAT) { + } else if (type == TYPE_CORE || type == TYPE_COMPAT || type == TYPE_ES) { GLuint prog = glCreateProgram(); for (unsigned i = 0; i < num_shaders; i++) { @@ -784,6 +844,7 @@ main(int argc, char **argv) eglDestroyContext(egl_dpy, compat_ctx); eglDestroyContext(egl_dpy, core_ctx); + eglDestroyContext(egl_dpy, es_ctx); eglReleaseThread(); clock_gettime(CLOCK_THREAD_CPUTIME_ID, &end); -- 2.14.3 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev