etnaviv: call util_blitter_save_fragment_constant_buffer_slot(..)
[mesa.git] / src / gallium / drivers / etnaviv / etnaviv_clear_blit.c
index ae5300a24d41ca381ad7c194ef7ba918748b06eb..3619ea5bb77f49786b8deda9431acd812361ba28 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "hw/common.xml.h"
 
+#include "etnaviv_blt.h"
 #include "etnaviv_context.h"
 #include "etnaviv_emit.h"
 #include "etnaviv_format.h"
 void
 etna_blit_save_state(struct etna_context *ctx)
 {
+   util_blitter_save_fragment_constant_buffer_slot(ctx->blitter,
+                                                   ctx->constant_buffer[PIPE_SHADER_FRAGMENT].cb);
    util_blitter_save_vertex_buffer_slot(ctx->blitter, ctx->vertex_buffer.vb);
    util_blitter_save_vertex_elements(ctx->blitter, ctx->vertex_elements);
    util_blitter_save_vertex_shader(ctx->blitter, ctx->shader.bind_vs);
    util_blitter_save_rasterizer(ctx->blitter, ctx->rasterizer);
    util_blitter_save_viewport(ctx->blitter, &ctx->viewport_s);
-   util_blitter_save_scissor(ctx->blitter, &ctx->scissor_s);
+   util_blitter_save_scissor(ctx->blitter, &ctx->scissor);
    util_blitter_save_fragment_shader(ctx->blitter, ctx->shader.bind_fs);
    util_blitter_save_blend(ctx->blitter, ctx->blend);
    util_blitter_save_depth_stencil_alpha(ctx->blitter, ctx->zsa);
@@ -65,15 +68,29 @@ etna_blit_save_state(struct etna_context *ctx)
          ctx->num_fragment_sampler_views, ctx->sampler_view);
 }
 
-uint32_t
-etna_clear_blit_pack_rgba(enum pipe_format format, const float *rgba)
+uint64_t
+etna_clear_blit_pack_rgba(enum pipe_format format, const union pipe_color_union *color)
 {
    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] & 0xffff);
-   else
-      return uc.ui[0];
+
+   if (util_format_is_pure_uint(format)) {
+      util_format_write_4ui(format, color->ui, 0, &uc, 0, 0, 0, 1, 1);
+   } else if (util_format_is_pure_sint(format)) {
+      util_format_write_4i(format, color->i, 0, &uc, 0, 0, 0, 1, 1);
+   } else {
+      util_pack_color(color->f, format, &uc);
+   }
+
+   switch (util_format_get_blocksize(format)) {
+   case 1:
+      uc.ui[0] = uc.ui[0] << 8 | (uc.ui[0] & 0xff);
+   case 2:
+      uc.ui[0] =  uc.ui[0] << 16 | (uc.ui[0] & 0xffff);
+   case 4:
+      uc.ui[1] = uc.ui[0];
+   default:
+      return (uint64_t) uc.ui[1] << 32 | uc.ui[0];
+   }
 }
 
 static void
@@ -113,9 +130,6 @@ etna_resource_copy_region(struct pipe_context *pctx, struct pipe_resource *dst,
 {
    struct etna_context *ctx = etna_context(pctx);
 
-   /* The resource must be of the same format. */
-   assert(src->format == dst->format);
-
    /* XXX we can use the RS as a literal copy engine here
     * the only complexity is tiling; the size of the boxes needs to be aligned
     * to the tile size
@@ -140,10 +154,10 @@ etna_flush_resource(struct pipe_context *pctx, struct pipe_resource *prsc)
 {
    struct etna_resource *rsc = etna_resource(prsc);
 
-   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;
+   if (rsc->render) {
+      if (etna_resource_older(rsc, etna_resource(rsc->render))) {
+         etna_copy_resource(pctx, prsc, rsc->render, 0, 0);
+         rsc->seqno = etna_resource(rsc->render)->seqno;
       }
    } else if (etna_resource_needs_flush(rsc)) {
       etna_copy_resource(pctx, prsc, prsc, 0, 0);
@@ -178,9 +192,14 @@ etna_copy_resource(struct pipe_context *pctx, struct pipe_resource *dst,
          MIN2(src_priv->levels[level].padded_width, dst_priv->levels[level].padded_width);
       blit.src.box.height = blit.dst.box.height =
          MIN2(src_priv->levels[level].padded_height, dst_priv->levels[level].padded_height);
+      unsigned depth = MIN2(src_priv->levels[level].depth, dst_priv->levels[level].depth);
+      if (dst->array_size > 1) {
+         assert(depth == 1); /* no array of 3d texture */
+         depth = dst->array_size;
+      }
 
-      for (int layer = 0; layer < dst->array_size; layer++) {
-         blit.src.box.z = blit.dst.box.z = layer;
+      for (int z = 0; z < depth; z++) {
+         blit.src.box.z = blit.dst.box.z = z;
          pctx->blit(pctx, &blit);
       }
    }
@@ -207,8 +226,8 @@ etna_copy_resource_box(struct pipe_context *pctx, struct pipe_resource *dst,
    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;
+   for (int z = 0; z < box->depth; z++) {
+      blit.src.box.z = blit.dst.box.z = box->z + z;
       pctx->blit(pctx, &blit);
    }
 }
@@ -216,10 +235,16 @@ etna_copy_resource_box(struct pipe_context *pctx, struct pipe_resource *dst,
 void
 etna_clear_blit_init(struct pipe_context *pctx)
 {
+   struct etna_context *ctx = etna_context(pctx);
+   struct etna_screen *screen = ctx->screen;
+
    pctx->clear_render_target = etna_clear_render_target;
    pctx->clear_depth_stencil = etna_clear_depth_stencil;
    pctx->resource_copy_region = etna_resource_copy_region;
    pctx->flush_resource = etna_flush_resource;
 
-   etna_clear_blit_rs_init(pctx);
+   if (screen->specs.use_blt)
+      etna_clear_blit_blt_init(pctx);
+   else
+      etna_clear_blit_rs_init(pctx);
 }