From 981464356c0bb75ed4b5ee3b8db472d467023bc7 Mon Sep 17 00:00:00 2001 From: "Kristian H. Kristensen" Date: Mon, 28 Sep 2020 20:21:49 +0000 Subject: [PATCH] freedreno/a6xx: Support PIPE_FORMAT_R8_G8B8_420_UNORM for texturing This makes freedreno advertise support for PIPE_FORMAT_R8_G8B8_420_UNORM on a6xx, which enables lowering NV12 to this format. Reviewed-by: Rob Clark Part-of: --- .../drivers/freedreno/a6xx/fd6_format.c | 2 ++ .../drivers/freedreno/a6xx/fd6_resource.c | 3 ++ .../drivers/freedreno/a6xx/fd6_texture.c | 34 ++++++++++++++++--- 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/src/gallium/drivers/freedreno/a6xx/fd6_format.c b/src/gallium/drivers/freedreno/a6xx/fd6_format.c index bbc71cf0a08..0f6b70472c1 100644 --- a/src/gallium/drivers/freedreno/a6xx/fd6_format.c +++ b/src/gallium/drivers/freedreno/a6xx/fd6_format.c @@ -332,6 +332,8 @@ static struct fd6_format formats[PIPE_FORMAT_COUNT] = { _T_(ASTC_10x10_SRGB, ASTC_10x10, WZYX), _T_(ASTC_12x10_SRGB, ASTC_12x10, WZYX), _T_(ASTC_12x12_SRGB, ASTC_12x12, WZYX), + + _T_(R8_G8B8_420_UNORM, R8_G8B8_2PLANE_420_UNORM, WZYX), }; /* convert pipe format to vertex buffer format: */ diff --git a/src/gallium/drivers/freedreno/a6xx/fd6_resource.c b/src/gallium/drivers/freedreno/a6xx/fd6_resource.c index 7adc92d3968..fc4a757826a 100644 --- a/src/gallium/drivers/freedreno/a6xx/fd6_resource.c +++ b/src/gallium/drivers/freedreno/a6xx/fd6_resource.c @@ -58,6 +58,9 @@ ok_ubwc_format(struct fd_resource *rsc, enum pipe_format pfmt) pfmt == PIPE_FORMAT_Z24_UNORM_S8_UINT) return false; + if (pfmt == PIPE_FORMAT_R8_G8B8_420_UNORM) + return true; + switch (fd6_pipe2color(pfmt)) { case FMT6_10_10_10_2_UINT: case FMT6_10_10_10_2_UNORM_DEST: diff --git a/src/gallium/drivers/freedreno/a6xx/fd6_texture.c b/src/gallium/drivers/freedreno/a6xx/fd6_texture.c index 05022fbac9f..ff408eb334a 100644 --- a/src/gallium/drivers/freedreno/a6xx/fd6_texture.c +++ b/src/gallium/drivers/freedreno/a6xx/fd6_texture.c @@ -267,11 +267,37 @@ fd6_sampler_view_create(struct pipe_context *pctx, struct pipe_resource *prsc, so->texconst2 = A6XX_TEX_CONST_2_PITCHALIGN(rsc->layout.pitchalign - 6) | A6XX_TEX_CONST_2_PITCH(fd_resource_pitch(rsc, lvl)); - so->offset1 = fd_resource_offset(rsc, lvl, cso->u.tex.first_layer); + ubwc_enabled = fd_resource_ubwc_enabled(rsc, lvl); - if (ubwc_enabled) { - so->ptr2 = rsc; - so->offset2 = fd_resource_ubwc_offset(rsc, lvl, cso->u.tex.first_layer); + + if (rsc->base.format == PIPE_FORMAT_R8_G8B8_420_UNORM) { + struct fd_resource *next = fd_resource(rsc->base.next); + + /* In case of biplanar R8_G8B8, the UBWC metadata address in + * dwords 7 and 8, is instead the pointer to the second plane. + */ + so->ptr2 = next; + so->texconst6 = + A6XX_TEX_CONST_6_PLANE_PITCH(fd_resource_pitch(next, lvl)); + + if (ubwc_enabled) { + /* Further, if using UBWC with R8_G8B8, we only point to the + * UBWC header and the color data is expected to follow immediately. + */ + so->offset1 = + fd_resource_ubwc_offset(rsc, lvl, cso->u.tex.first_layer); + so->offset2 = + fd_resource_ubwc_offset(next, lvl, cso->u.tex.first_layer); + } else { + so->offset1 = fd_resource_offset(rsc, lvl, cso->u.tex.first_layer); + so->offset2 = fd_resource_offset(next, lvl, cso->u.tex.first_layer); + } + } else { + so->offset1 = fd_resource_offset(rsc, lvl, cso->u.tex.first_layer); + if (ubwc_enabled) { + so->ptr2 = rsc; + so->offset2 = fd_resource_ubwc_offset(rsc, lvl, cso->u.tex.first_layer); + } } }