diff options
author | Marek Olšák <marek.olsak@amd.com> | 2024-01-29 17:22:36 -0500 |
---|---|---|
committer | Marge Bot <emma+marge@anholt.net> | 2024-02-23 18:03:59 +0000 |
commit | 798f4307778560d5a0127cf2ab55c636d496e4a7 (patch) | |
tree | a29a268b6fd25f714ee88ad3a756650c833932b2 | |
parent | 5d70c21d82f7e3d631379bfbe99bb7cc389caa10 (diff) | |
download | mesa3d-798f4307778560d5a0127cf2ab55c636d496e4a7.tar.gz |
glthread: deduplicate batch finalization code
Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27350>
-rw-r--r-- | src/mesa/main/glthread.c | 44 |
1 files changed, 21 insertions, 23 deletions
diff --git a/src/mesa/main/glthread.c b/src/mesa/main/glthread.c index 0df187ef3b6..7b02e79b8be 100644 --- a/src/mesa/main/glthread.c +++ b/src/mesa/main/glthread.c @@ -331,6 +331,25 @@ void _mesa_glthread_disable(struct gl_context *ctx) _mesa_glthread_unbind_uploaded_vbos(ctx); } +static void +glthread_finalize_batch(struct glthread_state *glthread, + unsigned *num_items_counter) +{ + struct glthread_batch *next = glthread->next_batch; + + /* Mark the end of the batch, but don't increment "used". */ + struct marshal_cmd_base *last = + (struct marshal_cmd_base *)&next->buffer[glthread->used]; + last->cmd_id = NUM_DISPATCH_CMD; + + p_atomic_add(num_items_counter, glthread->used); + next->used = glthread->used; + glthread->used = 0; + + glthread->LastCallList = NULL; + glthread->LastBindBuffer = NULL; +} + void _mesa_glthread_flush_batch(struct gl_context *ctx) { @@ -347,26 +366,15 @@ _mesa_glthread_flush_batch(struct gl_context *ctx) return; /* the batch is empty */ glthread_apply_thread_sched_policy(ctx, false); + glthread_finalize_batch(glthread, &glthread->stats.num_offloaded_items); struct glthread_batch *next = glthread->next_batch; - /* Mark the end of the batch, but don't increment "used". */ - struct marshal_cmd_base *last = - (struct marshal_cmd_base *)&next->buffer[glthread->used]; - last->cmd_id = NUM_DISPATCH_CMD; - - p_atomic_add(&glthread->stats.num_offloaded_items, glthread->used); - next->used = glthread->used; - util_queue_add_job(&glthread->queue, next, &next->fence, glthread_unmarshal_batch, NULL, 0); glthread->last = glthread->next; glthread->next = (glthread->next + 1) % MARSHAL_MAX_BATCHES; glthread->next_batch = &glthread->batches[glthread->next]; - glthread->used = 0; - - glthread->LastCallList = NULL; - glthread->LastBindBuffer = NULL; } /** @@ -402,17 +410,7 @@ _mesa_glthread_finish(struct gl_context *ctx) glthread_apply_thread_sched_policy(ctx, false); if (glthread->used) { - /* Mark the end of the batch, but don't increment "used". */ - struct marshal_cmd_base *last = - (struct marshal_cmd_base *)&next->buffer[glthread->used]; - last->cmd_id = NUM_DISPATCH_CMD; - - p_atomic_add(&glthread->stats.num_direct_items, glthread->used); - next->used = glthread->used; - glthread->used = 0; - - glthread->LastCallList = NULL; - glthread->LastBindBuffer = NULL; + glthread_finalize_batch(glthread, &glthread->stats.num_direct_items); /* Since glthread_unmarshal_batch changes the dispatch to direct, * restore it after it's done. |