* USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "r600_pipe.h"
+#include "compute_memory_pool.h"
+#include "evergreen_compute.h"
#include "util/u_surface.h"
-#include "util/u_blitter.h"
#include "util/u_format.h"
#include "evergreend.h"
R600_COPY_TEXTURE = R600_SAVE_FRAGMENT_STATE | R600_SAVE_FRAMEBUFFER | R600_SAVE_TEXTURES |
R600_DISABLE_RENDER_COND,
- R600_BLIT = R600_SAVE_FRAGMENT_STATE | R600_SAVE_FRAMEBUFFER | R600_SAVE_TEXTURES |
- R600_DISABLE_RENDER_COND,
+ R600_BLIT = R600_SAVE_FRAGMENT_STATE | R600_SAVE_FRAMEBUFFER | R600_SAVE_TEXTURES,
R600_DECOMPRESS = R600_SAVE_FRAGMENT_STATE | R600_SAVE_FRAMEBUFFER | R600_DISABLE_RENDER_COND,
- R600_COLOR_RESOLVE = R600_SAVE_FRAGMENT_STATE | R600_SAVE_FRAMEBUFFER | R600_DISABLE_RENDER_COND
+ R600_COLOR_RESOLVE = R600_SAVE_FRAGMENT_STATE | R600_SAVE_FRAMEBUFFER
};
static void r600_blitter_begin(struct pipe_context *ctx, enum r600_blitter_op op)
return true;
}
-static void r600_clear_buffer(struct pipe_context *ctx, struct pipe_resource *dst,
- unsigned offset, unsigned size, unsigned value);
-
-static void evergreen_set_clear_color(struct pipe_surface *cbuf,
- const union pipe_color_union *color)
-{
- unsigned *clear_value = ((struct r600_texture *)cbuf->texture)->color_clear_value;
- union util_color uc;
-
- memset(&uc, 0, sizeof(uc));
-
- if (util_format_is_pure_uint(cbuf->format)) {
- util_format_write_4ui(cbuf->format, color->ui, 0, &uc, 0, 0, 0, 1, 1);
- } else if (util_format_is_pure_sint(cbuf->format)) {
- util_format_write_4i(cbuf->format, color->i, 0, &uc, 0, 0, 0, 1, 1);
- } else {
- util_pack_color(color->f, cbuf->format, &uc);
- }
-
- memcpy(clear_value, &uc, 2 * sizeof(uint32_t));
-}
-
-static void r600_try_fast_color_clear(struct r600_context *rctx, unsigned *buffers,
- const union pipe_color_union *color)
-{
- struct pipe_framebuffer_state *fb = &rctx->framebuffer.state;
- int i;
-
- for (i = 0; i < fb->nr_cbufs; i++) {
- struct r600_texture *tex;
- unsigned clear_bit = PIPE_CLEAR_COLOR0 << i;
-
- if (!fb->cbufs[i])
- continue;
-
- /* if this colorbuffer is not being cleared */
- if (!(*buffers & clear_bit))
- continue;
-
- tex = (struct r600_texture *)fb->cbufs[i]->texture;
-
- /* 128-bit formats are unusupported */
- if (util_format_get_blocksizebits(fb->cbufs[i]->format) > 64) {
- continue;
- }
-
- /* the clear is allowed if all layers are bound */
- if (fb->cbufs[i]->u.tex.first_layer != 0 ||
- fb->cbufs[i]->u.tex.last_layer != util_max_layer(&tex->resource.b.b, 0)) {
- continue;
- }
-
- /* cannot clear mipmapped textures */
- if (fb->cbufs[i]->texture->last_level != 0) {
- continue;
- }
-
- /* only supported on tiled surfaces */
- if (tex->surface.level[0].mode < RADEON_SURF_MODE_1D) {
- continue;
- }
-
- /* ensure CMASK is enabled */
- r600_texture_alloc_cmask_separate(&rctx->screen->b, tex);
- if (tex->cmask.size == 0) {
- continue;
- }
-
- /* Do the fast clear. */
- evergreen_set_clear_color(fb->cbufs[i], color);
- r600_clear_buffer(&rctx->b.b, &tex->cmask_buffer->b.b,
- tex->cmask.offset, tex->cmask.size, 0);
-
- tex->dirty_level_mask |= 1 << fb->cbufs[i]->u.tex.level;
- rctx->framebuffer.atom.dirty = true;
- *buffers &= ~clear_bit;
- }
-}
-
static void r600_clear(struct pipe_context *ctx, unsigned buffers,
const union pipe_color_union *color,
double depth, unsigned stencil)
struct pipe_framebuffer_state *fb = &rctx->framebuffer.state;
if (buffers & PIPE_CLEAR_COLOR && rctx->b.chip_class >= EVERGREEN) {
- r600_try_fast_color_clear(rctx, &buffers, color);
+ evergreen_do_fast_color_clear(&rctx->b, fb, &rctx->framebuffer.atom,
+ &buffers, color);
}
if (buffers & PIPE_CLEAR_COLOR) {
* disable fast clear for texture array.
*/
/* Only use htile for first level */
- if (rtex->htile_buffer && !level && rtex->surface.array_size == 1) {
+ if (rtex->htile_buffer && !level &&
+ fb->zsbuf->u.tex.first_layer == 0 &&
+ fb->zsbuf->u.tex.last_layer == util_max_layer(&rtex->resource.b.b, level)) {
if (rtex->depth_clear_value != depth) {
rtex->depth_clear_value = depth;
rctx->db_state.atom.dirty = true;
}
r600_blitter_begin(ctx, R600_CLEAR);
- util_blitter_clear(rctx->blitter, fb->width, fb->height, 1,
+ util_blitter_clear(rctx->blitter, fb->width, fb->height,
+ util_framebuffer_get_num_layers(fb),
buffers, color, depth, stencil);
r600_blitter_end(ctx);
} else {
util_resource_copy_region(ctx, dst, 0, dstx, 0, 0, src, 0, src_box);
}
+
+ /* The index buffer (VGT) doesn't seem to see the result of the copying.
+ * Can we somehow flush the index buffer cache? Starting a new IB seems
+ * to do the trick. */
+ if (rctx->b.chip_class <= R700)
+ rctx->b.rings.gfx.flush(ctx, RADEON_FLUSH_ASYNC, NULL);
}
/**
* into a single global resource (r600_screen::global_pool). The means
* they don't have their own cs_buf handle, so they cannot be passed
* to r600_copy_buffer() and must be handled separately.
- *
- * XXX: It should be possible to implement this function using
- * r600_copy_buffer() by passing the memory_pool resource as both src
- * and dst and updating dstx and src_box to point to the correct offsets.
- * This would likely perform better than the current implementation.
*/
static void r600_copy_global_buffer(struct pipe_context *ctx,
struct pipe_resource *dst, unsigned
dstx, struct pipe_resource *src,
const struct pipe_box *src_box)
{
- struct pipe_box dst_box; struct pipe_transfer *src_pxfer,
- *dst_pxfer;
-
- u_box_1d(dstx, src_box->width, &dst_box);
- void *src_ptr = ctx->transfer_map(ctx, src, 0, PIPE_TRANSFER_READ,
- src_box, &src_pxfer);
- void *dst_ptr = ctx->transfer_map(ctx, dst, 0, PIPE_TRANSFER_WRITE,
- &dst_box, &dst_pxfer);
- memcpy(dst_ptr, src_ptr, src_box->width);
-
- ctx->transfer_unmap(ctx, src_pxfer);
- ctx->transfer_unmap(ctx, dst_pxfer);
+ struct r600_context *rctx = (struct r600_context*)ctx;
+ struct compute_memory_pool *pool = rctx->screen->global_pool;
+ struct pipe_box new_src_box = *src_box;
+
+ if (src->bind & PIPE_BIND_GLOBAL) {
+ struct r600_resource_global *rsrc =
+ (struct r600_resource_global *)src;
+ struct compute_memory_item *item = rsrc->chunk;
+
+ if (is_item_in_pool(item)) {
+ new_src_box.x += 4 * item->start_in_dw;
+ src = (struct pipe_resource *)pool->bo;
+ } else {
+ if (item->real_buffer == NULL) {
+ item->real_buffer = (struct r600_resource*)
+ r600_compute_buffer_alloc_vram(pool->screen,
+ item->size_in_dw * 4);
+ }
+ src = (struct pipe_resource*)item->real_buffer;
+ }
+ }
+ if (dst->bind & PIPE_BIND_GLOBAL) {
+ struct r600_resource_global *rdst =
+ (struct r600_resource_global *)dst;
+ struct compute_memory_item *item = rdst->chunk;
+
+ if (is_item_in_pool(item)) {
+ dstx += 4 * item->start_in_dw;
+ dst = (struct pipe_resource *)pool->bo;
+ } else {
+ if (item->real_buffer == NULL) {
+ item->real_buffer = (struct r600_resource*)
+ r600_compute_buffer_alloc_vram(pool->screen,
+ item->size_in_dw * 4);
+ }
+ dst = (struct pipe_resource*)item->real_buffer;
+ }
+ }
+
+ r600_copy_buffer(ctx, dst, dstx, src, &new_src_box);
}
static void r600_clear_buffer(struct pipe_context *ctx, struct pipe_resource *dst,
- unsigned offset, unsigned size, unsigned value)
+ unsigned offset, unsigned size, unsigned value,
+ bool is_framebuffer)
{
struct r600_context *rctx = (struct r600_context*)ctx;
}
}
-static bool util_format_is_subsampled_2x1_32bpp(enum pipe_format format)
-{
- const struct util_format_description *desc = util_format_description(format);
-
- return desc->layout == UTIL_FORMAT_LAYOUT_SUBSAMPLED &&
- desc->block.width == 2 &&
- desc->block.height == 1 &&
- desc->block.bits == 32;
-}
-
-static void r600_resource_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)
+void r600_resource_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;
struct pipe_surface *dst_view, dst_templ;
src_force_level = src_level;
} else if (!util_blitter_is_copy_supported(rctx->blitter, dst, src)) {
- if (util_format_is_subsampled_2x1_32bpp(src->format)) {
+ if (util_format_is_subsampled_422(src->format)) {
src_templ.format = PIPE_FORMAT_R8G8B8A8_UINT;
dst_templ.format = PIPE_FORMAT_R8G8B8A8_UINT;
info->src.box.width == dst_width &&
info->src.box.height == dst_height &&
info->src.box.depth == 1 &&
- dst->surface.level[info->dst.level].mode >= RADEON_SURF_MODE_1D) {
- r600_blitter_begin(ctx, R600_COLOR_RESOLVE);
+ dst->surface.level[info->dst.level].mode >= RADEON_SURF_MODE_1D &&
+ (!dst->cmask.size || !dst->dirty_level_mask) /* dst cannot be fast-cleared */) {
+ r600_blitter_begin(ctx, R600_COLOR_RESOLVE |
+ (info->render_condition_enable ? 0 : R600_DISABLE_RENDER_COND));
util_blitter_custom_resolve_color(rctx->blitter,
info->dst.resource, info->dst.level,
info->dst.box.z,
return; /* error */
}
- r600_blitter_begin(ctx, R600_BLIT);
+ if (rctx->screen->b.debug_flags & DBG_FORCE_DMA &&
+ util_try_blit_via_copy_region(ctx, info))
+ return;
+
+ r600_blitter_begin(ctx, R600_BLIT |
+ (info->render_condition_enable ? 0 : R600_DISABLE_RENDER_COND));
util_blitter_blit(rctx->blitter, info);
r600_blitter_end(ctx);
}
if (!rtex->is_depth && rtex->cmask.size) {
r600_blit_decompress_color(ctx, rtex, 0, res->last_level,
- 0, res->array_size - 1);
+ 0, util_max_layer(res, 0));
}
}