isl/format: Add some helpers for working with RGB formats
authorJason Ekstrand <jason.ekstrand@intel.com>
Thu, 31 Dec 2015 22:57:51 +0000 (14:57 -0800)
committerJason Ekstrand <jason.ekstrand@intel.com>
Tue, 5 Jan 2016 00:08:05 +0000 (16:08 -0800)
src/isl/isl.h
src/isl/isl_format.c

index c6baca0978d6619b708035c939a902fd3d1e3ffe..842bbbb0265ea1a2ac00dd35c6797fcea7ee366f 100644 (file)
@@ -823,6 +823,18 @@ isl_format_block_is_1x1x1(enum isl_format fmt)
    return fmtl->bw == 1 && fmtl->bh == 1 && fmtl->bd == 1;
 }
 
+static inline bool
+isl_format_is_rgb(enum isl_format fmt)
+{
+   return isl_format_layouts[fmt].channels.r.bits > 0 &&
+          isl_format_layouts[fmt].channels.g.bits > 0 &&
+          isl_format_layouts[fmt].channels.b.bits > 0 &&
+          isl_format_layouts[fmt].channels.a.bits == 0;
+}
+
+enum isl_format isl_format_rgb_to_rgba(enum isl_format rgb) ATTRIBUTE_CONST;
+enum isl_format isl_format_rgb_to_rgbx(enum isl_format rgb) ATTRIBUTE_CONST;
+
 bool isl_is_storage_image_format(enum isl_format fmt);
 
 enum isl_format
index bebbd6efbc033667516775d19ebf878a424e38be..0fe6e9b83ab3238b51dd81a599305d8beaf0ee81 100644 (file)
@@ -39,3 +39,57 @@ isl_format_has_sint_channel(enum isl_format fmt)
           fmtl->channels.p.type == ISL_SINT ||
           fmtl->channels.g.type == ISL_SINT;
 }
+
+enum isl_format
+isl_format_rgb_to_rgba(enum isl_format rgb)
+{
+   assert(isl_format_is_rgb(rgb));
+
+   switch (rgb) {
+   case ISL_FORMAT_R32G32B32_FLOAT:    return ISL_FORMAT_R32G32B32A32_FLOAT;
+   case ISL_FORMAT_R32G32B32_SINT:     return ISL_FORMAT_R32G32B32A32_SINT;
+   case ISL_FORMAT_R32G32B32_UINT:     return ISL_FORMAT_R32G32B32A32_UINT;
+   case ISL_FORMAT_R32G32B32_UNORM:    return ISL_FORMAT_R32G32B32A32_UNORM;
+   case ISL_FORMAT_R32G32B32_SNORM:    return ISL_FORMAT_R32G32B32A32_SNORM;
+   case ISL_FORMAT_R32G32B32_SSCALED:  return ISL_FORMAT_R32G32B32A32_SSCALED;
+   case ISL_FORMAT_R32G32B32_USCALED:  return ISL_FORMAT_R32G32B32A32_USCALED;
+   case ISL_FORMAT_R32G32B32_SFIXED:   return ISL_FORMAT_R32G32B32A32_SFIXED;
+   case ISL_FORMAT_R8G8B8_UNORM:       return ISL_FORMAT_R8G8B8A8_UNORM;
+   case ISL_FORMAT_R8G8B8_SNORM:       return ISL_FORMAT_R8G8B8A8_SNORM;
+   case ISL_FORMAT_R8G8B8_SSCALED:     return ISL_FORMAT_R8G8B8A8_SSCALED;
+   case ISL_FORMAT_R8G8B8_USCALED:     return ISL_FORMAT_R8G8B8A8_USCALED;
+   case ISL_FORMAT_R16G16B16_FLOAT:    return ISL_FORMAT_R16G16B16A16_FLOAT;
+   case ISL_FORMAT_R16G16B16_UNORM:    return ISL_FORMAT_R16G16B16A16_UNORM;
+   case ISL_FORMAT_R16G16B16_SNORM:    return ISL_FORMAT_R16G16B16A16_SNORM;
+   case ISL_FORMAT_R16G16B16_SSCALED:  return ISL_FORMAT_R16G16B16A16_SSCALED;
+   case ISL_FORMAT_R16G16B16_USCALED:  return ISL_FORMAT_R16G16B16A16_USCALED;
+   case ISL_FORMAT_R8G8B8_UNORM_SRGB:  return ISL_FORMAT_R8G8B8A8_UNORM_SRGB;
+   case ISL_FORMAT_R16G16B16_UINT:     return ISL_FORMAT_R16G16B16A16_UINT;
+   case ISL_FORMAT_R16G16B16_SINT:     return ISL_FORMAT_R16G16B16A16_SINT;
+   case ISL_FORMAT_R8G8B8_UINT:        return ISL_FORMAT_R8G8B8A8_UINT;
+   case ISL_FORMAT_R8G8B8_SINT:        return ISL_FORMAT_R8G8B8A8_SINT;
+   default:
+      return ISL_FORMAT_UNSUPPORTED;
+   }
+}
+
+enum isl_format
+isl_format_rgb_to_rgbx(enum isl_format rgb)
+{
+   assert(isl_format_is_rgb(rgb));
+
+   switch (rgb) {
+   case ISL_FORMAT_R32G32B32_FLOAT:
+      return ISL_FORMAT_R32G32B32X32_FLOAT;
+   case ISL_FORMAT_R16G16B16_UNORM:
+      return ISL_FORMAT_R16G16B16X16_UNORM;
+   case ISL_FORMAT_R16G16B16_FLOAT:
+      return ISL_FORMAT_R16G16B16X16_FLOAT;
+   case ISL_FORMAT_R8G8B8_UNORM:
+      return ISL_FORMAT_R8G8B8X8_UNORM;
+   case ISL_FORMAT_R8G8B8_UNORM_SRGB:
+      return ISL_FORMAT_R8G8B8X8_UNORM_SRGB;
+   default:
+      return ISL_FORMAT_UNSUPPORTED;
+   }
+}