R600_COPY = R600_SAVE_FRAMEBUFFER | R600_SAVE_TEXTURES |
R600_DISABLE_RENDER_COND,
+ R600_BLIT = R600_SAVE_FRAMEBUFFER | R600_SAVE_TEXTURES |
+ R600_DISABLE_RENDER_COND,
+
R600_DECOMPRESS = R600_SAVE_FRAMEBUFFER | R600_DISABLE_RENDER_COND,
};
if (rctx->queued.named.viewport) {
util_blitter_save_viewport(rctx->blitter, &rctx->queued.named.viewport->viewport);
}
- util_blitter_save_vertex_buffers(rctx->blitter,
- rctx->nr_vertex_buffers,
- rctx->vertex_buffer);
+ util_blitter_save_vertex_buffer_slot(rctx->blitter, rctx->vertex_buffer);
util_blitter_save_so_targets(rctx->blitter, rctx->num_so_targets,
(struct pipe_stream_output_target**)rctx->so_targets);
if ((op & R600_DISABLE_RENDER_COND) && rctx->current_render_cond) {
rctx->saved_render_cond = rctx->current_render_cond;
+ rctx->saved_render_cond_cond = rctx->current_render_cond_cond;
rctx->saved_render_cond_mode = rctx->current_render_cond_mode;
- rctx->context.render_condition(&rctx->context, NULL, 0);
+ rctx->context.render_condition(&rctx->context, NULL, FALSE, 0);
}
}
if (rctx->saved_render_cond) {
rctx->context.render_condition(&rctx->context,
rctx->saved_render_cond,
+ rctx->saved_render_cond_cond,
rctx->saved_render_cond_mode);
rctx->saved_render_cond = NULL;
}
r600_context_queries_resume(rctx);
}
-static unsigned u_num_layers(struct pipe_resource *r, unsigned level)
-{
- switch (r->target) {
- case PIPE_TEXTURE_CUBE:
- return 6;
- case PIPE_TEXTURE_3D:
- return u_minify(r->depth0, level);
- case PIPE_TEXTURE_1D_ARRAY:
- return r->array_size;
- case PIPE_TEXTURE_2D_ARRAY:
- return r->array_size;
- default:
- return 1;
- }
-}
-
-void r600_blit_uncompress_depth(struct pipe_context *ctx, struct r600_resource_texture *texture)
+void si_blit_uncompress_depth(struct pipe_context *ctx,
+ struct r600_resource_texture *texture,
+ struct r600_resource_texture *staging,
+ unsigned first_level, unsigned last_level,
+ unsigned first_layer, unsigned last_layer)
{
struct r600_context *rctx = (struct r600_context *)ctx;
- unsigned layer, level;
+ unsigned layer, level, checked_last_layer, max_layer;
float depth = 1.0f;
+ const struct util_format_description *desc;
+ void *custom_dsa;
+ struct r600_resource_texture *flushed_depth_texture = staging ?
+ staging : texture->flushed_depth_texture;
- if (!texture->dirty_db)
+ if (!staging && !texture->dirty_db_mask)
return;
- for (level = 0; level <= texture->resource.b.b.last_level; level++) {
- unsigned num_layers = u_num_layers(&texture->resource.b.b, level);
+ desc = util_format_description(flushed_depth_texture->resource.b.b.format);
+ switch (util_format_has_depth(desc) | util_format_has_stencil(desc) << 1) {
+ default:
+ assert(!"No depth or stencil to uncompress");
+ case 3:
+ custom_dsa = rctx->custom_dsa_flush_depth_stencil;
+ break;
+ case 2:
+ custom_dsa = rctx->custom_dsa_flush_stencil;
+ break;
+ case 1:
+ custom_dsa = rctx->custom_dsa_flush_depth;
+ break;
+ }
+
+ for (level = first_level; level <= last_level; level++) {
+ if (!staging && !(texture->dirty_db_mask & (1 << level)))
+ continue;
- for (layer = 0; layer < num_layers; layer++) {
+ /* The smaller the mipmap level, the less layers there are
+ * as far as 3D textures are concerned. */
+ max_layer = util_max_layer(&texture->resource.b.b, level);
+ checked_last_layer = last_layer < max_layer ? last_layer : max_layer;
+
+ for (layer = first_layer; layer <= checked_last_layer; layer++) {
struct pipe_surface *zsurf, *cbsurf, surf_tmpl;
surf_tmpl.format = texture->real_format;
surf_tmpl.u.tex.level = level;
surf_tmpl.u.tex.first_layer = layer;
surf_tmpl.u.tex.last_layer = layer;
- surf_tmpl.usage = PIPE_BIND_DEPTH_STENCIL;
zsurf = ctx->create_surface(ctx, &texture->resource.b.b, &surf_tmpl);
- surf_tmpl.format = texture->flushed_depth_texture->real_format;
- surf_tmpl.usage = PIPE_BIND_RENDER_TARGET;
+ surf_tmpl.format = flushed_depth_texture->real_format;
cbsurf = ctx->create_surface(ctx,
- (struct pipe_resource*)texture->flushed_depth_texture, &surf_tmpl);
+ (struct pipe_resource*)flushed_depth_texture, &surf_tmpl);
r600_blitter_begin(ctx, R600_DECOMPRESS);
- util_blitter_custom_depth_stencil(rctx->blitter, zsurf, cbsurf, rctx->custom_dsa_flush, depth);
+ util_blitter_custom_depth_stencil(rctx->blitter, zsurf, cbsurf, ~0, custom_dsa, depth);
r600_blitter_end(ctx);
pipe_surface_reference(&zsurf, NULL);
pipe_surface_reference(&cbsurf, NULL);
}
- }
- texture->dirty_db = FALSE;
+ /* The texture will always be dirty if some layers aren't flushed.
+ * I don't think this case can occur though. */
+ if (!staging && first_layer == 0 && last_layer == max_layer) {
+ texture->dirty_db_mask &= ~(1 << level);
+ }
+ }
}
-void r600_flush_depth_textures(struct r600_context *rctx)
+static void si_blit_decompress_depth_in_place(struct r600_context *rctx,
+ struct r600_resource_texture *texture,
+ unsigned first_level, unsigned last_level,
+ unsigned first_layer, unsigned last_layer)
{
- unsigned int i;
+ struct pipe_surface *zsurf, surf_tmpl = {{0}};
+ unsigned layer, max_layer, checked_last_layer, level;
- /* FIXME: This handles fragment shader textures only. */
+ surf_tmpl.format = texture->resource.b.b.format;
- for (i = 0; i < rctx->ps_samplers.n_views; ++i) {
- struct si_pipe_sampler_view *view;
- struct r600_resource_texture *tex;
+ for (level = first_level; level <= last_level; level++) {
+ if (!(texture->dirty_db_mask & (1 << level)))
+ continue;
- view = rctx->ps_samplers.views[i];
- if (!view) continue;
+ surf_tmpl.u.tex.level = level;
- tex = (struct r600_resource_texture *)view->base.texture;
- if (!tex->depth)
- continue;
+ /* The smaller the mipmap level, the less layers there are
+ * as far as 3D textures are concerned. */
+ max_layer = util_max_layer(&texture->resource.b.b, level);
+ checked_last_layer = last_layer < max_layer ? last_layer : max_layer;
- if (tex->is_flushing_texture)
- continue;
+ for (layer = first_layer; layer <= checked_last_layer; layer++) {
+ surf_tmpl.u.tex.first_layer = layer;
+ surf_tmpl.u.tex.last_layer = layer;
+
+ zsurf = rctx->context.create_surface(&rctx->context, &texture->resource.b.b, &surf_tmpl);
+
+ r600_blitter_begin(&rctx->context, R600_DECOMPRESS);
+ util_blitter_custom_depth_stencil(rctx->blitter, zsurf, NULL, ~0,
+ rctx->custom_dsa_flush_inplace,
+ 1.0f);
+ r600_blitter_end(&rctx->context);
+
+ pipe_surface_reference(&zsurf, NULL);
+ }
- r600_blit_uncompress_depth(&rctx->context, tex);
+ /* The texture will always be dirty if some layers aren't flushed.
+ * I don't think this case occurs often though. */
+ if (first_layer == 0 && last_layer == max_layer) {
+ texture->dirty_db_mask &= ~(1 << level);
+ }
}
+}
+
+void si_flush_depth_textures(struct r600_context *rctx,
+ struct r600_textures_info *textures)
+{
+ unsigned i;
- /* also check CB here */
- for (i = 0; i < rctx->framebuffer.nr_cbufs; i++) {
+ for (i = 0; i < textures->n_views; ++i) {
+ struct pipe_sampler_view *view;
struct r600_resource_texture *tex;
- tex = (struct r600_resource_texture *)rctx->framebuffer.cbufs[i]->texture;
- if (!tex->depth)
- continue;
+ view = &textures->views[i]->base;
+ if (!view) continue;
- if (tex->is_flushing_texture)
+ tex = (struct r600_resource_texture *)view->texture;
+ if (!tex->is_depth || tex->is_flushing_texture)
continue;
- r600_blit_uncompress_depth(&rctx->context, tex);
+ si_blit_decompress_depth_in_place(rctx, tex,
+ view->u.tex.first_level, view->u.tex.last_level,
+ 0, util_max_layer(&tex->resource.b.b, view->u.tex.first_level));
}
}
r600_blitter_begin(ctx, R600_CLEAR);
util_blitter_clear(rctx->blitter, fb->width, fb->height,
- fb->nr_cbufs, buffers, fb->nr_cbufs ? fb->cbufs[0]->format : PIPE_FORMAT_NONE,
- color, depth, stencil);
+ buffers, color, depth, stencil);
r600_blitter_end(ctx);
}
r600_blitter_end(ctx);
}
-
-
-/* Copy a block of pixels from one surface to another using HW. */
-static void r600_hw_copy_region(struct pipe_context *ctx,
- struct pipe_resource *dst,
- unsigned dst_level,
- unsigned dstx, unsigned dsty, unsigned dstz,
- struct pipe_resource *src,
- unsigned src_level,
- const struct pipe_box *src_box)
-{
- struct r600_context *rctx = (struct r600_context *)ctx;
-
- r600_blitter_begin(ctx, R600_COPY);
- util_blitter_copy_texture(rctx->blitter, dst, dst_level, dstx, dsty, dstz,
- src, src_level, src_box, TRUE);
- r600_blitter_end(ctx);
-}
-
struct texture_orig_info {
unsigned format;
unsigned width0;
struct texture_orig_info *orig)
{
struct r600_resource_texture *rtex = (struct r600_resource_texture*)tex;
- struct r600_screen *rscreen = (struct r600_screen *)tex->screen;
unsigned pixsize = util_format_get_blocksize(rtex->real_format);
int new_format;
int new_height, new_width;
rtex->surface.level[level].npix_y = util_format_get_nblocksy(orig->format, orig->npix_y);
}
-static void r600_reset_blittable_to_compressed(struct pipe_resource *tex,
- unsigned level,
- struct texture_orig_info *orig)
+static void r600_change_format(struct pipe_resource *tex,
+ unsigned level,
+ struct texture_orig_info *orig,
+ enum pipe_format format)
+{
+ struct r600_resource_texture *rtex = (struct r600_resource_texture*)tex;
+
+ orig->format = tex->format;
+ orig->width0 = tex->width0;
+ orig->height0 = tex->height0;
+ orig->npix0_x = rtex->surface.level[0].npix_x;
+ orig->npix0_y = rtex->surface.level[0].npix_y;
+ orig->npix_x = rtex->surface.level[level].npix_x;
+ orig->npix_y = rtex->surface.level[level].npix_y;
+
+ tex->format = format;
+}
+
+static void r600_reset_blittable_to_orig(struct pipe_resource *tex,
+ unsigned level,
+ struct texture_orig_info *orig)
{
struct r600_resource_texture *rtex = (struct r600_resource_texture*)tex;
- struct r600_screen *rscreen = (struct r600_screen *)tex->screen;
tex->format = orig->format;
tex->width0 = orig->width0;
unsigned src_level,
const struct pipe_box *src_box)
{
+ struct r600_context *rctx = (struct r600_context *)ctx;
struct r600_resource_texture *rsrc = (struct r600_resource_texture*)src;
struct texture_orig_info orig_info[2];
struct pipe_box sbox;
- const struct pipe_box *psbox;
+ const struct pipe_box *psbox = src_box;
boolean restore_orig[2];
memset(orig_info, 0, sizeof(orig_info));
return;
}
- if (rsrc->depth && !rsrc->is_flushing_texture)
- r600_texture_depth_flush(ctx, src, FALSE);
+ /* This must be done before entering u_blitter to avoid recursion. */
+ if (rsrc->is_depth && !rsrc->is_flushing_texture) {
+ si_blit_decompress_depth_in_place(rctx, rsrc,
+ src_level, src_level,
+ src_box->z, src_box->z + src_box->depth - 1);
+ }
restore_orig[0] = restore_orig[1] = FALSE;
- if (util_format_is_compressed(src->format)) {
+ if (util_format_is_compressed(src->format) &&
+ util_format_is_compressed(dst->format)) {
r600_compressed_to_blittable(src, src_level, &orig_info[0]);
restore_orig[0] = TRUE;
sbox.x = util_format_get_nblocksx(orig_info[0].format, src_box->x);
sbox.height = util_format_get_nblocksy(orig_info[0].format, src_box->height);
sbox.depth = src_box->depth;
psbox=&sbox;
- } else
- psbox=src_box;
- if (util_format_is_compressed(dst->format)) {
r600_compressed_to_blittable(dst, dst_level, &orig_info[1]);
restore_orig[1] = TRUE;
/* translate the dst box as well */
dstx = util_format_get_nblocksx(orig_info[1].format, dstx);
dsty = util_format_get_nblocksy(orig_info[1].format, dsty);
+ } else if (!util_blitter_is_copy_supported(rctx->blitter, dst, src,
+ PIPE_MASK_RGBAZS)) {
+ unsigned blocksize = util_format_get_blocksize(src->format);
+
+ switch (blocksize) {
+ case 1:
+ r600_change_format(src, src_level, &orig_info[0],
+ PIPE_FORMAT_R8_UNORM);
+ r600_change_format(dst, dst_level, &orig_info[1],
+ PIPE_FORMAT_R8_UNORM);
+ break;
+ case 2:
+ r600_change_format(src, src_level, &orig_info[0],
+ PIPE_FORMAT_R8G8_UNORM);
+ r600_change_format(dst, dst_level, &orig_info[1],
+ PIPE_FORMAT_R8G8_UNORM);
+ break;
+ case 4:
+ r600_change_format(src, src_level, &orig_info[0],
+ PIPE_FORMAT_R8G8B8A8_UNORM);
+ r600_change_format(dst, dst_level, &orig_info[1],
+ PIPE_FORMAT_R8G8B8A8_UNORM);
+ break;
+ case 8:
+ r600_change_format(src, src_level, &orig_info[0],
+ PIPE_FORMAT_R16G16B16A16_UINT);
+ r600_change_format(dst, dst_level, &orig_info[1],
+ PIPE_FORMAT_R16G16B16A16_UINT);
+ break;
+ case 16:
+ r600_change_format(src, src_level, &orig_info[0],
+ PIPE_FORMAT_R32G32B32A32_UINT);
+ r600_change_format(dst, dst_level, &orig_info[1],
+ PIPE_FORMAT_R32G32B32A32_UINT);
+ break;
+ default:
+ fprintf(stderr, "Unhandled format %s with blocksize %u\n",
+ util_format_short_name(src->format), blocksize);
+ assert(0);
+ }
+ restore_orig[0] = TRUE;
+ restore_orig[1] = TRUE;
}
- r600_hw_copy_region(ctx, dst, dst_level, dstx, dsty, dstz,
- src, src_level, psbox);
+ r600_blitter_begin(ctx, R600_COPY);
+ util_blitter_copy_texture(rctx->blitter, dst, dst_level, dstx, dsty, dstz,
+ src, src_level, psbox, PIPE_MASK_RGBAZS, TRUE);
+ r600_blitter_end(ctx);
if (restore_orig[0])
- r600_reset_blittable_to_compressed(src, src_level, &orig_info[0]);
+ r600_reset_blittable_to_orig(src, src_level, &orig_info[0]);
if (restore_orig[1])
- r600_reset_blittable_to_compressed(dst, dst_level, &orig_info[1]);
+ r600_reset_blittable_to_orig(dst, dst_level, &orig_info[1]);
+}
+
+static void si_blit(struct pipe_context *ctx,
+ const struct pipe_blit_info *info)
+{
+ struct r600_context *rctx = (struct r600_context*)ctx;
+ struct r600_resource_texture *rsrc = (struct r600_resource_texture*)info->src.resource;
+
+ assert(util_blitter_is_blit_supported(rctx->blitter, info));
+
+ if (info->src.resource->nr_samples > 1 &&
+ info->dst.resource->nr_samples <= 1 &&
+ !util_format_is_depth_or_stencil(info->src.resource->format) &&
+ !util_format_is_pure_integer(info->src.resource->format)) {
+ debug_printf("radeonsi: color resolve is unimplemented\n");
+ return;
+ }
+
+ if (rsrc->is_depth && !rsrc->is_flushing_texture) {
+ si_blit_decompress_depth_in_place(rctx, rsrc,
+ info->src.level, info->src.level,
+ info->src.box.z,
+ info->src.box.z + info->src.box.depth - 1);
+ }
+
+ r600_blitter_begin(ctx, R600_BLIT);
+ util_blitter_blit(rctx->blitter, info);
+ r600_blitter_end(ctx);
}
-void r600_init_blit_functions(struct r600_context *rctx)
+void si_init_blit_functions(struct r600_context *rctx)
{
rctx->context.clear = r600_clear;
rctx->context.clear_render_target = r600_clear_render_target;
rctx->context.clear_depth_stencil = r600_clear_depth_stencil;
rctx->context.resource_copy_region = r600_resource_copy_region;
-}
-
-void r600_blit_push_depth(struct pipe_context *ctx, struct r600_resource_texture *texture)
-{
- struct pipe_box sbox;
-
- sbox.x = sbox.y = sbox.z = 0;
- sbox.width = texture->resource.b.b.width0;
- sbox.height = texture->resource.b.b.height0;
- /* XXX that might be wrong */
- sbox.depth = 1;
-
- r600_hw_copy_region(ctx, (struct pipe_resource *)texture, 0,
- 0, 0, 0,
- (struct pipe_resource *)texture->flushed_depth_texture, 0,
- &sbox);
+ rctx->context.blit = si_blit;
}