u_format: Remove pointless comments.
[mesa.git] / src / gallium / auxiliary / util / u_format.h
index ffdb864fa83e40be0b096b9c60c9ecbf434f529e..fe348aa55c8f6b67a33e063d5842d269a4e44655 100644 (file)
@@ -83,15 +83,14 @@ enum util_format_layout {
     */
    UTIL_FORMAT_LAYOUT_BPTC = 7,
 
-   /**
-    * ASTC
-    */
    UTIL_FORMAT_LAYOUT_ASTC = 8,
 
+   UTIL_FORMAT_LAYOUT_ATC = 9,
+
    /**
     * Everything else that doesn't fit in any of the above layouts.
     */
-   UTIL_FORMAT_LAYOUT_OTHER = 9
+   UTIL_FORMAT_LAYOUT_OTHER = 10
 };
 
 
@@ -117,18 +116,6 @@ enum util_format_type {
 };
 
 
-enum util_format_swizzle {
-   UTIL_FORMAT_SWIZZLE_X = 0,
-   UTIL_FORMAT_SWIZZLE_Y = 1,
-   UTIL_FORMAT_SWIZZLE_Z = 2,
-   UTIL_FORMAT_SWIZZLE_W = 3,
-   UTIL_FORMAT_SWIZZLE_0 = 4,
-   UTIL_FORMAT_SWIZZLE_1 = 5,
-   UTIL_FORMAT_SWIZZLE_NONE = 6,
-   UTIL_FORMAT_SWIZZLE_MAX = 7  /**< Number of enums counter (must be last) */
-};
-
-
 enum util_format_colorspace {
    UTIL_FORMAT_COLORSPACE_RGB = 0,
    UTIL_FORMAT_COLORSPACE_SRGB = 1,
@@ -189,6 +176,16 @@ struct util_format_description
     */
    unsigned is_mixed:1;
 
+   /**
+    * Whether the format contains UNORM channels
+    */
+   unsigned is_unorm:1;
+
+   /**
+    * Whether the format contains SNORM channels
+    */
+   unsigned is_snorm:1;
+
    /**
     * Input channel description, in the order XYZW.
     *
@@ -487,6 +484,7 @@ util_format_is_compressed(enum pipe_format format)
    case UTIL_FORMAT_LAYOUT_ETC:
    case UTIL_FORMAT_LAYOUT_BPTC:
    case UTIL_FORMAT_LAYOUT_ASTC:
+   case UTIL_FORMAT_LAYOUT_ATC:
       /* XXX add other formats in the future */
       return TRUE;
    default:
@@ -507,6 +505,19 @@ util_format_is_s3tc(enum pipe_format format)
    return desc->layout == UTIL_FORMAT_LAYOUT_S3TC ? TRUE : FALSE;
 }
 
+static inline boolean
+util_format_is_etc(enum pipe_format format)
+{
+   const struct util_format_description *desc = util_format_description(format);
+
+   assert(desc);
+   if (!desc) {
+      return FALSE;
+   }
+
+   return desc->layout == UTIL_FORMAT_LAYOUT_ETC ? TRUE : FALSE;
+}
+
 static inline boolean 
 util_format_is_srgb(enum pipe_format format)
 {
@@ -518,14 +529,14 @@ static inline boolean
 util_format_has_depth(const struct util_format_description *desc)
 {
    return desc->colorspace == UTIL_FORMAT_COLORSPACE_ZS &&
-          desc->swizzle[0] != UTIL_FORMAT_SWIZZLE_NONE;
+          desc->swizzle[0] != PIPE_SWIZZLE_NONE;
 }
 
 static inline boolean
 util_format_has_stencil(const struct util_format_description *desc)
 {
    return desc->colorspace == UTIL_FORMAT_COLORSPACE_ZS &&
-          desc->swizzle[1] != UTIL_FORMAT_SWIZZLE_NONE;
+          desc->swizzle[1] != PIPE_SWIZZLE_NONE;
 }
 
 static inline boolean
@@ -556,6 +567,39 @@ util_format_is_depth_and_stencil(enum pipe_format format)
           util_format_has_stencil(desc);
 }
 
+/**
+ * For depth-stencil formats, return the equivalent depth-only format.
+ */
+static inline boolean
+util_format_get_depth_only(enum pipe_format format)
+{
+   switch (format) {
+   case PIPE_FORMAT_Z24_UNORM_S8_UINT:
+      return PIPE_FORMAT_Z24X8_UNORM;
+
+   case PIPE_FORMAT_S8_UINT_Z24_UNORM:
+      return PIPE_FORMAT_X8Z24_UNORM;
+
+   case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT:
+      return PIPE_FORMAT_Z32_FLOAT;
+
+   default:
+      return format;
+   }
+}
+
+static inline boolean
+util_format_is_yuv(enum pipe_format format)
+{
+   const struct util_format_description *desc = util_format_description(format);
+
+   assert(desc);
+   if (!desc) {
+      return FALSE;
+   }
+
+   return desc->colorspace == UTIL_FORMAT_COLORSPACE_YUV;
+}
 
 /**
  * Calculates the depth format type based upon the incoming format description.
@@ -565,7 +609,7 @@ util_get_depth_format_type(const struct util_format_description *desc)
 {
    unsigned depth_channel = desc->swizzle[0];
    if (desc->colorspace == UTIL_FORMAT_COLORSPACE_ZS &&
-       depth_channel != UTIL_FORMAT_SWIZZLE_NONE) {
+       depth_channel != PIPE_SWIZZLE_NONE) {
       return desc->channel[depth_channel].type;
    } else {
       return UTIL_FORMAT_TYPE_VOID;
@@ -692,6 +736,9 @@ util_format_is_pure_uint(enum pipe_format format);
 boolean
 util_format_is_snorm(enum pipe_format format);
 
+boolean
+util_format_is_unorm(enum pipe_format format);
+
 boolean
 util_format_is_snorm8(enum pipe_format format);
 
@@ -704,13 +751,6 @@ boolean
 util_is_format_compatible(const struct util_format_description *src_desc,
                           const struct util_format_description *dst_desc);
 
-/**
- * Whether the format is supported by Gallium for the given bindings.
- * This covers S3TC textures and floating-point render targets.
- */
-boolean
-util_format_is_supported(enum pipe_format format, unsigned bind);
-
 /**
  * Whether this format is a rgab8 variant.
  *
@@ -742,7 +782,6 @@ util_format_is_rgba8_variant(const struct util_format_description *desc)
    return TRUE;
 }
 
-
 /**
  * Return total bits needed for the pixel format per block.
  */
@@ -872,13 +911,13 @@ util_format_get_component_bits(enum pipe_format format,
    }
 
    switch (desc->swizzle[component]) {
-   case UTIL_FORMAT_SWIZZLE_X:
+   case PIPE_SWIZZLE_X:
       return desc->channel[0].size;
-   case UTIL_FORMAT_SWIZZLE_Y:
+   case PIPE_SWIZZLE_Y:
       return desc->channel[1].size;
-   case UTIL_FORMAT_SWIZZLE_Z:
+   case PIPE_SWIZZLE_Z:
       return desc->channel[2].size;
-   case UTIL_FORMAT_SWIZZLE_W:
+   case PIPE_SWIZZLE_W:
       return desc->channel[3].size;
    default:
       return 0;
@@ -898,6 +937,8 @@ util_format_srgb(enum pipe_format format)
    switch (format) {
    case PIPE_FORMAT_L8_UNORM:
       return PIPE_FORMAT_L8_SRGB;
+   case PIPE_FORMAT_R8_UNORM:
+      return PIPE_FORMAT_R8_SRGB;
    case PIPE_FORMAT_L8A8_UNORM:
       return PIPE_FORMAT_L8A8_SRGB;
    case PIPE_FORMAT_R8G8B8_UNORM:
@@ -974,6 +1015,8 @@ util_format_linear(enum pipe_format format)
    switch (format) {
    case PIPE_FORMAT_L8_SRGB:
       return PIPE_FORMAT_L8_UNORM;
+   case PIPE_FORMAT_R8_SRGB:
+      return PIPE_FORMAT_R8_UNORM;
    case PIPE_FORMAT_L8A8_SRGB:
       return PIPE_FORMAT_L8A8_UNORM;
    case PIPE_FORMAT_R8G8B8_SRGB:
@@ -1215,6 +1258,22 @@ util_format_get_first_non_void_channel(enum pipe_format format)
    return i;
 }
 
+/**
+ * Whether this format is any 8-bit UNORM variant. Looser than
+ * util_is_rgba8_variant (also includes alpha textures, for instance).
+ */
+
+static inline bool
+util_format_is_unorm8(const struct util_format_description *desc)
+{
+   int c = util_format_get_first_non_void_channel(desc->format);
+
+   if (c == -1)
+      return false;
+
+   return desc->is_unorm && desc->is_array && desc->channel[c].size == 8;
+}
+
 /*
  * Format access functions.
  */
@@ -1283,6 +1342,19 @@ util_format_translate(enum pipe_format dst_format,
                       unsigned src_x, unsigned src_y,
                       unsigned width, unsigned height);
 
+boolean
+util_format_translate_3d(enum pipe_format dst_format,
+                         void *dst, unsigned dst_stride,
+                         unsigned dst_slice_stride,
+                         unsigned dst_x, unsigned dst_y,
+                         unsigned dst_z,
+                         enum pipe_format src_format,
+                         const void *src, unsigned src_stride,
+                         unsigned src_slice_stride,
+                         unsigned src_x, unsigned src_y,
+                         unsigned src_z, unsigned width,
+                         unsigned height, unsigned depth);
+
 /*
  * Swizzle operations.
  */
@@ -1298,19 +1370,22 @@ void util_format_compose_swizzles(const unsigned char swz1[4],
 
 /* Apply the swizzle provided in \param swz (which is one of PIPE_SWIZZLE_x)
  * to \param src and store the result in \param dst.
- * \param is_integer determines the value written for PIPE_SWIZZLE_ONE.
+ * \param is_integer determines the value written for PIPE_SWIZZLE_1.
  */
 void util_format_apply_color_swizzle(union pipe_color_union *dst,
                                      const union pipe_color_union *src,
                                      const unsigned char swz[4],
                                      const boolean is_integer);
 
-void util_format_swizzle_4f(float *dst, const float *src,
+void pipe_swizzle_4f(float *dst, const float *src,
                             const unsigned char swz[4]);
 
 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