util/u_blit: Support blits from cubemaps.
authorJosé Fonseca <jfonseca@vmware.com>
Tue, 17 Sep 2013 18:22:44 +0000 (19:22 +0100)
committerJosé Fonseca <jfonseca@vmware.com>
Wed, 18 Sep 2013 10:24:59 +0000 (11:24 +0100)
By calling util_map_texcoords2d_onto_cubemap.

A new parameter for util_blit_pixels_tex is necessary, as
pipe_sampler_view::first_layer is always supposed to point to the first
face when sampling from cubemaps.

Reviewed-by: Zack Rusin <zackr@vmware.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Reviewed-by: Roland Scheidegger <sroland@vmware.com>
src/gallium/auxiliary/util/u_blit.c
src/gallium/auxiliary/util/u_blit.h

index 8cc080cc9c734e1ee2bcb1a2dd2768c188584d88..e9bec4a3e74387281549950287ad7c1045e70c47 100644 (file)
@@ -46,6 +46,7 @@
 #include "util/u_math.h"
 #include "util/u_memory.h"
 #include "util/u_sampler.h"
+#include "util/u_texture.h"
 #include "util/u_simple_shaders.h"
 
 #include "cso_cache/cso_context.h"
@@ -143,7 +144,6 @@ util_create_blit(struct pipe_context *pipe, struct cso_context *cso)
    /* init vertex data that doesn't change */
    for (i = 0; i < 4; i++) {
       ctx->vertices[i][0][3] = 1.0f; /* w */
-      ctx->vertices[i][1][2] = 0.0f; /* r */
       ctx->vertices[i][1][3] = 1.0f; /* q */
    }
 
@@ -327,6 +327,8 @@ get_next_slot( struct blit_state *ctx )
  */
 static unsigned
 setup_vertex_data_tex(struct blit_state *ctx,
+                      unsigned src_target,
+                      unsigned src_face,
                       float x0, float y0, float x1, float y1,
                       float s0, float t0, float s1, float t1,
                       float z)
@@ -338,24 +340,37 @@ setup_vertex_data_tex(struct blit_state *ctx,
    ctx->vertices[0][0][2] = z;
    ctx->vertices[0][1][0] = s0; /*s*/
    ctx->vertices[0][1][1] = t0; /*t*/
+   ctx->vertices[0][1][2] = 0;  /*r*/
 
    ctx->vertices[1][0][0] = x1;
    ctx->vertices[1][0][1] = y0;
    ctx->vertices[1][0][2] = z;
    ctx->vertices[1][1][0] = s1; /*s*/
    ctx->vertices[1][1][1] = t0; /*t*/
+   ctx->vertices[1][1][2] = 0;  /*r*/
 
    ctx->vertices[2][0][0] = x1;
    ctx->vertices[2][0][1] = y1;
    ctx->vertices[2][0][2] = z;
    ctx->vertices[2][1][0] = s1;
    ctx->vertices[2][1][1] = t1;
+   ctx->vertices[3][1][2] = 0;
 
    ctx->vertices[3][0][0] = x0;
    ctx->vertices[3][0][1] = y1;
    ctx->vertices[3][0][2] = z;
    ctx->vertices[3][1][0] = s0;
    ctx->vertices[3][1][1] = t1;
+   ctx->vertices[3][1][2] = 0;
+
+   if (src_target == PIPE_TEXTURE_CUBE ||
+       src_target == PIPE_TEXTURE_CUBE_ARRAY) {
+      /* Map cubemap texture coordinates inplace. */
+      const unsigned stride = sizeof ctx->vertices[0] / sizeof ctx->vertices[0][0][0];
+      util_map_texcoords2d_onto_cubemap(src_face,
+                                        &ctx->vertices[0][1][0], stride,
+                                        &ctx->vertices[0][1][0], stride);
+   }
 
    offset = get_next_slot( ctx );
 
@@ -770,6 +785,8 @@ util_blit_pixels(struct blit_state *ctx,
 
    /* draw quad */
    offset = setup_vertex_data_tex(ctx,
+                                  sampler_view->texture->target,
+                                  srcZ0 % 6,
                                   (float) dstX0 / dst_surface->width * 2.0f - 1.0f,
                                   (float) dstY0 / dst_surface->height * 2.0f - 1.0f,
                                   (float) dstX1 / dst_surface->width * 2.0f - 1.0f,
@@ -811,16 +828,25 @@ util_blit_pixels(struct blit_state *ctx,
 
 
 /**
- * Copy pixel block from src texture to dst surface.
+ * Copy pixel block from src sampler view to dst surface.
+ *
  * The sampler view's first_level field indicates the source
  * mipmap level to use.
- * XXX need some control over blitting Z and/or stencil.
+ *
+ * The sampler view's first_layer indicate the layer to use, but for
+ * cube maps it must point to the first face.  Face is passed in src_face.
+ *
+ * The main advantage over util_blit_pixels is that it allows to specify swizzles in
+ * pipe_sampler_view::swizzle_?.
+ *
+ * But there is no control over blitting Z and/or stencil.
  */
 void
 util_blit_pixels_tex(struct blit_state *ctx,
                      struct pipe_sampler_view *src_sampler_view,
                      int srcX0, int srcY0,
                      int srcX1, int srcY1,
+                     unsigned src_face,
                      struct pipe_surface *dst,
                      int dstX0, int dstY0,
                      int dstX1, int dstY1,
@@ -922,6 +948,8 @@ util_blit_pixels_tex(struct blit_state *ctx,
 
    /* draw quad */
    offset = setup_vertex_data_tex(ctx,
+                                  src_sampler_view->texture->target,
+                                  src_face,
                                   (float) dstX0 / dst->width * 2.0f - 1.0f,
                                   (float) dstY0 / dst->height * 2.0f - 1.0f,
                                   (float) dstX1 / dst->width * 2.0f - 1.0f,
index 56ab030830526d6c5cd34557c0559426589dbc14..bfcd1bb28c82cff0741a7b71fad6ddda1cb05bb9 100644 (file)
@@ -73,6 +73,7 @@ util_blit_pixels_tex(struct blit_state *ctx,
                      struct pipe_sampler_view *src_sampler_view,
                      int srcX0, int srcY0,
                      int srcX1, int srcY1,
+                     unsigned src_face,
                      struct pipe_surface *dst,
                      int dstX0, int dstY0,
                      int dstX1, int dstY1,