Mesa (master): st/nine: Optimize DrawPrimitiveUp
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Sat Mar 13 21:39:03 UTC 2021
Module: Mesa
Branch: master
Commit: a2c3db34d1596443891e7b4fe3bb90d4302bb6e3
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=a2c3db34d1596443891e7b4fe3bb90d4302bb6e3
Author: Axel Davy <davyaxel0 at gmail.com>
Date: Sat Mar 6 14:53:18 2021 +0100
st/nine: Optimize DrawPrimitiveUp
Try to keep the same vertex buffer state when
having several consecutive DrawPrimitiveUp.
Signed-off-by: Axel Davy <davyaxel0 at gmail.com>
Nicer DrawPrimUp opt patch
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9451>
---
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 d224b072f51..0a28440b788 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 55df570d31c..113f41e8649 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);
More information about the mesa-commit
mailing list