gallium/u_threaded: store start/count in min/max_index for better packing

This increases the maximum number of draws per batch from 192 to 256.

Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7441>
This commit is contained in:
Marek Olšák
2020-11-01 11:44:04 -05:00
committed by Marge Bot
parent 1cd455b17b
commit 52ad436740
2 changed files with 36 additions and 17 deletions
+29 -14
View File
@@ -64,7 +64,6 @@ enum tc_call_id {
* not needed. */
struct tc_draw_single {
struct pipe_draw_info info;
struct pipe_draw_start_count draw;
};
typedef void (*tc_execute)(struct pipe_context *pipe, union tc_payload *payload);
@@ -95,8 +94,6 @@ simplify_draw_info(struct pipe_draw_info *info)
*/
info->index_bounds_valid = false;
info->_pad = 0;
info->min_index = 0;
info->max_index = ~0;
/* This shouldn't be set when merging single draws. */
info->increment_draw_id = false;
@@ -124,10 +121,16 @@ is_next_call_a_mergeable_draw(struct tc_draw_single *first_info,
*next_info = (struct tc_draw_single*)&next->payload;
simplify_draw_info(&(*next_info)->info);
STATIC_ASSERT(offsetof(struct pipe_draw_info, min_index) ==
sizeof(struct pipe_draw_info) - 8);
STATIC_ASSERT(offsetof(struct pipe_draw_info, max_index) ==
sizeof(struct pipe_draw_info) - 4);
/* All fields must be the same except start and count. */
/* u_threaded_context stores start/count in min/max_index for single draws. */
return memcmp((uint32_t*)&first_info->info,
(uint32_t*)&(*next_info)->info,
sizeof(struct pipe_draw_info)) == 0;
sizeof(struct pipe_draw_info) - 8) == 0;
}
static void
@@ -162,10 +165,11 @@ tc_batch_execute(void *job, UNUSED int thread_index)
struct pipe_draw_start_count multi[256];
unsigned num_draws = 2;
multi[0].start = first_info->draw.start;
multi[0].count = first_info->draw.count;
multi[1].start = next_info->draw.start;
multi[1].count = next_info->draw.count;
/* u_threaded_context stores start/count in min/max_index for single draws. */
multi[0].start = first_info->info.min_index;
multi[0].count = first_info->info.max_index;
multi[1].start = next_info->info.min_index;
multi[1].count = next_info->info.max_index;
if (next_info->info.index_size)
pipe_resource_reference(&next_info->info.index.resource, NULL);
@@ -175,8 +179,9 @@ tc_batch_execute(void *job, UNUSED int thread_index)
for (; next != last && num_draws < ARRAY_SIZE(multi) &&
is_next_call_a_mergeable_draw(first_info, next, &next_info);
next += next->num_call_slots, num_draws++) {
multi[num_draws].start = next_info->draw.start;
multi[num_draws].count = next_info->draw.count;
/* u_threaded_context stores start/count in min/max_index for single draws. */
multi[num_draws].start = next_info->info.min_index;
multi[num_draws].count = next_info->info.max_index;
if (next_info->info.index_size)
pipe_resource_reference(&next_info->info.index.resource, NULL);
@@ -2230,8 +2235,15 @@ static void
tc_call_draw_single(struct pipe_context *pipe, union tc_payload *payload)
{
struct tc_draw_single *info = (struct tc_draw_single*)payload;
struct pipe_draw_start_count draw;
pipe->draw_vbo(pipe, &info->info, NULL, &info->draw, 1);
/* u_threaded_context stores start/count in min/max_index for single draws. */
/* Drivers using u_threaded_context shouldn't use min/max_index. */
draw.start = info->info.min_index;
draw.count = info->info.max_index;
info->info.index_bounds_valid = false;
pipe->draw_vbo(pipe, &info->info, NULL, &draw, 1);
if (info->info.index_size)
pipe_resource_reference(&info->info.index.resource, NULL);
}
@@ -2311,8 +2323,9 @@ tc_draw_vbo(struct pipe_context *_pipe, const struct pipe_draw_info *info,
memcpy(&p->info, info, sizeof(*info));
p->info.has_user_indices = false;
p->info.index.resource = buffer;
p->draw.start = offset >> util_logbase2(index_size);
p->draw.count = draws[0].count;
/* u_threaded_context stores start/count in min/max_index for single draws. */
p->info.min_index = offset >> util_logbase2(index_size);
p->info.max_index = draws[0].count;
} else {
/* Non-indexed call or indexed with a real index buffer. */
struct tc_draw_single *p =
@@ -2322,7 +2335,9 @@ tc_draw_vbo(struct pipe_context *_pipe, const struct pipe_draw_info *info,
info->index.resource);
}
memcpy(&p->info, info, sizeof(*info));
p->draw = draws[0];
/* u_threaded_context stores start/count in min/max_index for single draws. */
p->info.min_index = draws[0].start;
p->info.max_index = draws[0].count;
}
}
+7 -3
View File
@@ -768,15 +768,15 @@ struct pipe_draw_info
* For indexed drawing, these fields apply after index lookup.
*/
int index_bias; /**< a bias to be added to each index */
unsigned min_index; /**< the min index */
unsigned max_index; /**< the max index */
/**
* Primitive restart enable/index (only applies to indexed drawing)
*/
unsigned restart_index;
/* Pointers must be at the end for an optimal structure layout on 64-bit. */
/* Pointers must be placed appropriately for optimal structure packing on
* 64-bit CPUs.
*/
/**
* An index buffer. When an index buffer is bound, all indices to vertices
@@ -788,6 +788,10 @@ struct pipe_draw_info
struct pipe_resource *resource; /**< real buffer */
const void *user; /**< pointer to a user buffer */
} index;
/* These must be last for better packing in u_threaded_context. */
unsigned min_index; /**< the min index */
unsigned max_index; /**< the max index */
};