gallium/util: add util_format_snorm8_to_sint8 (from radeonsi)
authorMarek Olšák <marek.olsak@amd.com>
Tue, 15 Jan 2019 17:33:53 +0000 (12:33 -0500)
committerMarek Olšák <marek.olsak@amd.com>
Tue, 22 Jan 2019 17:21:43 +0000 (12:21 -0500)
src/gallium/auxiliary/util/u_format.c
src/gallium/auxiliary/util/u_format.h
src/gallium/drivers/radeonsi/si_blit.c

index 231e89017b41e34006c84eca1b0d5dcb67858cc7..862061a8ec278597da987d9f789e7a3f2b29b956 100644 (file)
@@ -886,3 +886,43 @@ void util_format_unswizzle_4f(float *dst, const float *src,
       }
    }
 }
+
+enum pipe_format
+util_format_snorm8_to_sint8(enum pipe_format format)
+{
+   switch (format) {
+   case PIPE_FORMAT_R8_SNORM:
+      return PIPE_FORMAT_R8_SINT;
+   case PIPE_FORMAT_R8G8_SNORM:
+      return PIPE_FORMAT_R8G8_SINT;
+   case PIPE_FORMAT_R8G8B8_SNORM:
+      return PIPE_FORMAT_R8G8B8_SINT;
+   case PIPE_FORMAT_R8G8B8A8_SNORM:
+      return PIPE_FORMAT_R8G8B8A8_SINT;
+
+   case PIPE_FORMAT_A8_SNORM:
+      return PIPE_FORMAT_A8_SINT;
+   case PIPE_FORMAT_L8_SNORM:
+      return PIPE_FORMAT_L8_SINT;
+   case PIPE_FORMAT_L8A8_SNORM:
+      return PIPE_FORMAT_L8A8_SINT;
+   case PIPE_FORMAT_I8_SNORM:
+      return PIPE_FORMAT_I8_SINT;
+
+   case PIPE_FORMAT_R8G8B8X8_SNORM:
+      return PIPE_FORMAT_R8G8B8X8_SINT;
+   case PIPE_FORMAT_R8A8_SNORM:
+      return PIPE_FORMAT_R8A8_SINT;
+   case PIPE_FORMAT_A8L8_SNORM:
+      return PIPE_FORMAT_A8L8_SINT;
+   case PIPE_FORMAT_G8R8_SNORM:
+      return PIPE_FORMAT_G8R8_SINT;
+   case PIPE_FORMAT_A8B8G8R8_SNORM:
+      return PIPE_FORMAT_A8B8G8R8_SINT;
+   case PIPE_FORMAT_X8B8G8R8_SNORM:
+      return PIPE_FORMAT_X8B8G8R8_SINT;
+
+   default:
+      return format;
+   }
+}
index 8dcc438a4a1d75f81fe2a3ddcecf630aacb86995..0c0c505e3918cdbca419fdb10a12d7bece933e26 100644 (file)
@@ -1358,6 +1358,9 @@ void pipe_swizzle_4f(float *dst, const float *src,
 void util_format_unswizzle_4f(float *dst, const float *src,
                               const unsigned char swz[4]);
 
+enum pipe_format
+util_format_snorm8_to_sint8(enum pipe_format format);
+
 #ifdef __cplusplus
 } // extern "C" {
 #endif
index 69b1af02db088102ce586837c5d9246e4b204dbe..16be11247e4fe4c8d7251848874d9955ee121094 100644 (file)
@@ -1012,36 +1012,8 @@ void si_resource_copy_region(struct pipe_context *ctx,
         * Note that some chips avoid this issue by using SDMA.
         */
        if (util_format_is_snorm8(dst_templ.format)) {
-               switch (dst_templ.format) {
-               case PIPE_FORMAT_R8_SNORM:
-                       dst_templ.format = src_templ.format = PIPE_FORMAT_R8_SINT;
-                       break;
-               case PIPE_FORMAT_R8G8_SNORM:
-                       dst_templ.format = src_templ.format = PIPE_FORMAT_R8G8_SINT;
-                       break;
-               case PIPE_FORMAT_R8G8B8X8_SNORM:
-                       dst_templ.format = src_templ.format = PIPE_FORMAT_R8G8B8X8_SINT;
-                       break;
-               case PIPE_FORMAT_R8G8B8A8_SNORM:
-               /* There are no SINT variants for ABGR and XBGR, so we have to use RGBA. */
-               case PIPE_FORMAT_A8B8G8R8_SNORM:
-               case PIPE_FORMAT_X8B8G8R8_SNORM:
-                       dst_templ.format = src_templ.format = PIPE_FORMAT_R8G8B8A8_SINT;
-                       break;
-               case PIPE_FORMAT_A8_SNORM:
-                       dst_templ.format = src_templ.format = PIPE_FORMAT_A8_SINT;
-                       break;
-               case PIPE_FORMAT_L8_SNORM:
-                       dst_templ.format = src_templ.format = PIPE_FORMAT_L8_SINT;
-                       break;
-               case PIPE_FORMAT_L8A8_SNORM:
-                       dst_templ.format = src_templ.format = PIPE_FORMAT_L8A8_SINT;
-                       break;
-               case PIPE_FORMAT_I8_SNORM:
-                       dst_templ.format = src_templ.format = PIPE_FORMAT_I8_SINT;
-                       break;
-               default:; /* fall through */
-               }
+               dst_templ.format = src_templ.format =
+                       util_format_snorm8_to_sint8(dst_templ.format);
        }
 
        vi_disable_dcc_if_incompatible_format(sctx, dst, dst_level,