gallium/u_threaded: merge draws faster by merging indexbuf unreferencing

Instead of N times decrementing the index buffer refcount by 1, decrement
it by N once.

Reviewed-by: Rob Clark <robdclark@chromium.org>
Reviewed-By: Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11349>
This commit is contained in:
Marek Olšák 2021-06-13 12:13:50 -04:00 committed by Marge Bot
parent 639579d116
commit eb0fa78b68
2 changed files with 17 additions and 7 deletions

View file

@ -163,6 +163,20 @@ pipe_resource_reference(struct pipe_resource **dst, struct pipe_resource *src)
*dst = src;
}
/**
* Subtract the given number of references.
*/
static inline void
pipe_drop_resource_references(struct pipe_resource *dst, int num_refs)
{
int count = p_atomic_add_return(&dst->reference.count, -num_refs);
assert(count >= 0);
/* Underflows shouldn't happen, but let's be safe. */
if (count <= 0)
pipe_resource_destroy(dst);
}
/**
* Same as pipe_surface_release, but used when pipe_context doesn't exist
* anymore.

View file

@ -2969,9 +2969,6 @@ tc_call_draw_single(struct pipe_context *pipe, void *call, uint64_t *last_ptr)
multi[1].count = next->info.max_index;
multi[1].index_bias = next->index_bias;
if (next->info.index_size)
tc_drop_resource_reference(next->info.index.resource);
/* Find how many other draws can be merged. */
next = get_next_call(next, tc_draw_single);
for (; next != last && is_next_call_a_mergeable_draw(first, next);
@ -2981,15 +2978,14 @@ tc_call_draw_single(struct pipe_context *pipe, void *call, uint64_t *last_ptr)
multi[num_draws].count = next->info.max_index;
multi[num_draws].index_bias = next->index_bias;
index_bias_varies |= first->index_bias != next->index_bias;
if (next->info.index_size)
tc_drop_resource_reference(next->info.index.resource);
}
first->info.index_bias_varies = index_bias_varies;
pipe->draw_vbo(pipe, &first->info, 0, NULL, multi, num_draws);
/* Since all draws use the same index buffer, drop all references at once. */
if (first->info.index_size)
tc_drop_resource_reference(first->info.index.resource);
pipe_drop_resource_references(first->info.index.resource, num_draws);
return call_size(tc_draw_single) * num_draws;
}