gallium/u_blitter: use draw_rectangle for all blits except cubemaps
authorMarek Olšák <marek.olsak@amd.com>
Thu, 17 Aug 2017 01:32:23 +0000 (03:32 +0200)
committerMarek Olšák <marek.olsak@amd.com>
Mon, 11 Sep 2017 00:10:24 +0000 (02:10 +0200)
Add ZW coordinates to the draw_rectangle callback and use it.

Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
Tested-by: Brian Paul <brianp@vmware.com>
src/gallium/auxiliary/util/u_blitter.c
src/gallium/auxiliary/util/u_blitter.h
src/gallium/drivers/r300/r300_render.c
src/gallium/drivers/radeon/r600_pipe_common.c

index fff598d61e2df652c176d46de38eef25b8027c14..f7606a6a1d0c424d7e3c7c1af3d5a325838ded68 100644 (file)
@@ -755,8 +755,9 @@ static void blitter_set_clear_color(struct blitter_context_priv *ctx,
 
 static void get_texcoords(struct pipe_sampler_view *src,
                           unsigned src_width0, unsigned src_height0,
-                          int x1, int y1, int x2, int y2, bool uses_txf,
-                          union blitter_attrib *out)
+                          int x1, int y1, int x2, int y2,
+                          float layer, unsigned sample,
+                          bool uses_txf, union blitter_attrib *out)
 {
    unsigned level = src->u.tex.first_level;
    bool normalized = !uses_txf &&
@@ -774,49 +775,9 @@ static void get_texcoords(struct pipe_sampler_view *src,
       out->texcoord.x2 = x2;
       out->texcoord.y2 = y2;
    }
-}
 
-static void set_texcoords_in_vertices(const union blitter_attrib *attrib,
-                                      float *out, unsigned stride)
-{
-   out[0] = attrib->texcoord.x1;
-   out[1] = attrib->texcoord.y1;
-   out += stride;
-   out[0] = attrib->texcoord.x2;
-   out[1] = attrib->texcoord.y1;
-   out += stride;
-   out[0] = attrib->texcoord.x2;
-   out[1] = attrib->texcoord.y2;
-   out += stride;
-   out[0] = attrib->texcoord.x1;
-   out[1] = attrib->texcoord.y2;
-}
-
-static void blitter_set_texcoords(struct blitter_context_priv *ctx,
-                                  struct pipe_sampler_view *src,
-                                  unsigned src_width0, unsigned src_height0,
-                                  float layer, unsigned sample,
-                                  int x1, int y1, int x2, int y2,
-                                  bool uses_txf)
-{
-   unsigned i;
-   union blitter_attrib coord;
-   float face_coord[4][2];
-
-   get_texcoords(src, src_width0, src_height0, x1, y1, x2, y2, uses_txf,
-                 &coord);
-
-   if (src->target == PIPE_TEXTURE_CUBE ||
-       src->target == PIPE_TEXTURE_CUBE_ARRAY) {
-      set_texcoords_in_vertices(&coord, &face_coord[0][0], 2);
-      util_map_texcoords2d_onto_cubemap((unsigned)layer % 6,
-                                        /* pointer, stride in floats */
-                                        &face_coord[0][0], 2,
-                                        &ctx->vertices[0][1][0], 8,
-                                        false);
-   } else {
-      set_texcoords_in_vertices(&coord, &ctx->vertices[0][1][0], 8);
-   }
+   out->texcoord.z = 0;
+   out->texcoord.w = 0;
 
    /* Set the layer. */
    switch (src->target) {
@@ -827,32 +788,25 @@ static void blitter_set_texcoords(struct blitter_context_priv *ctx,
          if (!uses_txf)
             r /= u_minify(src->texture->depth0, src->u.tex.first_level);
 
-         for (i = 0; i < 4; i++)
-            ctx->vertices[i][1][2] = r; /*r*/
+         out->texcoord.z = r;
       }
       break;
 
    case PIPE_TEXTURE_1D_ARRAY:
-      for (i = 0; i < 4; i++)
-         ctx->vertices[i][1][1] = (float) layer; /*t*/
+      out->texcoord.y1 = out->texcoord.y2 = layer;
       break;
 
    case PIPE_TEXTURE_2D_ARRAY:
-      for (i = 0; i < 4; i++) {
-         ctx->vertices[i][1][2] = (float) layer;  /*r*/
-         ctx->vertices[i][1][3] = (float) sample; /*q*/
-      }
+      out->texcoord.z = layer;
+      out->texcoord.w = sample;
       break;
 
    case PIPE_TEXTURE_CUBE_ARRAY:
-      for (i = 0; i < 4; i++)
-         ctx->vertices[i][1][3] = (float) ((unsigned)layer / 6); /*w*/
+      out->texcoord.w = (unsigned)layer / 6;
       break;
 
    case PIPE_TEXTURE_2D:
-      for (i = 0; i < 4; i++) {
-         ctx->vertices[i][1][3] = (float) sample; /*r*/
-      }
+      out->texcoord.w = sample;
       break;
 
    default:;
@@ -866,6 +820,22 @@ static void blitter_set_dst_dimensions(struct blitter_context_priv *ctx,
    ctx->dst_height = height;
 }
 
+static void set_texcoords_in_vertices(const union blitter_attrib *attrib,
+                                      float *out, unsigned stride)
+{
+   out[0] = attrib->texcoord.x1;
+   out[1] = attrib->texcoord.y1;
+   out += stride;
+   out[0] = attrib->texcoord.x2;
+   out[1] = attrib->texcoord.y1;
+   out += stride;
+   out[0] = attrib->texcoord.x2;
+   out[1] = attrib->texcoord.y2;
+   out += stride;
+   out[0] = attrib->texcoord.x1;
+   out[1] = attrib->texcoord.y2;
+}
+
 static void *blitter_get_fs_texfetch_col(struct blitter_context_priv *ctx,
                                          enum pipe_format src_format,
                                          enum pipe_format dst_format,
@@ -1274,13 +1244,20 @@ void util_blitter_draw_rectangle(struct blitter_context *blitter,
                                  const union blitter_attrib *attrib)
 {
    struct blitter_context_priv *ctx = (struct blitter_context_priv*)blitter;
+   unsigned i;
 
    switch (type) {
       case UTIL_BLITTER_ATTRIB_COLOR:
          blitter_set_clear_color(ctx, attrib->color);
          break;
 
-      case UTIL_BLITTER_ATTRIB_TEXCOORD:
+      case UTIL_BLITTER_ATTRIB_TEXCOORD_XYZW:
+         for (i = 0; i < 4; i++) {
+            ctx->vertices[i][1][2] = attrib->texcoord.z;
+            ctx->vertices[i][1][3] = attrib->texcoord.w;
+         }
+         /* fall through */
+      case UTIL_BLITTER_ATTRIB_TEXCOORD_XY:
          set_texcoords_in_vertices(attrib, &ctx->vertices[0][1][0], 8);
          break;
 
@@ -1597,6 +1574,42 @@ void util_blitter_copy_texture(struct blitter_context *blitter,
    pipe_sampler_view_reference(&src_view, NULL);
 }
 
+static void
+blitter_draw_tex(struct blitter_context_priv *ctx,
+                 int dst_x1, int dst_y1, int dst_x2, int dst_y2,
+                 struct pipe_sampler_view *src,
+                 unsigned src_width0, unsigned src_height0,
+                 int src_x1, int src_y1, int src_x2, int src_y2,
+                 float layer, unsigned sample,
+                 bool uses_txf, enum blitter_attrib_type type)
+{
+   union blitter_attrib coord;
+
+   get_texcoords(src, src_width0, src_height0,
+                 src_x1, src_y1, src_x2, src_y2, layer, sample,
+                 uses_txf, &coord);
+
+   if (src->target == PIPE_TEXTURE_CUBE ||
+       src->target == PIPE_TEXTURE_CUBE_ARRAY) {
+      float face_coord[4][2];
+
+      set_texcoords_in_vertices(&coord, &face_coord[0][0], 2);
+      util_map_texcoords2d_onto_cubemap((unsigned)layer % 6,
+                                        /* pointer, stride in floats */
+                                        &face_coord[0][0], 2,
+                                        &ctx->vertices[0][1][0], 8,
+                                        false);
+      for (unsigned i = 0; i < 4; i++)
+         ctx->vertices[i][1][3] = coord.texcoord.w;
+
+      /* Cubemaps don't use draw_rectangle. */
+      blitter_draw(ctx, dst_x1, dst_y1, dst_x2, dst_y2, 0, 1);
+   } else {
+      ctx->base.draw_rectangle(&ctx->base, dst_x1, dst_y1, dst_x2, dst_y2, 0,
+                               1, type, &coord);
+   }
+}
+
 static void do_blits(struct blitter_context_priv *ctx,
                      struct pipe_surface *dst,
                      const struct pipe_box *dstbox,
@@ -1624,14 +1637,6 @@ static void do_blits(struct blitter_context_priv *ctx,
         src_target == PIPE_TEXTURE_2D ||
         src_target == PIPE_TEXTURE_RECT) &&
        src_samples <= 1) {
-      /* Draw the quad with the draw_rectangle callback. */
-
-      /* Set texture coordinates. */
-      union blitter_attrib coord;
-      get_texcoords(src, src_width0, src_height0, srcbox->x, srcbox->y,
-                    srcbox->x+srcbox->width, srcbox->y+srcbox->height,
-                    uses_txf, &coord);
-
       /* Set framebuffer state. */
       if (is_zsbuf) {
          fb_state.zsbuf = dst;
@@ -1642,10 +1647,12 @@ static void do_blits(struct blitter_context_priv *ctx,
 
       /* Draw. */
       pipe->set_sample_mask(pipe, ~0);
-      ctx->base.draw_rectangle(&ctx->base, dstbox->x, dstbox->y,
-                               dstbox->x + dstbox->width,
-                               dstbox->y + dstbox->height, 0, 1,
-                               UTIL_BLITTER_ATTRIB_TEXCOORD, &coord);
+      blitter_draw_tex(ctx, dstbox->x, dstbox->y,
+                       dstbox->x + dstbox->width,
+                       dstbox->y + dstbox->height,
+                       src, src_width0, src_height0, srcbox->x, srcbox->y,
+                       srcbox->x + srcbox->width, srcbox->y + srcbox->height,
+                       0, 0, uses_txf, UTIL_BLITTER_ATTRIB_TEXCOORD_XY);
    } else {
       /* Draw the quad with the generic codepath. */
       int dst_z;
@@ -1689,26 +1696,28 @@ static void do_blits(struct blitter_context_priv *ctx,
 
             for (i = 0; i <= max_sample; i++) {
                pipe->set_sample_mask(pipe, 1 << i);
-               blitter_set_texcoords(ctx, src, src_width0, src_height0,
-                                     srcbox->z + src_z,
-                                     i, srcbox->x, srcbox->y,
-                                     srcbox->x + srcbox->width,
-                                     srcbox->y + srcbox->height, uses_txf);
-               blitter_draw(ctx, dstbox->x, dstbox->y,
-                            dstbox->x + dstbox->width,
-                            dstbox->y + dstbox->height, 0, 1);
+               blitter_draw_tex(ctx, dstbox->x, dstbox->y,
+                                dstbox->x + dstbox->width,
+                                dstbox->y + dstbox->height,
+                                src, src_width0, src_height0,
+                                srcbox->x, srcbox->y,
+                                srcbox->x + srcbox->width,
+                                srcbox->y + srcbox->height,
+                                srcbox->z + src_z, i, uses_txf,
+                                UTIL_BLITTER_ATTRIB_TEXCOORD_XYZW);
             }
          } else {
             /* Normal copy, MSAA upsampling, or MSAA resolve. */
             pipe->set_sample_mask(pipe, ~0);
-            blitter_set_texcoords(ctx, src, src_width0, src_height0,
-                                  srcbox->z + src_z, 0,
-                                  srcbox->x, srcbox->y,
-                                  srcbox->x + srcbox->width,
-                                  srcbox->y + srcbox->height, uses_txf);
-            blitter_draw(ctx, dstbox->x, dstbox->y,
-                         dstbox->x + dstbox->width,
-                         dstbox->y + dstbox->height, 0, 1);
+            blitter_draw_tex(ctx, dstbox->x, dstbox->y,
+                             dstbox->x + dstbox->width,
+                             dstbox->y + dstbox->height,
+                             src, src_width0, src_height0,
+                             srcbox->x, srcbox->y,
+                             srcbox->x + srcbox->width,
+                             srcbox->y + srcbox->height,
+                             srcbox->z + src_z, 0, uses_txf,
+                             UTIL_BLITTER_ATTRIB_TEXCOORD_XYZW);
          }
 
          /* Get the next surface or (if this is the last iteration)
index b335de0ef58c577a573a7780d64c186f7ecc98bd..626d46aae47935ce4dccfa3ff3f6312efff734b5 100644 (file)
@@ -41,14 +41,15 @@ struct pipe_context;
 enum blitter_attrib_type {
    UTIL_BLITTER_ATTRIB_NONE,
    UTIL_BLITTER_ATTRIB_COLOR,
-   UTIL_BLITTER_ATTRIB_TEXCOORD
+   UTIL_BLITTER_ATTRIB_TEXCOORD_XY,
+   UTIL_BLITTER_ATTRIB_TEXCOORD_XYZW,
 };
 
 union blitter_attrib {
    float color[4];
 
    struct {
-      float x1, y1, x2, y2;
+      float x1, y1, x2, y2, z, w;
    } texcoord;
 };
 
index 1f896da22e947cf4f01f3bfc32bd653391843aa4..ddd24523ca67dac43e3b76ffb2d647598305629f 100644 (file)
@@ -1125,13 +1125,14 @@ void r300_blitter_draw_rectangle(struct blitter_context *blitter,
     unsigned vertex_size =
             type == UTIL_BLITTER_ATTRIB_COLOR || !r300->draw ? 8 : 4;
     unsigned dwords = 13 + vertex_size +
-                      (type == UTIL_BLITTER_ATTRIB_TEXCOORD ? 7 : 0);
+                      (type == UTIL_BLITTER_ATTRIB_TEXCOORD_XY ? 7 : 0);
     static const union blitter_attrib zeros;
     CS_LOCALS(r300);
 
     /* XXX workaround for a lockup in MSAA resolve on SWTCL chipsets, this
      * function most probably doesn't handle type=NONE correctly */
     if ((!r300->screen->caps.has_tcl && type == UTIL_BLITTER_ATTRIB_NONE) ||
+        type == UTIL_BLITTER_ATTRIB_TEXCOORD_XYZW ||
         num_instances > 1) {
         util_blitter_draw_rectangle(blitter, x1, y1, x2, y2, depth,
                                     num_instances, type, attrib);
@@ -1141,7 +1142,7 @@ void r300_blitter_draw_rectangle(struct blitter_context *blitter,
     if (r300->skip_rendering)
         return;
 
-    if (type == UTIL_BLITTER_ATTRIB_TEXCOORD)
+    if (type == UTIL_BLITTER_ATTRIB_TEXCOORD_XY)
         r300->sprite_coord_enable = 1;
 
     r300_update_derived_state(r300);
@@ -1158,7 +1159,7 @@ void r300_blitter_draw_rectangle(struct blitter_context *blitter,
     /* Set up GA. */
     OUT_CS_REG(R300_GA_POINT_SIZE, (height * 6) | ((width * 6) << 16));
 
-    if (type == UTIL_BLITTER_ATTRIB_TEXCOORD) {
+    if (type == UTIL_BLITTER_ATTRIB_TEXCOORD_XY) {
         /* Set up the GA to generate texcoords. */
         OUT_CS_REG(R300_GB_ENABLE, R300_GB_POINT_STUFF_ENABLE |
                    (R300_GB_TEX_STR << R300_GB_TEX0_SOURCE_SHIFT));
index f5f1524617640ed65b9db38e0e45cd95257045d9..72553292f59aa2559f2c6dee099ebe0728bb286d 100644 (file)
@@ -266,7 +266,11 @@ void r600_draw_rectangle(struct blitter_context *blitter,
                memcpy(vb+12, attrib->color, sizeof(float)*4);
                memcpy(vb+20, attrib->color, sizeof(float)*4);
                break;
-       case UTIL_BLITTER_ATTRIB_TEXCOORD:
+       case UTIL_BLITTER_ATTRIB_TEXCOORD_XYZW:
+               vb[6] = vb[14] = vb[22] = attrib->texcoord.z;
+               vb[7] = vb[15] = vb[23] = attrib->texcoord.w;
+               /* fall through */
+       case UTIL_BLITTER_ATTRIB_TEXCOORD_XY:
                vb[4] = attrib->texcoord.x1;
                vb[5] = attrib->texcoord.y1;
                vb[12] = attrib->texcoord.x1;