summaryrefslogtreecommitdiffstats
path: root/src/gallium/drivers/r600/r600_blit.c
diff options
context:
space:
mode:
authorGrigori Goronzy <[email protected]>2013-06-12 00:04:01 +0200
committerMarek Olšák <[email protected]>2013-07-01 03:02:43 +0200
commit30004b20c2ae5ee78619f441b01afef0d4d992f0 (patch)
treea0c2f26db57707a29fe287c470f61433cb59b09a /src/gallium/drivers/r600/r600_blit.c
parentb1693194eee7e99ef8abb6c8319834bd93879400 (diff)
r600g: implement fast color clears for MSAA on evergreen+
Allows MSAA colorbuffers, which have a CMASK automatically and don't need any further special handling, to be fast cleared. Instead of clearing the buffer, set the clear color and the CMASK to the cleared state. Fast clear is used only when all bound colorbuffers fulfill certain conditions: a CMASK is required, we have to be able to create a clear color value for the format and the texture mustn't contain multiple images. Technically, it should be possible to support array textures and cubemaps if all images are attached to the framebuffer, but this does not appear to be common. v2: fix fast clear check v3: Marek: - disable fast clear with 128-bit formats, which are unsupported - set tex->dirty_level_mask in r600_clear, so that the driver knows the resource must be decompressed/expanded - return early from r600_clear if there's nothing else to do Signed-off-by: Marek Olšák <[email protected]>
Diffstat (limited to 'src/gallium/drivers/r600/r600_blit.c')
-rw-r--r--src/gallium/drivers/r600/r600_blit.c72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/gallium/drivers/r600/r600_blit.c b/src/gallium/drivers/r600/r600_blit.c
index dcc397851fc..1cdd1c81109 100644
--- a/src/gallium/drivers/r600/r600_blit.c
+++ b/src/gallium/drivers/r600/r600_blit.c
@@ -413,6 +413,58 @@ static boolean is_simple_msaa_resolve(const struct pipe_blit_info *info)
dst_tile_mode >= RADEON_SURF_MODE_1D;
}
+static void r600_clear_buffer(struct pipe_context *ctx, struct pipe_resource *dst,
+ unsigned offset, unsigned size, unsigned char value);
+
+static void evergreen_set_clear_color(struct pipe_context *ctx,
+ struct pipe_surface *cbuf,
+ const union pipe_color_union *color)
+{
+ struct r600_context *rctx = (struct r600_context *)ctx;
+ struct pipe_framebuffer_state *fb = &rctx->framebuffer.state;
+ unsigned *clear_value = ((struct r600_texture *)cbuf->texture)->color_clear_value;
+ union util_color uc;
+
+ memset(&uc, 0, sizeof(uc));
+ util_pack_color(color->f, fb->cbufs[0]->format, &uc);
+ memcpy(clear_value, &uc, 2 * sizeof(uint32_t));
+}
+
+static bool can_fast_clear_color(struct pipe_context *ctx)
+{
+ struct r600_context *rctx = (struct r600_context *)ctx;
+ struct pipe_framebuffer_state *fb = &rctx->framebuffer.state;
+ int i;
+
+ if (rctx->chip_class < EVERGREEN) {
+ return false;
+ }
+
+ for (i = 0; i < fb->nr_cbufs; i++) {
+ struct r600_texture *tex = (struct r600_texture *)fb->cbufs[i]->texture;
+ int target = fb->cbufs[i]->texture->target;
+
+ if (tex->cmask_size == 0) {
+ return false;
+ }
+
+ /* cannot pack color for pure integer formats */
+ /* 128-bit formats are unuspported */
+ if (util_format_is_pure_integer(fb->cbufs[i]->format) ||
+ util_format_get_blocksizebits(fb->cbufs[i]->format) > 64) {
+ return false;
+ }
+
+ /* textures with multiple images are not supported */
+ if (target != PIPE_TEXTURE_2D && target != PIPE_TEXTURE_RECT &&
+ target != PIPE_TEXTURE_1D) {
+ return false;
+ }
+ }
+
+ return true;
+}
+
static void r600_clear(struct pipe_context *ctx, unsigned buffers,
const union pipe_color_union *color,
double depth, unsigned stencil)
@@ -420,6 +472,26 @@ static void r600_clear(struct pipe_context *ctx, unsigned buffers,
struct r600_context *rctx = (struct r600_context *)ctx;
struct pipe_framebuffer_state *fb = &rctx->framebuffer.state;
+ /* fast color clear on AA framebuffers (EG+) */
+ if ((buffers & PIPE_CLEAR_COLOR) && can_fast_clear_color(ctx)) {
+ int i;
+
+ for (i = 0; i < fb->nr_cbufs; i++) {
+ struct r600_texture *tex = (struct r600_texture *)fb->cbufs[i]->texture;
+
+ evergreen_set_clear_color(ctx, fb->cbufs[i], color);
+ r600_clear_buffer(ctx, fb->cbufs[i]->texture,
+ tex->cmask_offset, tex->cmask_size, 0);
+ tex->dirty_level_mask |= 1 << fb->cbufs[i]->u.tex.level;
+ }
+
+ rctx->framebuffer.atom.dirty = true;
+
+ buffers &= ~PIPE_CLEAR_COLOR;
+ if (!buffers)
+ return;
+ }
+
/* if hyperz enabled just clear hyperz */
if (fb->zsbuf && (buffers & PIPE_CLEAR_DEPTH)) {
struct r600_texture *rtex;