From a4a21b6104e7692de070a6f48a768d1894b732ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Sat, 2 Jan 2021 16:32:42 -0500 Subject: [PATCH] cso_context,u_vbuf: add take_ownership param into set_vertex_buffers st/mesa will use this to skip atomic ops for reference counting. Reviewed-by: Pierre-Eric Pelloux-Prayer Part-of: --- src/gallium/auxiliary/cso_cache/cso_context.c | 10 ++++++---- src/gallium/auxiliary/cso_cache/cso_context.h | 1 + src/gallium/auxiliary/util/u_vbuf.c | 8 +++++++- src/gallium/auxiliary/util/u_vbuf.h | 1 + src/mesa/state_tracker/st_atom_array.c | 1 + 5 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/gallium/auxiliary/cso_cache/cso_context.c b/src/gallium/auxiliary/cso_cache/cso_context.c index e48f12993ea..fc54dfc7be7 100644 --- a/src/gallium/auxiliary/cso_cache/cso_context.c +++ b/src/gallium/auxiliary/cso_cache/cso_context.c @@ -1027,7 +1027,7 @@ void cso_set_vertex_buffers(struct cso_context *ctx, return; if (vbuf) { - u_vbuf_set_vertex_buffers(vbuf, start_slot, count, 0, buffers); + u_vbuf_set_vertex_buffers(vbuf, start_slot, count, 0, false, buffers); return; } @@ -1052,6 +1052,7 @@ cso_set_vertex_buffers_and_elements(struct cso_context *ctx, const struct cso_velems_state *velems, unsigned vb_count, unsigned unbind_trailing_vb_count, + bool take_ownership, bool uses_user_vertex_buffers, const struct pipe_vertex_buffer *vbuffers) { @@ -1073,7 +1074,8 @@ cso_set_vertex_buffers_and_elements(struct cso_context *ctx, if (vb_count || unbind_trailing_vb_count) { u_vbuf_set_vertex_buffers(vbuf, 0, vb_count, - unbind_trailing_vb_count, vbuffers); + unbind_trailing_vb_count, + take_ownership, vbuffers); } u_vbuf_set_vertex_elements(vbuf, velems); return; @@ -1083,7 +1085,7 @@ cso_set_vertex_buffers_and_elements(struct cso_context *ctx, /* Unbind all buffers in u_vbuf, because we'll use cso_context. */ unsigned unbind_vb_count = vb_count + unbind_trailing_vb_count; if (unbind_vb_count) - u_vbuf_set_vertex_buffers(vbuf, 0, 0, unbind_vb_count, NULL); + u_vbuf_set_vertex_buffers(vbuf, 0, 0, unbind_vb_count, false, NULL); /* Unset this to make sure the CSO is re-bound on the next use. */ u_vbuf_unset_vertex_elements(vbuf); @@ -1093,7 +1095,7 @@ cso_set_vertex_buffers_and_elements(struct cso_context *ctx, if (vb_count || unbind_trailing_vb_count) { pipe->set_vertex_buffers(pipe, 0, vb_count, unbind_trailing_vb_count, - false, vbuffers); + take_ownership, vbuffers); } cso_set_vertex_elements_direct(ctx, velems); } diff --git a/src/gallium/auxiliary/cso_cache/cso_context.h b/src/gallium/auxiliary/cso_cache/cso_context.h index cd0fc0f616e..826e153ab7a 100644 --- a/src/gallium/auxiliary/cso_cache/cso_context.h +++ b/src/gallium/auxiliary/cso_cache/cso_context.h @@ -169,6 +169,7 @@ cso_set_vertex_buffers_and_elements(struct cso_context *ctx, const struct cso_velems_state *velems, unsigned vb_count, unsigned unbind_trailing_vb_count, + bool take_ownership, bool uses_user_vertex_buffers, const struct pipe_vertex_buffer *vbuffers); diff --git a/src/gallium/auxiliary/util/u_vbuf.c b/src/gallium/auxiliary/util/u_vbuf.c index fc4d3469189..b51631f2cee 100644 --- a/src/gallium/auxiliary/util/u_vbuf.c +++ b/src/gallium/auxiliary/util/u_vbuf.c @@ -878,6 +878,7 @@ static void u_vbuf_delete_vertex_elements(void *ctx, void *state, void u_vbuf_set_vertex_buffers(struct u_vbuf *mgr, unsigned start_slot, unsigned count, unsigned unbind_num_trailing_slots, + bool take_ownership, const struct pipe_vertex_buffer *bufs) { unsigned i; @@ -928,7 +929,12 @@ void u_vbuf_set_vertex_buffers(struct u_vbuf *mgr, continue; } - pipe_vertex_buffer_reference(orig_vb, vb); + if (take_ownership) { + pipe_vertex_buffer_unreference(orig_vb); + memcpy(orig_vb, vb, sizeof(*vb)); + } else { + pipe_vertex_buffer_reference(orig_vb, vb); + } if (vb->stride) { nonzero_stride_vb_mask |= 1 << dst_index; diff --git a/src/gallium/auxiliary/util/u_vbuf.h b/src/gallium/auxiliary/util/u_vbuf.h index 82188236766..fcf99fcd3e1 100644 --- a/src/gallium/auxiliary/util/u_vbuf.h +++ b/src/gallium/auxiliary/util/u_vbuf.h @@ -77,6 +77,7 @@ void u_vbuf_unset_vertex_elements(struct u_vbuf *mgr); void u_vbuf_set_vertex_buffers(struct u_vbuf *mgr, unsigned start_slot, unsigned count, unsigned unbind_num_trailing_slots, + bool take_ownership, const struct pipe_vertex_buffer *bufs); void u_vbuf_draw_vbo(struct u_vbuf *mgr, const struct pipe_draw_info *info, const struct pipe_draw_indirect_info *indirect, diff --git a/src/mesa/state_tracker/st_atom_array.c b/src/mesa/state_tracker/st_atom_array.c index 406baa73e3e..97f93627550 100644 --- a/src/mesa/state_tracker/st_atom_array.c +++ b/src/mesa/state_tracker/st_atom_array.c @@ -354,6 +354,7 @@ st_update_array(struct st_context *st) cso_set_vertex_buffers_and_elements(cso, &velements, num_vbuffers, unbind_trailing_vbuffers, + false, uses_user_vertex_buffers, vbuffer); st->last_num_vbuffers = num_vbuffers;