From ec653eda9d449580eb47b9c9d04c48440336cbdd Mon Sep 17 00:00:00 2001 From: Lucas Stach Date: Fri, 12 Aug 2022 18:35:08 +0200 Subject: [PATCH] etnaviv: rewrite sampler TS check The current way this check is written is getting hard to read. Make things a bit more verbose by splitting the checks and putting the comments directly in front of them. No functional change, GCC11 generates exactly the same machine code before and after the change. Signed-off-by: Lucas Stach Reviewed-by: Christian Gmeiner Part-of: --- src/gallium/drivers/etnaviv/etnaviv_texture.c | 50 ++++++++++++------- 1 file changed, 32 insertions(+), 18 deletions(-) diff --git a/src/gallium/drivers/etnaviv/etnaviv_texture.c b/src/gallium/drivers/etnaviv/etnaviv_texture.c index 78ec27f4142..3120364bfd8 100644 --- a/src/gallium/drivers/etnaviv/etnaviv_texture.c +++ b/src/gallium/drivers/etnaviv/etnaviv_texture.c @@ -119,27 +119,41 @@ etna_configure_sampler_ts(struct etna_sampler_ts *sts, struct pipe_sampler_view static bool etna_can_use_sampler_ts(struct pipe_sampler_view *view, int num) { - /* Can use sampler TS when: - * - the hardware supports sampler TS. - * - the sampler view will be bound to sampler texture); struct etna_screen *screen = etna_screen(rsc->base.screen); - return VIV_FEATURE(screen, chipMinorFeatures2, TEXTURE_TILED_READ) && - num < VIVS_TS_SAMPLER__LEN && - rsc->base.target != PIPE_BUFFER && - (rsc->levels[0].ts_compress_fmt < 0 || screen->specs.v4_compression) && - view->u.tex.first_level == 0 && MIN2(view->u.tex.last_level, rsc->base.last_level) == 0 && - rsc->levels[0].ts_valid; + /* Sampler TS can be used under the following conditions: */ + + /* The hardware supports it. */ + if (!VIV_FEATURE(screen, chipMinorFeatures2, TEXTURE_TILED_READ)) + return false; + + /* The sampler view will be bound to sampler < VIVS_TS_SAMPLER__LEN. + * HALTI5 adds a mapping from sampler to sampler TS unit, but this is AFAIK + * absent on earlier models. */ + if (num >= VIVS_TS_SAMPLER__LEN) + return false; + + /* It is a texture, not a buffer. */ + if (rsc->base.target == PIPE_BUFFER) + return false; + + /* Does not use compression or the hardware supports V4 compression. */ + if (rsc->levels[0].ts_compress_fmt >= 0 && !screen->specs.v4_compression) + return false; + + /* The sampler will have one LOD, and it happens to be level 0. + * (It is not sure if the hw supports it for other levels, but available + * state strongly suggests only one at a time). */ + if (view->u.tex.first_level != 0 || + MIN2(view->u.tex.last_level, rsc->base.last_level) != 0) + return false; + + /* The resource TS is valid for level 0. */ + if (!rsc->levels[0].ts_valid) + return false; + + return true; } void