GPUMaterial: Make Localize tree live longer

This is in order to reference the localized node->storage when populating
the UBO data.
This commit is contained in:
Clément Foucault 2018-08-01 19:25:58 +02:00
parent 4510f30026
commit ad64cb6344
3 changed files with 11 additions and 8 deletions

View File

@ -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);
/** \} */

View File

@ -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 */

View File

@ -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)