Mesa (master): i965: expose type of memcpy instead of memcpy function itself

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Oct 23 11:44:38 UTC 2018


Module: Mesa
Branch: master
Commit: 91d3a5d1a86915480e9e07cf370ad0e9743ab5b5
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=91d3a5d1a86915480e9e07cf370ad0e9743ab5b5

Author: Tapani Pälli <tapani.palli at intel.com>
Date:   Wed Sep 19 10:16:58 2018 +0300

i965: expose type of memcpy instead of memcpy function itself

There is currently no use of returned memcpy functions outside
intel_tiled_memcpy. Patch changes intel_get_memcpy to return memcpy
type instead of actual function. This makes it easier later to separate
streaming load copy in to own static library.

Signed-off-by: Tapani Pälli <tapani.palli at intel.com>
Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
Reviewed-by: Matt Turner <mattst88 at gmail.com>

---

 src/mesa/drivers/dri/i965/intel_pixel_read.c   |  6 +--
 src/mesa/drivers/dri/i965/intel_tex_image.c    | 14 ++++---
 src/mesa/drivers/dri/i965/intel_tiled_memcpy.c | 58 ++++++++++++++++++--------
 src/mesa/drivers/dri/i965/intel_tiled_memcpy.h | 15 +++++--
 4 files changed, 63 insertions(+), 30 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/intel_pixel_read.c b/src/mesa/drivers/dri/i965/intel_pixel_read.c
index 09a3c3440f..537ac057a3 100644
--- a/src/mesa/drivers/dri/i965/intel_pixel_read.c
+++ b/src/mesa/drivers/dri/i965/intel_pixel_read.c
@@ -87,7 +87,7 @@ intel_readpixels_tiled_memcpy(struct gl_context * ctx,
    struct brw_bo *bo;
 
    uint32_t cpp;
-   mem_copy_fn mem_copy = NULL;
+   mem_copy_fn_type copy_type;
 
    /* This fastpath is restricted to specific renderbuffer types:
     * a 2D BGRA, RGBA, L8 or A8 texture. It could be generalized to support
@@ -125,7 +125,7 @@ intel_readpixels_tiled_memcpy(struct gl_context * ctx,
    if (rb->_BaseFormat == GL_RGB)
       return false;
 
-   if (!intel_get_memcpy(rb->Format, format, type, &mem_copy, &cpp))
+   if (!intel_get_memcpy_type(rb->Format, format, type, &copy_type, &cpp))
       return false;
 
    if (!irb->mt ||
@@ -206,7 +206,7 @@ intel_readpixels_tiled_memcpy(struct gl_context * ctx,
       dst_pitch, irb->mt->surf.row_pitch_B,
       brw->has_swizzling,
       irb->mt->surf.tiling,
-      mem_copy
+      copy_type
    );
 
    brw_bo_unmap(bo);
diff --git a/src/mesa/drivers/dri/i965/intel_tex_image.c b/src/mesa/drivers/dri/i965/intel_tex_image.c
index 9775f78878..bdcdb7736e 100644
--- a/src/mesa/drivers/dri/i965/intel_tex_image.c
+++ b/src/mesa/drivers/dri/i965/intel_tex_image.c
@@ -192,7 +192,7 @@ intel_texsubimage_tiled_memcpy(struct gl_context * ctx,
    struct brw_bo *bo;
 
    uint32_t cpp;
-   mem_copy_fn mem_copy = NULL;
+   mem_copy_fn_type copy_type;
 
    /* This fastpath is restricted to specific texture types:
     * a 2D BGRA, RGBA, L8 or A8 texture. It could be generalized to support
@@ -222,7 +222,8 @@ intel_texsubimage_tiled_memcpy(struct gl_context * ctx,
    if (ctx->_ImageTransferState)
       return false;
 
-   if (!intel_get_memcpy(texImage->TexFormat, format, type, &mem_copy, &cpp))
+   if (!intel_get_memcpy_type(texImage->TexFormat, format, type, &copy_type,
+                              &cpp))
       return false;
 
    /* If this is a nontrivial texture view, let another path handle it instead. */
@@ -297,7 +298,7 @@ intel_texsubimage_tiled_memcpy(struct gl_context * ctx,
       image->mt->surf.row_pitch_B, src_pitch,
       brw->has_swizzling,
       image->mt->surf.tiling,
-      mem_copy
+      copy_type
    );
 
    brw_bo_unmap(bo);
@@ -694,7 +695,7 @@ intel_gettexsubimage_tiled_memcpy(struct gl_context *ctx,
    struct brw_bo *bo;
 
    uint32_t cpp;
-   mem_copy_fn mem_copy = NULL;
+   mem_copy_fn_type copy_type;
 
    /* This fastpath is restricted to specific texture types:
     * a 2D BGRA, RGBA, L8 or A8 texture. It could be generalized to support
@@ -728,7 +729,8 @@ intel_gettexsubimage_tiled_memcpy(struct gl_context *ctx,
    if (texImage->_BaseFormat == GL_RGB)
       return false;
 
-   if (!intel_get_memcpy(texImage->TexFormat, format, type, &mem_copy, &cpp))
+   if (!intel_get_memcpy_type(texImage->TexFormat, format, type, &copy_type,
+                              &cpp))
       return false;
 
    /* If this is a nontrivial texture view, let another path handle it instead. */
@@ -800,7 +802,7 @@ intel_gettexsubimage_tiled_memcpy(struct gl_context *ctx,
       dst_pitch, image->mt->surf.row_pitch_B,
       brw->has_swizzling,
       image->mt->surf.tiling,
-      mem_copy
+      copy_type
    );
 
    brw_bo_unmap(bo);
diff --git a/src/mesa/drivers/dri/i965/intel_tiled_memcpy.c b/src/mesa/drivers/dri/i965/intel_tiled_memcpy.c
index 7c6bde990d..76a92b4d41 100644
--- a/src/mesa/drivers/dri/i965/intel_tiled_memcpy.c
+++ b/src/mesa/drivers/dri/i965/intel_tiled_memcpy.c
@@ -230,7 +230,7 @@ typedef void (*tile_copy_fn)(uint32_t x0, uint32_t x1, uint32_t x2, uint32_t x3,
                              char *dst, const char *src,
                              int32_t linear_pitch,
                              uint32_t swizzle_bit,
-                             mem_copy_fn mem_copy);
+                             mem_copy_fn_type copy_type);
 
 /**
  * Copy texture data from linear to X tile layout.
@@ -566,6 +566,19 @@ ytiled_to_linear(uint32_t x0, uint32_t x1, uint32_t x2, uint32_t x3,
    }
 }
 
+static mem_copy_fn
+choose_copy_function(mem_copy_fn_type copy_type)
+{
+   switch(copy_type) {
+   case INTEL_COPY_MEMCPY:
+      return memcpy;
+   case INTEL_COPY_RGBA8:
+      return rgba8_copy;
+   default:
+      assert(!"unreachable");
+   }
+   return NULL;
+}
 
 /**
  * Copy texture data from linear to X tile layout, faster.
@@ -582,8 +595,10 @@ linear_to_xtiled_faster(uint32_t x0, uint32_t x1, uint32_t x2, uint32_t x3,
                         char *dst, const char *src,
                         int32_t src_pitch,
                         uint32_t swizzle_bit,
-                        mem_copy_fn mem_copy)
+                        mem_copy_fn_type copy_type)
 {
+   mem_copy_fn mem_copy = choose_copy_function(copy_type);
+
    if (x0 == 0 && x3 == xtile_width && y0 == 0 && y1 == xtile_height) {
       if (mem_copy == memcpy)
          return linear_to_xtiled(0, 0, xtile_width, xtile_width, 0, xtile_height,
@@ -625,8 +640,10 @@ linear_to_ytiled_faster(uint32_t x0, uint32_t x1, uint32_t x2, uint32_t x3,
                         char *dst, const char *src,
                         int32_t src_pitch,
                         uint32_t swizzle_bit,
-                        mem_copy_fn mem_copy)
+                        mem_copy_fn_type copy_type)
 {
+   mem_copy_fn mem_copy = choose_copy_function(copy_type);
+
    if (x0 == 0 && x3 == ytile_width && y0 == 0 && y1 == ytile_height) {
       if (mem_copy == memcpy)
          return linear_to_ytiled(0, 0, ytile_width, ytile_width, 0, ytile_height,
@@ -667,8 +684,10 @@ xtiled_to_linear_faster(uint32_t x0, uint32_t x1, uint32_t x2, uint32_t x3,
                         char *dst, const char *src,
                         int32_t dst_pitch,
                         uint32_t swizzle_bit,
-                        mem_copy_fn mem_copy)
+                        mem_copy_fn_type copy_type)
 {
+   mem_copy_fn mem_copy = choose_copy_function(copy_type);
+
    if (x0 == 0 && x3 == xtile_width && y0 == 0 && y1 == xtile_height) {
       if (mem_copy == memcpy)
          return xtiled_to_linear(0, 0, xtile_width, xtile_width, 0, xtile_height,
@@ -709,8 +728,10 @@ ytiled_to_linear_faster(uint32_t x0, uint32_t x1, uint32_t x2, uint32_t x3,
                         char *dst, const char *src,
                         int32_t dst_pitch,
                         uint32_t swizzle_bit,
-                        mem_copy_fn mem_copy)
+                        mem_copy_fn_type copy_type)
 {
+   mem_copy_fn mem_copy = choose_copy_function(copy_type);
+
    if (x0 == 0 && x3 == ytile_width && y0 == 0 && y1 == ytile_height) {
       if (mem_copy == memcpy)
          return ytiled_to_linear(0, 0, ytile_width, ytile_width, 0, ytile_height,
@@ -754,7 +775,7 @@ linear_to_tiled(uint32_t xt1, uint32_t xt2,
                 uint32_t dst_pitch, int32_t src_pitch,
                 bool has_swizzling,
                 enum isl_tiling tiling,
-                mem_copy_fn mem_copy)
+                mem_copy_fn_type copy_type)
 {
    tile_copy_fn tile_copy;
    uint32_t xt0, xt3;
@@ -822,7 +843,7 @@ linear_to_tiled(uint32_t xt1, uint32_t xt2,
                    src + (ptrdiff_t)xt - xt1 + ((ptrdiff_t)yt - yt1) * src_pitch,
                    src_pitch,
                    swizzle_bit,
-                   mem_copy);
+                   copy_type);
       }
    }
 }
@@ -845,7 +866,7 @@ tiled_to_linear(uint32_t xt1, uint32_t xt2,
                 int32_t dst_pitch, uint32_t src_pitch,
                 bool has_swizzling,
                 enum isl_tiling tiling,
-                mem_copy_fn mem_copy)
+                mem_copy_fn_type copy_type)
 {
    tile_copy_fn tile_copy;
    uint32_t xt0, xt3;
@@ -913,7 +934,7 @@ tiled_to_linear(uint32_t xt1, uint32_t xt2,
                    src + (ptrdiff_t)xt * th  +  (ptrdiff_t)yt        * src_pitch,
                    dst_pitch,
                    swizzle_bit,
-                   mem_copy);
+                   copy_type);
       }
    }
 }
@@ -939,9 +960,12 @@ tiled_to_linear(uint32_t xt1, uint32_t xt2,
  *
  * \return true if the format and type combination are valid
  */
-bool intel_get_memcpy(mesa_format tiledFormat, GLenum format,
-                      GLenum type, mem_copy_fn *mem_copy, uint32_t *cpp)
+bool
+intel_get_memcpy_type(mesa_format tiledFormat, GLenum format, GLenum type,
+                      mem_copy_fn_type *copy_type, uint32_t *cpp)
 {
+   *copy_type = INTEL_COPY_INVALID;
+
    if (type == GL_UNSIGNED_INT_8_8_8_8_REV &&
        !(format == GL_RGBA || format == GL_BGRA))
       return false; /* Invalid type/format combination */
@@ -949,16 +973,16 @@ bool intel_get_memcpy(mesa_format tiledFormat, GLenum format,
    if ((tiledFormat == MESA_FORMAT_L_UNORM8 && format == GL_LUMINANCE) ||
        (tiledFormat == MESA_FORMAT_A_UNORM8 && format == GL_ALPHA)) {
       *cpp = 1;
-      *mem_copy = memcpy;
+      *copy_type = INTEL_COPY_MEMCPY;
    } else if ((tiledFormat == MESA_FORMAT_B8G8R8A8_UNORM) ||
               (tiledFormat == MESA_FORMAT_B8G8R8X8_UNORM) ||
               (tiledFormat == MESA_FORMAT_B8G8R8A8_SRGB) ||
               (tiledFormat == MESA_FORMAT_B8G8R8X8_SRGB)) {
       *cpp = 4;
       if (format == GL_BGRA) {
-         *mem_copy = memcpy;
+         *copy_type = INTEL_COPY_MEMCPY;
       } else if (format == GL_RGBA) {
-         *mem_copy = rgba8_copy;
+         *copy_type = INTEL_COPY_RGBA8;
       }
    } else if ((tiledFormat == MESA_FORMAT_R8G8B8A8_UNORM) ||
               (tiledFormat == MESA_FORMAT_R8G8B8X8_UNORM) ||
@@ -969,13 +993,13 @@ bool intel_get_memcpy(mesa_format tiledFormat, GLenum format,
          /* Copying from RGBA to BGRA is the same as BGRA to RGBA so we can
           * use the same function.
           */
-         *mem_copy = rgba8_copy;
+         *copy_type = INTEL_COPY_RGBA8;
       } else if (format == GL_RGBA) {
-         *mem_copy = memcpy;
+         *copy_type = INTEL_COPY_MEMCPY;
       }
    }
 
-   if (!(*mem_copy))
+   if (*copy_type == INTEL_COPY_INVALID)
       return false;
 
    return true;
diff --git a/src/mesa/drivers/dri/i965/intel_tiled_memcpy.h b/src/mesa/drivers/dri/i965/intel_tiled_memcpy.h
index 62ec8847fb..7093441029 100644
--- a/src/mesa/drivers/dri/i965/intel_tiled_memcpy.h
+++ b/src/mesa/drivers/dri/i965/intel_tiled_memcpy.h
@@ -35,6 +35,12 @@
 #include <stdint.h>
 #include "main/mtypes.h"
 
+typedef enum {
+  INTEL_COPY_MEMCPY = 0,
+  INTEL_COPY_RGBA8,
+  INTEL_COPY_INVALID,
+} mem_copy_fn_type;
+
 typedef void *(*mem_copy_fn)(void *dest, const void *src, size_t n);
 
 void
@@ -44,7 +50,7 @@ linear_to_tiled(uint32_t xt1, uint32_t xt2,
                 uint32_t dst_pitch, int32_t src_pitch,
                 bool has_swizzling,
                 enum isl_tiling tiling,
-                mem_copy_fn mem_copy);
+                mem_copy_fn_type copy_type);
 
 void
 tiled_to_linear(uint32_t xt1, uint32_t xt2,
@@ -53,9 +59,10 @@ tiled_to_linear(uint32_t xt1, uint32_t xt2,
                 int32_t dst_pitch, uint32_t src_pitch,
                 bool has_swizzling,
                 enum isl_tiling tiling,
-                mem_copy_fn mem_copy);
+                mem_copy_fn_type copy_type);
 
-bool intel_get_memcpy(mesa_format tiledFormat, GLenum format,
-                      GLenum type, mem_copy_fn *mem_copy, uint32_t *cpp);
+bool intel_get_memcpy_type(mesa_format tiledFormat, GLenum format,
+                           GLenum type, mem_copy_fn_type *copy_type,
+                           uint32_t *cpp);
 
 #endif /* INTEL_TILED_MEMCPY */




More information about the mesa-commit mailing list