From a3431ffb693093868417f8813e4954a26464d6f9 Mon Sep 17 00:00:00 2001 From: Icecream95 Date: Sat, 5 Sep 2020 10:18:33 +1200 Subject: [PATCH] panfrost: Move tiled-linear conversion checking to a new function AFBC-linear conversion will also use this function. Reviewed-by: Alyssa Rosenzweig Part-of: --- src/gallium/drivers/panfrost/pan_resource.c | 48 +++++++++++++++++------------ 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/src/gallium/drivers/panfrost/pan_resource.c b/src/gallium/drivers/panfrost/pan_resource.c index 467ea91..60dc102 100644 --- a/src/gallium/drivers/panfrost/pan_resource.c +++ b/src/gallium/drivers/panfrost/pan_resource.c @@ -949,6 +949,33 @@ panfrost_transfer_map(struct pipe_context *pctx, } } +static bool +panfrost_should_linear_convert(struct panfrost_resource *prsrc, + struct pipe_transfer *transfer) +{ + if (prsrc->modifier_constant) + return false; + + /* Overwriting the entire resource indicates streaming, for which + * linear layout is most efficient due to the lack of expensive + * conversion. + * + * For now we just switch to linear after a number of complete + * overwrites to keep things simple, but we could do better. + */ + + bool entire_overwrite = prsrc->base.last_level == 0 + && transfer->box.width == prsrc->base.width0 + && transfer->box.height == prsrc->base.height0 + && transfer->box.x == 0 + && transfer->box.y == 0; + + if (entire_overwrite) + ++prsrc->modifier_updates; + + return prsrc->modifier_updates >= LAYOUT_CONVERT_THRESHOLD; +} + static void panfrost_transfer_unmap(struct pipe_context *pctx, struct pipe_transfer *transfer) @@ -982,26 +1009,7 @@ panfrost_transfer_unmap(struct pipe_context *pctx, if (prsrc->modifier == DRM_FORMAT_MOD_ARM_16X16_BLOCK_U_INTERLEAVED) { assert(transfer->box.depth == 1); - /* Do we overwrite the entire resource? If so, - * we don't need an intermediate blit so it's a - * good time to switch the modifier. */ - - bool discards_content = prsrc->base.last_level == 0 - && transfer->box.width == prsrc->base.width0 - && transfer->box.height == prsrc->base.height0 - && transfer->box.x == 0 - && transfer->box.y == 0 - && !prsrc->modifier_constant; - - /* It also serves as a good heuristic for - * streaming textures (e.g. in video players), - * but we could do better */ - - if (discards_content) - ++prsrc->modifier_updates; - - if (prsrc->modifier_updates >= LAYOUT_CONVERT_THRESHOLD) - { + if (panfrost_should_linear_convert(prsrc, transfer)) { prsrc->modifier = DRM_FORMAT_MOD_LINEAR; util_copy_rect( -- 2.7.4