Commit: 4acd218c0262f59edd2a0251d6c9530c8753349f
Author: Antony Riakiotakis
Date:   Mon Mar 21 00:53:48 2016 +0100
Branches: master
https://developer.blender.org/rB4acd218c0262f59edd2a0251d6c9530c8753349f

GPU compositing:

Minor optimization: Store the uniform interface of shaders instead of
re-querying every frame.

===================================================================

M       source/blender/gpu/GPU_compositing.h
M       source/blender/gpu/GPU_shader.h
M       source/blender/gpu/intern/gpu_compositing.c
M       source/blender/gpu/intern/gpu_shader.c

===================================================================

diff --git a/source/blender/gpu/GPU_compositing.h 
b/source/blender/gpu/GPU_compositing.h
index 892fe4f..d506d91 100644
--- a/source/blender/gpu/GPU_compositing.h
+++ b/source/blender/gpu/GPU_compositing.h
@@ -44,6 +44,7 @@ struct GPUOffScreen;
 struct GPUFXSettings;
 struct rcti;
 struct Scene;
+struct GPUShader;
 enum eGPUFXFlags;
 
 /**** Public API *****/
@@ -94,6 +95,10 @@ void GPU_fx_compositor_XRay_resolve(GPUFX *fx);
 
 void GPU_fx_compositor_init_dof_settings(struct GPUDOFSettings *dof);
 void GPU_fx_compositor_init_ssao_settings(struct GPUSSAOSettings *ssao);
+
+
+/* initialize and cache the shader unform interface for effects */
+void GPU_fx_shader_init_interface(struct GPUShader *shader, GPUFXShaderEffect 
effect);
 #ifdef __cplusplus
 }
 #endif
diff --git a/source/blender/gpu/GPU_shader.h b/source/blender/gpu/GPU_shader.h
index 0317976..4c674b4 100644
--- a/source/blender/gpu/GPU_shader.h
+++ b/source/blender/gpu/GPU_shader.h
@@ -69,6 +69,8 @@ void GPU_shader_free(GPUShader *shader);
 void GPU_shader_bind(GPUShader *shader);
 void GPU_shader_unbind(void);
 
+void *GPU_shader_get_interface(GPUShader *shader);
+void GPU_shader_set_interface(GPUShader *shader, void *interface);
 int GPU_shader_get_uniform(GPUShader *shader, const char *name);
 void GPU_shader_uniform_vector(GPUShader *shader, int location, int length,
        int arraysize, const float *value);
diff --git a/source/blender/gpu/intern/gpu_compositing.c 
b/source/blender/gpu/intern/gpu_compositing.c
index 8516a2d..c22f3ed 100644
--- a/source/blender/gpu/intern/gpu_compositing.c
+++ b/source/blender/gpu/intern/gpu_compositing.c
@@ -58,6 +58,97 @@
 static const float fullscreencos[4][2] = {{-1.0f, -1.0f}, {1.0f, -1.0f}, 
{-1.0f, 1.0f}, {1.0f, 1.0f}};
 static const float fullscreenuvs[4][2] = {{0.0f, 0.0f}, {1.0f, 0.0f}, {0.0f, 
1.0f}, {1.0f, 1.0f}};
 
+
+/* shader interfaces (legacy GL 2 style, without uniform buffer objects) */
+
+typedef struct
+{
+       int ssao_uniform;
+       int ssao_color_uniform;
+       int color_uniform;
+       int depth_uniform;
+       int viewvecs_uniform;
+       int ssao_sample_params_uniform;
+       int ssao_concentric_tex;
+       int ssao_jitter_uniform;
+} GPUSSAOShaderInterface;
+
+typedef struct
+{
+       int invrendertargetdim_uniform;
+       int color_uniform;
+       int dof_uniform;
+       int depth_uniform;
+       int viewvecs_uniform;
+} GPUDOFHQPassOneInterface;
+
+typedef struct
+{
+       int rendertargetdim_uniform;
+       int color_uniform;
+       int coc_uniform;
+       int select_uniform;
+       int dof_uniform;
+} GPUDOFHQPassTwoInterface;
+
+typedef struct
+{
+       int dof_uniform;
+       int invrendertargetdim_uniform;
+       int color_uniform;
+       int far_uniform;
+       int near_uniform;
+       int viewvecs_uniform;
+       int depth_uniform;
+} GPUDOFHQPassThreeInterface;
+
+typedef struct
+{
+       int dof_uniform;
+       int invrendertargetdim_uniform;
+       int color_uniform;
+       int depth_uniform;
+       int viewvecs_uniform;
+} GPUDOFPassOneInterface;
+
+typedef struct
+{
+       int dof_uniform;
+       int invrendertargetdim_uniform;
+       int color_uniform;
+       int depth_uniform;
+       int viewvecs_uniform;
+} GPUDOFPassTwoInterface;
+
+typedef struct
+{
+       int near_coc_downsampled;
+       int near_coc_blurred;
+} GPUDOFPassThreeInterface;
+
+typedef struct
+{
+       int near_coc_downsampled;
+       int invrendertargetdim_uniform;
+} GPUDOFPassFourInterface;
+
+typedef struct
+{
+       int medium_blurred_uniform;
+       int high_blurred_uniform;
+       int dof_uniform;
+       int invrendertargetdim_uniform;
+       int original_uniform;
+       int depth_uniform;
+       int viewvecs_uniform;
+} GPUDOFPassFiveInterface;
+
+typedef struct
+{
+       int depth_uniform;
+} GPUDepthResolveInterface;
+
+
 struct GPUFX {
        /* we borrow the term gbuffer from deferred rendering however this is 
just a regular
         * depth/color framebuffer. Could be extended later though */
@@ -618,15 +709,13 @@ void GPU_fx_compositor_XRay_resolve(GPUFX *fx)
        depth_resolve_shader = 
GPU_shader_get_builtin_fx_shader(GPU_SHADER_FX_DEPTH_RESOLVE, false);
 
        if (depth_resolve_shader) {
-               int depth_uniform;
-
-               depth_uniform = GPU_shader_get_uniform(depth_resolve_shader, 
"depthbuffer");
+               GPUDepthResolveInterface *interface = 
GPU_shader_get_interface(depth_resolve_shader);
 
                GPU_shader_bind(depth_resolve_shader);
 
                GPU_texture_bind(fx->depth_buffer_xray, 0);
                GPU_texture_filter_mode(fx->depth_buffer_xray, false, true);
-               GPU_shader_uniform_texture(depth_resolve_shader, depth_uniform, 
fx->depth_buffer_xray);
+               GPU_shader_uniform_texture(depth_resolve_shader, 
interface->depth_uniform, fx->depth_buffer_xray);
 
                /* draw */
                glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
@@ -724,9 +813,6 @@ bool GPU_fx_do_composite_pass(
                ssao_shader = 
GPU_shader_get_builtin_fx_shader(GPU_SHADER_FX_SSAO, is_persp);
                if (ssao_shader) {
                        const GPUSSAOSettings *fx_ssao = fx->settings.ssao;
-                       int color_uniform, depth_uniform;
-                       int ssao_uniform, ssao_color_uniform, viewvecs_uniform, 
ssao_sample_params_uniform;
-                       int ssao_jitter_uniform, ssao_concentric_tex;
                        float ssao_params[4] = {fx_ssao->distance_max, 
fx_ssao->factor, fx_ssao->attenuation, 0.0f};
                        float sample_params[3];
 
@@ -737,34 +823,27 @@ bool GPU_fx_do_composite_pass(
 
                        ssao_params[3] = (passes_left == 1 && !ofs) ? 
dfdyfac[0] : dfdyfac[1];
 
-                       ssao_uniform = GPU_shader_get_uniform(ssao_shader, 
"ssao_params");
-                       ssao_color_uniform = 
GPU_shader_get_uniform(ssao_shader, "ssao_color");
-                       color_uniform = GPU_shader_get_uniform(ssao_shader, 
"colorbuffer");
-                       depth_uniform = GPU_shader_get_uniform(ssao_shader, 
"depthbuffer");
-                       viewvecs_uniform = GPU_shader_get_uniform(ssao_shader, 
"viewvecs");
-                       ssao_sample_params_uniform = 
GPU_shader_get_uniform(ssao_shader, "ssao_sample_params");
-                       ssao_concentric_tex = 
GPU_shader_get_uniform(ssao_shader, "ssao_concentric_tex");
-                       ssao_jitter_uniform = 
GPU_shader_get_uniform(ssao_shader, "jitter_tex");
+                       GPUSSAOShaderInterface *interface = 
GPU_shader_get_interface(ssao_shader);
 
                        GPU_shader_bind(ssao_shader);
 
-                       GPU_shader_uniform_vector(ssao_shader, ssao_uniform, 4, 
1, ssao_params);
-                       GPU_shader_uniform_vector(ssao_shader, 
ssao_color_uniform, 4, 1, fx_ssao->color);
-                       GPU_shader_uniform_vector(ssao_shader, 
viewvecs_uniform, 4, 3, viewvecs[0]);
-                       GPU_shader_uniform_vector(ssao_shader, 
ssao_sample_params_uniform, 3, 1, sample_params);
+                       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);
+                       GPU_shader_uniform_vector(ssao_shader, 
interface->viewvecs_uniform, 4, 3, viewvecs[0]);
+                       GPU_shader_uniform_vector(ssao_shader, 
interface->ssao_sample_params_uniform, 3, 1, sample_params);
 
                        GPU_texture_bind(src, numslots++);
-                       GPU_shader_uniform_texture(ssao_shader, color_uniform, 
src);
+                       GPU_shader_uniform_texture(ssao_shader, 
interface->color_uniform, src);
 
                        GPU_texture_bind(fx->depth_buffer, numslots++);
                        GPU_texture_filter_mode(fx->depth_buffer, false, true);
-                       GPU_shader_uniform_texture(ssao_shader, depth_uniform, 
fx->depth_buffer);
+                       GPU_shader_uniform_texture(ssao_shader, 
interface->depth_uniform, fx->depth_buffer);
 
                        GPU_texture_bind(fx->jitter_buffer, numslots++);
-                       GPU_shader_uniform_texture(ssao_shader, 
ssao_jitter_uniform, fx->jitter_buffer);
+                       GPU_shader_uniform_texture(ssao_shader, 
interface->ssao_jitter_uniform, fx->jitter_buffer);
 
                        GPU_texture_bind(fx->ssao_spiral_samples_tex, 
numslots++);
-                       GPU_shader_uniform_texture(ssao_shader, 
ssao_concentric_tex, fx->ssao_spiral_samples_tex);
+                       GPU_shader_uniform_texture(ssao_shader, 
interface->ssao_concentric_tex, fx->ssao_spiral_samples_tex);
 
                        /* draw */
                        gpu_fx_bind_render_target(&passes_left, fx, ofs, 
target);
@@ -835,35 +914,26 @@ bool GPU_fx_do_composite_pass(
 
                        /* pass first, downsample the color buffer to near/far 
targets and calculate coc texture */
                        {
-                               int depth_uniform, dof_uniform;
-                               int viewvecs_uniform;
-                               int invrendertargetdim_uniform, color_uniform;
-
                                float invrendertargetdim[2] = {1.0f / 
fx->dof_downsampled_w, 1.0f / fx->dof_downsampled_h};
 
-                               invrendertargetdim_uniform = 
GPU_shader_get_uniform(dof_shader_pass1, "invrendertargetdim");
-                               color_uniform = 
GPU_shader_get_uniform(dof_shader_pass1, "colorbuffer");
-                               dof_uniform = 
GPU_shader_get_uniform(dof_shader_pass1, "dof_params");
-                               invrendertargetdim_uniform = 
GPU_shader_get_uniform(dof_shader_pass1, "invrendertargetdim");
-                               depth_uniform = 
GPU_shader_get_uniform(dof_shader_pass1, "depthbuffer");
-                               viewvecs_uniform = 
GPU_shader_get_uniform(dof_shader_pass1, "viewvecs");
+                               GPUDOFHQPassOneInterface *interface = 
GPU_shader_get_interface(dof_shader_pass1);
 
                                GPU_shader_bind(dof_shader_pass1);
 
-                               GPU_shader_uniform_vector(dof_shader_pass1, 
dof_uniform, 4, 1, dof_params);
-                               GPU_shader_uniform_vector(dof_shader_pass1, 
invrendertargetdim_uniform, 2, 1, invrendertargetdim);
-                               GPU_shader_uniform_vector(dof_shader_pass1, 
viewvecs_uniform, 4, 3, viewvecs[0]);
+                               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);
+                               GPU_shader_uniform_vector(dof_shader_pass1, 
interface->viewvecs_uniform, 4, 3, viewvecs[0]);
 
-                               GPU_shader_uniform_vector(dof_shader_pass1, 
invrendertargetdim_uniform, 2, 1, invrendertargetdim);
+                               GPU_shader_uniform_vector(dof_shader_pass1, 
interface->invrendertargetdim_uniform, 2, 1, invrendertargetdim);
 
                                GPU_texture_bind(fx->depth_buffer, numslots++);
                                GPU_texture_filter_mode(fx->depth_buffer, 
false, false);
-                               GPU_shader_uniform_texture(dof_shader_pass1, 
depth_uniform, fx->depth_buffer);
+                               GPU_shader_uniform_texture(dof_shader_pass1, 
interface->depth_uniform, fx->depth_buffer);
 
                                GPU_texture_bind(src, numslots++);
                                /* disable filtering for the texture so custom 
downsample can do the right thing */
                                GPU_texture_filter_mode(src, false, false);
-                               GPU_shader_uniform_texture(dof_shader_pass2, 
color_uniform, src);
+                               GPU_shader_uniform_texture(dof_shader_pass2, 
interface->color_uniform, src);
 
                                /* target is the downsampled coc buffer */
                                GPU_framebuffer_texture_attach(fx->gbuffer, 
fx->dof_half_downsampled_near, 0, N

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to