Mesa (master): mesa/gallium: add MESA_MAP_ONCE / PIPE_MAP_ONCE
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Tue Nov 17 10:15:17 UTC 2020
Module: Mesa
Branch: master
Commit: 68f152cb9a65ab20f03d5efb21d6f7ad3cb16e25
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=68f152cb9a65ab20f03d5efb21d6f7ad3cb16e25
Author: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer at amd.com>
Date: Thu Oct 22 15:46:08 2020 +0200
mesa/gallium: add MESA_MAP_ONCE / PIPE_MAP_ONCE
If set, this bit tells the driver that the buffer will only be
mapped once.
radeonsi uses it to disable its "never unmap buffers" optimisations.
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/3660
Reviewed-by: Marek Olšák <marek.olsak at amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7428>
---
src/gallium/drivers/radeonsi/si_buffer.c | 6 ++++++
src/gallium/include/pipe/p_defines.h | 5 +++++
src/mesa/main/dd.h | 3 +++
src/mesa/state_tracker/st_cb_bufferobjects.c | 2 ++
src/mesa/vbo/vbo_save_api.c | 3 ++-
5 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/src/gallium/drivers/radeonsi/si_buffer.c b/src/gallium/drivers/radeonsi/si_buffer.c
index f44f3fd2e32..463a9fe7088 100644
--- a/src/gallium/drivers/radeonsi/si_buffer.c
+++ b/src/gallium/drivers/radeonsi/si_buffer.c
@@ -388,6 +388,8 @@ static void *si_buffer_transfer_map(struct pipe_context *ctx, struct pipe_resour
*/
if (buf->b.is_user_ptr)
usage |= PIPE_MAP_PERSISTENT;
+ if (usage & PIPE_MAP_ONCE)
+ usage |= RADEON_MAP_TEMPORARY;
/* See if the buffer range being mapped has never been initialized,
* in which case it can be mapped unsynchronized. */
@@ -594,6 +596,10 @@ static void si_buffer_transfer_unmap(struct pipe_context *ctx, struct pipe_trans
if (transfer->usage & PIPE_MAP_WRITE && !(transfer->usage & PIPE_MAP_FLUSH_EXPLICIT))
si_buffer_do_flush_region(ctx, transfer, &transfer->box);
+ if (transfer->usage & (PIPE_MAP_ONCE | RADEON_MAP_TEMPORARY) &&
+ !stransfer->staging)
+ sctx->ws->buffer_unmap(si_resource(stransfer->b.b.resource)->buf);
+
si_resource_reference(&stransfer->staging, NULL);
assert(stransfer->b.staging == NULL); /* for threaded context only */
pipe_resource_reference(&transfer->resource, NULL);
diff --git a/src/gallium/include/pipe/p_defines.h b/src/gallium/include/pipe/p_defines.h
index efc5bec9740..38bc6fb3cfb 100644
--- a/src/gallium/include/pipe/p_defines.h
+++ b/src/gallium/include/pipe/p_defines.h
@@ -362,6 +362,11 @@ enum pipe_map_flags
*/
PIPE_MAP_STENCIL_ONLY = 1 << 17,
+ /**
+ * Mapping will be used only once (never remapped).
+ */
+ PIPE_MAP_ONCE = 1 << 18,
+
/**
* This and higher bits are reserved for private use by drivers. Drivers
* should use this as (PIPE_MAP_DRV_PRV << i).
diff --git a/src/mesa/main/dd.h b/src/mesa/main/dd.h
index eb3c14e64a9..506a18240cc 100644
--- a/src/mesa/main/dd.h
+++ b/src/mesa/main/dd.h
@@ -74,6 +74,9 @@ struct _mesa_index_buffer;
/* Mapping a buffer is allowed from any thread. */
#define MESA_MAP_THREAD_SAFE_BIT 0x8000
+/* This buffer will only be mapped/unmapped once */
+#define MESA_MAP_ONCE 0x10000
+
/**
* Device driver function table.
diff --git a/src/mesa/state_tracker/st_cb_bufferobjects.c b/src/mesa/state_tracker/st_cb_bufferobjects.c
index e7550ccf850..ad4a8381eb4 100644
--- a/src/mesa/state_tracker/st_cb_bufferobjects.c
+++ b/src/mesa/state_tracker/st_cb_bufferobjects.c
@@ -496,6 +496,8 @@ st_access_flags_to_transfer_flags(GLbitfield access, bool wholeBuffer)
flags |= PIPE_MAP_DONTBLOCK;
if (access & MESA_MAP_THREAD_SAFE_BIT)
flags |= PIPE_MAP_THREAD_SAFE;
+ if (access & MESA_MAP_ONCE)
+ flags |= PIPE_MAP_ONCE;
return flags;
}
diff --git a/src/mesa/vbo/vbo_save_api.c b/src/mesa/vbo/vbo_save_api.c
index 0203199b0a7..7540da53381 100644
--- a/src/mesa/vbo/vbo_save_api.c
+++ b/src/mesa/vbo/vbo_save_api.c
@@ -193,7 +193,8 @@ vbo_save_map_vertex_store(struct gl_context *ctx,
const GLbitfield access = (GL_MAP_WRITE_BIT |
GL_MAP_INVALIDATE_RANGE_BIT |
GL_MAP_UNSYNCHRONIZED_BIT |
- GL_MAP_FLUSH_EXPLICIT_BIT);
+ GL_MAP_FLUSH_EXPLICIT_BIT |
+ MESA_MAP_ONCE);
assert(vertex_store->bufferobj);
assert(!vertex_store->buffer_map); /* the buffer should not be mapped */
More information about the mesa-commit
mailing list