zink: try to handle multisampled null buffers
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Mon, 13 Jul 2020 20:35:10 +0000 (16:35 -0400)
committerMarge Bot <eric+marge@anholt.net>
Tue, 14 Jul 2020 16:40:12 +0000 (16:40 +0000)
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@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5686>

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

index 2367269e14739590a786136facf8e7a323fea2dc..be0c5ad9ebc6b7c2c9232c96378673436d1d907a 100644 (file)
@@ -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);
 }
index a0d4df43c55e6a565db12e27aafb78cb5d49b076..42dd4ca880f2780b9a9649c0ba04cf1f33e05909 100644 (file)
@@ -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];
index c72abd7486c924481e1ed4c83add520564bffc8f..a19db805c768486e675fb160300ee3fcb13bbe3e 100644 (file)
@@ -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
index 9ab00af8ab74f35c8df9881a19b43c0377cfe9a1..ca3fd4fb2314d310437388c6bee0911a69373f8b 100644 (file)
@@ -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;