zink: add batch usage flags for sampler views/states and desc sets
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Tue, 13 Oct 2020 12:12:59 +0000 (08:12 -0400)
committerMarge Bot <eric+marge@anholt.net>
Tue, 16 Mar 2021 01:01:57 +0000 (01:01 +0000)
this massively cuts down cpu time for hashing and lookups, resulting in
a noticeable performance increase

the sampler_state batch usage for now is just being set for future use when
it will be leveraged to permit immediate deletion

Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9567>

src/gallium/drivers/zink/zink_batch.c
src/gallium/drivers/zink/zink_context.h
src/gallium/drivers/zink/zink_descriptors.c
src/gallium/drivers/zink/zink_descriptors.h
src/gallium/drivers/zink/zink_draw.c

index 7255eaf..f6cf4f2 100644 (file)
@@ -36,6 +36,8 @@ zink_reset_batch(struct zink_context *ctx, struct zink_batch *batch)
    /* unref all used sampler-views */
    set_foreach(batch->sampler_views, entry) {
       struct pipe_sampler_view *pres = (struct pipe_sampler_view *)entry->key;
+      struct zink_sampler_view *sampler_view = zink_sampler_view(pres);
+      sampler_view->batch_uses &= ~BITFIELD_BIT(batch->batch_id);
       pipe_sampler_view_reference(&pres, NULL);
       _mesa_set_remove(batch->sampler_views, entry);
    }
@@ -54,6 +56,7 @@ zink_reset_batch(struct zink_context *ctx, struct zink_batch *batch)
 
    set_foreach(batch->desc_sets, entry) {
       struct zink_descriptor_set *zds = (void*)entry->key;
+      zds->batch_uses &= ~BITFIELD_BIT(batch->batch_id);
       /* reset descriptor pools when no batch is using this program to avoid
        * having some inactive program hogging a billion descriptors
        */
@@ -226,9 +229,13 @@ zink_batch_reference_sampler_view(struct zink_batch *batch,
                                   struct zink_sampler_view *sv)
 {
    bool found = false;
+   uint32_t bit = BITFIELD_BIT(batch->batch_id);
+   if (sv->batch_uses & bit)
+      return;
    _mesa_set_search_and_add(batch->sampler_views, sv, &found);
-   if (!found)
-      pipe_reference(NULL, &sv->base.reference);
+   assert(!found);
+   sv->batch_uses |= bit;
+   pipe_reference(NULL, &sv->base.reference);
    batch->has_work = true;
 }
 
@@ -257,9 +264,13 @@ bool
 zink_batch_add_desc_set(struct zink_batch *batch, struct zink_descriptor_set *zds)
 {
    bool found = false;
+   uint32_t bit = BITFIELD_BIT(batch->batch_id);
+   if (zds->batch_uses & bit)
+      return false;
    _mesa_set_search_and_add(batch->desc_sets, zds, &found);
-   if (!found)
-      pipe_reference(NULL, &zds->reference);
+   assert(!found);
+   zds->batch_uses |= bit;
+   pipe_reference(NULL, &zds->reference);
    return !found;
 }
 
index d4d770f..9283c70 100644 (file)
@@ -71,6 +71,7 @@ struct zink_sampler_state {
    VkSampler sampler;
    uint32_t hash;
    struct zink_descriptor_refs desc_set_refs;
+   uint32_t batch_uses;
    bool custom_border_color;
 };
 
@@ -82,6 +83,7 @@ struct zink_sampler_view {
       VkBufferView buffer_view;
    };
    uint32_t hash;
+   uint32_t batch_uses;
 };
 
 struct zink_image_view {
index 043e9d6..8c84b78 100644 (file)
@@ -232,6 +232,7 @@ allocate_desc_set(struct zink_screen *screen, struct zink_program *pg, enum zink
       pipe_reference_init(&zds->reference, 1);
       zds->pool = pool;
       zds->hash = 0;
+      zds->batch_uses = 0;
       zds->invalid = true;
       zds->recycled = false;
       if (num_resources) {
index 9c56e35..5ad1b81 100644 (file)
@@ -95,6 +95,7 @@ struct zink_descriptor_set {
    bool recycled;
    struct zink_descriptor_state_key key;
    struct util_dynarray barriers;
+   uint32_t batch_uses;
 #ifndef NDEBUG
    /* for extra debug asserts */
    unsigned num_resources;
index 8cbf5fb..b51c941 100644 (file)
@@ -625,6 +625,9 @@ update_sampler_descriptors(struct zink_context *ctx, struct zink_descriptor_set
             struct zink_batch *batch = is_compute ? &ctx->compute_batch : zink_curr_batch(ctx);
             if (sampler_view)
                zink_batch_reference_sampler_view(batch, sampler_view);
+            if (sampler)
+               /* this only tracks the most recent usage for now */
+               sampler->batch_uses = BITFIELD_BIT(batch->batch_id);
          }
          assert(num_wds < num_descriptors);