st/nine: Optimize DrawPrimitiveUp

Try to keep the same vertex buffer state when
having several consecutive DrawPrimitiveUp.

Signed-off-by: Axel Davy <davyaxel0@gmail.com>

Nicer DrawPrimUp opt patch

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9451>
This commit is contained in:
Axel Davy 2021-03-06 14:53:18 +01:00 committed by Marge Bot
parent 9168a37692
commit a2c3db34d1
2 changed files with 17 additions and 2 deletions

View File

@ -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);

View File

@ -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);