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
path: root/source
diff options
context:
space:
mode:
authorMike Erwin <significant.bit@gmail.com>2017-04-13 01:55:32 +0300
committerMike Erwin <significant.bit@gmail.com>2017-04-13 08:07:51 +0300
commitb02786ae6be71d3b7581b672b7896005f68c8b63 (patch)
tree15e094e9d7f9b3d442f07f76e3dd048ba8a1ecd4 /source
parent6bfb9b7b5f164b303433d729d1cbe38f1ba44366 (diff)
Gawain: use ShaderInterface to manage uniforms
This eliminates tons of glGetUniformLocation calls from the drawing loop. Vast majority of code can keep making the same function calls. They're just faster now! - Batch_Uniform* - immUniform* - gpuBindMatrices - and others
Diffstat (limited to 'source')
-rw-r--r--source/blender/draw/intern/draw_manager.c2
-rw-r--r--source/blender/gpu/GPU_matrix.h3
-rw-r--r--source/blender/gpu/intern/gpu_batch.c2
-rw-r--r--source/blender/gpu/intern/gpu_compositing.c22
-rw-r--r--source/blender/gpu/intern/gpu_immediate.c2
-rw-r--r--source/blender/gpu/intern/gpu_matrix.c49
-rw-r--r--source/blender/gpu/intern/gpu_shader.c2
7 files changed, 39 insertions, 43 deletions
diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c
index 3cb6c57eef6..19938605290 100644
--- a/source/blender/draw/intern/draw_manager.c
+++ b/source/blender/draw/intern/draw_manager.c
@@ -1002,7 +1002,7 @@ static void draw_geometry(DRWShadingGroup *shgroup, Batch *geom, const float (*o
}
/* step 2 : bind vertex array & draw */
- Batch_set_program(geom, GPU_shader_get_program(shgroup->shader));
+ Batch_set_program(geom, GPU_shader_get_program(shgroup->shader), GPU_shader_get_interface(shgroup->shader));
if (interface->instance_vbo) {
Batch_draw_stupid_instanced(geom, interface->instance_vbo, interface->instance_count, interface->attribs_count,
interface->attribs_stride, interface->attribs_size, interface->attribs_loc);
diff --git a/source/blender/gpu/GPU_matrix.h b/source/blender/gpu/GPU_matrix.h
index 85b1b5c7acf..07e4ff80f57 100644
--- a/source/blender/gpu/GPU_matrix.h
+++ b/source/blender/gpu/GPU_matrix.h
@@ -34,6 +34,7 @@
#include "BLI_sys_types.h"
#include "GPU_glew.h"
+#include "../../../intern/gawain/gawain/shader_interface.h"
#ifdef __cplusplus
extern "C" {
@@ -132,7 +133,7 @@ const float *gpuGetNormalMatrixInverse(float m[3][3]);
/* set uniform values for currently bound shader */
-void gpuBindMatrices(GLuint program);
+void gpuBindMatrices(const ShaderInterface*);
bool gpuMatricesDirty(void); /* since last bind */
#ifdef __cplusplus
diff --git a/source/blender/gpu/intern/gpu_batch.c b/source/blender/gpu/intern/gpu_batch.c
index a36830cf277..e98f07cb0e9 100644
--- a/source/blender/gpu/intern/gpu_batch.c
+++ b/source/blender/gpu/intern/gpu_batch.c
@@ -34,7 +34,7 @@
void Batch_set_builtin_program(Batch *batch, GPUBuiltinShader shader_id)
{
GPUShader *shader = GPU_shader_get_builtin_shader(shader_id);
- Batch_set_program(batch, shader->program);
+ Batch_set_program(batch, shader->program, shader->interface);
}
static Batch *sphere_high = NULL;
diff --git a/source/blender/gpu/intern/gpu_compositing.c b/source/blender/gpu/intern/gpu_compositing.c
index 719708ff7aa..72f2525c64e 100644
--- a/source/blender/gpu/intern/gpu_compositing.c
+++ b/source/blender/gpu/intern/gpu_compositing.c
@@ -734,7 +734,7 @@ void GPU_fx_compositor_XRay_resolve(GPUFX *fx)
GPUDepthResolveInterface *interface = GPU_fx_shader_get_interface(depth_resolve_shader);
/* set up quad buffer */
- Batch_set_program(fx->quad_batch, GPU_shader_get_program(depth_resolve_shader));
+ Batch_set_program(fx->quad_batch, GPU_shader_get_program(depth_resolve_shader), GPU_shader_get_interface(depth_resolve_shader));
GPU_texture_bind(fx->depth_buffer_xray, 0);
GPU_texture_compare_mode(fx->depth_buffer_xray, false);
@@ -838,7 +838,7 @@ bool GPU_fx_do_composite_pass(
GPUSSAOShaderInterface *interface = GPU_fx_shader_get_interface(ssao_shader);
- Batch_set_program(fx->quad_batch, GPU_shader_get_program(ssao_shader));
+ Batch_set_program(fx->quad_batch, GPU_shader_get_program(ssao_shader), GPU_shader_get_interface(ssao_shader));
GPU_shader_uniform_vector(ssao_shader, interface->ssao_uniform, 4, 1, ssao_params);
GPU_shader_uniform_vector(ssao_shader, interface->ssao_color_uniform, 4, 1, fx_ssao->color);
@@ -931,7 +931,7 @@ bool GPU_fx_do_composite_pass(
GPUDOFHQPassOneInterface *interface = GPU_fx_shader_get_interface(dof_shader_pass1);
- Batch_set_program(fx->quad_batch, GPU_shader_get_program(dof_shader_pass1));
+ Batch_set_program(fx->quad_batch, GPU_shader_get_program(dof_shader_pass1), GPU_shader_get_interface(dof_shader_pass1));
GPU_shader_uniform_vector(dof_shader_pass1, interface->dof_uniform, 4, 1, dof_params);
GPU_shader_uniform_vector(dof_shader_pass1, interface->invrendertargetdim_uniform, 2, 1, invrendertargetdim);
@@ -983,7 +983,7 @@ bool GPU_fx_do_composite_pass(
GPUDOFHQPassTwoInterface *interface = GPU_fx_shader_get_interface(dof_shader_pass2);
- Batch_set_program(fx->point_batch, GPU_shader_get_program(dof_shader_pass2));
+ Batch_set_program(fx->point_batch, GPU_shader_get_program(dof_shader_pass2), GPU_shader_get_interface(dof_shader_pass2));
GPU_texture_bind(fx->dof_nearfar_coc, numslots++);
GPU_texture_bind(fx->dof_half_downsampled_far, numslots++);
@@ -1046,7 +1046,7 @@ bool GPU_fx_do_composite_pass(
GPUDOFHQPassThreeInterface *interface = GPU_fx_shader_get_interface(dof_shader_pass3);
- Batch_set_program(fx->quad_batch, GPU_shader_get_program(dof_shader_pass3));
+ Batch_set_program(fx->quad_batch, GPU_shader_get_program(dof_shader_pass3), GPU_shader_get_interface(dof_shader_pass3));
GPU_shader_uniform_vector(dof_shader_pass3, interface->dof_uniform, 4, 1, dof_params);
@@ -1125,7 +1125,7 @@ bool GPU_fx_do_composite_pass(
GPUDOFPassOneInterface *interface = GPU_fx_shader_get_interface(dof_shader_pass1);
- Batch_set_program(fx->quad_batch, GPU_shader_get_program(dof_shader_pass1));
+ Batch_set_program(fx->quad_batch, GPU_shader_get_program(dof_shader_pass1), GPU_shader_get_interface(dof_shader_pass1));
GPU_shader_uniform_vector(dof_shader_pass1, interface->dof_uniform, 4, 1, dof_params);
GPU_shader_uniform_vector(dof_shader_pass1, interface->invrendertargetdim_uniform, 2, 1, invrendertargetdim);
@@ -1167,7 +1167,7 @@ bool GPU_fx_do_composite_pass(
dof_params[2] = GPU_texture_width(fx->dof_near_coc_blurred_buffer) / (scale_camera * fx_dof->sensor);
/* Blurring vertically */
- Batch_set_program(fx->quad_batch, GPU_shader_get_program(dof_shader_pass2));
+ Batch_set_program(fx->quad_batch, GPU_shader_get_program(dof_shader_pass2), GPU_shader_get_interface(dof_shader_pass2));
GPU_shader_uniform_vector(dof_shader_pass2, interface->dof_uniform, 4, 1, dof_params);
GPU_shader_uniform_vector(dof_shader_pass2, interface->invrendertargetdim_uniform, 2, 1, invrendertargetdim);
@@ -1188,7 +1188,7 @@ bool GPU_fx_do_composite_pass(
Batch_draw(fx->quad_batch);
/* Rebind Shader */
- Batch_set_program(fx->quad_batch, GPU_shader_get_program(dof_shader_pass2));
+ Batch_set_program(fx->quad_batch, GPU_shader_get_program(dof_shader_pass2), GPU_shader_get_interface(dof_shader_pass2));
/* *unbind/detach */
GPU_texture_unbind(fx->dof_near_coc_buffer);
@@ -1224,7 +1224,7 @@ bool GPU_fx_do_composite_pass(
{
GPUDOFPassThreeInterface *interface = GPU_fx_shader_get_interface(dof_shader_pass3);
- Batch_set_program(fx->quad_batch, GPU_shader_get_program(dof_shader_pass3));
+ Batch_set_program(fx->quad_batch, GPU_shader_get_program(dof_shader_pass3), GPU_shader_get_interface(dof_shader_pass3));
GPU_texture_bind(fx->dof_near_coc_buffer, numslots++);
GPU_shader_uniform_texture(dof_shader_pass3, interface->near_coc_downsampled, fx->dof_near_coc_buffer);
@@ -1252,7 +1252,7 @@ bool GPU_fx_do_composite_pass(
GPUDOFPassFourInterface *interface = GPU_fx_shader_get_interface(dof_shader_pass4);
- Batch_set_program(fx->quad_batch, GPU_shader_get_program(dof_shader_pass4));
+ Batch_set_program(fx->quad_batch, GPU_shader_get_program(dof_shader_pass4), GPU_shader_get_interface(dof_shader_pass4));
GPU_texture_bind(fx->dof_near_coc_final_buffer, numslots++);
GPU_shader_uniform_texture(dof_shader_pass4, interface->near_coc_downsampled, fx->dof_near_coc_final_buffer);
@@ -1277,7 +1277,7 @@ bool GPU_fx_do_composite_pass(
GPUDOFPassFiveInterface *interface = GPU_fx_shader_get_interface(dof_shader_pass5);
- Batch_set_program(fx->quad_batch, GPU_shader_get_program(dof_shader_pass5));
+ Batch_set_program(fx->quad_batch, GPU_shader_get_program(dof_shader_pass5), GPU_shader_get_interface(dof_shader_pass5));
GPU_shader_uniform_vector(dof_shader_pass5, interface->dof_uniform, 4, 1, dof_params);
GPU_shader_uniform_vector(dof_shader_pass5, interface->invrendertargetdim_uniform, 2, 1, invrendertargetdim);
diff --git a/source/blender/gpu/intern/gpu_immediate.c b/source/blender/gpu/intern/gpu_immediate.c
index 34d32be15ed..5f22b7f9279 100644
--- a/source/blender/gpu/intern/gpu_immediate.c
+++ b/source/blender/gpu/intern/gpu_immediate.c
@@ -35,7 +35,7 @@
void immBindBuiltinProgram(GPUBuiltinShader shader_id)
{
GPUShader *shader = GPU_shader_get_builtin_shader(shader_id);
- immBindProgram(shader->program);
+ immBindProgram(shader->program, shader->interface);
}
void immUniformThemeColor(int color_id)
diff --git a/source/blender/gpu/intern/gpu_matrix.c b/source/blender/gpu/intern/gpu_matrix.c
index 8f8754f612d..8195722917d 100644
--- a/source/blender/gpu/intern/gpu_matrix.c
+++ b/source/blender/gpu/intern/gpu_matrix.c
@@ -829,74 +829,69 @@ const float *gpuGetNormalMatrixInverse(float m[3][3])
return (const float*)m;
}
-void gpuBindMatrices(GLuint program)
+void gpuBindMatrices(const ShaderInterface* shaderface)
{
- /* TODO: split this into 2 functions
- * 1) get uniform locations & determine 2D or 3D
+ /* set uniform values to matrix stack values
+ * call this before a draw call if desired matrices are dirty
+ * call glUseProgram before this, as glUniform expects program to be bound
*/
- GLint loc_MV = glGetUniformLocation(program, "ModelViewMatrix");
- GLint loc_P = glGetUniformLocation(program, "ProjectionMatrix");
- GLint loc_MVP = glGetUniformLocation(program, "ModelViewProjectionMatrix");
- GLint loc_N = glGetUniformLocation(program, "NormalMatrix");
-
- /* 2) set uniform values to matrix stack values
- * program needs to be bound
- */
- glUseProgram(program);
+ const ShaderInput *MV = ShaderInterface_builtin_uniform(shaderface, UNIFORM_MODELVIEW_3D);
+ const ShaderInput *P = ShaderInterface_builtin_uniform(shaderface, UNIFORM_PROJECTION_3D);
+ const ShaderInput *MVP = ShaderInterface_builtin_uniform(shaderface, UNIFORM_MVP_3D);
+ const ShaderInput *N = ShaderInterface_builtin_uniform(shaderface, UNIFORM_NORMAL_3D);
- /* call this portion before a draw call if desired matrices are dirty */
- if (loc_MV != -1) {
+ if (MV) {
#if DEBUG_MATRIX_BIND
puts("setting 3D MV matrix");
#endif
- glUniformMatrix4fv(loc_MV, 1, GL_FALSE, gpuGetModelViewMatrix3D(NULL));
+ glUniformMatrix4fv(MV->location, 1, GL_FALSE, gpuGetModelViewMatrix3D(NULL));
}
- if (loc_P != -1) {
+ if (P) {
#if DEBUG_MATRIX_BIND
puts("setting 3D P matrix");
#endif
- glUniformMatrix4fv(loc_P, 1, GL_FALSE, gpuGetProjectionMatrix3D(NULL));
+ glUniformMatrix4fv(P->location, 1, GL_FALSE, gpuGetProjectionMatrix3D(NULL));
}
- if (loc_MVP != -1) {
+ if (MVP) {
#if DEBUG_MATRIX_BIND
puts("setting 3D MVP matrix");
#endif
- glUniformMatrix4fv(loc_MVP, 1, GL_FALSE, gpuGetModelViewProjectionMatrix3D(NULL));
+ glUniformMatrix4fv(MVP->location, 1, GL_FALSE, gpuGetModelViewProjectionMatrix3D(NULL));
}
- if (loc_N != -1) {
+ if (N) {
#if DEBUG_MATRIX_BIND
puts("setting 3D normal matrix");
#endif
- glUniformMatrix3fv(loc_N, 1, GL_FALSE, gpuGetNormalMatrix(NULL));
+ glUniformMatrix3fv(N->location, 1, GL_FALSE, gpuGetNormalMatrix(NULL));
}
/* also needed by material.glsl
* - ProjectionMatrixInverse
* - ModelViewMatrixInverse
*/
- GLint loc_MV_inv = glGetUniformLocation(program, "ModelViewInverseMatrix");
- GLint loc_P_inv = glGetUniformLocation(program, "ProjectionInverseMatrix");
+ const ShaderInput *MV_inv = ShaderInterface_builtin_uniform(shaderface, UNIFORM_MODELVIEW_INV_3D);
+ const ShaderInput *P_inv = ShaderInterface_builtin_uniform(shaderface, UNIFORM_PROJECTION_INV_3D);
- if (loc_MV_inv != -1) {
+ if (MV_inv) {
Mat4 m;
gpuGetModelViewMatrix3D(m);
invert_m4(m);
- glUniformMatrix4fv(loc_MV_inv, 1, GL_FALSE, (const float*) m);
+ glUniformMatrix4fv(MV_inv->location, 1, GL_FALSE, (const float*) m);
}
- if (loc_P_inv != -1) {
+ if (P_inv) {
Mat4 m;
gpuGetProjectionMatrix3D(m);
invert_m4(m);
- glUniformMatrix4fv(loc_P_inv, 1, GL_FALSE, (const float*) m);
+ glUniformMatrix4fv(P_inv->location, 1, GL_FALSE, (const float*) m);
}
state.dirty = false;
diff --git a/source/blender/gpu/intern/gpu_shader.c b/source/blender/gpu/intern/gpu_shader.c
index 7ea148e15d6..fa63dff1458 100644
--- a/source/blender/gpu/intern/gpu_shader.c
+++ b/source/blender/gpu/intern/gpu_shader.c
@@ -490,7 +490,7 @@ void GPU_shader_bind(GPUShader *shader)
BLI_assert(shader && shader->program);
glUseProgram(shader->program);
- gpuBindMatrices(shader->program);
+ gpuBindMatrices(shader->interface);
}
void GPU_shader_unbind(void)