Significant memory leaking with shader application
Hi,
I've been experiencing issues with any shader used through libplacebo.
The memory seems to increase with every frame rendered/processed with the shader applied.
I've spent a while trying to determine the source of the problem and it seems to be coming from libplacebo itself.
My use case is a little complicated to reproduce because it relies on VapourSynth and vs-placebo
.
The specific issue seems to be only related to shaders, as other operations such as debanding do not leak memory.
With my current testing, the memory increases on average by 1GB every 1000 frames rendered.
The shader I'm using is SSimDownscaler, which can be found here: https://gist.github.com/igv/36508af3ffc84410fe39761d6969be10
Which is being used to downsample a 3840x2160 image to 1920x1080.
The shader code of vs-placebo
is available here: https://github.com/Lypheo/vs-placebo/blob/master/shader.c
And the specific part that seem to cause issues is the do_plane_S
function: https://github.com/Lypheo/vs-placebo/blob/master/shader.c#L34-L62
Interestingly, on current master, the only time that the memory does not leak is when pl_render_image
returns false at the beginning of the processing.
I have no idea what that could mean, however.
I've done a bisect and ended up on commit 8ef0f369, for which I can consistently reproduce memory leaking.
8ef0f36917b84d3893bee68d87293b37160f12dc is the first bad commit
commit 8ef0f36917b84d3893bee68d87293b37160f12dc
Author: Niklas Haas <git@haasn.xyz>
Date: Thu Feb 4 14:41:15 2021 +0100
renderer: merge similar planes before heavy operations
This makes most types of planar operations faster, especially
scaling, debanding, AV1 grain application and other plane shaders.
Care needs to be taken to avoid doing this unnecessarily though, to
avoid an FBO roundtrip when there's no point.
Note that we try re-using the same plane texture format if possible, and
only pick as many components for the FBO as we deem necessary. This cuts
down on memory bandwidth.
Closes https://code.videolan.org/videolan/libplacebo/-/issues/26
src/renderer.c | 203 ++++++++++++++++++++++++++++++++++++++++++++++++---------
As for a reproducible test case, I don't think I can figure out a way to use libplacebo alone easily.
At best I could get a reproducible script that uses both VapourSynth and vs-placebo.
I'm looking at getting a meaningful valgrind report as well.