[Bf-blender-cvs] [9fea65a93de] master: DRW: Speedup: Don't call GPU_shader_uniform_vector if not needed
Clément Foucault
noreply at git.blender.org
Wed May 8 17:58:58 CEST 2019
Commit: 9fea65a93def1ee72fdc1585a381607441f76c21
Author: Clément Foucault
Date: Tue May 7 17:21:26 2019 +0200
Branches: master
https://developer.blender.org/rB9fea65a93def1ee72fdc1585a381607441f76c21
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.
===================================================================
M source/blender/draw/intern/draw_manager_exec.c
===================================================================
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);
+ }
}
}
More information about the Bf-blender-cvs
mailing list