From e1715c6a4f0548078d80047dd41388bf372a3366 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Sat, 10 Sep 2022 17:56:10 -0400 Subject: [PATCH] asahi: Don't crash on <4 channel render targets It doesn't matter what we put in the swizzle for the unused components, but if we try to stuff out-of-bounds PIPE_SWIZZLE_0/1/NONE values, we'll crash in GenXML. Fixes failing tests in dEQP-GLES3.functional.fragment_out.basic.fixed.* Signed-off-by: Alyssa Rosenzweig Part-of: --- src/gallium/drivers/asahi/agx_state.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/gallium/drivers/asahi/agx_state.c b/src/gallium/drivers/asahi/agx_state.c index bb31397..a032fdc 100644 --- a/src/gallium/drivers/asahi/agx_state.c +++ b/src/gallium/drivers/asahi/agx_state.c @@ -773,10 +773,19 @@ agx_set_framebuffer_state(struct pipe_context *pctx, agx_pack(ctx->render_target[i], RENDER_TARGET, cfg) { cfg.layout = agx_translate_layout(tex->modifier); cfg.format = agx_pixel_format[surf->format].hw; + + assert(desc->nr_channels >= 1 && desc->nr_channels <= 4); cfg.swizzle_r = agx_channel_from_pipe(desc->swizzle[0]); - cfg.swizzle_g = agx_channel_from_pipe(desc->swizzle[1]); - cfg.swizzle_b = agx_channel_from_pipe(desc->swizzle[2]); - cfg.swizzle_a = agx_channel_from_pipe(desc->swizzle[3]); + + if (desc->nr_channels >= 2) + cfg.swizzle_g = agx_channel_from_pipe(desc->swizzle[1]); + + if (desc->nr_channels >= 3) + cfg.swizzle_b = agx_channel_from_pipe(desc->swizzle[2]); + + if (desc->nr_channels >= 4) + cfg.swizzle_a = agx_channel_from_pipe(desc->swizzle[3]); + cfg.width = state->width; cfg.height = state->height; cfg.level = surf->u.tex.level; -- 2.7.4