+ src_templ.format = dst_templ.format;
+ }
+
+ /* Handle compressed formats. */
+ if (layout == UTIL_FORMAT_LAYOUT_S3TC ||
+ layout == UTIL_FORMAT_LAYOUT_RGTC) {
+ assert(src_templ.format == dst_templ.format);
+
+ box = *src_box;
+ src_box = &box;
+
+ dst_width0 = align(dst_width0, 4);
+ dst_height0 = align(dst_height0, 4);
+ src_width0 = align(src_width0, 4);
+ src_height0 = align(src_height0, 4);
+ box.width = align(box.width, 4);
+ box.height = align(box.height, 4);
+
+ switch (util_format_get_blocksize(dst_templ.format)) {
+ case 8:
+ /* one 4x4 pixel block has 8 bytes.
+ * we set 1 pixel = 4 bytes ===> 1 block corrensponds to 2 pixels. */
+ dst_templ.format = PIPE_FORMAT_R8G8B8A8_UNORM;
+ dst_width0 = dst_width0 / 2;
+ src_width0 = src_width0 / 2;
+ dstx /= 2;
+ box.x /= 2;
+ box.width /= 2;
+ break;
+ case 16:
+ /* one 4x4 pixel block has 16 bytes.
+ * we set 1 pixel = 4 bytes ===> 1 block corresponds to 4 pixels. */
+ dst_templ.format = PIPE_FORMAT_R8G8B8A8_UNORM;
+ break;
+ }
+ src_templ.format = dst_templ.format;
+
+ dst_height0 = dst_height0 / 4;
+ src_height0 = src_height0 / 4;
+ dsty /= 4;
+ box.y /= 4;
+ box.height /= 4;
+ }
+
+ /* Fallback for textures. */
+ if (!screen->is_format_supported(screen, dst_templ.format,
+ dst->target, dst->nr_samples,
+ dst->nr_storage_samples,
+ PIPE_BIND_RENDER_TARGET) ||
+ !screen->is_format_supported(screen, src_templ.format,
+ src->target, src->nr_samples,
+ src->nr_storage_samples,
+ PIPE_BIND_SAMPLER_VIEW)) {
+ assert(0 && "this shouldn't happen, update r300_is_blit_supported");
+ util_resource_copy_region(pipe, dst, dst_level, dstx, dsty, dstz,
+ src, src_level, src_box);
+ return;
+ }
+
+ /* Decompress ZMASK. */
+ if (r300->zmask_in_use && !r300->locked_zbuffer) {
+ if (fb->zsbuf->texture == src ||
+ fb->zsbuf->texture == dst) {
+ r300_decompress_zmask(r300);
+ }
+ }
+
+ dst_view = r300_create_surface_custom(pipe, dst, &dst_templ, dst_width0, dst_height0);
+ src_view = r300_create_sampler_view_custom(pipe, src, &src_templ, src_width0, src_height0);
+
+ u_box_3d(dstx, dsty, dstz, abs(src_box->width), abs(src_box->height),
+ abs(src_box->depth), &dstbox);
+
+ r300_blitter_begin(r300, R300_COPY);
+ util_blitter_blit_generic(r300->blitter, dst_view, &dstbox,
+ src_view, src_box, src_width0, src_height0,
+ PIPE_MASK_RGBAZS, PIPE_TEX_FILTER_NEAREST, NULL,
+ FALSE);
+ r300_blitter_end(r300);
+
+ pipe_surface_reference(&dst_view, NULL);
+ pipe_sampler_view_reference(&src_view, NULL);
+}
+
+static boolean r300_is_simple_msaa_resolve(const struct pipe_blit_info *info)
+{
+ unsigned dst_width = u_minify(info->dst.resource->width0, info->dst.level);
+ unsigned dst_height = u_minify(info->dst.resource->height0, info->dst.level);
+
+ return info->src.resource->nr_samples > 1 &&
+ info->dst.resource->nr_samples <= 1 &&
+ info->dst.resource->format == info->src.resource->format &&
+ info->dst.resource->format == info->dst.format &&
+ info->src.resource->format == info->src.format &&
+ !info->scissor_enable &&
+ info->mask == PIPE_MASK_RGBA &&
+ dst_width == info->src.resource->width0 &&
+ dst_height == info->src.resource->height0 &&
+ info->dst.box.x == 0 &&
+ info->dst.box.y == 0 &&
+ info->dst.box.width == dst_width &&
+ info->dst.box.height == dst_height &&
+ info->src.box.x == 0 &&
+ info->src.box.y == 0 &&
+ info->src.box.width == dst_width &&
+ info->src.box.height == dst_height &&
+ (r300_resource(info->dst.resource)->tex.microtile != RADEON_LAYOUT_LINEAR ||
+ r300_resource(info->dst.resource)->tex.macrotile[info->dst.level] != RADEON_LAYOUT_LINEAR);
+}
+
+static void r300_simple_msaa_resolve(struct pipe_context *pipe,
+ struct pipe_resource *dst,
+ unsigned dst_level,
+ unsigned dst_layer,
+ struct pipe_resource *src,
+ enum pipe_format format)
+{
+ struct r300_context *r300 = r300_context(pipe);
+ struct r300_surface *srcsurf, *dstsurf;
+ struct pipe_surface surf_tmpl;
+ struct r300_aa_state *aa = (struct r300_aa_state*)r300->aa_state.state;
+
+ memset(&surf_tmpl, 0, sizeof(surf_tmpl));
+ surf_tmpl.format = format;
+ srcsurf = r300_surface(pipe->create_surface(pipe, src, &surf_tmpl));
+
+ surf_tmpl.format = format;
+ surf_tmpl.u.tex.level = dst_level;
+ surf_tmpl.u.tex.first_layer =
+ surf_tmpl.u.tex.last_layer = dst_layer;
+ dstsurf = r300_surface(pipe->create_surface(pipe, dst, &surf_tmpl));
+
+ /* COLORPITCH should contain the tiling info of the resolve buffer.
+ * The tiling of the AA buffer isn't programmable anyway. */
+ srcsurf->pitch &= ~(R300_COLOR_TILE(1) | R300_COLOR_MICROTILE(3));
+ srcsurf->pitch |= dstsurf->pitch & (R300_COLOR_TILE(1) | R300_COLOR_MICROTILE(3));
+
+ /* Enable AA resolve. */
+ aa->dest = dstsurf;
+ r300->aa_state.size = 8;
+ r300_mark_atom_dirty(r300, &r300->aa_state);
+
+ /* Resolve the surface. */
+ r300_blitter_begin(r300, R300_CLEAR_SURFACE);
+ util_blitter_custom_color(r300->blitter, &srcsurf->base, NULL);
+ r300_blitter_end(r300);
+
+ /* Disable AA resolve. */
+ aa->dest = NULL;
+ r300->aa_state.size = 4;
+ r300_mark_atom_dirty(r300, &r300->aa_state);
+
+ pipe_surface_reference((struct pipe_surface**)&srcsurf, NULL);
+ pipe_surface_reference((struct pipe_surface**)&dstsurf, NULL);
+}
+
+static void r300_msaa_resolve(struct pipe_context *pipe,
+ const struct pipe_blit_info *info)
+{
+ struct r300_context *r300 = r300_context(pipe);
+ struct pipe_screen *screen = pipe->screen;
+ struct pipe_resource *tmp, templ;
+ struct pipe_blit_info blit;
+
+ assert(info->src.level == 0);
+ assert(info->src.box.z == 0);
+ assert(info->src.box.depth == 1);
+ assert(info->dst.box.depth == 1);
+
+ if (r300_is_simple_msaa_resolve(info)) {
+ r300_simple_msaa_resolve(pipe, info->dst.resource, info->dst.level,
+ info->dst.box.z, info->src.resource,
+ info->src.format);
+ return;