union util_color uc;
util_pack_color(rgba, format, &uc);
if (util_format_get_blocksize(format) == 2)
- return uc.ui[0] << 16 | uc.ui[0];
+ return uc.ui[0] << 16 | (uc.ui[0] & 0xffff);
else
return uc.ui[0];
}
return true;
}
+static inline size_t
+etna_compute_tileoffset(const struct pipe_box *box, enum pipe_format format,
+ size_t stride, enum etna_surface_layout layout)
+{
+ size_t offset;
+ unsigned int x = box->x, y = box->y;
+ unsigned int blocksize = util_format_get_blocksize(format);
+
+ switch (layout) {
+ case ETNA_LAYOUT_LINEAR:
+ offset = y * stride + x * blocksize;
+ break;
+ case ETNA_LAYOUT_MULTI_TILED:
+ y >>= 1;
+ /* fall-through */
+ case ETNA_LAYOUT_TILED:
+ assert(!(x & 0x03) && !(y & 0x03));
+ offset = (y & ~0x03) * stride + blocksize * ((x & ~0x03) << 2);
+ break;
+ case ETNA_LAYOUT_MULTI_SUPERTILED:
+ y >>= 1;
+ /* fall-through */
+ case ETNA_LAYOUT_SUPER_TILED:
+ assert(!(x & 0x3f) && !(y & 0x3f));
+ offset = (y & ~0x3f) * stride + blocksize * ((x & ~0x3f) << 6);
+ break;
+ default:
+ unreachable("invalid resource layout");
+ }
+
+ return offset;
+}
+
+static inline void
+etna_get_rs_alignment_mask(const struct etna_context *ctx,
+ const enum etna_surface_layout layout,
+ unsigned int *width_mask, unsigned int *height_mask)
+{
+ unsigned int h_align, w_align;
+
+ if (layout & ETNA_LAYOUT_BIT_SUPER) {
+ w_align = h_align = 64;
+ } else {
+ w_align = ETNA_RS_WIDTH_MASK + 1;
+ h_align = ETNA_RS_HEIGHT_MASK + 1;
+ }
+
+ h_align *= ctx->screen->specs.pixel_pipes;
+
+ *width_mask = w_align - 1;
+ *height_mask = h_align -1;
+}
+
static bool
etna_try_rs_blit(struct pipe_context *pctx,
const struct pipe_blit_info *blit_info)
}
unsigned src_format = etna_compatible_rs_format(blit_info->src.format);
- unsigned dst_format = etna_compatible_rs_format(blit_info->src.format);
+ unsigned dst_format = etna_compatible_rs_format(blit_info->dst.format);
if (translate_rs_format(src_format) == ETNA_NO_MATCH ||
translate_rs_format(dst_format) == ETNA_NO_MATCH ||
- blit_info->scissor_enable || blit_info->src.box.x != 0 ||
- blit_info->src.box.y != 0 || blit_info->dst.box.x != 0 ||
- blit_info->dst.box.y != 0 ||
+ blit_info->scissor_enable ||
blit_info->dst.box.depth != blit_info->src.box.depth ||
blit_info->dst.box.depth != 1) {
return FALSE;
}
+ unsigned w_mask, h_mask;
+
+ etna_get_rs_alignment_mask(ctx, src->layout, &w_mask, &h_mask);
+ if ((blit_info->src.box.x & w_mask) || (blit_info->src.box.y & h_mask))
+ return FALSE;
+
+ etna_get_rs_alignment_mask(ctx, dst->layout, &w_mask, &h_mask);
+ if ((blit_info->dst.box.x & w_mask) || (blit_info->dst.box.y & h_mask))
+ return FALSE;
+
/* Ensure that the Z coordinate is sane */
if (dst->base.target != PIPE_TEXTURE_CUBE)
assert(blit_info->dst.box.z == 0);
assert(blit_info->dst.box.x + blit_info->dst.box.width <= dst_lev->padded_width);
assert(blit_info->dst.box.y + blit_info->dst.box.height <= dst_lev->padded_height);
- unsigned src_offset =
- src_lev->offset + blit_info->src.box.z * src_lev->layer_stride;
- unsigned dst_offset =
- dst_lev->offset + blit_info->dst.box.z * dst_lev->layer_stride;
+ unsigned src_offset = src_lev->offset +
+ blit_info->src.box.z * src_lev->layer_stride +
+ etna_compute_tileoffset(&blit_info->src.box,
+ blit_info->src.format,
+ src_lev->stride,
+ src->layout);
+ unsigned dst_offset = dst_lev->offset +
+ blit_info->dst.box.z * dst_lev->layer_stride +
+ etna_compute_tileoffset(&blit_info->dst.box,
+ blit_info->dst.format,
+ dst_lev->stride,
+ dst->layout);
if (src_lev->padded_width <= ETNA_RS_WIDTH_MASK ||
dst_lev->padded_width <= ETNA_RS_WIDTH_MASK ||
ts_mem_config |= VIVS_TS_MEM_CONFIG_MSAA | msaa_format;
}
- uint32_t to_flush = 0;
-
- if (src->base.bind & PIPE_BIND_RENDER_TARGET)
- to_flush |= VIVS_GL_FLUSH_CACHE_COLOR;
- if (src->base.bind & PIPE_BIND_DEPTH_STENCIL)
- to_flush |= VIVS_GL_FLUSH_CACHE_DEPTH;
-
- if (to_flush) {
- etna_set_state(ctx->stream, VIVS_GL_FLUSH_CACHE, to_flush);
+ /* Always flush color and depth cache together before resolving. This works
+ * around artifacts that appear in some cases when scanning out a texture
+ * directly after it has been rendered to, such as rendering an animated web
+ * page in a QtWebEngine based WebView on GC2000. The artifacts look like
+ * the texture sampler samples zeroes instead of texture data in a small,
+ * irregular triangle in the lower right of each browser tile quad. Other
+ * attempts to avoid these artifacts, including a pipeline stall before the
+ * color flush or a TS cache flush afterwards, or flushing multiple times,
+ * with stalls before and after each flush, have shown no effect. */
+ if (src->base.bind & PIPE_BIND_RENDER_TARGET ||
+ src->base.bind & PIPE_BIND_DEPTH_STENCIL) {
+ etna_set_state(ctx->stream, VIVS_GL_FLUSH_CACHE,
+ VIVS_GL_FLUSH_CACHE_COLOR | VIVS_GL_FLUSH_CACHE_DEPTH);
etna_stall(ctx->stream, SYNC_RECIPIENT_RA, SYNC_RECIPIENT_PE);
+
+ if (src->levels[blit_info->src.level].ts_size &&
+ src->levels[blit_info->src.level].ts_valid)
+ etna_set_state(ctx->stream, VIVS_TS_FLUSH_CACHE, VIVS_TS_FLUSH_CACHE_FLUSH);
}
/* Set up color TS to source surface before blit, if needed */
memset(&reloc, 0, sizeof(struct etna_reloc));
reloc.bo = src->bo;
- reloc.offset = src_offset;
+ reloc.offset = src_lev->offset +
+ blit_info->src.box.z * src_lev->layer_stride;
reloc.flags = ETNA_RELOC_READ;
etna_set_state_reloc(ctx->stream, VIVS_TS_COLOR_SURFACE_BASE, &reloc);
{
struct etna_resource *rsc = etna_resource(prsc);
- if (rsc->scanout &&
- etna_resource_older(etna_resource(rsc->scanout->prime), rsc)) {
- etna_copy_resource(pctx, rsc->scanout->prime, prsc, 0, 0);
- etna_resource(rsc->scanout->prime)->seqno = rsc->seqno;
+ if (rsc->external) {
+ if (etna_resource_older(etna_resource(rsc->external), rsc)) {
+ etna_copy_resource(pctx, rsc->external, prsc, 0, 0);
+ etna_resource(rsc->external)->seqno = rsc->seqno;
+ }
} else if (etna_resource_needs_flush(rsc)) {
etna_copy_resource(pctx, prsc, prsc, 0, 0);
rsc->flush_seqno = rsc->seqno;
}
}
+void
+etna_copy_resource_box(struct pipe_context *pctx, struct pipe_resource *dst,
+ struct pipe_resource *src, int level,
+ struct pipe_box *box)
+{
+ assert(src->format == dst->format);
+ assert(src->array_size == dst->array_size);
+
+ struct pipe_blit_info blit = {};
+ blit.mask = util_format_get_mask(dst->format);
+ blit.filter = PIPE_TEX_FILTER_NEAREST;
+ blit.src.resource = src;
+ blit.src.format = src->format;
+ blit.src.box = *box;
+ blit.dst.resource = dst;
+ blit.dst.format = dst->format;
+ blit.dst.box = *box;
+
+ blit.dst.box.depth = blit.src.box.depth = 1;
+ blit.src.level = blit.dst.level = level;
+
+ for (int layer = 0; layer < dst->array_size; layer++) {
+ blit.src.box.z = blit.dst.box.z = layer;
+ pctx->blit(pctx, &blit);
+ }
+}
+
void
etna_clear_blit_init(struct pipe_context *pctx)
{