gallium: use MAP_DIRECTLY to mean supression of DISCARD in buffer_subdata
authorMarek Olšák <marek.olsak@amd.com>
Wed, 3 Jul 2019 22:51:24 +0000 (18:51 -0400)
committerMarek Olšák <marek.olsak@amd.com>
Mon, 15 Jul 2019 18:58:23 +0000 (14:58 -0400)
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
src/gallium/auxiliary/util/u_transfer.c
src/gallium/drivers/r600/r600_buffer_common.c
src/gallium/drivers/radeonsi/si_buffer.c
src/gallium/drivers/virgl/virgl_resource.c
src/gallium/include/pipe/p_defines.h

index fc4489085640e03cca4ca62f9a6e7313fa362ede..8f5ed4a5a678018c32f3d5c02413199145929890 100644 (file)
@@ -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);
 
index 3089bcb1f340381f35d89b26b3380e8284063e8a..1ad47b00399aa53d5059e2568064074163aac080 100644 (file)
@@ -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);
index 047394a5297c46cc602ea414a08e935cb61d303d..04f80daec1d6ab86b7df8a61e63496ab786f89b1 100644 (file)
@@ -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;
 
index 614d00b4667177e9a13b7bd890f3ab8243225711..57b8aeea4866fd154600eb1d6476e43d628f1a83 100644 (file)
@@ -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;
 
index c8e0d23fe12d620c7bede9cfd5eec870aa3fb33c..c22a78a473158fbc9d94e0ef90baa1e18fd7b297 100644 (file)
@@ -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);
 
index d3afd4420462a513f6e85a95212dc001dcc6eb2c..d6e33ce9daa9462d8fb3ab92f9f5d87dfc47c26d 100644 (file)
@@ -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),