zink: replace context-based null framebuffer surfaces with internal ones
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Thu, 25 Mar 2021 19:44:18 +0000 (15:44 -0400)
committerMarge Bot <eric+marge@anholt.net>
Wed, 2 Jun 2021 16:53:57 +0000 (16:53 +0000)
this is a bit cleaner and avoids accessing the context

Reviewed-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11122>

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

index e2297e6..3888cb3 100644 (file)
@@ -98,9 +98,6 @@ zink_context_destroy(struct pipe_context *pctx)
    if (ctx->tc)
       util_queue_destroy(&ctx->batch.flush_queue);
 
-   for (unsigned i = 0; i < ARRAY_SIZE(ctx->null_buffers); i++)
-      pipe_resource_reference(&ctx->null_buffers[i], NULL);
-
    simple_mtx_destroy(&ctx->batch_mtx);
    zink_clear_batch_state(ctx, ctx->batch.state);
    zink_batch_state_reference(screen, &ctx->batch.state, NULL);
index f097c66..e1d1e44 100644 (file)
@@ -231,7 +231,6 @@ struct zink_context {
 
    struct pipe_resource *dummy_vertex_buffer;
    struct pipe_resource *dummy_xfb_buffer;
-   struct pipe_resource *null_buffers[5]; /* used to create zink_framebuffer->null_surface, one buffer per samplecount */
 
    struct {
       /* descriptor info */
index 3ddd2f0..6464944 100644 (file)
 #include "util/u_memory.h"
 #include "util/u_string.h"
 
-static struct pipe_surface *
-framebuffer_null_surface_init(struct zink_context *ctx, struct zink_framebuffer_state *state)
-{
-   struct pipe_surface surf_templ = {};
-   unsigned idx = util_logbase2_ceil(MAX2(state->samples, 1));
-
-   if (!ctx->null_buffers[idx]) {
-      struct pipe_resource *pres;
-      struct pipe_resource templ = {};
-      templ.width0 = state->width;
-      templ.height0 = state->height;
-      templ.depth0 = 1;
-      templ.format = PIPE_FORMAT_R8_UINT;
-      templ.target = PIPE_TEXTURE_2D;
-      templ.bind = PIPE_BIND_RENDER_TARGET;
-      templ.nr_samples = state->samples;
-
-      pres = ctx->base.screen->resource_create(ctx->base.screen, &templ);
-      if (!pres)
-         return NULL;
-
-      ctx->null_buffers[idx] = pres;
-   }
-   surf_templ.format = PIPE_FORMAT_R8_UINT;
-   surf_templ.nr_samples = state->samples;
-   return ctx->base.create_surface(&ctx->base, ctx->null_buffers[idx], &surf_templ);
-}
-
 void
 zink_destroy_framebuffer(struct zink_screen *screen,
                          struct zink_framebuffer *fb)
@@ -72,6 +44,8 @@ zink_destroy_framebuffer(struct zink_screen *screen,
 #endif
    }
 
+   if (fb->null_surface)
+      pipe_resource_reference(&fb->null_surface->texture, NULL);
    zink_surface_reference(screen, (struct zink_surface**)&fb->null_surface, NULL);
 
    ralloc_free(fb);
@@ -145,7 +119,7 @@ zink_create_framebuffer(struct zink_context *ctx,
          num_attachments++;
       } else {
          if (!fb->null_surface)
-            fb->null_surface = framebuffer_null_surface_init(ctx, state);
+            fb->null_surface = zink_surface_create_null(ctx, PIPE_TEXTURE_2D, state->width, state->height, state->samples);
          surf = zink_surface(fb->null_surface);
          state->attachments[i] = zink_surface(fb->null_surface)->image_view;
       }