Eevee: Remove some of the non-necessary uniforms
authorClément Foucault <foucault.clem@gmail.com>
Fri, 3 Aug 2018 16:53:36 +0000 (18:53 +0200)
committerClément Foucault <foucault.clem@gmail.com>
Wed, 8 Aug 2018 19:26:49 +0000 (21:26 +0200)
The remaining ones are from the attributes linear/srgb switches and from
nodes that should be pruned before running their _gpu function.

13 files changed:
source/blender/draw/engines/eevee/eevee_materials.c
source/blender/gpu/GPU_material.h
source/blender/gpu/intern/gpu_material.c
source/blender/gpu/shaders/gpu_shader_material.glsl
source/blender/nodes/shader/nodes/node_shader_bsdf_anisotropic.c
source/blender/nodes/shader/nodes/node_shader_bsdf_diffuse.c
source/blender/nodes/shader/nodes/node_shader_bsdf_glass.c
source/blender/nodes/shader/nodes/node_shader_bsdf_glossy.c
source/blender/nodes/shader/nodes/node_shader_bsdf_principled.c
source/blender/nodes/shader/nodes/node_shader_bsdf_refraction.c
source/blender/nodes/shader/nodes/node_shader_bsdf_translucent.c
source/blender/nodes/shader/nodes/node_shader_bsdf_velvet.c
source/blender/nodes/shader/nodes/node_shader_subsurface_scattering.c

index 535dce7730ae94a6f2409bdec03cdb3e75326c5c..769ac11736d8a8493c945646dcb2e2a97e42644a 100644 (file)
@@ -360,7 +360,9 @@ static char *eevee_get_volume_defines(int options)
  **/
 static void add_standard_uniforms(
         DRWShadingGroup *shgrp, EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata,
-        int *ssr_id, float *refract_depth, bool use_ssrefraction, bool use_alpha_blend)
+        int *ssr_id, float *refract_depth,
+        bool use_diffuse, bool use_glossy, bool use_refract,
+        bool use_ssrefraction, bool use_alpha_blend)
 {
        LightCache *lcache = vedata->stl->g_data->light_cache;
 
@@ -377,13 +379,13 @@ static void add_standard_uniforms(
        DRW_shgroup_uniform_block(shgrp, "common_block", sldata->common_ubo);
        DRW_shgroup_uniform_block(shgrp, "clip_block", sldata->clip_ubo);
 
-       /* TODO if glossy or diffuse bsdf */
-       if (true) {
+       if (use_diffuse || use_glossy || use_refract) {
                DRW_shgroup_uniform_texture(shgrp, "utilTex", e_data.util_tex);
                DRW_shgroup_uniform_texture_ref(shgrp, "shadowCubeTexture", &sldata->shadow_cube_pool);
                DRW_shgroup_uniform_texture_ref(shgrp, "shadowCascadeTexture", &sldata->shadow_cascade_pool);
                DRW_shgroup_uniform_texture_ref(shgrp, "maxzBuffer", &vedata->txl->maxzbuffer);
-
+       }
+       if ((use_diffuse || use_glossy) && !use_refract) {
                if ((vedata->stl->effects->enabled_effects & EFFECT_GTAO) != 0) {
                        DRW_shgroup_uniform_texture_ref(shgrp, "horizonBuffer", &vedata->stl->effects->gtao_horizons);
                }
@@ -392,15 +394,13 @@ static void add_standard_uniforms(
                        DRW_shgroup_uniform_texture_ref(shgrp, "horizonBuffer", &vedata->txl->maxzbuffer);
                }
        }
-
-       /* TODO if diffuse bsdf */
-       if (true) {
+       if (use_diffuse) {
                DRW_shgroup_uniform_texture_ref(shgrp, "irradianceGrid", &lcache->grid_tx.tex);
        }
-
-       /* TODO if glossy bsdf */
-       if (true) {
+       if (use_glossy || use_refract) {
                DRW_shgroup_uniform_texture_ref(shgrp, "probeCubes", &lcache->cube_tx.tex);
+       }
+       if (use_glossy) {
                DRW_shgroup_uniform_texture_ref(shgrp, "probePlanars", &vedata->txl->planar_pool);
                DRW_shgroup_uniform_int(shgrp, "outputSsrId", ssr_id, 1);
        }
@@ -851,7 +851,7 @@ static struct DRWShadingGroup *EEVEE_default_shading_group_create(
        }
 
        DRWShadingGroup *shgrp = DRW_shgroup_create(e_data.default_lit[options], pass);
-       add_standard_uniforms(shgrp, sldata, vedata, &ssr_id, NULL, false, use_blend);
+       add_standard_uniforms(shgrp, sldata, vedata, &ssr_id, NULL, true, true, false, false, use_blend);
 
        return shgrp;
 }
@@ -888,7 +888,7 @@ static struct DRWShadingGroup *EEVEE_default_shading_group_get(
                 * EDIT: THIS IS NOT THE CASE FOR HAIRS !!! DUMMY!!! */
                if (!is_hair) {
                        DRWShadingGroup *shgrp = DRW_shgroup_create(e_data.default_lit[options], vedata->psl->default_pass[options]);
-                       add_standard_uniforms(shgrp, sldata, vedata, &ssr_id, NULL, false, false);
+                       add_standard_uniforms(shgrp, sldata, vedata, &ssr_id, NULL, true, true, false, false, false);
                }
        }
 
@@ -896,7 +896,7 @@ static struct DRWShadingGroup *EEVEE_default_shading_group_get(
                DRWShadingGroup *shgrp = DRW_shgroup_hair_create(ob, psys, md,
                                                                 vedata->psl->default_pass[options],
                                                                 e_data.default_lit[options]);
-               add_standard_uniforms(shgrp, sldata, vedata, &ssr_id, NULL, false, false);
+               add_standard_uniforms(shgrp, sldata, vedata, &ssr_id, NULL, true, true, false, false, false);
                return shgrp;
        }
        else {
@@ -928,7 +928,7 @@ static struct DRWShadingGroup *EEVEE_lookdev_shading_group_get(
                DRWShadingGroup *shgrp = DRW_shgroup_create(e_data.default_lit[options], vedata->psl->lookdev_pass);
                /* XXX / WATCH: This creates non persistent binds for the ubos and textures.
                 * But it's currently OK because the following shgroups does not add any bind. */
-               add_standard_uniforms(shgrp, sldata, vedata, &ssr_id, NULL, false, false);
+               add_standard_uniforms(shgrp, sldata, vedata, &ssr_id, NULL, true, true, false, false, false);
        }
 
        return DRW_shgroup_create(e_data.default_lit[options], vedata->psl->lookdev_pass);
@@ -1116,6 +1116,7 @@ static void material_opaque(
        EEVEE_StorageList *stl = ((EEVEE_Data *)vedata)->stl;
        EEVEE_PassList *psl = ((EEVEE_Data *)vedata)->psl;
        EEVEE_LampsInfo *linfo = sldata->lamps;
+       bool use_diffuse, use_glossy, use_refract;
 
        float *color_p = &ma->r;
        float *metal_p = &ma->metallic;
@@ -1123,7 +1124,7 @@ static void material_opaque(
        float *rough_p = &ma->roughness;
 
        const bool use_gpumat = (ma->use_nodes && ma->nodetree);
-       const bool use_refract = ((ma->blend_flag & MA_BL_SS_REFRACTION) != 0) &&
+       const bool use_ssrefract = ((ma->blend_flag & MA_BL_SS_REFRACTION) != 0) &&
                                 ((effects->enabled_effects & EFFECT_REFRACT) != 0);
        const bool use_sss = ((ma->blend_flag & MA_BL_SS_SUBSURFACE) != 0) &&
                             ((effects->enabled_effects & EFFECT_SSS) != 0);
@@ -1138,7 +1139,7 @@ static void material_opaque(
 
                /* This will have been created already, just perform a lookup. */
                *gpumat = (use_gpumat) ? EEVEE_material_mesh_get(
-                       scene, ma, vedata, false, false, use_refract, use_sss, use_translucency, linfo->shadow_method) : NULL;
+                       scene, ma, vedata, false, false, use_ssrefract, use_sss, use_translucency, linfo->shadow_method) : NULL;
                *gpumat_depth = (use_gpumat) ? EEVEE_material_mesh_depth_get(
                        scene, ma, (ma->blend_method == MA_BM_HASHED), false) : NULL;
                return;
@@ -1151,7 +1152,7 @@ static void material_opaque(
 
                /* Shading */
                *gpumat = EEVEE_material_mesh_get(
-                       scene, ma, vedata, false, false, use_refract,
+                       scene, ma, vedata, false, false, use_ssrefract,
                        use_sss, use_translucency, linfo->shadow_method);
 
                GPUMaterialStatus status_mat_surface = GPU_material_status(*gpumat);
@@ -1167,7 +1168,7 @@ static void material_opaque(
                                 * the surface shader. */
                                status_mat_surface = status_mat_depth;
                        }
-                       else if (use_refract) {
+                       else if (use_ssrefract) {
                                *shgrp_depth = DRW_shgroup_material_create(
                                        *gpumat_depth, (do_cull) ? psl->refract_depth_pass_cull : psl->refract_depth_pass);
                                *shgrp_depth_clip = DRW_shgroup_material_create(
@@ -1181,8 +1182,14 @@ static void material_opaque(
                        }
 
                        if (*shgrp_depth != NULL) {
-                               add_standard_uniforms(*shgrp_depth, sldata, vedata, NULL, NULL, false, false);
-                               add_standard_uniforms(*shgrp_depth_clip, sldata, vedata, NULL, NULL, false, false);
+                               use_diffuse = GPU_material_flag_get(*gpumat_depth, GPU_MATFLAG_DIFFUSE);
+                               use_glossy = GPU_material_flag_get(*gpumat_depth, GPU_MATFLAG_GLOSSY);
+                               use_refract = GPU_material_flag_get(*gpumat_depth, GPU_MATFLAG_REFRACT);
+
+                               add_standard_uniforms(*shgrp_depth, sldata, vedata, NULL, NULL,
+                                                     use_diffuse, use_glossy, use_refract, false, false);
+                               add_standard_uniforms(*shgrp_depth_clip, sldata, vedata, NULL, NULL,
+                                                     use_diffuse, use_glossy, use_refract, false, false);
 
                                if (ma->blend_method == MA_BM_CLIP) {
                                        DRW_shgroup_uniform_float(*shgrp_depth, "alphaThreshold", &ma->alpha_threshold, 1);
@@ -1200,13 +1207,18 @@ static void material_opaque(
                        {
                                static int no_ssr = -1;
                                static int first_ssr = 1;
-                               int *ssr_id = (((effects->enabled_effects & EFFECT_SSR) != 0) && !use_refract) ? &first_ssr : &no_ssr;
+                               int *ssr_id = (((effects->enabled_effects & EFFECT_SSR) != 0) && !use_ssrefract) ? &first_ssr : &no_ssr;
+                               use_diffuse = GPU_material_flag_get(*gpumat, GPU_MATFLAG_DIFFUSE);
+                               use_glossy = GPU_material_flag_get(*gpumat, GPU_MATFLAG_GLOSSY);
+                               use_refract = GPU_material_flag_get(*gpumat, GPU_MATFLAG_REFRACT);
 
                                *shgrp = DRW_shgroup_material_create(
                                        *gpumat,
-                                       (use_refract) ? psl->refract_pass :
+                                       (use_ssrefract) ? psl->refract_pass :
                                        (use_sss) ? psl->sss_pass : psl->material_pass);
-                               add_standard_uniforms(*shgrp, sldata, vedata, ssr_id, &ma->refract_depth, use_refract, false);
+
+                               add_standard_uniforms(*shgrp, sldata, vedata, ssr_id, &ma->refract_depth,
+                                                     use_diffuse, use_glossy, use_refract, use_ssrefract, false);
 
                                if (use_sss) {
                                        struct GPUTexture *sss_tex_profile = NULL;
@@ -1237,7 +1249,6 @@ static void material_opaque(
                        }
                        case GPU_MAT_QUEUED:
                        {
-                               /* TODO Bypass probe compilation. */
                                color_p = compile_col;
                                metal_p = spec_p = rough_p = &half;
                                break;
@@ -1264,7 +1275,7 @@ static void material_opaque(
 
        /* Fallback default depth prepass */
        if (*shgrp_depth == NULL) {
-               if (use_refract) {
+               if (use_ssrefract) {
                        *shgrp_depth = (do_cull) ? stl->g_data->refract_depth_shgrp_cull : stl->g_data->refract_depth_shgrp;
                        *shgrp_depth_clip = (do_cull) ? stl->g_data->refract_depth_shgrp_clip_cull : stl->g_data->refract_depth_shgrp_clip;
                }
@@ -1292,7 +1303,7 @@ static void material_transparent(
        EEVEE_PassList *psl = ((EEVEE_Data *)vedata)->psl;
        EEVEE_LampsInfo *linfo = sldata->lamps;
 
-       const bool use_refract = (
+       const bool use_ssrefract = (
                ((ma->blend_flag & MA_BL_SS_REFRACTION) != 0) &&
                ((stl->effects->enabled_effects & EFFECT_REFRACT) != 0)
        );
@@ -1308,7 +1319,7 @@ static void material_transparent(
 
                /* Shading */
                *gpumat = EEVEE_material_mesh_get(
-                       scene, ma, vedata, true, (ma->blend_method == MA_BM_MULTIPLY), use_refract,
+                       scene, ma, vedata, true, (ma->blend_method == MA_BM_MULTIPLY), use_ssrefract,
                        false, false, linfo->shadow_method);
 
                switch (GPU_material_status(*gpumat)) {
@@ -1318,7 +1329,13 @@ static void material_transparent(
                                bool use_blend = (ma->blend_method & MA_BM_BLEND) != 0;
 
                                *shgrp = DRW_shgroup_material_create(*gpumat, psl->transparent_pass);
-                               add_standard_uniforms(*shgrp, sldata, vedata, &ssr_id, &ma->refract_depth, use_refract, use_blend);
+
+                               bool use_diffuse = GPU_material_flag_get(*gpumat, GPU_MATFLAG_DIFFUSE);
+                               bool use_glossy = GPU_material_flag_get(*gpumat, GPU_MATFLAG_GLOSSY);
+                               bool use_refract = GPU_material_flag_get(*gpumat, GPU_MATFLAG_REFRACT);
+
+                               add_standard_uniforms(*shgrp, sldata, vedata, &ssr_id, &ma->refract_depth,
+                                                     use_diffuse, use_glossy, use_refract, use_ssrefract, use_blend);
                                break;
                        }
                        case GPU_MAT_QUEUED:
@@ -1643,11 +1660,17 @@ void EEVEE_hair_cache_populate(EEVEE_Data *vedata, EEVEE_ViewLayerData *sldata,
                                        switch (GPU_material_status(gpumat)) {
                                                case GPU_MAT_SUCCESS:
                                                {
+                                                       bool use_diffuse = GPU_material_flag_get(gpumat, GPU_MATFLAG_DIFFUSE);
+                                                       bool use_glossy = GPU_material_flag_get(gpumat, GPU_MATFLAG_GLOSSY);
+                                                       bool use_refract = GPU_material_flag_get(gpumat, GPU_MATFLAG_REFRACT);
+
                                                        shgrp = DRW_shgroup_material_hair_create(
                                                                ob, psys, md,
                                                                psl->material_pass,
                                                                gpumat);
-                                                       add_standard_uniforms(shgrp, sldata, vedata, &ssr_id, NULL, false, false);
+
+                                                       add_standard_uniforms(shgrp, sldata, vedata, &ssr_id, NULL,
+                                                                             use_diffuse, use_glossy, use_refract, false, false);
                                                        break;
                                                }
                                                case GPU_MAT_QUEUED:
index 5945621cb656dfd0cffa4ee649c78735b7c1ff9b..cc1150b6d77e52b10207187be6f77cc76f61b53b 100644 (file)
@@ -124,6 +124,11 @@ typedef enum GPUMatType {
        GPU_MATERIAL_TYPE_WORLD = 2,
 } GPUMatType;
 
+typedef enum GPUMatFlag {
+       GPU_MATFLAG_DIFFUSE       = (1 << 0),
+       GPU_MATFLAG_GLOSSY        = (1 << 1),
+       GPU_MATFLAG_REFRACT       = (1 << 2),
+} GPUMatFlag;
 
 typedef enum GPUBlendMode {
        GPU_BLEND_SOLID = 0,
@@ -270,6 +275,9 @@ bool GPU_material_do_color_management(GPUMaterial *mat);
 bool GPU_material_use_domain_surface(GPUMaterial *mat);
 bool GPU_material_use_domain_volume(GPUMaterial *mat);
 
+void GPU_material_flag_set(GPUMaterial *mat, GPUMatFlag flag);
+bool GPU_material_flag_get(GPUMaterial *mat, GPUMatFlag flag);
+
 void GPU_pass_cache_init(void);
 void GPU_pass_cache_garbage_collect(void);
 void GPU_pass_cache_free(void);
index 9859f56c1dbe423fb164915019aff7fcaa300c5b..69c3a3a73ba1b7eb10f1a83b0277aedae4009343 100644 (file)
@@ -109,6 +109,9 @@ struct GPUMaterial {
         */
        int domain;
 
+       /* Only used by Eevee to know which bsdf are used. */
+       int flag;
+
        /* Used by 2.8 pipeline */
        GPUUniformBuffer *ubo; /* UBOs for shader uniforms. */
 
@@ -564,6 +567,16 @@ bool GPU_material_use_domain_volume(GPUMaterial *mat)
        return (mat->domain & GPU_DOMAIN_VOLUME);
 }
 
+void GPU_material_flag_set(GPUMaterial *mat, GPUMatFlag flag)
+{
+       mat->flag |= flag;
+}
+
+bool GPU_material_flag_get(GPUMaterial *mat, GPUMatFlag flag)
+{
+       return (mat->flag & flag);
+}
+
 GPUMaterial *GPU_material_from_nodetree_find(
         ListBase *gpumaterials, const void *engine_type, int options)
 {
index 064ee42907e8c697db7058193e8b31a6627e5ff4..808d2f736593e8e5fbfb9f498a7066e1eaa860ea 100644 (file)
@@ -1102,7 +1102,7 @@ void node_bsdf_anisotropic(
         vec4 color, float roughness, float anisotropy, float rotation, vec3 N, vec3 T,
         out Closure result)
 {
-       node_bsdf_diffuse(color, 0.0, N, result);
+       node_bsdf_glossy(color, roughness, N, -1, result);
 }
 
 void node_bsdf_glass(vec4 color, float roughness, float ior, vec3 N, float ssr_id, out Closure result)
index c1423867d96776397d72107a68fbfeb7873a9d50..6551b20a3758bffbd91c542bb60e707976cba101 100644 (file)
@@ -54,6 +54,8 @@ static int node_shader_gpu_bsdf_anisotropic(GPUMaterial *mat, bNode *node, bNode
        if (!in[4].link)
                GPU_link(mat, "world_normals_get", &in[4].link);
 
+       GPU_material_flag_set(mat, GPU_MATFLAG_GLOSSY);
+
        return GPU_stack_link(mat, node, "node_bsdf_anisotropic", in, out);
 }
 
index 58a37b0e81d4dc6f344eef9f90cafcdaf7f44d9f..c1b8c748657d9a137a5b4a7d88beeb285043627b 100644 (file)
@@ -46,6 +46,8 @@ static int node_shader_gpu_bsdf_diffuse(GPUMaterial *mat, bNode *node, bNodeExec
        if (!in[2].link)
                GPU_link(mat, "world_normals_get", &in[2].link);
 
+       GPU_material_flag_set(mat, GPU_MATFLAG_DIFFUSE);
+
        return GPU_stack_link(mat, node, "node_bsdf_diffuse", in, out);
 }
 
index 7b060bc68aa8dc2da71a25aac06a78d0183ea3d4..ada6e21356fc1f125dafaffdeacaea1b13e6e85d 100644 (file)
@@ -52,6 +52,8 @@ static int node_shader_gpu_bsdf_glass(GPUMaterial *mat, bNode *node, bNodeExecDa
        if (!in[3].link)
                GPU_link(mat, "world_normals_get", &in[3].link);
 
+       GPU_material_flag_set(mat, GPU_MATFLAG_GLOSSY | GPU_MATFLAG_REFRACT);
+
        return GPU_stack_link(mat, node, "node_bsdf_glass", in, out, GPU_uniform(&node->ssr_id));
 }
 
index c3fb43c0ce82f3723bd5eaee0ec322b2dbaf0121..f56837de2614e93ffbfda7a7b2f6c7456313756c 100644 (file)
@@ -51,6 +51,8 @@ static int node_shader_gpu_bsdf_glossy(GPUMaterial *mat, bNode *node, bNodeExecD
        if (!in[2].link)
                GPU_link(mat, "world_normals_get", &in[2].link);
 
+       GPU_material_flag_set(mat, GPU_MATFLAG_GLOSSY);
+
        return GPU_stack_link(mat, node, "node_bsdf_glossy", in, out, GPU_uniform(&node->ssr_id));
 }
 
index 7f02295d45f632bbcaa4bac38fc171052671bdee..831ac1c98da55314fa92eae58d5cb448436b551b 100644 (file)
@@ -117,6 +117,8 @@ static int node_shader_gpu_bsdf_principled(GPUMaterial *mat, bNode *node, bNodeE
                GPU_link(mat, "set_rgb", GPU_uniform((float *)one), &sss_scale);
        }
 
+       GPU_material_flag_set(mat, GPU_MATFLAG_DIFFUSE | GPU_MATFLAG_GLOSSY | GPU_MATFLAG_REFRACT);
+
        return GPU_stack_link(mat, node, "node_bsdf_principled_clearcoat", in, out, GPU_builtin(GPU_VIEW_POSITION),
                              GPU_uniform(&node->ssr_id), GPU_uniform(&node->sss_id), sss_scale);
 }
index 41dd3f8af3cb06fc244646fe63a4e857954cc47d..b59f1c80342eeaa2bbd5a2fd847366eb04ab8714 100644 (file)
@@ -52,6 +52,8 @@ static int node_shader_gpu_bsdf_refraction(GPUMaterial *mat, bNode *node, bNodeE
        if (!in[3].link)
                GPU_link(mat, "world_normals_get", &in[3].link);
 
+       GPU_material_flag_set(mat, GPU_MATFLAG_REFRACT);
+
        return GPU_stack_link(mat, node, "node_bsdf_refraction", in, out);
 }
 
index 2c0949f275c5602a87ea967cac05c09189fe9c52..349db30af14032da14d117a5d9261292aeaf47b8 100644 (file)
@@ -45,6 +45,8 @@ static int node_shader_gpu_bsdf_translucent(GPUMaterial *mat, bNode *node, bNode
        if (!in[1].link)
                GPU_link(mat, "world_normals_get", &in[1].link);
 
+       GPU_material_flag_set(mat, GPU_MATFLAG_DIFFUSE);
+
        return GPU_stack_link(mat, node, "node_bsdf_translucent", in, out);
 }
 
index ce331f03d4e6d0deabde77ad8c2e25a04abd2134..59b831c0dab1950aa513133b6cbc08c1e2b68d7b 100644 (file)
@@ -46,6 +46,8 @@ static int node_shader_gpu_bsdf_velvet(GPUMaterial *mat, bNode *node, bNodeExecD
        if (!in[2].link)
                GPU_link(mat, "world_normals_get", &in[2].link);
 
+       GPU_material_flag_set(mat, GPU_MATFLAG_DIFFUSE);
+
        return GPU_stack_link(mat, node, "node_bsdf_velvet", in, out);
 }
 
index 57fb90265950777b5d9edaa09980afd3a07fd9a2..3f0ba3c1c60f8431c53d9e6c5371ac060187d358 100644 (file)
@@ -54,6 +54,8 @@ static int node_shader_gpu_subsurface_scattering(GPUMaterial *mat, bNode *node,
        if (!in[5].link)
                GPU_link(mat, "world_normals_get", &in[5].link);
 
+       GPU_material_flag_set(mat, GPU_MATFLAG_DIFFUSE);
+
        if (node->sss_id == 1) {
                bNodeSocket *socket = BLI_findlink(&node->original->inputs, 2);
                bNodeSocketValueRGBA *socket_data = socket->default_value;