Skip to content

Commit

Permalink
EEVEE: Fix GPUNodeLink memory leak for displacement nodes using SHD_S…
Browse files Browse the repository at this point in the history
…PACE_WORLD

When the displacement space is set to SHD_SPACE_WORLD, the GLSL method
"node_displacement_world" is used instead of the "node_displacement_object" method. The two GLSL methods:
```
void node_displacement_object(
    float height, float midlevel, float scale, vec3 N, mat4 obmat, out vec3 result)
{
  N = (vec4(N, 0.0) * obmat).xyz;
  result = (height - midlevel) * scale * normalize(N);
  result = (obmat * vec4(result, 0.0)).xyz;
}

void node_displacement_world(float height, float midlevel, float scale, vec3 N, out vec3 result)
{
  result = (height - midlevel) * scale * normalize(N);
}
```
In contrast to the "node_displacement_object" method, the "node_displacement_world"
does not require an "obmat" parameter. Attempting to still pass "GPU_builtin(GPU_OBJECT_MATRIX)"
as additional parameter will result in a memory leak. The "GPUNodeLink" allocated in
the "GPU_builtin" method will never get released.

Fixes T83941 Memory leak when using the Displacement shader node in Eevee with the displacement
space set to "World Space"
  • Loading branch information
Michael Möller authored and Clément Foucault committed Jan 29, 2021
1 parent b3fc885 commit 5d215d5
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions source/blender/nodes/shader/nodes/node_shader_displacement.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ static int gpu_shader_displacement(GPUMaterial *mat,
mat, node, "node_displacement_object", in, out, GPU_builtin(GPU_OBJECT_MATRIX));
}

return GPU_stack_link(
mat, node, "node_displacement_world", in, out, GPU_builtin(GPU_OBJECT_MATRIX));
return GPU_stack_link(mat, node, "node_displacement_world", in, out);
}

/* node type definition */
Expand Down

0 comments on commit 5d215d5

Please sign in to comment.