diff options
author | Marek Olšák <marek.olsak@amd.com> | 2023-11-20 13:48:09 -0500 |
---|---|---|
committer | Marge Bot <emma+marge@anholt.net> | 2024-01-14 21:55:19 +0000 |
commit | eb20ef92772c6a4963128370260d578f100efee9 (patch) | |
tree | 04d3baa5430fa12a4afd0c2debc4764bf9dec8f5 /src/gallium | |
parent | 2725b095ea2a16a1ce28aca8ae31e9d3df448c67 (diff) |
gallium: remove unbind_trailing_count from set_vertex_buffers
It should implicitly unbind all bound buffers after "count".
This also slightly simplies u_vbuf.
This is a cleanup suggested by:
https://gitlab.freedesktop.org/mesa/mesa/-/issues/8142
Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io> (asahi & panfrost)
Reviewed-By: Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26309>
Diffstat (limited to 'src/gallium')
73 files changed, 315 insertions, 433 deletions
diff --git a/src/gallium/auxiliary/cso_cache/cso_context.c b/src/gallium/auxiliary/cso_cache/cso_context.c index fd24be07d2d..bfaec3ca975 100644 --- a/src/gallium/auxiliary/cso_cache/cso_context.c +++ b/src/gallium/auxiliary/cso_cache/cso_context.c @@ -1287,25 +1287,19 @@ cso_restore_vertex_elements(struct cso_context_priv *ctx) void cso_set_vertex_buffers(struct cso_context *cso, unsigned count, - unsigned unbind_trailing_count, bool take_ownership, const struct pipe_vertex_buffer *buffers) { struct cso_context_priv *ctx = (struct cso_context_priv *)cso; struct u_vbuf *vbuf = ctx->vbuf_current; - if (!count && !unbind_trailing_count) - return; - if (vbuf) { - u_vbuf_set_vertex_buffers(vbuf, count, unbind_trailing_count, - take_ownership, buffers); + u_vbuf_set_vertex_buffers(vbuf, count, take_ownership, buffers); return; } struct pipe_context *pipe = ctx->base.pipe; - pipe->set_vertex_buffers(pipe, count, unbind_trailing_count, - take_ownership, buffers); + pipe->set_vertex_buffers(pipe, count, take_ownership, buffers); } @@ -1325,7 +1319,6 @@ void cso_set_vertex_buffers_and_elements(struct cso_context *cso, 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) @@ -1337,45 +1330,32 @@ cso_set_vertex_buffers_and_elements(struct cso_context *cso, if (vbuf && (ctx->always_use_vbuf || uses_user_vertex_buffers)) { if (!ctx->vbuf_current) { /* Unbind all buffers in cso_context, because we'll use u_vbuf. */ - unsigned unbind_vb_count = vb_count + unbind_trailing_vb_count; - if (unbind_vb_count) - pipe->set_vertex_buffers(pipe, 0, unbind_vb_count, false, NULL); + pipe->set_vertex_buffers(pipe, 0, false, NULL); /* Unset this to make sure the CSO is re-bound on the next use. */ ctx->velements = NULL; ctx->vbuf_current = pipe->vbuf = vbuf; if (pipe->draw_vbo == tc_draw_vbo) ctx->base.draw_vbo = u_vbuf_draw_vbo; - unbind_trailing_vb_count = 0; } - if (vb_count || unbind_trailing_vb_count) { - u_vbuf_set_vertex_buffers(vbuf, vb_count, - unbind_trailing_vb_count, - take_ownership, vbuffers); - } + u_vbuf_set_vertex_buffers(vbuf, vb_count, take_ownership, vbuffers); u_vbuf_set_vertex_elements(vbuf, velems); return; } if (ctx->vbuf_current) { /* 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, unbind_vb_count, false, NULL); + u_vbuf_set_vertex_buffers(vbuf, 0, false, NULL); /* Unset this to make sure the CSO is re-bound on the next use. */ u_vbuf_unset_vertex_elements(vbuf); ctx->vbuf_current = pipe->vbuf = NULL; if (pipe->draw_vbo == tc_draw_vbo) ctx->base.draw_vbo = pipe->draw_vbo; - unbind_trailing_vb_count = 0; } - if (vb_count || unbind_trailing_vb_count) { - pipe->set_vertex_buffers(pipe, vb_count, unbind_trailing_vb_count, - take_ownership, vbuffers); - } + pipe->set_vertex_buffers(pipe, vb_count, take_ownership, vbuffers); cso_set_vertex_elements_direct(ctx, velems); } @@ -1766,7 +1746,7 @@ cso_restore_state(struct cso_context *ctx, unsigned unbind) if (state_mask & CSO_BIT_VERTEX_ELEMENTS) cso_restore_vertex_elements(cso); if (unbind & CSO_UNBIND_VERTEX_BUFFER0) - cso->base.pipe->set_vertex_buffers(cso->base.pipe, 0, 1, false, NULL); + cso->base.pipe->set_vertex_buffers(cso->base.pipe, 0, false, NULL); if (state_mask & CSO_BIT_STREAM_OUTPUTS) cso_restore_stream_outputs(cso); if (state_mask & CSO_BIT_PAUSE_QUERIES) diff --git a/src/gallium/auxiliary/cso_cache/cso_context.h b/src/gallium/auxiliary/cso_cache/cso_context.h index f796310d39b..fcd3585718b 100644 --- a/src/gallium/auxiliary/cso_cache/cso_context.h +++ b/src/gallium/auxiliary/cso_cache/cso_context.h @@ -95,7 +95,6 @@ cso_set_vertex_elements(struct cso_context *ctx, void cso_set_vertex_buffers(struct cso_context *ctx, unsigned count, - unsigned unbind_trailing_count, bool take_ownership, const struct pipe_vertex_buffer *buffers); @@ -205,7 +204,6 @@ void 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/draw/draw_context.c b/src/gallium/auxiliary/draw/draw_context.c index 58e8aced4e4..ef371dc1214 100644 --- a/src/gallium/auxiliary/draw/draw_context.c +++ b/src/gallium/auxiliary/draw/draw_context.c @@ -405,15 +405,13 @@ draw_set_viewport_states(struct draw_context *draw, void draw_set_vertex_buffers(struct draw_context *draw, unsigned count, - unsigned unbind_num_trailing_slots, const struct pipe_vertex_buffer *buffers) { assert(count <= PIPE_MAX_ATTRIBS); util_set_vertex_buffers_count(draw->pt.vertex_buffer, &draw->pt.nr_vertex_buffers, - buffers, count, - unbind_num_trailing_slots, false); + buffers, count, false); } diff --git a/src/gallium/auxiliary/draw/draw_context.h b/src/gallium/auxiliary/draw/draw_context.h index 2c5ea81ed48..0f94285b0a7 100644 --- a/src/gallium/auxiliary/draw/draw_context.h +++ b/src/gallium/auxiliary/draw/draw_context.h @@ -321,7 +321,6 @@ void draw_delete_mesh_shader(struct draw_context *draw, void draw_set_vertex_buffers(struct draw_context *draw, unsigned count, - unsigned unbind_num_trailing_slots, const struct pipe_vertex_buffer *buffers); void draw_set_vertex_elements(struct draw_context *draw, diff --git a/src/gallium/auxiliary/driver_ddebug/dd_context.c b/src/gallium/auxiliary/driver_ddebug/dd_context.c index f7991708f01..4c5bea1f361 100644 --- a/src/gallium/auxiliary/driver_ddebug/dd_context.c +++ b/src/gallium/auxiliary/driver_ddebug/dd_context.c @@ -571,7 +571,6 @@ dd_context_set_shader_buffers(struct pipe_context *_pipe, static void dd_context_set_vertex_buffers(struct pipe_context *_pipe, unsigned num_buffers, - unsigned unbind_num_trailing_slots, bool take_ownership, const struct pipe_vertex_buffer *buffers) { @@ -580,11 +579,12 @@ dd_context_set_vertex_buffers(struct pipe_context *_pipe, safe_memcpy(&dctx->draw_state.vertex_buffers[0], buffers, sizeof(buffers[0]) * num_buffers); - safe_memcpy(&dctx->draw_state.vertex_buffers[num_buffers], NULL, - sizeof(buffers[0]) * unbind_num_trailing_slots); - pipe->set_vertex_buffers(pipe, num_buffers, - unbind_num_trailing_slots, take_ownership, - buffers); + if (dctx->num_vertex_buffers > num_buffers) { + safe_memcpy(&dctx->draw_state.vertex_buffers[num_buffers], NULL, + sizeof(buffers[0]) * (dctx->num_vertex_buffers - num_buffers)); + } + pipe->set_vertex_buffers(pipe, num_buffers, take_ownership, buffers); + dctx->num_vertex_buffers = num_buffers; } static void diff --git a/src/gallium/auxiliary/driver_ddebug/dd_pipe.h b/src/gallium/auxiliary/driver_ddebug/dd_pipe.h index d9a24789830..26a17e60969 100644 --- a/src/gallium/auxiliary/driver_ddebug/dd_pipe.h +++ b/src/gallium/auxiliary/driver_ddebug/dd_pipe.h @@ -302,6 +302,7 @@ struct dd_context struct dd_draw_state draw_state; unsigned num_draw_calls; + unsigned num_vertex_buffers; struct u_log_context log; diff --git a/src/gallium/auxiliary/driver_noop/noop_state.c b/src/gallium/auxiliary/driver_noop/noop_state.c index f93039b1d2c..af487cf9fcd 100644 --- a/src/gallium/auxiliary/driver_noop/noop_state.c +++ b/src/gallium/auxiliary/driver_noop/noop_state.c @@ -215,7 +215,6 @@ static void noop_delete_state(struct pipe_context *ctx, void *state) static void noop_set_vertex_buffers(struct pipe_context *ctx, unsigned count, - unsigned unbind_num_trailing_slots, bool take_ownership, const struct pipe_vertex_buffer *buffers) { diff --git a/src/gallium/auxiliary/driver_trace/tr_context.c b/src/gallium/auxiliary/driver_trace/tr_context.c index 65cf6a6cbea..c03cdc70d41 100644 --- a/src/gallium/auxiliary/driver_trace/tr_context.c +++ b/src/gallium/auxiliary/driver_trace/tr_context.c @@ -1238,7 +1238,6 @@ trace_context_set_sampler_views(struct pipe_context *_pipe, static void trace_context_set_vertex_buffers(struct pipe_context *_pipe, unsigned num_buffers, - unsigned unbind_num_trailing_slots, bool take_ownership, const struct pipe_vertex_buffer *buffers) { @@ -1249,16 +1248,13 @@ trace_context_set_vertex_buffers(struct pipe_context *_pipe, trace_dump_arg(ptr, pipe); trace_dump_arg(uint, num_buffers); - trace_dump_arg(uint, unbind_num_trailing_slots); trace_dump_arg(bool, take_ownership); trace_dump_arg_begin("buffers"); trace_dump_struct_array(vertex_buffer, buffers, num_buffers); trace_dump_arg_end(); - pipe->set_vertex_buffers(pipe, num_buffers, - unbind_num_trailing_slots, take_ownership, - buffers); + pipe->set_vertex_buffers(pipe, num_buffers, take_ownership, buffers); trace_dump_call_end(); } diff --git a/src/gallium/auxiliary/hud/hud_context.c b/src/gallium/auxiliary/hud/hud_context.c index 9d3e4e79221..ead8b38a865 100644 --- a/src/gallium/auxiliary/hud/hud_context.c +++ b/src/gallium/auxiliary/hud/hud_context.c @@ -112,7 +112,7 @@ hud_draw_colored_prims(struct hud_context *hud, unsigned prim, &vbuffer.buffer_offset, &vbuffer.buffer.resource); u_upload_unmap(hud->pipe->stream_uploader); - cso_set_vertex_buffers(cso, 1, 0, false, &vbuffer); + cso_set_vertex_buffers(cso, 1, false, &vbuffer); pipe_resource_reference(&vbuffer.buffer.resource, NULL); cso_set_fragment_shader_handle(hud->cso, hud->fs_color); cso_draw_arrays(cso, prim, 0, num_vertices); @@ -601,7 +601,7 @@ hud_draw_results(struct hud_context *hud, struct pipe_resource *tex) pipe->set_constant_buffer(pipe, PIPE_SHADER_VERTEX, 0, false, &hud->constbuf); - cso_set_vertex_buffers(cso, 1, 0, false, &hud->bg.vbuf); + cso_set_vertex_buffers(cso, 1, false, &hud->bg.vbuf); cso_draw_arrays(cso, MESA_PRIM_QUADS, 0, hud->bg.num_vertices); } pipe_resource_reference(&hud->bg.vbuf.buffer.resource, NULL); @@ -610,7 +610,7 @@ hud_draw_results(struct hud_context *hud, struct pipe_resource *tex) if (hud->text.num_vertices) { cso_set_vertex_shader_handle(cso, hud->vs_text); cso_set_vertex_elements(cso, &hud->text_velems); - cso_set_vertex_buffers(cso, 1, 0, false, &hud->text.vbuf); + cso_set_vertex_buffers(cso, 1, false, &hud->text.vbuf); cso_set_fragment_shader_handle(hud->cso, hud->fs_text); cso_draw_arrays(cso, MESA_PRIM_QUADS, 0, hud->text.num_vertices); cso_set_vertex_elements(cso, &hud->velems); @@ -635,7 +635,7 @@ hud_draw_results(struct hud_context *hud, struct pipe_resource *tex) if (hud->whitelines.num_vertices) { cso_set_vertex_shader_handle(cso, hud->vs_color); - cso_set_vertex_buffers(cso, 1, 0, false, &hud->whitelines.vbuf); + cso_set_vertex_buffers(cso, 1, false, &hud->whitelines.vbuf); cso_set_fragment_shader_handle(hud->cso, hud->fs_color); cso_draw_arrays(cso, MESA_PRIM_LINES, 0, hud->whitelines.num_vertices); } diff --git a/src/gallium/auxiliary/util/u_blitter.c b/src/gallium/auxiliary/util/u_blitter.c index f4a0a2f898b..cf058da6396 100644 --- a/src/gallium/auxiliary/util/u_blitter.c +++ b/src/gallium/auxiliary/util/u_blitter.c @@ -643,10 +643,12 @@ void util_blitter_restore_vertex_states(struct blitter_context *blitter) unsigned i; /* Vertex buffer. */ - if (ctx->base.saved_vertex_buffer.buffer.resource) { - pipe->set_vertex_buffers(pipe, 1, 0, true, - &ctx->base.saved_vertex_buffer); - ctx->base.saved_vertex_buffer.buffer.resource = NULL; + if (ctx->base.saved_num_vb) { + pipe->set_vertex_buffers(pipe, ctx->base.saved_num_vb, true, + ctx->base.saved_vertex_buffers); + memset(ctx->base.saved_vertex_buffers, 0, + sizeof(ctx->base.saved_vertex_buffers[0]) * ctx->base.saved_num_vb); + ctx->base.saved_num_vb = 0; } /* Vertex elements. */ @@ -1409,7 +1411,7 @@ static void blitter_draw(struct blitter_context_priv *ctx, return; u_upload_unmap(pipe->stream_uploader); - pipe->set_vertex_buffers(pipe, 1, 0, false, &vb); + pipe->set_vertex_buffers(pipe, 1, false, &vb); pipe->bind_vertex_elements_state(pipe, vertex_elements_cso); pipe->bind_vs_state(pipe, get_vs(&ctx->base)); @@ -2631,7 +2633,7 @@ void util_blitter_clear_buffer(struct blitter_context *blitter, blitter_check_saved_vertex_states(ctx); blitter_disable_render_cond(ctx); - pipe->set_vertex_buffers(pipe, 1, 0, false, &vb); + pipe->set_vertex_buffers(pipe, 1, false, &vb); pipe->bind_vertex_elements_state(pipe, ctx->velem_state_readbuf[num_channels-1]); bind_vs_pos_only(ctx, num_channels); diff --git a/src/gallium/auxiliary/util/u_blitter.h b/src/gallium/auxiliary/util/u_blitter.h index bd4cfdc52ae..2746b704f16 100644 --- a/src/gallium/auxiliary/util/u_blitter.h +++ b/src/gallium/auxiliary/util/u_blitter.h @@ -129,7 +129,8 @@ struct blitter_context unsigned cb_slot; struct pipe_constant_buffer saved_fs_constant_buffer; - struct pipe_vertex_buffer saved_vertex_buffer; + unsigned saved_num_vb; + struct pipe_vertex_buffer saved_vertex_buffers[PIPE_MAX_ATTRIBS]; unsigned saved_num_so_targets; struct pipe_stream_output_target *saved_so_targets[PIPE_MAX_SO_BUFFERS]; @@ -532,11 +533,15 @@ util_blitter_save_fragment_constant_buffer_slot( } static inline void -util_blitter_save_vertex_buffer_slot(struct blitter_context *blitter, - struct pipe_vertex_buffer *vertex_buffers) +util_blitter_save_vertex_buffers(struct blitter_context *blitter, + struct pipe_vertex_buffer *vertex_buffers, + unsigned count) { - pipe_vertex_buffer_reference(&blitter->saved_vertex_buffer, - &vertex_buffers[0]); + for (unsigned i = 0; i < count; i++) { + pipe_vertex_buffer_reference(&blitter->saved_vertex_buffers[i], + &vertex_buffers[i]); + } + blitter->saved_num_vb = count; } static inline void diff --git a/src/gallium/auxiliary/util/u_draw_quad.c b/src/gallium/auxiliary/util/u_draw_quad.c index 619f4e6b6ec..a6c92deee00 100644 --- a/src/gallium/auxiliary/util/u_draw_quad.c +++ b/src/gallium/auxiliary/util/u_draw_quad.c @@ -59,10 +59,10 @@ util_draw_vertex_buffer(struct pipe_context *pipe, /* note: vertex elements already set by caller */ if (cso) { - cso_set_vertex_buffers(cso, 1, 0, false, &vbuffer); + cso_set_vertex_buffers(cso, 1, false, &vbuffer); cso_draw_arrays(cso, prim_type, 0, num_verts); } else { - pipe->set_vertex_buffers(pipe, 1, 0, false, &vbuffer); + pipe->set_vertex_buffers(pipe, 1, false, &vbuffer); util_draw_arrays(pipe, prim_type, 0, num_verts); } } @@ -86,7 +86,7 @@ util_draw_user_vertex_buffer(struct cso_context *cso, void *buffer, /* note: vertex elements already set by caller */ - cso_set_vertex_buffers(cso, 1, 0, false, &vbuffer); + cso_set_vertex_buffers(cso, 1, false, &vbuffer); cso_draw_arrays(cso, prim_type, 0, num_verts); } @@ -104,6 +104,6 @@ util_draw_user_vertices(struct cso_context *cso, struct cso_velems_state *ve, vbuffer.is_user_buffer = true; vbuffer.buffer.user = buffer; - cso_set_vertex_buffers_and_elements(cso, ve, 1, 0, false, true, &vbuffer); + cso_set_vertex_buffers_and_elements(cso, ve, 1, false, true, &vbuffer); cso_draw_arrays(cso, prim_type, 0, num_verts); } diff --git a/src/gallium/auxiliary/util/u_helpers.c b/src/gallium/auxiliary/util/u_helpers.c index 881a84e7840..762bddc3dc0 100644 --- a/src/gallium/auxiliary/util/u_helpers.c +++ b/src/gallium/auxiliary/util/u_helpers.c @@ -48,16 +48,16 @@ void util_set_vertex_buffers_mask(struct pipe_vertex_buffer *dst, uint32_t *enabled_buffers, const struct pipe_vertex_buffer *src, unsigned count, - unsigned unbind_num_trailing_slots, bool take_ownership) { - unsigned i; + unsigned last_count = util_last_bit(*enabled_buffers); uint32_t bitmask = 0; + unsigned i = 0; - *enabled_buffers &= ~BITFIELD_MASK(count); + assert(!count || src); if (src) { - for (i = 0; i < count; i++) { + for (; i < count; i++) { if (src[i].buffer.resource) bitmask |= 1 << i; @@ -69,17 +69,12 @@ void util_set_vertex_buffers_mask(struct pipe_vertex_buffer *dst, /* Copy over the other members of pipe_vertex_buffer. */ memcpy(dst, src, count * sizeof(struct pipe_vertex_buffer)); - - *enabled_buffers |= bitmask; - } - else { - /* Unreference the buffers. */ - for (i = 0; i < count; i++) - pipe_vertex_buffer_unreference(&dst[i]); } - for (i = 0; i < unbind_num_trailing_slots; i++) - pipe_vertex_buffer_unreference(&dst[count + i]); + *enabled_buffers = bitmask; + + for (; i < last_count; i++) + pipe_vertex_buffer_unreference(&dst[i]); } /** @@ -90,19 +85,16 @@ void util_set_vertex_buffers_count(struct pipe_vertex_buffer *dst, unsigned *dst_count, const struct pipe_vertex_buffer *src, unsigned count, - unsigned unbind_num_trailing_slots, bool take_ownership) { - unsigned i; uint32_t enabled_buffers = 0; - for (i = 0; i < *dst_count; i++) { + for (unsigned i = 0; i < *dst_count; i++) { if (dst[i].buffer.resource) enabled_buffers |= (1ull << i); } - util_set_vertex_buffers_mask(dst, &enabled_buffers, src, - count, unbind_num_trailing_slots, + util_set_vertex_buffers_mask(dst, &enabled_buffers, src, count, take_ownership); *dst_count = util_last_bit(enabled_buffers); diff --git a/src/gallium/auxiliary/util/u_helpers.h b/src/gallium/auxiliary/util/u_helpers.h index 4299e595535..e4ba00b5ac1 100644 --- a/src/gallium/auxiliary/util/u_helpers.h +++ b/src/gallium/auxiliary/util/u_helpers.h @@ -41,14 +41,12 @@ void util_set_vertex_buffers_mask(struct pipe_vertex_buffer *dst, uint32_t *enabled_buffers, const struct pipe_vertex_buffer *src, unsigned count, - unsigned unbind_num_trailing_slots, bool take_ownership); void util_set_vertex_buffers_count(struct pipe_vertex_buffer *dst, unsigned *dst_count, const struct pipe_vertex_buffer *src, unsigned count, - unsigned unbind_num_trailing_slots, bool take_ownership); void util_set_shader_buffers_mask(struct pipe_shader_buffer *dst, diff --git a/src/gallium/auxiliary/util/u_threaded_context.c b/src/gallium/auxiliary/util/u_threaded_context.c index 3cd98c562d9..8da515805b0 100644 --- a/src/gallium/auxiliary/util/u_threaded_context.c +++ b/src/gallium/auxiliary/util/u_threaded_context.c @@ -945,7 +945,7 @@ tc_add_all_gfx_bindings_to_buffer_list(struct threaded_context *tc) { BITSET_WORD *buffer_list = tc->buffer_lists[tc->next_buf_list].buffer_list; - tc_add_bindings_to_buffer_list(buffer_list, tc->vertex_buffers, tc->max_vertex_buffers); + tc_add_bindings_to_buffer_list(buffer_list, tc->vertex_buffers, tc->num_vertex_buffers); if (tc->seen_streamout_buffers) tc_add_bindings_to_buffer_list(buffer_list, tc->streamout_buffers, PIPE_MAX_SO_BUFFERS); @@ -981,7 +981,7 @@ tc_rebind_buffer(struct threaded_context *tc, uint32_t old_id, uint32_t new_id, unsigned vbo = 0, so = 0; vbo = tc_rebind_bindings(old_id, new_id, tc->vertex_buffers, - tc->max_vertex_buffers); + tc->num_vertex_buffers); if (vbo) *rebind_mask |= BITFIELD_BIT(TC_BINDING_VERTEX_BUFFER); @@ -2153,7 +2153,6 @@ tc_set_shader_buffers(struct pipe_context *_pipe, struct tc_vertex_buffers { struct tc_call_base base; uint8_t count; - uint8_t unbind_num_trailing_slots; struct pipe_vertex_buffer slot[0]; /* more will be allocated if needed */ }; @@ -2164,34 +2163,31 @@ tc_call_set_vertex_buffers(struct pipe_context *pipe, void *call) unsigned count = p->count; if (!count) { - pipe->set_vertex_buffers(pipe, 0, p->unbind_num_trailing_slots, false, NULL); + pipe->set_vertex_buffers(pipe, 0, false, NULL); return call_size(tc_vertex_buffers); } for (unsigned i = 0; i < count; i++) tc_assert(!p->slot[i].is_user_buffer); - pipe->set_vertex_buffers(pipe, count, p->unbind_num_trailing_slots, true, p->slot); + pipe->set_vertex_buffers(pipe, count, true, p->slot); return p->base.num_slots; } static void tc_set_vertex_buffers(struct pipe_context *_pipe, unsigned count, - unsigned unbind_num_trailing_slots, bool take_ownership, const struct pipe_vertex_buffer *buffers) { struct threaded_context *tc = threaded_context(_pipe); - if (!count && !unbind_num_trailing_slots) - return; + assert(!count || buffers); - if (count && buffers) { + if (count) { struct tc_vertex_buffers *p = tc_add_slot_based_call(tc, TC_CALL_set_vertex_buffers, tc_vertex_buffers, count); p->count = count; - p->unbind_num_trailing_slots = unbind_num_trailing_slots; struct tc_buffer_list *next = &tc->buffer_lists[tc->next_buf_list]; @@ -2225,18 +2221,16 @@ tc_set_vertex_buffers(struct pipe_context *_pipe, } } } - - tc_unbind_buffers(&tc->vertex_buffers[count], - unbind_num_trailing_slots); } else { struct tc_vertex_buffers *p = tc_add_slot_based_call(tc, TC_CALL_set_vertex_buffers, tc_vertex_buffers, 0); p->count = 0; - p->unbind_num_trailing_slots = count + unbind_num_trailing_slots; - - tc_unbind_buffers(&tc->vertex_buffers[0], - count + unbind_num_trailing_slots); } + + /* We don't need to unbind trailing buffers because we never touch bindings + * after num_vertex_buffers. + */ + tc->num_vertex_buffers = count; } struct tc_stream_outputs { @@ -5285,8 +5279,6 @@ threaded_context_create(struct pipe_context *pipe, /* If you have different limits in each shader stage, set the maximum. */ struct pipe_screen *screen = pipe->screen;; - tc->max_vertex_buffers = - screen->get_param(screen, PIPE_CAP_MAX_VERTEX_BUFFERS); tc->max_const_buffers = screen->get_shader_param(screen, PIPE_SHADER_FRAGMENT, PIPE_SHADER_CAP_MAX_CONST_BUFFERS); diff --git a/src/gallium/auxiliary/util/u_threaded_context.h b/src/gallium/auxiliary/util/u_threaded_context.h index 0ceb9bba75b..8fa6cfd4443 100644 --- a/src/gallium/auxiliary/util/u_threaded_context.h +++ b/src/gallium/auxiliary/util/u_threaded_context.h @@ -616,7 +616,7 @@ struct threaded_context { int8_t last_completed; - unsigned max_vertex_buffers; + uint8_t num_vertex_buffers; unsigned max_const_buffers; unsigned max_shader_buffers; unsigned max_images; diff --git a/src/gallium/auxiliary/util/u_vbuf.c b/src/gallium/auxiliary/util/u_vbuf.c index 1ab194cfe52..dc67af8b609 100644 --- a/src/gallium/auxiliary/util/u_vbuf.c +++ b/src/gallium/auxiliary/util/u_vbuf.c @@ -171,6 +171,9 @@ struct u_vbuf { /* This is what was set in set_vertex_buffers. * May contain user buffers. */ struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS]; + uint8_t num_vertex_buffers; + uint8_t num_real_vertex_buffers; + bool vertex_buffers_dirty; uint32_t enabled_vb_mask; uint32_t unaligned_vb_mask[2]; //16/32bit @@ -178,8 +181,6 @@ struct u_vbuf { /* Vertex buffers for the driver. * There are usually no user buffers. */ struct pipe_vertex_buffer real_vertex_buffer[PIPE_MAX_ATTRIBS]; - uint32_t dirty_real_vb_mask; /* which buffers are dirty since the last - call of set_vertex_buffers */ /* Vertex elements. */ struct u_vbuf_elements *ve, *ve_saved; @@ -441,12 +442,9 @@ void u_vbuf_unset_vertex_elements(struct u_vbuf *mgr) void u_vbuf_destroy(struct u_vbuf *mgr) { - struct pipe_screen *screen = mgr->pipe->screen; unsigned i; - const unsigned num_vb = screen->get_shader_param(screen, PIPE_SHADER_VERTEX, - PIPE_SHADER_CAP_MAX_INPUTS); - mgr->pipe->set_vertex_buffers(mgr->pipe, 0, num_vb, false, NULL); + mgr->pipe->set_vertex_buffers(mgr->pipe, 0, false, NULL); for (i = 0; i < PIPE_MAX_ATTRIBS; i++) pipe_vertex_buffer_unreference(&mgr->vertex_buffer[i]); @@ -672,7 +670,9 @@ u_vbuf_translate_find_free_vb_slots(struct u_vbuf *mgr, for (type = 0; type < VB_NUM; type++) { if (mask[type]) { - mgr->dirty_real_vb_mask |= 1 << fallback_vbs[type]; + mgr->num_real_vertex_buffers = + MAX2(mgr->num_real_vertex_buffers, fallback_vbs[type] + 1); + mgr->vertex_buffers_dirty = true; } } @@ -863,8 +863,11 @@ static void u_vbuf_translate_end(struct u_vbuf *mgr) mgr->fallback_vbs[i] = ~0; } } - /* This will cause the buffer to be unbound in the driver later. */ - mgr->dirty_real_vb_mask |= mgr->fallback_vbs_mask; + /* This will cause the fallback buffers above num_vertex_buffers to be + * unbound. + */ + mgr->num_real_vertex_buffers = mgr->num_vertex_buffers; + mgr->vertex_buffers_dirty = true; mgr->fallback_vbs_mask = 0; } @@ -993,10 +996,34 @@ static void u_vbuf_delete_vertex_elements(void *ctx, void *state, void u_vbuf_set_vertex_buffers(struct u_vbuf *mgr, unsigned count, - unsigned unbind_num_trailing_slots, bool take_ownership, const struct pipe_vertex_buffer *bufs) { + if (!count) { + struct pipe_context *pipe = mgr->pipe; + unsigned last_count = mgr->num_vertex_buffers; + + /* Unbind. */ + mgr->num_vertex_buffers = 0; + mgr->num_real_vertex_buffers = 0; + mgr->user_vb_mask = 0; + mgr->incompatible_vb_mask = 0; + mgr->enabled_vb_mask = 0; + mgr->unaligned_vb_mask[0] = 0; + mgr->unaligned_vb_mask[1] = 0; + mgr->vertex_buffers_dirty = false; + + for (unsigned i = 0; i < last_count; i++) { + pipe_vertex_buffer_unreference(&mgr->vertex_buffer[i]); + pipe_vertex_buffer_unreference(&mgr->real_vertex_buffer[i]); + } + + pipe->set_vertex_buffers(pipe, 0, false, NULL); + return; + } + + assert(bufs); + unsigned i; /* which buffers are enabled */ uint32_t enabled_vb_mask = 0; @@ -1006,29 +1033,7 @@ void u_vbuf_set_vertex_buffers(struct u_vbuf *mgr, uint32_t incompatible_vb_mask = 0; /* which buffers are unaligned to 2/4 bytes */ uint32_t unaligned_vb_mask[2] = {0}; - uint32_t mask = ~BITFIELD64_MASK(count + unbind_num_trailing_slots); - - if (!bufs) { - struct pipe_context *pipe = mgr->pipe; - /* Unbind. */ - unsigned total_count = count + unbind_num_trailing_slots; - mgr->dirty_real_vb_mask &= mask; - - /* Zero out the bits we are going to rewrite completely. */ - mgr->user_vb_mask &= mask; - mgr->incompatible_vb_mask &= mask; - mgr->enabled_vb_mask &= mask; - mgr->unaligned_vb_mask[0] &= mask; - mgr->unaligned_vb_mask[1] &= mask; - - for (i = 0; i < total_count; i++) { - pipe_vertex_buffer_unreference(&mgr->vertex_buffer[i]); - pipe_vertex_buffer_unreference(&mgr->real_vertex_buffer[i]); - } - - pipe->set_vertex_buffers(pipe, count, unbind_num_trailing_slots, false, NULL); - return; - } + unsigned num_identical = 0; for (i = 0; i < count; i++) { const struct pipe_vertex_buffer *vb = &bufs[i]; @@ -1041,20 +1046,11 @@ void u_vbuf_set_vertex_buffers(struct u_vbuf *mgr, continue; } - bool not_user = !vb->is_user_buffer && vb->is_user_buffer == orig_vb->is_user_buffer; - /* struct isn't tightly packed: do not use memcmp */ - if (not_user && - orig_vb->buffer_offset == vb->buffer_offset && orig_vb->buffer.resource == vb->buffer.resource) { - mask |= BITFIELD_BIT(i); - if (take_ownership) { - pipe_vertex_buffer_unreference(orig_vb); - /* the pointer was unset in the line above, so copy it back */ - orig_vb->buffer.resource = vb->buffer.resource; - } - if (mask == UINT32_MAX) - return; - continue; - } + /* The structure has holes: do not use memcmp. */ + if (orig_vb->is_user_buffer == vb->is_user_buffer && + orig_vb->buffer_offset == vb->buffer_offset && + orig_vb->buffer.resource == vb->buffer.resource) + num_identical++; if (take_ownership) { pipe_vertex_buffer_unreference(orig_vb); @@ -1091,30 +1087,24 @@ void u_vbuf_set_vertex_buffers(struct u_vbuf *mgr, pipe_vertex_buffer_reference(real_vb, vb); } - for (i = 0; i < unbind_num_trailing_slots; i++) { - unsigned dst_index = count + i; + unsigned last_count = mgr->num_vertex_buffers; - pipe_vertex_buffer_unreference(&mgr->vertex_buffer[dst_index]); - pipe_vertex_buffer_unreference(&mgr->real_vertex_buffer[dst_index]); - } - - - /* Zero out the bits we are going to rewrite completely. */ - mgr->user_vb_mask &= mask; - mgr->incompatible_vb_mask &= mask; - mgr->enabled_vb_mask &= mask; - mgr->unaligned_vb_mask[0] &= mask; - mgr->unaligned_vb_mask[1] &= mask; + if (num_identical == count && count == last_count) + return; - mgr->user_vb_mask |= user_vb_mask; - mgr->incompatible_vb_mask |= incompatible_vb_mask; - mgr->enabled_vb_mask |= enabled_vb_mask; - mgr->unaligned_vb_mask[0] |= unaligned_vb_mask[0]; - mgr->unaligned_vb_mask[1] |= unaligned_vb_mask[1]; + for (; i < last_count; i++) { + pipe_vertex_buffer_unreference(&mgr->vertex_buffer[i]); + pipe_vertex_buffer_unreference(&mgr->real_vertex_buffer[i]); + } - /* All changed buffers are marked as dirty, even the NULL ones, - * which will cause the NULL buffers to be unbound in the driver later. */ - mgr->dirty_real_vb_mask |= ~mask; + mgr->num_vertex_buffers = count; + mgr->num_real_vertex_buffers = count; + mgr->user_vb_mask = user_vb_mask; + mgr->incompatible_vb_mask = incompatible_vb_mask; + mgr->enabled_vb_mask = enabled_vb_mask; + mgr->unaligned_vb_mask[0] = unaligned_vb_mask[0]; + mgr->unaligned_vb_mask[1] = unaligned_vb_mask[1]; + mgr->vertex_buffers_dirty = true; } static ALWAYS_INLINE bool @@ -1403,15 +1393,16 @@ void u_vbuf_get_minmax_index(struct pipe_context *pipe, static void u_vbuf_set_driver_vertex_buffers(struct u_vbuf *mgr) { struct pipe_context *pipe = mgr->pipe; - unsigned count = util_last_bit(mgr->dirty_real_vb_mask); + unsigned count = mgr->num_real_vertex_buffers; + + assert(mgr->vertex_buffers_dirty); - if (mgr->dirty_real_vb_mask == mgr->enabled_vb_mask && - mgr->dirty_real_vb_mask == mgr->user_vb_mask) { + if (mgr->user_vb_mask == BITFIELD_MASK(count)) { /* Fast path that allows us to transfer the VBO references to the driver * to skip atomic reference counting there. These are freshly uploaded * user buffers that can be discarded after this call. */ - pipe->set_vertex_buffers(pipe, count, 0, true, mgr->real_vertex_buffer); + pipe->set_vertex_buffers(pipe, count, true, mgr->real_vertex_buffer); /* We don't own the VBO references now. Set them to NULL. */ for (unsigned i = 0; i < count; i++) { @@ -1420,9 +1411,9 @@ static void u_vbuf_set_driver_vertex_buffers(struct u_vbuf *mgr) } } else { /* Slow path where we have to keep VBO references. */ - pipe->set_vertex_buffers(pipe, count, 0, false, mgr->real_vertex_buffer); + pipe->set_vertex_buffers(pipe, count, false, mgr->real_vertex_buffer); } - mgr->dirty_real_vb_mask = 0; + mgr->vertex_buffers_dirty = false; } static void @@ -1489,7 +1480,7 @@ void u_vbuf_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *inf mgr->caps.supported_prim_modes & BITFIELD_BIT(info->mode)) { /* Set vertex buffers if needed. */ - if (mgr->dirty_real_vb_mask & used_vb_mask) { + if (mgr->vertex_buffers_dirty) { u_vbuf_set_driver_vertex_buffers(mgr); } @@ -1740,6 +1731,7 @@ void u_vbuf_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *inf user_vb_mask &= ~(incompatible_vb_mask | mgr->ve->incompatible_vb_mask_all); + mgr->vertex_buffers_dirty = true; } /* Upload user buffers. */ @@ -1751,7 +1743,7 @@ void u_vbuf_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *inf goto cleanup; } - mgr->dirty_real_vb_mask |= user_vb_mask; + mgr->vertex_buffers_dirty = true; } /* @@ -1776,7 +1768,7 @@ void u_vbuf_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *inf */ u_upload_unmap(pipe->stream_uploader); - if (mgr->dirty_real_vb_mask) + if (mgr->vertex_buffers_dirty) u_vbuf_set_driver_vertex_buffers(mgr); if ((new_info.index_size == 1 && mgr->caps.rewrite_ubyte_ibs) || diff --git a/src/gallium/auxiliary/util/u_vbuf.h b/src/gallium/auxiliary/util/u_vbuf.h index c8cefa7a4a0..e3509a66df3 100644 --- a/src/gallium/auxiliary/util/u_vbuf.h +++ b/src/gallium/auxiliary/util/u_vbuf.h @@ -82,7 +82,6 @@ void u_vbuf_set_vertex_elements(struct u_vbuf *mgr, void u_vbuf_unset_vertex_elements(struct u_vbuf *mgr); void u_vbuf_set_vertex_buffers(struct u_vbuf *mgr, unsigned count, - unsigned unbind_num_trailing_slots, bool take_ownership, const struct pipe_vertex_buffer *bufs); void u_vbuf_draw_vbo(struct pipe_context *pipe, diff --git a/src/gallium/auxiliary/vl/vl_bicubic_filter.c b/src/gallium/auxiliary/vl/vl_bicubic_filter.c index 7ff833b1ad8..88b63e372c5 100644 --- a/src/gallium/auxiliary/vl/vl_bicubic_filter.c +++ b/src/gallium/auxiliary/vl/vl_bicubic_filter.c @@ -461,7 +461,7 @@ vl_bicubic_filter_render(struct vl_bicubic_filter *filter, filter->pipe->bind_fs_state(filter->pipe, filter->fs); filter->pipe->set_framebuffer_state(filter->pipe, &fb_state); filter->pipe->set_viewport_states(filter->pipe, 0, 1, &viewport); - filter->pipe->set_vertex_buffers(filter->pipe, 1, 0, false, &filter->quad); + filter->pipe->set_vertex_buffers(filter->pipe, 1, false, &filter->quad); filter->pipe->bind_vertex_elements_state(filter->pipe, filter->ves); util_draw_arrays(filter->pipe, MESA_PRIM_QUADS, 0, 4); diff --git a/src/gallium/auxiliary/vl/vl_compositor_gfx.c b/src/gallium/auxiliary/vl/vl_compositor_gfx.c index f6fef79066f..9177e8f6717 100644 --- a/src/gallium/auxiliary/vl/vl_compositor_gfx.c +++ b/src/gallium/auxiliary/vl/vl_compositor_gfx.c @@ -739,7 +739,7 @@ vl_compositor_gfx_render(struct vl_compositor_state *s, c->pipe->set_framebuffer_state(c->pipe, &c->fb_state); c->pipe->bind_vs_state(c->pipe, c->vs); - c->pipe->set_vertex_buffers(c->pipe, 1, 0, false, &c->vertex_buf); + c->pipe->set_vertex_buffers(c->pipe, 1, false, &c->vertex_buf); c->pipe->bind_vertex_elements_state(c->pipe, c->vertex_elems_state); pipe_set_constant_buffer(c->pipe, PIPE_SHADER_FRAGMENT, 0, s->shader_params); c->pipe->bind_rasterizer_state(c->pipe, c->rast); diff --git a/src/gallium/auxiliary/vl/vl_deint_filter.c b/src/gallium/auxiliary/vl/vl_deint_filter.c index 9197c6ee924..ecfa76a2802 100644 --- a/src/gallium/auxiliary/vl/vl_deint_filter.c +++ b/src/gallium/auxiliary/vl/vl_deint_filter.c @@ -479,7 +479,7 @@ vl_deint_filter_render(struct vl_deint_filter *filter, /* set up pipe state */ filter->pipe->bind_rasterizer_state(filter->pipe, filter->rs_state); - filter->pipe->set_vertex_buffers(filter->pipe, 1, 0, false, &filter->quad); + filter->pipe->set_vertex_buffers(filter->pipe, 1, false, &filter->quad); filter->pipe->bind_vertex_elements_state(filter->pipe, filter->ves); filter->pipe->bind_vs_state(filter->pipe, filter->vs); filter->pipe->bind_sampler_states(filter->pipe, PIPE_SHADER_FRAGMENT, diff --git a/src/gallium/auxiliary/vl/vl_matrix_filter.c b/src/gallium/auxiliary/vl/vl_matrix_filter.c index 988e19298b9..92de9f158f0 100644 --- a/src/gallium/auxiliary/vl/vl_matrix_filter.c +++ b/src/gallium/auxiliary/vl/vl_matrix_filter.c @@ -307,7 +307,7 @@ vl_matrix_filter_render(struct vl_matrix_filter *filter, filter->pipe->bind_fs_state(filter->pipe, filter->fs); filter->pipe->set_framebuffer_state(filter->pipe, &fb_state); filter->pipe->set_viewport_states(filter->pipe, 0, 1, &viewport); - filter->pipe->set_vertex_buffers(filter->pipe, 1, 0, false, &filter->quad); + filter->pipe->set_vertex_buffers(filter->pipe, 1, false, &filter->quad); filter->pipe->bind_vertex_elements_state(filter->pipe, filter->ves); util_draw_arrays(filter->pipe, MESA_PRIM_QUADS, 0, 4); diff --git a/src/gallium/auxiliary/vl/vl_median_filter.c b/src/gallium/auxiliary/vl/vl_median_filter.c index b9f037ed4ef..f294386e5d6 100644 --- a/src/gallium/auxiliary/vl/vl_median_filter.c +++ b/src/gallium/auxiliary/vl/vl_median_filter.c @@ -426,7 +426,7 @@ vl_median_filter_render(struct vl_median_filter *filter, filter->pipe->bind_fs_state(filter->pipe, filter->fs); filter->pipe->set_framebuffer_state(filter->pipe, &fb_state); filter->pipe->set_viewport_states(filter->pipe, 0, 1, &viewport); - filter->pipe->set_vertex_buffers(filter->pipe, 1, 0, false, &filter->quad); + filter->pipe->set_vertex_buffers(filter->pipe, 1, false, &filter->quad); filter->pipe->bind_vertex_elements_state(filter->pipe, filter->ves); util_draw_arrays(filter->pipe, MESA_PRIM_QUADS, 0, 4); diff --git a/src/gallium/auxiliary/vl/vl_mpeg12_decoder.c b/src/gallium/auxiliary/vl/vl_mpeg12_decoder.c index 68f8f19752f..8f5d00c410c 100644 --- a/src/gallium/auxiliary/vl/vl_mpeg12_decoder.c +++ b/src/gallium/auxiliary/vl/vl_mpeg12_decoder.c @@ -794,7 +794,7 @@ vl_mpeg12_end_frame(struct pipe_video_codec *decoder, if (!ref_frames[j] || !ref_frames[j][i]) continue; vb[2] = vl_vb_get_mv(&buf->vertex_stream, j); - dec->context->set_vertex_buffers(dec->context, 3, 0, false, vb); + dec->context->set_vertex_buffers(dec->context, 3, false, vb); vl_mc_render_ref(i ? &dec->mc_c : &dec->mc_y, &buf->mc[i], ref_frames[j][i]); } @@ -805,7 +805,7 @@ vl_mpeg12_end_frame(struct pipe_video_codec *decoder, if (!buf->num_ycbcr_blocks[i]) continue; vb[1] = vl_vb_get_ycbcr(&buf->vertex_stream, i); - dec->context->set_vertex_buffers(dec->context, 2, 0, false, vb); + dec->context->set_vertex_buffers(dec->context, 2, false, vb); vl_zscan_render(i ? &dec->zscan_c : & dec->zscan_y, &buf->zscan[i] , buf->num_ycbcr_blocks[i]); @@ -824,7 +824,7 @@ vl_mpeg12_end_frame(struct pipe_video_codec *decoder, if (!buf->num_ycbcr_blocks[plane]) continue; vb[1] = vl_vb_get_ycbcr(&buf->vertex_stream, plane); - dec->context->set_vertex_buffers(dec->context, 2, 0, false, vb); + dec->context->set_vertex_buffers(dec->context, 2, false, vb); if (dec->base.entrypoint <= PIPE_VIDEO_ENTRYPOINT_IDCT) vl_idct_prepare_stage2(i ? &dec->idct_c : &dec->idct_y, &buf->idct[plane]); diff --git a/src/gallium/drivers/asahi/agx_blit.c b/src/gallium/drivers/asahi/agx_blit.c index dd6d2e6fe7b..7f6cccf171f 100644 --- a/src/gallium/drivers/asahi/agx_blit.c +++ b/src/gallium/drivers/asahi/agx_blit.c @@ -318,7 +318,8 @@ void agx_blitter_save(struct agx_context *ctx, struct blitter_context *blitter, bool render_cond) { - util_blitter_save_vertex_buffer_slot(blitter, ctx->vertex_buffers); + util_blitter_save_vertex_buffers(blitter, ctx->vertex_buffers, + util_last_bit(ctx->vb_mask)); util_blitter_save_vertex_elements(blitter, ctx->attributes); util_blitter_save_vertex_shader(blitter, ctx->stage[PIPE_SHADER_VERTEX].shader); diff --git a/src/gallium/drivers/asahi/agx_state.c b/src/gallium/drivers/asahi/agx_state.c index 78bd371b326..5e816dfd186 100644 --- a/src/gallium/drivers/asahi/agx_state.c +++ b/src/gallium/drivers/asahi/agx_state.c @@ -1419,14 +1419,13 @@ agx_delete_state(struct pipe_context *ctx, void *state) static void agx_set_vertex_buffers(struct pipe_context *pctx, unsigned count, - unsigned unbind_num_trailing_slots, bool take_ownership, + bool take_ownership, const struct pipe_vertex_buffer *buffers) { struct agx_context *ctx = agx_context(pctx); util_set_vertex_buffers_mask(ctx->vertex_buffers, &ctx->vb_mask, buffers, - count, unbind_num_trailing_slots, - take_ownership); + count, take_ownership); ctx->dirty |= AGX_DIRTY_VERTEX; } diff --git a/src/gallium/drivers/crocus/crocus_blit.c b/src/gallium/drivers/crocus/crocus_blit.c index 4a859921b5d..bb59faabf65 100644 --- a/src/gallium/drivers/crocus/crocus_blit.c +++ b/src/gallium/drivers/crocus/crocus_blit.c @@ -42,7 +42,8 @@ void crocus_blitter_begin(struct crocus_context *ice, enum crocus_blitter_op op, util_blitter_save_geometry_shader(ice->blitter, ice->shaders.uncompiled[MESA_SHADER_GEOMETRY]); util_blitter_save_so_targets(ice->blitter, ice->state.so_targets, (struct pipe_stream_output_target**)ice->state.so_target); - util_blitter_save_vertex_buffer_slot(ice->blitter, ice->state.vertex_buffers); + util_blitter_save_vertex_buffers(ice->blitter, ice->state.vertex_buffers, + util_last_bit(ice->state.bound_vertex_buffers)); util_blitter_save_vertex_elements(ice->blitter, (void *)ice->state.cso_vertex_elements); if (op & CROCUS_SAVE_FRAGMENT_STATE) { util_blitter_save_blend(ice->blitter, ice->state.cso_blend); diff --git a/src/gallium/drivers/crocus/crocus_state.c b/src/gallium/drivers/crocus/crocus_state.c index 60156dadf71..2781470fb9c 100644 --- a/src/gallium/drivers/crocus/crocus_state.c +++ b/src/gallium/drivers/crocus/crocus_state.c @@ -3659,7 +3659,6 @@ crocus_delete_state(struct pipe_context *ctx, void *state) static void crocus_set_vertex_buffers(struct pipe_context *ctx, unsigned count, - unsigned unbind_num_trailing_slots, bool take_ownership, const struct pipe_vertex_buffer *buffers) { @@ -3667,12 +3666,9 @@ crocus_set_vertex_buffers(struct pipe_context *ctx, struct crocus_screen *screen = (struct crocus_screen *) ctx->screen; const unsigned padding = (GFX_VERx10 < 75 && screen->devinfo.platform != INTEL_PLATFORM_BYT) * 2; - ice->state.bound_vertex_buffers &= - ~u_bit_consecutive64(0, count + unbind_num_trailing_slots); util_set_vertex_buffers_mask(ice->state.vertex_buffers, &ice->state.bound_vertex_buffers, - buffers, count, unbind_num_trailing_slots, - take_ownership); + buffers, count, take_ownership); for (unsigned i = 0; i < count; i++) { struct pipe_vertex_buffer *state = diff --git a/src/gallium/drivers/d3d12/d3d12_blit.cpp b/src/gallium/drivers/d3d12/d3d12_blit.cpp index 1c6af1e8483..2fbdd52c652 100644 --- a/src/gallium/drivers/d3d12/d3d12_blit.cpp +++ b/src/gallium/drivers/d3d12/d3d12_blit.cpp @@ -557,7 +557,7 @@ util_blit_save_state(struct d3d12_context *ctx) ctx->num_sampler_views[PIPE_SHADER_FRAGMENT], ctx->sampler_views[PIPE_SHADER_FRAGMENT]); util_blitter_save_fragment_constant_buffer_slot(ctx->blitter, ctx->cbufs[PIPE_SHADER_FRAGMENT]); - util_blitter_save_vertex_buffer_slot(ctx->blitter, ctx->vbs); + util_blitter_save_vertex_buffers(ctx->blitter, ctx->vbs, ctx->num_vbs); util_blitter_save_sample_mask(ctx->blitter, ctx->gfx_pipeline_state.sample_mask, 0); util_blitter_save_so_targets(ctx->blitter, ctx->gfx_pipeline_state.num_so_targets, ctx->so_targets); } diff --git a/src/gallium/drivers/d3d12/d3d12_context.cpp b/src/gallium/drivers/d3d12/d3d12_context.cpp index a8bea419dd9..4474d13e243 100644 --- a/src/gallium/drivers/d3d12/d3d12_context.cpp +++ b/src/gallium/drivers/d3d12/d3d12_context.cpp @@ -1334,15 +1334,11 @@ d3d12_set_polygon_stipple(struct pipe_context *pctx, static void d3d12_set_vertex_buffers(struct pipe_context *pctx, unsigned num_buffers, - unsigned unbind_num_trailing_slots, bool take_ownership, const struct pipe_vertex_buffer *buffers) { struct d3d12_context *ctx = d3d12_context(pctx); - util_set_vertex_buffers_count(ctx->vbs, &ctx->num_vbs, - buffers, num_buffers, - unbind_num_trailing_slots, - take_ownership); + util_set_vertex_buffers_count(ctx->vbs, &ctx->num_vbs, buffers, num_buffers, take_ownership); for (unsigned i = 0; i < ctx->num_vbs; ++i) { const struct pipe_vertex_buffer* buf = ctx->vbs + i; @@ -2097,7 +2093,7 @@ d3d12_clear_render_target(struct pipe_context *pctx, ctx->num_sampler_views[PIPE_SHADER_FRAGMENT], ctx->sampler_views[PIPE_SHADER_FRAGMENT]); util_blitter_save_fragment_constant_buffer_slot(ctx->blitter, ctx->cbufs[PIPE_SHADER_FRAGMENT]); - util_blitter_save_vertex_buffer_slot(ctx->blitter, ctx->vbs); + util_blitter_save_vertex_buffers(ctx->blitter, ctx->vbs, ctx->num_vbs); util_blitter_save_sample_mask(ctx->blitter, ctx->gfx_pipeline_state.sample_mask, 0); util_blitter_save_so_targets(ctx->blitter, ctx->gfx_pipeline_state.num_so_targets, ctx->so_targets); diff --git a/src/gallium/drivers/etnaviv/etnaviv_clear_blit.c b/src/gallium/drivers/etnaviv/etnaviv_clear_blit.c index adba89af620..275dffbdc7f 100644 --- a/src/gallium/drivers/etnaviv/etnaviv_clear_blit.c +++ b/src/gallium/drivers/etnaviv/etnaviv_clear_blit.c @@ -51,7 +51,8 @@ etna_blit_save_state(struct etna_context *ctx, bool render_cond) { util_blitter_save_fragment_constant_buffer_slot(ctx->blitter, ctx->constant_buffer[PIPE_SHADER_FRAGMENT].cb); - util_blitter_save_vertex_buffer_slot(ctx->blitter, ctx->vertex_buffer.vb); + util_blitter_save_vertex_buffers(ctx->blitter, ctx->vertex_buffer.vb, + ctx->vertex_buffer.count); util_blitter_save_vertex_elements(ctx->blitter, ctx->vertex_elements); util_blitter_save_vertex_shader(ctx->blitter, ctx->shader.bind_vs); util_blitter_save_rasterizer(ctx->blitter, ctx->rasterizer); diff --git a/src/gallium/drivers/etnaviv/etnaviv_state.c b/src/gallium/drivers/etnaviv/etnaviv_state.c index 8c8b86e754b..c7619a512b0 100644 --- a/src/gallium/drivers/etnaviv/etnaviv_state.c +++ b/src/gallium/drivers/etnaviv/etnaviv_state.c @@ -451,14 +451,12 @@ etna_set_viewport_states(struct pipe_context *pctx, unsigned start_slot, static void etna_set_vertex_buffers(struct pipe_context *pctx, unsigned num_buffers, - unsigned unbind_num_trailing_slots, bool take_ownership, - const struct pipe_vertex_buffer *vb) + bool take_ownership, const struct pipe_vertex_buffer *vb) { struct etna_context *ctx = etna_context(pctx); struct etna_vertexbuf_state *so = &ctx->vertex_buffer; - util_set_vertex_buffers_mask(so->vb, &so->enabled_mask, vb, - num_buffers, unbind_num_trailing_slots, + util_set_vertex_buffers_mask(so->vb, &so->enabled_mask, vb, num_buffers, take_ownership); so->count = util_last_bit(so->enabled_mask); diff --git a/src/gallium/drivers/freedreno/freedreno_blitter.c b/src/gallium/drivers/freedreno/freedreno_blitter.c index a0c402d41e2..c308316512e 100644 --- a/src/gallium/drivers/freedreno/freedreno_blitter.c +++ b/src/gallium/drivers/freedreno/freedreno_blitter.c @@ -79,7 +79,9 @@ default_src_texture(struct pipe_sampler_view *src_templ, static void fd_blitter_pipe_begin(struct fd_context *ctx, bool render_cond) assert_dt { - util_blitter_save_vertex_buffer_slot(ctx->blitter, ctx->vtx.vertexbuf.vb); + util_blitter_save_vertex_buffers( + ctx->blitter, ctx->vtx.vertexbuf.vb, + util_last_bit(ctx->vtx.vertexbuf.enabled_mask)); util_blitter_save_vertex_elements(ctx->blitter, ctx->vtx.vtx); util_blitter_save_vertex_shader(ctx->blitter, ctx->prog.vs); util_blitter_save_tessctrl_shader(ctx->blitter, ctx->prog.hs); @@ -235,7 +237,7 @@ fd_blitter_clear(struct pipe_context *pctx, unsigned buffers, pctx->set_viewport_states(pctx, 0, 1, &vp); pctx->bind_vertex_elements_state(pctx, ctx->solid_vbuf_state.vtx); - pctx->set_vertex_buffers(pctx, 1, 0, false, + pctx->set_vertex_buffers(pctx, 1, false, &ctx->solid_vbuf_state.vertexbuf.vb[0]); pctx->set_stream_output_targets(pctx, 0, NULL, NULL); diff --git a/src/gallium/drivers/freedreno/freedreno_state.c b/src/gallium/drivers/freedreno/freedreno_state.c index 69164c1c25b..3849052c09b 100644 --- a/src/gallium/drivers/freedreno/freedreno_state.c +++ b/src/gallium/drivers/freedreno/freedreno_state.c @@ -468,8 +468,7 @@ fd_set_viewport_states(struct pipe_context *pctx, unsigned start_slot, } static void -fd_set_vertex_buffers(struct pipe_context *pctx, - unsigned count, unsigned unbind_num_trailing_slots, +fd_set_vertex_buffers(struct pipe_context *pctx, unsigned count, bool take_ownership, const struct pipe_vertex_buffer *vb) in_dt { @@ -492,8 +491,7 @@ fd_set_vertex_buffers(struct pipe_context *pctx, } } - util_set_vertex_buffers_mask(so->vb, &so->enabled_mask, vb, - count, unbind_num_trailing_slots, + util_set_vertex_buffers_mask(so->vb, &so->enabled_mask, vb, count, take_ownership); so->count = util_last_bit(so->enabled_mask); diff --git a/src/gallium/drivers/i915/i915_state.c b/src/gallium/drivers/i915/i915_state.c index 8d8c3527823..8e5ab25ab41 100644 --- a/src/gallium/drivers/i915/i915_state.c +++ b/src/gallium/drivers/i915/i915_state.c @@ -992,18 +992,17 @@ i915_delete_rasterizer_state(struct pipe_context *pipe, void *raster) static void i915_set_vertex_buffers(struct pipe_context *pipe, unsigned count, - unsigned unbind_num_trailing_slots, bool take_ownership, + bool take_ownership, const struct pipe_vertex_buffer *buffers) { struct i915_context *i915 = i915_context(pipe); struct draw_context *draw = i915->draw; util_set_vertex_buffers_count(i915->vertex_buffers, &i915->nr_vertex_buffers, - buffers, count, unbind_num_trailing_slots, - take_ownership); + buffers, count, take_ownership); /* pass-through to draw module */ - draw_set_vertex_buffers(draw, count, unbind_num_trailing_slots, buffers); + draw_set_vertex_buffers(draw, count, buffers); } static void * diff --git a/src/gallium/drivers/i915/i915_surface.c b/src/gallium/drivers/i915/i915_surface.c index a0b8568851e..fd94e8f5d82 100644 --- a/src/gallium/drivers/i915/i915_surface.c +++ b/src/gallium/drivers/i915/i915_surface.c @@ -60,7 +60,8 @@ i915_util_blitter_save_states(struct i915_context *i915) util_blitter_save_viewport(i915->blitter, &i915->viewport); util_blitter_save_scissor(i915->blitter, &i915->scissor); util_blitter_save_vertex_elements(i915->blitter, i915->velems); - util_blitter_save_vertex_buffer_slot(i915->blitter, i915->vertex_buffers); + util_blitter_save_vertex_buffers(i915->blitter, i915->vertex_buffers, + i915->nr_vertex_buffers); util_blitter_save_framebuffer(i915->blitter, &i915->framebuffer); diff --git a/src/gallium/drivers/iris/iris_state.c b/src/gallium/drivers/iris/iris_state.c index ac911b79fe4..9fe6bc566d7 100644 --- a/src/gallium/drivers/iris/iris_state.c +++ b/src/gallium/drivers/iris/iris_state.c @@ -4008,7 +4008,6 @@ iris_delete_state(struct pipe_context *ctx, void *state) static void iris_set_vertex_buffers(struct pipe_context *ctx, unsigned count, - unsigned unbind_num_trailing_slots, bool take_ownership, const struct pipe_vertex_buffer *buffers) { @@ -4016,8 +4015,8 @@ iris_set_vertex_buffers(struct pipe_context *ctx, struct iris_screen *screen = (struct iris_screen *)ctx->screen; struct iris_genx_state *genx = ice->state.genx; - ice->state.bound_vertex_buffers &= - ~u_bit_consecutive64(0, count + unbind_num_trailing_slots); + unsigned last_count = util_last_bit64(ice->state.bound_vertex_buffers); + ice->state.bound_vertex_buffers = 0; for (unsigned i = 0; i < count; i++) { const struct pipe_vertex_buffer *buffer = buffers ? &buffers[i] : NULL; @@ -4072,9 +4071,9 @@ iris_set_vertex_buffers(struct pipe_context *ctx, } } - for (unsigned i = 0; i < unbind_num_trailing_slots; i++) { + for (unsigned i = count; i < last_count; i++) { struct iris_vertex_buffer_state *state = - &genx->vertex_buffers[count + i]; + &genx->vertex_buffers[i]; pipe_resource_reference(&state->resource, NULL); } diff --git a/src/gallium/drivers/lima/lima_resource.c b/src/gallium/drivers/lima/lima_resource.c index 56302e06726..d7fe9da69f7 100644 --- a/src/gallium/drivers/lima/lima_resource.c +++ b/src/gallium/drivers/lima/lima_resource.c @@ -837,8 +837,8 @@ lima_util_blitter_save_states(struct lima_context *ctx) util_blitter_save_scissor(ctx->blitter, &ctx->scissor); util_blitter_save_vertex_elements(ctx->blitter, ctx->vertex_elements); - util_blitter_save_vertex_buffer_slot(ctx->blitter, - ctx->vertex_buffers.vb); + util_blitter_save_vertex_buffers(ctx->blitter, + ctx->vertex_buffers.vb, ctx->vertex_buffers.count); util_blitter_save_framebuffer(ctx->blitter, &ctx->framebuffer.base); diff --git a/src/gallium/drivers/lima/lima_state.c b/src/gallium/drivers/lima/lima_state.c index 65a046afb59..14557505196 100644 --- a/src/gallium/drivers/lima/lima_state.c +++ b/src/gallium/drivers/lima/lima_state.c @@ -187,7 +187,6 @@ lima_delete_vertex_elements_state(struct pipe_context *pctx, void *hwcso) static void lima_set_vertex_buffers(struct pipe_context *pctx, unsigned count, - unsigned unbind_num_trailing_slots, bool take_ownership, const struct pipe_vertex_buffer *vb) { @@ -195,9 +194,7 @@ lima_set_vertex_buffers(struct pipe_context *pctx, struct lima_context_vertex_buffer *so = &ctx->vertex_buffers; util_set_vertex_buffers_mask(so->vb, &so->enabled_mask, - vb, count, - unbind_num_trailing_slots, - take_ownership); + vb, count, take_ownership); so->count = util_last_bit(so->enabled_mask); ctx->dirty |= LIMA_CONTEXT_DIRTY_VERTEX_BUFF; @@ -472,5 +469,5 @@ lima_state_fini(struct lima_context *ctx) struct lima_context_vertex_buffer *so = &ctx->vertex_buffers; util_set_vertex_buffers_mask(so->vb, &so->enabled_mask, NULL, - 0, ARRAY_SIZE(so->vb), false); + 0, false); } diff --git a/src/gallium/drivers/llvmpipe/lp_state_vertex.c b/src/gallium/drivers/llvmpipe/lp_state_vertex.c index b5998d0d7a6..ba995a5d169 100644 --- a/src/gallium/drivers/llvmpipe/lp_state_vertex.c +++ b/src/gallium/drivers/llvmpipe/lp_state_vertex.c @@ -81,7 +81,6 @@ llvmpipe_delete_vertex_elements_state(struct pipe_context *pipe, void *velems) static void llvmpipe_set_vertex_buffers(struct pipe_context *pipe, unsigned count, - unsigned unbind_num_trailing_slots, bool take_ownership, const struct pipe_vertex_buffer *buffers) { @@ -92,13 +91,11 @@ llvmpipe_set_vertex_buffers(struct pipe_context *pipe, util_set_vertex_buffers_count(llvmpipe->vertex_buffer, &llvmpipe->num_vertex_buffers, buffers, count, - unbind_num_trailing_slots, take_ownership); llvmpipe->dirty |= LP_NEW_VERTEX; - draw_set_vertex_buffers(llvmpipe->draw, count, - unbind_num_trailing_slots, buffers); + draw_set_vertex_buffers(llvmpipe->draw, count, buffers); } diff --git a/src/gallium/drivers/llvmpipe/lp_surface.c b/src/gallium/drivers/llvmpipe/lp_surface.c index ff2554774b3..cf5e4a48cdd 100644 --- a/src/gallium/drivers/llvmpipe/lp_surface.c +++ b/src/gallium/drivers/llvmpipe/lp_surface.c @@ -162,7 +162,8 @@ lp_blit(struct pipe_context *pipe, info.mask = PIPE_MASK_R; } - util_blitter_save_vertex_buffer_slot(lp->blitter, lp->vertex_buffer); + util_blitter_save_vertex_buffers(lp->blitter, lp->vertex_buffer, + lp->num_vertex_buffers); util_blitter_save_vertex_elements(lp->blitter, (void*)lp->velems); util_blitter_save_vertex_shader(lp->blitter, (void*)lp->vs); util_blitter_save_geometry_shader(lp->blitter, (void*)lp->gs); diff --git a/src/gallium/drivers/nouveau/nv30/nv30_draw.c b/src/gallium/drivers/nouveau/nv30/nv30_draw.c index 926272be55a..bdc5cab7608 100644 --- a/src/gallium/drivers/nouveau/nv30/nv30_draw.c +++ b/src/gallium/drivers/nouveau/nv30/nv30_draw.c @@ -396,7 +396,7 @@ nv30_render_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info, if (nv30->draw_dirty & NV30_NEW_CLIP) draw_set_clip_state(draw, &nv30->clip); if (nv30->draw_dirty & NV30_NEW_ARRAYS) { - draw_set_vertex_buffers(draw, nv30->num_vtxbufs, 0, nv30->vtxbuf); + draw_set_vertex_buffers(draw, nv30->num_vtxbufs, nv30->vtxbuf); draw_set_vertex_elements(draw, nv30->vertex->num_elements, nv30->vertex->pipe); } if (nv30->draw_dirty & NV30_NEW_FRAGPROG) { diff --git a/src/gallium/drivers/nouveau/nv30/nv30_miptree.c b/src/gallium/drivers/nouveau/nv30/nv30_miptree.c index f712134f6cc..e81585f4a12 100644 --- a/src/gallium/drivers/nouveau/nv30/nv30_miptree.c +++ b/src/gallium/drivers/nouveau/nv30/nv30_miptree.c @@ -248,7 +248,7 @@ nv30_blit(struct pipe_context *pipe, /* XXX turn off occlusion queries */ - util_blitter_save_vertex_buffer_slot(nv30->blitter, nv30->vtxbuf); + util_blitter_save_vertex_buffers(nv30->blitter, nv30->vtxbuf, nv30->num_vtxbufs); util_blitter_save_vertex_elements(nv30->blitter, nv30->vertex); util_blitter_save_vertex_shader(nv30->blitter, nv30->vertprog.program); util_blitter_save_rasterizer(nv30->blitter, nv30->rast); diff --git a/src/gallium/drivers/nouveau/nv30/nv30_state.c b/src/gallium/drivers/nouveau/nv30/nv30_state.c index 94b9c2d774d..3eefac77095 100644 --- a/src/gallium/drivers/nouveau/nv30/nv30_state.c +++ b/src/gallium/drivers/nouveau/nv30/nv30_state.c @@ -437,7 +437,6 @@ nv30_set_viewport_states(struct pipe_context *pipe, static void nv30_set_vertex_buffers(struct pipe_context *pipe, unsigned count, - unsigned unbind_num_trailing_slots, bool take_ownership, const struct pipe_vertex_buffer *vb) { @@ -446,9 +445,7 @@ nv30_set_vertex_buffers(struct pipe_context *pipe, nouveau_bufctx_reset(nv30->bufctx, BUFCTX_VTXBUF); util_set_vertex_buffers_count(nv30->vtxbuf, &nv30->num_vtxbufs, - vb, count, - unbind_num_trailing_slots, - take_ownership); + vb, count, take_ownership); nv30->dirty |= NV30_NEW_ARRAYS; } diff --git a/src/gallium/drivers/nouveau/nv50/nv50_state.c b/src/gallium/drivers/nouveau/nv50/nv50_state.c index 64fb3270015..0a6dee2bc03 100644 --- a/src/gallium/drivers/nouveau/nv50/nv50_state.c +++ b/src/gallium/drivers/nouveau/nv50/nv50_state.c @@ -1085,7 +1085,6 @@ nv50_set_window_rectangles(struct pipe_context *pipe, static void nv50_set_vertex_buffers(struct pipe_context *pipe, unsigned count, - unsigned unbind_num_trailing_slots, bool take_ownership, const struct pipe_vertex_buffer *vb) { @@ -1095,11 +1094,12 @@ nv50_set_vertex_buffers(struct pipe_context *pipe, nouveau_bufctx_reset(nv50->bufctx_3d, NV50_BIND_3D_VERTEX); nv50->dirty_3d |= NV50_NEW_3D_ARRAYS; + unsigned last_count = nv50->num_vtxbufs; util_set_vertex_buffers_count(nv50->vtxbuf, &nv50->num_vtxbufs, vb, - count, unbind_num_trailing_slots, - take_ownership); + count, take_ownership); - unsigned clear_mask = ~u_bit_consecutive(count, unbind_num_trailing_slots); + unsigned clear_mask = + last_count > count ? BITFIELD_RANGE(count, last_count - count) : 0; nv50->vbo_user &= clear_mask; nv50->vbo_constant &= clear_mask; nv50->vtxbufs_coherent &= clear_mask; diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_state.c b/src/gallium/drivers/nouveau/nvc0/nvc0_state.c index 9fa9b992ca5..89be0bbce54 100644 --- a/src/gallium/drivers/nouveau/nvc0/nvc0_state.c +++ b/src/gallium/drivers/nouveau/nvc0/nvc0_state.c @@ -1038,7 +1038,6 @@ nvc0_set_patch_vertices(struct pipe_context *pipe, uint8_t patch_vertices) static void nvc0_set_vertex_buffers(struct pipe_context *pipe, unsigned count, - unsigned unbind_num_trailing_slots, bool take_ownership, const struct pipe_vertex_buffer *vb) { @@ -1048,11 +1047,12 @@ nvc0_set_vertex_buffers(struct pipe_context *pipe, nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_3D_VTX); nvc0->dirty_3d |= NVC0_NEW_3D_ARRAYS; + unsigned last_count = nvc0->num_vtxbufs; util_set_vertex_buffers_count(nvc0->vtxbuf, &nvc0->num_vtxbufs, vb, - count, unbind_num_trailing_slots, - take_ownership); + count, take_ownership); - unsigned clear_mask = ~u_bit_consecutive(count, unbind_num_trailing_slots); + unsigned clear_mask = + last_count > count ? BITFIELD_RANGE(count, last_count - count) : 0; nvc0->vbo_user &= clear_mask; nvc0->constant_vbos &= clear_mask; nvc0->vtxbufs_coherent &= clear_mask; diff --git a/src/gallium/drivers/panfrost/pan_blit.c b/src/gallium/drivers/panfrost/pan_blit.c index 8347c0cdaee..235afc118be 100644 --- a/src/gallium/drivers/panfrost/pan_blit.c +++ b/src/gallium/drivers/panfrost/pan_blit.c @@ -38,7 +38,8 @@ panfrost_blitter_save(struct panfrost_context *ctx, { struct blitter_context *blitter = ctx->blitter; - util_blitter_save_vertex_buffer_slot(blitter, ctx->vertex_buffers); + util_blitter_save_vertex_buffers(blitter, ctx->vertex_buffers, + util_last_bit(ctx->vb_mask)); util_blitter_save_vertex_elements(blitter, ctx->vertex); util_blitter_save_vertex_shader(blitter, ctx->uncompiled[PIPE_SHADER_VERTEX]); diff --git a/src/gallium/drivers/panfrost/pan_context.c b/src/gallium/drivers/panfrost/pan_context.c index e1fed545c4b..cd8f2488ff7 100644 --- a/src/gallium/drivers/panfrost/pan_context.c +++ b/src/gallium/drivers/panfrost/pan_context.c @@ -327,15 +327,13 @@ panfrost_bind_sampler_states(struct pipe_context *pctx, static void panfrost_set_vertex_buffers(struct pipe_context *pctx, unsigned num_buffers, - unsigned unbind_num_trailing_slots, bool take_ownership, const struct pipe_vertex_buffer *buffers) { struct panfrost_context *ctx = pan_context(pctx); util_set_vertex_buffers_mask(ctx->vertex_buffers, &ctx->vb_mask, buffers, - num_buffers, unbind_num_trailing_slots, - take_ownership); + num_buffers, take_ownership); ctx->dirty |= PAN_DIRTY_VERTEX; } diff --git a/src/gallium/drivers/r300/r300_blit.c b/src/gallium/drivers/r300/r300_blit.c index 09a5eb3c64a..f2ca10ff334 100644 --- a/src/gallium/drivers/r300/r300_blit.c +++ b/src/gallium/drivers/r300/r300_blit.c @@ -69,7 +69,8 @@ static void r300_blitter_begin(struct r300_context* r300, enum r300_blitter_op o util_blitter_save_viewport(r300->blitter, &r300->viewport); util_blitter_save_scissor(r300->blitter, r300->scissor_state.state); util_blitter_save_sample_mask(r300->blitter, *(unsigned*)r300->sample_mask.state, 0); - util_blitter_save_vertex_buffer_slot(r300->blitter, r300->vertex_buffer); + util_blitter_save_vertex_buffers(r300->blitter, r300->vertex_buffer, + r300->nr_vertex_buffers); util_blitter_save_vertex_elements(r300->blitter, r300->velems); struct pipe_constant_buffer cb = { diff --git a/src/gallium/drivers/r300/r300_context.c b/src/gallium/drivers/r300/r300_context.c index edad0071a5a..a549bc18c67 100644 --- a/src/gallium/drivers/r300/r300_context.c +++ b/src/gallium/drivers/r300/r300_context.c @@ -474,7 +474,7 @@ struct pipe_context* r300_create_context(struct pipe_screen* screen, vb.depth0 = 1; r300->dummy_vb.buffer.resource = screen->resource_create(screen, &vb); - r300->context.set_vertex_buffers(&r300->context, 1, 0, false, &r300->dummy_vb); + r300->context.set_vertex_buffers(&r300->context, 1, false, &r300->dummy_vb); } { diff --git a/src/gallium/drivers/r300/r300_state.c b/src/gallium/drivers/r300/r300_state.c index a0177280444..cf1d6cc7e16 100644 --- a/src/gallium/drivers/r300/r300_state.c +++ b/src/gallium/drivers/r300/r300_state.c @@ -1771,23 +1771,20 @@ static void r300_set_viewport_states(struct pipe_context* pipe, } static void r300_set_vertex_buffers_hwtcl(struct pipe_context* pipe, - unsigned count, - unsigned unbind_num_trailing_slots, - bool take_ownership, + unsigned count, bool take_ownership, const struct pipe_vertex_buffer* buffers) { struct r300_context* r300 = r300_context(pipe); util_set_vertex_buffers_count(r300->vertex_buffer, - &r300->nr_vertex_buffers, - buffers, count, - unbind_num_trailing_slots, take_ownership); + &r300->nr_vertex_buffers, buffers, count, + take_ownership); /* There must be at least one vertex buffer set, otherwise it locks up. */ if (!r300->nr_vertex_buffers) { util_set_vertex_buffers_count(r300->vertex_buffer, &r300->nr_vertex_buffers, - &r300->dummy_vb, 1, 0, false); + &r300->dummy_vb, 1, false); } r300->vertex_arrays_dirty = true; @@ -1795,7 +1792,6 @@ static void r300_set_vertex_buffers_hwtcl(struct pipe_context* pipe, static void r300_set_vertex_buffers_swtcl(struct pipe_context* pipe, unsigned count, - unsigned unbind_num_trailing_slots, bool take_ownership, const struct pipe_vertex_buffer* buffers) { @@ -1803,11 +1799,9 @@ static void r300_set_vertex_buffers_swtcl(struct pipe_context* pipe, unsigned i; util_set_vertex_buffers_count(r300->vertex_buffer, - &r300->nr_vertex_buffers, - buffers, count, - unbind_num_trailing_slots, take_ownership); - draw_set_vertex_buffers(r300->draw, count, - unbind_num_trailing_slots, buffers); + &r300->nr_vertex_buffers, buffers, count, + take_ownership); + draw_set_vertex_buffers(r300->draw, count, buffers); if (!buffers) return; diff --git a/src/gallium/drivers/r600/r600_blit.c b/src/gallium/drivers/r600/r600_blit.c index b73a7b5b70e..174faf402f5 100644 --- a/src/gallium/drivers/r600/r600_blit.c +++ b/src/gallium/drivers/r600/r600_blit.c @@ -59,7 +59,8 @@ static void r600_blitter_begin(struct pipe_context *ctx, enum r600_blitter_op op rctx->cmd_buf_is_compute = false; } - util_blitter_save_vertex_buffer_slot(rctx->blitter, rctx->vertex_buffer_state.vb); + util_blitter_save_vertex_buffers(rctx->blitter, rctx->vertex_buffer_state.vb, + util_last_bit(rctx->vertex_buffer_state.enabled_mask)); util_blitter_save_vertex_elements(rctx->blitter, rctx->vertex_fetch_shader.cso); util_blitter_save_vertex_shader(rctx->blitter, rctx->vs_shader); util_blitter_save_geometry_shader(rctx->blitter, rctx->gs_shader); diff --git a/src/gallium/drivers/r600/r600_pipe_common.c b/src/gallium/drivers/r600/r600_pipe_common.c index 4ab183dde08..1ea614ed39d 100644 --- a/src/gallium/drivers/r600/r600_pipe_common.c +++ b/src/gallium/drivers/r600/r600_pipe_common.c @@ -208,7 +208,7 @@ void r600_draw_rectangle(struct blitter_context *blitter, vbuffer.buffer.resource = buf; vbuffer.buffer_offset = offset; - rctx->b.set_vertex_buffers(&rctx->b, 1, 0, false, &vbuffer); + rctx->b.set_vertex_buffers(&rctx->b, 1, false, &vbuffer); util_draw_arrays_instanced(&rctx->b, R600_PRIM_RECTANGLE_LIST, 0, 3, 0, num_instances); pipe_resource_reference(&buf, NULL); diff --git a/src/gallium/drivers/r600/r600_state_common.c b/src/gallium/drivers/r600/r600_state_common.c index bcd78fc0cf8..9163d19594c 100644 --- a/src/gallium/drivers/r600/r600_state_common.c +++ b/src/gallium/drivers/r600/r600_state_common.c @@ -577,9 +577,7 @@ static void r600_bind_vertex_elements(struct pipe_context *ctx, void *state) } static void r600_set_vertex_buffers(struct pipe_context *ctx, - unsigned count, - unsigned unbind_num_trailing_slots, - bool take_ownership, + unsigned count, bool take_ownership, const struct pipe_vertex_buffer *input) { struct r600_context *rctx = (struct r600_context *)ctx; @@ -591,27 +589,12 @@ static void r600_set_vertex_buffers(struct pipe_context *ctx, uint32_t new_buffer_mask = 0; /* Set vertex buffers. */ - if (input) { - for (i = 0; i < count; i++) { - if (likely((input[i].buffer.resource != vb[i].buffer.resource) || - (vb[i].buffer_offset != input[i].buffer_offset) || - (vb[i].is_user_buffer != input[i].is_user_buffer))) { - if (input[i].buffer.resource) { - vb[i].buffer_offset = input[i].buffer_offset; - if (take_ownership) { - pipe_resource_reference(&vb[i].buffer.resource, NULL); - vb[i].buffer.resource = input[i].buffer.resource; - } else { - pipe_resource_reference(&vb[i].buffer.resource, - input[i].buffer.resource); - } - new_buffer_mask |= 1 << i; - r600_context_add_resource_size(ctx, input[i].buffer.resource); - } else { - pipe_resource_reference(&vb[i].buffer.resource, NULL); - disable_mask |= 1 << i; - } - } else if (input[i].buffer.resource) { + for (i = 0; i < count; i++) { + if (likely((input[i].buffer.resource != vb[i].buffer.resource) || + (vb[i].buffer_offset != input[i].buffer_offset) || + (vb[i].is_user_buffer != input[i].is_user_buffer))) { + if (input[i].buffer.resource) { + vb[i].buffer_offset = input[i].buffer_offset; if (take_ownership) { pipe_resource_reference(&vb[i].buffer.resource, NULL); vb[i].buffer.resource = input[i].buffer.resource; @@ -619,19 +602,29 @@ static void r600_set_vertex_buffers(struct pipe_context *ctx, pipe_resource_reference(&vb[i].buffer.resource, input[i].buffer.resource); } + new_buffer_mask |= 1 << i; + r600_context_add_resource_size(ctx, input[i].buffer.resource); + } else { + pipe_resource_reference(&vb[i].buffer.resource, NULL); + disable_mask |= 1 << i; + } + } else if (input[i].buffer.resource) { + if (take_ownership) { + pipe_resource_reference(&vb[i].buffer.resource, NULL); + vb[i].buffer.resource = input[i].buffer.resource; + } else { + pipe_resource_reference(&vb[i].buffer.resource, + input[i].buffer.resource); } } - } else { - for (i = 0; i < count; i++) { - pipe_resource_reference(&vb[i].buffer.resource, NULL); - } - disable_mask = ((1ull << count) - 1); } - for (i = 0; i < unbind_num_trailing_slots; i++) { - pipe_resource_reference(&vb[count + i].buffer.resource, NULL); - } - disable_mask |= ((1ull << unbind_num_trailing_slots) - 1) << count; + unsigned last_count = util_last_bit(rctx->vertex_buffer_state.enabled_mask); + for (; i < last_count; i++) + pipe_resource_reference(&vb[i].buffer.resource, NULL); + + if (last_count > count) + disable_mask |= BITFIELD_RANGE(count, last_count - count); rctx->vertex_buffer_state.enabled_mask &= ~disable_mask; rctx->vertex_buffer_state.dirty_mask &= rctx->vertex_buffer_state.enabled_mask; diff --git a/src/gallium/drivers/radeonsi/si_pipe.h b/src/gallium/drivers/radeonsi/si_pipe.h index 50849fc8920..9c1dcb63946 100644 --- a/src/gallium/drivers/radeonsi/si_pipe.h +++ b/src/gallium/drivers/radeonsi/si_pipe.h @@ -1160,6 +1160,7 @@ struct si_context { /* Vertex buffers. */ bool vertex_buffers_dirty; + uint8_t num_vertex_buffers; uint16_t vertex_buffer_unaligned; /* bitmask of not dword-aligned buffers */ struct pipe_vertex_buffer vertex_buffer[SI_NUM_VERTEX_BUFFERS]; diff --git a/src/gallium/drivers/radeonsi/si_state.c b/src/gallium/drivers/radeonsi/si_state.c index 47485a23feb..8f7ca07432f 100644 --- a/src/gallium/drivers/radeonsi/si_state.c +++ b/src/gallium/drivers/radeonsi/si_state.c @@ -5546,70 +5546,48 @@ static void si_delete_vertex_element(struct pipe_context *ctx, void *state) FREE(state); } -static void si_set_vertex_buffers(struct pipe_context *ctx, unsigned count, - unsigned unbind_num_trailing_slots, bool take_ownership, +static void si_set_vertex_buffers(struct pipe_context *ctx, unsigned count, bool take_ownership, const struct pipe_vertex_buffer *buffers) { struct si_context *sctx = (struct si_context *)ctx; - unsigned updated_mask = u_bit_consecutive(0, count + unbind_num_trailing_slots); - uint32_t orig_unaligned = sctx->vertex_buffer_unaligned; uint32_t unaligned = 0; - int i; + unsigned i; + + assert(count <= ARRAY_SIZE(sctx->vertex_buffer)); + assert(!count || buffers); - assert(count + unbind_num_trailing_slots <= ARRAY_SIZE(sctx->vertex_buffer)); + for (i = 0; i < count; i++) { + const struct pipe_vertex_buffer *src = buffers + i; + struct pipe_vertex_buffer *dst = sctx->vertex_buffer + i; + struct pipe_resource *buf = src->buffer.resource; - if (buffers) { + dst->buffer_offset = src->buffer_offset; + + /* Only unreference bound vertex buffers. (take_ownership) */ if (take_ownership) { - for (i = 0; i < count; i++) { - const struct pipe_vertex_buffer *src = buffers + i; - struct pipe_vertex_buffer *dst = sctx->vertex_buffer + i; - struct pipe_resource *buf = src->buffer.resource; - unsigned slot_bit = 1 << i; - - /* Only unreference bound vertex buffers. (take_ownership) */ - pipe_resource_reference(&dst->buffer.resource, NULL); - - if (src->buffer_offset & 3) - unaligned |= slot_bit; - - if (buf) { - si_resource(buf)->bind_history |= SI_BIND_VERTEX_BUFFER; - radeon_add_to_buffer_list(sctx, &sctx->gfx_cs, si_resource(buf), - RADEON_USAGE_READ | RADEON_PRIO_VERTEX_BUFFER); - } - } - /* take_ownership allows us to copy pipe_resource pointers without refcounting. */ - memcpy(sctx->vertex_buffer, buffers, count * sizeof(struct pipe_vertex_buffer)); + pipe_resource_reference(&dst->buffer.resource, NULL); + dst->buffer.resource = src->buffer.resource; } else { - for (i = 0; i < count; i++) { - const struct pipe_vertex_buffer *src = buffers + i; - struct pipe_vertex_buffer *dst = sctx->vertex_buffer + i; - struct pipe_resource *buf = src->buffer.resource; - unsigned slot_bit = 1 << i; - - pipe_resource_reference(&dst->buffer.resource, buf); - dst->buffer_offset = src->buffer_offset; - - if (dst->buffer_offset & 3) - unaligned |= slot_bit; - - if (buf) { - si_resource(buf)->bind_history |= SI_BIND_VERTEX_BUFFER; - radeon_add_to_buffer_list(sctx, &sctx->gfx_cs, si_resource(buf), - RADEON_USAGE_READ | RADEON_PRIO_VERTEX_BUFFER); - } - } + pipe_resource_reference(&dst->buffer.resource, src->buffer.resource); + } + + if (src->buffer_offset & 3) + unaligned |= BITFIELD_BIT(i); + + if (buf) { + si_resource(buf)->bind_history |= SI_BIND_VERTEX_BUFFER; + radeon_add_to_buffer_list(sctx, &sctx->gfx_cs, si_resource(buf), + RADEON_USAGE_READ | RADEON_PRIO_VERTEX_BUFFER); } - } else { - for (i = 0; i < count; i++) - pipe_resource_reference(&sctx->vertex_buffer[i].buffer.resource, NULL); } - for (i = 0; i < unbind_num_trailing_slots; i++) - pipe_resource_reference(&sctx->vertex_buffer[count + i].buffer.resource, NULL); + unsigned last_count = sctx->num_vertex_buffers; + for (; i < last_count; i++) + pipe_resource_reference(&sctx->vertex_buffer[i].buffer.resource, NULL); + sctx->num_vertex_buffers = count; sctx->vertex_buffers_dirty = sctx->num_vertex_elements > 0; - sctx->vertex_buffer_unaligned = (orig_unaligned & ~updated_mask) | unaligned; + sctx->vertex_buffer_unaligned = unaligned; /* Check whether alignment may have changed in a way that requires * shader changes. This check is conservative: a vertex buffer can only @@ -5618,8 +5596,7 @@ static void si_set_vertex_buffers(struct pipe_context *ctx, unsigned count, * whether buffers are at least dword-aligned, since that should always * be the case in well-behaved applications anyway. */ - if ((sctx->vertex_elements->vb_alignment_check_mask & - (unaligned | orig_unaligned) & updated_mask)) { + if (sctx->vertex_elements->vb_alignment_check_mask & unaligned) { si_vs_key_update_inputs(sctx); sctx->do_update_shaders = true; } diff --git a/src/gallium/drivers/softpipe/sp_state_vertex.c b/src/gallium/drivers/softpipe/sp_state_vertex.c index 8f8aa47d454..bf9f32dd2b1 100644 --- a/src/gallium/drivers/softpipe/sp_state_vertex.c +++ b/src/gallium/drivers/softpipe/sp_state_vertex.c @@ -81,7 +81,6 @@ softpipe_delete_vertex_elements_state(struct pipe_context *pipe, void *velems) static void softpipe_set_vertex_buffers(struct pipe_context *pipe, unsigned count, - unsigned unbind_num_trailing_slots, bool take_ownership, const struct pipe_vertex_buffer *buffers) { @@ -92,12 +91,11 @@ softpipe_set_vertex_buffers(struct pipe_context *pipe, util_set_vertex_buffers_count(softpipe->vertex_buffer, &softpipe->num_vertex_buffers, buffers, count, - unbind_num_trailing_slots, take_ownership); softpipe->dirty |= SP_NEW_VERTEX; - draw_set_vertex_buffers(softpipe->draw, count, unbind_num_trailing_slots, buffers); + draw_set_vertex_buffers(softpipe->draw, count, buffers); } diff --git a/src/gallium/drivers/softpipe/sp_surface.c b/src/gallium/drivers/softpipe/sp_surface.c index 3f48c94b6e5..d25247a5e1d 100644 --- a/src/gallium/drivers/softpipe/sp_surface.c +++ b/src/gallium/drivers/softpipe/sp_surface.c @@ -60,7 +60,8 @@ static void sp_blit(struct pipe_context *pipe, /* XXX turn off occlusion and streamout queries */ - util_blitter_save_vertex_buffer_slot(sp->blitter, sp->vertex_buffer); + util_blitter_save_vertex_buffers(sp->blitter, sp->vertex_buffer, + sp->num_vertex_buffers); util_blitter_save_vertex_elements(sp->blitter, sp->velems); util_blitter_save_vertex_shader(sp->blitter, sp->vs); util_blitter_save_geometry_shader(sp->blitter, sp->gs); diff --git a/src/gallium/drivers/svga/svga_pipe_blit.c b/src/gallium/drivers/svga/svga_pipe_blit.c index a9432568371..b9157abb2fe 100644 --- a/src/gallium/drivers/svga/svga_pipe_blit.c +++ b/src/gallium/drivers/svga/svga_pipe_blit.c @@ -619,7 +619,8 @@ try_blit(struct svga_context *svga, const struct pipe_blit_info *blit_info) /* XXX turn off occlusion and streamout queries */ - util_blitter_save_vertex_buffer_slot(svga->blitter, svga->curr.vb); + util_blitter_save_vertex_buffers(svga->blitter, svga->curr.vb, + svga->curr.num_vertex_buffers); util_blitter_save_vertex_elements(svga->blitter, (void*)svga->curr.velems); util_blitter_save_vertex_shader(svga->blitter, svga->curr.vs); util_blitter_save_geometry_shader(svga->blitter, svga->curr.user_gs); diff --git a/src/gallium/drivers/svga/svga_pipe_clear.c b/src/gallium/drivers/svga/svga_pipe_clear.c index 3917328650b..62f9cfef746 100644 --- a/src/gallium/drivers/svga/svga_pipe_clear.c +++ b/src/gallium/drivers/svga/svga_pipe_clear.c @@ -41,7 +41,8 @@ static void begin_blit(struct svga_context *svga) { - util_blitter_save_vertex_buffer_slot(svga->blitter, svga->curr.vb); + util_blitter_save_vertex_buffers(svga->blitter, svga->curr.vb, + svga->curr.num_vertex_buffers); util_blitter_save_vertex_elements(svga->blitter, (void*)svga->curr.velems); util_blitter_save_vertex_shader(svga->blitter, svga->curr.vs); util_blitter_save_geometry_shader(svga->blitter, svga->curr.gs); diff --git a/src/gallium/drivers/svga/svga_pipe_vertex.c b/src/gallium/drivers/svga/svga_pipe_vertex.c index abfd303c516..4b9794e07b1 100644 --- a/src/gallium/drivers/svga/svga_pipe_vertex.c +++ b/src/gallium/drivers/svga/svga_pipe_vertex.c @@ -42,7 +42,6 @@ static void svga_set_vertex_buffers(struct pipe_context *pipe, unsigned count, - unsigned unbind_num_trailing_slots, bool take_ownership, const struct pipe_vertex_buffer *buffers) { @@ -50,9 +49,7 @@ svga_set_vertex_buffers(struct pipe_context *pipe, util_set_vertex_buffers_count(svga->curr.vb, &svga->curr.num_vertex_buffers, - buffers, count, - unbind_num_trailing_slots, - take_ownership); + buffers, count, take_ownership); svga->dirty |= SVGA_NEW_VBUFFER; } diff --git a/src/gallium/drivers/svga/svga_swtnl_state.c b/src/gallium/drivers/svga/svga_swtnl_state.c index b64acdd0a78..c49647f822a 100644 --- a/src/gallium/drivers/svga/svga_swtnl_state.c +++ b/src/gallium/drivers/svga/svga_swtnl_state.c @@ -114,7 +114,7 @@ update_swtnl_draw(struct svga_context *svga, uint64_t dirty) if (dirty & SVGA_NEW_VBUFFER) draw_set_vertex_buffers(svga->swtnl.draw, - svga->curr.num_vertex_buffers, 0, + svga->curr.num_vertex_buffers, svga->curr.vb); if (dirty & SVGA_NEW_VELEMENT) diff --git a/src/gallium/drivers/tegra/tegra_context.c b/src/gallium/drivers/tegra/tegra_context.c index c98953744a3..fcfbc94aa63 100644 --- a/src/gallium/drivers/tegra/tegra_context.c +++ b/src/gallium/drivers/tegra/tegra_context.c @@ -635,7 +635,7 @@ tegra_set_shader_images(struct pipe_context *pcontext, enum pipe_shader_type sha static void tegra_set_vertex_buffers(struct pipe_context *pcontext, - unsigned num_buffers, unsigned unbind_num_trailing_slots, + unsigned num_buffers, bool take_ownership, const struct pipe_vertex_buffer *buffers) { @@ -655,7 +655,6 @@ tegra_set_vertex_buffers(struct pipe_context *pcontext, } context->gpu->set_vertex_buffers(context->gpu, num_buffers, - unbind_num_trailing_slots, take_ownership, buffers); } diff --git a/src/gallium/drivers/v3d/v3d_blit.c b/src/gallium/drivers/v3d/v3d_blit.c index 7cad3762dd1..e8ddf103d55 100644 --- a/src/gallium/drivers/v3d/v3d_blit.c +++ b/src/gallium/drivers/v3d/v3d_blit.c @@ -42,7 +42,7 @@ v3d_blitter_save(struct v3d_context *v3d, bool op_blit, bool render_cond) { util_blitter_save_fragment_constant_buffer_slot(v3d->blitter, v3d->constbuf[PIPE_SHADER_FRAGMENT].cb); - util_blitter_save_vertex_buffer_slot(v3d->blitter, v3d->vertexbuf.vb); + util_blitter_save_vertex_buffers(v3d->blitter, v3d->vertexbuf.vb, v3d->vertexbuf.count); util_blitter_save_vertex_elements(v3d->blitter, v3d->vtx); util_blitter_save_vertex_shader(v3d->blitter, v3d->prog.bind_vs); util_blitter_save_geometry_shader(v3d->blitter, v3d->prog.bind_gs); diff --git a/src/gallium/drivers/v3d/v3dx_state.c b/src/gallium/drivers/v3d/v3dx_state.c index f2b2b2dab66..c98d98f2a56 100644 --- a/src/gallium/drivers/v3d/v3dx_state.c +++ b/src/gallium/drivers/v3d/v3dx_state.c @@ -292,7 +292,6 @@ v3d_set_viewport_states(struct pipe_context *pctx, static void v3d_set_vertex_buffers(struct pipe_context *pctx, unsigned count, - unsigned unbind_num_trailing_slots, bool take_ownership, const struct pipe_vertex_buffer *vb) { @@ -300,8 +299,7 @@ v3d_set_vertex_buffers(struct pipe_context *pctx, struct v3d_vertexbuf_stateobj *so = &v3d->vertexbuf; util_set_vertex_buffers_mask(so->vb, &so->enabled_mask, vb, - count, unbind_num_trailing_slots, - take_ownership); + count, take_ownership); so->count = util_last_bit(so->enabled_mask); v3d->dirty |= V3D_DIRTY_VTXBUF; diff --git a/src/gallium/drivers/vc4/vc4_blit.c b/src/gallium/drivers/vc4/vc4_blit.c index 0e885d180c5..c15e537a5a9 100644 --- a/src/gallium/drivers/vc4/vc4_blit.c +++ b/src/gallium/drivers/vc4/vc4_blit.c @@ -195,7 +195,8 @@ vc4_blitter_save(struct vc4_context *vc4) { util_blitter_save_fragment_constant_buffer_slot(vc4->blitter, vc4->constbuf[PIPE_SHADER_FRAGMENT].cb); - util_blitter_save_vertex_buffer_slot(vc4->blitter, vc4->vertexbuf.vb); + util_blitter_save_vertex_buffers(vc4->blitter, vc4->vertexbuf.vb, + vc4->vertexbuf.count); util_blitter_save_vertex_elements(vc4->blitter, vc4->vtx); util_blitter_save_vertex_shader(vc4->blitter, vc4->prog.bind_vs); util_blitter_save_rasterizer(vc4->blitter, vc4->rasterizer); diff --git a/src/gallium/drivers/vc4/vc4_state.c b/src/gallium/drivers/vc4/vc4_state.c index bea71c8ddc8..c12c57f5c56 100644 --- a/src/gallium/drivers/vc4/vc4_state.c +++ b/src/gallium/drivers/vc4/vc4_state.c @@ -313,7 +313,6 @@ vc4_set_viewport_states(struct pipe_context *pctx, static void vc4_set_vertex_buffers(struct pipe_context *pctx, unsigned count, - unsigned unbind_num_trailing_slots, bool take_ownership, const struct pipe_vertex_buffer *vb) { @@ -321,8 +320,7 @@ vc4_set_vertex_buffers(struct pipe_context *pctx, struct vc4_vertexbuf_stateobj *so = &vc4->vertexbuf; util_set_vertex_buffers_mask(so->vb, &so->enabled_mask, vb, - count, unbind_num_trailing_slots, - take_ownership); + count, take_ownership); so->count = util_last_bit(so->enabled_mask); vc4->dirty |= VC4_DIRTY_VTXBUF; diff --git a/src/gallium/drivers/virgl/virgl_context.c b/src/gallium/drivers/virgl/virgl_context.c index 2c2a741ada4..f632f50cae3 100644 --- a/src/gallium/drivers/virgl/virgl_context.c +++ b/src/gallium/drivers/virgl/virgl_context.c @@ -565,7 +565,6 @@ static void virgl_bind_vertex_elements_state(struct pipe_context *ctx, static void virgl_set_vertex_buffers(struct pipe_context *ctx, unsigned num_buffers, - unsigned unbind_num_trailing_slots, bool take_ownership, const struct pipe_vertex_buffer *buffers) { @@ -574,7 +573,6 @@ static void virgl_set_vertex_buffers(struct pipe_context *ctx, util_set_vertex_buffers_count(vctx->vertex_buffer, &vctx->num_vertex_buffers, buffers, num_buffers, - unbind_num_trailing_slots, take_ownership); if (buffers) { diff --git a/src/gallium/drivers/zink/zink_blit.c b/src/gallium/drivers/zink/zink_blit.c index 43ab2db5649..f82fe1d954e 100644 --- a/src/gallium/drivers/zink/zink_blit.c +++ b/src/gallium/drivers/zink/zink_blit.c @@ -501,7 +501,8 @@ zink_blit_begin(struct zink_context *ctx, enum zink_blit_flags flags) util_blitter_save_vertex_elements(ctx->blitter, ctx->element_state); util_blitter_save_viewport(ctx->blitter, ctx->vp_state.viewport_states); - util_blitter_save_vertex_buffer_slot(ctx->blitter, ctx->vertex_buffers); + util_blitter_save_vertex_buffers(ctx->blitter, ctx->vertex_buffers, + util_last_bit(ctx->gfx_pipeline_state.vertex_buffers_enabled_mask)); util_blitter_save_vertex_shader(ctx->blitter, ctx->gfx_stages[MESA_SHADER_VERTEX]); util_blitter_save_tessctrl_shader(ctx->blitter, ctx->gfx_stages[MESA_SHADER_TESS_CTRL]); util_blitter_save_tesseval_shader(ctx->blitter, ctx->gfx_stages[MESA_SHADER_TESS_EVAL]); diff --git a/src/gallium/drivers/zink/zink_context.c b/src/gallium/drivers/zink/zink_context.c index df5472448b4..2c4f8167f9d 100644 --- a/src/gallium/drivers/zink/zink_context.c +++ b/src/gallium/drivers/zink/zink_context.c @@ -1339,7 +1339,6 @@ update_existing_vbo(struct zink_context *ctx, unsigned slot) static void zink_set_vertex_buffers(struct pipe_context *pctx, unsigned num_buffers, - unsigned unbind_num_trailing_slots, bool take_ownership, const struct pipe_vertex_buffer *buffers) { @@ -1348,44 +1347,39 @@ zink_set_vertex_buffers(struct pipe_context *pctx, const bool need_state_change = !zink_screen(pctx->screen)->info.have_EXT_extended_dynamic_state && !have_input_state; uint32_t enabled_buffers = ctx->gfx_pipeline_state.vertex_buffers_enabled_mask; - enabled_buffers |= u_bit_consecutive(0, num_buffers); - enabled_buffers &= ~u_bit_consecutive(num_buffers, unbind_num_trailing_slots); - - if (buffers) { - for (unsigned i = 0; i < num_buffers; ++i) { - const struct pipe_vertex_buffer *vb = buffers + i; - struct pipe_vertex_buffer *ctx_vb = &ctx->vertex_buffers[i]; - update_existing_vbo(ctx, i); - if (!take_ownership) - pipe_resource_reference(&ctx_vb->buffer.resource, vb->buffer.resource); - else { - pipe_resource_reference(&ctx_vb->buffer.resource, NULL); - ctx_vb->buffer.resource = vb->buffer.resource; - } - if (vb->buffer.resource) { - struct zink_resource *res = zink_resource(vb->buffer.resource); - res->vbo_bind_mask |= BITFIELD_BIT(i); - res->vbo_bind_count++; - res->gfx_barrier |= VK_PIPELINE_STAGE_VERTEX_INPUT_BIT; - res->barrier_access[0] |= VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT; - update_res_bind_count(ctx, res, false, false); - ctx_vb->buffer_offset = vb->buffer_offset; - /* always barrier before possible rebind */ - zink_screen(ctx->base.screen)->buffer_barrier(ctx, res, VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT, - VK_PIPELINE_STAGE_VERTEX_INPUT_BIT); - zink_batch_resource_usage_set(&ctx->batch, res, false, true); - res->obj->unordered_read = false; - } else { - enabled_buffers &= ~BITFIELD_BIT(i); - } + unsigned last_count = util_last_bit(enabled_buffers); + enabled_buffers = u_bit_consecutive(0, num_buffers); + + assert(!num_buffers || buffers); + + for (unsigned i = 0; i < num_buffers; ++i) { + const struct pipe_vertex_buffer *vb = buffers + i; + struct pipe_vertex_buffer *ctx_vb = &ctx->vertex_buffers[i]; + update_existing_vbo(ctx, i); + if (!take_ownership) + pipe_resource_reference(&ctx_vb->buffer.resource, vb->buffer.resource); + else { + pipe_resource_reference(&ctx_vb->buffer.resource, NULL); + ctx_vb->buffer.resource = vb->buffer.resource; } - } else { - for (unsigned i = 0; i < num_buffers; ++i) { - update_existing_vbo(ctx, i); - pipe_resource_reference(&ctx->vertex_buffers[i].buffer.resource, NULL); + if (vb->buffer.resource) { + struct zink_resource *res = zink_resource(vb->buffer.resource); + res->vbo_bind_mask |= BITFIELD_BIT(i); + res->vbo_bind_count++; + res->gfx_barrier |= VK_PIPELINE_STAGE_VERTEX_INPUT_BIT; + res->barrier_access[0] |= VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT; + update_res_bind_count(ctx, res, false, false); + ctx_vb->buffer_offset = vb->buffer_offset; + /* always barrier before possible rebind */ + zink_screen(ctx->base.screen)->buffer_barrier(ctx, res, VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT, + VK_PIPELINE_STAGE_VERTEX_INPUT_BIT); + zink_batch_resource_usage_set(&ctx->batch, res, false, true); + res->obj->unordered_read = false; + } else { + enabled_buffers &= ~BITFIELD_BIT(i); } } - for (unsigned i = 0; i < unbind_num_trailing_slots; i++) { + for (unsigned i = num_buffers; i < last_count; i++) { update_existing_vbo(ctx, i); pipe_resource_reference(&ctx->vertex_buffers[i].buffer.resource, NULL); } diff --git a/src/gallium/frontends/lavapipe/lvp_execute.c b/src/gallium/frontends/lavapipe/lvp_execute.c index cade927d3cc..c0733c44ccb 100644 --- a/src/gallium/frontends/lavapipe/lvp_execute.c +++ b/src/gallium/frontends/lavapipe/lvp_execute.c @@ -504,7 +504,7 @@ static void emit_state(struct rendering_state *state) } if (state->vb_dirty) { - cso_set_vertex_buffers(state->cso, state->num_vb, 0, false, state->vb); + cso_set_vertex_buffers(state->cso, state->num_vb, false, state->vb); state->vb_dirty = false; } diff --git a/src/gallium/frontends/nine/nine_state.c b/src/gallium/frontends/nine/nine_state.c index fb7caba7900..4e87d37d8eb 100644 --- a/src/gallium/frontends/nine/nine_state.c +++ b/src/gallium/frontends/nine/nine_state.c @@ -959,7 +959,6 @@ update_vertex_buffers(struct NineDevice9 *device) struct pipe_context *pipe = context->pipe; struct pipe_vertex_buffer vbuffer[PIPE_MAX_ATTRIBS]; unsigned vtxbuf_count; - unsigned trailing_count; unsigned mask, i, vtxbuf_i; mask = context->vtxbuf_mask | @@ -978,12 +977,10 @@ update_vertex_buffers(struct NineDevice9 *device) } } - trailing_count = (context->last_vtxbuf_count <= vtxbuf_count) ? 0 : - context->last_vtxbuf_count - vtxbuf_count; if (vtxbuf_count) - pipe->set_vertex_buffers(pipe, vtxbuf_count, trailing_count, false, vbuffer); + pipe->set_vertex_buffers(pipe, vtxbuf_count, false, vbuffer); else - pipe->set_vertex_buffers(pipe, 0, trailing_count, false, NULL); + pipe->set_vertex_buffers(pipe, 0, false, NULL); context->last_vtxbuf_count = vtxbuf_count; context->changed.vtxbuf = 0; @@ -2546,7 +2543,7 @@ CSMT_ITEM_NO_WAIT(nine_context_draw_indexed_primitive_from_vtxbuf_idxbuf, else info.index.user = user_ibuf; - context->pipe->set_vertex_buffers(context->pipe, 1, 0, false, vbuf); + context->pipe->set_vertex_buffers(context->pipe, 1, false, vbuf); context->changed.vtxbuf |= 1; context->pipe->draw_vbo(context->pipe, &info, 0, NULL, &draw, 1); @@ -3067,7 +3064,7 @@ nine_context_clear(struct NineDevice9 *device) pipe->set_sampler_views(pipe, PIPE_SHADER_FRAGMENT, 0, 0, NINE_MAX_SAMPLERS_PS, false, NULL); - pipe->set_vertex_buffers(pipe, 0, device->caps.MaxStreams, false, NULL); + pipe->set_vertex_buffers(pipe, 0, false, NULL); for (i = 0; i < ARRAY_SIZE(context->rt); ++i) nine_bind(&context->rt[i], NULL); @@ -3273,7 +3270,7 @@ update_vertex_buffers_sw(struct NineDevice9 *device, int dummy_vbo_stream, } vtxbuf_count = j; - pipe_sw->set_vertex_buffers(pipe_sw, vtxbuf_count, device->caps.MaxStreams-vtxbuf_count, true, vbuffer); + pipe_sw->set_vertex_buffers(pipe_sw, vtxbuf_count, true, vbuffer); nine_context_get_pipe_release(device); } @@ -3412,7 +3409,7 @@ nine_state_after_draw_sw(struct NineDevice9 *device) struct pipe_context *pipe_sw = device->pipe_sw; int i; - pipe_sw->set_vertex_buffers(pipe_sw, 0, device->caps.MaxStreams, false, NULL); + pipe_sw->set_vertex_buffers(pipe_sw, 0, false, NULL); for (i = 0; i < 4; i++) { if (sw_internal->transfers_so[i]) pipe->buffer_unmap(pipe, sw_internal->transfers_so[i]); diff --git a/src/gallium/include/pipe/p_context.h b/src/gallium/include/pipe/p_context.h index 802dda5c5c8..689622409d5 100644 --- a/src/gallium/include/pipe/p_context.h +++ b/src/gallium/include/pipe/p_context.h @@ -608,7 +608,6 @@ struct pipe_context { * Bind an array of vertex buffers to the specified slots. * * \param count number of consecutive vertex buffers to bind. - * \param unbind_num_trailing_slots unbind slots after the bound slots * \param take_ownership the caller holds buffer references and they * should be taken over by the callee. This means * that drivers shouldn't increment reference counts. @@ -616,7 +615,6 @@ struct pipe_context { */ void (*set_vertex_buffers)(struct pipe_context *, unsigned num_buffers, - unsigned unbind_num_trailing_slots, bool take_ownership, const struct pipe_vertex_buffer *); |