[Mesa-dev] [PATCH v3] gallium/util: Break recursion in pipe_resource_reference
Nicolai Hähnle
nhaehnle at gmail.com
Wed Jun 14 07:42:33 UTC 2017
On 14.06.2017 05:39, Michel Dänzer wrote:
> From: Michel Dänzer <michel.daenzer at amd.com>
>
> It calling itself recursively prevented it from being inlined, resulting
> in a copy being generated in every compilation unit referencing it. This
> bloated the text segment of the Gallium mega-driver *_dri.so by ~4%,
> and might also have impacted performance.
Did you update the size measurement?
>
> Fixes: ecd6fce2611e ("mesa/st: support lowering multi-planar YUV")
> v2:
> * Add comment above pipe_resource_next_reference [Samuel Pitoiset]
> v3:
> * Use loop to unreference the full chain of resources referenced via
> the next members [Timothy Arceri]
>
> Signed-off-by: Michel Dänzer <michel.daenzer at amd.com>
> ---
> src/gallium/auxiliary/util/u_inlines.h | 13 ++++++++++++-
> 1 file changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/src/gallium/auxiliary/util/u_inlines.h b/src/gallium/auxiliary/util/u_inlines.h
> index 6a3d5043cf..08326da03d 100644
> --- a/src/gallium/auxiliary/util/u_inlines.h
> +++ b/src/gallium/auxiliary/util/u_inlines.h
> @@ -137,8 +137,19 @@ pipe_resource_reference(struct pipe_resource **ptr, struct pipe_resource *tex)
>
> if (pipe_reference_described(&(*ptr)->reference, &tex->reference,
> (debug_reference_descriptor)debug_describe_resource)) {
> - pipe_resource_reference(&old_tex->next, NULL);
> + struct pipe_resource *next = old_tex->next;
> +
> old_tex->screen->resource_destroy(old_tex->screen, old_tex);
> +
> + /* Avoid recursion, which would prevent inlining this function */
> + while (next) {
> + old_tex = next;
> + next = old_tex->next;
> + old_tex->next = NULL;
Is this really necessary? I don't think so, but if it is, it's probably
necessary above as well. Either way, it's best to be consistent about it.
Cheers,
Nicolai
> + if (pipe_reference_described(&old_tex->reference, NULL,
> + (debug_reference_descriptor)debug_describe_resource))
> + old_tex->screen->resource_destroy(old_tex->screen, old_tex);
> + }
> }
> *ptr = tex;
> }
>
--
Lerne, wie die Welt wirklich ist,
Aber vergiss niemals, wie sie sein sollte.
More information about the mesa-dev
mailing list