diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2018-08-01 20:25:58 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2018-08-01 23:08:36 +0300 |
commit | ad64cb63448d69ec1667bfa2e4941dfb996841dd (patch) | |
tree | 837354560da816a85fa4a4aa2602394eec7f0002 /source/blender | |
parent | 4510f30026da8eb090062687f386b9e3a7cf3fa3 (diff) |
GPUMaterial: Make Localize tree live longer
This is in order to reference the localized node->storage when populating
the UBO data.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/BKE_node.h | 2 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_material.c | 9 | ||||
-rw-r--r-- | source/blender/nodes/shader/node_shader_tree.c | 8 |
3 files changed, 11 insertions, 8 deletions
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) |