[Beignet] [PATCH OCL20 1/5] Runtime: Add support for sRGB

Xiuli Pan xiuli.pan at intel.com
Fri Mar 4 02:05:20 UTC 2016


From: Pan Xiuli <xiuli.pan at intel.com>

CL_sRGBA with CL_UNNORM_INT8 is the minimum request for OpenCL2.0
and CL_sBGRA is also support by hardware.
None of the sRGB surface type suport hardware write.

Signed-off-by: Pan Xiuli <xiuli.pan at intel.com>
---
 backend/src/ocl_common_defines.h |  7 ++++++-
 src/cl_api.c                     |  2 +-
 src/cl_image.c                   | 19 ++++++++++++++++++-
 utests/utest_helper.cpp          |  2 ++
 4 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/backend/src/ocl_common_defines.h b/backend/src/ocl_common_defines.h
index cb9190a..1278f25 100644
--- a/backend/src/ocl_common_defines.h
+++ b/backend/src/ocl_common_defines.h
@@ -5,7 +5,7 @@
 //
 // Common defines for Image intrinsics
 // Channel order
-#define CLK_HAS_ALPHA(color) (color == CLK_A || color == CLK_RA || color == CLK_RGBA || color == CLK_BGRA || color == CLK_ARGB)
+#define CLK_HAS_ALPHA(color) (color == CLK_A || color == CLK_RA || color == CLK_RGBA || color == CLK_BGRA || color == CLK_ARGB || color == CLK_sRGBA || color == CLK_sBGRA)
 enum {
   CLK_R = 0x10B0,
   CLK_A = 0x10B1,
@@ -29,6 +29,11 @@ enum {
   CLK_RGx = 0x10BB,
   CLK_RGBx = 0x10BC
 #endif
+#if (__NV_CL_C_VERSION >= __NV_CL_C_VERSION_2_0)
+  ,
+  CLK_sRGBA = 0x10C1,
+  CLK_sBGRA = 0x10C2
+#endif
 };
 
 
diff --git a/src/cl_api.c b/src/cl_api.c
index d04ad44..e18ff5c 100644
--- a/src/cl_api.c
+++ b/src/cl_api.c
@@ -600,7 +600,7 @@ clCreateImage(cl_context context,
     goto error;
   }
   if (image_format->image_channel_order < CL_R ||
-          image_format->image_channel_order > CL_RGBx) {
+          image_format->image_channel_order > CL_sBGRA) {
     err = CL_INVALID_IMAGE_FORMAT_DESCRIPTOR;
     goto error;
   }
diff --git a/src/cl_image.c b/src/cl_image.c
index d58bdf3..47298b6 100644
--- a/src/cl_image.c
+++ b/src/cl_image.c
@@ -91,6 +91,13 @@ cl_image_byte_per_pixel(const cl_image_format *fmt, uint32_t *bpp)
         return CL_INVALID_IMAGE_FORMAT_DESCRIPTOR;
       *bpp *= 4;
     break;
+    case CL_sRGBA:
+    case CL_sBGRA:
+      if (type != CL_UNORM_INT8)
+        return CL_INVALID_IMAGE_FORMAT_DESCRIPTOR;
+      *bpp *= 4;
+    break;
+
     default: return CL_INVALID_IMAGE_FORMAT_DESCRIPTOR;
   };
 
@@ -189,13 +196,23 @@ cl_image_get_intel_format(const cl_image_format *fmt)
         case CL_UNORM_INT8:     return I965_SURFACEFORMAT_B8G8R8A8_UNORM;
         default: return INTEL_UNSUPPORTED_FORMAT;
       };
+    case CL_sRGBA:
+      switch (type) {
+        case CL_UNORM_INT8:     return I965_SURFACEFORMAT_R8G8B8A8_UNORM_SRGB;
+        default: return INTEL_UNSUPPORTED_FORMAT;
+      };
+    case CL_sBGRA:
+      switch (type) {
+        case CL_UNORM_INT8:     return I965_SURFACEFORMAT_B8G8R8A8_UNORM_SRGB;
+        default: return INTEL_UNSUPPORTED_FORMAT;
+      };
     default: return INTEL_UNSUPPORTED_FORMAT;
   };
 }
 
 static const uint32_t cl_image_order[] = {
   CL_R, CL_A, CL_RG, CL_RA, CL_RGB, CL_RGBA, CL_BGRA, CL_ARGB,
-  CL_INTENSITY, CL_LUMINANCE, CL_Rx, CL_RGx, CL_RGBx
+  CL_INTENSITY, CL_LUMINANCE, CL_Rx, CL_RGx, CL_RGBx, CL_sRGBA, CL_sBGRA
 };
 
 static const uint32_t cl_image_type[] = {
diff --git a/utests/utest_helper.cpp b/utests/utest_helper.cpp
index d265d4c..f65360d 100644
--- a/utests/utest_helper.cpp
+++ b/utests/utest_helper.cpp
@@ -169,6 +169,8 @@ cl_test_channel_order_string(cl_channel_order order)
     DECL_ORDER(Rx);
     DECL_ORDER(RGx);
     DECL_ORDER(RGBx);
+    DECL_ORDER(sRGBA);
+    DECL_ORDER(sBGRA);
 #undef DECL_ORDER
     default: return "Unsupported image channel order";
   };
-- 
2.5.0



More information about the Beignet mailing list