zink: refactor clears a little to track a bitfield of enabled clears on the context

this makes the state of 'are there clears pending?' more accessible

Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9726>
This commit is contained in:
Mike Blumenkrantz 2020-11-04 09:08:14 -05:00 committed by Marge Bot
parent a1d03cd031
commit 6d138b5f92
4 changed files with 42 additions and 27 deletions

View file

@ -213,7 +213,7 @@ zink_clear(struct pipe_context *pctx,
struct zink_framebuffer_clear *fb_clear = &ctx->fb_clears[i];
struct zink_framebuffer_clear_data *clear = get_clear_data(ctx, fb_clear, needs_rp ? scissor_state : NULL);
fb_clear->enabled = true;
ctx->clears_enabled |= PIPE_CLEAR_COLOR0 << i;
clear->conditional = ctx->render_condition_active;
clear->has_scissor = needs_rp;
if (scissor_state && needs_rp)
@ -228,7 +228,7 @@ zink_clear(struct pipe_context *pctx,
if (buffers & PIPE_CLEAR_DEPTHSTENCIL && fb->zsbuf) {
struct zink_framebuffer_clear *fb_clear = &ctx->fb_clears[PIPE_MAX_COLOR_BUFS];
struct zink_framebuffer_clear_data *clear = get_clear_data(ctx, fb_clear, needs_rp ? scissor_state : NULL);
fb_clear->enabled = true;
ctx->clears_enabled |= PIPE_CLEAR_DEPTHSTENCIL;
clear->conditional = ctx->render_condition_active;
clear->has_scissor = needs_rp;
if (scissor_state && needs_rp)
@ -286,6 +286,7 @@ zink_clear_framebuffer(struct zink_context *ctx, unsigned clear_buffers)
clear_buffers &= ~(PIPE_CLEAR_COLOR0 << i);
to_clear |= (PIPE_CLEAR_COLOR0 << i);
}
clear_buffers &= ~PIPE_CLEAR_COLOR;
if (clear_buffers & PIPE_CLEAR_DEPTHSTENCIL) {
struct zink_framebuffer_clear *fb_clear = &ctx->fb_clears[PIPE_MAX_COLOR_BUFS];
if (color_clear) {
@ -336,7 +337,7 @@ out:
to_clear = 0;
}
for (int i = 0; i < ARRAY_SIZE(ctx->fb_clears); i++)
zink_fb_clear_reset(&ctx->fb_clears[i]);
zink_fb_clear_reset(ctx, i);
}
static struct pipe_surface *
@ -448,7 +449,7 @@ fb_clears_apply_internal(struct zink_context *ctx, struct pipe_resource *pres, i
{
struct zink_framebuffer_clear *fb_clear = &ctx->fb_clears[i];
if (!fb_clear->enabled)
if (!zink_fb_clear_enabled(ctx, i))
return;
if (zink_resource(pres)->aspect == VK_IMAGE_ASPECT_COLOR_BIT) {
assert(!zink_batch_g(ctx)->in_rp);
@ -465,7 +466,7 @@ fb_clears_apply_internal(struct zink_context *ctx, struct pipe_resource *pres, i
psurf->u.tex.level, psurf->u.tex.first_layer,
psurf->u.tex.last_layer - psurf->u.tex.first_layer + 1);
}
zink_fb_clear_reset(&ctx->fb_clears[i]);
zink_fb_clear_reset(ctx, i);
return;
} else {
assert(!zink_batch_g(ctx)->in_rp);
@ -485,7 +486,17 @@ fb_clears_apply_internal(struct zink_context *ctx, struct pipe_resource *pres, i
psurf->u.tex.last_layer - psurf->u.tex.first_layer + 1);
}
}
zink_fb_clear_reset(fb_clear);
zink_fb_clear_reset(ctx, i);
}
void
zink_fb_clear_reset(struct zink_context *ctx, unsigned i)
{
util_dynarray_fini(&ctx->fb_clears[i].clears);
if (i == PIPE_MAX_COLOR_BUFS)
ctx->clears_enabled &= ~PIPE_CLEAR_DEPTHSTENCIL;
else
ctx->clears_enabled &= ~(PIPE_CLEAR_COLOR0 << i);
}
void
@ -511,16 +522,16 @@ zink_fb_clears_discard(struct zink_context *ctx, struct pipe_resource *pres)
if (zink_resource(pres)->aspect == VK_IMAGE_ASPECT_COLOR_BIT) {
for (int i = 0; i < ctx->fb_state.nr_cbufs; i++) {
if (ctx->fb_state.cbufs[i] && ctx->fb_state.cbufs[i]->texture == pres) {
if (ctx->fb_clears[i].enabled) {
zink_fb_clear_reset(&ctx->fb_clears[i]);
if (zink_fb_clear_enabled(ctx, i)) {
zink_fb_clear_reset(ctx, i);
return;
}
}
}
} else {
if (ctx->fb_clears[PIPE_MAX_COLOR_BUFS].enabled && ctx->fb_state.zsbuf && ctx->fb_state.zsbuf->texture == pres) {
if (zink_fb_clear_enabled(ctx, PIPE_MAX_COLOR_BUFS) && ctx->fb_state.zsbuf && ctx->fb_state.zsbuf->texture == pres) {
int i = PIPE_MAX_COLOR_BUFS;
zink_fb_clear_reset(&ctx->fb_clears[i]);
zink_fb_clear_reset(ctx, i);
}
}
}
@ -530,7 +541,7 @@ zink_clear_apply_conditionals(struct zink_context *ctx)
{
for (int i = 0; i < ARRAY_SIZE(ctx->fb_clears); i++) {
struct zink_framebuffer_clear *fb_clear = &ctx->fb_clears[i];
if (!fb_clear->enabled)
if (!zink_fb_clear_enabled(ctx, i))
continue;
for (int j = 0; j < zink_fb_clear_count(fb_clear); j++) {
struct zink_framebuffer_clear_data *clear = zink_fb_clear_element(fb_clear, j);
@ -543,7 +554,7 @@ zink_clear_apply_conditionals(struct zink_context *ctx)
if (surf)
fb_clears_apply_internal(ctx, surf->texture, i);
else
zink_fb_clear_reset(&ctx->fb_clears[i]);
zink_fb_clear_reset(ctx, i);
break;
}
}
@ -554,7 +565,7 @@ static void
fb_clears_apply_or_discard_internal(struct zink_context *ctx, struct pipe_resource *pres, struct u_rect region, bool discard_only, bool invert, int i)
{
struct zink_framebuffer_clear *fb_clear = &ctx->fb_clears[i];
if (fb_clear->enabled) {
if (zink_fb_clear_enabled(ctx, i)) {
if (zink_blit_region_fills(region, pres->width0, pres->height0)) {
if (invert)
fb_clears_apply_internal(ctx, pres, i);
@ -591,7 +602,7 @@ zink_fb_clears_apply_or_discard(struct zink_context *ctx, struct pipe_resource *
}
}
} else {
if (ctx->fb_clears[PIPE_MAX_COLOR_BUFS].enabled && ctx->fb_state.zsbuf && ctx->fb_state.zsbuf->texture == pres) {
if (zink_fb_clear_enabled(ctx, PIPE_MAX_COLOR_BUFS) && ctx->fb_state.zsbuf && ctx->fb_state.zsbuf->texture == pres) {
fb_clears_apply_or_discard_internal(ctx, pres, region, discard_only, false, PIPE_MAX_COLOR_BUFS);
}
}

View file

@ -51,7 +51,6 @@ struct zink_framebuffer_clear_data {
struct zink_framebuffer_clear {
struct util_dynarray clears;
bool enabled;
};
void
@ -85,15 +84,11 @@ zink_fb_clear_element(struct zink_framebuffer_clear *fb_clear, int idx)
static inline unsigned
zink_fb_clear_count(struct zink_framebuffer_clear *fb_clear)
{
return util_dynarray_num_elements(&fb_clear->clears, struct zink_framebuffer_clear_data);
return fb_clear ? util_dynarray_num_elements(&fb_clear->clears, struct zink_framebuffer_clear_data) : 0;
}
static inline void
zink_fb_clear_reset(struct zink_framebuffer_clear *fb_clear)
{
util_dynarray_fini(&fb_clear->clears);
fb_clear->enabled = false;
}
void
zink_fb_clear_reset(struct zink_context *ctx, unsigned idx);
static inline bool
zink_fb_clear_element_needs_explicit(struct zink_framebuffer_clear_data *clear)

View file

@ -1129,7 +1129,7 @@ get_render_pass(struct zink_context *ctx)
state.rts[i].format = zink_get_format(screen, surf->format);
state.rts[i].samples = surf->texture->nr_samples > 0 ? surf->texture->nr_samples :
VK_SAMPLE_COUNT_1_BIT;
state.rts[i].clear_color = ctx->fb_clears[i].enabled && !zink_fb_clear_first_needs_explicit(&ctx->fb_clears[i]);
state.rts[i].clear_color = zink_fb_clear_enabled(ctx, i) && !zink_fb_clear_first_needs_explicit(&ctx->fb_clears[i]);
clears |= !!state.rts[i].clear_color ? BITFIELD_BIT(i) : 0;
} else {
state.rts[i].format = VK_FORMAT_R8_UINT;
@ -1144,10 +1144,10 @@ get_render_pass(struct zink_context *ctx)
struct zink_framebuffer_clear *fb_clear = &ctx->fb_clears[PIPE_MAX_COLOR_BUFS];
state.rts[fb->nr_cbufs].format = zsbuf->format;
state.rts[fb->nr_cbufs].samples = zsbuf->base.nr_samples > 0 ? zsbuf->base.nr_samples : VK_SAMPLE_COUNT_1_BIT;
state.rts[fb->nr_cbufs].clear_color = fb_clear->enabled &&
state.rts[fb->nr_cbufs].clear_color = zink_fb_clear_enabled(ctx, PIPE_MAX_COLOR_BUFS) &&
!zink_fb_clear_first_needs_explicit(fb_clear) &&
(zink_fb_clear_element(fb_clear, 0)->zs.bits & PIPE_CLEAR_DEPTH);
state.rts[fb->nr_cbufs].clear_stencil = fb_clear->enabled &&
state.rts[fb->nr_cbufs].clear_stencil = zink_fb_clear_enabled(ctx, PIPE_MAX_COLOR_BUFS) &&
!zink_fb_clear_first_needs_explicit(fb_clear) &&
(zink_fb_clear_element(fb_clear, 0)->zs.bits & PIPE_CLEAR_STENCIL);
clears |= state.rts[fb->nr_cbufs].clear_color || state.rts[fb->nr_cbufs].clear_stencil ? BITFIELD_BIT(fb->nr_cbufs) : 0;;
@ -1269,7 +1269,7 @@ zink_begin_render_pass(struct zink_context *ctx, struct zink_batch *batch)
uint32_t clear_validate = 0;
for (int i = 0; i < fb_state->nr_cbufs; i++) {
/* these are no-ops */
if (!fb_state->cbufs[i] || !ctx->fb_clears[i].enabled)
if (!fb_state->cbufs[i] || !zink_fb_clear_enabled(ctx, i))
continue;
/* these need actual clear calls inside the rp */
struct zink_framebuffer_clear_data *clear = zink_fb_clear_element(&ctx->fb_clears[i], 0);
@ -1285,7 +1285,7 @@ zink_begin_render_pass(struct zink_context *ctx, struct zink_batch *batch)
clear_validate |= BITFIELD_BIT(i);
assert(ctx->framebuffer->rp->state.clears);
}
if (fb_state->zsbuf && ctx->fb_clears[PIPE_MAX_COLOR_BUFS].enabled) {
if (fb_state->zsbuf && zink_fb_clear_enabled(ctx, PIPE_MAX_COLOR_BUFS)) {
struct zink_framebuffer_clear *fb_clear = &ctx->fb_clears[PIPE_MAX_COLOR_BUFS];
struct zink_framebuffer_clear_data *clear = zink_fb_clear_element(fb_clear, 0);
if (!zink_fb_clear_element_needs_explicit(clear)) {

View file

@ -182,6 +182,7 @@ struct zink_context {
struct zink_framebuffer *framebuffer;
struct zink_framebuffer_clear fb_clears[PIPE_MAX_COLOR_BUFS + 1];
uint16_t clears_enabled;
struct pipe_vertex_buffer vertex_buffers[PIPE_MAX_ATTRIBS];
@ -229,6 +230,14 @@ zink_context(struct pipe_context *context)
return (struct zink_context *)context;
}
static inline bool
zink_fb_clear_enabled(const struct zink_context *ctx, unsigned idx)
{
if (idx == PIPE_MAX_COLOR_BUFS)
return ctx->clears_enabled & PIPE_CLEAR_DEPTHSTENCIL;
return ctx->clears_enabled & (PIPE_CLEAR_COLOR0 << idx);
}
static inline struct zink_batch *
zink_batch_queue(struct zink_context *ctx, enum zink_queue queue_type)
{