diff options
author | Wladimir J. van der Laan <[email protected]> | 2017-11-14 10:21:23 +0100 |
---|---|---|
committer | Christian Gmeiner <[email protected]> | 2017-11-15 23:27:54 +0100 |
commit | d61a9143948a45d6b6075e598affc1bb847b890a (patch) | |
tree | e7e469835bea9a12f6c5fe8b58016d94b7fd57f1 /src/gallium/drivers | |
parent | 59d76e7ab67e61f0ea2a798025e89bbe5a28e393 (diff) |
etnaviv: Add sampler TS support
Sampler TS is an hardware optimization that can be used when rendering
to textures. After rendering to a resource with TS enabled, the
texture unit can use this to bypass lookups to empty tiles. This also
means a resolve-in-place can be avoided to flush the TS.
This commit is also an optimization when not using sampler TS, as
resolve-in-place will now be skipped if a resource has no (valid) TS.
Signed-off-by: Wladimir J. van der Laan <[email protected]>
Reviewed-by: Christian Gmeiner <[email protected]>
Diffstat (limited to 'src/gallium/drivers')
-rw-r--r-- | src/gallium/drivers/etnaviv/etnaviv_emit.c | 26 | ||||
-rw-r--r-- | src/gallium/drivers/etnaviv/etnaviv_texture.c | 74 | ||||
-rw-r--r-- | src/gallium/drivers/etnaviv/etnaviv_texture.h | 5 |
3 files changed, 99 insertions, 6 deletions
diff --git a/src/gallium/drivers/etnaviv/etnaviv_emit.c b/src/gallium/drivers/etnaviv/etnaviv_emit.c index b6b06e3c1fa..999d2ca06a5 100644 --- a/src/gallium/drivers/etnaviv/etnaviv_emit.c +++ b/src/gallium/drivers/etnaviv/etnaviv_emit.c @@ -632,6 +632,32 @@ etna_emit_state(struct etna_context *ctx) /*01668*/ EMIT_STATE_RELOC(TS_DEPTH_SURFACE_BASE, &ctx->framebuffer.TS_DEPTH_SURFACE_BASE); /*0166C*/ EMIT_STATE(TS_DEPTH_CLEAR_VALUE, ctx->framebuffer.TS_DEPTH_CLEAR_VALUE); } + if (unlikely(dirty & ETNA_DIRTY_SAMPLER_VIEWS)) { + for (int x = 0; x < VIVS_TS_SAMPLER__LEN; ++x) { + if ((1 << x) & active_samplers) { + struct etna_sampler_view *sv = etna_sampler_view(ctx->sampler_view[x]); + /*01720*/ EMIT_STATE(TS_SAMPLER_CONFIG(x), sv->TS_SAMPLER_CONFIG); + } + } + for (int x = 0; x < VIVS_TS_SAMPLER__LEN; ++x) { + if ((1 << x) & active_samplers) { + struct etna_sampler_view *sv = etna_sampler_view(ctx->sampler_view[x]); + /*01740*/ EMIT_STATE_RELOC(TS_SAMPLER_STATUS_BASE(x), &sv->TS_SAMPLER_STATUS_BASE); + } + } + for (int x = 0; x < VIVS_TS_SAMPLER__LEN; ++x) { + if ((1 << x) & active_samplers) { + struct etna_sampler_view *sv = etna_sampler_view(ctx->sampler_view[x]); + /*01760*/ EMIT_STATE(TS_SAMPLER_CLEAR_VALUE(x), sv->TS_SAMPLER_CLEAR_VALUE); + } + } + for (int x = 0; x < VIVS_TS_SAMPLER__LEN; ++x) { + if ((1 << x) & active_samplers) { + struct etna_sampler_view *sv = etna_sampler_view(ctx->sampler_view[x]); + /*01780*/ EMIT_STATE(TS_SAMPLER_CLEAR_VALUE2(x), sv->TS_SAMPLER_CLEAR_VALUE2); + } + } + } if (unlikely(dirty & (ETNA_DIRTY_SAMPLER_VIEWS | ETNA_DIRTY_SAMPLERS))) { for (int x = 0; x < VIVS_TE_SAMPLER__LEN; ++x) { uint32_t val = 0; /* 0 == sampler inactive */ diff --git a/src/gallium/drivers/etnaviv/etnaviv_texture.c b/src/gallium/drivers/etnaviv/etnaviv_texture.c index 34529c600c4..6a33f787a1b 100644 --- a/src/gallium/drivers/etnaviv/etnaviv_texture.c +++ b/src/gallium/drivers/etnaviv/etnaviv_texture.c @@ -112,11 +112,67 @@ etna_delete_sampler_state(struct pipe_context *pctx, void *ss) FREE(ss); } +/* Return true if the GPU can use sampler TS with this sampler view. + * Sampler TS is an optimization used when rendering to textures, where + * a resolve-in-place can be avoided when rendering has left a (valid) TS. + */ +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 <VIVS_TS_SAMPLER__LEN. + * HALTI5 adds a mapping from sampler to sampler TS unit, but this is AFAIK + * absent on earlier models. + * - it is a texture, not a buffer. + * - the sampler view has a supported format for sampler TS. + * - 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). + * - the resource TS is valid for level 0. + */ + struct etna_resource *rsc = etna_resource(view->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 && + translate_ts_sampler_format(rsc->base.format) != ETNA_NO_MATCH && + view->u.tex.first_level == 0 && MIN2(view->u.tex.last_level, rsc->base.last_level) == 0 && + rsc->levels[0].ts_valid; +} + +static void +etna_configure_sampler_ts(struct pipe_sampler_view *pview, bool enable) +{ + struct etna_sampler_view *view = etna_sampler_view(pview); + if (enable) { + struct etna_resource *rsc = etna_resource(view->base.texture); + struct etna_resource_level *lev = &rsc->levels[0]; + assert(rsc->ts_bo && lev->ts_valid); + + view->TE_SAMPLER_CONFIG1 |= VIVS_TE_SAMPLER_CONFIG1_USE_TS; + view->TS_SAMPLER_CONFIG = + VIVS_TS_SAMPLER_CONFIG_ENABLE(1) | + VIVS_TS_SAMPLER_CONFIG_FORMAT(translate_ts_sampler_format(rsc->base.format)); + view->TS_SAMPLER_CLEAR_VALUE = lev->clear_value; + view->TS_SAMPLER_CLEAR_VALUE2 = lev->clear_value; /* To handle 64-bit formats this needs a different value */ + view->TS_SAMPLER_STATUS_BASE.bo = rsc->ts_bo; + view->TS_SAMPLER_STATUS_BASE.offset = lev->ts_offset; + view->TS_SAMPLER_STATUS_BASE.flags = ETNA_RELOC_READ; + } else { + view->TE_SAMPLER_CONFIG1 &= ~VIVS_TE_SAMPLER_CONFIG1_USE_TS; + view->TS_SAMPLER_CONFIG = 0; + view->TS_SAMPLER_STATUS_BASE.bo = NULL; + } + /* n.b.: relies on caller to mark ETNA_DIRTY_SAMPLER_VIEWS */ +} + static void -etna_update_sampler_source(struct pipe_sampler_view *view) +etna_update_sampler_source(struct pipe_sampler_view *view, int num) { struct etna_resource *base = etna_resource(view->texture); struct etna_resource *to = base, *from = base; + bool enable_sampler_ts = false; if (base->external && etna_resource_newer(etna_resource(base->external), base)) from = etna_resource(base->external); @@ -129,11 +185,17 @@ etna_update_sampler_source(struct pipe_sampler_view *view) view->texture->last_level); to->seqno = from->seqno; } else if ((to == from) && etna_resource_needs_flush(to)) { - /* Resolve TS if needed, remove when adding sampler TS */ - etna_copy_resource(view->context, &to->base, &from->base, 0, - view->texture->last_level); - to->flush_seqno = from->seqno; + if (etna_can_use_sampler_ts(view, num)) { + enable_sampler_ts = true; + /* Do not set flush_seqno because the resolve-to-self was bypassed */ + } else { + /* Resolve TS if needed */ + etna_copy_resource(view->context, &to->base, &from->base, 0, + view->texture->last_level); + to->flush_seqno = from->seqno; + } } + etna_configure_sampler_ts(view, enable_sampler_ts); } static bool @@ -332,7 +394,7 @@ etna_set_sampler_views(struct pipe_context *pctx, enum pipe_shader_type shader, for (unsigned idx = 0; idx < num_views; ++idx) { if (views[idx]) - etna_update_sampler_source(views[idx]); + etna_update_sampler_source(views[idx], idx); } switch (shader) { diff --git a/src/gallium/drivers/etnaviv/etnaviv_texture.h b/src/gallium/drivers/etnaviv/etnaviv_texture.h index eafaae23f50..304373303cd 100644 --- a/src/gallium/drivers/etnaviv/etnaviv_texture.h +++ b/src/gallium/drivers/etnaviv/etnaviv_texture.h @@ -62,6 +62,11 @@ struct etna_sampler_view { uint32_t TE_SAMPLER_ASTC0; struct etna_reloc TE_SAMPLER_LOD_ADDR[VIVS_TE_SAMPLER_LOD_ADDR__LEN]; unsigned min_lod, max_lod; /* 5.5 fixp */ + + uint32_t TS_SAMPLER_CONFIG; + struct etna_reloc TS_SAMPLER_STATUS_BASE; + uint32_t TS_SAMPLER_CLEAR_VALUE; + uint32_t TS_SAMPLER_CLEAR_VALUE2; }; static inline struct etna_sampler_view * |