This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch evas_gl_buffer_optimization
in repository efl.

View the commit online.

commit 75fe56b2ffff031d670b721b6d2a71602528db28
Author: Carsten Haitzler <ras...@rasterman.com>
AuthorDate: Tue Jan 10 20:20:50 2017 +0900

    evas gl common - move program vertext attrib arrays init to shadeer init
    
    this removes glDisableVertexAttribArray() entirely and moves
    glEnableVertexAttribArray() and glBindAttribLocation() purely to
    initial shader load/compile/init because there is no point redoing
    this all the time because they are actually bound to the program. we
    still have to determine what they point to with
    glVertexAttribPointer() as we go but this does cut it down from the
    draw path. this doesnt seem to have a measurable effect on nvidia but
    on rpi vc4 this dropped vc4's program/shader overhead thats doing
    memcmp()'s from 22% of cpu down to 14% of cpu. so the shader
    validation/cahe lookups and so on seem to scale by the more we modify
    property-wise on a shader. not pretty. seemingly no other drivers
    suffer from this that i have seen, but this is a worth speedup of
    putting right in now as it can stand on its own.
    
    @optimize
---
 .../evas/engines/gl_common/evas_gl_context.c       |  55 ----------
 .../evas/engines/gl_common/evas_gl_shader.c        | 121 +++++++++++++++++----
 2 files changed, 102 insertions(+), 74 deletions(-)

diff --git a/src/modules/evas/engines/gl_common/evas_gl_context.c b/src/modules/evas/engines/gl_common/evas_gl_context.c
index dc04597cbc..470b4f7e81 100644
--- a/src/modules/evas/engines/gl_common/evas_gl_context.c
+++ b/src/modules/evas/engines/gl_common/evas_gl_context.c
@@ -1061,9 +1061,6 @@ evas_gl_common_context_new(void)
           glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.0);
 #endif
 
-        glEnableVertexAttribArray(SHAD_VERTEX);
-        glEnableVertexAttribArray(SHAD_COLOR);
-
         if (!evas_gl_common_shader_program_init(shared))
           goto error;
 
@@ -1266,8 +1263,6 @@ evas_gl_common_context_newframe(Evas_Engine_GL_Context *gc)
      glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.0);
 #endif
 
-   glEnableVertexAttribArray(SHAD_VERTEX);
-   glEnableVertexAttribArray(SHAD_COLOR);
    if (gc->state.current.prog != PRG_INVALID)
      glUseProgram(gc->state.current.prog->prog);
 
@@ -3404,11 +3399,8 @@ shader_array_flush(Evas_Engine_GL_Context *gc)
 
         if (gc->pipe[i].array.use_color)
           {
-             glEnableVertexAttribArray(SHAD_COLOR);
              glVertexAttribPointer(SHAD_COLOR, COLOR_CNT, GL_UNSIGNED_BYTE, GL_TRUE, 0, color_ptr);
           }
-        else
-          glDisableVertexAttribArray(SHAD_COLOR);
 
         if (gc->pipe[i].array.line)
           {
@@ -3424,16 +3416,9 @@ shader_array_flush(Evas_Engine_GL_Context *gc)
                   glDisable(GL_LINE_SMOOTH);
                }
 
-             glDisableVertexAttribArray(SHAD_TEXUV);
-             glDisableVertexAttribArray(SHAD_TEXUV2);
-             glDisableVertexAttribArray(SHAD_TEXUV3);
-             glDisableVertexAttribArray(SHAD_TEXA);
-             glDisableVertexAttribArray(SHAD_TEXSAM);
-
              /* kopi pasta from below */
              if (gc->pipe[i].array.use_mask)
                {
-                  glEnableVertexAttribArray(SHAD_MASK);
                   glVertexAttribPointer(SHAD_MASK, MASK_CNT, GL_FLOAT, GL_FALSE, 0, mask_ptr);
                   glActiveTexture(MASK_TEXTURE);
                   glBindTexture(GL_TEXTURE_2D, gc->pipe[i].shader.cur_texm);
@@ -3457,37 +3442,23 @@ shader_array_flush(Evas_Engine_GL_Context *gc)
 
                   if (gc->pipe[i].array.use_masksam)
                     {
-                       glEnableVertexAttribArray(SHAD_MASKSAM);
                        glVertexAttribPointer(SHAD_MASKSAM, SAM_CNT, GL_FLOAT, GL_FALSE, 0, masksam_ptr);
                     }
-                  else glDisableVertexAttribArray(SHAD_MASKSAM);
                }
-             else
-               {
-                  glDisableVertexAttribArray(SHAD_MASK);
-                  glDisableVertexAttribArray(SHAD_MASKSAM);
-               }
-
              glDrawArrays(GL_LINES, 0, gc->pipe[i].array.num);
           }
         else
           {
              if (gc->pipe[i].array.use_texuv)
                {
-                  glEnableVertexAttribArray(SHAD_TEXUV);
                   glVertexAttribPointer(SHAD_TEXUV, TEX_CNT, GL_FLOAT, GL_FALSE, 0, texuv_ptr);
 
                   MASK_TEXTURE += 1;
                }
-             else
-               {
-                  glDisableVertexAttribArray(SHAD_TEXUV);
-               }
 
              /* Alpha plane */
              if (gc->pipe[i].array.use_texa)
                {
-                  glEnableVertexAttribArray(SHAD_TEXA);
                   glVertexAttribPointer(SHAD_TEXA, TEX_CNT, GL_FLOAT, GL_FALSE, 0, texa_ptr);
                   glActiveTexture(GL_TEXTURE1);
                   glBindTexture(GL_TEXTURE_2D, gc->pipe[i].shader.cur_texa);
@@ -3511,25 +3482,14 @@ shader_array_flush(Evas_Engine_GL_Context *gc)
 
                   MASK_TEXTURE += 1;
                }
-             else
-               {
-                  glDisableVertexAttribArray(SHAD_TEXA);
-               }
 
              if (gc->pipe[i].array.use_texsam)
                {
-                  glEnableVertexAttribArray(SHAD_TEXSAM);
                   glVertexAttribPointer(SHAD_TEXSAM, SAM_CNT, GL_FLOAT, GL_FALSE, 0, texsam_ptr);
                }
-             else
-               {
-                  glDisableVertexAttribArray(SHAD_TEXSAM);
-               }
 
              if ((gc->pipe[i].array.use_texuv2) && (gc->pipe[i].array.use_texuv3))
                {
-                  glEnableVertexAttribArray(SHAD_TEXUV2);
-                  glEnableVertexAttribArray(SHAD_TEXUV3);
                   glVertexAttribPointer(SHAD_TEXUV2, TEX_CNT, GL_FLOAT, GL_FALSE, 0, texuv2_ptr);
                   glVertexAttribPointer(SHAD_TEXUV3, TEX_CNT, GL_FLOAT, GL_FALSE, 0, texuv3_ptr);
 
@@ -3560,7 +3520,6 @@ shader_array_flush(Evas_Engine_GL_Context *gc)
                }
              else if (gc->pipe[i].array.use_texuv2)
                {
-                  glEnableVertexAttribArray(SHAD_TEXUV2);
                   glVertexAttribPointer(SHAD_TEXUV2, TEX_CNT, GL_FLOAT, GL_FALSE, 0, texuv2_ptr);
 
                   glActiveTexture(GL_TEXTURE1);
@@ -3586,19 +3545,12 @@ shader_array_flush(Evas_Engine_GL_Context *gc)
                     }
                   glActiveTexture(GL_TEXTURE0);
 
-                  glDisableVertexAttribArray(SHAD_TEXUV3);
                   MASK_TEXTURE += 1;
                }
-             else
-               {
-                  glDisableVertexAttribArray(SHAD_TEXUV2);
-                  glDisableVertexAttribArray(SHAD_TEXUV3);
-               }
 
              /* Mask surface */
              if (gc->pipe[i].array.use_mask)
                {
-                  glEnableVertexAttribArray(SHAD_MASK);
                   glVertexAttribPointer(SHAD_MASK, MASK_CNT, GL_FLOAT, GL_FALSE, 0, mask_ptr);
                   glActiveTexture(MASK_TEXTURE);
                   glBindTexture(GL_TEXTURE_2D, gc->pipe[i].shader.cur_texm);
@@ -3622,15 +3574,8 @@ shader_array_flush(Evas_Engine_GL_Context *gc)
 
                   if (gc->pipe[i].array.use_masksam)
                     {
-                       glEnableVertexAttribArray(SHAD_MASKSAM);
                        glVertexAttribPointer(SHAD_MASKSAM, SAM_CNT, GL_FLOAT, GL_FALSE, 0, masksam_ptr);
                     }
-                  else glDisableVertexAttribArray(SHAD_MASKSAM);
-               }
-             else
-               {
-                  glDisableVertexAttribArray(SHAD_MASK);
-                  glDisableVertexAttribArray(SHAD_MASKSAM);
                }
 
              if (dbgflushnum == 1)
diff --git a/src/modules/evas/engines/gl_common/evas_gl_shader.c b/src/modules/evas/engines/gl_common/evas_gl_shader.c
index d80d77976f..06707c7801 100644
--- a/src/modules/evas/engines/gl_common/evas_gl_shader.c
+++ b/src/modules/evas/engines/gl_common/evas_gl_shader.c
@@ -93,6 +93,103 @@ gl_compile_link_error(GLuint target, const char *action, Eina_Bool is_shader)
      }
 }
 
+static void
+_evas_gl_common_shader_program_attrib_init(GLint prg, unsigned int flags)
+{
+/*
+   glBindAttribLocation(prg, SHAD_VERTEX,  "vertex");
+   glBindAttribLocation(prg, SHAD_COLOR,   "color");
+   glBindAttribLocation(prg, SHAD_TEXUV,   "tex_coord");
+   glBindAttribLocation(prg, SHAD_TEXUV2,  "tex_coord2");
+   glBindAttribLocation(prg, SHAD_TEXUV3,  "tex_coord3");
+   glBindAttribLocation(prg, SHAD_TEXA,    "tex_coorda");
+   glBindAttribLocation(prg, SHAD_TEXSAM,  "tex_sample");
+   glBindAttribLocation(prg, SHAD_MASK,    "mask_coord");
+   glBindAttribLocation(prg, SHAD_MASKSAM, "tex_masksample");
+ */
+
+   glBindAttribLocation(prg, SHAD_VERTEX,  "vertex");
+   glBindAttribLocation(prg, SHAD_COLOR,   "color");
+
+   if (flags & (SHADER_FLAG_TEX | SHADER_FLAG_IMG |
+                SHADER_FLAG_YUV | SHADER_FLAG_YUY2 |
+                SHADER_FLAG_NV12 | SHADER_FLAG_YUV_709 |
+                SHADER_FLAG_EXTERNAL | SHADER_FLAG_BGRA |
+                SHADER_FLAG_SAM12 | SHADER_FLAG_SAM21 |
+                SHADER_FLAG_SAM22))
+     {
+        glBindAttribLocation(prg, SHAD_TEXUV,   "tex_coord");
+     }
+   if (flags & (SHADER_FLAG_YUV | SHADER_FLAG_YUY2 |
+                SHADER_FLAG_NV12 | SHADER_FLAG_YUV_709))
+     {
+        glBindAttribLocation(prg, SHAD_TEXUV2,  "tex_coord2");
+        glBindAttribLocation(prg, SHAD_TEXUV3,  "tex_coord3");
+     }
+   if (flags & (SHADER_FLAG_RGB_A_PAIR))
+     {
+        glBindAttribLocation(prg, SHAD_TEXA,    "tex_coorda");
+     }
+   if (flags & (SHADER_FLAG_SAM12 | SHADER_FLAG_SAM21 |
+                SHADER_FLAG_SAM22))
+     {
+        glBindAttribLocation(prg, SHAD_TEXSAM,  "tex_sample");
+     }
+   if (flags & (SHADER_FLAG_MASK | SHADER_FLAG_MASKSAM12 |
+                SHADER_FLAG_MASKSAM21 | SHADER_FLAG_MASKSAM22))
+     {
+        glBindAttribLocation(prg, SHAD_MASK,    "mask_coord");
+     }
+   if (flags & (SHADER_FLAG_MASKSAM12 | SHADER_FLAG_MASKSAM21 |
+                SHADER_FLAG_MASKSAM22))
+     {
+        glBindAttribLocation(prg, SHAD_MASKSAM, "tex_masksample");
+     }
+}
+
+static void
+_evas_gl_common_shader_program_attrib_enable(GLint prg, unsigned int flags)
+{
+   glUseProgram(prg);
+   glEnableVertexAttribArray(SHAD_VERTEX);
+   glEnableVertexAttribArray(SHAD_COLOR);
+
+   if (flags & (SHADER_FLAG_TEX | SHADER_FLAG_IMG |
+                SHADER_FLAG_YUV | SHADER_FLAG_YUY2 |
+                SHADER_FLAG_NV12 | SHADER_FLAG_YUV_709 |
+                SHADER_FLAG_EXTERNAL | SHADER_FLAG_BGRA |
+                SHADER_FLAG_SAM12 | SHADER_FLAG_SAM21 |
+                SHADER_FLAG_SAM22))
+     {
+        glEnableVertexAttribArray(SHAD_TEXUV);
+     }
+   if (flags & (SHADER_FLAG_YUV | SHADER_FLAG_YUY2 |
+                SHADER_FLAG_NV12 | SHADER_FLAG_YUV_709))
+     {
+        glEnableVertexAttribArray(SHAD_TEXUV2);
+        glEnableVertexAttribArray(SHAD_TEXUV3);
+     }
+   if (flags & (SHADER_FLAG_RGB_A_PAIR))
+     {
+        glEnableVertexAttribArray(SHAD_TEXA);
+     }
+   if (flags & (SHADER_FLAG_SAM12 | SHADER_FLAG_SAM21 |
+                SHADER_FLAG_SAM22))
+     {
+        glEnableVertexAttribArray(SHAD_TEXSAM);
+     }
+   if (flags & (SHADER_FLAG_MASK | SHADER_FLAG_MASKSAM12 |
+                SHADER_FLAG_MASKSAM21 | SHADER_FLAG_MASKSAM22))
+     {
+        glEnableVertexAttribArray(SHAD_MASK);
+     }
+   if (flags & (SHADER_FLAG_MASKSAM12 | SHADER_FLAG_MASKSAM21 |
+                SHADER_FLAG_MASKSAM22))
+     {
+        glEnableVertexAttribArray(SHAD_MASKSAM);
+     }
+}
+
 static Evas_GL_Program *
 _evas_gl_common_shader_program_binary_load(Eet_File *ef, unsigned int flags)
 {
@@ -136,15 +233,7 @@ _evas_gl_common_shader_program_binary_load(Eet_File *ef, unsigned int flags)
 #endif
    glsym_glProgramBinary(prg, formats[0], data, length);
 
-   glBindAttribLocation(prg, SHAD_VERTEX,  "vertex");
-   glBindAttribLocation(prg, SHAD_COLOR,   "color");
-   glBindAttribLocation(prg, SHAD_TEXUV,   "tex_coord");
-   glBindAttribLocation(prg, SHAD_TEXUV2,  "tex_coord2");
-   glBindAttribLocation(prg, SHAD_TEXUV3,  "tex_coord3");
-   glBindAttribLocation(prg, SHAD_TEXA,    "tex_coorda");
-   glBindAttribLocation(prg, SHAD_TEXSAM,  "tex_sample");
-   glBindAttribLocation(prg, SHAD_MASK,    "mask_coord");
-   glBindAttribLocation(prg, SHAD_MASKSAM, "tex_masksample");
+   _evas_gl_common_shader_program_attrib_init(prg, flags);
 
    glGetProgramiv(prg, GL_LINK_STATUS, &ok);
    if (!ok)
@@ -160,6 +249,7 @@ _evas_gl_common_shader_program_binary_load(Eet_File *ef, unsigned int flags)
    p->prog = prg;
    p->reset = EINA_TRUE;
    p->bin_saved = EINA_TRUE;
+   _evas_gl_common_shader_program_attrib_enable(p->prog, flags);
    p->uniform.mvp = glGetUniformLocation(prg, "mvp");
    p->uniform.rotation_id = glGetUniformLocation(prg, "rotation_id");
    evas_gl_common_shader_textures_bind(p);
@@ -458,15 +548,7 @@ evas_gl_common_shader_compile(unsigned int flags, const char *vertex,
    glAttachShader(prg, vtx);
    glAttachShader(prg, frg);
 
-   glBindAttribLocation(prg, SHAD_VERTEX,  "vertex");
-   glBindAttribLocation(prg, SHAD_COLOR,   "color");
-   glBindAttribLocation(prg, SHAD_TEXUV,   "tex_coord");
-   glBindAttribLocation(prg, SHAD_TEXUV2,  "tex_coord2");
-   glBindAttribLocation(prg, SHAD_TEXUV3,  "tex_coord3");
-   glBindAttribLocation(prg, SHAD_TEXA,    "tex_coorda");
-   glBindAttribLocation(prg, SHAD_TEXSAM,  "tex_sample");
-   glBindAttribLocation(prg, SHAD_MASK,    "mask_coord");
-   glBindAttribLocation(prg, SHAD_MASKSAM, "tex_masksample");
+   _evas_gl_common_shader_program_attrib_init(prg, flags);
 
    glLinkProgram(prg);
    glGetProgramiv(prg, GL_LINK_STATUS, &ok);
@@ -480,6 +562,7 @@ evas_gl_common_shader_compile(unsigned int flags, const char *vertex,
         return 0;
      }
 
+
    p = calloc(1, sizeof(*p));
    p->flags = flags;
    p->prog = prg;
@@ -568,6 +651,7 @@ evas_gl_common_shader_generate_and_compile(Evas_GL_Shared *shared, unsigned int
    if (p)
      {
         shared->needs_shaders_flush = 1;
+        _evas_gl_common_shader_program_attrib_enable(p->prog, flags);
         p->uniform.mvp = glGetUniformLocation(p->prog, "mvp");
         p->uniform.rotation_id = glGetUniformLocation(p->prog, "rotation_id");
         evas_gl_common_shader_textures_bind(p);
@@ -875,7 +959,6 @@ evas_gl_common_shader_textures_bind(Evas_GL_Program *p)
 
    if (hastex)
      {
-        glUseProgram(p->prog); // is this necessary??
         for (i = 0; textures[i].name; i++)
           {
              if (!textures[i].enabled) continue;

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to