From 0ac5dc5ab5ce2da3b0b2e7a0d3f95ef7952b2156 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Thu, 4 Jan 2024 22:15:09 -0500 Subject: [PATCH] gallium/u_threaded: expose helpers for filling set_vertex_buffers externally Reviewed-By: Mike Blumenkrantz Part-of: --- .../auxiliary/util/u_threaded_context.c | 32 +++++++-------- .../auxiliary/util/u_threaded_context.h | 40 +++++++++++++++++++ 2 files changed, 56 insertions(+), 16 deletions(-) diff --git a/src/gallium/auxiliary/util/u_threaded_context.c b/src/gallium/auxiliary/util/u_threaded_context.c index 6ccf6adf863..f513040e574 100644 --- a/src/gallium/auxiliary/util/u_threaded_context.c +++ b/src/gallium/auxiliary/util/u_threaded_context.c @@ -827,22 +827,6 @@ tc_add_to_buffer_list(struct tc_buffer_list *next, struct pipe_resource *buf) BITSET_SET(next->buffer_list, id & TC_BUFFER_ID_MASK); } -/* Set a buffer binding and add it to the buffer list. */ -static void -tc_bind_buffer(uint32_t *binding, struct tc_buffer_list *next, struct pipe_resource *buf) -{ - uint32_t id = threaded_resource(buf)->buffer_id_unique; - *binding = id; - BITSET_SET(next->buffer_list, id & TC_BUFFER_ID_MASK); -} - -/* Reset a buffer binding. */ -static void -tc_unbind_buffer(uint32_t *binding) -{ - *binding = 0; -} - /* Reset a range of buffer binding slots. */ static void tc_unbind_buffers(uint32_t *binding, unsigned count) @@ -2193,6 +2177,22 @@ tc_set_vertex_buffers(struct pipe_context *_pipe, unsigned count, tc->num_vertex_buffers = count; } +struct pipe_vertex_buffer * +tc_add_set_vertex_buffers_call(struct pipe_context *_pipe, unsigned count) +{ + struct threaded_context *tc = threaded_context(_pipe); + + /* We don't need to unbind trailing buffers because we never touch bindings + * after num_vertex_buffers. + */ + tc->num_vertex_buffers = count; + + struct tc_vertex_buffers *p = + tc_add_slot_based_call(tc, TC_CALL_set_vertex_buffers, tc_vertex_buffers, count); + p->count = count; + return p->slot; +} + struct tc_stream_outputs { struct tc_call_base base; unsigned count; diff --git a/src/gallium/auxiliary/util/u_threaded_context.h b/src/gallium/auxiliary/util/u_threaded_context.h index c906aac567d..3932dd1925b 100644 --- a/src/gallium/auxiliary/util/u_threaded_context.h +++ b/src/gallium/auxiliary/util/u_threaded_context.h @@ -710,6 +710,8 @@ threaded_context_flush(struct pipe_context *_pipe, struct tc_draw_single * tc_add_draw_single_call(struct pipe_context *_pipe, struct pipe_resource *index_bo); +struct pipe_vertex_buffer * +tc_add_set_vertex_buffers_call(struct pipe_context *_pipe, unsigned count); void tc_draw_vbo(struct pipe_context *_pipe, const struct pipe_draw_info *info, @@ -795,6 +797,44 @@ tc_buffer_write(struct pipe_context *pipe, pipe->buffer_subdata(pipe, buf, PIPE_MAP_WRITE | TC_TRANSFER_MAP_NO_INVALIDATE, offset, size, data); } +static inline struct tc_buffer_list * +tc_get_next_buffer_list(struct pipe_context *_pipe) +{ + struct threaded_context *tc = threaded_context(_pipe); + + return &tc->buffer_lists[tc->next_buf_list]; +} + +/* Set a buffer binding and add it to the buffer list. */ +static inline void +tc_bind_buffer(uint32_t *binding, struct tc_buffer_list *next, struct pipe_resource *buf) +{ + uint32_t id = threaded_resource(buf)->buffer_id_unique; + *binding = id; + BITSET_SET(next->buffer_list, id & TC_BUFFER_ID_MASK); +} + +/* Reset a buffer binding. */ +static inline void +tc_unbind_buffer(uint32_t *binding) +{ + *binding = 0; +} + +static inline void +tc_track_vertex_buffer(struct pipe_context *_pipe, unsigned index, + struct pipe_resource *buf, + struct tc_buffer_list *next_buffer_list) +{ + struct threaded_context *tc = threaded_context(_pipe); + + if (buf) { + tc_bind_buffer(&tc->vertex_buffers[index], next_buffer_list, buf); + } else { + tc_unbind_buffer(&tc->vertex_buffers[index]); + } +} + #ifdef __cplusplus } #endif