From a2c3db34d1596443891e7b4fe3bb90d4302bb6e3 Mon Sep 17 00:00:00 2001 From: Axel Davy Date: Sat, 6 Mar 2021 14:53:18 +0100 Subject: [PATCH] st/nine: Optimize DrawPrimitiveUp Try to keep the same vertex buffer state when having several consecutive DrawPrimitiveUp. Signed-off-by: Axel Davy Nicer DrawPrimUp opt patch Part-of: --- src/gallium/frontends/nine/device9.c | 12 ++++++++++-- src/gallium/frontends/nine/nine_state.c | 7 +++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/gallium/frontends/nine/device9.c b/src/gallium/frontends/nine/device9.c index d224b07..0a28440 100644 --- a/src/gallium/frontends/nine/device9.c +++ b/src/gallium/frontends/nine/device9.c @@ -2966,6 +2966,7 @@ NineDevice9_DrawPrimitiveUP( struct NineDevice9 *This, { struct pipe_resource *resource = NULL; unsigned buffer_offset; + unsigned StartVertex = 0; DBG("iface %p, PrimitiveType %u, PrimitiveCount %u, data %p, stride %u\n", This, PrimitiveType, PrimitiveCount, @@ -2978,18 +2979,25 @@ NineDevice9_DrawPrimitiveUP( struct NineDevice9 *This, u_upload_data(This->vertex_uploader, 0, (prim_count_to_vertex_count(PrimitiveType, PrimitiveCount)) * VertexStreamZeroStride, - 64, + 1, pVertexStreamZeroData, &buffer_offset, &resource); u_upload_unmap(This->vertex_uploader); + /* Optimization to skip changing the bound vertex buffer data + * for consecutive DrawPrimitiveUp with identical VertexStreamZeroStride */ + if (VertexStreamZeroStride > 0) { + StartVertex = buffer_offset / VertexStreamZeroStride; + buffer_offset -= StartVertex * VertexStreamZeroStride; + } + nine_context_set_stream_source_apply(This, 0, resource, buffer_offset, VertexStreamZeroStride); pipe_resource_reference(&resource, NULL); NineBeforeDraw(This); - nine_context_draw_primitive(This, PrimitiveType, 0, PrimitiveCount); + nine_context_draw_primitive(This, PrimitiveType, StartVertex, PrimitiveCount); NineAfterDraw(This); NineDevice9_PauseRecording(This); diff --git a/src/gallium/frontends/nine/nine_state.c b/src/gallium/frontends/nine/nine_state.c index 55df570..113f41e 100644 --- a/src/gallium/frontends/nine/nine_state.c +++ b/src/gallium/frontends/nine/nine_state.c @@ -1545,6 +1545,13 @@ CSMT_ITEM_NO_WAIT(nine_context_set_stream_source_apply, struct nine_context *context = &device->context; const unsigned i = StreamNumber; + /* For normal draws, these tests are useless, + * but not for *Up draws */ + if (context->vtxbuf[i].buffer.resource == res && + context->vtxbuf[i].buffer_offset == OffsetInBytes && + context->vtxbuf[i].stride == Stride) + return; + context->vtxbuf[i].stride = Stride; context->vtxbuf[i].buffer_offset = OffsetInBytes; pipe_resource_reference(&context->vtxbuf[i].buffer.resource, res); -- 2.7.4