summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2015-02-11 21:13:13 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2015-02-12 11:23:03 +0900
commit7e26c305220b4dd8e7e2a85b7b50444e855e26fe (patch)
treef22a61bc1f2423690018d152c680b8750afbaafc /src
parent986b60eaf0175b3592883c85cfb6f5f5a280f31d (diff)
Evas GL common: Call glGetUniformLocation as early as possible
This should speed up setting uniforms in the shaders, by storing their locations in the Evas_GL_Program description. I kept the previous solution with name as fallback, but it won't actually be used with the current shaders.
Diffstat (limited to 'src')
-rw-r--r--src/modules/evas/engines/gl_common/evas_gl_common.h5
-rw-r--r--src/modules/evas/engines/gl_common/evas_gl_context.c31
-rw-r--r--src/modules/evas/engines/gl_common/evas_gl_shader.c13
3 files changed, 39 insertions, 10 deletions
diff --git a/src/modules/evas/engines/gl_common/evas_gl_common.h b/src/modules/evas/engines/gl_common/evas_gl_common.h
index f8effa3a64..f431b20fc9 100644
--- a/src/modules/evas/engines/gl_common/evas_gl_common.h
+++ b/src/modules/evas/engines/gl_common/evas_gl_common.h
@@ -301,6 +301,11 @@ struct _Evas_GL_Program
301 GLuint vert, frag, prog; 301 GLuint vert, frag, prog;
302 302
303 int tex_count; 303 int tex_count;
304 struct {
305 GLint loc_sample;
306 GLint loc_yinvert;
307 GLint loc_mask_Absolute;
308 } uniforms;
304}; 309};
305 310
306struct _Evas_GL_Program_Source 311struct _Evas_GL_Program_Source
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 1cdb240da5..4ad661dbd2 100644
--- a/src/modules/evas/engines/gl_common/evas_gl_context.c
+++ b/src/modules/evas/engines/gl_common/evas_gl_context.c
@@ -1329,8 +1329,9 @@ enum _Evas_GL_Uniform_Type {
1329}; 1329};
1330 1330
1331struct _Evas_GL_Uniform { 1331struct _Evas_GL_Uniform {
1332 Eina_Stringshare *name;
1333 Evas_GL_Uniform_Type type; 1332 Evas_GL_Uniform_Type type;
1333 Eina_Stringshare *name; // May be NULL if location was found at link time
1334 GLint location;
1334 union { 1335 union {
1335 GLfloat f; 1336 GLfloat f;
1336 GLfloat vec2[2]; 1337 GLfloat vec2[2];
@@ -1339,15 +1340,17 @@ struct _Evas_GL_Uniform {
1339}; 1340};
1340 1341
1341static inline void 1342static inline void
1342push_uniform(Evas_Engine_GL_Context *gc, int n, Evas_GL_Uniform_Type type, const char *name, ...) 1343push_uniform(Evas_Engine_GL_Context *gc, int n, Evas_GL_Uniform_Type type,
1344 const char *name, GLint loc, ...)
1343{ 1345{
1344 Evas_GL_Uniform *u = calloc(1, sizeof(Evas_GL_Uniform)); 1346 Evas_GL_Uniform *u = calloc(1, sizeof(Evas_GL_Uniform));
1345 va_list args; 1347 va_list args;
1346 va_start(args, name); 1348 va_start(args, loc);
1347 1349
1348 if (!gc || !u) return; 1350 if (!gc || !u) return;
1349 u->name = eina_stringshare_add(name);
1350 u->type = type; 1351 u->type = type;
1352 u->location = loc;
1353 if (loc < 0) u->name = eina_stringshare_add(name);
1351 1354
1352 switch (type) 1355 switch (type)
1353 { 1356 {
@@ -1365,6 +1368,7 @@ push_uniform(Evas_Engine_GL_Context *gc, int n, Evas_GL_Uniform_Type type, const
1365 u->value.vec4[3] = (GLfloat) va_arg(args, double); 1368 u->value.vec4[3] = (GLfloat) va_arg(args, double);
1366 break; 1369 break;
1367 default: 1370 default:
1371 eina_stringshare_del(u->name);
1368 free(u); 1372 free(u);
1369 va_end(args); 1373 va_end(args);
1370 return; 1374 return;
@@ -1378,12 +1382,18 @@ static inline void
1378shader_array_uniforms_set(Evas_Engine_GL_Context *gc, int n) 1382shader_array_uniforms_set(Evas_Engine_GL_Context *gc, int n)
1379{ 1383{
1380 Evas_GL_Uniform *u; 1384 Evas_GL_Uniform *u;
1385 GLint loc;
1381 1386
1382 if (!gc || !gc->pipe[n].array.uniforms) return; 1387 if (!gc || !gc->pipe[n].array.uniforms) return;
1383 EINA_LIST_FREE(gc->pipe[n].array.uniforms, u) 1388 EINA_LIST_FREE(gc->pipe[n].array.uniforms, u)
1384 { 1389 {
1385 GLint loc = glGetUniformLocation(gc->pipe[n].shader.cur_prog, u->name); 1390 if (u->location >= 0)
1386 GLERR(__FUNCTION__, __FILE__, __LINE__, "glUniform"); 1391 loc = u->location;
1392 else
1393 {
1394 loc = glGetUniformLocation(gc->pipe[n].shader.cur_prog, u->name);
1395 GLERR(__FUNCTION__, __FILE__, __LINE__, "glGetUniformLocation");
1396 }
1387 if (loc >= 0) 1397 if (loc >= 0)
1388 { 1398 {
1389 switch (u->type) 1399 switch (u->type)
@@ -1406,7 +1416,8 @@ shader_array_uniforms_set(Evas_Engine_GL_Context *gc, int n)
1406 } 1416 }
1407} 1417}
1408 1418
1409#define PUSH_UNIFORM(pn, type, name, ...) push_uniform(gc, pn, type, name, __VA_ARGS__) 1419#define PUSH_UNIFORM(pn, shader, type, name, ...) \
1420 push_uniform(gc, pn, type, #name, gc->shared->shader[shader].uniforms.loc_##name, __VA_ARGS__)
1410 1421
1411#ifdef GLPIPES 1422#ifdef GLPIPES
1412static int 1423static int
@@ -2098,7 +2109,7 @@ evas_gl_common_context_image_push(Evas_Engine_GL_Context *gc,
2098 { 2109 {
2099 double samx = (double)(sw) / (double)(tex->pt->w * w * 4); 2110 double samx = (double)(sw) / (double)(tex->pt->w * w * 4);
2100 double samy = (double)(sh) / (double)(tex->pt->h * h * 4); 2111 double samy = (double)(sh) / (double)(tex->pt->h * h * 4);
2101 PUSH_UNIFORM(pn, EVAS_GL_UNIFORM_VEC2, "sample", samx, samy); 2112 PUSH_UNIFORM(pn, shader, EVAS_GL_UNIFORM_VEC2, sample, samx, samy);
2102 } 2113 }
2103 2114
2104 PUSH_MASK(pn, mtex, mx, my, mw, mh); 2115 PUSH_MASK(pn, mtex, mx, my, mw, mh);
@@ -2879,8 +2890,8 @@ evas_gl_common_context_image_map_push(Evas_Engine_GL_Context *gc,
2879 if (mdw) glmdw = (double) gw / (double) mdw; 2890 if (mdw) glmdw = (double) gw / (double) mdw;
2880 if (mdh) glmdh = (double) gh / (double) mdh; 2891 if (mdh) glmdh = (double) gh / (double) mdh;
2881 2892
2882 PUSH_UNIFORM(pn, EVAS_GL_UNIFORM_VEC4, "mask_Absolute", glmdx, glmdy, glmdw, glmdh); 2893 PUSH_UNIFORM(pn, shader, EVAS_GL_UNIFORM_VEC4, mask_Absolute, glmdx, glmdy, glmdw, glmdh);
2883 PUSH_UNIFORM(pn, EVAS_GL_UNIFORM_FLOAT, "yinvert", yinv); 2894 PUSH_UNIFORM(pn, shader, EVAS_GL_UNIFORM_FLOAT, yinvert, yinv);
2884 2895
2885 //DBG("Orig %d,%d - %dx%d --> %f,%f - %f x %f", mdx, mdy, mdw, mdh, 2896 //DBG("Orig %d,%d - %dx%d --> %f,%f - %f x %f", mdx, mdy, mdw, mdh,
2886 // glmdx, glmdy, glmdw, glmdh); 2897 // glmdx, glmdy, glmdw, glmdh);
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 bc5010c5a6..7b6a10f786 100644
--- a/src/modules/evas/engines/gl_common/evas_gl_shader.c
+++ b/src/modules/evas/engines/gl_common/evas_gl_shader.c
@@ -34,6 +34,10 @@ gl_compile_link_error(GLuint target, const char *action)
34 } 34 }
35} 35}
36 36
37#define ATTACH_UNIFORM(p, name) do { \
38 p->uniforms.loc_##name = glGetUniformLocation(p->prog, #name); \
39 } while (0)
40
37static int 41static int
38_evas_gl_common_shader_program_binary_init(Evas_GL_Program *p, 42_evas_gl_common_shader_program_binary_init(Evas_GL_Program *p,
39 const char *pname, 43 const char *pname,
@@ -88,6 +92,10 @@ _evas_gl_common_shader_program_binary_init(Evas_GL_Program *p,
88 goto finish; 92 goto finish;
89 } 93 }
90 94
95 ATTACH_UNIFORM(p, sample);
96 ATTACH_UNIFORM(p, yinvert);
97 ATTACH_UNIFORM(p, mask_Absolute);
98
91 res = 1; 99 res = 1;
92 100
93finish: 101finish:
@@ -216,6 +224,11 @@ _evas_gl_common_shader_program_source_init(Evas_GL_Program *p,
216 ERR("Abort compile of shader vert (%s): %s", name, vert->src); 224 ERR("Abort compile of shader vert (%s): %s", name, vert->src);
217 return 0; 225 return 0;
218 } 226 }
227
228 ATTACH_UNIFORM(p, sample);
229 ATTACH_UNIFORM(p, yinvert);
230 ATTACH_UNIFORM(p, mask_Absolute);
231
219 return 1; 232 return 1;
220} 233}
221 234