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:
Miguel Pozo 2022-11-14 12:21:37 +01:00
parent 0190b104c8
commit a84c92fc73
Notes: blender-bot 2023-11-23 19:28:52 +01:00
Referenced by issue #100749, Blender LTS: Maintenance Task 3.3
Referenced by issue #103903, Regression: Eevee render takes 3x longer in 3.4 than 3.1.2 - shading related?
Referenced by issue #98989, Regression: Eevee bad performance when using procedural bump map.
Referenced by issue #115226, A Shader Compile Error Occurs with Two AOV Outputs in a Specific Shader Node Configuration
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);