mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-04-23 00:50:36 +02:00
gallium/u_threaded: Add to_call() helper
Add helper for casting the call, which when asserts are enabled will sanity check the call size to detect corruption. Signed-off-by: Rob Clark <robdclark@chromium.org> Reviewed-by: Marek Olšák <marek.olsak@amd.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10753>
This commit is contained in:
parent
e8640fef90
commit
3b69cbe06c
1 changed files with 47 additions and 38 deletions
|
|
@ -101,6 +101,17 @@ tc_clear_driver_thread(struct threaded_context *tc)
|
|||
#endif
|
||||
}
|
||||
|
||||
static void *
|
||||
to_call_check(void *ptr, unsigned num_slots)
|
||||
{
|
||||
#if TC_DEBUG >= 1
|
||||
struct tc_call_base *call = ptr;
|
||||
tc_assert(call->num_slots == num_slots);
|
||||
#endif
|
||||
return ptr;
|
||||
}
|
||||
#define to_call(ptr, type) ((struct type *)to_call_check((void *)(ptr), call_size(type)))
|
||||
|
||||
#define size_to_slots(size) DIV_ROUND_UP(size, 8)
|
||||
#define call_size(type) size_to_slots(sizeof(struct type))
|
||||
#define call_size_with_slots(type, num_slots) size_to_slots( \
|
||||
|
|
@ -219,7 +230,7 @@ tc_batch_execute(void *job, UNUSED int thread_index)
|
|||
|
||||
/* Draw call merging. */
|
||||
if (call->call_id == TC_CALL_draw_single) {
|
||||
struct tc_draw_single *first = (struct tc_draw_single *)call;
|
||||
struct tc_draw_single *first = to_call(call, tc_draw_single);
|
||||
struct tc_draw_single *next =
|
||||
(struct tc_draw_single *)(iter + first->base.num_slots);
|
||||
|
||||
|
|
@ -470,7 +481,7 @@ threaded_context_unwrap_sync(struct pipe_context *pipe)
|
|||
static void \
|
||||
tc_call_##func(struct pipe_context *pipe, void *call) \
|
||||
{ \
|
||||
pipe->func(pipe, addr(((struct tc_call_##func*)call)->state)); \
|
||||
pipe->func(pipe, addr(to_call(call, tc_call_##func)->state)); \
|
||||
} \
|
||||
\
|
||||
static void \
|
||||
|
|
@ -530,7 +541,7 @@ struct tc_query_call {
|
|||
static void
|
||||
tc_call_destroy_query(struct pipe_context *pipe, void *call)
|
||||
{
|
||||
struct pipe_query *query = ((struct tc_query_call*)call)->query;
|
||||
struct pipe_query *query = to_call(call, tc_query_call)->query;
|
||||
struct threaded_query *tq = threaded_query(query);
|
||||
|
||||
if (list_is_linked(&tq->head_unflushed))
|
||||
|
|
@ -550,7 +561,7 @@ tc_destroy_query(struct pipe_context *_pipe, struct pipe_query *query)
|
|||
static void
|
||||
tc_call_begin_query(struct pipe_context *pipe, void *call)
|
||||
{
|
||||
pipe->begin_query(pipe, ((struct tc_query_call*)call)->query);
|
||||
pipe->begin_query(pipe, to_call(call, tc_query_call)->query);
|
||||
}
|
||||
|
||||
static bool
|
||||
|
|
@ -571,7 +582,7 @@ struct tc_end_query_call {
|
|||
static void
|
||||
tc_call_end_query(struct pipe_context *pipe, void *call)
|
||||
{
|
||||
struct tc_end_query_call *p = (struct tc_end_query_call *)call;
|
||||
struct tc_end_query_call *p = to_call(call, tc_end_query_call);
|
||||
struct threaded_query *tq = threaded_query(p->query);
|
||||
|
||||
if (!list_is_linked(&tq->head_unflushed))
|
||||
|
|
@ -639,7 +650,7 @@ struct tc_query_result_resource {
|
|||
static void
|
||||
tc_call_get_query_result_resource(struct pipe_context *pipe, void *call)
|
||||
{
|
||||
struct tc_query_result_resource *p = (struct tc_query_result_resource *)call;
|
||||
struct tc_query_result_resource *p = to_call(call, tc_query_result_resource);
|
||||
|
||||
pipe->get_query_result_resource(pipe, p->query, p->wait, p->result_type,
|
||||
p->index, p->resource, p->offset);
|
||||
|
|
@ -675,7 +686,7 @@ struct tc_render_condition {
|
|||
static void
|
||||
tc_call_render_condition(struct pipe_context *pipe, void *call)
|
||||
{
|
||||
struct tc_render_condition *p = (struct tc_render_condition *)call;
|
||||
struct tc_render_condition *p = to_call(call, tc_render_condition);
|
||||
pipe->render_condition(pipe, p->query, p->condition, p->mode);
|
||||
}
|
||||
|
||||
|
|
@ -784,7 +795,7 @@ struct tc_framebuffer {
|
|||
static void
|
||||
tc_call_set_framebuffer_state(struct pipe_context *pipe, void *call)
|
||||
{
|
||||
struct pipe_framebuffer_state *p = &((struct tc_framebuffer*)call)->state;
|
||||
struct pipe_framebuffer_state *p = &to_call(call, tc_framebuffer)->state;
|
||||
|
||||
pipe->set_framebuffer_state(pipe, p);
|
||||
|
||||
|
|
@ -825,7 +836,7 @@ struct tc_tess_state {
|
|||
static void
|
||||
tc_call_set_tess_state(struct pipe_context *pipe, void *call)
|
||||
{
|
||||
float *p = ((struct tc_tess_state*)call)->state;
|
||||
float *p = to_call(call, tc_tess_state)->state;
|
||||
pipe->set_tess_state(pipe, p, p + 4);
|
||||
}
|
||||
|
||||
|
|
@ -925,7 +936,7 @@ struct tc_inlinable_constants {
|
|||
static void
|
||||
tc_call_set_inlinable_constants(struct pipe_context *pipe, void *call)
|
||||
{
|
||||
struct tc_inlinable_constants *p = (struct tc_inlinable_constants *)call;
|
||||
struct tc_inlinable_constants *p = to_call(call, tc_inlinable_constants);
|
||||
|
||||
pipe->set_inlinable_constants(pipe, p->shader, p->num_values, p->values);
|
||||
}
|
||||
|
|
@ -1319,7 +1330,7 @@ struct tc_stream_outputs {
|
|||
static void
|
||||
tc_call_set_stream_output_targets(struct pipe_context *pipe, void *call)
|
||||
{
|
||||
struct tc_stream_outputs *p = (struct tc_stream_outputs *)call;
|
||||
struct tc_stream_outputs *p = to_call(call, tc_stream_outputs);
|
||||
unsigned count = p->count;
|
||||
|
||||
pipe->set_stream_output_targets(pipe, count, p->targets, p->offsets);
|
||||
|
|
@ -1475,7 +1486,7 @@ static void
|
|||
tc_call_make_texture_handle_resident(struct pipe_context *pipe, void *call)
|
||||
{
|
||||
struct tc_make_texture_handle_resident *p =
|
||||
(struct tc_make_texture_handle_resident *)call;
|
||||
to_call(call, tc_make_texture_handle_resident);
|
||||
|
||||
pipe->make_texture_handle_resident(pipe, p->handle, p->resident);
|
||||
}
|
||||
|
|
@ -1515,7 +1526,7 @@ static void
|
|||
tc_call_make_image_handle_resident(struct pipe_context *pipe, void *call)
|
||||
{
|
||||
struct tc_make_image_handle_resident *p =
|
||||
(struct tc_make_image_handle_resident *)call;
|
||||
to_call(call, tc_make_image_handle_resident);
|
||||
|
||||
pipe->make_image_handle_resident(pipe, p->handle, p->access, p->resident);
|
||||
}
|
||||
|
|
@ -1549,8 +1560,7 @@ struct tc_replace_buffer_storage {
|
|||
static void
|
||||
tc_call_replace_buffer_storage(struct pipe_context *pipe, void *call)
|
||||
{
|
||||
struct tc_replace_buffer_storage *p =
|
||||
(struct tc_replace_buffer_storage *)call;
|
||||
struct tc_replace_buffer_storage *p = to_call(call, tc_replace_buffer_storage);
|
||||
|
||||
p->func(pipe, p->dst, p->src);
|
||||
tc_drop_resource_reference(p->dst);
|
||||
|
|
@ -1786,8 +1796,7 @@ struct tc_transfer_flush_region {
|
|||
static void
|
||||
tc_call_transfer_flush_region(struct pipe_context *pipe, void *call)
|
||||
{
|
||||
struct tc_transfer_flush_region *p =
|
||||
(struct tc_transfer_flush_region *)call;
|
||||
struct tc_transfer_flush_region *p = to_call(call, tc_transfer_flush_region);
|
||||
|
||||
pipe->transfer_flush_region(pipe, p->transfer, &p->box);
|
||||
}
|
||||
|
|
@ -1874,7 +1883,7 @@ struct tc_transfer_unmap {
|
|||
static void
|
||||
tc_call_transfer_unmap(struct pipe_context *pipe, void *call)
|
||||
{
|
||||
struct tc_transfer_unmap *p = (struct tc_transfer_unmap *) call;
|
||||
struct tc_transfer_unmap *p = to_call(call, tc_transfer_unmap);
|
||||
if (p->was_staging_transfer) {
|
||||
struct threaded_resource *tres = threaded_resource(p->resource);
|
||||
/* Nothing to do except keeping track of staging uploads */
|
||||
|
|
@ -2215,7 +2224,7 @@ struct tc_fence_call {
|
|||
static void
|
||||
tc_call_fence_server_sync(struct pipe_context *pipe, void *call)
|
||||
{
|
||||
struct pipe_fence_handle *fence = ((struct tc_fence_call*)call)->fence;
|
||||
struct pipe_fence_handle *fence = to_call(call, tc_fence_call)->fence;
|
||||
|
||||
pipe->fence_server_sync(pipe, fence);
|
||||
pipe->screen->fence_reference(pipe->screen, &fence, NULL);
|
||||
|
|
@ -2237,7 +2246,7 @@ tc_fence_server_sync(struct pipe_context *_pipe,
|
|||
static void
|
||||
tc_call_fence_server_signal(struct pipe_context *pipe, void *call)
|
||||
{
|
||||
struct pipe_fence_handle *fence = ((struct tc_fence_call*)call)->fence;
|
||||
struct pipe_fence_handle *fence = to_call(call, tc_fence_call)->fence;
|
||||
|
||||
pipe->fence_server_signal(pipe, fence);
|
||||
pipe->screen->fence_reference(pipe->screen, &fence, NULL);
|
||||
|
|
@ -2281,7 +2290,7 @@ struct tc_context_param {
|
|||
static void
|
||||
tc_call_set_context_param(struct pipe_context *pipe, void *call)
|
||||
{
|
||||
struct tc_context_param *p = (struct tc_context_param*)call;
|
||||
struct tc_context_param *p = to_call(call, tc_context_param);
|
||||
|
||||
if (pipe->set_context_param)
|
||||
pipe->set_context_param(pipe, p->param, p->value);
|
||||
|
|
@ -2348,7 +2357,7 @@ tc_flush_queries(struct threaded_context *tc)
|
|||
static void
|
||||
tc_call_flush(struct pipe_context *pipe, void *call)
|
||||
{
|
||||
struct tc_flush_call *p = (struct tc_flush_call *)call;
|
||||
struct tc_flush_call *p = to_call(call, tc_flush_call);
|
||||
struct pipe_screen *screen = pipe->screen;
|
||||
|
||||
pipe->flush(pipe, p->fence ? &p->fence : NULL, p->flags);
|
||||
|
|
@ -2414,7 +2423,7 @@ struct tc_draw_single_drawid {
|
|||
static void
|
||||
tc_call_draw_single_drawid(struct pipe_context *pipe, void *call)
|
||||
{
|
||||
struct tc_draw_single_drawid *info_drawid = (struct tc_draw_single_drawid*)call;
|
||||
struct tc_draw_single_drawid *info_drawid = to_call(call, tc_draw_single_drawid);
|
||||
struct tc_draw_single *info = &info_drawid->base;
|
||||
|
||||
/* u_threaded_context stores start/count in min/max_index for single draws. */
|
||||
|
|
@ -2437,7 +2446,7 @@ tc_call_draw_single_drawid(struct pipe_context *pipe, void *call)
|
|||
static void
|
||||
tc_call_draw_single(struct pipe_context *pipe, void *call)
|
||||
{
|
||||
struct tc_draw_single *info = (struct tc_draw_single*)call;
|
||||
struct tc_draw_single *info = to_call(call, tc_draw_single);
|
||||
|
||||
/* u_threaded_context stores start/count in min/max_index for single draws. */
|
||||
/* Drivers using u_threaded_context shouldn't use min/max_index. */
|
||||
|
|
@ -2466,7 +2475,7 @@ struct tc_draw_indirect {
|
|||
static void
|
||||
tc_call_draw_indirect(struct pipe_context *pipe, void *call)
|
||||
{
|
||||
struct tc_draw_indirect *info = (struct tc_draw_indirect*)call;
|
||||
struct tc_draw_indirect *info = to_call(call, tc_draw_indirect);
|
||||
|
||||
info->info.index_bounds_valid = false;
|
||||
info->info.take_index_buffer_ownership = false;
|
||||
|
|
@ -2708,7 +2717,7 @@ struct tc_launch_grid_call {
|
|||
static void
|
||||
tc_call_launch_grid(struct pipe_context *pipe, void *call)
|
||||
{
|
||||
struct pipe_grid_info *p = &((struct tc_launch_grid_call *)call)->info;
|
||||
struct pipe_grid_info *p = &to_call(call, tc_launch_grid_call)->info;
|
||||
|
||||
pipe->launch_grid(pipe, p);
|
||||
tc_drop_resource_reference(p->indirect);
|
||||
|
|
@ -2730,7 +2739,7 @@ tc_launch_grid(struct pipe_context *_pipe,
|
|||
static void
|
||||
tc_call_resource_copy_region(struct pipe_context *pipe, void *call)
|
||||
{
|
||||
struct tc_resource_copy_region *p = (struct tc_resource_copy_region *)call;
|
||||
struct tc_resource_copy_region *p = to_call(call, tc_resource_copy_region);
|
||||
|
||||
pipe->resource_copy_region(pipe, p->dst, p->dst_level, p->dstx, p->dsty,
|
||||
p->dstz, p->src, p->src_level, &p->src_box);
|
||||
|
|
@ -2773,7 +2782,7 @@ struct tc_blit_call {
|
|||
static void
|
||||
tc_call_blit(struct pipe_context *pipe, void *call)
|
||||
{
|
||||
struct pipe_blit_info *blit = &((struct tc_blit_call*)call)->info;
|
||||
struct pipe_blit_info *blit = &to_call(call, tc_blit_call)->info;
|
||||
|
||||
pipe->blit(pipe, blit);
|
||||
tc_drop_resource_reference(blit->dst.resource);
|
||||
|
|
@ -2804,7 +2813,7 @@ struct tc_generate_mipmap {
|
|||
static void
|
||||
tc_call_generate_mipmap(struct pipe_context *pipe, void *call)
|
||||
{
|
||||
struct tc_generate_mipmap *p = (struct tc_generate_mipmap *)call;
|
||||
struct tc_generate_mipmap *p = to_call(call, tc_generate_mipmap);
|
||||
ASSERTED bool result = pipe->generate_mipmap(pipe, p->res, p->format,
|
||||
p->base_level,
|
||||
p->last_level,
|
||||
|
|
@ -2858,7 +2867,7 @@ struct tc_resource_call {
|
|||
static void
|
||||
tc_call_flush_resource(struct pipe_context *pipe, void *call)
|
||||
{
|
||||
struct pipe_resource *resource = ((struct tc_resource_call*)call)->resource;
|
||||
struct pipe_resource *resource = to_call(call, tc_resource_call)->resource;
|
||||
|
||||
pipe->flush_resource(pipe, resource);
|
||||
tc_drop_resource_reference(resource);
|
||||
|
|
@ -2877,7 +2886,7 @@ tc_flush_resource(struct pipe_context *_pipe, struct pipe_resource *resource)
|
|||
static void
|
||||
tc_call_invalidate_resource(struct pipe_context *pipe, void *call)
|
||||
{
|
||||
struct pipe_resource *resource = ((struct tc_resource_call*)call)->resource;
|
||||
struct pipe_resource *resource = to_call(call, tc_resource_call)->resource;
|
||||
|
||||
pipe->invalidate_resource(pipe, resource);
|
||||
tc_drop_resource_reference(resource);
|
||||
|
|
@ -2912,7 +2921,7 @@ struct tc_clear {
|
|||
static void
|
||||
tc_call_clear(struct pipe_context *pipe, void *call)
|
||||
{
|
||||
struct tc_clear *p = (struct tc_clear *)call;
|
||||
struct tc_clear *p = to_call(call, tc_clear);
|
||||
pipe->clear(pipe, p->buffers, p->scissor_state_set ? &p->scissor_state : NULL, &p->color, p->depth, p->stencil);
|
||||
}
|
||||
|
||||
|
|
@ -2977,7 +2986,7 @@ struct tc_clear_buffer {
|
|||
static void
|
||||
tc_call_clear_buffer(struct pipe_context *pipe, void *call)
|
||||
{
|
||||
struct tc_clear_buffer *p = (struct tc_clear_buffer *)call;
|
||||
struct tc_clear_buffer *p = to_call(call, tc_clear_buffer);
|
||||
|
||||
pipe->clear_buffer(pipe, p->res, p->offset, p->size, p->clear_value,
|
||||
p->clear_value_size);
|
||||
|
|
@ -3014,7 +3023,7 @@ struct tc_clear_texture {
|
|||
static void
|
||||
tc_call_clear_texture(struct pipe_context *pipe, void *call)
|
||||
{
|
||||
struct tc_clear_texture *p = (struct tc_clear_texture *)call;
|
||||
struct tc_clear_texture *p = to_call(call, tc_clear_texture);
|
||||
|
||||
pipe->clear_texture(pipe, p->res, p->level, &p->box, p->data);
|
||||
tc_drop_resource_reference(p->res);
|
||||
|
|
@ -3046,7 +3055,7 @@ struct tc_resource_commit {
|
|||
static void
|
||||
tc_call_resource_commit(struct pipe_context *pipe, void *call)
|
||||
{
|
||||
struct tc_resource_commit *p = (struct tc_resource_commit *)call;
|
||||
struct tc_resource_commit *p = to_call(call, tc_resource_commit);
|
||||
|
||||
pipe->resource_commit(pipe, p->res, p->level, &p->box, p->commit);
|
||||
tc_drop_resource_reference(p->res);
|
||||
|
|
@ -3123,7 +3132,7 @@ tc_new_intel_perf_query_obj(struct pipe_context *_pipe, unsigned query_index)
|
|||
static void
|
||||
tc_call_begin_intel_perf_query(struct pipe_context *pipe, void *call)
|
||||
{
|
||||
(void)pipe->begin_intel_perf_query(pipe, ((struct tc_query_call*)call)->query);
|
||||
(void)pipe->begin_intel_perf_query(pipe, to_call(call, tc_query_call)->query);
|
||||
}
|
||||
|
||||
static bool
|
||||
|
|
@ -3140,7 +3149,7 @@ tc_begin_intel_perf_query(struct pipe_context *_pipe, struct pipe_query *q)
|
|||
static void
|
||||
tc_call_end_intel_perf_query(struct pipe_context *pipe, void *call)
|
||||
{
|
||||
pipe->end_intel_perf_query(pipe, ((struct tc_query_call*)call)->query);
|
||||
pipe->end_intel_perf_query(pipe, to_call(call, tc_query_call)->query);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -3208,7 +3217,7 @@ struct tc_callback_call {
|
|||
static void
|
||||
tc_call_callback(UNUSED struct pipe_context *pipe, void *call)
|
||||
{
|
||||
struct tc_callback_call *p = (struct tc_callback_call *)call;
|
||||
struct tc_callback_call *p = to_call(call, tc_callback_call);
|
||||
|
||||
p->fn(p->data);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue