From: Marek Olšák <marek.ol...@amd.com> for radeonsi --- src/gallium/auxiliary/util/u_upload_mgr.c | 33 ++++++++++++++++++----- src/gallium/auxiliary/util/u_upload_mgr.h | 4 +++ 2 files changed, 31 insertions(+), 6 deletions(-)
diff --git a/src/gallium/auxiliary/util/u_upload_mgr.c b/src/gallium/auxiliary/util/u_upload_mgr.c index f703852be81..c2c0ba957e3 100644 --- a/src/gallium/auxiliary/util/u_upload_mgr.c +++ b/src/gallium/auxiliary/util/u_upload_mgr.c @@ -46,20 +46,21 @@ struct u_upload_mgr { enum pipe_resource_usage usage; unsigned flags; unsigned map_flags; /* Bitmask of PIPE_TRANSFER_* flags. */ boolean map_persistent; /* If persistent mappings are supported. */ struct pipe_resource *buffer; /* Upload buffer. */ struct pipe_transfer *transfer; /* Transfer object for the upload buffer. */ uint8_t *map; /* Pointer to the mapped upload buffer. */ unsigned offset; /* Aligned offset to the upload buffer, pointing * at the first unused byte. */ + unsigned flushed_size; /* Size we have flushed by transfer_flush_region. */ }; struct u_upload_mgr * u_upload_create(struct pipe_context *pipe, unsigned default_size, unsigned bind, enum pipe_resource_usage usage, unsigned flags) { struct u_upload_mgr *upload = CALLOC_STRUCT(u_upload_mgr); if (!upload) return NULL; @@ -95,41 +96,61 @@ u_upload_create_default(struct pipe_context *pipe) return u_upload_create(pipe, 1024 * 1024, PIPE_BIND_VERTEX_BUFFER | PIPE_BIND_INDEX_BUFFER | PIPE_BIND_CONSTANT_BUFFER, PIPE_USAGE_STREAM, 0); } struct u_upload_mgr * u_upload_clone(struct pipe_context *pipe, struct u_upload_mgr *upload) { - return u_upload_create(pipe, upload->default_size, upload->bind, - upload->usage, upload->flags); + struct u_upload_mgr *result = u_upload_create(pipe, upload->default_size, + upload->bind, upload->usage, + upload->flags); + if (upload->map_persistent && + upload->map_flags & PIPE_TRANSFER_FLUSH_EXPLICIT) + u_upload_enable_flush_explicit(result); + + return result; +} + +void +u_upload_enable_flush_explicit(struct u_upload_mgr *upload) +{ + assert(upload->map_persistent); + upload->map_flags &= ~PIPE_TRANSFER_COHERENT; + upload->map_flags |= PIPE_TRANSFER_FLUSH_EXPLICIT; } static void upload_unmap_internal(struct u_upload_mgr *upload, boolean destroying) { - if (!destroying && upload->map_persistent) + if (!upload->transfer) return; - if (upload->transfer) { + if (upload->map_flags & PIPE_TRANSFER_FLUSH_EXPLICIT) { struct pipe_box *box = &upload->transfer->box; + unsigned flush_offset = box->x + upload->flushed_size; - if (!upload->map_persistent && (int) upload->offset > box->x) { + if (upload->offset > flush_offset) { pipe_buffer_flush_mapped_range(upload->pipe, upload->transfer, - box->x, upload->offset - box->x); + flush_offset, + upload->offset - flush_offset); + upload->flushed_size = upload->offset; } + } + if (destroying || !upload->map_persistent) { pipe_transfer_unmap(upload->pipe, upload->transfer); upload->transfer = NULL; upload->map = NULL; + upload->flushed_size = 0; } } void u_upload_unmap(struct u_upload_mgr *upload) { upload_unmap_internal(upload, FALSE); } diff --git a/src/gallium/auxiliary/util/u_upload_mgr.h b/src/gallium/auxiliary/util/u_upload_mgr.h index a66b7365565..80832016272 100644 --- a/src/gallium/auxiliary/util/u_upload_mgr.h +++ b/src/gallium/auxiliary/util/u_upload_mgr.h @@ -62,20 +62,24 @@ u_upload_create(struct pipe_context *pipe, unsigned default_size, struct u_upload_mgr * u_upload_create_default(struct pipe_context *pipe); /** * Create an uploader with identical parameters as another one, but using * the given pipe_context instead. */ struct u_upload_mgr * u_upload_clone(struct pipe_context *pipe, struct u_upload_mgr *upload); +/** Whether to use FLUSH_EXPLICIT with persistent mappings. */ +void +u_upload_enable_flush_explicit(struct u_upload_mgr *upload); + /** * Destroy the upload manager. */ void u_upload_destroy( struct u_upload_mgr *upload ); /** * Unmap upload buffer * * \param upload Upload manager * -- 2.17.1 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev