Commit: d8223468fe445797a300dd5cd97fe49f74ca6128
Author: Brecht Van Lommel
Date:   Thu Jul 5 17:20:44 2018 +0200
Branches: blender2.8
https://developer.blender.org/rBd8223468fe445797a300dd5cd97fe49f74ca6128

GPU: avoid unnecessary multiple nodetree localize and output finding.

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

M       source/blender/blenkernel/BKE_node.h
M       source/blender/gpu/intern/gpu_material.c
M       source/blender/nodes/shader/node_shader_tree.c
M       source/blender/nodes/shader/node_shader_util.c
M       source/blender/nodes/shader/node_shader_util.h
M       source/blender/nodes/shader/nodes/node_shader_common.c

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

diff --git a/source/blender/blenkernel/BKE_node.h 
b/source/blender/blenkernel/BKE_node.h
index 1578176d465..a400337e2cf 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -254,7 +254,6 @@ typedef struct bNodeType {
 /* nodetype->compatibility */
 #define NODE_OLD_SHADING       (1 << 0)
 #define NODE_NEW_SHADING       (1 << 1)
-#define NODE_NEWER_SHADING     (1 << 2)
 
 /* node resize directions */
 #define NODE_RESIZE_TOP                1
@@ -814,8 +813,8 @@ struct bNodeTreeExec *ntreeShaderBeginExecTree(struct 
bNodeTree *ntree);
 void            ntreeShaderEndExecTree(struct bNodeTreeExec *exec);
 bool            ntreeShaderExecTree(struct bNodeTree *ntree, int thread);
 
-void            ntreeGPUMaterialNodes(struct bNodeTree *ntree, struct 
GPUMaterial *mat, short compatibility);
-void            ntreeGPUMaterialDomain(struct bNodeTree *ntree, bool 
*has_surface_output, bool *has_volume_output);
+void            ntreeGPUMaterialNodes(struct bNodeTree *ntree, struct 
GPUMaterial *mat,
+                                      bool *has_surface_output, bool 
*has_volume_output);
 
 /** \} */
 
diff --git a/source/blender/gpu/intern/gpu_material.c 
b/source/blender/gpu/intern/gpu_material.c
index 9c776e64ba0..c224e3e0e32 100644
--- a/source/blender/gpu/intern/gpu_material.c
+++ b/source/blender/gpu/intern/gpu_material.c
@@ -644,8 +644,7 @@ GPUMaterial *GPU_material_from_nodetree(
        mat->engine_type = engine_type;
        mat->options = options;
 
-       ntreeGPUMaterialNodes(ntree, mat, NODE_NEW_SHADING | 
NODE_NEWER_SHADING);
-       ntreeGPUMaterialDomain(ntree, &has_surface_output, &has_volume_output);
+       ntreeGPUMaterialNodes(ntree, mat, &has_surface_output, 
&has_volume_output);
 
        if (has_surface_output) {
                mat->domain |= GPU_DOMAIN_SURFACE;
diff --git a/source/blender/nodes/shader/node_shader_tree.c 
b/source/blender/nodes/shader/node_shader_tree.c
index 301fd3c35a8..329e850d19e 100644
--- a/source/blender/nodes/shader/node_shader_tree.c
+++ b/source/blender/nodes/shader/node_shader_tree.c
@@ -258,11 +258,11 @@ static bNodeSocket *ntree_shader_node_find_output(bNode 
*node,
  * also returned.
  */
 static bool ntree_shader_has_displacement(bNodeTree *ntree,
+                                          bNode *output_node,
                                           bNode **r_node,
                                           bNodeSocket **r_socket,
                                           bNodeLink **r_link)
 {
-       bNode *output_node = ntree_shader_output_node(ntree);
        if (output_node == NULL) {
                /* We can't have displacement without output node, apparently. 
*/
                return false;
@@ -426,17 +426,13 @@ static void ntree_shader_link_builtin_normal(bNodeTree 
*ntree,
 /* Re-link displacement output to unconnected normal sockets via bump node.
  * This way material with have proper displacement in the viewport.
  */
-static void ntree_shader_relink_displacement(bNodeTree *ntree,
-                                             short compatibility)
+static void ntree_shader_relink_displacement(bNodeTree *ntree, bNode 
*output_node)
 {
-       if ((compatibility & NODE_NEW_SHADING) == 0) {
-               /* We can only deal with new shading system here. */
-               return;
-       }
        bNode *displacement_node;
        bNodeSocket *displacement_socket;
        bNodeLink *displacement_link;
        if (!ntree_shader_has_displacement(ntree,
+                                          output_node,
                                           &displacement_node,
                                           &displacement_socket,
                                           &displacement_link))
@@ -514,14 +510,8 @@ static bool ntree_tag_ssr_bsdf_cb(bNode *fromnode, bNode 
*UNUSED(tonode), void *
 /* EEVEE: Scan the ntree to set the Screen Space Reflection
  * layer id of every specular node.
  */
-static void ntree_shader_tag_ssr_node(bNodeTree *ntree, short compatibility)
+static void ntree_shader_tag_ssr_node(bNodeTree *ntree, bNode *output_node)
 {
-       if ((compatibility & NODE_NEWER_SHADING) == 0) {
-               /* We can only deal with new shading system here. */
-               return;
-       }
-
-       bNode *output_node = ntree_shader_output_node(ntree);
        if (output_node == NULL) {
                return;
        }
@@ -549,14 +539,8 @@ static bool ntree_tag_sss_bsdf_cb(bNode *fromnode, bNode 
*UNUSED(tonode), void *
 
 /* EEVEE: Scan the ntree to set the Subsurface Scattering id of every SSS node.
  */
-static void ntree_shader_tag_sss_node(bNodeTree *ntree, short compatibility)
+static void ntree_shader_tag_sss_node(bNodeTree *ntree, bNode *output_node)
 {
-       if ((compatibility & NODE_NEWER_SHADING) == 0) {
-               /* We can only deal with new shading system here. */
-               return;
-       }
-
-       bNode *output_node = ntree_shader_output_node(ntree);
        if (output_node == NULL) {
                return;
        }
@@ -567,15 +551,26 @@ static void ntree_shader_tag_sss_node(bNodeTree *ntree, 
short compatibility)
        nodeChainIter(ntree, output_node, ntree_tag_sss_bsdf_cb, &sss_id, true);
 }
 
-/* EEVEE: Find which material domain are used (volume, surface ...).
- */
-void ntreeGPUMaterialDomain(bNodeTree *ntree, bool *has_surface_output, bool 
*has_volume_output)
+void ntreeGPUMaterialNodes(bNodeTree *ntree, GPUMaterial *mat, bool 
*has_surface_output, bool *has_volume_output)
 {
        /* localize tree to create links for reroute and mute */
        bNodeTree *localtree = ntreeLocalize(ntree);
+       bNode *output = ntree_shader_output_node(localtree);
+       bNodeTreeExec *exec;
+
+       /* Perform all needed modifications on the tree in order to support
+        * displacement/bump mapping.
+        */
+       ntree_shader_relink_displacement(localtree, output);
+
+       ntree_shader_tag_ssr_node(localtree, output);
+       ntree_shader_tag_sss_node(localtree, output);
 
-       struct bNode *output = ntree_shader_output_node(localtree);
+       exec = ntreeShaderBeginExecTree(localtree);
+       ntreeExecGPUNodes(exec, mat, 1);
+       ntreeShaderEndExecTree(exec);
 
+       /* EEVEE: Find which material domain was used (volume, surface ...). */
        *has_surface_output = false;
        *has_volume_output = false;
 
@@ -596,28 +591,6 @@ void ntreeGPUMaterialDomain(bNodeTree *ntree, bool 
*has_surface_output, bool *ha
        MEM_freeN(localtree);
 }
 
-void ntreeGPUMaterialNodes(bNodeTree *ntree, GPUMaterial *mat, short 
compatibility)
-{
-       /* localize tree to create links for reroute and mute */
-       bNodeTree *localtree = ntreeLocalize(ntree);
-       bNodeTreeExec *exec;
-
-       /* Perform all needed modifications on the tree in order to support
-        * displacement/bump mapping.
-        */
-       ntree_shader_relink_displacement(localtree, compatibility);
-
-       ntree_shader_tag_ssr_node(localtree, compatibility);
-       ntree_shader_tag_sss_node(localtree, compatibility);
-
-       exec = ntreeShaderBeginExecTree(localtree);
-       ntreeExecGPUNodes(exec, mat, 1, compatibility);
-       ntreeShaderEndExecTree(exec);
-
-       ntreeFreeTree(localtree);
-       MEM_freeN(localtree);
-}
-
 bNodeTreeExec *ntreeShaderBeginExecTree_internal(bNodeExecContext *context, 
bNodeTree *ntree, bNodeInstanceKey parent_key)
 {
        bNodeTreeExec *exec;
diff --git a/source/blender/nodes/shader/node_shader_util.c 
b/source/blender/nodes/shader/node_shader_util.c
index 5cc7d14bc8b..1ae50dab358 100644
--- a/source/blender/nodes/shader/node_shader_util.c
+++ b/source/blender/nodes/shader/node_shader_util.c
@@ -207,7 +207,7 @@ bNode *nodeGetActiveTexture(bNodeTree *ntree)
        return inactivenode;
 }
 
-void ntreeExecGPUNodes(bNodeTreeExec *exec, GPUMaterial *mat, int do_outputs, 
short compatibility)
+void ntreeExecGPUNodes(bNodeTreeExec *exec, GPUMaterial *mat, int do_outputs)
 {
        bNodeExec *nodeexec;
        bNode *node;
@@ -226,7 +226,7 @@ void ntreeExecGPUNodes(bNodeTreeExec *exec, GPUMaterial 
*mat, int do_outputs, sh
                do_it = false;
                /* for groups, only execute outputs for edited group */
                if (node->typeinfo->nclass == NODE_CLASS_OUTPUT) {
-                       if (node->typeinfo->compatibility & compatibility)
+                       if (node->typeinfo->compatibility & NODE_NEW_SHADING)
                                if (do_outputs && (node->flag & NODE_DO_OUTPUT))
                                        do_it = true;
                }
diff --git a/source/blender/nodes/shader/node_shader_util.h 
b/source/blender/nodes/shader/node_shader_util.h
index 4fb18b1a9d8..7fce5ed9927 100644
--- a/source/blender/nodes/shader/node_shader_util.h
+++ b/source/blender/nodes/shader/node_shader_util.h
@@ -98,6 +98,6 @@ void node_gpu_stack_from_data(struct GPUNodeStack *gs, int 
type, struct bNodeSta
 void node_data_from_gpu_stack(struct bNodeStack *ns, struct GPUNodeStack *gs);
 void node_shader_gpu_tex_mapping(struct GPUMaterial *mat, struct bNode *node, 
struct GPUNodeStack *in, struct GPUNodeStack *out);
 
-void ntreeExecGPUNodes(struct bNodeTreeExec *exec, struct GPUMaterial *mat, 
int do_outputs, short compatibility);
+void ntreeExecGPUNodes(struct bNodeTreeExec *exec, struct GPUMaterial *mat, 
int do_outputs);
 
 #endif
diff --git a/source/blender/nodes/shader/nodes/node_shader_common.c 
b/source/blender/nodes/shader/nodes/node_shader_common.c
index 24de03dbda4..09fc10a4c71 100644
--- a/source/blender/nodes/shader/nodes/node_shader_common.c
+++ b/source/blender/nodes/shader/nodes/node_shader_common.c
@@ -215,11 +215,7 @@ static int gpu_group_execute(GPUMaterial *mat, bNode 
*node, bNodeExecData *execd
                return 0;
 
        group_gpu_copy_inputs(node, in, exec->stack);
-#if 0   /* XXX NODE_GROUP_EDIT is deprecated, depends on node space */
-       ntreeExecGPUNodes(exec, mat, (node->flag & NODE_GROUP_EDIT));
-#else
-       ntreeExecGPUNodes(exec, mat, 0, NODE_NEW_SHADING | NODE_OLD_SHADING);
-#endif
+       ntreeExecGPUNodes(exec, mat, 0);
        group_gpu_move_outputs(node, out, exec->stack);
 
        return 1;

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to