From 4f344db8b0fdb08cdcba00d714309f27e073edf8 Mon Sep 17 00:00:00 2001 From: Axel Davy Date: Sun, 6 Nov 2016 12:38:38 +0100 Subject: [PATCH] st/nine: Upload Managed buffers just before draw call using them Previously we were uploading Managed buffers at the next draw call after they were set dirty. This is not the expected behaviour. Instead upload just before draw call needing the content. Signed-off-by: Axel Davy --- src/gallium/state_trackers/nine/buffer9.c | 19 ++++--------------- src/gallium/state_trackers/nine/buffer9.h | 12 ++++++++++-- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/gallium/state_trackers/nine/buffer9.c b/src/gallium/state_trackers/nine/buffer9.c index 64c79359139..726408aed89 100644 --- a/src/gallium/state_trackers/nine/buffer9.c +++ b/src/gallium/state_trackers/nine/buffer9.c @@ -133,7 +133,6 @@ NineBuffer9_ctor( struct NineBuffer9 *This, u_box_1d(0, Size, &This->managed.dirty_box); list_inithead(&This->managed.list); list_inithead(&This->managed.list2); - list_add(&This->managed.list, &pParams->device->update_buffers); list_add(&This->managed.list2, &pParams->device->managed_buffers); } @@ -208,12 +207,8 @@ NineBuffer9_Lock( struct NineBuffer9 *This, assert(LIST_IS_EMPTY(&This->managed.list)); This->managed.dirty = TRUE; This->managed.dirty_box = box; - } else { + } else u_box_union_2d(&This->managed.dirty_box, &This->managed.dirty_box, &box); - /* Do not upload while we are locking, we'll add it back later */ - if (!LIST_IS_EMPTY(&This->managed.list)) - list_delinit(&This->managed.list); - } } *ppbData = (char *)This->managed.data + OffsetToLock; DBG("returning pointer %p\n", *ppbData); @@ -287,10 +282,7 @@ NineBuffer9_Unlock( struct NineBuffer9 *This ) pipe->transfer_unmap(pipe, This->maps[--(This->nmaps)]); } else { This->nmaps--; - /* TODO: Fix this to upload at the first draw call needing the data, - * instead of at the next draw call */ - if (!This->nmaps && This->managed.dirty && LIST_IS_EMPTY(&This->managed.list)) - list_add(&This->managed.list, &This->base.base.device->update_buffers); + BASEBUF_REGISTER_UPDATE(This); } return D3D_OK; } @@ -300,10 +292,7 @@ NineBuffer9_SetDirty( struct NineBuffer9 *This ) { assert(This->base.pool == D3DPOOL_MANAGED); - if (!This->managed.dirty) { - assert(LIST_IS_EMPTY(&This->managed.list)); - list_add(&This->managed.list, &This->base.base.device->update_buffers); - This->managed.dirty = TRUE; - } + This->managed.dirty = TRUE; u_box_1d(0, This->size, &This->managed.dirty_box); + BASEBUF_REGISTER_UPDATE(This); } diff --git a/src/gallium/state_trackers/nine/buffer9.h b/src/gallium/state_trackers/nine/buffer9.h index 0dd2fc64c0e..49b67a9eaf9 100644 --- a/src/gallium/state_trackers/nine/buffer9.h +++ b/src/gallium/state_trackers/nine/buffer9.h @@ -104,9 +104,11 @@ NineBindBufferToDevice( struct NineDevice9 *device, { struct NineBuffer9 *old = *slot; - (void)device; - if (buf) + if (buf) { + if ((buf->managed.dirty) && LIST_IS_EMPTY(&buf->managed.list)) + list_add(&buf->managed.list, &device->update_buffers); buf->bind_count++; + } if (old) old->bind_count--; @@ -116,4 +118,10 @@ NineBindBufferToDevice( struct NineDevice9 *device, void NineBuffer9_SetDirty( struct NineBuffer9 *This ); +#define BASEBUF_REGISTER_UPDATE(b) { \ + if ((b)->managed.dirty && (b)->bind_count) \ + if (LIST_IS_EMPTY(&(b)->managed.list)) \ + list_add(&(b)->managed.list, &(b)->base.base.device->update_buffers); \ + } + #endif /* _NINE_BUFFER9_H_ */ -- 2.11.0