Mesa (master): gallium: use MAP_DIRECTLY to mean supression of DISCARD in buffer_subdata

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Jul 15 18:58:57 UTC 2019


Module: Mesa
Branch: master
Commit: fc4302d1dfe4fe724df250d0de1fcf0f60953c99
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=fc4302d1dfe4fe724df250d0de1fcf0f60953c99

Author: Marek Olšák <marek.olsak at amd.com>
Date:   Wed Jul  3 18:51:24 2019 -0400

gallium: use MAP_DIRECTLY to mean supression of DISCARD in buffer_subdata

This is needed to fix an issue with OpenGL when a buffer is mapped and
BufferSubData is called. In this case, we can't invalidate the buffer range.

---

 src/gallium/auxiliary/util/u_threaded_context.c |  7 +++++--
 src/gallium/auxiliary/util/u_transfer.c         | 14 +++++++++-----
 src/gallium/drivers/r600/r600_buffer_common.c   | 11 ++++++-----
 src/gallium/drivers/radeonsi/si_buffer.c        | 11 ++++++-----
 src/gallium/drivers/virgl/virgl_resource.c      | 10 ++++++----
 src/gallium/include/pipe/p_defines.h            |  2 ++
 6 files changed, 34 insertions(+), 21 deletions(-)

diff --git a/src/gallium/auxiliary/util/u_threaded_context.c b/src/gallium/auxiliary/util/u_threaded_context.c
index fc448908564..8f5ed4a5a67 100644
--- a/src/gallium/auxiliary/util/u_threaded_context.c
+++ b/src/gallium/auxiliary/util/u_threaded_context.c
@@ -1630,8 +1630,11 @@ tc_buffer_subdata(struct pipe_context *_pipe,
    if (!size)
       return;
 
-   usage |= PIPE_TRANSFER_WRITE |
-            PIPE_TRANSFER_DISCARD_RANGE;
+   usage |= PIPE_TRANSFER_WRITE;
+
+   /* PIPE_TRANSFER_MAP_DIRECTLY supresses implicit DISCARD_RANGE. */
+   if (!(usage & PIPE_TRANSFER_MAP_DIRECTLY))
+      usage |= PIPE_TRANSFER_DISCARD_RANGE;
 
    usage = tc_improve_map_buffer_flags(tc, tres, usage, offset, size);
 
diff --git a/src/gallium/auxiliary/util/u_transfer.c b/src/gallium/auxiliary/util/u_transfer.c
index 3089bcb1f34..1ad47b00399 100644
--- a/src/gallium/auxiliary/util/u_transfer.c
+++ b/src/gallium/auxiliary/util/u_transfer.c
@@ -18,11 +18,15 @@ void u_default_buffer_subdata(struct pipe_context *pipe,
    /* the write flag is implicit by the nature of buffer_subdata */
    usage |= PIPE_TRANSFER_WRITE;
 
-   /* buffer_subdata implicitly discards the rewritten buffer range */
-   if (offset == 0 && size == resource->width0) {
-      usage |= PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE;
-   } else {
-      usage |= PIPE_TRANSFER_DISCARD_RANGE;
+   /* buffer_subdata implicitly discards the rewritten buffer range.
+    * PIPE_TRANSFER_MAP_DIRECTLY supresses that.
+    */
+   if (!(usage & PIPE_TRANSFER_MAP_DIRECTLY)) {
+      if (offset == 0 && size == resource->width0) {
+         usage |= PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE;
+      } else {
+         usage |= PIPE_TRANSFER_DISCARD_RANGE;
+      }
    }
 
    u_box_1d(offset, size, &box);
diff --git a/src/gallium/drivers/r600/r600_buffer_common.c b/src/gallium/drivers/r600/r600_buffer_common.c
index 047394a5297..04f80daec1d 100644
--- a/src/gallium/drivers/r600/r600_buffer_common.c
+++ b/src/gallium/drivers/r600/r600_buffer_common.c
@@ -545,12 +545,13 @@ void r600_buffer_subdata(struct pipe_context *ctx,
 	struct pipe_box box;
 	uint8_t *map = NULL;
 
+	usage |= PIPE_TRANSFER_WRITE;
+
+	if (!(usage & PIPE_TRANSFER_MAP_DIRECTLY))
+		usage |= PIPE_TRANSFER_DISCARD_RANGE;
+
 	u_box_1d(offset, size, &box);
-	map = r600_buffer_transfer_map(ctx, buffer, 0,
-				       PIPE_TRANSFER_WRITE |
-				       PIPE_TRANSFER_DISCARD_RANGE |
-				       usage,
-				       &box, &transfer);
+	map = r600_buffer_transfer_map(ctx, buffer, 0, usage, &box, &transfer);
 	if (!map)
 		return;
 
diff --git a/src/gallium/drivers/radeonsi/si_buffer.c b/src/gallium/drivers/radeonsi/si_buffer.c
index 614d00b4667..57b8aeea486 100644
--- a/src/gallium/drivers/radeonsi/si_buffer.c
+++ b/src/gallium/drivers/radeonsi/si_buffer.c
@@ -637,12 +637,13 @@ static void si_buffer_subdata(struct pipe_context *ctx,
 	struct pipe_box box;
 	uint8_t *map = NULL;
 
+	usage |= PIPE_TRANSFER_WRITE;
+
+	if (!(usage & PIPE_TRANSFER_MAP_DIRECTLY))
+		usage |= PIPE_TRANSFER_DISCARD_RANGE;
+
 	u_box_1d(offset, size, &box);
-	map = si_buffer_transfer_map(ctx, buffer, 0,
-				       PIPE_TRANSFER_WRITE |
-				       PIPE_TRANSFER_DISCARD_RANGE |
-				       usage,
-				       &box, &transfer);
+	map = si_buffer_transfer_map(ctx, buffer, 0, usage, &box, &transfer);
 	if (!map)
 		return;
 
diff --git a/src/gallium/drivers/virgl/virgl_resource.c b/src/gallium/drivers/virgl/virgl_resource.c
index c8e0d23fe12..c22a78a4731 100644
--- a/src/gallium/drivers/virgl/virgl_resource.c
+++ b/src/gallium/drivers/virgl/virgl_resource.c
@@ -588,10 +588,12 @@ static void virgl_buffer_subdata(struct pipe_context *pipe,
    /* the write flag is implicit by the nature of buffer_subdata */
    usage |= PIPE_TRANSFER_WRITE;
 
-   if (offset == 0 && size == resource->width0)
-      usage |= PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE;
-   else
-      usage |= PIPE_TRANSFER_DISCARD_RANGE;
+   if (!(usage & PIPE_TRANSFER_MAP_DIRECTLY)) {
+      if (offset == 0 && size == resource->width0)
+         usage |= PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE;
+      else
+         usage |= PIPE_TRANSFER_DISCARD_RANGE;
+   }
 
    u_box_1d(offset, size, &box);
 
diff --git a/src/gallium/include/pipe/p_defines.h b/src/gallium/include/pipe/p_defines.h
index d3afd442046..d6e33ce9daa 100644
--- a/src/gallium/include/pipe/p_defines.h
+++ b/src/gallium/include/pipe/p_defines.h
@@ -261,6 +261,8 @@ enum pipe_transfer_usage
     * E.g. the state tracker could have a simpler path which maps textures and
     * does read/modify/write cycles on them directly, and a more complicated
     * path which uses minimal read and write transfers.
+    *
+    * This flag supresses implicit "DISCARD" for buffer_subdata.
     */
    PIPE_TRANSFER_MAP_DIRECTLY = (1 << 2),
 




More information about the mesa-commit mailing list