Mesa (master): zink: try to handle multisampled null buffers

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Jul 14 16:53:44 UTC 2020


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

Author: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Date:   Mon Jul 13 16:35:10 2020 -0400

zink: try to handle multisampled null buffers

I don't have any tests for this that I've run into yet, so this is mostly
just guessing

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

---

 src/gallium/drivers/zink/zink_context.c     |  6 ++++--
 src/gallium/drivers/zink/zink_context.h     |  2 +-
 src/gallium/drivers/zink/zink_framebuffer.c | 11 +++++++----
 src/gallium/drivers/zink/zink_framebuffer.h |  1 +
 4 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/src/gallium/drivers/zink/zink_context.c b/src/gallium/drivers/zink/zink_context.c
index 2367269e147..be0c5ad9ebc 100644
--- a/src/gallium/drivers/zink/zink_context.c
+++ b/src/gallium/drivers/zink/zink_context.c
@@ -58,7 +58,8 @@ zink_context_destroy(struct pipe_context *pctx)
    if (vkQueueWaitIdle(ctx->queue) != VK_SUCCESS)
       debug_printf("vkQueueWaitIdle failed\n");
 
-   pipe_resource_reference(&ctx->null_buffer, NULL);
+   for (unsigned i = 0; i < ARRAY_SIZE(ctx->null_buffers); i++)
+      pipe_resource_reference(&ctx->null_buffers[i], NULL);
 
    for (int i = 0; i < ARRAY_SIZE(ctx->batches); ++i)
       vkFreeCommandBuffers(screen->dev, ctx->cmdpool, 1, &ctx->batches[i].cmdbuf);
@@ -506,7 +507,7 @@ get_render_pass(struct zink_context *ctx)
                                                        VK_SAMPLE_COUNT_1_BIT;
       } else {
          state.rts[i].format = VK_FORMAT_R8_UINT;
-         state.rts[i].samples = VK_SAMPLE_COUNT_1_BIT;
+         state.rts[i].samples = MAX2(fb->samples, 1);
       }
    }
    state.num_cbufs = fb->nr_cbufs;
@@ -553,6 +554,7 @@ create_framebuffer(struct zink_context *ctx)
    state.width = ctx->fb_state.width;
    state.height = ctx->fb_state.height;
    state.layers = MAX2(ctx->fb_state.layers, 1);
+   state.samples = ctx->fb_state.samples;
 
    return zink_create_framebuffer(ctx, screen, &state);
 }
diff --git a/src/gallium/drivers/zink/zink_context.h b/src/gallium/drivers/zink/zink_context.h
index a0d4df43c55..42dd4ca880f 100644
--- a/src/gallium/drivers/zink/zink_context.h
+++ b/src/gallium/drivers/zink/zink_context.h
@@ -125,7 +125,7 @@ struct zink_context {
    bool queries_disabled;
 
    struct pipe_resource *dummy_buffer;
-   struct pipe_resource *null_buffer; /* used to create zink_framebuffer->null_surface */
+   struct pipe_resource *null_buffers[5]; /* used to create zink_framebuffer->null_surface, one buffer per samplecount */
 
    uint32_t num_so_targets;
    struct pipe_stream_output_target *so_targets[PIPE_MAX_SO_OUTPUTS];
diff --git a/src/gallium/drivers/zink/zink_framebuffer.c b/src/gallium/drivers/zink/zink_framebuffer.c
index c72abd7486c..a19db805c76 100644
--- a/src/gallium/drivers/zink/zink_framebuffer.c
+++ b/src/gallium/drivers/zink/zink_framebuffer.c
@@ -35,7 +35,9 @@ static struct pipe_surface *
 framebuffer_null_surface_init(struct zink_context *ctx, struct zink_framebuffer_state *state)
 {
    struct pipe_surface surf_templ = {};
-   if (!ctx->null_buffer) {
+   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;
@@ -44,16 +46,17 @@ framebuffer_null_surface_init(struct zink_context *ctx, struct zink_framebuffer_
       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_buffer = pres;
+      ctx->null_buffers[idx] = pres;
    }
    surf_templ.format = PIPE_FORMAT_R8_UINT;
-   surf_templ.nr_samples = 1;
-   return ctx->base.create_surface(&ctx->base, ctx->null_buffer, &surf_templ);
+   surf_templ.nr_samples = state->samples;
+   return ctx->base.create_surface(&ctx->base, ctx->null_buffers[idx], &surf_templ);
 }
 
 void
diff --git a/src/gallium/drivers/zink/zink_framebuffer.h b/src/gallium/drivers/zink/zink_framebuffer.h
index 9ab00af8ab7..ca3fd4fb231 100644
--- a/src/gallium/drivers/zink/zink_framebuffer.h
+++ b/src/gallium/drivers/zink/zink_framebuffer.h
@@ -37,6 +37,7 @@ struct zink_framebuffer_state {
    struct zink_render_pass *rp;
    uint32_t width;
    uint16_t height, layers;
+   uint8_t samples;
    uint8_t num_attachments;
    struct zink_surface *attachments[PIPE_MAX_COLOR_BUFS + 1];
    bool has_null_attachments;



More information about the mesa-commit mailing list