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

Author: Mike Blumenkrantz <[email protected]>
Date:   Thu Aug 13 10:53:25 2020 -0400

zink: track persistent, non-coherent, writable transfer map count for resources

these require explicit memory flushes before being submitted to a batch

Reviewed-by: Erik Faye-Lund <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8942>

---

 src/gallium/drivers/zink/zink_batch.c    | 4 ++++
 src/gallium/drivers/zink/zink_batch.h    | 1 +
 src/gallium/drivers/zink/zink_context.c  | 1 +
 src/gallium/drivers/zink/zink_resource.c | 4 ++++
 src/gallium/drivers/zink/zink_resource.h | 1 +
 5 files changed, 11 insertions(+)

diff --git a/src/gallium/drivers/zink/zink_batch.c 
b/src/gallium/drivers/zink/zink_batch.c
index 1ee394fa427..0ade85d13d1 100644
--- a/src/gallium/drivers/zink/zink_batch.c
+++ b/src/gallium/drivers/zink/zink_batch.c
@@ -55,6 +55,7 @@ zink_batch_release(struct zink_screen *screen, struct 
zink_batch *batch)
       vkDestroySampler(screen->dev, *samp, NULL);
    }
    util_dynarray_clear(&batch->zombie_samplers);
+   util_dynarray_clear(&batch->persistent_resources);
 }
 
 static void
@@ -161,6 +162,9 @@ zink_batch_reference_resource_rw(struct zink_batch *batch, 
struct zink_resource
       if (stencil)
          pipe_reference(NULL, &stencil->base.reference);
    }
+   /* multiple array entries are fine */
+   if (res->persistent_maps)
+      util_dynarray_append(&batch->persistent_resources, struct 
zink_resource*, res);
    /* the batch_uses value for this batch is guaranteed to not be in use now 
because
     * reset_batch() waits on the fence and removes access before resetting
     */
diff --git a/src/gallium/drivers/zink/zink_batch.h 
b/src/gallium/drivers/zink/zink_batch.h
index 5b3577d2023..b08ec4062bb 100644
--- a/src/gallium/drivers/zink/zink_batch.h
+++ b/src/gallium/drivers/zink/zink_batch.h
@@ -56,6 +56,7 @@ struct zink_batch {
    struct set *sampler_views;
    struct set *surfaces;
 
+   struct util_dynarray persistent_resources;
    struct util_dynarray zombie_samplers;
 
    struct set *active_queries; /* zink_query objects which were active at some 
point in this batch */
diff --git a/src/gallium/drivers/zink/zink_context.c 
b/src/gallium/drivers/zink/zink_context.c
index 43625fe88cc..2e7f9ad3ce1 100644
--- a/src/gallium/drivers/zink/zink_context.c
+++ b/src/gallium/drivers/zink/zink_context.c
@@ -1618,6 +1618,7 @@ init_batch(struct zink_context *ctx, struct zink_batch 
*batch, unsigned idx)
       return false;
 
    util_dynarray_init(&batch->zombie_samplers, NULL);
+   util_dynarray_init(&batch->persistent_resources, NULL);
 
    if (vkCreateDescriptorPool(screen->dev, &dpci, 0,
                               &batch->descpool) != VK_SUCCESS)
diff --git a/src/gallium/drivers/zink/zink_resource.c 
b/src/gallium/drivers/zink/zink_resource.c
index 2fdf275cfeb..85807cc958e 100644
--- a/src/gallium/drivers/zink/zink_resource.c
+++ b/src/gallium/drivers/zink/zink_resource.c
@@ -665,6 +665,8 @@ zink_transfer_map(struct pipe_context *pctx,
          ptr = ((uint8_t *)ptr) + offset;
       }
    }
+   if ((usage & PIPE_MAP_PERSISTENT) && !(usage & PIPE_MAP_COHERENT))
+      res->persistent_maps++;
 
    *transfer = &trans->base;
    return ptr;
@@ -696,6 +698,8 @@ zink_transfer_unmap(struct pipe_context *pctx,
       pipe_resource_reference(&trans->staging_res, NULL);
    } else
       vkUnmapMemory(screen->dev, res->mem);
+   if ((trans->base.usage & PIPE_MAP_PERSISTENT) && !(trans->base.usage & 
PIPE_MAP_COHERENT))
+      res->persistent_maps--;
 
    pipe_resource_reference(&trans->base.resource, NULL);
    slab_free(&ctx->transfer_pool, ptrans);
diff --git a/src/gallium/drivers/zink/zink_resource.h 
b/src/gallium/drivers/zink/zink_resource.h
index 1115891cf76..ab90ccb44c6 100644
--- a/src/gallium/drivers/zink/zink_resource.h
+++ b/src/gallium/drivers/zink/zink_resource.h
@@ -59,6 +59,7 @@ struct zink_resource {
 
    struct sw_displaytarget *dt;
    unsigned dt_stride;
+   unsigned persistent_maps; //if nonzero, requires vkFlushMappedMemoryRanges 
during batch use
 
    /* this has to be atomic for fence access, so we can't use a bitmask and 
make everything neat */
    uint8_t batch_uses[5]; //ZINK_NUM_BATCHES

_______________________________________________
mesa-commit mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/mesa-commit

Reply via email to