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@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5686>
This commit is contained in:
Mike Blumenkrantz 2020-07-13 16:35:10 -04:00 committed by Marge Bot
parent 1ee598cfed
commit 2e488305d6
4 changed files with 13 additions and 7 deletions

View 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);
}

View 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];

View 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

View 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;