Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClément Foucault <foucault.clem@gmail.com>2019-05-07 18:21:26 +0300
committerClément Foucault <foucault.clem@gmail.com>2019-05-08 18:49:28 +0300
commit9fea65a93def1ee72fdc1585a381607441f76c21 (patch)
tree10b6350fc00ce7ea65b576b27e50b2b9db68793f
parent45caba37330e623ed1dd8a24aa6698e937325c2b (diff)
DRW: Speedup: Don't call GPU_shader_uniform_vector if not needed
This seems to remove a bit of overhead of going into the function even if the uniform is not needed.
-rw-r--r--source/blender/draw/intern/draw_manager_exec.c130
1 files changed, 85 insertions, 45 deletions
diff --git a/source/blender/draw/intern/draw_manager_exec.c b/source/blender/draw/intern/draw_manager_exec.c
index 46f4d0620c8..75f552da2d7 100644
--- a/source/blender/draw/intern/draw_manager_exec.c
+++ b/source/blender/draw/intern/draw_manager_exec.c
@@ -835,31 +835,56 @@ static void draw_geometry_prepare(DRWShadingGroup *shgroup, DRWCall *call)
/* step 1 : bind object dependent matrices */
if (call != NULL) {
DRWCallState *state = call->state;
- float objectinfo[4];
- objectinfo[0] = state->objectinfo[0];
- objectinfo[1] = call->single.ma_index; /* WATCH this is only valid for single drawcalls. */
- objectinfo[2] = state->objectinfo[1];
- objectinfo[3] = (state->flag & DRW_CALL_NEGSCALE) ? -1.0f : 1.0f;
-
- GPU_shader_uniform_vector(shgroup->shader, shgroup->model, 16, 1, (float *)state->model);
- GPU_shader_uniform_vector(
- shgroup->shader, shgroup->modelinverse, 16, 1, (float *)state->modelinverse);
- GPU_shader_uniform_vector(
- shgroup->shader, shgroup->modelview, 16, 1, (float *)state->modelview);
- GPU_shader_uniform_vector(
- shgroup->shader, shgroup->modelviewinverse, 16, 1, (float *)state->modelviewinverse);
- GPU_shader_uniform_vector(
- shgroup->shader, shgroup->modelviewprojection, 16, 1, (float *)state->modelviewprojection);
- GPU_shader_uniform_vector(
- shgroup->shader, shgroup->normalview, 9, 1, (float *)state->normalview);
- GPU_shader_uniform_vector(
- shgroup->shader, shgroup->normalviewinverse, 9, 1, (float *)state->normalviewinverse);
- GPU_shader_uniform_vector(
- shgroup->shader, shgroup->normalworld, 9, 1, (float *)state->normalworld);
- GPU_shader_uniform_vector(shgroup->shader, shgroup->objectinfo, 4, 1, (float *)objectinfo);
- GPU_shader_uniform_vector(
- shgroup->shader, shgroup->orcotexfac, 3, 2, (float *)state->orcotexfac);
- GPU_shader_uniform_vector(shgroup->shader, shgroup->eye, 3, 1, (float *)state->eyevec);
+
+ if (shgroup->model != -1) {
+ GPU_shader_uniform_vector(shgroup->shader, shgroup->model, 16, 1, (float *)state->model);
+ }
+ if (shgroup->modelinverse != -1) {
+ GPU_shader_uniform_vector(
+ shgroup->shader, shgroup->modelinverse, 16, 1, (float *)state->modelinverse);
+ }
+ if (shgroup->modelview != -1) {
+ GPU_shader_uniform_vector(
+ shgroup->shader, shgroup->modelview, 16, 1, (float *)state->modelview);
+ }
+ if (shgroup->modelviewinverse != -1) {
+ GPU_shader_uniform_vector(
+ shgroup->shader, shgroup->modelviewinverse, 16, 1, (float *)state->modelviewinverse);
+ }
+ if (shgroup->modelviewprojection != -1) {
+ GPU_shader_uniform_vector(shgroup->shader,
+ shgroup->modelviewprojection,
+ 16,
+ 1,
+ (float *)state->modelviewprojection);
+ }
+ if (shgroup->normalview != -1) {
+ GPU_shader_uniform_vector(
+ shgroup->shader, shgroup->normalview, 9, 1, (float *)state->normalview);
+ }
+ if (shgroup->normalviewinverse != -1) {
+ GPU_shader_uniform_vector(
+ shgroup->shader, shgroup->normalviewinverse, 9, 1, (float *)state->normalviewinverse);
+ }
+ if (shgroup->normalworld != -1) {
+ GPU_shader_uniform_vector(
+ shgroup->shader, shgroup->normalworld, 9, 1, (float *)state->normalworld);
+ }
+ if (shgroup->objectinfo != -1) {
+ float objectinfo[4];
+ objectinfo[0] = state->objectinfo[0];
+ objectinfo[1] = call->single.ma_index; /* WATCH this is only valid for single drawcalls. */
+ objectinfo[2] = state->objectinfo[1];
+ objectinfo[3] = (state->flag & DRW_CALL_NEGSCALE) ? -1.0f : 1.0f;
+ GPU_shader_uniform_vector(shgroup->shader, shgroup->objectinfo, 4, 1, (float *)objectinfo);
+ }
+ if (shgroup->orcotexfac != -1) {
+ GPU_shader_uniform_vector(
+ shgroup->shader, shgroup->orcotexfac, 3, 2, (float *)state->orcotexfac);
+ }
+ if (shgroup->eye != -1) {
+ GPU_shader_uniform_vector(shgroup->shader, shgroup->eye, 3, 1, (float *)state->eyevec);
+ }
}
else {
BLI_assert((shgroup->normalview == -1) && (shgroup->normalworld == -1) &&
@@ -867,26 +892,41 @@ static void draw_geometry_prepare(DRWShadingGroup *shgroup, DRWCall *call)
/* For instancing and batching. */
float unitmat[4][4];
unit_m4(unitmat);
- GPU_shader_uniform_vector(shgroup->shader, shgroup->model, 16, 1, (float *)unitmat);
- GPU_shader_uniform_vector(shgroup->shader, shgroup->modelinverse, 16, 1, (float *)unitmat);
- GPU_shader_uniform_vector(shgroup->shader,
- shgroup->modelview,
- 16,
- 1,
- (float *)DST.view_data.matstate.mat[DRW_MAT_VIEW]);
- GPU_shader_uniform_vector(shgroup->shader,
- shgroup->modelviewinverse,
- 16,
- 1,
- (float *)DST.view_data.matstate.mat[DRW_MAT_VIEWINV]);
- GPU_shader_uniform_vector(shgroup->shader,
- shgroup->modelviewprojection,
- 16,
- 1,
- (float *)DST.view_data.matstate.mat[DRW_MAT_PERS]);
- GPU_shader_uniform_vector(shgroup->shader, shgroup->objectinfo, 4, 1, (float *)unitmat);
- GPU_shader_uniform_vector(
- shgroup->shader, shgroup->orcotexfac, 3, 2, (float *)shgroup->instance_orcofac);
+
+ if (shgroup->model != -1) {
+ GPU_shader_uniform_vector(shgroup->shader, shgroup->model, 16, 1, (float *)unitmat);
+ }
+ if (shgroup->modelinverse != -1) {
+ GPU_shader_uniform_vector(shgroup->shader, shgroup->modelinverse, 16, 1, (float *)unitmat);
+ }
+ if (shgroup->modelview != -1) {
+ GPU_shader_uniform_vector(shgroup->shader,
+ shgroup->modelview,
+ 16,
+ 1,
+ (float *)DST.view_data.matstate.mat[DRW_MAT_VIEW]);
+ }
+ if (shgroup->modelviewinverse != -1) {
+ GPU_shader_uniform_vector(shgroup->shader,
+ shgroup->modelviewinverse,
+ 16,
+ 1,
+ (float *)DST.view_data.matstate.mat[DRW_MAT_VIEWINV]);
+ }
+ if (shgroup->modelviewprojection != -1) {
+ GPU_shader_uniform_vector(shgroup->shader,
+ shgroup->modelviewprojection,
+ 16,
+ 1,
+ (float *)DST.view_data.matstate.mat[DRW_MAT_PERS]);
+ }
+ if (shgroup->objectinfo != -1) {
+ GPU_shader_uniform_vector(shgroup->shader, shgroup->objectinfo, 4, 1, (float *)unitmat);
+ }
+ if (shgroup->orcotexfac != -1) {
+ GPU_shader_uniform_vector(
+ shgroup->shader, shgroup->orcotexfac, 3, 2, (float *)shgroup->instance_orcofac);
+ }
}
}