[Mesa-dev] [RFC] [PATCH 0/3] Introduce a new EGL/DRI extension for resource sharing with Open CL.

2013-07-14 Thread Zhigang Gong
Hi Kristian,

The OpenCL spec has one extension to support interoperation between OpenGL and 
OpenCL.
The key requirement for this extension is to export an OpenGL resource
(texture/buffer object/render buffer)'s internal attributes to the OpenCL's 
driver side.

IMHO, to support that cl extension we may need to add a new extension to the 
EGL/DRI layer
which let the OpenCL driver could use this interface to query the low level 
attributes of
the resource from the mesa dri driver side. Thus I propose this extension as 
below:

EGLAPI EGLBoolean EGLAPIENTRY eglAcquireResourceMESA(EGLDisplay dpy, EGLContext 
ctx, const EGLenum target, const EGLint *attrib_list, void * user_data);
EGLAPI EGLBoolean EGLAPIENTRY eglReleaseResourceMESA(EGLDisplay dpy, EGLContext 
ctx, const EGLenum target, const EGLint *attrib_list);

The first API is to acquire the specified resource and get the low level 
attribute back
in the driver specified user_data structure. The OpenCL side could use this 
structure to
create a correct buffer object in OpenCL domain. The eglAcquireResourceMESA 
will also
implicitly increase the resoruce's reference counter.

The second API is to be called when the resource is no longer be shared with 
Open CL
domain. It will decrease the resource's reference counter.

The following patchset is to implement this extension, and I also implemented 
the OpenCL side
on Beignet's runtime library. The texture sharing part works fine.

Any comments are welcome and if this new extension is not the right way to 
solve the
original problem, please feel free to point it out and kindly guide which is 
the right
way to implement the cl-gl interoperations. Thanks.

Zhigang Gong (3):
  EGL: introduce a new extension to share resource with external
library.
  DRI: implement helper functions for dri resource sharing extension.
  i965: implement driResourceSharing extension.

 include/EGL/eglext.h   |   19 ++
 include/GL/internal/dri_interface.h|   19 ++
 src/egl/drivers/dri2/egl_dri2.c|  167 +
 src/egl/drivers/dri2/egl_dri2.h|2 +
 src/egl/main/Makefile.am   |4 +-
 src/egl/main/eglapi.c  |   33 
 src/egl/main/eglapi.h  |9 +
 src/egl/main/eglresshare.c |  139 ++
 src/egl/main/eglresshare.h |   47 +
 src/mesa/drivers/dri/common/dri_util.c |   48 +
 src/mesa/drivers/dri/common/dri_util.h |   10 +
 src/mesa/drivers/dri/i965/Makefile.am  |2 +
 src/mesa/drivers/dri/i965/Makefile.sources |1 +
 .../drivers/dri/i965/intel_dri_resource_share.c|  192 
 .../drivers/dri/i965/intel_dri_resource_share.h|   36 
 src/mesa/drivers/dri/i965/intel_screen.c   |9 +-
 src/mesa/drivers/dri/i965/intel_screen.h   |   10 +
 17 files changed, 745 insertions(+), 2 deletions(-)
 create mode 100644 src/egl/main/eglresshare.c
 create mode 100644 src/egl/main/eglresshare.h
 create mode 100644 src/mesa/drivers/dri/i965/intel_dri_resource_share.c
 create mode 100644 src/mesa/drivers/dri/i965/intel_dri_resource_share.h

-- 
1.7.9.5

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [RFC] [PATCH 1/3] EGL: introduce a new extension to share resource with external library.

2013-07-14 Thread Zhigang Gong
OpenCL has some extension can create CL memory object from GL
textures/buffer objects/render buffers. The existing extension
can't satisfied this requirement. As we need to pass the resource
handler directly to the dri driver layer and get some low level
information back which may include the low level buffer object
handler/name, the internal color format and the layout and tiling
information. Then the external library, say Open CL's driver module,
could use this information to create an shared CL memory object.

As Open CL defines a strict usage model of GL-CL interoperations,
it simplfy the requirement of this extension. We just need to provide
two functions,
1. The acquireResource method to get those information and increase
the underlying reference counter of the buffer object at dri driver layer.
2. The releaseResource method to decrease the underlying reference counter
at dri driver layer.

Signed-off-by: Zhigang Gong 
---
 include/EGL/eglext.h|   19 
 include/GL/internal/dri_interface.h |   19 
 src/egl/drivers/dri2/egl_dri2.c |  167 +++
 src/egl/drivers/dri2/egl_dri2.h |2 +
 src/egl/main/Makefile.am|4 +-
 src/egl/main/eglapi.c   |   33 +++
 src/egl/main/eglapi.h   |9 ++
 src/egl/main/eglresshare.c  |  139 +
 src/egl/main/eglresshare.h  |   47 ++
 9 files changed, 438 insertions(+), 1 deletion(-)
 create mode 100644 src/egl/main/eglresshare.c
 create mode 100644 src/egl/main/eglresshare.h

diff --git a/include/EGL/eglext.h b/include/EGL/eglext.h
index 1d68178..1e2be31 100644
--- a/include/EGL/eglext.h
+++ b/include/EGL/eglext.h
@@ -283,6 +283,25 @@ typedef EGLImageKHR (EGLAPIENTRYP 
PFNEGLCREATEDRMIMAGEMESAPROC) (EGLDisplay dpy,
 typedef EGLBoolean (EGLAPIENTRYP PFNEGLEXPORTDRMIMAGEMESAPROC) (EGLDisplay 
dpy, EGLImageKHR image, EGLint *name, EGLint *handle, EGLint *stride);
 #endif
 
+#ifndef EGL_MESA_cl_khr_gl_sharing
+#define EGL_MESA_cl_khr_gl_sharing 1
+#define EGL_CLGL_TEXTURE_MESA0x3300  /* eglAcuireResource target */
+#define EGL_CLGL_BUFFER_OBJECT_MESA   0x3301  /* eglAcuireResource target 
*/
+#define EGL_CLGL_RENDER_BUFFER_MESA   0x3302  /* eglAcuireResource target 
*/
+#define EGL_CLGL_TEXTURE_ID_MESA 0x3303  /* eglAcuireResource 
attribute */
+#define EGL_CLGL_TEXTURE_LEVEL_MESA  0x3304  /* eglAcuireResource 
attribute */
+#define EGL_CLGL_TEXTURE_TARGET_MESA 0x3305  /* eglAcuireResource 
attribute */
+#define EGL_CLGL_BUFFER_OBJECT_ID_MESA0x3306  /* eglAcuireResource 
attribute */
+#define EGL_CLGL_RENDER_BUFFER_ID_MESA0x3307  /* eglAcuireResource 
attribute */
+
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglAcquireResourceMESA(EGLDisplay dpy, 
EGLContext ctx, const EGLenum target, const EGLint *attrib_list, void * 
user_data);
+EGLAPI EGLBoolean EGLAPIENTRY eglReleaseResourceMESA(EGLDisplay dpy, 
EGLContext ctx, const EGLenum target, const EGLint *attrib_list);
+#endif
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLACQUIRERESOURCEMESAPROC) (EGLDisplay 
dpy, EGLContext ctx, const EGLenum target, const EGLint *attrib_list, void * 
user_data);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLRELEASERESOURCEMESAPROC) (EGLDisplay 
dpy, EGLContext ctx, const EGLenum target, const EGLint *attrib_list);
+#endif
+
 #ifndef EGL_NV_post_sub_buffer
 #define EGL_NV_post_sub_buffer 1
 #define EGL_POST_SUB_BUFFER_SUPPORTED_NV   0x30BE
diff --git a/include/GL/internal/dri_interface.h 
b/include/GL/internal/dri_interface.h
index 30ce175..0d799e6 100644
--- a/include/GL/internal/dri_interface.h
+++ b/include/GL/internal/dri_interface.h
@@ -1169,6 +1169,25 @@ struct __DRI2configQueryExtensionRec {
 };
 
 /**
+ * This extension allows to share GL resources with OpenCL.
+ */
+#define __DRI_RESOURCE_SHARE "DRI_RESOURCE_SHARE"
+#define __DRI_RESOURCE_SHARE_VERSION 1
+typedef struct __DRIResourceShareExtensionRec __DRIResourceShareExtension;
+struct __DRIResourceShareExtensionRec {
+   __DRIextension base;
+
+   GLboolean (*acquireTexture)(__DRIcontext *context, GLenum target,
+  GLint level, GLuint texture, void 
*user_data);
+   GLboolean (*releaseTexture)(__DRIcontext *context, GLenum target,
+  GLint level, GLuint texture);
+   GLboolean (*acquireBufferObj)(__DRIcontext *context, GLuint bufobj, void 
*user_data);
+   GLboolean (*releaseBufferObj)(__DRIcontext *context, GLuint bufobj);
+   GLboolean (*acquireRenderBuffer)(__DRIcontext *context, GLuint rb, void 
*user_data);
+   GLboolean (*releaseRenderBuffer)(__DRIcontext *context, GLuint rb);
+};
+
+/**
  * Robust context driver extension.
  *
  * Existence of this extension means the driver can accept the
diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 1bce314..c8a2a8b 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/

[Mesa-dev] [RFC] [PATCH 2/3] DRI: implement helper functions for dri resource sharing extension.

2013-07-14 Thread Zhigang Gong
Signed-off-by: Zhigang Gong 
---
 src/mesa/drivers/dri/common/dri_util.c |   48 
 src/mesa/drivers/dri/common/dri_util.h |   10 +++
 2 files changed, 58 insertions(+)

diff --git a/src/mesa/drivers/dri/common/dri_util.c 
b/src/mesa/drivers/dri/common/dri_util.c
index 9ed9df4..4f798dc 100644
--- a/src/mesa/drivers/dri/common/dri_util.c
+++ b/src/mesa/drivers/dri/common/dri_util.c
@@ -520,6 +520,43 @@ dri2ReleaseBuffer(__DRIscreen *screen, __DRIbuffer *buffer)
 driDriverAPI.ReleaseBuffer(screen, buffer);
 }
 
+static GLboolean
+driAcquireTexture(__DRIcontext *context, GLenum target,
+  GLint level, GLuint texture, void *user_data)
+{
+return driDriverAPI.AcquireTexture(context, target, level, texture, 
user_data);
+}
+
+static GLboolean
+driReleaseTexture(__DRIcontext *context, GLenum target,
+  GLint level, GLuint texture)
+{
+return driDriverAPI.ReleaseTexture(context, target, level, texture);
+}
+
+static GLboolean
+driAcquireBufferObj(__DRIcontext *context, GLuint bufobj, void *user_data)
+{
+return driDriverAPI.AcquireBufferObj(context, bufobj, user_data);
+}
+
+static GLboolean
+driReleaseBufferObj(__DRIcontext *context, GLuint bufobj)
+{
+return driDriverAPI.ReleaseBufferObj(context, bufobj);
+}
+
+static GLboolean
+driAcquireRenderBuffer(__DRIcontext *context, GLuint rb, void *user_data)
+{
+return driDriverAPI.AcquireBufferObj(context, rb, user_data);
+}
+
+static GLboolean
+driReleaseRenderBuffer(__DRIcontext *context, GLuint rb)
+{
+return driDriverAPI.ReleaseBufferObj(context, rb);
+}
 
 static int
 dri2ConfigQueryb(__DRIscreen *screen, const char *var, GLboolean *val)
@@ -603,6 +640,17 @@ const __DRI2configQueryExtension dri2ConfigQueryExtension 
= {
.configQueryf= dri2ConfigQueryf,
 };
 
+const __DRIResourceShareExtension driResourceShareExtension = {
+   .base = { __DRI_RESOURCE_SHARE, __DRI_RESOURCE_SHARE_VERSION },
+
+   .acquireTexture= driAcquireTexture,
+   .releaseTexture= driReleaseTexture,
+   .acquireBufferObj  = driAcquireBufferObj,
+   .releaseBufferObj  = driReleaseBufferObj,
+   .acquireRenderBuffer   = driAcquireRenderBuffer,
+   .releaseRenderBuffer   = driReleaseRenderBuffer
+};
+
 void
 dri2InvalidateDrawable(__DRIdrawable *drawable)
 {
diff --git a/src/mesa/drivers/dri/common/dri_util.h 
b/src/mesa/drivers/dri/common/dri_util.h
index 900f048..393d00a 100644
--- a/src/mesa/drivers/dri/common/dri_util.h
+++ b/src/mesa/drivers/dri/common/dri_util.h
@@ -65,6 +65,7 @@ extern const __DRIcoreExtension driCoreExtension;
 extern const __DRIswrastExtension driSWRastExtension;
 extern const __DRIdri2Extension driDRI2Extension;
 extern const __DRI2configQueryExtension dri2ConfigQueryExtension;
+extern const __DRIResourceShareExtension driResourceShareExtension;
 
 /**
  * Driver callback functions.
@@ -113,6 +114,15 @@ struct __DriverAPIRec {
 int width, int height);
 
 void (*ReleaseBuffer) (__DRIscreen *screenPrivate, __DRIbuffer *buffer);
+
+GLboolean (*AcquireTexture) (__DRIcontext *driContextPriv, GLenum target, 
GLint level, GLuint tex, void *user_data);
+GLboolean (*ReleaseTexture) (__DRIcontext *driContextPriv, GLenum target, 
GLint level, GLuint tex);
+
+GLboolean (*AcquireBufferObj) (__DRIcontext *driContextPriv, GLuint 
bufobj, void *user_data);
+GLboolean (*ReleaseBufferObj) (__DRIcontext *driContextPriv, GLuint 
bufobj);
+
+GLboolean (*AcquireRenderBuffer) (__DRIcontext *driContextPriv, GLuint rb, 
void *user_data);
+GLboolean (*ReleaseRenderBuffer) (__DRIcontext *driContextPriv, GLuint rb);
 };
 
 extern const struct __DriverAPIRec driDriverAPI;
-- 
1.7.9.5

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [RFC] [PATCH 3/3] i965: implement driResourceSharing extension.

2013-07-14 Thread Zhigang Gong
This patch implements the texture sharing.

Signed-off-by: Zhigang Gong 
---
 src/mesa/drivers/dri/i965/Makefile.am  |2 +
 src/mesa/drivers/dri/i965/Makefile.sources |1 +
 .../drivers/dri/i965/intel_dri_resource_share.c|  192 
 .../drivers/dri/i965/intel_dri_resource_share.h|   36 
 src/mesa/drivers/dri/i965/intel_screen.c   |9 +-
 src/mesa/drivers/dri/i965/intel_screen.h   |   10 +
 6 files changed, 249 insertions(+), 1 deletion(-)
 create mode 100644 src/mesa/drivers/dri/i965/intel_dri_resource_share.c
 create mode 100644 src/mesa/drivers/dri/i965/intel_dri_resource_share.h

diff --git a/src/mesa/drivers/dri/i965/Makefile.am 
b/src/mesa/drivers/dri/i965/Makefile.am
index 27c67d1..d456910 100644
--- a/src/mesa/drivers/dri/i965/Makefile.am
+++ b/src/mesa/drivers/dri/i965/Makefile.am
@@ -48,6 +48,8 @@ AM_CFLAGS += \
-DFEATURE_ES2=1
 endif
 
+include_HEADERS = intel_dri_resource_share.h
+
 AM_CXXFLAGS = $(AM_CFLAGS)
 
 dridir = $(DRI_DRIVER_INSTALL_DIR)
diff --git a/src/mesa/drivers/dri/i965/Makefile.sources 
b/src/mesa/drivers/dri/i965/Makefile.sources
index 1f401fe..695d9b3 100644
--- a/src/mesa/drivers/dri/i965/Makefile.sources
+++ b/src/mesa/drivers/dri/i965/Makefile.sources
@@ -14,6 +14,7 @@ i965_FILES = \
intel_regions.c \
intel_resolve_map.c \
intel_screen.c \
+intel_dri_resource_share.c \
intel_pixel.c \
intel_pixel_bitmap.c \
intel_pixel_copy.c \
diff --git a/src/mesa/drivers/dri/i965/intel_dri_resource_share.c 
b/src/mesa/drivers/dri/i965/intel_dri_resource_share.c
new file mode 100644
index 000..ffcc5ce
--- /dev/null
+++ b/src/mesa/drivers/dri/i965/intel_dri_resource_share.c
@@ -0,0 +1,192 @@
+/**
+ *
+ * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **/
+
+#include 
+#include 
+#include "main/glheader.h"
+#include "main/context.h"
+#include "main/framebuffer.h"
+#include "main/renderbuffer.h"
+#include "main/texobj.h"
+#include "main/hash.h"
+#include "main/fbobject.h"
+#include "main/version.h"
+
+#include "utils.h"
+#include "xmlpool.h"
+
+#include "intel_batchbuffer.h"
+#include "intel_buffers.h"
+#include "intel_bufmgr.h"
+#include "intel_chipset.h"
+#include "intel_fbo.h"
+#include "intel_mipmap_tree.h"
+#include "intel_screen.h"
+#include "intel_tex.h"
+#include "intel_regions.h"
+#include "intel_context.h"
+
+#include "i915_drm.h"
+#include "intel_dri_resource_share.h"
+
+
+/**
+ * Sets up a DRIImage structure to point to our shared image in a region
+ */
+static GLboolean
+intel_setup_cl_region_from_mipmap_tree(struct intel_context *intel,
+   struct intel_mipmap_tree *mt,
+   GLuint level, GLuint zoffset,
+   struct _intel_dri_share_image_region 
*region)
+{
+   unsigned int draw_x, draw_y;
+   uint32_t mask_x, mask_y;
+   struct intel_region *null_region = (struct intel_region *)NULL;
+
+   intel_miptree_check_level_layer(mt, level, zoffset);
+
+   intel_region_get_tile_masks(mt->region, &mask_x, &mask_y, false);
+   intel_miptree_get_image_offset(mt, level, zoffset, &draw_x, &draw_y);
+
+   region->w = mt->level[level].width;
+   region->h = mt->level[level].height;
+   region->tile_x = draw_x & mask_x;
+   region->tile_y = draw_y & mask_y

[Mesa-dev] [PATCH v2 1/4] Introduce a new EGL extension MESA_EGL_resource_sharing

2013-07-16 Thread Zhigang Gong
This extension provides entry points for exposing internal GL
resouces to external libraries for sharing access purpose. One good
candiate of the external library is the Open CL GL extension. The
extension lets applications can acquire a low level attributes of the
given texture/buffer object/render buffer. The low level attributes
are defined at dri driver layer. It a driver specific data structure
which could be used by the external library (Open Cl driver) to
create another shared buffer object to access the same resource
correctly.

Signed-off-by: Zhigang Gong 
---
 docs/specs/MESA_resource_sharing.spec |  134 +
 1 file changed, 134 insertions(+)
 create mode 100644 docs/specs/MESA_resource_sharing.spec

diff --git a/docs/specs/MESA_resource_sharing.spec 
b/docs/specs/MESA_resource_sharing.spec
new file mode 100644
index 000..a226997
--- /dev/null
+++ b/docs/specs/MESA_resource_sharing.spec
@@ -0,0 +1,134 @@
+Name
+
+MESA_resource_sharing
+
+Name Strings
+
+EGL_MESA_resource_sharing
+
+Contact
+
+Zhigang Gong 
+
+Status
+
+Proposal
+
+Version
+
+Version 1, Jul 16, 2013
+
+Number
+
+EGL Extension #not assigned
+
+Dependencies
+
+Requires EGL 1.4 or later.  This extension is written against the
+wording of the EGL 1.4 specification.
+
+Overview
+
+This extension provides entry points for exposing internal GL
+resouces to external libraries for sharing access purpose. One good
+candiate of the external library is the Open CL GL extension. The
+extension lets applications can acquire a low level attributes of the
+given texture/buffer object/render buffer. The low level attributes
+are defined at dri driver layer. It a driver specific data structure
+which could be used by the external library (Open Cl driver) to
+create another shared buffer object to access the same resource
+correctly.
+
+IP Status
+
+Open-source; freely implementable.
+
+New Procedures and Functions
+
+EGLBoolean eglAcquireResourceMESA(EGLDisplay dpy,
+  EGLContext ctx,
+  const EGLenum target,
+  const EGLint *attrib_list,
+  void * user_data);
+EGLBoolean eglReleaseResourceMESA(EGLDisplay dpy,
+  EGLContext ctx,
+  const EGLenum target,
+  const EGLint *attrib_list);
+
+New Tokens
+
+Accepted in  parameter of eglAcquireResourceMESA and
+eglReleaseResourceMESA:
+
+EGL_GL_TEXTURE_MESA 0x3300
+EGL_GL_BUFFER_OBJECT_MESA   0x3301
+EGL_GL_RENDER_BUFFER_MESA   0x3302
+
+Accepted in the  parameter of eglAcquireResourceMESA
+and eglReleaseResourceMESA:
+EGL_GL_TEXTURE_ID_MESA  0x3303
+EGL_GL_TEXTURE_LEVEL_MESA   0x3304
+EGL_GL_TEXTURE_TARGET_MESA  0x3305
+EGL_GL_BUFFER_OBJECT_ID_MESA0x3306
+EGL_GL_RENDER_BUFFER_ID_MESA0x3307
+
+Accepted as value for the EGL_GL_TEXTURE_ID_MESA:
+
+A valid texture id which is created from the specified context.
+And the texture object should be complete.
+
+Values accepted for EGL_GL_TEXTURE_LEVEL_MESA/TARGET_MESA:
+
+   The mipmap level and the corresponding texture target for the
+   specified texture id.
+
+Value accepted for EGL_GL_BUFFER_OBJECT_ID_MESA:
+   A valid buffer object id in the specified context and should
+   be allocated.
+
+Value accepeted for EGL_GL_RENDER_BUFFER_ID_MESA:
+   A valid render buffer id created in the specified context.
+
+Additions to the EGL 1.4 Specification:
+
+To expose a resource to external library, call
+
+EGLImageKHR eglAcquireResourceMESA(EGLDisplay dpy,
+   EGLContext ctx,
+   EGLenum target,
+   const EGLint *attrib_list,
+   void * user_data);
+Use the target parameter to identify whether this resource is
+texture/buffer object or render buffer. In the attribute list, we
+can get all the needed values for the specified resource target.
+The user_data should be a driver specified data structure and EGL
+layer just need to treat it as an opaque pointer. EGL/dri2 driver
+need to call the registered dri driver layer function and pass the
+corresponding resource parameter and the user_data pointer to the
+dri driver layer. And if the driver layer has a valid implementation,
+then the driver should lookup the resource's object from the
+specified context, and get the needed attributes into the user_data
+structure. Take texture in i965 platform as an example, it needs to
+get the texture object's width/he

[Mesa-dev] [PATCH v2 2/4] EGL: Implement the new extension MESA_EGL_extension_sharing.

2013-07-16 Thread Zhigang Gong
OpenCL has some extension can create CL memory object from GL
textures/buffer objects/render buffers. The existing extension
can't satisfied this requirement. As we need to pass the resource
handler directly to the dri driver layer and get some low level
information back which may include the low level buffer object
handler/name, the internal color format and the layout and tiling
information. Then the external library, say Open CL's driver module,
could use this information to create an shared CL memory object.

As Open CL defines a strict usage model of GL-CL interoperations,
it simplfy the requirement of this extension. We just need to provide
two functions,
1. The acquireResource method to get those information and increase
the underlying reference counter of the buffer object at dri driver layer.
2. The releaseResource method to decrease the underlying reference counter
at dri driver layer.

Signed-off-by: Zhigang Gong 
---
 include/EGL/eglext.h|   19 
 include/GL/internal/dri_interface.h |   19 
 src/egl/drivers/dri2/egl_dri2.c |  167 +++
 src/egl/drivers/dri2/egl_dri2.h |2 +
 src/egl/main/Makefile.am|4 +-
 src/egl/main/eglapi.c   |   33 +++
 src/egl/main/eglapi.h   |9 ++
 src/egl/main/eglresshare.c  |  139 +
 src/egl/main/eglresshare.h  |   47 ++
 9 files changed, 438 insertions(+), 1 deletion(-)
 create mode 100644 src/egl/main/eglresshare.c
 create mode 100644 src/egl/main/eglresshare.h

diff --git a/include/EGL/eglext.h b/include/EGL/eglext.h
index 1d68178..74040bc 100644
--- a/include/EGL/eglext.h
+++ b/include/EGL/eglext.h
@@ -283,6 +283,25 @@ typedef EGLImageKHR (EGLAPIENTRYP 
PFNEGLCREATEDRMIMAGEMESAPROC) (EGLDisplay dpy,
 typedef EGLBoolean (EGLAPIENTRYP PFNEGLEXPORTDRMIMAGEMESAPROC) (EGLDisplay 
dpy, EGLImageKHR image, EGLint *name, EGLint *handle, EGLint *stride);
 #endif
 
+#ifndef EGL_MESA_resource_sharing
+#define EGL_MESA_resource_sharing 1
+#define EGL_GL_TEXTURE_MESA 0x3300  /* eglAcuireResource target */
+#define EGL_GL_BUFFER_OBJECT_MESA   0x3301  /* eglAcuireResource target */
+#define EGL_GL_RENDER_BUFFER_MESA   0x3302  /* eglAcuireResource target */
+#define EGL_GL_TEXTURE_ID_MESA  0x3303  /* eglAcuireResource attribute 
*/
+#define EGL_GL_TEXTURE_LEVEL_MESA   0x3304  /* eglAcuireResource attribute 
*/
+#define EGL_GL_TEXTURE_TARGET_MESA  0x3305  /* eglAcuireResource attribute 
*/
+#define EGL_GL_BUFFER_OBJECT_ID_MESA0x3306  /* eglAcuireResource attribute 
*/
+#define EGL_GL_RENDER_BUFFER_ID_MESA0x3307  /* eglAcuireResource attribute 
*/
+
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglAcquireResourceMESA(EGLDisplay dpy, 
EGLContext ctx, EGLenum target, const EGLint *attrib_list, void * user_data);
+EGLAPI EGLBoolean EGLAPIENTRY eglReleaseResourceMESA(EGLDisplay dpy, 
EGLContext ctx, EGLenum target, const EGLint *attrib_list);
+#endif
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLACQUIRERESOURCEMESAPROC) (EGLDisplay 
dpy, EGLContext ctx, EGLenum target, const EGLint *attrib_list, void * 
user_data);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLRELEASERESOURCEMESAPROC) (EGLDisplay 
dpy, EGLContext ctx, EGLenum target, const EGLint *attrib_list);
+#endif
+
 #ifndef EGL_NV_post_sub_buffer
 #define EGL_NV_post_sub_buffer 1
 #define EGL_POST_SUB_BUFFER_SUPPORTED_NV   0x30BE
diff --git a/include/GL/internal/dri_interface.h 
b/include/GL/internal/dri_interface.h
index 30ce175..21ee61e 100644
--- a/include/GL/internal/dri_interface.h
+++ b/include/GL/internal/dri_interface.h
@@ -1169,6 +1169,25 @@ struct __DRI2configQueryExtensionRec {
 };
 
 /**
+ * This extension allows to share GL resources with OpenCL.
+ */
+#define __DRI_RESOURCE_SHARING "DRI_RESOURCE_SHARING"
+#define __DRI_RESOURCE_SHARING_VERSION 1
+typedef struct __DRIResourceShareExtensionRec __DRIResourceShareExtension;
+struct __DRIResourceShareExtensionRec {
+   __DRIextension base;
+
+   GLboolean (*acquireTexture)(__DRIcontext *context, GLenum target,
+  GLint level, GLuint texture, void 
*user_data);
+   GLboolean (*releaseTexture)(__DRIcontext *context, GLenum target,
+  GLint level, GLuint texture);
+   GLboolean (*acquireBufferObj)(__DRIcontext *context, GLuint bufobj, void 
*user_data);
+   GLboolean (*releaseBufferObj)(__DRIcontext *context, GLuint bufobj);
+   GLboolean (*acquireRenderBuffer)(__DRIcontext *context, GLuint rb, void 
*user_data);
+   GLboolean (*releaseRenderBuffer)(__DRIcontext *context, GLuint rb);
+};
+
+/**
  * Robust context driver extension.
  *
  * Existence of this extension means the driver can accept the
diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 1bce314..d8cccb4 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri

[Mesa-dev] [PATCH v2 3/4] DRI: implement helper functions for dri resource sharing extension.

2013-07-16 Thread Zhigang Gong
Signed-off-by: Zhigang Gong 
---
 src/mesa/drivers/dri/common/dri_util.c |   48 
 src/mesa/drivers/dri/common/dri_util.h |   10 +++
 2 files changed, 58 insertions(+)

diff --git a/src/mesa/drivers/dri/common/dri_util.c 
b/src/mesa/drivers/dri/common/dri_util.c
index 9ed9df4..b7b9ed9 100644
--- a/src/mesa/drivers/dri/common/dri_util.c
+++ b/src/mesa/drivers/dri/common/dri_util.c
@@ -520,6 +520,43 @@ dri2ReleaseBuffer(__DRIscreen *screen, __DRIbuffer *buffer)
 driDriverAPI.ReleaseBuffer(screen, buffer);
 }
 
+static GLboolean
+driAcquireTexture(__DRIcontext *context, GLenum target,
+  GLint level, GLuint texture, void *user_data)
+{
+return driDriverAPI.AcquireTexture(context, target, level, texture, 
user_data);
+}
+
+static GLboolean
+driReleaseTexture(__DRIcontext *context, GLenum target,
+  GLint level, GLuint texture)
+{
+return driDriverAPI.ReleaseTexture(context, target, level, texture);
+}
+
+static GLboolean
+driAcquireBufferObj(__DRIcontext *context, GLuint bufobj, void *user_data)
+{
+return driDriverAPI.AcquireBufferObj(context, bufobj, user_data);
+}
+
+static GLboolean
+driReleaseBufferObj(__DRIcontext *context, GLuint bufobj)
+{
+return driDriverAPI.ReleaseBufferObj(context, bufobj);
+}
+
+static GLboolean
+driAcquireRenderBuffer(__DRIcontext *context, GLuint rb, void *user_data)
+{
+return driDriverAPI.AcquireBufferObj(context, rb, user_data);
+}
+
+static GLboolean
+driReleaseRenderBuffer(__DRIcontext *context, GLuint rb)
+{
+return driDriverAPI.ReleaseBufferObj(context, rb);
+}
 
 static int
 dri2ConfigQueryb(__DRIscreen *screen, const char *var, GLboolean *val)
@@ -603,6 +640,17 @@ const __DRI2configQueryExtension dri2ConfigQueryExtension 
= {
.configQueryf= dri2ConfigQueryf,
 };
 
+const __DRIResourceShareExtension driResourceShareExtension = {
+   .base = { __DRI_RESOURCE_SHARING, __DRI_RESOURCE_SHARING_VERSION },
+
+   .acquireTexture= driAcquireTexture,
+   .releaseTexture= driReleaseTexture,
+   .acquireBufferObj  = driAcquireBufferObj,
+   .releaseBufferObj  = driReleaseBufferObj,
+   .acquireRenderBuffer   = driAcquireRenderBuffer,
+   .releaseRenderBuffer   = driReleaseRenderBuffer
+};
+
 void
 dri2InvalidateDrawable(__DRIdrawable *drawable)
 {
diff --git a/src/mesa/drivers/dri/common/dri_util.h 
b/src/mesa/drivers/dri/common/dri_util.h
index 900f048..393d00a 100644
--- a/src/mesa/drivers/dri/common/dri_util.h
+++ b/src/mesa/drivers/dri/common/dri_util.h
@@ -65,6 +65,7 @@ extern const __DRIcoreExtension driCoreExtension;
 extern const __DRIswrastExtension driSWRastExtension;
 extern const __DRIdri2Extension driDRI2Extension;
 extern const __DRI2configQueryExtension dri2ConfigQueryExtension;
+extern const __DRIResourceShareExtension driResourceShareExtension;
 
 /**
  * Driver callback functions.
@@ -113,6 +114,15 @@ struct __DriverAPIRec {
 int width, int height);
 
 void (*ReleaseBuffer) (__DRIscreen *screenPrivate, __DRIbuffer *buffer);
+
+GLboolean (*AcquireTexture) (__DRIcontext *driContextPriv, GLenum target, 
GLint level, GLuint tex, void *user_data);
+GLboolean (*ReleaseTexture) (__DRIcontext *driContextPriv, GLenum target, 
GLint level, GLuint tex);
+
+GLboolean (*AcquireBufferObj) (__DRIcontext *driContextPriv, GLuint 
bufobj, void *user_data);
+GLboolean (*ReleaseBufferObj) (__DRIcontext *driContextPriv, GLuint 
bufobj);
+
+GLboolean (*AcquireRenderBuffer) (__DRIcontext *driContextPriv, GLuint rb, 
void *user_data);
+GLboolean (*ReleaseRenderBuffer) (__DRIcontext *driContextPriv, GLuint rb);
 };
 
 extern const struct __DriverAPIRec driDriverAPI;
-- 
1.7.9.5

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v2 4/4] i965: implement driResourceSharing extension.

2013-07-16 Thread Zhigang Gong
This patch implements the texture sharing.

Signed-off-by: Zhigang Gong 
---
 src/mesa/drivers/dri/i965/Makefile.am  |2 +
 src/mesa/drivers/dri/i965/Makefile.sources |1 +
 .../drivers/dri/i965/intel_dri_resource_sharing.c  |  192 
 .../drivers/dri/i965/intel_dri_resource_sharing.h  |   36 
 src/mesa/drivers/dri/i965/intel_screen.c   |9 +-
 src/mesa/drivers/dri/i965/intel_screen.h   |   10 +
 6 files changed, 249 insertions(+), 1 deletion(-)
 create mode 100644 src/mesa/drivers/dri/i965/intel_dri_resource_sharing.c
 create mode 100644 src/mesa/drivers/dri/i965/intel_dri_resource_sharing.h

diff --git a/src/mesa/drivers/dri/i965/Makefile.am 
b/src/mesa/drivers/dri/i965/Makefile.am
index 27c67d1..381711c 100644
--- a/src/mesa/drivers/dri/i965/Makefile.am
+++ b/src/mesa/drivers/dri/i965/Makefile.am
@@ -48,6 +48,8 @@ AM_CFLAGS += \
-DFEATURE_ES2=1
 endif
 
+include_HEADERS = intel_dri_resource_sharing.h
+
 AM_CXXFLAGS = $(AM_CFLAGS)
 
 dridir = $(DRI_DRIVER_INSTALL_DIR)
diff --git a/src/mesa/drivers/dri/i965/Makefile.sources 
b/src/mesa/drivers/dri/i965/Makefile.sources
index 1f401fe..e6cbd90 100644
--- a/src/mesa/drivers/dri/i965/Makefile.sources
+++ b/src/mesa/drivers/dri/i965/Makefile.sources
@@ -14,6 +14,7 @@ i965_FILES = \
intel_regions.c \
intel_resolve_map.c \
intel_screen.c \
+intel_dri_resource_sharing.c \
intel_pixel.c \
intel_pixel_bitmap.c \
intel_pixel_copy.c \
diff --git a/src/mesa/drivers/dri/i965/intel_dri_resource_sharing.c 
b/src/mesa/drivers/dri/i965/intel_dri_resource_sharing.c
new file mode 100644
index 000..d16a7e4
--- /dev/null
+++ b/src/mesa/drivers/dri/i965/intel_dri_resource_sharing.c
@@ -0,0 +1,192 @@
+/**
+ *
+ * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **/
+
+#include 
+#include 
+#include "main/glheader.h"
+#include "main/context.h"
+#include "main/framebuffer.h"
+#include "main/renderbuffer.h"
+#include "main/texobj.h"
+#include "main/hash.h"
+#include "main/fbobject.h"
+#include "main/version.h"
+
+#include "utils.h"
+#include "xmlpool.h"
+
+#include "intel_batchbuffer.h"
+#include "intel_buffers.h"
+#include "intel_bufmgr.h"
+#include "intel_chipset.h"
+#include "intel_fbo.h"
+#include "intel_mipmap_tree.h"
+#include "intel_screen.h"
+#include "intel_tex.h"
+#include "intel_regions.h"
+#include "intel_context.h"
+
+#include "i915_drm.h"
+#include "intel_dri_resource_sharing.h"
+
+
+/**
+ * Sets up a DRIImage structure to point to our shared image in a region
+ */
+static GLboolean
+intel_setup_cl_region_from_mipmap_tree(struct intel_context *intel,
+   struct intel_mipmap_tree *mt,
+   GLuint level, GLuint zoffset,
+   struct _intel_dri_share_image_region 
*region)
+{
+   unsigned int draw_x, draw_y;
+   uint32_t mask_x, mask_y;
+   struct intel_region *null_region = (struct intel_region *)NULL;
+
+   intel_miptree_check_level_layer(mt, level, zoffset);
+
+   intel_region_get_tile_masks(mt->region, &mask_x, &mask_y, false);
+   intel_miptree_get_image_offset(mt, level, zoffset, &draw_x, &draw_y);
+
+   region->w = mt->level[level].width;
+   region->h = mt->level[level].height;
+   region->tile_x = draw_x & mask_x;
+   region->tile_y = draw_y &a

[Mesa-dev] Question about how to implement gl sharing extension in Open CL C with mesa

2013-07-07 Thread Zhigang Gong
Hi,

I'm developing gl sharing for Open Cl 1.1 implementation. My current solution 
is to
use the existing interface and extension to export a gl texture/buffer object 
to the
OpenCL domain, and create an cl memory object from the same buffer object(drm 
level).
But I met some gaps with current mesa implementation.

First, I want to talk about the gl 2d/3d texture sharing problem.
The basic idea is to use EGL_KHR_gl_texture_3D_image and 
EGL_KHR_gl_texture_2D_image
extension to create an EGL image from the 2d/3d textures, then use EGL API to 
get the
image's attribute and the image's bo's name. But I found there is no way to get 
the
image's detail attributes which are width/height/format/... . I also found that 
this
is as desgiend according KHR_image_base spec:

3.  Should attributes (width, height, format, etc.) for EGLImages
be queriable?

SUGGESTION:  No.  Given the wealth of attributes that we would
need to specify all possible EGLImages (and possible
memory layout optimizations performed by implementations), we
can dramatically simplify the API without loss of key
functionality by making EGLImages opaque and allowing
implementations to make the correct decisions internally.

But we do need to query these attributes when we want to create a CL memory 
object
from a gl texture/egl image. Another reason is that GLES doesn't provide APIs to
get a texture's width/height/internal format neighter.

I just wonder is there any possibility to provide such functions at the image 
extensions layer?
If no, then one alternative solution is to leverage gbm's capability. And we do 
need to
extent the GBM's interface to create a GBM device from a existing egl  dri2 
display. Then
we can use GBM's API to query those attributes. Current GBM only support to 
create a new
GBM device as a new dri loader. Thus it can't be used to access the images 
created from
the existing EGL context. Is it doable/acceptable to add a new way to create a 
GBM device
from an existing egl dri2 display?

Or is there any other way to achieve the same goal more gracefully?

Second, back to the gl buffer object sharing problem.
If either the above two issues get fixed(extent EGL image extension or extent 
gbm
library), we can achieve the goal to share a gl 2d/3d texutres with Open CL. But
we still can't achieve the same goal with buffer object. As there is no any 
extension to export
a buffer object. I don't have any good idea about this point. Is there any 
suggestion
for the buffer object sharing with OpenCL in mesa?

Looking forward to your valuable suggestion/feedback.

- Zhigang
Thanks.
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] Question about the texture's reference count processing in _mesa_update_texture

2011-11-22 Thread zhigang gong
Hi guys,

I have a question about the internal implementation of glDrawArrays or any
rendering functions.
In the code path, it calls to _mesa_update_texture(), and if there is
really a complete texture,
it will call _mesa_reference_texobj to set it to _Current, and increase the
texture object's reference
counter.

My question is when it will decrease the reference counter? This implicit
increasing seems
causes the reference counter unbalanced, and then will cause unexpected
behaviour. Here is an
example:

1   glGenTextures(1, &tex);
2   glActiveTexture(GL_TEXTURE0);
3   glBindTexture(GL_TEXTURE_2D, tex);
4   glTexImage2D(GL_TEXTURE_2D, 0, iformat,
   w, h, 0, format, type, bits);
5   glEnable(GL_TEXTURE_2D);
6   glUseProgram(shader_prog);
7... /*setup attribute array here.*/
8   glDrawArray(GL_TRIANGLE_FAN, 0, 4);
9   glUseProgram(0);
10 glDeleteTexture(1, &tex);

At Line 1, tex object is created with reference count initialized to 1.
At Line 3, tex object's reference count increased to 2.
At Line 8, it implicit increases tex object's reference count to 3.
At Line 10, it implict unbinds the tex object which decreases the count to
2.
 then it try to unreference the tex object which decreases
the count to1.

You can see that finally, the tex object's reference's count is 1 not zero
and thus it will not be freed. This is not what I expected.

Is there any mistakes in my use case? Or anyone can tell me how to
make sure the texture object get freed after the usage of it.

Thanks.
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] Question about the texture's reference count processing in _mesa_update_texture

2011-11-25 Thread zhigang gong
Sorry, forgot to copy to the mail list.

-- Forwarded message --
From: zhigang gong 
Date: Fri, Nov 25, 2011 at 5:18 PM
Subject: Re: [Mesa-dev] Question about the texture's reference count
processing in _mesa_update_texture
To: Brian Paul 


Hi Brian,

The test case is attached. It is based on the eglkms.c in mesa-demos package.
Here is a explaintation of the case:

1. use gbm to create two bos. one is shadow bo and the other is screen bo.
2. create a shadow image by using the shadow bo's handle.
   Then creat shadow texture from the shadow image.
3. create a screen image by using the screen bo directly.
   Then create screen texture from the screen image.
4. create two frame buffer objects, one is screen fbo and the other is
screen fbo.
5. bind shadow texture to shadow fbo, and bind screen texture to screen fbo.
6. choose shadow fbo as render target, and use shader to fill a rectangle in it.
7. choose screen fbo as render target, set the shadow texture as a
source texture.
  use shader to copy shadow texture to screen fbo.
8. Use KMS to show the screen fbo to the hardware frame buffer.
9. delete all fbos.
10. delete all textures.
11. destroy all images.
12. use the shadow bo's handle to create another shadow image.
13. destroy the shadow image.
14. destroy all gbm bos.
15. other cleanups.

Now the key step is in 7 and 12. By default, the function will fail at step 12.
It will fail to create another shadow image from the shadow bo's handle,
EGL will complain:
"Region for name 1 already exists but is not compatible "
But this confused me, as the previous shadow image is already destroied at
step 11. Why EGL can still find a image region with the same handle?

I traced into mesa and got some finding:

 glDrawArray will implicitly increase the shadow texture's reference count.
 And then latter when we delete the texture, the count will remain 1 rather
 then zero, and then it will not decrease the corresponding image region's
 reference counter and then when we destroy the shadow image,   the
 image's reference counter will also be 1 and can't be freed. Then next time
 we use the same handle to create a new image, it will find the previou zombie
image region and find they are not compatible.

Just simply comment out the glDrawArray in step 7 can avoid this case
to hit the problem, and it can create the second smaller image successfully.

Any hint here.

BTW, Sorry I can't make a simpler test case here, as it seems that
using the shadow
texture as a source texture is a must condition to hit this problem.

Any hint to fix this problem? Thanks.

On Wed, Nov 23, 2011 at 11:49 PM, Brian Paul  wrote:
>
> On 11/23/2011 12:28 AM, zhigang gong wrote:
>>
>> Hi guys,
>> I have a question about the internal implementation of glDrawArrays or
>> any rendering functions.
>> In the code path, it calls to _mesa_update_texture(), and if there is
>> really a complete texture,
>> it will call _mesa_reference_texobj to set it to _Current, and
>> increase the texture object's reference
>> counter.
>> My question is when it will decrease the reference counter? This
>> implicit increasing seems
>> causes the reference counter unbalanced, and then will cause
>> unexpected behaviour. Here is an
>> example:
>> 1       glGenTextures(1, &tex);
>> 2       glActiveTexture(GL_TEXTURE0);
>> 3       glBindTexture(GL_TEXTURE_2D, tex);
>> 4       glTexImage2D(GL_TEXTURE_2D, 0, iformat,
>>                                w, h, 0, format, type, bits);
>> 5       glEnable(GL_TEXTURE_2D);
>> 6       glUseProgram(shader_prog);
>> 7        ... /*setup attribute array here.*/
>> 8       glDrawArray(GL_TRIANGLE_FAN, 0, 4);
>> 9       glUseProgram(0);
>> 10     glDeleteTexture(1, &tex);
>> At Line 1, tex object is created with reference count initialized to 1.
>> At Line 3, tex object's reference count increased to 2.
>> At Line 8, it implicit increases tex object's reference count to 3.
>> At Line 10, it implict unbinds the tex object which decreases the
>> count to 2.
>>                  then it try to unreference the tex object which
>> decreases the count to1.
>> You can see that finally, the tex object's reference's count is 1 not
>> zero
>> and thus it will not be freed. This is not what I expected.
>> Is there any mistakes in my use case? Or anyone can tell me how to
>> make sure the texture object get freed after the usage of it.
>
> As long as the texture object is still bound to unit 0's GL_TEXTURE_2D, the 
> texture will not get deleted.
>
> When another texture gets bound to the binding point, the "deleted" texture's 
> ref count should go to zero and really be deleted.  For 

[Mesa-dev] About MESA drm image extension

2011-12-05 Thread zhigang gong
Hi Kristian,

I'm integrating glamor with intel's video driver now. The basic idea
is to allocate a BO
 by calling libdrm directly in intel uxa code path, then latter create
an EGL image from
that BO's handle. And then bind the image to a texture then glamor can
use it as usual.

Now the problem is that per the spec, EGL_MESA_drm_image extension only support
one format,   EGL_DRM_BUFFER_FORMAT_ARGB32_MESA which has a 32bit depth.

But a normal pixmap may has 8 or 16 bit depth color format, thus we can't get a
correct format image.

Would you like to extent the MESA drm image extension to support more formats?
If so, then I can contribute on that including implement it in mesa.
Or do you have any
suggestion for my issues. Thanks.
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] About MESA drm image extension

2011-12-06 Thread zhigang gong
2011/12/5 Kristian Høgsberg :
> 2011/12/5 zhigang gong :
>> Hi Kristian,
>>
>> I'm integrating glamor with intel's video driver now. The basic idea
>> is to allocate a BO
>>  by calling libdrm directly in intel uxa code path, then latter create
>> an EGL image from
>> that BO's handle. And then bind the image to a texture then glamor can
>> use it as usual.
>>
>> Now the problem is that per the spec, EGL_MESA_drm_image extension only 
>> support
>> one format,   EGL_DRM_BUFFER_FORMAT_ARGB32_MESA which has a 32bit depth.
>>
>> But a normal pixmap may has 8 or 16 bit depth color format, thus we can't 
>> get a
>> correct format image.
>>
>> Would you like to extent the MESA drm image extension to support more 
>> formats?
>> If so, then I can contribute on that including implement it in mesa.
>> Or do you have any
>> suggestion for my issues. Thanks.
>
> I think we should try to use libgbm instead of EGL_MESA_drm_image.  We
> can add more formats to gbm if that helps.
I know that libgbm should be the preferred method to allocate drm
buffers in MESA.
But this is a little special case. The buffer object is allocated in
intel video driver by
calling libdrm directly. And we need to create a KHR image from that
BO. Currently,
the only avialable method is to use eglCreateImageKHR with
EGL_DRM_BUFFER_MESA target. And thus I met the format limitation with that
target.

If libgbm can provide a new API as below:

gbm_bo_create_from_name(struct gbm_device *gbm, int name,
   int width, int height,
enum gbm_bo_format format,
   uint32_t usage)

The name is a BO's name which is allocated by libdrm.

And then extent gbm_bo_format to meet my requirement, then that will be perfect
for me.

copy to Benjamin, any comments?

Thanks.
-- Zhigang

>
> Kristian
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 1/2] gbm: Introduce a new API gbm_bo_create_from_name.

2011-12-15 Thread zhigang . gong
From: Zhigang Gong 

Glamor need a function to create a texture from a
BO allocated by using libdrm directly in DDX layer.
EGL image extension API eglCreateImageKHR does support
this function, but that extension only support one
colore format - ARGB32 which is not sufficent for
us. I discussed this in the mail list and KRH suggest
me to extent GBM to support more color formats should
be better. I took his advice and decide to use gbm
bo to create image. Now before extent the color formats,
I have to add a new API to the create a gbo from a
name. This commit is for that purpose.

Signed-off-by: Zhigang Gong 
---
 src/gbm/backends/dri/gbm_dri.c |   87 ++--
 src/gbm/main/gbm.c |   14 ++
 src/gbm/main/gbm.h |6 +++
 src/gbm/main/gbmint.h  |4 ++
 4 files changed, 98 insertions(+), 13 deletions(-)

diff --git a/src/gbm/backends/dri/gbm_dri.c b/src/gbm/backends/dri/gbm_dri.c
index 9de8cb6..d78cf5f 100644
--- a/src/gbm/backends/dri/gbm_dri.c
+++ b/src/gbm/backends/dri/gbm_dri.c
@@ -284,6 +284,22 @@ gbm_dri_bo_create_from_egl_image(struct gbm_device *gbm,
return &bo->base.base;
 }
 
+static int
+gbm_dri_match_format(enum gbm_bo_format format, int *dri_format)
+{
+   switch (format) {
+   case GBM_BO_FORMAT_XRGB:
+  *dri_format = __DRI_IMAGE_FORMAT_XRGB;
+  break;
+   case GBM_BO_FORMAT_ARGB:
+  *dri_format = __DRI_IMAGE_FORMAT_ARGB;
+  break;
+   default:
+  return -1;
+   }
+  return 0;
+}
+
 static struct gbm_bo *
 gbm_dri_bo_create(struct gbm_device *gbm,
   uint32_t width, uint32_t height,
@@ -296,23 +312,15 @@ gbm_dri_bo_create(struct gbm_device *gbm,
 
bo = calloc(1, sizeof *bo);
if (bo == NULL)
-  return NULL;
+  goto fail;
 
bo->base.base.gbm = gbm;
bo->base.base.width = width;
bo->base.base.height = height;
 
-   switch (format) {
-   case GBM_BO_FORMAT_XRGB:
-  dri_format = __DRI_IMAGE_FORMAT_XRGB;
-  break;
-   case GBM_BO_FORMAT_ARGB:
-  dri_format = __DRI_IMAGE_FORMAT_ARGB;
-  break;
-   default:
-  return NULL;
-   }
-
+   if (gbm_dri_match_format(format, &dri_format) != 0)
+  goto fail;
+
if (usage & GBM_BO_USE_SCANOUT)
   dri_use |= __DRI_IMAGE_USE_SCANOUT;
if (usage & GBM_BO_USE_CURSOR_64X64)
@@ -323,8 +331,9 @@ gbm_dri_bo_create(struct gbm_device *gbm,
   width, height,
   dri_format, dri_use,
   bo);
+
if (bo->image == NULL)
-  return NULL;
+  goto fail;
 
dri->image->queryImage(bo->image, __DRI_IMAGE_ATTRIB_HANDLE,
   &bo->base.base.handle.s32);
@@ -332,8 +341,59 @@ gbm_dri_bo_create(struct gbm_device *gbm,
   (int *) &bo->base.base.pitch);
 
return &bo->base.base;
+
+fail:
+
+   if (bo)
+  free(bo);
+   return NULL;
 }
 
+static struct gbm_bo *
+gbm_dri_bo_create_from_name(struct gbm_device *gbm,
+uint32_t width, uint32_t height,
+enum gbm_bo_format format, int name,
+int pitch)
+{
+   struct gbm_dri_device *dri = gbm_dri_device(gbm);
+   struct gbm_dri_bo *bo;
+   int dri_format;
+
+   bo = calloc(1, sizeof *bo);
+   if (bo == NULL)
+  goto fail;
+
+   bo->base.base.gbm = gbm;
+   bo->base.base.width = width;
+   bo->base.base.height = height;
+
+   if (gbm_dri_match_format(format, &dri_format) != 0)
+  goto fail;
+
+   bo->image =
+  dri->image->createImageFromName(dri->screen,
+  width, height,
+  dri_format, name, pitch,
+  bo);
+   if (bo->image == NULL)
+  goto fail;
+
+   dri->image->queryImage(bo->image, __DRI_IMAGE_ATTRIB_HANDLE,
+  &bo->base.base.handle.s32);
+   dri->image->queryImage(bo->image, __DRI_IMAGE_ATTRIB_STRIDE,
+  (int *) &bo->base.base.pitch);
+
+   return &bo->base.base;
+
+fail:
+
+   if (bo)
+  free(bo);
+   return NULL;
+
+}
+
+
 static void
 dri_destroy(struct gbm_device *gbm)
 {
@@ -358,6 +418,7 @@ dri_device_create(int fd)
dri->base.base.fd = fd;
dri->base.base.bo_create = gbm_dri_bo_create;
dri->base.base.bo_create_from_egl_image = gbm_dri_bo_create_from_egl_image;
+   dri->base.base.bo_create_from_name = gbm_dri_bo_create_from_name;
dri->base.base.is_format_supported = gbm_dri_is_format_supported;
dri->base.base.bo_destroy = gbm_dri_bo_destroy;
dri->base.base.destroy = dri_destroy;
diff --git a/src/gbm/main/gbm.c b/src/gbm/main/gbm.c
index 8440b2c..93e06f3 100644
--- a/src/gbm/main/gbm.c
+++ b/src/gbm/main/gbm.c
@@ -177,6 +177,20 @@ gbm_bo_create(struct gbm_de

[Mesa-dev] [PATCH 2/2] gbm/dri: Added more color formats.

2011-12-15 Thread zhigang . gong
From: Zhigang Gong 

Added two color formats RGB565 and A8 to gbm layer.
Add A8 to dri layer.

Signed-off-by: Zhigang Gong 
---
 include/GL/internal/dri_interface.h   |1 +
 src/gbm/backends/dri/gbm_dri.c|6 ++
 src/gbm/main/gbm.h|2 ++
 src/mesa/drivers/dri/intel/intel_screen.c |5 +
 4 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/include/GL/internal/dri_interface.h 
b/include/GL/internal/dri_interface.h
index 4f768f0..40034e2 100644
--- a/include/GL/internal/dri_interface.h
+++ b/include/GL/internal/dri_interface.h
@@ -840,6 +840,7 @@ struct __DRIdri2ExtensionRec {
 #define __DRI_IMAGE_FORMAT_XRGB 0x1002
 #define __DRI_IMAGE_FORMAT_ARGB 0x1003
 #define __DRI_IMAGE_FORMAT_ABGR 0x1004
+#define __DRI_IMAGE_FORMAT_A8   0x1005
 
 #define __DRI_IMAGE_USE_SHARE  0x0001
 #define __DRI_IMAGE_USE_SCANOUT0x0002
diff --git a/src/gbm/backends/dri/gbm_dri.c b/src/gbm/backends/dri/gbm_dri.c
index d78cf5f..206ddb4 100644
--- a/src/gbm/backends/dri/gbm_dri.c
+++ b/src/gbm/backends/dri/gbm_dri.c
@@ -294,6 +294,12 @@ gbm_dri_match_format(enum gbm_bo_format format, int 
*dri_format)
case GBM_BO_FORMAT_ARGB:
   *dri_format = __DRI_IMAGE_FORMAT_ARGB;
   break;
+   case GBM_BO_FORMAT_RGB565:
+  *dri_format = __DRI_IMAGE_FORMAT_RGB565;
+  break;
+   case GBM_BO_FORMAT_A8:
+  *dri_format = __DRI_IMAGE_FORMAT_A8;
+  break;
default:
   return -1;
}
diff --git a/src/gbm/main/gbm.h b/src/gbm/main/gbm.h
index aeed0df..889efa2 100644
--- a/src/gbm/main/gbm.h
+++ b/src/gbm/main/gbm.h
@@ -51,6 +51,8 @@ union gbm_bo_handle {
 enum gbm_bo_format {
GBM_BO_FORMAT_XRGB,
GBM_BO_FORMAT_ARGB,
+   GBM_BO_FORMAT_RGB565,
+   GBM_BO_FORMAT_A8
 };
 
 enum gbm_bo_flags {
diff --git a/src/mesa/drivers/dri/intel/intel_screen.c 
b/src/mesa/drivers/dri/intel/intel_screen.c
index e4cc5b0..6284071 100644
--- a/src/mesa/drivers/dri/intel/intel_screen.c
+++ b/src/mesa/drivers/dri/intel/intel_screen.c
@@ -143,6 +143,11 @@ intel_create_image_from_name(__DRIscreen *screen,
return NULL;
 
 switch (format) {
+case __DRI_IMAGE_FORMAT_A8:
+   image->format = MESA_FORMAT_A8;
+   image->internal_format = GL_ALPHA;
+   image->data_type = GL_UNSIGNED_BYTE;
+   break;
 case __DRI_IMAGE_FORMAT_RGB565:
image->format = MESA_FORMAT_RGB565;
image->internal_format = GL_RGB;
-- 
1.7.4.4

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 1/2] gbm: Introduce a new API gbm_bo_create_from_name.

2011-12-15 Thread zhigang gong
On Thu, Dec 15, 2011 at 11:57 PM, Eric Anholt  wrote:
> On Thu, 15 Dec 2011 17:58:45 +0800, zhigang.g...@linux.intel.com wrote:
>> From: Zhigang Gong 
>>
>> Glamor need a function to create a texture from a
>> BO allocated by using libdrm directly in DDX layer.
>> EGL image extension API eglCreateImageKHR does support
>> this function, but that extension only support one
>> colore format - ARGB32 which is not sufficent for
>> us. I discussed this in the mail list and KRH suggest
>> me to extent GBM to support more color formats should
>> be better. I took his advice and decide to use gbm
>> bo to create image. Now before extent the color formats,
>> I have to add a new API to the create a gbo from a
>> name. This commit is for that purpose.
>
> If the DDX is going to be doing the memory management, then the DRI
> driver needs to be using the same bufmgr struct and DRI fd as the DDX so
> you can share the handle (and thus the mapping and userland caching)
> instead of the name.
Looks better than just create an image from the name as the DDX and DRI
are really running in the same process in this case. But I don't know how to
share the DDX's bufmgr with DRI driver, and how to make a texture from
a handle directly by using the EGL/GBM interfaces. Can you give me more hints
about how to achieve that?  Thanks.

>
> ___
> mesa-dev mailing list
> mesa-dev@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev
>
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 0/3] gbm extension patch set - v2

2011-12-17 Thread Zhigang Gong
According to Ian's comments, split the original patchset
to three. The last one is to add new API to create a gbm
bo from external name. Now I'm convinced that in one process
, it's better to use one bufmgr. Just for API completeness,
I still submit it here.

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 1/3] gbm: Added new funtions to match dri format and usage.

2011-12-17 Thread Zhigang Gong
To map GBM format and usage to corresponding dri format
and usage are common functions. For the convinent of
future extension, pull out the code and create two
separated functions. Slightly change the sequence of
the gbm_bo creation, before allocate a buffer, we check
whether the input parameters are valid and if not, we
return NULL directly. And if we fail to create image,
we need to free the allocated buffer.

Signed-off-by: Zhigang Gong 
---
 src/gbm/backends/dri/gbm_dri.c |   64 +---
 src/gbm/main/gbm.h |4 ++
 2 files changed, 44 insertions(+), 24 deletions(-)

diff --git a/src/gbm/backends/dri/gbm_dri.c b/src/gbm/backends/dri/gbm_dri.c
index 9de8cb6..e44e5c6 100644
--- a/src/gbm/backends/dri/gbm_dri.c
+++ b/src/gbm/backends/dri/gbm_dri.c
@@ -215,20 +215,44 @@ free_screen:
 }
 
 static int
-gbm_dri_is_format_supported(struct gbm_device *gbm,
-enum gbm_bo_format format,
-uint32_t usage)
+gbm_dri_match_format(enum gbm_bo_format format, int *dri_format)
 {
switch (format) {
case GBM_BO_FORMAT_XRGB:
+  *dri_format = __DRI_IMAGE_FORMAT_XRGB;
   break;
case GBM_BO_FORMAT_ARGB:
-  if (usage & GBM_BO_USE_SCANOUT)
- return 0;
+  *dri_format = __DRI_IMAGE_FORMAT_ARGB;
   break;
default:
-  return 0;
+  return -1;
}
+  return 0;
+}
+
+static void
+gbm_dri_match_usage(enum  gbm_bo_flags usage, unsigned int *dri_use)
+{
+   if (usage & GBM_BO_USE_SCANOUT)
+  *dri_use |= __DRI_IMAGE_USE_SCANOUT;
+   if (usage & GBM_BO_USE_CURSOR_64X64)
+  *dri_use |= __DRI_IMAGE_USE_CURSOR;
+}
+
+static int
+gbm_dri_is_format_supported(struct gbm_device *gbm,
+enum gbm_bo_format format,
+uint32_t usage)
+{
+   int dri_format = 0;
+
+   if (gbm_dri_match_format(format, &dri_format)
+   || (usage & ~GBM_BO_USE_VALID_FLAGS)
+   || ((usage & GBM_BO_USE_SCANOUT)
+&& (format == GBM_BO_FORMAT_ARGB))
+   || ((usage & GBM_BO_USE_CURSOR_64X64)
+&& (usage & GBM_BO_USE_RENDERING)))
+  return 0;
 
if (usage & GBM_BO_USE_CURSOR_64X64 &&
usage & GBM_BO_USE_RENDERING)
@@ -292,7 +316,12 @@ gbm_dri_bo_create(struct gbm_device *gbm,
struct gbm_dri_device *dri = gbm_dri_device(gbm);
struct gbm_dri_bo *bo;
int dri_format;
-   unsigned dri_use = 0;
+   unsigned int dri_use = 0;
+
+   if (gbm_dri_match_format(format, &dri_format) != 0)
+  return NULL;
+   if (usage & ~GBM_BO_USE_VALID_FLAGS)
+  return NULL;
 
bo = calloc(1, sizeof *bo);
if (bo == NULL)
@@ -302,29 +331,16 @@ gbm_dri_bo_create(struct gbm_device *gbm,
bo->base.base.width = width;
bo->base.base.height = height;
 
-   switch (format) {
-   case GBM_BO_FORMAT_XRGB:
-  dri_format = __DRI_IMAGE_FORMAT_XRGB;
-  break;
-   case GBM_BO_FORMAT_ARGB:
-  dri_format = __DRI_IMAGE_FORMAT_ARGB;
-  break;
-   default:
-  return NULL;
-   }
-
-   if (usage & GBM_BO_USE_SCANOUT)
-  dri_use |= __DRI_IMAGE_USE_SCANOUT;
-   if (usage & GBM_BO_USE_CURSOR_64X64)
-  dri_use |= __DRI_IMAGE_USE_CURSOR;
-
+   gbm_dri_match_usage(usage, &dri_use);
bo->image =
   dri->image->createImage(dri->screen,
   width, height,
   dri_format, dri_use,
   bo);
-   if (bo->image == NULL)
+   if (bo->image == NULL) {
+  free(bo);
   return NULL;
+   }
 
dri->image->queryImage(bo->image, __DRI_IMAGE_ATTRIB_HANDLE,
   &bo->base.base.handle.s32);
diff --git a/src/gbm/main/gbm.h b/src/gbm/main/gbm.h
index 05d2292..a994451 100644
--- a/src/gbm/main/gbm.h
+++ b/src/gbm/main/gbm.h
@@ -59,6 +59,10 @@ enum gbm_bo_flags {
GBM_BO_USE_RENDERING= (1 << 2),
 };
 
+#define GBM_BO_USE_VALID_FLAGS (GBM_BO_USE_SCANOUT\
+| GBM_BO_USE_CURSOR_64X64 \
+| GBM_BO_USE_RENDERING)
+
 int
 gbm_device_get_fd(struct gbm_device *gbm);
 
-- 
1.7.3.1

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 2/3] gbm/dri: Add more color formats support.

2011-12-17 Thread Zhigang Gong
Added two color formats RGB565 and A8 to gbm layer.
Add A8 to dri layer.

Signed-off-by: Zhigang Gong 
---
 include/GL/internal/dri_interface.h   |1 +
 src/gbm/backends/dri/gbm_dri.c|6 ++
 src/gbm/main/gbm.h|2 ++
 src/mesa/drivers/dri/intel/intel_screen.c |5 +
 4 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/include/GL/internal/dri_interface.h 
b/include/GL/internal/dri_interface.h
index 4f768f0..da3f11e 100644
--- a/include/GL/internal/dri_interface.h
+++ b/include/GL/internal/dri_interface.h
@@ -840,6 +840,7 @@ struct __DRIdri2ExtensionRec {
 #define __DRI_IMAGE_FORMAT_XRGB 0x1002
 #define __DRI_IMAGE_FORMAT_ARGB 0x1003
 #define __DRI_IMAGE_FORMAT_ABGR 0x1004
+#define __DRI_IMAGE_FORMAT_A8   0x1005
 
 #define __DRI_IMAGE_USE_SHARE  0x0001
 #define __DRI_IMAGE_USE_SCANOUT0x0002
diff --git a/src/gbm/backends/dri/gbm_dri.c b/src/gbm/backends/dri/gbm_dri.c
index e44e5c6..7673953 100644
--- a/src/gbm/backends/dri/gbm_dri.c
+++ b/src/gbm/backends/dri/gbm_dri.c
@@ -224,6 +224,12 @@ gbm_dri_match_format(enum gbm_bo_format format, int 
*dri_format)
case GBM_BO_FORMAT_ARGB:
   *dri_format = __DRI_IMAGE_FORMAT_ARGB;
   break;
+   case GBM_BO_FORMAT_RGB565:
+  *dri_format = __DRI_IMAGE_FORMAT_RGB565;
+  break;
+   case GBM_BO_FORMAT_A8:
+  *dri_format = __DRI_IMAGE_FORMAT_A8;
+  break;
default:
   return -1;
}
diff --git a/src/gbm/main/gbm.h b/src/gbm/main/gbm.h
index a994451..e3cecb4 100644
--- a/src/gbm/main/gbm.h
+++ b/src/gbm/main/gbm.h
@@ -51,6 +51,8 @@ union gbm_bo_handle {
 enum gbm_bo_format {
GBM_BO_FORMAT_XRGB,
GBM_BO_FORMAT_ARGB,
+   GBM_BO_FORMAT_RGB565,
+   GBM_BO_FORMAT_A8
 };
 
 enum gbm_bo_flags {
diff --git a/src/mesa/drivers/dri/intel/intel_screen.c 
b/src/mesa/drivers/dri/intel/intel_screen.c
index e4cc5b0..6284071 100644
--- a/src/mesa/drivers/dri/intel/intel_screen.c
+++ b/src/mesa/drivers/dri/intel/intel_screen.c
@@ -143,6 +143,11 @@ intel_create_image_from_name(__DRIscreen *screen,
return NULL;
 
 switch (format) {
+case __DRI_IMAGE_FORMAT_A8:
+   image->format = MESA_FORMAT_A8;
+   image->internal_format = GL_ALPHA;
+   image->data_type = GL_UNSIGNED_BYTE;
+   break;
 case __DRI_IMAGE_FORMAT_RGB565:
image->format = MESA_FORMAT_RGB565;
image->internal_format = GL_RGB;
-- 
1.7.3.1

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 3/3] gbm: Add interface to create bo from name.

2011-12-17 Thread Zhigang Gong
Added a new interface to create a gbm_bo from external name.

Signed-off-by: Zhigang Gong 
---
 src/gbm/backends/dri/gbm_dri.c |   40 
 src/gbm/main/gbm.c |   12 
 src/gbm/main/gbm.h |6 ++
 src/gbm/main/gbmint.h  |4 
 4 files changed, 62 insertions(+), 0 deletions(-)

diff --git a/src/gbm/backends/dri/gbm_dri.c b/src/gbm/backends/dri/gbm_dri.c
index 7673953..c8f6196 100644
--- a/src/gbm/backends/dri/gbm_dri.c
+++ b/src/gbm/backends/dri/gbm_dri.c
@@ -356,6 +356,45 @@ gbm_dri_bo_create(struct gbm_device *gbm,
return &bo->base.base;
 }
 
+static struct gbm_bo *
+gbm_dri_bo_create_from_name(struct gbm_device *gbm,
+uint32_t width, uint32_t height,
+enum gbm_bo_format format, int name,
+int pitch)
+{
+   struct gbm_dri_device *dri = gbm_dri_device(gbm);
+   struct gbm_dri_bo *bo;
+   int dri_format;
+
+   if (gbm_dri_match_format(format, &dri_format) != 0)
+  return NULL;
+
+   bo = calloc(1, sizeof *bo);
+   if (bo == NULL)
+  return NULL;
+
+   bo->base.base.gbm = gbm;
+   bo->base.base.width = width;
+   bo->base.base.height = height;
+
+   bo->image =
+  dri->image->createImageFromName(dri->screen,
+  width, height,
+  dri_format, name, pitch,
+  bo);
+   if (bo->image == NULL) {
+  free(bo);
+  return NULL;
+   }
+
+   dri->image->queryImage(bo->image, __DRI_IMAGE_ATTRIB_HANDLE,
+  &bo->base.base.handle.s32);
+   dri->image->queryImage(bo->image, __DRI_IMAGE_ATTRIB_STRIDE,
+  (int *) &bo->base.base.pitch);
+
+   return &bo->base.base;
+}
+
 static void
 dri_destroy(struct gbm_device *gbm)
 {
@@ -380,6 +419,7 @@ dri_device_create(int fd)
dri->base.base.fd = fd;
dri->base.base.bo_create = gbm_dri_bo_create;
dri->base.base.bo_create_from_egl_image = gbm_dri_bo_create_from_egl_image;
+   dri->base.base.bo_create_from_name = gbm_dri_bo_create_from_name;
dri->base.base.is_format_supported = gbm_dri_is_format_supported;
dri->base.base.bo_destroy = gbm_dri_bo_destroy;
dri->base.base.destroy = dri_destroy;
diff --git a/src/gbm/main/gbm.c b/src/gbm/main/gbm.c
index 8440b2c..71c02a2 100644
--- a/src/gbm/main/gbm.c
+++ b/src/gbm/main/gbm.c
@@ -177,6 +177,18 @@ gbm_bo_create(struct gbm_device *gbm,
 }
 
 GBM_EXPORT struct gbm_bo *
+gbm_bo_create_from_name(struct gbm_device *gbm,
+uint32_t width, uint32_t height,
+enum gbm_bo_format format, int name,
+int pitch)
+{
+   if (width == 0 || height == 0)
+  return NULL;
+
+   return gbm->bo_create_from_name(gbm, width, height, format, name, pitch);
+}
+
+GBM_EXPORT struct gbm_bo *
 gbm_bo_create_from_egl_image(struct gbm_device *gbm,
  void *egl_dpy, void *egl_image,
  uint32_t width, uint32_t height,
diff --git a/src/gbm/main/gbm.h b/src/gbm/main/gbm.h
index e3cecb4..49ff2a8 100644
--- a/src/gbm/main/gbm.h
+++ b/src/gbm/main/gbm.h
@@ -88,6 +88,12 @@ gbm_bo_create(struct gbm_device *gbm,
   enum gbm_bo_format format, uint32_t flags);
 
 struct gbm_bo *
+gbm_bo_create_from_name(struct gbm_device *gbm,
+uint32_t width, uint32_t height,
+enum gbm_bo_format format, int name,
+int pitch);
+
+struct gbm_bo *
 gbm_bo_create_from_egl_image(struct gbm_device *gbm,
  void *egl_dpy, void *egl_img,
  uint32_t width, uint32_t height,
diff --git a/src/gbm/main/gbmint.h b/src/gbm/main/gbmint.h
index fb8db80..1aab789 100644
--- a/src/gbm/main/gbmint.h
+++ b/src/gbm/main/gbmint.h
@@ -60,6 +60,10 @@ struct gbm_device {
   void *egl_dpy, void *egl_img,
   uint32_t width, uint32_t height,
   uint32_t usage);
+   struct gbm_bo *(*bo_create_from_name)(struct gbm_device *gbm,
+ uint32_t width, uint32_t height,
+ enum gbm_bo_format format, int name,
+ int pitch);
void (*bo_destroy)(struct gbm_bo *bo);
 };
 
-- 
1.7.3.1

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH] configure.ac: Enable GLX_USE_TLS if possible.

2012-02-08 Thread zhigang . gong
From: Zhigang Gong 

If the system support tls, we prefer to enable it by default
just as xserver does. Actually, the checking code is copied
from xserver/configure.ac.

Signed-off-by: Zhigang Gong 
---
 configure.ac |   10 --
 1 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/configure.ac b/configure.ac
index b2b1ab8..7c2756b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1103,8 +1103,14 @@ dnl
 AC_ARG_ENABLE([glx-tls],
 [AS_HELP_STRING([--enable-glx-tls],
 [enable TLS support in GLX @<:@default=disabled@:>@])],
-[GLX_USE_TLS="$enableval"],
-[GLX_USE_TLS=no])
+[GLX_USE_TLS=$enableval
+ if test "x$GLX_USE_TLS" = "xyes" && test "${ac_cv_tls}" = "none" ; then
+AC_MSG_ERROR([GLX with TLS support requested, but the compiler does 
not support it.])
+ fi],
+[GLX_USE_TLS=no
+ if test "${ac_cv_tls}" != "none" ; then
+GLX_USE_TLS=yes
+ fi])
 AC_SUBST(GLX_TLS, ${GLX_USE_TLS})
 
 AS_IF([test "x$GLX_USE_TLS" = xyes],
-- 
1.7.4.4

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH] EGL: Add hardware cursor image format for EGL image extension.

2011-05-10 Thread zhigang gong
 Current EGL only support one drm buffer format which is
 EGL_DRM_BUFFER_FORMAT_ARGB32_MESA. This
 format works fine with normal image, but if we want to
 create a drm buffer which will be used for a hardware cursor,
 then it has problem. The default behaviou for this format is to
 enable tiling for i915 driver. Thus it will choose 512 as the buffer's
 stride. But the hardware cursor can only support 256 as the
 row stride. To solve this problem, I create a new drm buffer
 format named EGL_DRM_BUFFER_FORMAT_HWCURSOR_ARGB32_MESA
 for hardware cursor usage. It will disable the tiling by default
 for i915 driver and then choose 256 as its pitch value. I tested it on a
 Sandy bridge platform, it works fine.
---
 include/EGL/eglext.h  |1 +
 include/GL/internal/dri_interface.h   |1 +
 src/egl/drivers/dri2/egl_dri2.c   |3 +++
 src/mesa/drivers/dri/intel/intel_screen.c |7 +--
 4 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/include/EGL/eglext.h b/include/EGL/eglext.h
index 9fd3eb8..d0153d3 100644
--- a/include/EGL/eglext.h
+++ b/include/EGL/eglext.h
@@ -127,6 +127,7 @@ typedef EGLBoolean (EGLAPIENTRYP
PFNEGLDESTROYIMAGEKHRPROC) (EGLDisplay dpy, EGL

 /* EGL_DRM_BUFFER_FORMAT_MESA tokens */
 #define EGL_DRM_BUFFER_FORMAT_ARGB32_MESA  0x31D2
+#define EGL_DRM_BUFFER_FORMAT_HWCURSOR_ARGB32_MESA 0x31D3

 /* EGL_DRM_BUFFER_USE_MESA bits */
 #define EGL_DRM_BUFFER_USE_SCANOUT_MESA0x0001
diff --git a/include/GL/internal/dri_interface.h
b/include/GL/internal/dri_interface.h
index 2fb729a..fa2341b 100644
--- a/include/GL/internal/dri_interface.h
+++ b/include/GL/interna
@@ -127,6 +127,7 @@ typedef EGLBoolean (EGLAPIENTRYP
PFNEGLDESTROYIMAGEKHRPROC) (EGLDisplay dpy, EGL

 /* EGL_DRM_BUFFER_FORMAT_MESA tokens */
 #define EGL_DRM_BUFFER_FORMAT_ARGB32_MESA  0x31D2
+#define EGL_DRM_BUFFER_FORMAT_HWCURSOR_ARGB32_MESA 0x31D3

 /* EGL_DRM_BUFFER_USE_MESA bits */
 #define EGL_DRM_BUFFER_USE_SCANOUT_MESA0x0001
diff --git a/include/GL/internal/dri_interface.h
b/include/GL/internal/dri_interface.h
index 2fb729a..fa2341b 100644
--- a/include/GL/internal/dri_interface.h
+++ b/include/GL/internal/dri_interface.h
@@ -813,6 +813,7 @@ struct __DRIdri2ExtensionRec {
 #define __DRI_IMAGE_FORMAT_RGB565   0x1001
 #define __DRI_IMAGE_FORMAT_XRGB 0x1002
 #define __DRI_IMAGE_FORMAT_ARGB 0x1003
+#define __DRI_IMAGE_FORMAT_HWCURSOR_ARGB 0x1004

 #define __DRI_IMAGE_USE_SHARE  0x0001
 #define __DRI_IMAGE_USE_SCANOUT0x0002
diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 5e47fbe..23ab0ed 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1043,6 +1043,9 @@ dri2_create_drm_image_mesa(_EGLDriver *drv,
_EGLDisplay *disp,
}

switch (attrs.DRMBufferFormatMESA) {
+   case EGL_DRM_BUFFER_FORMAT_HWCURSOR_ARGB32_MESA:
+  format = __DRI_IMAGE_FORMAT_HWCURSOR_ARGB;
+  break;
case EGL_DRM_BUFFER_FORMAT_ARGB32_MESA:
   format = __DRI_IMAGE_FORMAT_ARGB;
   break;
diff --git a/src/mesa/drivers/dri/intel/intel_screen.c
b/src/mesa/drivers/dri/intel/intel_screen.c
index 7de0d12..475c142 100644
--- a/src/mesa/drivers/dri/intel/intel_screen.c
+++ b/src/mesa/drivers/dri/intel/intel_screen.c
@@ -217,11 +217,12 @@ intel_create_image(__DRIscreen *screen,
__DRIimage *image;
struct intel_screen *intelScreen = screen->private;
int cpp;
+   int tiling;

image = CALLOC(sizeof *image);
if (image == NULL)
   return NULL;
-
+   tiling = I915_TILING_X;
switch (format) {
case __DRI_IMAGE_FORMAT_RGB565:
   image->format = MESA_FORMAT_RGB565;
@@ -233,6 +234,8 @@ intel_create_image(__DRIscreen *screen,
   image->internal_format = GL_RGB;
   image->data_type = GL_UNSIGNED_BYTE;
   break;
+   case __DRI_IMAGE_FORMAT_HWCURSOR_ARGB:
+  tiling = I915_TILING_NONE;
case __DRI_IMAGE_FORMAT_ARGB:
   image->format = MESA_FORMAT_ARGB;
   image->internal_format = GL_RGBA;
@@ -247,7 +250,7 @@ intel_create_image(__DRIscreen *screen,
cpp = _mesa_get_format_bytes(image->format);

image->region =
-  intel_region_alloc(intelScreen, I915_TILING_X,
+  intel_region_alloc(intelScreen, tiling,
 cpp, width, height, GL_TRUE);
if (image->region == NULL) {
   FREE(image);
--
1.7.3.1
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH] mesa: silence some compilation warnings.

2011-05-12 Thread zhigang gong
glu.h: typedef void (GLAPIENTRYP _GLUfuncptr)(); causes the following
   warning: function declaration isn't a prototype.
egl:   When convert a (void *) to a int type, it's better to
   convert to long firstly, otherwise in 64 bit envirnonment, it
   causes compilation warning.
---
 include/GL/glu.h|2 +-
 src/egl/drivers/dri2/egl_dri2.c |4 ++--
 src/egl/drivers/dri2/platform_drm.c |4 ++--
 src/egl/drivers/dri2/platform_x11.c |2 +-
 src/egl/main/eglapi.c   |2 +-
 5 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/include/GL/glu.h b/include/GL/glu.h
index cd967ac..ba2228d 100644
--- a/include/GL/glu.h
+++ b/include/GL/glu.h
@@ -284,7 +284,7 @@ typedef GLUtesselator GLUtriangulatorObj;
 #define GLU_TESS_MAX_COORD 1.0e150

 /* Internal convenience typedefs */
-typedef void (GLAPIENTRYP _GLUfuncptr)();
+typedef void (GLAPIENTRYP _GLUfuncptr)(void);

 GLAPI void GLAPIENTRY gluBeginCurve (GLUnurbs* nurb);
 GLAPI void GLAPIENTRY gluBeginPolygon (GLUtesselator* tess);
diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index afab679..f5f5ac3 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -835,7 +835,7 @@ dri2_create_image_khr_renderbuffer(_EGLDisplay
*disp, _EGLContext *ctx,
struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx);
struct dri2_egl_image *dri2_img;
-   GLuint renderbuffer = (GLuint) buffer;
+   GLuint renderbuffer =  (unsigned long) buffer;

if (renderbuffer == 0) {
   _eglError(EGL_BAD_PARAMETER, "dri2_create_image_khr");
@@ -870,7 +870,7 @@ dri2_create_image_mesa_drm_buffer(_EGLDisplay
*disp, _EGLContext *ctx,

(void) ctx;

-   name = (EGLint) buffer;
+   name = (unsigned long) buffer;

err = _eglParseImageAttribList(&attrs, disp, attr_list);
if (err != EGL_SUCCESS)
diff --git a/src/egl/drivers/dri2/platform_drm.c
b/src/egl/drivers/dri2/platform_drm.c
index 68912e3..cea8418 100644
--- a/src/egl/drivers/dri2/platform_drm.c
+++ b/src/egl/drivers/dri2/platform_drm.c
@@ -596,7 +596,7 @@ dri2_get_device_name(int fd)
   goto out;
}

-   device_name = udev_device_get_devnode(device);
+   device_name = (char*)udev_device_get_devnode(device);
if (!device_name)
   goto out;
device_name = strdup(device_name);
@@ -690,7 +690,7 @@ dri2_initialize_drm(_EGLDriver *drv, _EGLDisplay *disp)
memset(dri2_dpy, 0, sizeof *dri2_dpy);

disp->DriverData = (void *) dri2_dpy;
-   dri2_dpy->fd = (int) disp->PlatformDisplay;
+   dri2_dpy->fd = (long) disp->PlatformDisplay;

dri2_dpy->driver_name = dri2_get_driver_for_fd(dri2_dpy->fd);
if (dri2_dpy->driver_name == NULL)
diff --git a/src/egl/drivers/dri2/platform_x11.c
b/src/egl/drivers/dri2/platform_x11.c
index 5d4ac6a..90136f4 100644
--- a/src/egl/drivers/dri2/platform_x11.c
+++ b/src/egl/drivers/dri2/platform_x11.c
@@ -784,7 +784,7 @@ dri2_create_image_khr_pixmap(_EGLDisplay *disp,
_EGLContext *ctx,

(void) ctx;

-   drawable = (xcb_drawable_t) buffer;
+   drawable = (xcb_drawable_t) (long)buffer;
xcb_dri2_create_drawable (dri2_dpy->conn, drawable);
attachments[0] = XCB_DRI2_ATTACHMENT_BUFFER_FRONT_LEFT;
buffers_cookie =
diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c
index 336ec23..9063752 100644
--- a/src/egl/main/eglapi.c
+++ b/src/egl/main/eglapi.c
@@ -1168,7 +1168,7 @@ eglQueryModeStringMESA(EGLDisplay dpy, EGLModeMESA mode)
 EGLDisplay EGLAPIENTRY
 eglGetDRMDisplayMESA(int fd)
 {
-   _EGLDisplay *dpy = _eglFindDisplay(_EGL_PLATFORM_DRM, (void *) fd);
+   _EGLDisplay *dpy = _eglFindDisplay(_EGL_PLATFORM_DRM, (void *) (long)fd);
return _eglGetDisplayHandle(dpy);
 }

--
1.7.3.1
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH] mesa: silence some compilation warnings.

2011-05-12 Thread zhigang gong
Thanks for your suggestion. Jose already revised my patch to use
uintptr_t instead of long.

On Fri, May 13, 2011 at 1:48 AM, Ian Romanick  wrote:
> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
>
> On 05/12/2011 01:49 AM, zhigang gong wrote:
>> glu.h: typedef void (GLAPIENTRYP _GLUfuncptr)(); causes the following
>>        warning: function declaration isn't a prototype.
>> egl:   When convert a (void *) to a int type, it's better to
>>        convert to long firstly, otherwise in 64 bit envirnonment, it
>>        causes compilation warning.
>
> I would suggest using either uintptr_t / intptr_t (preferable) or
> ptrdiff_t for this purpose.
>
>> ---
>>  include/GL/glu.h                    |    2 +-
>>  src/egl/drivers/dri2/egl_dri2.c     |    4 ++--
>>  src/egl/drivers/dri2/platform_drm.c |    4 ++--
>>  src/egl/drivers/dri2/platform_x11.c |    2 +-
>>  src/egl/main/eglapi.c               |    2 +-
>>  5 files changed, 7 insertions(+), 7 deletions(-)
>>
>> diff --git a/include/GL/glu.h b/include/GL/glu.h
>> index cd967ac..ba2228d 100644
>> --- a/include/GL/glu.h
>> +++ b/include/GL/glu.h
>> @@ -284,7 +284,7 @@ typedef GLUtesselator GLUtriangulatorObj;
>>  #define GLU_TESS_MAX_COORD 1.0e150
>>
>>  /* Internal convenience typedefs */
>> -typedef void (GLAPIENTRYP _GLUfuncptr)();
>> +typedef void (GLAPIENTRYP _GLUfuncptr)(void);
>>
>>  GLAPI void GLAPIENTRY gluBeginCurve (GLUnurbs* nurb);
>>  GLAPI void GLAPIENTRY gluBeginPolygon (GLUtesselator* tess);
>> diff --git a/src/egl/drivers/dri2/egl_dri2.c 
>> b/src/egl/drivers/dri2/egl_dri2.c
>> index afab679..f5f5ac3 100644
>> --- a/src/egl/drivers/dri2/egl_dri2.c
>> +++ b/src/egl/drivers/dri2/egl_dri2.c
>> @@ -835,7 +835,7 @@ dri2_create_image_khr_renderbuffer(_EGLDisplay
>> *disp, _EGLContext *ctx,
>>     struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
>>     struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx);
>>     struct dri2_egl_image *dri2_img;
>> -   GLuint renderbuffer = (GLuint) buffer;
>> +   GLuint renderbuffer =  (unsigned long) buffer;
>>
>>     if (renderbuffer == 0) {
>>        _eglError(EGL_BAD_PARAMETER, "dri2_create_image_khr");
>> @@ -870,7 +870,7 @@ dri2_create_image_mesa_drm_buffer(_EGLDisplay
>> *disp, _EGLContext *ctx,
>>
>>     (void) ctx;
>>
>> -   name = (EGLint) buffer;
>> +   name = (unsigned long) buffer;
>>
>>     err = _eglParseImageAttribList(&attrs, disp, attr_list);
>>     if (err != EGL_SUCCESS)
>> diff --git a/src/egl/drivers/dri2/platform_drm.c
>> b/src/egl/drivers/dri2/platform_drm.c
>> index 68912e3..cea8418 100644
>> --- a/src/egl/drivers/dri2/platform_drm.c
>> +++ b/src/egl/drivers/dri2/platform_drm.c
>> @@ -596,7 +596,7 @@ dri2_get_device_name(int fd)
>>        goto out;
>>     }
>>
>> -   device_name = udev_device_get_devnode(device);
>> +   device_name = (char*)udev_device_get_devnode(device);
>>     if (!device_name)
>>            goto out;
>>     device_name = strdup(device_name);
>> @@ -690,7 +690,7 @@ dri2_initialize_drm(_EGLDriver *drv, _EGLDisplay *disp)
>>     memset(dri2_dpy, 0, sizeof *dri2_dpy);
>>
>>     disp->DriverData = (void *) dri2_dpy;
>> -   dri2_dpy->fd = (int) disp->PlatformDisplay;
>> +   dri2_dpy->fd = (long) disp->PlatformDisplay;
>>
>>     dri2_dpy->driver_name = dri2_get_driver_for_fd(dri2_dpy->fd);
>>     if (dri2_dpy->driver_name == NULL)
>> diff --git a/src/egl/drivers/dri2/platform_x11.c
>> b/src/egl/drivers/dri2/platform_x11.c
>> index 5d4ac6a..90136f4 100644
>> --- a/src/egl/drivers/dri2/platform_x11.c
>> +++ b/src/egl/drivers/dri2/platform_x11.c
>> @@ -784,7 +784,7 @@ dri2_create_image_khr_pixmap(_EGLDisplay *disp,
>> _EGLContext *ctx,
>>
>>     (void) ctx;
>>
>> -   drawable = (xcb_drawable_t) buffer;
>> +   drawable = (xcb_drawable_t) (long)buffer;
>>     xcb_dri2_create_drawable (dri2_dpy->conn, drawable);
>>     attachments[0] = XCB_DRI2_ATTACHMENT_BUFFER_FRONT_LEFT;
>>     buffers_cookie =
>> diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c
>> index 336ec23..9063752 100644
>> --- a/src/egl/main/eglapi.c
>> +++ b/src/egl/main/eglapi.c
>> @@ -1168,7 +1168,7 @@ eglQueryModeStringMESA(EGLDisplay dpy, EGLModeMESA 
>> mode)
>>  EGLDisplay EGLAPIENTRY
>>  eglGetDRMDisplayMESA(int fd)
>>  {
>> -   _EGLDisplay *dpy = _eglFindDisplay(_EGL_PLATFORM_DRM, (void *) fd);
>> +   _EGLDisplay *dpy = _eg

Re: [Mesa-dev] [PATCH] configure.ac: Enable GLX_USE_TLS if possible.

2012-02-08 Thread Zhigang Gong
On Wed, Feb 08, 2012 at 02:46:42PM -0800, Eric Anholt wrote:
> On Wed,  8 Feb 2012 16:19:38 +0800, zhigang.g...@linux.intel.com wrote:
> > From: Zhigang Gong 
> > 
> > If the system support tls, we prefer to enable it by default
> > just as xserver does. Actually, the checking code is copied
> > from xserver/configure.ac.
> > 
> > Signed-off-by: Zhigang Gong 
> > ---
> >  configure.ac |   10 --
> >  1 files changed, 8 insertions(+), 2 deletions(-)
> > 
> > diff --git a/configure.ac b/configure.ac
> > index b2b1ab8..7c2756b 100644
> > --- a/configure.ac
> > +++ b/configure.ac
> > @@ -1103,8 +1103,14 @@ dnl
> >  AC_ARG_ENABLE([glx-tls],
> >  [AS_HELP_STRING([--enable-glx-tls],
> >  [enable TLS support in GLX @<:@default=disabled@:>@])],
> > -[GLX_USE_TLS="$enableval"],
> > -[GLX_USE_TLS=no])
> > +[GLX_USE_TLS=$enableval
> > + if test "x$GLX_USE_TLS" = "xyes" && test "${ac_cv_tls}" = "none" ; 
> > then
> > +AC_MSG_ERROR([GLX with TLS support requested, but the compiler 
> > does not support it.])
> > + fi],
> > +[GLX_USE_TLS=no
> > + if test "${ac_cv_tls}" != "none" ; then
> > +    GLX_USE_TLS=yes
> > + fi])
> >  AC_SUBST(GLX_TLS, ${GLX_USE_TLS})
> 
> I don't think you have anything setting ac_cv_tls.

You are right, I forgot to add the checking code which is also from xserver.
Sorry for that, here is the v2 patch:

From: Zhigang Gong 
Date: Wed, 8 Feb 2012 16:12:42 +0800
Subject: [PATCH v2] configure.ac: Enable GLX_USE_TLS if possible.

If the system support tls, we prefer to enable it by default
just as xserver does. Actually, the checking code is copied
from xserver/configure.ac.

Signed-off-by: Zhigang Gong 
---
 configure.ac |   39 +--
 1 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/configure.ac b/configure.ac
index b2b1ab8..3dfafba 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1099,12 +1099,47 @@ esac
 dnl
 dnl TLS detection
 dnl
+AC_MSG_CHECKING(for thread local storage (TLS) support)
+AC_CACHE_VAL(ac_cv_tls, [
+ac_cv_tls=none
+keywords="__thread __declspec(thread)"
+for kw in $keywords ; do
+AC_TRY_COMPILE([int $kw test;], [], ac_cv_tls=$kw)
+done
+])
+AC_MSG_RESULT($ac_cv_tls)
+
+if test "$ac_cv_tls" != "none"; then
+AC_MSG_CHECKING(for tls_model attribute support)
+AC_CACHE_VAL(ac_cv_tls_model, [
+save_CFLAGS="$CFLAGS"
+CFLAGS="$CFLAGS $STRICT_CFLAGS"
+AC_TRY_COMPILE([int $ac_cv_tls 
__attribute__((tls_model("initial-exec"))) test;], [],
+   ac_cv_tls_model=yes, ac_cv_tls_model=no)
+CFLAGS="$save_CFLAGS"
+])
+AC_MSG_RESULT($ac_cv_tls_model)
+
+if test "x$ac_cv_tls_model" = "xyes" ; then
+mesa_tls=$ac_cv_tls' __attribute__((tls_model("initial-exec")))'
+else
+mesa_tls=$ac_cv_tls
+fi
+
+AC_DEFINE_UNQUOTED([TLS], $mesa_tls, [The compiler supported TLS storage 
class, prefering initial-exec if tls_model is supported])
+fi
 
 AC_ARG_ENABLE([glx-tls],
 [AS_HELP_STRING([--enable-glx-tls],
 [enable TLS support in GLX @<:@default=disabled@:>@])],
-[GLX_USE_TLS="$enableval"],
-[GLX_USE_TLS=no])
+[GLX_USE_TLS=$enableval
+ if test "x$GLX_USE_TLS" = "xyes" && test "${ac_cv_tls}" = "none" ; then
+AC_MSG_ERROR([GLX with TLS support requested, but the compiler does 
not support it.])
+ fi],
+[GLX_USE_TLS=no
+ if test "${ac_cv_tls}" != "none" ; then
+GLX_USE_TLS=yes
+ fi])
 AC_SUBST(GLX_TLS, ${GLX_USE_TLS})
 
 AS_IF([test "x$GLX_USE_TLS" = xyes],
-- 
1.7.4.4

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH v2 1/2] configure.ac: Enable GLX_USE_TLS if possible.

2012-02-13 Thread Zhigang Gong
On Sun, Feb 12, 2012 at 09:02:44AM -0500, nobled wrote:
> Judging by the patch that tried to change the tls_model:
> https://bugs.freedesktop.org/show_bug.cgi?id=35268
> It looks like we'd need to disable enable_asm if the tls_model
> attribute isn't supported, since it would probably end up defaulting
> to general-dynamic for PIC code IIRC, and the assembly depends on it
> being initial-exec. Clang still doesn't support the tls_model
> attribute, and it doesn't fail compilation: it just gives a
> -Wattributes warning, so we might need to add '-Werror -Wattributes'
> (to catch the versions before -Wattributes was added, which give an
> 'unknown warning option' warning) to the test-compilation CFLAGS...
> 
> Plus, the test would have to be moved to before enable_asm is decided
> and adds the -DUSE_X86_ASM, etc defines.
> 

Thanks for the comments, I refined the patch according to you and
Dan's suggestion. Here is the new version. As to the version check
of CLANG, I haven't handled it as I don't have the environment at
hand. Could you help to add it?

>From 75de119cf92cb43cecd4813267ed0c76979ddef4 Mon Sep 17 00:00:00 2001
From: Zhigang Gong 
Date: Mon, 13 Feb 2012 17:26:21 +0800
Subject: [PATCH 1/2 v2] configure.ac: Enable GLX_USE_TLS if possible.

If the system support tls, we prefer to enable it by default
just as xserver does. Actually, the checking code is copied
from xserver/configure.ac.
According to nobled's suggestion, move the checking before
enable_asm. As if tls_model is not supported, then asm may
can't work correctly. Then we check the tls model first,
and if doesn't support it, we need to disable the asm code.

Signed-off-by: Zhigang Gong 
Reviewed-by: Dan Nicholson 
---
 acinclude.m4 |   36 
 configure.ac |   25 ++---
 2 files changed, 58 insertions(+), 3 deletions(-)

diff --git a/acinclude.m4 b/acinclude.m4
index a5b389d..509de5b 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -117,3 +117,39 @@ if test "$enable_pic" != no; then
 fi
 AC_SUBST([PIC_FLAGS])
 ])# MESA_PIC_FLAGS
+
+dnl TLS detection
+AC_DEFUN([MESA_TLS],
+[AC_MSG_CHECKING(for thread local storage (TLS) support)
+AC_CACHE_VAL(ac_cv_tls, [
+ac_cv_tls=none
+keywords="__thread __declspec(thread)"
+for kw in $keywords ; do
+AC_TRY_COMPILE([int $kw test;], [], ac_cv_tls=$kw)
+done
+])
+AC_MSG_RESULT($ac_cv_tls)
+
+if test "$ac_cv_tls" != "none"; then
+AC_MSG_CHECKING(for tls_model attribute support)
+saved_CFLAGS="$CFLAGS"
+if test "x$acv_mesa_CLANG" = "xyes"; then
+CFLAGS="$CFLAGS -Wattribute -Werror"
+fi
+AC_CACHE_VAL(ac_cv_tls_model, [
+AC_TRY_COMPILE([int $ac_cv_tls 
__attribute__((tls_model("initial-exec"))) test;], [],
+   ac_cv_tls_model=yes, ac_cv_tls_model=no)
+])
+CFLAGS="$saved_CFLAGS"
+AC_MSG_RESULT($ac_cv_tls_model)
+
+AC_MSG_CHECKING([for $CC option to define TLS variable])
+if test "x$ac_cv_tls_model" = "xyes" ; then
+TLS=$ac_cv_tls' __attribute__((tls_model(\"initial-exec\")))'
+else
+TLS=$ac_cv_tls
+fi
+DEFINES="$DEFINES -DTLS=\"$TLS\""
+AC_MSG_RESULT([$TLS])
+fi
+])
diff --git a/configure.ac b/configure.ac
index b2b1ab8..3423cb2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -433,6 +433,11 @@ AC_SUBST([VG_LIB_GLOB])
 AC_SUBST([GLAPI_LIB_GLOB])
 
 dnl
+dnl Check tls model support 
+dnl
+MESA_TLS
+
+dnl
 dnl Arch/platform-specific settings
 dnl
 AC_ARG_ENABLE([asm],
@@ -446,6 +451,14 @@ ASM_FLAGS=""
 MESA_ASM_SOURCES=""
 GLAPI_ASM_SOURCES=""
 AC_MSG_CHECKING([whether to enable assembly])
+
+if test "x$ac_cv_tls_model" = "xno" ; then
+dnl
+dnl If tls model is not supported, disable asm.
+dnl
+enable_asm=no
+fi
+
 test "x$enable_asm" = xno && AC_MSG_RESULT([no])
 # disable if cross compiling on x86/x86_64 since we must run gen_matypes
 if test "x$enable_asm" = xyes && test "x$cross_compiling" = xyes; then
@@ -1102,9 +1115,15 @@ dnl
 
 AC_ARG_ENABLE([glx-tls],
 [AS_HELP_STRING([--enable-glx-tls],
-[enable TLS support in GLX @<:@default=disabled@:>@])],
-[GLX_USE_TLS="$enableval"],
-[GLX_USE_TLS=no])
+[enable TLS support in GLX @<:@default=auto@:>@])],
+[GLX_USE_TLS=$enableval
+ if test "x$GLX_USE_TLS" = "xyes" && test "${ac_cv_tls}" = "none" ; then
+AC_MSG_ERROR([GLX with TLS support requested, but the compiler does 
not support it.])
+ fi],
+[GLX_USE_TLS=no
+ if test "${ac_cv_tls}" != "none" ; then
+GLX_USE_TLS=yes
+ fi])
 AC_SUBST(GLX_TLS, ${GLX_USE_TLS})
 
 AS_IF([test "x$GLX_USE_TLS" = xyes],
-- 
1.7.4.4

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH v2 2/2] GLX_TLS: use TLS macros when define those TLS variables.

2012-02-13 Thread Zhigang Gong
On Mon, Feb 13, 2012 at 06:10:36PM +0800, Zhigang Gong wrote:
> On Sun, Feb 12, 2012 at 09:02:44AM -0500, nobled wrote:
>From ac92209ccf1d8877eb58bf0bfdd0ccc389200bac Mon Sep 17 00:00:00 2001
From: Zhigang Gong 
Date: Mon, 13 Feb 2012 17:29:12 +0800
Subject: [PATCH 2/2] GLX_TLS: use TLS macros when define those TLS variables.

Use the TLS marco detected at autoconf stage.

Signed-off-by: Zhigang Gong 
---
 src/egl/main/eglcurrent.c  |3 +--
 src/glx/glxclient.h|3 +--
 src/glx/glxcurrent.c   |3 +--
 src/mapi/glapi/glapi.h |6 ++
 src/mapi/mapi/u_current.c  |6 ++
 src/mapi/mapi/u_current.h  |6 ++
 src/mesa/drivers/dri/common/dri_test.c |6 ++
 src/mesa/drivers/x11/glxapi.c  |3 +--
 8 files changed, 12 insertions(+), 24 deletions(-)

diff --git a/src/egl/main/eglcurrent.c b/src/egl/main/eglcurrent.c
index 54fc4f7..d301a4b 100644
--- a/src/egl/main/eglcurrent.c
+++ b/src/egl/main/eglcurrent.c
@@ -51,8 +51,7 @@ static pthread_key_t _egl_TSD;
 static void (*_egl_FreeTSD)(_EGLThreadInfo *);
 
 #ifdef GLX_USE_TLS
-static __thread const _EGLThreadInfo *_egl_TLS
-   __attribute__ ((tls_model("initial-exec")));
+static TLS const _EGLThreadInfo * _egl_TLS; 
 #endif
 
 static INLINE void _eglSetTSD(const _EGLThreadInfo *t)
diff --git a/src/glx/glxclient.h b/src/glx/glxclient.h
index f8ae450..06785df 100644
--- a/src/glx/glxclient.h
+++ b/src/glx/glxclient.h
@@ -630,9 +630,8 @@ extern void __glXSetCurrentContext(struct glx_context * c);
 
 # if defined( GLX_USE_TLS )
 
-extern __thread void *__glX_tls_Context
-   __attribute__ ((tls_model("initial-exec")));
 
+extern TLS void *__glX_tls_Context;
 #  define __glXGetCurrentContext() __glX_tls_Context
 
 # else
diff --git a/src/glx/glxcurrent.c b/src/glx/glxcurrent.c
index c92a2fd..f295d2c 100644
--- a/src/glx/glxcurrent.c
+++ b/src/glx/glxcurrent.c
@@ -86,8 +86,7 @@ _X_HIDDEN pthread_mutex_t __glXmutex = 
PTHREAD_MUTEX_INITIALIZER;
  * \b never be \c NULL.  This is important!  Because of this
  * \c __glXGetCurrentContext can be implemented as trivial macro.
  */
-__thread void *__glX_tls_Context __attribute__ ((tls_model("initial-exec")))
-   = &dummyContext;
+TLS void *__glX_tls_Context = &dummyContext;
 
 _X_HIDDEN void
 __glXSetCurrentContext(struct glx_context * c)
diff --git a/src/mapi/glapi/glapi.h b/src/mapi/glapi/glapi.h
index f685475..ef69e64 100644
--- a/src/mapi/glapi/glapi.h
+++ b/src/mapi/glapi/glapi.h
@@ -85,11 +85,9 @@ struct _glapi_table;
 
 #if defined (GLX_USE_TLS)
 
-_GLAPI_EXPORT extern __thread struct _glapi_table * _glapi_tls_Dispatch
-__attribute__((tls_model("initial-exec")));
+_GLAPI_EXPORT extern TLS struct _glapi_table * _glapi_tls_Dispatch;
 
-_GLAPI_EXPORT extern __thread void * _glapi_tls_Context
-__attribute__((tls_model("initial-exec")));
+_GLAPI_EXPORT extern TLS void * _glapi_tls_Context;
 
 _GLAPI_EXPORT extern const struct _glapi_table *_glapi_Dispatch;
 _GLAPI_EXPORT extern const void *_glapi_Context;
diff --git a/src/mapi/mapi/u_current.c b/src/mapi/mapi/u_current.c
index 21a07ab..f4e241e 100644
--- a/src/mapi/mapi/u_current.c
+++ b/src/mapi/mapi/u_current.c
@@ -99,12 +99,10 @@ extern void (*__glapi_noop_table[])(void);
 /*@{*/
 #if defined(GLX_USE_TLS)
 
-__thread struct mapi_table *u_current_table
-__attribute__((tls_model("initial-exec")))
+TLS struct mapi_table *u_current_table
 = (struct mapi_table *) table_noop_array;
 
-__thread void *u_current_user
-__attribute__((tls_model("initial-exec")));
+TLS void *u_current_user;
 
 #else
 
diff --git a/src/mapi/mapi/u_current.h b/src/mapi/mapi/u_current.h
index f9cffd8..0584dc8 100644
--- a/src/mapi/mapi/u_current.h
+++ b/src/mapi/mapi/u_current.h
@@ -30,11 +30,9 @@ struct mapi_table;
 
 #ifdef GLX_USE_TLS
 
-extern __thread struct mapi_table *u_current_table
-__attribute__((tls_model("initial-exec")));
+extern TLS struct mapi_table *u_current_table;
 
-extern __thread void *u_current_user
-__attribute__((tls_model("initial-exec")));
+extern TLS void *u_current_user;
 
 #else /* GLX_USE_TLS */
 
diff --git a/src/mesa/drivers/dri/common/dri_test.c 
b/src/mesa/drivers/dri/common/dri_test.c
index 793f0c3..aaad90c 100644
--- a/src/mesa/drivers/dri/common/dri_test.c
+++ b/src/mesa/drivers/dri/common/dri_test.c
@@ -11,11 +11,9 @@ extern char __driDriverExtensions[];
 
 #if defined(GLX_USE_TLS)
 
-PUBLIC __thread struct _glapi_table * _glapi_tls_Dispatch
-__attribute__((tls_model("initial-exec")));
+PUBLIC TLS struct _glapi_table * _glapi_tls_Dispatch;
 
-PUBLIC __thread void * _glapi_tls_Context
-__attribute__((tls_model("initial-exec")));
+PUBLIC TLS void * _glapi_tls_Context;
 
 PUBLIC const struct _glapi_table *_glapi_Dispatch;
 PUBLIC const void *_glapi_Context;
diff --git a/src/mesa/driv

[Mesa-dev] [PATCH 1/2] gbm: Use a separate function to check format and usage.

2012-02-14 Thread zhigang . gong
From: Zhigang Gong 

To extent gbm to support more formats and usages, it's better
to do the format and usage matching in a seprated function.
Also fixed a memory leak at gbm_dri_bo_create, if failed to
create a DRI image, before return NULL, we need to free
bo.

Signed-off-by: Zhigang Gong 
---
 src/gbm/backends/dri/gbm_dri.c |   61 ---
 src/gbm/main/gbm.h |4 ++
 2 files changed, 41 insertions(+), 24 deletions(-)

diff --git a/src/gbm/backends/dri/gbm_dri.c b/src/gbm/backends/dri/gbm_dri.c
index ddd153a..7932d12 100644
--- a/src/gbm/backends/dri/gbm_dri.c
+++ b/src/gbm/backends/dri/gbm_dri.c
@@ -215,20 +215,41 @@ free_screen:
 }
 
 static int
-gbm_dri_is_format_supported(struct gbm_device *gbm,
-enum gbm_bo_format format,
-uint32_t usage)
+gbm_dri_match_format(enum gbm_bo_format format, int *dri_format)
 {
switch (format) {
case GBM_BO_FORMAT_XRGB:
+  *dri_format = __DRI_IMAGE_FORMAT_XRGB;
   break;
case GBM_BO_FORMAT_ARGB:
-  if (usage & GBM_BO_USE_SCANOUT)
- return 0;
+  *dri_format = __DRI_IMAGE_FORMAT_ARGB;
   break;
default:
-  return 0;
+  return -1;
}
+  return 0;
+}
+
+static void
+gbm_dri_match_usage(enum  gbm_bo_flags usage, unsigned int *dri_use) {
+   if (usage & GBM_BO_USE_SCANOUT)
+  *dri_use |= __DRI_IMAGE_USE_SCANOUT;
+   if (usage & GBM_BO_USE_CURSOR_64X64)
+  *dri_use |= __DRI_IMAGE_USE_CURSOR; }
+
+static int
+gbm_dri_is_format_supported(struct gbm_device *gbm,
+enum gbm_bo_format format,
+uint32_t usage) {
+   int dri_format = 0;
+
+   if (gbm_dri_match_format(format, &dri_format)
+   || (usage & ~GBM_BO_USE_VALID_FLAGS)
+   || ((usage & GBM_BO_USE_SCANOUT)
+&& (format == GBM_BO_FORMAT_ARGB))
+   || ((usage & GBM_BO_USE_CURSOR_64X64)
+&& (usage & GBM_BO_USE_RENDERING)))
+  return 0;
 
if (usage & GBM_BO_USE_CURSOR_64X64 &&
usage & GBM_BO_USE_RENDERING)
@@ -303,7 +324,12 @@ gbm_dri_bo_create(struct gbm_device *gbm,
struct gbm_dri_device *dri = gbm_dri_device(gbm);
struct gbm_dri_bo *bo;
int dri_format;
-   unsigned dri_use = 0;
+   unsigned int dri_use = 0;
+
+   if (gbm_dri_match_format(format, &dri_format) != 0)
+  return NULL;
+   if (usage & ~GBM_BO_USE_VALID_FLAGS)
+  return NULL;
 
bo = calloc(1, sizeof *bo);
if (bo == NULL)
@@ -313,29 +339,16 @@ gbm_dri_bo_create(struct gbm_device *gbm,
bo->base.base.width = width;
bo->base.base.height = height;
 
-   switch (format) {
-   case GBM_BO_FORMAT_XRGB:
-  dri_format = __DRI_IMAGE_FORMAT_XRGB;
-  break;
-   case GBM_BO_FORMAT_ARGB:
-  dri_format = __DRI_IMAGE_FORMAT_ARGB;
-  break;
-   default:
-  return NULL;
-   }
-
-   if (usage & GBM_BO_USE_SCANOUT)
-  dri_use |= __DRI_IMAGE_USE_SCANOUT;
-   if (usage & GBM_BO_USE_CURSOR_64X64)
-  dri_use |= __DRI_IMAGE_USE_CURSOR;
-
+   gbm_dri_match_usage(usage, &dri_use);
bo->image =
   dri->image->createImage(dri->screen,
   width, height,
   dri_format, dri_use,
   bo);
-   if (bo->image == NULL)
+   if (bo->image == NULL) {
+  free(bo);
   return NULL;
+   }
 
dri->image->queryImage(bo->image, __DRI_IMAGE_ATTRIB_HANDLE,
   &bo->base.base.handle.s32);
diff --git a/src/gbm/main/gbm.h b/src/gbm/main/gbm.h
index c4ae51d..ec64b94 100644
--- a/src/gbm/main/gbm.h
+++ b/src/gbm/main/gbm.h
@@ -100,6 +100,10 @@ enum gbm_bo_flags {
GBM_BO_USE_RENDERING= (1 << 2),
 };
 
+#define GBM_BO_USE_VALID_FLAGS (GBM_BO_USE_SCANOUT\
+| GBM_BO_USE_CURSOR_64X64 \
+| GBM_BO_USE_RENDERING)
+
 int
 gbm_device_get_fd(struct gbm_device *gbm);
 
-- 
1.7.4.4

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 2/2] gbm/dri: Add more color formats support.

2012-02-14 Thread zhigang . gong
From: Zhigang Gong 

Added two color formats RGB565 and A8 to gbm layer.
Added A8 to dri layer.

Signed-off-by: Zhigang Gong 
---
 include/GL/internal/dri_interface.h   |1 +
 src/gbm/backends/dri/gbm_dri.c|6 ++
 src/gbm/main/gbm.h|6 +-
 src/mesa/drivers/dri/intel/intel_screen.c |5 +
 4 files changed, 17 insertions(+), 1 deletions(-)

diff --git a/include/GL/internal/dri_interface.h 
b/include/GL/internal/dri_interface.h
index 701e83e..b98ee3d 100644
--- a/include/GL/internal/dri_interface.h
+++ b/include/GL/internal/dri_interface.h
@@ -906,6 +906,7 @@ struct __DRIdri2ExtensionRec {
 #define __DRI_IMAGE_FORMAT_XRGB 0x1002
 #define __DRI_IMAGE_FORMAT_ARGB 0x1003
 #define __DRI_IMAGE_FORMAT_ABGR 0x1004
+#define __DRI_IMAGE_FORMAT_A8   0x1005
 
 #define __DRI_IMAGE_USE_SHARE  0x0001
 #define __DRI_IMAGE_USE_SCANOUT0x0002
diff --git a/src/gbm/backends/dri/gbm_dri.c b/src/gbm/backends/dri/gbm_dri.c
index 7932d12..d5a73f2 100644
--- a/src/gbm/backends/dri/gbm_dri.c
+++ b/src/gbm/backends/dri/gbm_dri.c
@@ -224,6 +224,12 @@ gbm_dri_match_format(enum gbm_bo_format format, int 
*dri_format)
case GBM_BO_FORMAT_ARGB:
   *dri_format = __DRI_IMAGE_FORMAT_ARGB;
   break;
+   case GBM_BO_FORMAT_RGB565:
+  *dri_format = __DRI_IMAGE_FORMAT_RGB565;
+  break;
+   case GBM_BO_FORMAT_A8:
+  *dri_format = __DRI_IMAGE_FORMAT_A8;
+  break;
default:
   return -1;
}
diff --git a/src/gbm/main/gbm.h b/src/gbm/main/gbm.h
index ec64b94..2880872 100644
--- a/src/gbm/main/gbm.h
+++ b/src/gbm/main/gbm.h
@@ -72,7 +72,11 @@ enum gbm_bo_format {
/** RGB with 8 bits per channel in a 32 bit value */
GBM_BO_FORMAT_XRGB, 
/** ARGB with 8 bits per channel in a 32 bit value */
-   GBM_BO_FORMAT_ARGB
+   GBM_BO_FORMAT_ARGB,
+   /* RGB with 5 bits red channel, 6 bits green channel and 5 bits blue 
channel*/
+   GBM_BO_FORMAT_RGB565,
+   /* Alpha with 8 bits alpha channel. */
+   GBM_BO_FORMAT_A8
 };
 
 /**
diff --git a/src/mesa/drivers/dri/intel/intel_screen.c 
b/src/mesa/drivers/dri/intel/intel_screen.c
index 60781e5..f0fc5a4 100644
--- a/src/mesa/drivers/dri/intel/intel_screen.c
+++ b/src/mesa/drivers/dri/intel/intel_screen.c
@@ -147,6 +147,11 @@ intel_create_image_from_name(__DRIscreen *screen,
return NULL;
 
 switch (format) {
+case __DRI_IMAGE_FORMAT_A8:
+   image->format = MESA_FORMAT_A8;
+   image->internal_format = GL_ALPHA;
+   image->data_type = GL_UNSIGNED_BYTE;
+   break;
 case __DRI_IMAGE_FORMAT_RGB565:
image->format = MESA_FORMAT_RGB565;
image->internal_format = GL_RGB;
-- 
1.7.4.4

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v3 0/2] Enable GLX_USE_TLS if possible.

2012-02-15 Thread zhigang . gong
From: Zhigang Gong 

This version fixed the CFLAGS setting when check whether support 
tls model.

---
This patchset enable GLX_USE_TLS if the system support
it. And this patchset will check whether we support tls
model and choose propriate method to define those TLS
variables rather than define them by using hard coded
"attribute(..)". For the system doesn't support tls model,
this patchset will disable asm according to
nobled 's suggestion.
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v3 1/2] configure.ac: Enable GLX_USE_TLS if possible.

2012-02-15 Thread zhigang . gong
From: Zhigang Gong 

If the system support tls, we prefer to enable it by default
just as xserver does. Actually, the checking code is copied
from xserver/configure.ac.
According to nobled's suggestion, move the checking before
enable_asm. As if tls_model is not supported, then asm may
can't work correctly. Then we check the tls model first,
and if doesn't support it, we need to disable the asm code.
Here is the reference:
https://bugs.freedesktop.org/show_bug.cgi?id=35268

Signed-off-by: Zhigang Gong 
Reviewed-by: Dan Nicholson 
---
 acinclude.m4 |   41 +
 configure.ac |   25 ++---
 2 files changed, 63 insertions(+), 3 deletions(-)

diff --git a/acinclude.m4 b/acinclude.m4
index a5b389d..23805f3 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -117,3 +117,44 @@ if test "$enable_pic" != no; then
 fi
 AC_SUBST([PIC_FLAGS])
 ])# MESA_PIC_FLAGS
+
+dnl TLS detection
+AC_DEFUN([MESA_TLS],
+[AC_MSG_CHECKING(for thread local storage (TLS) support)
+AC_CACHE_VAL(ac_cv_tls, [
+ac_cv_tls=none
+keywords="__thread __declspec(thread)"
+for kw in $keywords ; do
+AC_TRY_COMPILE([int $kw test;], [], ac_cv_tls=$kw)
+done
+])
+AC_MSG_RESULT($ac_cv_tls)
+
+if test "$ac_cv_tls" != "none"; then
+STRICT_CFLAGS="-pedantic -Werror"
+# Add -Werror=attributes if supported (gcc 4.2 & later)
+AC_MSG_CHECKING([if $CC supports -Werror=attributes])
+save_CFLAGS="$CFLAGS"
+CFLAGS="$CFLAGS $STRICT_CFLAGS -Werror=attributes"
+AC_TRY_COMPILE([int test;], [],
+   [STRICT_CFLAGS="$STRICT_CFLAGS -Werror=attributes"
+AC_MSG_RESULT([yes])],
+   [AC_MSG_RESULT([no])])
+CFLAGS="$save_CFLAGS $STRICT_CFLAGS"
+
+AC_MSG_CHECKING(for tls_model attribute support)
+AC_CACHE_VAL(ac_cv_tls_model, [
+AC_TRY_COMPILE([int $ac_cv_tls 
__attribute__((tls_model("initial-exec"))) test;], [],
+   ac_cv_tls_model=yes, ac_cv_tls_model=no)
+])
+AC_MSG_RESULT($ac_cv_tls_model)
+
+if test "x$ac_cv_tls_model" = "xyes" ; then
+TLS=$ac_cv_tls' __attribute__((tls_model(\"initial-exec\")))'
+else
+TLS=$ac_cv_tls
+fi
+DEFINES="$DEFINES -DTLS=\"$TLS\""
+CFLAGS="$save_CFLAGS"
+fi
+])
diff --git a/configure.ac b/configure.ac
index b2b1ab8..3226a09 100644
--- a/configure.ac
+++ b/configure.ac
@@ -433,6 +433,11 @@ AC_SUBST([VG_LIB_GLOB])
 AC_SUBST([GLAPI_LIB_GLOB])
 
 dnl
+dnl Check tls model support
+dnl
+MESA_TLS
+
+dnl
 dnl Arch/platform-specific settings
 dnl
 AC_ARG_ENABLE([asm],
@@ -446,6 +451,14 @@ ASM_FLAGS=""
 MESA_ASM_SOURCES=""
 GLAPI_ASM_SOURCES=""
 AC_MSG_CHECKING([whether to enable assembly])
+
+if test "x$ac_cv_tls_model" = "xno" ; then
+dnl
+dnl If tls model is not supported, disable asm.
+dnl
+enable_asm=no
+fi
+
 test "x$enable_asm" = xno && AC_MSG_RESULT([no])
 # disable if cross compiling on x86/x86_64 since we must run gen_matypes
 if test "x$enable_asm" = xyes && test "x$cross_compiling" = xyes; then
@@ -1102,9 +1115,15 @@ dnl
 
 AC_ARG_ENABLE([glx-tls],
 [AS_HELP_STRING([--enable-glx-tls],
-[enable TLS support in GLX @<:@default=disabled@:>@])],
-[GLX_USE_TLS="$enableval"],
-[GLX_USE_TLS=no])
+[enable TLS support in GLX @<:@default=auto@:>@])],
+[GLX_USE_TLS=$enableval
+ if test "x$GLX_USE_TLS" = "xyes" && test "${ac_cv_tls}" = "none" ; then
+AC_MSG_ERROR([GLX with TLS support requested, but the compiler does 
not support it.])
+ fi],
+[GLX_USE_TLS=no
+ if test "${ac_cv_tls}" != "none" ; then
+GLX_USE_TLS=yes
+ fi])
 AC_SUBST(GLX_TLS, ${GLX_USE_TLS})
 
 AS_IF([test "x$GLX_USE_TLS" = xyes],
-- 
1.7.4.4

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v3 2/2] GLX_TLS: use TLS macros when define those TLS variables.

2012-02-15 Thread zhigang . gong
From: Zhigang Gong 

Use the properate way detected in autoconf stage to define
those TLS variables rather than using hard coded
"attribute..."

Signed-off-by: Zhigang Gong 
---
 src/egl/main/eglcurrent.c  |3 +--
 src/glx/glxclient.h|3 +--
 src/glx/glxcurrent.c   |3 +--
 src/mapi/glapi/glapi.h |6 ++
 src/mapi/mapi/u_current.c  |6 ++
 src/mapi/mapi/u_current.h  |6 ++
 src/mesa/drivers/dri/common/dri_test.c |6 ++
 src/mesa/drivers/x11/glxapi.c  |3 +--
 8 files changed, 12 insertions(+), 24 deletions(-)

diff --git a/src/egl/main/eglcurrent.c b/src/egl/main/eglcurrent.c
index 54fc4f7..bbd46ac 100644
--- a/src/egl/main/eglcurrent.c
+++ b/src/egl/main/eglcurrent.c
@@ -51,8 +51,7 @@ static pthread_key_t _egl_TSD;
 static void (*_egl_FreeTSD)(_EGLThreadInfo *);
 
 #ifdef GLX_USE_TLS
-static __thread const _EGLThreadInfo *_egl_TLS
-   __attribute__ ((tls_model("initial-exec")));
+static TLS const _EGLThreadInfo * _egl_TLS;
 #endif
 
 static INLINE void _eglSetTSD(const _EGLThreadInfo *t)
diff --git a/src/glx/glxclient.h b/src/glx/glxclient.h
index f8ae450..06785df 100644
--- a/src/glx/glxclient.h
+++ b/src/glx/glxclient.h
@@ -630,9 +630,8 @@ extern void __glXSetCurrentContext(struct glx_context * c);
 
 # if defined( GLX_USE_TLS )
 
-extern __thread void *__glX_tls_Context
-   __attribute__ ((tls_model("initial-exec")));
 
+extern TLS void *__glX_tls_Context;
 #  define __glXGetCurrentContext() __glX_tls_Context
 
 # else
diff --git a/src/glx/glxcurrent.c b/src/glx/glxcurrent.c
index c92a2fd..f295d2c 100644
--- a/src/glx/glxcurrent.c
+++ b/src/glx/glxcurrent.c
@@ -86,8 +86,7 @@ _X_HIDDEN pthread_mutex_t __glXmutex = 
PTHREAD_MUTEX_INITIALIZER;
  * \b never be \c NULL.  This is important!  Because of this
  * \c __glXGetCurrentContext can be implemented as trivial macro.
  */
-__thread void *__glX_tls_Context __attribute__ ((tls_model("initial-exec")))
-   = &dummyContext;
+TLS void *__glX_tls_Context = &dummyContext;
 
 _X_HIDDEN void
 __glXSetCurrentContext(struct glx_context * c)
diff --git a/src/mapi/glapi/glapi.h b/src/mapi/glapi/glapi.h
index f685475..ef69e64 100644
--- a/src/mapi/glapi/glapi.h
+++ b/src/mapi/glapi/glapi.h
@@ -85,11 +85,9 @@ struct _glapi_table;
 
 #if defined (GLX_USE_TLS)
 
-_GLAPI_EXPORT extern __thread struct _glapi_table * _glapi_tls_Dispatch
-__attribute__((tls_model("initial-exec")));
+_GLAPI_EXPORT extern TLS struct _glapi_table * _glapi_tls_Dispatch;
 
-_GLAPI_EXPORT extern __thread void * _glapi_tls_Context
-__attribute__((tls_model("initial-exec")));
+_GLAPI_EXPORT extern TLS void * _glapi_tls_Context;
 
 _GLAPI_EXPORT extern const struct _glapi_table *_glapi_Dispatch;
 _GLAPI_EXPORT extern const void *_glapi_Context;
diff --git a/src/mapi/mapi/u_current.c b/src/mapi/mapi/u_current.c
index 21a07ab..f4e241e 100644
--- a/src/mapi/mapi/u_current.c
+++ b/src/mapi/mapi/u_current.c
@@ -99,12 +99,10 @@ extern void (*__glapi_noop_table[])(void);
 /*@{*/
 #if defined(GLX_USE_TLS)
 
-__thread struct mapi_table *u_current_table
-__attribute__((tls_model("initial-exec")))
+TLS struct mapi_table *u_current_table
 = (struct mapi_table *) table_noop_array;
 
-__thread void *u_current_user
-__attribute__((tls_model("initial-exec")));
+TLS void *u_current_user;
 
 #else
 
diff --git a/src/mapi/mapi/u_current.h b/src/mapi/mapi/u_current.h
index f9cffd8..0584dc8 100644
--- a/src/mapi/mapi/u_current.h
+++ b/src/mapi/mapi/u_current.h
@@ -30,11 +30,9 @@ struct mapi_table;
 
 #ifdef GLX_USE_TLS
 
-extern __thread struct mapi_table *u_current_table
-__attribute__((tls_model("initial-exec")));
+extern TLS struct mapi_table *u_current_table;
 
-extern __thread void *u_current_user
-__attribute__((tls_model("initial-exec")));
+extern TLS void *u_current_user;
 
 #else /* GLX_USE_TLS */
 
diff --git a/src/mesa/drivers/dri/common/dri_test.c 
b/src/mesa/drivers/dri/common/dri_test.c
index 793f0c3..aaad90c 100644
--- a/src/mesa/drivers/dri/common/dri_test.c
+++ b/src/mesa/drivers/dri/common/dri_test.c
@@ -11,11 +11,9 @@ extern char __driDriverExtensions[];
 
 #if defined(GLX_USE_TLS)
 
-PUBLIC __thread struct _glapi_table * _glapi_tls_Dispatch
-__attribute__((tls_model("initial-exec")));
+PUBLIC TLS struct _glapi_table * _glapi_tls_Dispatch;
 
-PUBLIC __thread void * _glapi_tls_Context
-__attribute__((tls_model("initial-exec")));
+PUBLIC TLS void * _glapi_tls_Context;
 
 PUBLIC const struct _glapi_table *_glapi_Dispatch;
 PUBLIC const void *_glapi_Context;
diff --git a/src/mesa/drivers/x11/glxapi.c b/src/mesa/drivers/x11/glxapi.c
index 255a37b..57f3e9d 100644
--- a/src/mesa/drivers/x11/glxapi.c
+++ b/src/mesa/drivers/x11/glxapi.c
@@ -159,8 +159,7 @@ get_dispatch(Display *dpy)
  * GLX API current context.
  

Re: [Mesa-dev] [PATCH v3 1/2] configure.ac: Enable GLX_USE_TLS if possible.

2012-02-15 Thread Zhigang Gong
> -Original Message-
> From: tf (mobile) [mailto:tfo...@sci.utah.edu]
> Sent: Wednesday, February 15, 2012 8:53 PM
> To: zhigang.g...@linux.intel.com
> Cc: dbn.li...@gmail.com; nob...@dreamwidth.org;
> mesa-dev@lists.freedesktop.org
> Subject: Re: [Mesa-dev] [PATCH v3 1/2] configure.ac: Enable GLX_USE_TLS
> if possible.
> 
> Even if the system supports tls, the x server may not have been built with
it.
> As i recall, there is an issue with mismatching tls between x and
drivers...
> Can a non-tls server load a tls driver?
AFAIK, a mesa built without TLS can work with a xserver built with TLS
enabled,
Actually, this is current situation. Xserver will enable TLS if the system
support
It, but mesa will not enable TLS by default no matter the system support it.

IMO, the only relevant part may be the indirect GLX in xserver which will
load
DRI driver and thus mesa. But xserver has its own glapi.c and will not share
the mesa's glapi.c, then the mismatch will not be a big issue. If I missed
anything,
please correct me.

Anyway, I still think it's better to keep the xserver and mesa have the same
configuration
when they are built/running on the same system. Right?

Besides that issue, I think mesa should check whether the system support
TLS and tls model before enable it. So I still want this patchset get
accepted.

Any comment?

> 
> Anyway, if there's an issue there, this check must be more complicated --
it
> can't be just, "does the system support this",  it would instead need to
be
> "can the system support this and is it enabled in the x server."
> 
> IIRC Eric and ajax and Dan know more, but there should also be a
> discussion of this in the xorg-devel and/or mesa archives.
> 
> -tom
> 
> On 15.02.2012, at 12:41, zhigang.g...@linux.intel.com wrote:
> 
> > From: Zhigang Gong 
> >
> > If the system support tls, we prefer to enable it by default just as
> > xserver does. Actually, the checking code is copied from
> > xserver/configure.ac.
> > According to nobled's suggestion, move the checking before
> enable_asm.
> > As if tls_model is not supported, then asm may can't work correctly.
> > Then we check the tls model first, and if doesn't support it, we need
> > to disable the asm code.
> > Here is the reference:
> > https://bugs.freedesktop.org/show_bug.cgi?id=35268
> >
> > Signed-off-by: Zhigang Gong 
> > Reviewed-by: Dan Nicholson 
> > ---
> > acinclude.m4 |   41
> +
> > configure.ac |   25 ++---
> > 2 files changed, 63 insertions(+), 3 deletions(-)
> >
> > diff --git a/acinclude.m4 b/acinclude.m4 index a5b389d..23805f3
> 100644
> > --- a/acinclude.m4
> > +++ b/acinclude.m4
> > @@ -117,3 +117,44 @@ if test "$enable_pic" != no; then fi
> > AC_SUBST([PIC_FLAGS])
> > ])# MESA_PIC_FLAGS
> > +
> > +dnl TLS detection
> > +AC_DEFUN([MESA_TLS],
> > +[AC_MSG_CHECKING(for thread local storage (TLS) support)
> > +AC_CACHE_VAL(ac_cv_tls, [
> > +ac_cv_tls=none
> > +keywords="__thread __declspec(thread)"
> > +for kw in $keywords ; do
> > +AC_TRY_COMPILE([int $kw test;], [], ac_cv_tls=$kw)
> > +done
> > +])
> > +AC_MSG_RESULT($ac_cv_tls)
> > +
> > +if test "$ac_cv_tls" != "none"; then
> > +STRICT_CFLAGS="-pedantic -Werror"
> > +# Add -Werror=attributes if supported (gcc 4.2 & later)
> > +AC_MSG_CHECKING([if $CC supports -Werror=attributes])
> > +save_CFLAGS="$CFLAGS"
> > +CFLAGS="$CFLAGS $STRICT_CFLAGS -Werror=attributes"
> > +AC_TRY_COMPILE([int test;], [],
> > +   [STRICT_CFLAGS="$STRICT_CFLAGS
> -Werror=attributes"
> > +AC_MSG_RESULT([yes])],
> > +   [AC_MSG_RESULT([no])])
> > +CFLAGS="$save_CFLAGS $STRICT_CFLAGS"
> > +
> > +AC_MSG_CHECKING(for tls_model attribute support)
> > +AC_CACHE_VAL(ac_cv_tls_model, [
> > +AC_TRY_COMPILE([int $ac_cv_tls
> __attribute__((tls_model("initial-exec"))) test;], [],
> > +   ac_cv_tls_model=yes, ac_cv_tls_model=no)
> > +])
> > +AC_MSG_RESULT($ac_cv_tls_model)
> > +
> > +if test "x$ac_cv_tls_model" = "xyes" ; then
> > +TLS=$ac_cv_tls' __attribute__((tls_model(\"initial-exec\")))'
> > +else
> > +TLS=$ac_cv_tls
> > +fi
> > +DEFINES="$DEFINES -DTLS=\"$TLS\""
> &g

Re: [Mesa-dev] [PATCH v3 2/2] GLX_TLS: use TLS macros when define those TLS variables.

2012-03-19 Thread Zhigang Gong
Hi Brian,

Have you tried those testings(osmesa, static lib builds, etc) already and 
any new comments for the previous patchset.

Thanks.

> -Original Message-
> From:
> mesa-dev-bounces+zhigang.gong=linux.intel@lists.freedesktop.org
> [mailto:mesa-dev-bounces+zhigang.gong=linux.intel.com@lists.freedeskto
> p.org] On Behalf Of Brian Paul
> Sent: Thursday, February 16, 2012 10:38 PM
> To: Kenneth Graunke
> Cc: mesa-dev@lists.freedesktop.org
> Subject: Re: [Mesa-dev] [PATCH v3 2/2] GLX_TLS: use TLS macros when
> define those TLS variables.
> 
> On 02/16/2012 01:42 AM, Kenneth Graunke wrote:
> > On 02/15/2012 04:58 AM, tf (mobile) wrote:
> >> Personally i don't care much about non-autoconf builds, but as this
> >> relies on a -DTLS= setting during configuration time, it will break
> >> non-ac builds (which need tls), no?
> >>
> >> Other than that, LGTM.
> >>
> >> -tom
> >
> > That's okay, we've already broken non-automake builds. They're going
> > away at last. We should just go ahead and delete the old configs at
> > some point.
> 
> Please don't do that w/out fair warning.  I'd like to verify a few things
with
> automake (osmesa, static lib builds, etc.) first.  I'll try to do that in
my
> spare time, but I haven't had much lately.
> 
> -Brian
> ___
> mesa-dev mailing list
> mesa-dev@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev