[Bf-blender-cvs] [ad64cb63448] blender2.8: GPUMaterial: Make Localize tree live longer

Clément Foucault noreply at git.blender.org
Wed Aug 1 22:10:40 CEST 2018


Commit: ad64cb63448d69ec1667bfa2e4941dfb996841dd
Author: Clément Foucault
Date:   Wed Aug 1 19:25:58 2018 +0200
Branches: blender2.8
https://developer.blender.org/rBad64cb63448d69ec1667bfa2e4941dfb996841dd

GPUMaterial: Make Localize tree live longer

This is in order to reference the localized node->storage when populating
the UBO data.

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

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

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

diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h
index cf55885a5ef..901822583cb 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -811,7 +811,7 @@ void            ntreeShaderEndExecTree(struct bNodeTreeExec *exec);
 bool            ntreeShaderExecTree(struct bNodeTree *ntree, int thread);
 struct bNode   *ntreeShaderOutputNode(struct bNodeTree *ntree, int target);
 
-void            ntreeGPUMaterialNodes(struct bNodeTree *ntree, struct GPUMaterial *mat,
+void            ntreeGPUMaterialNodes(struct bNodeTree *localtree, 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 2264836f24a..5e0d9275aa2 100644
--- a/source/blender/gpu/intern/gpu_material.c
+++ b/source/blender/gpu/intern/gpu_material.c
@@ -595,7 +595,9 @@ GPUMaterial *GPU_material_from_nodetree(
 	mat->engine_type = engine_type;
 	mat->options = options;
 
-	ntreeGPUMaterialNodes(ntree, mat, &has_surface_output, &has_volume_output);
+	/* localize tree to create links for reroute and mute */
+	bNodeTree *localtree = ntreeLocalize(ntree);
+	ntreeGPUMaterialNodes(localtree, mat, &has_surface_output, &has_volume_output);
 
 	if (has_surface_output) {
 		mat->domain |= GPU_DOMAIN_SURFACE;
@@ -640,6 +642,11 @@ GPUMaterial *GPU_material_from_nodetree(
 		mat->status = GPU_MAT_FAILED;
 	}
 
+	/* Only free after GPU_pass_shader_get where GPUUniformBuffer
+	 * read data from the local tree. */
+	ntreeFreeTree(localtree);
+	MEM_freeN(localtree);
+
 	/* note that even if building the shader fails in some way, we still keep
 	 * it to avoid trying to compile again and again, and simply do not use
 	 * the actual shader on drawing */
diff --git a/source/blender/nodes/shader/node_shader_tree.c b/source/blender/nodes/shader/node_shader_tree.c
index 919af171756..6f2c7835a3c 100644
--- a/source/blender/nodes/shader/node_shader_tree.c
+++ b/source/blender/nodes/shader/node_shader_tree.c
@@ -583,10 +583,9 @@ static void ntree_shader_tag_sss_node(bNodeTree *ntree, bNode *output_node)
 	nodeChainIter(ntree, output_node, ntree_tag_sss_bsdf_cb, &sss_id, true);
 }
 
-void ntreeGPUMaterialNodes(bNodeTree *ntree, GPUMaterial *mat, bool *has_surface_output, bool *has_volume_output)
+/* This one needs to work on a local tree. */
+void ntreeGPUMaterialNodes(bNodeTree *localtree, 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 = ntreeShaderOutputNode(localtree, SHD_OUTPUT_EEVEE);
 	bNodeTreeExec *exec;
 
@@ -618,9 +617,6 @@ void ntreeGPUMaterialNodes(bNodeTree *ntree, GPUMaterial *mat, bool *has_surface
 			*has_volume_output = (nodeCountSocketLinks(localtree, volume_sock) > 0);
 		}
 	}
-
-	ntreeFreeTree(localtree);
-	MEM_freeN(localtree);
 }
 
 bNodeTreeExec *ntreeShaderBeginExecTree_internal(bNodeExecContext *context, bNodeTree *ntree, bNodeInstanceKey parent_key)



More information about the Bf-blender-cvs mailing list