[Mesa-dev] [PATCH 3/7] intel/isl: Add some helpers for working with RGBX formats

Jason Ekstrand jason at jlekstrand.net
Tue Jan 24 23:45:50 UTC 2017


---
 src/intel/isl/isl.h        | 11 +++++++++++
 src/intel/isl/isl_format.c | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 43 insertions(+)

diff --git a/src/intel/isl/isl.h b/src/intel/isl/isl.h
index 07368f9..9d5b372 100644
--- a/src/intel/isl/isl.h
+++ b/src/intel/isl/isl.h
@@ -1138,8 +1138,19 @@ isl_format_is_rgb(enum isl_format fmt)
           isl_format_layouts[fmt].channels.a.bits == 0;
 }
 
+static inline bool
+isl_format_is_rgbx(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 &&
+          isl_format_layouts[fmt].channels.a.type == ISL_VOID;
+}
+
 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;
+enum isl_format isl_format_rgbx_to_rgba(enum isl_format rgb) ATTRIBUTE_CONST;
 
 bool isl_is_storage_image_format(enum isl_format fmt);
 
diff --git a/src/intel/isl/isl_format.c b/src/intel/isl/isl_format.c
index c8daece..8473285 100644
--- a/src/intel/isl/isl_format.c
+++ b/src/intel/isl/isl_format.c
@@ -623,3 +623,35 @@ isl_format_rgb_to_rgbx(enum isl_format rgb)
       return ISL_FORMAT_UNSUPPORTED;
    }
 }
+
+enum isl_format
+isl_format_rgbx_to_rgba(enum isl_format rgbx)
+{
+   assert(isl_format_is_rgbx(rgbx));
+
+   switch (rgbx) {
+   case ISL_FORMAT_R32G32B32X32_FLOAT:
+      return ISL_FORMAT_R32G32B32A32_FLOAT;
+   case ISL_FORMAT_R16G16B16X16_UNORM:
+      return ISL_FORMAT_R16G16B16A16_UNORM;
+   case ISL_FORMAT_R16G16B16X16_FLOAT:
+      return ISL_FORMAT_R16G16B16A16_FLOAT;
+   case ISL_FORMAT_B8G8R8X8_UNORM:
+      return ISL_FORMAT_B8G8R8A8_UNORM;
+   case ISL_FORMAT_B8G8R8X8_UNORM_SRGB:
+      return ISL_FORMAT_B8G8R8A8_UNORM_SRGB;
+   case ISL_FORMAT_R8G8B8X8_UNORM:
+      return ISL_FORMAT_R8G8B8A8_UNORM;
+   case ISL_FORMAT_R8G8B8X8_UNORM_SRGB:
+      return ISL_FORMAT_R8G8B8A8_UNORM_SRGB;
+   case ISL_FORMAT_B10G10R10X2_UNORM:
+      return ISL_FORMAT_B10G10R10A2_UNORM;
+   case ISL_FORMAT_B5G5R5X1_UNORM:
+      return ISL_FORMAT_B5G5R5A1_UNORM;
+   case ISL_FORMAT_B5G5R5X1_UNORM_SRGB:
+      return ISL_FORMAT_B5G5R5A1_UNORM_SRGB;
+   default:
+      assert(!"Invalid RGBX format");
+      return rgbx;
+   }
+}
-- 
2.5.0.400.gff86faf



More information about the mesa-dev mailing list