zink: remove direct samplerview batch-tracking
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Tue, 16 Mar 2021 17:54:21 +0000 (13:54 -0400)
committerMarge Bot <eric+marge@anholt.net>
Wed, 17 Mar 2021 01:40:55 +0000 (01:40 +0000)
this moves tracking onto the surface/bufferview, which is more accurate
and allows the removal of a temporary hack in resource invalidation

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

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

index 4422815..464667e 100644 (file)
@@ -33,22 +33,6 @@ zink_reset_batch(struct zink_context *ctx, struct zink_batch *batch)
       _mesa_set_remove(batch->resources, entry);
    }
 
-   /* 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);
-      if (sampler_view->base.target == PIPE_BUFFER) {
-         struct zink_buffer_view *buffer_view = sampler_view->buffer_view;
-         zink_buffer_view_reference(screen, &buffer_view, NULL);
-      } else {
-         struct zink_surface *surface = sampler_view->image_view;
-         pipe_surface_reference((struct pipe_surface**)&surface, NULL);
-      }
-      pipe_sampler_view_reference(&pres, NULL);
-      _mesa_set_remove(batch->sampler_views, entry);
-   }
-
    set_foreach(batch->surfaces, entry) {
       struct zink_surface *surf = (struct zink_surface *)entry->key;
       surf->batch_uses &= ~BITFIELD64_BIT(batch->batch_id);
@@ -238,22 +222,32 @@ zink_batch_reference_resource_rw(struct zink_batch *batch, struct zink_resource
    return batch_to_flush;
 }
 
-void
-zink_batch_reference_sampler_view(struct zink_batch *batch,
-                                  struct zink_sampler_view *sv)
+static bool
+ptr_add_usage(struct zink_batch *batch, struct set *s, void *ptr, uint32_t *u)
 {
    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 ((*u) & bit)
+      return false;
+   _mesa_set_search_and_add(s, ptr, &found);
    assert(!found);
-   sv->batch_uses |= bit;
-   pipe_reference(NULL, &sv->base.reference);
-   if (sv->base.target == PIPE_BUFFER)
+   *u |= bit;
+   return true;
+}
+
+void
+zink_batch_reference_sampler_view(struct zink_batch *batch,
+                                  struct zink_sampler_view *sv)
+{
+   if (sv->base.target == PIPE_BUFFER) {
+      if (!ptr_add_usage(batch, batch->bufferviews, sv->buffer_view, &sv->buffer_view->batch_uses))
+         return;
       pipe_reference(NULL, &sv->buffer_view->reference);
-   else
+   } else {
+      if (!ptr_add_usage(batch, batch->surfaces, sv->image_view, &sv->image_view->batch_uses))
+         return;
       pipe_reference(NULL, &sv->image_view->base.reference);
+   }
    batch->has_work = true;
 }
 
index 790b0d2..1db1aed 100644 (file)
@@ -56,7 +56,6 @@ struct zink_batch {
    struct set *programs;
 
    struct set *resources;
-   struct set *sampler_views;
    struct set *surfaces;
    struct set *bufferviews;
    struct set *desc_sets;
index 5f17455..55ed0c0 100644 (file)
@@ -267,7 +267,6 @@ destroy_batch(struct zink_context* ctx, struct zink_batch* batch)
    zink_fence_reference(screen, &batch->fence, NULL);
    _mesa_set_destroy(batch->fbs, NULL);
    _mesa_set_destroy(batch->resources, NULL);
-   _mesa_set_destroy(batch->sampler_views, NULL);
    util_dynarray_fini(&batch->zombie_samplers);
    _mesa_set_destroy(batch->surfaces, NULL);
    _mesa_set_destroy(batch->programs, NULL);
@@ -2171,13 +2170,12 @@ init_batch(struct zink_context *ctx, struct zink_batch *batch, unsigned idx)
 
    batch->fbs = _mesa_pointer_set_create(NULL);
    batch->resources = _mesa_pointer_set_create(NULL);
-   batch->sampler_views = _mesa_pointer_set_create(NULL);
    batch->surfaces = _mesa_pointer_set_create(NULL);
    batch->bufferviews = _mesa_pointer_set_create(NULL);
    batch->programs = _mesa_pointer_set_create(NULL);
    batch->desc_sets = _mesa_pointer_set_create(ctx);
 
-   if (!batch->resources || !batch->sampler_views || !batch->desc_sets ||
+   if (!batch->resources || !batch->desc_sets ||
        !batch->programs || !batch->surfaces || !batch->bufferviews)
       return false;
 
index 80b6bd3..161dce0 100644 (file)
@@ -89,7 +89,6 @@ struct zink_sampler_view {
       struct zink_surface *image_view;
       struct zink_buffer_view *buffer_view;
    };
-   uint32_t batch_uses;
 };
 
 struct zink_image_view {