svga: Support ARB_buffer_storage
authorThomas Hellstrom <thellstrom@vmware.com>
Fri, 5 Apr 2019 15:07:49 +0000 (17:07 +0200)
committerThomas Hellstrom <thellstrom@vmware.com>
Thu, 20 Jun 2019 07:30:22 +0000 (09:30 +0200)
This basically boils down to supporting persistent and coherent buffer
storage.
We chose to use coherent buffer storage for all persistent buffers
even if it's not explicitly specified, since using glMemoryBarrier to
obtain coherency would be particularly expensive in our driver stack,
and require a lot of additional bookkeeping.

Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
src/gallium/drivers/svga/svga_context.c
src/gallium/drivers/svga/svga_resource_buffer.c
src/gallium/drivers/svga/svga_resource_buffer_upload.c
src/gallium/drivers/svga/svga_resource_texture.c
src/gallium/drivers/svga/svga_screen.c

index 57c0dc49957db5422ab738173f50b736fceb8c11..104a551356d02ced79ce9cde129c76fb6c49eb19 100644 (file)
@@ -148,12 +148,16 @@ svga_context_create(struct pipe_screen *screen, void *priv, unsigned flags)
    if (!svga->pipe.stream_uploader)
       goto cleanup;
 
+   u_upload_disable_persistent(svga->pipe.stream_uploader);
+
    svga->pipe.const_uploader = u_upload_create(&svga->pipe, 128 * 1024,
                                                PIPE_BIND_CONSTANT_BUFFER,
                                                PIPE_USAGE_STREAM, 0);
    if (!svga->pipe.const_uploader)
       goto cleanup;
 
+   u_upload_disable_persistent(svga->pipe.const_uploader);
+
    svga->swc = svgascreen->sws->context_create(svgascreen->sws);
    if (!svga->swc)
       goto cleanup;
@@ -236,6 +240,8 @@ svga_context_create(struct pipe_screen *screen, void *priv, unsigned flags)
    if (!svga->const0_upload)
       goto cleanup;
 
+   u_upload_disable_persistent(svga->const0_upload);
+
    if (!svga_texture_transfer_map_upload_create(svga))
       goto cleanup;
 
index 234d825d5a29a9d51f36828fe9a9ed4cce7cf782..712fffc83d392e43effff93d3b4ae2ba33b864da 100644 (file)
@@ -71,6 +71,9 @@ svga_buffer_needs_hw_storage(const struct svga_screen *ss,
          bind_mask |= PIPE_BIND_CONSTANT_BUFFER;
    }
 
+   if (template->flags & PIPE_RESOURCE_FLAG_MAP_PERSISTENT)
+      return TRUE;
+
    return !!(template->bind & bind_mask);
 }
 
@@ -126,7 +129,8 @@ svga_buffer_transfer_map(struct pipe_context *pipe,
       pipe_resource_reference(&sbuf->translated_indices.buffer, NULL);
    }
 
-   if ((usage & PIPE_TRANSFER_READ) && sbuf->dirty) {
+   if ((usage & PIPE_TRANSFER_READ) && sbuf->dirty &&
+       !sbuf->key.coherent && !svga->swc->force_coherent) {
       enum pipe_error ret;
 
       /* Host-side buffers can only be dirtied with vgpu10 features
@@ -160,7 +164,8 @@ svga_buffer_transfer_map(struct pipe_context *pipe,
    }
 
    if (usage & PIPE_TRANSFER_WRITE) {
-      if (usage & PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE) {
+      if ((usage & PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE) &&
+          !(resource->flags & PIPE_RESOURCE_FLAG_MAP_PERSISTENT)) {
          /*
           * Flush any pending primitives, finish writing any pending DMA
           * commands, and tell the host to discard the buffer contents on
@@ -317,7 +322,7 @@ svga_buffer_transfer_flush_region(struct pipe_context *pipe,
    assert(transfer->usage & PIPE_TRANSFER_WRITE);
    assert(transfer->usage & PIPE_TRANSFER_FLUSH_EXPLICIT);
 
-   if (!svga->swc->force_coherent || sbuf->swbuf) {
+   if (!(svga->swc->force_coherent || sbuf->key.coherent) || sbuf->swbuf) {
       mtx_lock(&ss->swc_mutex);
       svga_buffer_add_range(sbuf, offset, offset + length);
       mtx_unlock(&ss->swc_mutex);
@@ -361,7 +366,7 @@ svga_buffer_transfer_unmap(struct pipe_context *pipe,
 
          sbuf->dma.flags.discard = TRUE;
 
-         if (!svga->swc->force_coherent || sbuf->swbuf)
+         if (!(svga->swc->force_coherent || sbuf->key.coherent) || sbuf->swbuf)
             svga_buffer_add_range(sbuf, 0, sbuf->b.b.width0);
       }
    }
index 64f75231a656657a7f6a31410870c0a6a3b7f5e9..1bb7431abf4e995d838bf1d58e75044cb8c31938 100644 (file)
@@ -183,6 +183,14 @@ svga_buffer_create_host_surface(struct svga_screen *ss,
          sbuf->key.flags = SVGA3D_SURFACE_TRANSFER_FROM_BUFFER;
       }
 
+      if (sbuf->b.b.flags & PIPE_RESOURCE_FLAG_MAP_PERSISTENT) {
+         /* This surface can be mapped persistently. We use
+          * coherent memory to avoid implementing memory barriers for
+          * persistent non-coherent memory for now.
+          */
+         sbuf->key.coherent = 1;
+      }
+
       sbuf->key.size.width = sbuf->b.b.width0;
       sbuf->key.size.height = 1;
       sbuf->key.size.depth = 1;
@@ -448,7 +456,7 @@ svga_buffer_upload_gb_command(struct svga_context *svga,
    struct pipe_resource *dummy;
    unsigned i;
 
-   if (swc->force_coherent)
+   if (swc->force_coherent || sbuf->key.coherent)
       return PIPE_OK;
 
    assert(svga_have_gb_objects(svga));
@@ -648,7 +656,8 @@ svga_buffer_upload_flush(struct svga_context *svga, struct svga_buffer *sbuf)
    unsigned i;
    struct pipe_resource *dummy;
 
-   if (!sbuf->dma.pending || svga->swc->force_coherent) {
+   if (!sbuf->dma.pending || svga->swc->force_coherent ||
+       sbuf->key.coherent) {
       //debug_printf("no dma pending on buffer\n");
       return;
    }
@@ -875,7 +884,7 @@ svga_buffer_update_hw(struct svga_context *svga, struct svga_buffer *sbuf,
          memcpy((uint8_t *) map + start, (uint8_t *) sbuf->swbuf + start, len);
       }
 
-      if (svga->swc->force_coherent)
+      if (svga->swc->force_coherent || sbuf->key.coherent)
          sbuf->map.num_ranges = 0;
 
       svga_buffer_hw_storage_unmap(svga, sbuf);
@@ -1036,7 +1045,7 @@ svga_buffer_handle(struct svga_context *svga, struct pipe_resource *buf,
    }
 
    assert(sbuf->handle);
-   if (svga->swc->force_coherent)
+   if (svga->swc->force_coherent || sbuf->key.coherent)
       return sbuf->handle;
 
    if (sbuf->map.num_ranges) {
index 0b872da3ed218fe5f2cc3de88ed93e9f6ada4340..bfedbee7a488af813af190ed1d50903119f5f820 100644 (file)
@@ -1354,6 +1354,9 @@ svga_texture_transfer_map_upload_create(struct svga_context *svga)
 {
    svga->tex_upload = u_upload_create(&svga->pipe, TEX_UPLOAD_DEFAULT_SIZE,
                                       PIPE_BIND_CUSTOM, PIPE_USAGE_STAGING, 0);
+   if (svga->tex_upload)
+      u_upload_disable_persistent(svga->tex_upload);
+
    return svga->tex_upload != NULL;
 }
 
index 5300fada9ff05ac5596e0301c4fe7a4bb3fca281..c76d77f1bc24715b67af9580a0d53463c25c56a4 100644 (file)
@@ -351,6 +351,8 @@ svga_get_param(struct pipe_screen *screen, enum pipe_cap param)
       return sws->have_sm4_1 ? 1 : 0; /* only single-channel textures */
    case PIPE_CAP_MAX_VARYINGS:
       return sws->have_vgpu10 ? VGPU10_MAX_FS_INPUTS : 10;
+   case PIPE_CAP_BUFFER_MAP_PERSISTENT_COHERENT:
+      return sws->have_coherent;
 
    /* Unsupported features */
    case PIPE_CAP_TEXTURE_MIRROR_CLAMP:
@@ -366,7 +368,6 @@ svga_get_param(struct pipe_screen *screen, enum pipe_cap param)
    case PIPE_CAP_QUERY_PIPELINE_STATISTICS:
    case PIPE_CAP_TGSI_VS_LAYER_VIEWPORT:
    case PIPE_CAP_TEXTURE_GATHER_SM5:
-   case PIPE_CAP_BUFFER_MAP_PERSISTENT_COHERENT:
    case PIPE_CAP_TEXTURE_GATHER_OFFSETS:
    case PIPE_CAP_TGSI_VS_WINDOW_SPACE_POSITION:
    case PIPE_CAP_DRAW_INDIRECT: