Fix T98989: Performance regression when using multiple bump nodes

Ensure each graph material_function only evaluates the input links that are connected to it.

Differential Revision: https://developer.blender.org/D16425
This commit is contained in:
2022-11-14 12:21:37 +01:00
parent 0190b104c8
commit a84c92fc73
3 changed files with 13 additions and 2 deletions

View File

@@ -620,11 +620,21 @@ void GPUCodegen::generate_graphs()
std::stringstream eval_ss;
eval_ss << "\n/* Generated Functions */\n\n";
LISTBASE_FOREACH (GPUNodeGraphFunctionLink *, func_link, &graph.material_functions) {
/* Untag every node in the graph to avoid serializing nodes from other functions */
LISTBASE_FOREACH (GPUNode *, node, &graph.nodes) {
node->tag &= ~GPU_NODE_TAG_FUNCTION;
}
/* Tag only the nodes needed for the current function */
gpu_nodes_tag(func_link->outlink, GPU_NODE_TAG_FUNCTION);
char *fn = graph_serialize(GPU_NODE_TAG_FUNCTION, func_link->outlink);
eval_ss << "float " << func_link->name << "() {\n" << fn << "}\n\n";
MEM_SAFE_FREE(fn);
}
output.material_functions = extract_c_str(eval_ss);
/* Leave the function tags as they were before serialization */
LISTBASE_FOREACH (GPUNodeGraphFunctionLink *, funclink, &graph.material_functions) {
gpu_nodes_tag(funclink->outlink, GPU_NODE_TAG_FUNCTION);
}
}
LISTBASE_FOREACH (GPUMaterialAttribute *, attr, &graph.attributes) {

View File

@@ -890,7 +890,7 @@ void gpu_node_graph_free(GPUNodeGraph *graph)
/* Prune Unused Nodes */
static void gpu_nodes_tag(GPUNodeLink *link, eGPUNodeTag tag)
void gpu_nodes_tag(GPUNodeLink *link, eGPUNodeTag tag)
{
GPUNode *node;

View File

@@ -66,7 +66,7 @@ typedef enum {
GPU_NODE_TAG_COMPOSITOR = (1 << 6),
} eGPUNodeTag;
ENUM_OPERATORS(eGPUNodeTag, GPU_NODE_TAG_FUNCTION)
ENUM_OPERATORS(eGPUNodeTag, GPU_NODE_TAG_COMPOSITOR)
struct GPUNode {
struct GPUNode *next, *prev;
@@ -186,6 +186,7 @@ typedef struct GPUNodeGraph {
/* Node Graph */
void gpu_nodes_tag(GPUNodeLink *link, eGPUNodeTag tag);
void gpu_node_graph_prune_unused(GPUNodeGraph *graph);
void gpu_node_graph_finalize_uniform_attrs(GPUNodeGraph *graph);