/*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 */
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);
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
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) {