From a15838e4566205d9c8b58c26836dc6d54816af4a Mon Sep 17 00:00:00 2001 From: Gert Wollny Date: Wed, 5 Aug 2020 10:18:30 +0200 Subject: [PATCH] vrend: don't change the readback format for emulated BGRA unless bgraswz is active When reading back a BGRA surface the client expects the data in BGRA order, and when we emulate the format by using a swizzled BGRA on GLES we still have to use the original format information to read back the data. However, this results in mesa internally swizzling the RGBA data to BGRA ordering on the CPU. This performance hit can be avoided for applications that only blit or render to BGRA surfaces, because here we can set the bgraswz tweak that does the szizzling on the GPU when drawing or blitting to a BGRA surface and then we can read the data back as is. With that for vtest the bgraswz tweak becomes purley a performance tweak. Replaying a trace of The Raven Remastered showed a 1% increase of performance when enabling the bgraswz tweak. Closes #174 v2: Fix typo (Gurchetan) v3: fix more typos (Gurchetan) Signed-off-by: Gert Wollny Reviewed-by: Gurchetan Singh --- src/vrend_renderer.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/vrend_renderer.c b/src/vrend_renderer.c index e7b9f6c..49f7b08 100644 --- a/src/vrend_renderer.c +++ b/src/vrend_renderer.c @@ -7572,7 +7572,18 @@ static int vrend_transfer_send_readpixels(struct vrend_context *ctx, else glUseProgram(0); - enum virgl_formats fmt = vrend_format_replace_emulated(res->base.bind, res->base.format); + /* If the emubgra tweak is active then reading back the BGRA format emulated + * by swizzling a RGBA format will take a performance hit because mesa will + * manually swizzling the RGBA data. This can be avoided by setting the + * tweak bgraswz that does this swizzling already on the GPU when blitting + * or rendering to an emulated BGRA surface and reading back the data as + * RGBA. The check whether we are on gles and emugbra is active is done + * in vrend_format_replace_emulated, so no need to repeat the test here */ + enum virgl_formats fmt = res->base.format; + if (vrend_get_tweak_is_active(&ctx->sub->tweaks, + virgl_tweak_gles_brga_apply_dest_swizzle)) + fmt = vrend_format_replace_emulated(res->base.bind, res->base.format); + format = tex_conv_table[fmt].glformat; type = tex_conv_table[fmt].gltype; /* if we are asked to invert and reading from a front then don't */