Commit 176e7615 authored by Michel Dänzer's avatar Michel Dänzer Committed by Michel Dänzer

gallium/util: Break recursion in pipe_resource_reference

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 * by ~4%,
and might also have impacted performance.

Fixes: ecd6fce2 ("mesa/st: support lowering multi-planar YUV")
* Add comment above pipe_resource_next_reference [Samuel Pitoiset]
* Use loop to unreference the full chain of resources referenced via
  the next members [Timothy Arceri]
* Stop chasing ->next chain at the first sub-resource which isn't
  destroyed [Nicolai Hähnle]
Reviewed-by: default avatarNicolai Hähnle <>
Reviewed-by: default avatarMarek Olšák <>
parent 1c00af42
......@@ -137,8 +137,14 @@ 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);
old_tex->screen->resource_destroy(old_tex->screen, old_tex);
/* Avoid recursion, which would prevent inlining this function */
do {
struct pipe_resource *next = old_tex->next;
old_tex->screen->resource_destroy(old_tex->screen, old_tex);
old_tex = next;
} while (pipe_reference_described(&old_tex->reference, NULL,
*ptr = tex;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment