gallium: add PIPE_CAP_MAP_UNSYNCHRONIZED_THREAD_SAFE for glthread
authorMarek Olšák <marek.olsak@amd.com>
Fri, 6 Mar 2020 02:49:30 +0000 (21:49 -0500)
committerMarge Bot <eric+marge@anholt.net>
Mon, 27 Apr 2020 11:56:06 +0000 (11:56 +0000)
and add radeonsi support.

Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4758>

src/gallium/auxiliary/util/u_screen.c
src/gallium/docs/source/screen.rst
src/gallium/drivers/radeonsi/si_buffer.c
src/gallium/drivers/radeonsi/si_get.c
src/gallium/include/pipe/p_defines.h

index b3484beef2546c932ae432092b5111645035bb2b..54ebe77420dc0642c4cb41f94e2388dec8929f20 100644 (file)
@@ -422,6 +422,7 @@ u_pipe_screen_get_param_defaults(struct pipe_screen *pscreen,
 
    case PIPE_CAP_VIEWPORT_TRANSFORM_LOWERED:
    case PIPE_CAP_PSIZ_CLAMPED:
+   case PIPE_CAP_MAP_UNSYNCHRONIZED_THREAD_SAFE:
       return 0;
 
    case PIPE_CAP_GL_BEGIN_END_BUFFER_SIZE:
index a16e4994903ae4f37b738c6965a3f7f71733db72..3a9ccb4246b392ae823b8bf88bbf32353ecbbe85 100644 (file)
@@ -576,6 +576,7 @@ The integer capabilities:
 * ``PIPE_CAP_VIEWPORT_SWIZZLE``: Whether pipe_viewport_state::swizzle can be used to specify pre-clipping swizzling of coordinates (see GL_NV_viewport_swizzle).
 * ``PIPE_CAP_SYSTEM_SVM``: True if all application memory can be shared with the GPU without explicit mapping.
 * ``PIPE_CAP_VIEWPORT_MASK``: Whether ``TGSI_SEMANTIC_VIEWPORT_MASK`` and ``TGSI_PROPERTY_LAYER_VIEWPORT_RELATIVE`` are supported (see GL_NV_viewport_array2).
+* ``PIPE_CAP_MAP_UNSYNCHRONIZED_THREAD_SAFE``: Whether mapping a buffer as unsynchronized from any thread is safe.
 
 .. _pipe_capf:
 
index eb71636d3462477bcbf9a928e5b80ca5187fd8fd..6b58aebee2d78aed7db9e8aceea4682d4e78774d 100644 (file)
@@ -324,7 +324,9 @@ static void *si_buffer_get_transfer(struct pipe_context *ctx, struct pipe_resour
    struct si_context *sctx = (struct si_context *)ctx;
    struct si_transfer *transfer;
 
-   if (usage & TC_TRANSFER_MAP_THREADED_UNSYNC)
+   if (usage & PIPE_TRANSFER_THREAD_SAFE)
+      transfer = malloc(sizeof(*transfer));
+   else if (usage & TC_TRANSFER_MAP_THREADED_UNSYNC)
       transfer = slab_alloc(&sctx->pool_transfers_unsync);
    else
       transfer = slab_alloc(&sctx->pool_transfers);
@@ -461,7 +463,7 @@ static void *si_buffer_transfer_map(struct pipe_context *ctx, struct pipe_resour
             (buf->flags & RADEON_FLAG_SPARSE)) {
       struct si_resource *staging;
 
-      assert(!(usage & TC_TRANSFER_MAP_THREADED_UNSYNC));
+      assert(!(usage & (TC_TRANSFER_MAP_THREADED_UNSYNC | PIPE_TRANSFER_THREAD_SAFE)));
       staging = si_resource(pipe_buffer_create(ctx->screen, 0, PIPE_USAGE_STAGING,
                                                box->width + (box->x % SI_MAP_BUFFER_ALIGNMENT)));
       if (staging) {
@@ -574,9 +576,14 @@ static void si_buffer_transfer_unmap(struct pipe_context *ctx, struct pipe_trans
    assert(stransfer->b.staging == NULL); /* for threaded context only */
    pipe_resource_reference(&transfer->resource, NULL);
 
-   /* Don't use pool_transfers_unsync. We are always in the driver
-    * thread. */
-   slab_free(&sctx->pool_transfers, transfer);
+   if (transfer->usage & PIPE_TRANSFER_THREAD_SAFE) {
+      free(transfer);
+   } else {
+      /* Don't use pool_transfers_unsync. We are always in the driver
+       * thread. Freeing an object into a different pool is allowed.
+       */
+      slab_free(&sctx->pool_transfers, transfer);
+   }
 }
 
 static void si_buffer_subdata(struct pipe_context *ctx, struct pipe_resource *buffer,
index 0ec0d025b57b5c30d5070c3886b707e4746bba9d..8de60018627d95f6d0dbe455773d649d4a552fb6 100644 (file)
@@ -161,6 +161,7 @@ static int si_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
    case PIPE_CAP_GL_SPIRV:
    case PIPE_CAP_DRAW_INFO_START_WITH_USER_INDICES:
    case PIPE_CAP_ALPHA_TO_COVERAGE_DITHER_CONTROL:
+   case PIPE_CAP_MAP_UNSYNCHRONIZED_THREAD_SAFE:
       return 1;
 
    case PIPE_CAP_QUERY_SO_OVERFLOW:
index a3a53735b395cd3d87ef2dc6764f347f99e7d5df..13e124bf72893e7a941c458b72401d6b56713dc9 100644 (file)
@@ -345,6 +345,13 @@ enum pipe_transfer_usage
     */
    PIPE_TRANSFER_COHERENT = (1 << 14),
 
+   /**
+    * Map a resource in a thread-safe manner, because the calling thread can
+    * be any thread. It can only be used if both WRITE and UNSYNCHRONIZED are
+    * set.
+    */
+   PIPE_TRANSFER_THREAD_SAFE = 1 << 15,
+
    /**
     * This and higher bits are reserved for private use by drivers. Drivers
     * should use this as (PIPE_TRANSFER_DRV_PRV << i).
@@ -938,6 +945,7 @@ enum pipe_cap
    PIPE_CAP_SYSTEM_SVM,
    PIPE_CAP_VIEWPORT_MASK,
    PIPE_CAP_ALPHA_TO_COVERAGE_DITHER_CONTROL,
+   PIPE_CAP_MAP_UNSYNCHRONIZED_THREAD_SAFE,
 };
 
 /**