[Beignet] [PATCH] Runtime: re-enable cl_khr_gl_sharing with existing egl extension.

Yang, Rong R rong.r.yang at intel.com
Mon Sep 5 05:20:47 UTC 2016


Which version is this patch required?

I think it introduce a new dependence, suppose someone has an old verion libegl, will cause build error, even if doesn’t need cl_khr_gl_sharing extension.
Can you add an libegl version check to cmake to avoid it?

> -----Original Message-----
> From: Weng, Chuanbo
> Sent: Monday, September 5, 2016 11:10
> To: Yang, Rong R <rong.r.yang at intel.com>; beignet at lists.freedesktop.org
> Subject: RE: [Beignet] [PATCH] Runtime: re-enable cl_khr_gl_sharing with
> existing egl extension.
> 
> This is because of your egl version.
> Please build and install latest mesa code from upstream:
> https://cgit.freedesktop.org/mesa/mesa/
> With the following commands:
> ./autogen.sh --with-dri-drivers="swrast,i965" --with-gallium-drivers="" --
> enable-gles1 --enable-gles2 --with-egl-platforms="x11,drm"
> make
> make install
> 
> -----Original Message-----
> From: Yang, Rong R
> Sent: Thursday, September 1, 2016 2:04 PM
> To: Weng, Chuanbo <chuanbo.weng at intel.com>;
> beignet at lists.freedesktop.org
> Cc: Weng, Chuanbo <chuanbo.weng at intel.com>
> Subject: RE: [Beignet] [PATCH] Runtime: re-enable cl_khr_gl_sharing with
> existing egl extension.
> 
> After install libegl, there is a build error:
> error: unknown type name ‘EGLImage’
> 
> > -----Original Message-----
> > From: Beignet [mailto:beignet-bounces at lists.freedesktop.org] On Behalf
> Of
> > Chuanbo Weng
> > Sent: Wednesday, August 31, 2016 0:56
> > To: beignet at lists.freedesktop.org
> > Cc: Weng, Chuanbo <chuanbo.weng at intel.com>
> > Subject: [Beignet] [PATCH] Runtime: re-enable cl_khr_gl_sharing with
> > existing egl extension.
> >
> > In order to query low level layout of GL buffer object/texture/render
> > buffer, previous implementation introduced an egl extension and
> > implemented
> > in Beignet side. This way is broken once mesa change its related internal
> > code. In this patch, we use an new egl
> > extension(EGL_MESA_image_dma_buf_export)
> > to query related layout infomations of gl texture. Since this egl extension
> > is already accepted by Khronos, so it's a stable method.
> > This patch just implement GL texture 2d buffer sharing, and we will
> > implement other target type if necessary.
> >
> > Signed-off-by: Chuanbo Weng <chuanbo.weng at intel.com>
> > ---
> >  CMake/FindMesaSrc.cmake                    |  26 ---
> >  CMakeLists.txt                             |   8 -
> >  src/CMakeLists.txt                         |  11 +-
> >  src/cl_driver.h                            |  32 +--
> >  src/cl_driver_defs.c                       |   7 -
> >  src/cl_gl_api.c                            |  17 +-
> >  src/cl_mem.h                               |  10 +-
> >  src/cl_mem_gl.c                            |   7 +-
> >  src/intel/intel_cl_gl_share_image_info.h   |  18 ++
> >  src/intel/intel_dri_resource_sharing.c     | 208 --------------------
> >  src/intel/intel_dri_resource_sharing.h     |  39 ----
> >  src/intel/intel_dri_resource_sharing_int.h | 143 --------------
> >  src/intel/intel_driver.c                   | 132 +++++++++----
> >  src/x11/mesa_egl_extension.c               | 306 -----------------------------
> >  src/x11/mesa_egl_extension.h               |  20 --
> >  src/x11/mesa_egl_res_share.c               | 135 -------------
> >  src/x11/mesa_egl_res_share.h               |  44 -----
> >  utests/CMakeLists.txt                      |   2 +-
> >  utests/compiler_fill_gl_image.cpp          |  69 ++++---
> >  utests/utest_helper.hpp                    |   7 +-
> >  20 files changed, 174 insertions(+), 1067 deletions(-)
> >  delete mode 100644 CMake/FindMesaSrc.cmake
> >  create mode 100644 src/intel/intel_cl_gl_share_image_info.h
> >  delete mode 100644 src/intel/intel_dri_resource_sharing.c
> >  delete mode 100644 src/intel/intel_dri_resource_sharing.h
> >  delete mode 100644 src/intel/intel_dri_resource_sharing_int.h
> >  delete mode 100644 src/x11/mesa_egl_extension.c
> >  delete mode 100644 src/x11/mesa_egl_extension.h
> >  delete mode 100644 src/x11/mesa_egl_res_share.c
> >  delete mode 100644 src/x11/mesa_egl_res_share.h
> >
> > diff --git a/CMake/FindMesaSrc.cmake b/CMake/FindMesaSrc.cmake
> > deleted file mode 100644
> > index 978cb4e..0000000
> > --- a/CMake/FindMesaSrc.cmake
> > +++ /dev/null
> > @@ -1,26 +0,0 @@
> > -#
> > -# Try to find mesa source code
> > -# Once done this will define
> > -#
> > -# MESA_SOURCE_FOUND
> > -# MESA_SOURCE_INCLUDES
> > -#
> > -
> > -# Find mesa source code.
> > -FIND_PATH(MESA_SOURCE_PREFIX src/mesa/main/texobj.c
> > -  $ENV{MESA_SOURCE_DIR}
> > -  ${MAKE_CURRENT_SOURCE_DIR}/../mesa
> > -  ~/mesa
> > -  DOC "The mesa source directory which is needed for cl_khr_gl_sharing.")
> > -
> > -IF(MESA_SOURCE_PREFIX)
> > -SET(MESA_SOURCE_INCLUDES ${MESA_SOURCE_PREFIX}/src/mesa
> > -                         ${MESA_SOURCE_PREFIX}/include
> > -                         ${MESA_SOURCE_PREFIX}/src/mapi
> > -                         ${MESA_SOURCE_PREFIX}/src/mesa/drivers/dri/i965/
> > -                         ${MESA_SOURCE_PREFIX}/src/mesa/drivers/dri/i915/
> > -                         ${MESA_SOURCE_PREFIX}/src/mesa/drivers/dri/common/)
> > -SET(MESA_SOURCE_FOUND 1 CACHE STRING "Set to 1 if mesa source
> code
> > is found, 0 otherwise")
> > -ELSE(MESA_SOURCE_PREFIX)
> > -SET(MESA_SOURCE_FOUND 0 CACHE STRING "Set to 1 if mesa source
> code
> > is found, 0 otherwise")
> > -ENDIF(MESA_SOURCE_PREFIX)
> > diff --git a/CMakeLists.txt b/CMakeLists.txt
> > index f0b45ef..472c922 100644
> > --- a/CMakeLists.txt
> > +++ b/CMakeLists.txt
> > @@ -214,14 +214,6 @@ ELSE(EGL_FOUND)
> >    MESSAGE(STATUS "Looking for EGL - not found")
> >  ENDIF(EGL_FOUND)
> >
> > -# cl_khr_gl_sharing requires to build with mesa source
> > -#Find_Package(MesaSrc)
> > -#IF(MESA_SOURCE_FOUND)
> > -#  MESSAGE(STATUS "Looking for mesa source code - found at
> > ${MESA_SOURCE_PREFIX}")
> > -#ELSE(MESA_SOURCE_FOUND)
> > -#  MESSAGE(STATUS "Looking for mesa source code - not found,
> > cl_khr_gl_sharing will be disabled.")
> > -#ENDIF(MESA_SOURCE_FOUND)
> > -
> >  Find_Package(OCLIcd)
> >  IF(OCLIcd_FOUND)
> >    MESSAGE(STATUS "Looking for OCL ICD header file - found")
> > diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
> > index a002865..bf1e9ae 100644
> > --- a/src/CMakeLists.txt
> > +++ b/src/CMakeLists.txt
> > @@ -3,7 +3,6 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}
> >                      ${DRM_INCLUDE_DIRS}/../
> >                      ${CMAKE_CURRENT_SOURCE_DIR}/../backend/src/backend/
> >                      ${CMAKE_CURRENT_SOURCE_DIR}/../include
> > -                    ${MESA_SOURCE_INCLUDES}
> >                      ${LLVM_INCLUDE_DIR})
> >
> >  macro (MakeKernelBinStr KERNEL_PATH KERNEL_FILES)
> > @@ -108,14 +107,14 @@ if (CMRT_FOUND)
> >    set(OPENCL_SRC ${OPENCL_SRC} cl_cmrt.cpp)
> >  endif (CMRT_FOUND)
> >
> > -if (EGL_FOUND AND MESA_SOURCE_FOUND)
> > -  set (OPENCL_SRC ${OPENCL_SRC} cl_mem_gl.c cl_gl_api.c
> > x11/mesa_egl_extension.c x11/mesa_egl_res_share.c
> > intel/intel_dri_resource_sharing.c)
> > +if (EGL_FOUND)
> > +  set (OPENCL_SRC ${OPENCL_SRC} cl_mem_gl.c cl_gl_api.c )
> >    SET(CMAKE_CXX_FLAGS "-DHAS_EGL ${CMAKE_CXX_FLAGS}")
> >    SET(CMAKE_C_FLAGS "-DHAS_EGL ${CMAKE_C_FLAGS}")
> > -  SET(OPTIONAL_EGL_LIBRARY "${EGL_LIBRARY}")
> > -else(EGL_FOUND AND MESA_SOURCE_FOUND)
> > +  SET(OPTIONAL_EGL_LIBRARY "${EGL_LIBRARIES}")
> > +else(EGL_FOUND)
> >    SET(OPTIONAL_EGL_LIBRARY "")
> > -endif (EGL_FOUND AND MESA_SOURCE_FOUND)
> > +endif (EGL_FOUND)
> >
> >  if (OCLIcd_FOUND)
> >    set (OPENCL_SRC ${OPENCL_SRC} cl_khr_icd.c)
> > diff --git a/src/cl_driver.h b/src/cl_driver.h
> > index 16730db..1a9b607 100644
> > --- a/src/cl_driver.h
> > +++ b/src/cl_driver.h
> > @@ -347,7 +347,7 @@ typedef cl_buffer
> > (cl_buffer_alloc_from_texture_cb)(cl_context, unsigned int, in
> >                                                      struct _cl_mem_image *gl_image);
> >  extern cl_buffer_alloc_from_texture_cb *cl_buffer_alloc_from_texture;
> >
> > -typedef void (cl_buffer_release_from_texture_cb)(cl_context, unsigned
> int,
> > int, unsigned int);
> > +typedef void (cl_buffer_release_from_texture_cb)(cl_context, struct
> > _cl_mem_gl_image *);
> >  extern cl_buffer_release_from_texture_cb
> > *cl_buffer_release_from_texture;
> >
> >  typedef cl_buffer (cl_buffer_get_buffer_from_libva_cb)(cl_context ctx,
> > unsigned int bo_name, size_t *sz);
> > @@ -432,35 +432,5 @@ extern cl_driver_get_device_id_cb
> > *cl_driver_get_device_id;
> >  typedef void (cl_driver_update_device_info_cb)(cl_device_id device);
> >  extern cl_driver_update_device_info_cb *cl_driver_update_device_info;
> >
> > -
> >
> /**********************************************************
> > ****************
> > - * cl_khr_gl_sharing.
> > -
> >
> **********************************************************
> > ****************/
> > -typedef int (cl_gl_acquire_texture_cb)(void *driver, void *ctx, int target,
> > -                                       int level, int texture, void*user_data);
> > -extern cl_gl_acquire_texture_cb *cl_gl_acquire_texture;
> > -
> > -typedef int (cl_gl_release_texture_cb)(void *driver, void *ctx, int target,
> > -                                       int level, int texture);
> > -extern cl_gl_release_texture_cb *cl_gl_release_texture;
> > -
> > -typedef int (cl_gl_acquire_buffer_object_cb)(void *driver, void *ctx,
> > -                                             int bufobj, void* user_data);
> > -extern cl_gl_acquire_buffer_object_cb *cl_gl_acquire_buffer_object;
> > -
> > -typedef int (cl_gl_release_buffer_object_cb)(void *driver, void *ctx, int
> > bufobj);
> > -extern cl_gl_release_buffer_object_cb *cl_gl_release_buffer_object;
> > -
> > -typedef int (cl_gl_acquire_render_buffer_cb)(void *driver, void *ctx,
> > -                                             int rb, void* user_data);
> > -extern cl_gl_acquire_render_buffer_cb *cl_gl_acquire_render_buffer;
> > -
> > -typedef int (cl_gl_release_render_buffer_cb)(void *driver, void *ctx, int
> rb);
> > -extern cl_gl_release_render_buffer_cb *cl_gl_release_render_buffer;
> > -
> > -#ifndef DEFAULT_DRIVER_DIR
> > -/* this is normally defined in Mesa/configs/default with
> > DRI_DRIVER_SEARCH_PATH */
> > -#define DEFAULT_DRIVER_DIR "/usr/local/lib/dri"
> > -#endif
> > -
> >  #endif /* __CL_DRIVER_H__ */
> >
> > diff --git a/src/cl_driver_defs.c b/src/cl_driver_defs.c
> > index 31176a4..a4a137d 100644
> > --- a/src/cl_driver_defs.c
> > +++ b/src/cl_driver_defs.c
> > @@ -56,13 +56,6 @@ LOCAL cl_buffer_get_tiling_align_cb
> > *cl_buffer_get_tiling_align = NULL;
> >  LOCAL cl_buffer_get_buffer_from_fd_cb *cl_buffer_get_buffer_from_fd
> =
> > NULL;
> >  LOCAL cl_buffer_get_image_from_fd_cb *cl_buffer_get_image_from_fd
> =
> > NULL;
> >
> > -/* cl_khr_gl_sharing */
> > -LOCAL cl_gl_acquire_texture_cb *cl_gl_acquire_texture = NULL;
> > -LOCAL cl_gl_release_texture_cb *cl_gl_release_texture = NULL;
> > -LOCAL cl_gl_acquire_buffer_object_cb *cl_gl_acquire_buffer_object =
> > NULL;
> > -LOCAL cl_gl_release_buffer_object_cb *cl_gl_release_buffer_object =
> > NULL;
> > -LOCAL cl_gl_acquire_render_buffer_cb *cl_gl_acquire_render_buffer =
> > NULL;
> > -LOCAL cl_gl_release_render_buffer_cb *cl_gl_release_render_buffer =
> > NULL;
> >  /* GPGPU */
> >  LOCAL cl_gpgpu_new_cb *cl_gpgpu_new = NULL;
> >  LOCAL cl_gpgpu_delete_cb *cl_gpgpu_delete = NULL;
> > diff --git a/src/cl_gl_api.c b/src/cl_gl_api.c
> > index 519aab6..e89bb15 100644
> > --- a/src/cl_gl_api.c
> > +++ b/src/cl_gl_api.c
> > @@ -95,16 +95,7 @@ clCreateFromGLTexture3D(cl_context    context,
> >                          GLuint texture,
> >                          cl_int *      errcode_ret)
> >  {
> > -  cl_mem mem = NULL;
> > -  cl_int err = CL_SUCCESS;
> > -  CHECK_CONTEXT (context);
> > -  CHECK_GL_CONTEXT (context);
> > -
> > -  mem = cl_mem_new_gl_texture(context, flags, texture_target, miplevel,
> > texture, &err);
> > -error:
> > -  if (errcode_ret)
> > -    *errcode_ret = err;
> > -  return mem;
> > +  NOT_IMPLEMENTED;
> >  }
> >
> >  cl_mem
> > @@ -120,6 +111,12 @@ clCreateFromGLTexture(cl_context      context,
> >    CHECK_CONTEXT (context);
> >    CHECK_GL_CONTEXT (context);
> >
> > +  //We just support GL_TEXTURE_2D now.
> > +  if(target != GL_TEXTURE_2D){
> > +    err = CL_INVALID_VALUE;
> > +    goto error;
> > +  }
> > +
> >    mem = cl_mem_new_gl_texture(context, flags, target, miplevel, texture,
> > &err);
> >  error:
> >    if (errcode_ret)
> > diff --git a/src/cl_mem.h b/src/cl_mem.h
> > index c8f256d..ae85b73 100644
> > --- a/src/cl_mem.h
> > +++ b/src/cl_mem.h
> > @@ -26,6 +26,9 @@
> >  #include "cl_khr_icd.h"
> >  #include <assert.h>
> >  #include <pthread.h>
> > +#if defined(HAS_EGL)
> > +#include "EGL/egl.h"
> > +#endif
> >
> >  #ifndef CL_VERSION_1_2
> >  #define CL_MEM_OBJECT_IMAGE1D                       0x10F4
> > @@ -118,9 +121,10 @@ struct _cl_mem_image {
> >
> >  struct _cl_mem_gl_image {
> >    struct _cl_mem_image base;
> > -  uint32_t target;
> > -  int      miplevel;
> > -  uint32_t texture;
> > +  int fd;
> > +#if defined(HAS_EGL)
> > +  EGLImage egl_image;
> > +#endif
> >  };
> >
> >  struct _cl_mem_buffer1d_image {
> > diff --git a/src/cl_mem_gl.c b/src/cl_mem_gl.c
> > index b0b2c1b..fdad067 100644
> > --- a/src/cl_mem_gl.c
> > +++ b/src/cl_mem_gl.c
> > @@ -74,10 +74,6 @@ cl_mem_new_gl_texture(cl_context ctx,
> >      goto error;
> >    }
> >
> > -  cl_mem_gl_image(mem)->target = texture_target;
> > -  cl_mem_gl_image(mem)->miplevel = miplevel;
> > -  cl_mem_gl_image(mem)->texture = texture;
> > -
> >  exit:
> >    if (errcode_ret)
> >      *errcode_ret = err;
> > @@ -92,6 +88,5 @@ error:
> >  LOCAL void cl_mem_gl_delete(struct _cl_mem_gl_image *gl_image)
> >  {
> >    if (gl_image->base.base.bo != NULL)
> > -    cl_buffer_release_from_texture(gl_image->base.base.ctx, gl_image-
> > >target,
> > -                                   gl_image->miplevel, gl_image->texture);
> > +    cl_buffer_release_from_texture(gl_image->base.base.ctx, gl_image);
> >  }
> > diff --git a/src/intel/intel_cl_gl_share_image_info.h
> > b/src/intel/intel_cl_gl_share_image_info.h
> > new file mode 100644
> > index 0000000..21fbbd1
> > --- /dev/null
> > +++ b/src/intel/intel_cl_gl_share_image_info.h
> > @@ -0,0 +1,18 @@
> > +#ifndef __INTEL_CL_GL_SHARE_IMAGE_INFO_
> > +#define __INTEL_CL_GL_SHARE_IMAGE_INFO_
> > +
> > +struct _intel_cl_gl_share_image_info {
> > +  int fd;
> > +  size_t w;
> > +  size_t h;
> > +  size_t depth;
> > +  size_t pitch;
> > +  int tiling;
> > +  size_t offset;
> > +  size_t tile_x;
> > +  size_t tile_y;
> > +  unsigned int gl_format;
> > +  size_t row_pitch, slice_pitch;
> > +};
> > +
> > +#endif
> > diff --git a/src/intel/intel_dri_resource_sharing.c
> > b/src/intel/intel_dri_resource_sharing.c
> > deleted file mode 100644
> > index 188c1fa..0000000
> > --- a/src/intel/intel_dri_resource_sharing.c
> > +++ /dev/null
> > @@ -1,208 +0,0 @@
> > -
> >
> /**********************************************************
> > ****************
> > - *
> > - * 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.
> > - *
> > -
> >
> **********************************************************
> > ****************/
> > -
> > -#define HAVE_PTHREAD 1
> > -#include <errno.h>
> > -#include <time.h>
> > -#include "main/context.h"
> > -#include "main/renderbuffer.h"
> > -#include "main/texobj.h"
> > -#include <stdbool.h>
> > -#include <string.h>
> > -#include <drm.h>
> > -#include <i915_drm.h>
> > -#include <intel_bufmgr.h>
> > -#include <GL/internal/dri_interface.h>
> > -#include "intel_mipmap_tree.h"
> > -#include "intel_regions.h"
> > -#include "intel_context.h"
> > -
> > -#include "intel_dri_resource_sharing.h"
> > -#include "intel_dri_resource_sharing_int.h"
> > -
> > -#include <dlfcn.h>
> > -/**
> > - * Sets up a DRIImage structure to point to our shared image in a region
> > - */
> > -static bool
> > -intel_setup_cl_region_from_mipmap_tree(void *driver,
> > -                                       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;
> > -   region->tiling = mt->region->tiling;
> > -   /* XXX hard code to 1 right now. */
> > -   region->depth = 1;
> > -   region->row_pitch = mt->region->pitch;
> > -
> > -   region->offset = _intel_region_get_aligned_offset(mt->region,
> > -                                                     draw_x & ~mask_x,
> > -                                                     draw_y & ~mask_y,
> > -                                                     false);
> > -   if (!_intel_region_flink(mt->region, &region->name))
> > -      return false;
> > -   _intel_region_reference(&null_region, mt->region);
> > -   return true;
> > -}
> > -
> > -typedef void
> > -_mesa_test_texobj_completeness_t( const struct gl_context *ctx,
> > -                                struct gl_texture_object *t );
> > -_mesa_test_texobj_completeness_t
> *__mesa_test_texobj_completeness;
> > -
> > -typedef struct gl_texture_object *
> > -_mesa_lookup_texture_t( const struct gl_context *ctx, GLuint id);
> > -_mesa_lookup_texture_t *__mesa_lookup_texture;
> > -
> > -static struct gl_texture_object *
> > -intel_get_gl_obj_from_texture(void *driver,
> > -                              struct intel_context *intel,
> > -                              GLenum target, GLint level,
> > -                              GLuint texture, GLuint face)
> > -{
> > -   struct gl_texture_object *obj;
> > -   __mesa_lookup_texture = dlsym(driver, "_mesa_lookup_texture");
> > -   obj = __mesa_lookup_texture(&intel->ctx, texture);
> > -   if (!obj || obj->Target != target) {
> > -      return NULL;
> > -   }
> > -
> > -   __mesa_test_texobj_completeness = dlsym(driver,
> > "_mesa_test_texobj_completeness");
> > -   __mesa_test_texobj_completeness(&intel->ctx, obj);
> > -   if (!obj->_BaseComplete || (level > 0 && !obj->_MipmapComplete)) {
> > -      return NULL;
> > -   }
> > -
> > -   if (level < obj->BaseLevel || level > obj->_MaxLevel) {
> > -      return NULL;
> > -   }
> > -
> > -   return obj;
> > -}
> > -
> > -static GLenum
> > -get_cl_gl_format(mesa_format format)
> > -{
> > -   switch (format) {
> > -   case MESA_FORMAT_R8G8B8A8_UNORM:
> > -      return GL_RGBA;
> > -   case MESA_FORMAT_A8R8G8B8_UNORM:
> > -      return GL_BGRA;
> > -   default:
> > -      return GL_BGRA;
> > -  }
> > -}
> > -
> > -static bool
> > -intelAcquireTexture(void *driver, __DRIcontext *context, GLenum target,
> > -                    GLint level, GLuint texture, void *user_data)
> > -{
> > -   struct _intel_dri_share_image_region *region =
> > intel_dri_share_image_region(user_data);
> > -   struct intel_context *intel = context->driverPrivate;
> > -   struct gl_texture_object *obj;
> > -   struct intel_texture_object *iobj;
> > -   /* XXX Always be face 0? */
> > -   GLuint face = 0;
> > -
> > -   obj = intel_get_gl_obj_from_texture(driver, intel, target, level, texture,
> > face);
> > -   if (obj == NULL)
> > -     return false;
> > -   iobj = intel_texture_object(obj);
> > -   region->gl_format = get_cl_gl_format(obj->Image[face][level]-
> > >TexFormat);
> > -   return intel_setup_cl_region_from_mipmap_tree(driver, intel, iobj->mt,
> > level, 0, region);
> > -}
> > -
> > -static bool
> > -intelReleaseTexture(void *driver, __DRIcontext *context, GLenum target,
> > -                    GLint level, GLuint texture)
> > -{
> > -   struct intel_context *intel = context->driverPrivate;
> > -   struct gl_texture_object *obj;
> > -   struct intel_texture_object *iobj;
> > -   /* XXX Always be face 0? */
> > -   GLuint face = 0;
> > -
> > -   obj = intel_get_gl_obj_from_texture(driver, intel, target, level, texture,
> > face);
> > -   if (obj == NULL)
> > -     return false;
> > -
> > -   iobj = intel_texture_object(obj);
> > -   _intel_region_release(&iobj->mt->region);
> > -   return true;
> > -}
> > -
> > -static bool
> > -intelAcquireBufferObj(void *driver, __DRIcontext *driContextPriv,
> > -                      GLuint bufobj, void *user_data)
> > -{
> > -  return false;
> > -}
> > -
> > -static bool
> > -intelReleaseBufferObj(void *driver, __DRIcontext *driContextPriv, GLuint
> > bufobj)
> > -{
> > -  return false;
> > -}
> > -
> > -static bool
> > -intelAcquireRenderBuffer(void *driver, __DRIcontext *driContextPriv,
> > -                         GLuint bufobj, void *user_data)
> > -{
> > -  return false;
> > -}
> > -
> > -static bool
> > -intelReleaseRenderBuffer(void *driver, __DRIcontext *driContextPriv,
> > GLuint bufobj)
> > -{
> > -  return false;
> > -}
> > -
> > -#include "cl_driver.h"
> > -void
> > -intel_set_cl_gl_callbacks(void)
> > -{
> > -  cl_gl_acquire_texture = (cl_gl_acquire_texture_cb*)intelAcquireTexture;
> > -  cl_gl_release_texture = (cl_gl_release_texture_cb*)intelReleaseTexture;
> > -  cl_gl_acquire_buffer_object =
> > (cl_gl_acquire_buffer_object_cb*)intelAcquireBufferObj;
> > -  cl_gl_release_buffer_object =
> > (cl_gl_release_buffer_object_cb*)intelReleaseBufferObj;
> > -  cl_gl_acquire_render_buffer =
> > (cl_gl_acquire_render_buffer_cb*)intelAcquireRenderBuffer;
> > -  cl_gl_release_render_buffer =
> > (cl_gl_release_render_buffer_cb*)intelReleaseRenderBuffer;
> > -}
> > diff --git a/src/intel/intel_dri_resource_sharing.h
> > b/src/intel/intel_dri_resource_sharing.h
> > deleted file mode 100644
> > index 6d2ce4d..0000000
> > --- a/src/intel/intel_dri_resource_sharing.h
> > +++ /dev/null
> > @@ -1,39 +0,0 @@
> > -#ifndef __INTEL_DRI_RESOURCE_SHARING_H__
> > -#define __INTEL_DRI_RESOURCE_SHARING_H__
> > -
> > -struct _intel_dri_share_image_region {
> > -  unsigned int name;
> > -  size_t w;
> > -  size_t h;
> > -  size_t depth;
> > -  size_t pitch;
> > -  int tiling;
> > -  size_t offset;
> > -  size_t tile_x;
> > -  size_t tile_y;
> > -  unsigned int gl_format;
> > -  size_t row_pitch, slice_pitch;
> > -};
> > -
> > -struct _intel_dri_share_buffer_object {
> > -  unsigned int name;
> > -  size_t sz;
> > -  size_t offset;
> > -};
> > -
> > -inline static struct _intel_dri_share_image_region *
> > -intel_dri_share_image_region(void *user_data)
> > -{
> > -   return (struct _intel_dri_share_image_region *)user_data;
> > -}
> > -
> > -inline static struct _intel_dri_share_buffer_object *
> > -intel_dri_share_buffer_object(void *user_data)
> > -{
> > -   return (struct _intel_dri_share_buffer_object *)user_data;
> > -}
> > -
> > -extern void intel_set_cl_gl_callbacks(void);
> > -
> > -
> > -#endif
> > diff --git a/src/intel/intel_dri_resource_sharing_int.h
> > b/src/intel/intel_dri_resource_sharing_int.h
> > deleted file mode 100644
> > index c7b283a..0000000
> > --- a/src/intel/intel_dri_resource_sharing_int.h
> > +++ /dev/null
> > @@ -1,143 +0,0 @@
> > -
> >
> /**********************************************************
> > *******
> > - * The following functions are copied from i965 driver, commit
> > - * id 292368570a13501dfa95b1b0dd70966caf6ffc6b. Need to keep
> consistant
> > - * with the dri driver installed on current system.
> > -
> >
> **********************************************************
> > *******/
> > -static bool
> > -_intel_region_flink(struct intel_region *region, uint32_t *name)
> > -{
> > -   if (region->name == 0) {
> > -      if (drm_intel_bo_flink(region->bo, &region->name))
> > -         return false;
> > -   }
> > -
> > -   *name = region->name;
> > -
> > -   return true;
> > -}
> > -
> > -#define _DBG(...)
> > -static void
> > -_intel_region_release(struct intel_region **region_handle)
> > -{
> > -   struct intel_region *region = *region_handle;
> > -
> > -   if (region == NULL) {
> > -      _DBG("%s NULL\n", __FUNCTION__);
> > -      return;
> > -   }
> > -
> > -   _DBG("%s %p %d\n", __FUNCTION__, region, region->refcount - 1);
> > -
> > -   ASSERT(region->refcount > 0);
> > -   region->refcount--;
> > -
> > -   if (region->refcount == 0) {
> > -      drm_intel_bo_unreference(region->bo);
> > -
> > -      free(region);
> > -   }
> > -   *region_handle = NULL;
> > -}
> > -
> > -static void
> > -_intel_region_reference(struct intel_region **dst, struct intel_region *src)
> > -{
> > -   _DBG("%s: %p(%d) -> %p(%d)\n", __FUNCTION__,
> > -        *dst, *dst ? (*dst)->refcount : 0, src, src ? src->refcount : 0);
> > -
> > -   if (src != *dst) {
> > -      if (*dst)
> > -         _intel_region_release(dst);
> > -
> > -      if (src)
> > -         src->refcount++;
> > -      *dst = src;
> > -   }
> > -}
> > -
> > -/**
> > - * This function computes masks that may be used to select the bits of the
> X
> > - * and Y coordinates that indicate the offset within a tile.  If the region is
> > - * untiled, the masks are set to 0.
> > - */
> > -static void
> > -_intel_region_get_tile_masks(struct intel_region *region,
> > -                             uint32_t *mask_x, uint32_t *mask_y,
> > -                             bool map_stencil_as_y_tiled)
> > -{
> > -   int cpp = region->cpp;
> > -   uint32_t tiling = region->tiling;
> > -
> > -   if (map_stencil_as_y_tiled)
> > -      tiling = I915_TILING_Y;
> > -
> > -   switch (tiling) {
> > -   default:
> > -      assert(false);
> > -   case I915_TILING_NONE:
> > -      *mask_x = *mask_y = 0;
> > -      break;
> > -   case I915_TILING_X:
> > -      *mask_x = 512 / cpp - 1;
> > -      *mask_y = 7;
> > -      break;
> > -   case I915_TILING_Y:
> > -      *mask_x = 128 / cpp - 1;
> > -      *mask_y = 31;
> > -      break;
> > -   }
> > -}
> > -
> > -/**
> > - * Compute the offset (in bytes) from the start of the region to the given x
> > - * and y coordinate.  For tiled regions, caller must ensure that x and y are
> > - * multiples of the tile size.
> > - */
> > -static uint32_t
> > -_intel_region_get_aligned_offset(struct intel_region *region, uint32_t x,
> > -                                 uint32_t y, bool map_stencil_as_y_tiled)
> > -{
> > -   int cpp = region->cpp;
> > -   uint32_t pitch = region->pitch;
> > -   uint32_t tiling = region->tiling;
> > -
> > -   if (map_stencil_as_y_tiled) {
> > -      tiling = I915_TILING_Y;
> > -
> > -      /* When mapping a W-tiled stencil buffer as Y-tiled, each 64-high W-tile
> > -       * gets transformed into a 32-high Y-tile.  Accordingly, the pitch of
> > -       * the resulting region is twice the pitch of the original region, since
> > -       * each row in the Y-tiled view corresponds to two rows in the actual
> > -       * W-tiled surface.  So we need to correct the pitch before computing
> > -       * the offsets.
> > -       */
> > -      pitch *= 2;
> > -   }
> > -
> > -   switch (tiling) {
> > -   default:
> > -      assert(false);
> > -   case I915_TILING_NONE:
> > -      return y * pitch + x * cpp;
> > -   case I915_TILING_X:
> > -      assert((x % (512 / cpp)) == 0);
> > -      assert((y % 8) == 0);
> > -      return y * pitch + x / (512 / cpp) * 4096;
> > -   case I915_TILING_Y:
> > -      assert((x % (128 / cpp)) == 0);
> > -      assert((y % 32) == 0);
> > -      return y * pitch + x / (128 / cpp) * 4096;
> > -   }
> > -}
> > -
> > -static void
> > -_intel_miptree_get_image_offset(struct intel_mipmap_tree *mt,
> > -                                GLuint level, GLuint slice,
> > -                                GLuint *x, GLuint *y)
> > -{
> > -   assert(slice < mt->level[level].depth);
> > -
> > -   *x = mt->level[level].slice[slice].x_offset;
> > -   *y = mt->level[level].slice[slice].y_offset;
> > -}
> > diff --git a/src/intel/intel_driver.c b/src/intel/intel_driver.c
> > index e561725..6d3337a 100644
> > --- a/src/intel/intel_driver.c
> > +++ b/src/intel/intel_driver.c
> > @@ -47,9 +47,10 @@
> >   */
> >
> >  #if defined(HAS_EGL)
> > +#define EGL_EGLEXT_PROTOTYPES
> >  #include "GL/gl.h"
> >  #include "EGL/egl.h"
> > -#include "x11/mesa_egl_extension.h"
> > +#include <EGL/eglext.h>
> >  #endif
> >
> >  #ifdef HAS_X11
> > @@ -537,8 +538,25 @@ static uint32_t
> > intel_buffer_get_tiling_align(cl_context ctx, uint32_t tiling_mo
> >  }
> >
> >  #if defined(HAS_EGL)
> > -#include "intel_dri_resource_sharing.h"
> > +#include "intel_cl_gl_share_image_info.h"
> >  #include "cl_image.h"
> > +
> > +static PFNEGLEXPORTDMABUFIMAGEMESAPROC
> > eglExportDMABUFImageMESA_func = NULL;
> > +
> > +static int
> > +get_required_egl_extensions(){
> > +
> > +  if(eglExportDMABUFImageMESA_func == NULL){
> > +    eglExportDMABUFImageMESA_func =
> > (PFNEGLEXPORTDMABUFIMAGEMESAPROC)
> > eglGetProcAddress("eglExportDMABUFImageMESA");
> > +    if(eglExportDMABUFImageMESA_func == NULL){
> > +      fprintf(stderr, "Failed to get EGL extension function
> > eglExportDMABUFImageMESA\n");
> > +      return -1;
> > +    }
> > +  }
> > +  return 0;
> > +}
> > +
> > +
> >  static int cl_get_clformat_from_texture(GLint tex_format,
> cl_image_format
> > * cl_format)
> >  {
> >    cl_int ret = CL_SUCCESS;
> > @@ -627,29 +645,68 @@ intel_alloc_buffer_from_texture_egl(cl_context
> > ctx, unsigned int target,
> >                                      int miplevel, unsigned int texture,
> >                                      struct _cl_mem_image *image)
> >  {
> > -  cl_buffer bo = (cl_buffer) NULL;
> > -  struct _intel_dri_share_image_region region;
> > +  drm_intel_bo *intel_bo = NULL;
> > +  struct _intel_cl_gl_share_image_info info;
> >    unsigned int bpp, intel_fmt;
> >    cl_image_format cl_format;
> >    EGLBoolean ret;
> > -  EGLint attrib_list[] = { EGL_GL_TEXTURE_ID_MESA, texture,
> > -                           EGL_GL_TEXTURE_LEVEL_MESA, miplevel,
> > -                           EGL_GL_TEXTURE_TARGET_MESA, target,
> > -                           EGL_NONE};
> > -  ret = eglAcquireResourceMESA(EGL_DISP(ctx), EGL_CTX(ctx),
> > -                               EGL_GL_TEXTURE_MESA,
> > -                               &attrib_list[0], &region);
> > -  if (!ret)
> > -      goto out;
> > -
> > -  bo = (cl_buffer)intel_driver_share_buffer((intel_driver_t *)ctx->drv,
> > "rendering buffer", region.name);
> >
> > -  if (bo == NULL) {
> > -    eglReleaseResourceMESA(EGL_DISP(ctx), EGL_CTX(ctx),
> > EGL_GL_TEXTURE_MESA, &attrib_list[0]);
> > -    goto out;
> > +  EGLenum e_target;
> > +  //We just support GL_TEXTURE_2D because we can't query info like
> > slice_pitch now.
> > +  if(target == GL_TEXTURE_2D)
> > +    e_target = EGL_GL_TEXTURE_2D;
> > +  else
> > +    return NULL;
> > +
> > +  if(get_required_egl_extensions() != 0)
> > +    return NULL;
> > +
> > +  EGLAttrib attrib_list[] = {EGL_GL_TEXTURE_LEVEL, miplevel,
> > +                            EGL_NONE};
> > +  EGLImage e_image = eglCreateImage(EGL_DISP(ctx), EGL_CTX(ctx),
> > e_target,
> > +                                    (EGLClientBuffer)texture, &attrib_list[0]);
> > +  if(e_image == EGL_NO_IMAGE)
> > +    return NULL;
> > +
> > +  int fd, stride, offset;
> > +  ret = eglExportDMABUFImageMESA_func(EGL_DISP(ctx), e_image, &fd,
> > &stride, &offset);
> > +  if(ret != EGL_TRUE){
> > +    eglDestroyImage(EGL_DISP(ctx), e_image);
> > +    return NULL;
> > +  }
> > +  info.fd = fd;
> > +
> > +  /* The size argument just takes effect in
> > intel_driver_share_buffer_from_fd when
> > +   * Linux kernel is older than 3.12, so it doesn't matter we set to 0 here.
> > +   */
> > +  int size = 0;
> > +  intel_bo = intel_driver_share_buffer_from_fd((intel_driver_t *)ctx->drv,
> > fd, size);
> > +
> > +  if (intel_bo == NULL) {
> > +    eglDestroyImage(EGL_DISP(ctx), e_image);
> > +    return NULL;
> >    }
> > -  region.tiling = get_cl_tiling(region.tiling);
> > -  if (cl_get_clformat_from_texture(region.gl_format, &cl_format) != 0)
> > +
> > +  GLint param_value;
> > +  glGetTexLevelParameteriv(target, miplevel, GL_TEXTURE_WIDTH,
> > &param_value);
> > +  info.w = param_value;
> > +  glGetTexLevelParameteriv(target, miplevel, GL_TEXTURE_HEIGHT,
> > &param_value);
> > +  info.h = param_value;
> > +  glGetTexLevelParameteriv(target, miplevel, GL_TEXTURE_DEPTH,
> > &param_value);
> > +  info.depth = 1;
> > +  info.pitch = stride;
> > +  uint32_t tiling_mode, swizzle_mode;
> > +  drm_intel_bo_get_tiling(intel_bo, &tiling_mode, &swizzle_mode);
> > +  info.offset = offset;
> > +  info.tile_x = 0;
> > +  info.tile_y = 0;
> > +  glGetTexLevelParameteriv(target, miplevel,
> > GL_TEXTURE_INTERNAL_FORMAT, &param_value);
> > +  info.gl_format = param_value;
> > +  info.row_pitch = stride;
> > +  info.slice_pitch = 0;
> > +
> > +  info.tiling = get_cl_tiling(tiling_mode);
> > +  if (cl_get_clformat_from_texture(info.gl_format, &cl_format) != 0)
> >      goto error;
> >
> >    if (cl_image_byte_per_pixel(&cl_format, &bpp) != CL_SUCCESS)
> > @@ -661,17 +718,22 @@ intel_alloc_buffer_from_texture_egl(cl_context
> > ctx, unsigned int target,
> >    if (get_mem_type_from_target(target, &image_type) != 0)
> >      goto error;
> >
> > -  cl_mem_image_init(image, region.w, region.h,
> > -                    image_type, region.depth, cl_format,
> > -                    intel_fmt, bpp, region.row_pitch,
> > -                    region.slice_pitch, region.tiling,
> > -                    region.tile_x, region.tile_y, region.offset);
> > -out:
> > -  return bo;
> > +  cl_mem_image_init(image, info.w, info.h,
> > +                    image_type, info.depth, cl_format,
> > +                    intel_fmt, bpp, info.row_pitch,
> > +                    info.slice_pitch, info.tiling,
> > +                    info.tile_x, info.tile_y, info.offset);
> > +
> > +  struct _cl_mem_gl_image *gl_image = (struct
> _cl_mem_gl_image*)image;
> > +  gl_image->fd = fd;
> > +  gl_image->egl_image = e_image;
> > +
> > +  return (cl_buffer) intel_bo;
> >
> >  error:
> > -  cl_buffer_unreference(bo);
> > -  eglReleaseResourceMESA(EGL_DISP(ctx), EGL_CTX(ctx),
> > EGL_GL_TEXTURE_MESA, &attrib_list[0]);
> > +  drm_intel_bo_unreference(intel_bo);
> > +  close(fd);
> > +  eglDestroyImage(EGL_DISP(ctx), e_image);
> >    return NULL;
> >  }
> >
> > @@ -688,16 +750,11 @@ intel_alloc_buffer_from_texture(cl_context ctx,
> > unsigned int target,
> >  }
> >
> >  static int
> > -intel_release_buffer_from_texture(cl_context ctx, unsigned int target,
> > -                                  int miplevel, unsigned int texture)
> > +intel_release_buffer_from_texture(cl_context ctx, struct
> > _cl_mem_gl_image *gl_image)
> >  {
> >    if (IS_EGL_CONTEXT(ctx)) {
> > -    EGLint attrib_list[] = { EGL_GL_TEXTURE_ID_MESA, texture,
> > -                           EGL_GL_TEXTURE_LEVEL_MESA, miplevel,
> > -                           EGL_GL_TEXTURE_TARGET_MESA, target,
> > -                           EGL_NONE};
> > -
> > -    eglReleaseResourceMESA(EGL_DISP(ctx), EGL_CTX(ctx),
> > EGL_GL_TEXTURE_MESA, &attrib_list[0]);
> > +    close(gl_image->fd);
> > +    eglDestroyImage(EGL_DISP(ctx), gl_image->egl_image);
> >      return CL_SUCCESS;
> >    }
> >    return -1;
> > @@ -931,7 +988,6 @@ intel_setup_callbacks(void)
> >  #if defined(HAS_EGL)
> >    cl_buffer_alloc_from_texture = (cl_buffer_alloc_from_texture_cb *)
> > intel_alloc_buffer_from_texture;
> >    cl_buffer_release_from_texture = (cl_buffer_release_from_texture_cb
> *)
> > intel_release_buffer_from_texture;
> > -  intel_set_cl_gl_callbacks();
> >  #endif
> >    cl_buffer_get_buffer_from_libva =
> (cl_buffer_get_buffer_from_libva_cb
> > *) intel_share_buffer_from_libva;
> >    cl_buffer_get_image_from_libva = (cl_buffer_get_image_from_libva_cb
> *)
> > intel_share_image_from_libva;
> > diff --git a/src/x11/mesa_egl_extension.c b/src/x11/mesa_egl_extension.c
> > deleted file mode 100644
> > index 4a3e89c..0000000
> > --- a/src/x11/mesa_egl_extension.c
> > +++ /dev/null
> > @@ -1,306 +0,0 @@
> > -#include <stdio.h>
> > -#include "mesa_egl_extension.h"
> > -#include "mesa_egl_res_share.h"
> > -#include "src/cl_driver.h"
> > -
> > -struct _egl_display;
> > -struct _egl_resource;
> > -struct _egl_thread_info;
> > -struct _egl_config;
> > -struct _egl_surface;
> > -struct _egl_driver;
> > -
> > -typedef struct _egl_display _EGLDisplay;
> > -typedef struct _egl_resource _EGLResource;
> > -typedef struct _egl_thread_info _EGLThreadInfo;
> > -typedef struct _egl_config _EGLConfig;
> > -typedef struct _egl_surface _EGLSurface;
> > -typedef struct _egl_driver _EGLDriver;
> > -
> > -/**
> > - * A resource of a display.
> > - */
> > -struct _egl_resource
> > -{
> > -   /* which display the resource belongs to */
> > -   _EGLDisplay *Display;
> > -   EGLBoolean IsLinked;
> > -   EGLint RefCount;
> > -
> > -   /* used to link resources of the same type */
> > -   _EGLResource *Next;
> > -};
> > -
> > -/**
> > - * "Base" class for device driver contexts.
> > - */
> > -struct _egl_context
> > -{
> > -   /* A context is a display resource */
> > -   _EGLResource Resource;
> > -
> > -   /* The bound status of the context */
> > -   _EGLThreadInfo *Binding;
> > -   _EGLSurface *DrawSurface;
> > -   _EGLSurface *ReadSurface;
> > -
> > -   _EGLConfig *Config;
> > -
> > -   EGLint ClientAPI; /**< EGL_OPENGL_ES_API, EGL_OPENGL_API,
> > EGL_OPENVG_API */
> > -   EGLint ClientMajorVersion;
> > -   EGLint ClientMinorVersion;
> > -   EGLint Flags;
> > -   EGLint Profile;
> > -   EGLint ResetNotificationStrategy;
> > -
> > -   /* The real render buffer when a window surface is bound */
> > -   EGLint WindowRenderBuffer;
> > -};
> > -
> > -typedef struct _egl_context _EGLContext;
> > -
> > -struct dri2_egl_display
> > -{
> > -   int                       dri2_major;
> > -   int                       dri2_minor;
> > -   __DRIscreen              *dri_screen;
> > -   int                       own_dri_screen;
> > -   const __DRIconfig       **driver_configs;
> > -   void                     *driver;
> > -};
> > -
> > -enum _egl_platform_type {
> > -   _EGL_PLATFORM_WINDOWS,
> > -   _EGL_PLATFORM_X11,
> > -   _EGL_PLATFORM_WAYLAND,
> > -   _EGL_PLATFORM_DRM,
> > -   _EGL_PLATFORM_FBDEV,
> > -   _EGL_PLATFORM_NULL,
> > -   _EGL_PLATFORM_ANDROID,
> > -
> > -   _EGL_NUM_PLATFORMS,
> > -   _EGL_INVALID_PLATFORM = -1
> > -};
> > -typedef enum _egl_platform_type _EGLPlatformType;
> > -
> > -typedef pthread_mutex_t _EGLMutex;
> > -
> > -struct _egl_display
> > -{
> > -   /* used to link displays */
> > -   _EGLDisplay *Next;
> > -
> > -   _EGLMutex Mutex;
> > -
> > -   _EGLPlatformType Platform; /**< The type of the platform display */
> > -   void *PlatformDisplay;     /**< A pointer to the platform display */
> > -
> > -   _EGLDriver *Driver;        /**< Matched driver of the display */
> > -   EGLBoolean Initialized;    /**< True if the display is initialized */
> > -
> > -   /* options that affect how the driver initializes the display */
> > -   struct {
> > -      EGLBoolean TestOnly;    /**< Driver should not set fields when true */
> > -      EGLBoolean UseFallback; /**< Use fallback driver (sw or less features)
> */
> > -   } Options;
> > -
> > -   /* these fields are set by the driver during init */
> > -   void *DriverData;          /**< Driver private data */
> > -};
> > -
> > -static struct dri2_egl_display *
> > -dri2_egl_display(_EGLDisplay *dpy)
> > -{
> > -  return (struct dri2_egl_display *)dpy->DriverData;
> > -}
> > -
> > -static _EGLDisplay *
> > -_eglLockDisplay(EGLDisplay dpy)
> > -{
> > -  return (_EGLDisplay *)dpy;
> > -}
> > -
> > -static _EGLContext *
> > -_eglLookupContext(EGLContext ctx, EGLDisplay disp)
> > -{
> > -  return (_EGLContext *) ctx;
> > -}
> > -
> > -struct dri2_egl_context
> > -{
> > -   _EGLContext   base;
> > -   __DRIcontext *dri_context;
> > -};
> > -
> > -static struct dri2_egl_context *
> > -dri2_egl_context(_EGLContext *ctx)
> > -{
> > -  return (struct dri2_egl_context *)ctx;
> > -}
> > -
> > -static EGLBoolean
> > -dri2_acquire_texture(_EGLDisplay *disp,
> > -                     _EGLContext *ctx,
> > -                     const EGLint *attr_list,
> > -                     void *user_data)
> > -{
> > -   struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx);
> > -   struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
> > -   GLuint texture = 0;
> > -   GLenum gl_target = 0;
> > -   GLint level = 0;
> > -   GLboolean ret;
> > -
> > -   if (_eglParseTextureAttribList(&texture, &gl_target, &level, attr_list) !=
> > EGL_SUCCESS)
> > -      return EGL_FALSE;
> > -
> > -   ret = cl_gl_acquire_texture(dri2_dpy->driver,
> > -                               dri2_ctx->dri_context,
> > -                               gl_target, level, texture,
> > -                               user_data);
> > -   return ret;
> > -}
> > -
> > -static EGLBoolean
> > -dri2_release_texture(_EGLDisplay *disp, _EGLContext *ctx, const EGLint
> > *attr_list)
> > -{
> > -   struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx);
> > -   struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
> > -   GLuint texture = 0;
> > -   GLenum gl_target = 0;
> > -   GLint level = 0;
> > -   GLboolean ret;
> > -
> > -   if (_eglParseTextureAttribList(&texture, &gl_target, &level, attr_list) !=
> > EGL_SUCCESS)
> > -      return EGL_FALSE;
> > -
> > -   ret = cl_gl_release_texture(dri2_dpy->driver, dri2_ctx->dri_context,
> > -                               gl_target, level, texture);
> > -   return ret;
> > -}
> > -
> > -static EGLBoolean
> > -dri2_acquire_buffer_object(_EGLDisplay *disp, _EGLContext *ctx, const
> > EGLint *attr_list,
> > -                           void *user_data)
> > -{
> > -   struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx);
> > -   struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
> > -   GLuint bufobj = 0;
> > -   GLboolean ret;
> > -
> > -   if (_eglParseBufferObjAttribList(&bufobj, attr_list) != EGL_SUCCESS)
> > -      return EGL_FALSE;
> > -
> > -   ret = cl_gl_acquire_buffer_object(dri2_dpy->driver,
> > -                                     dri2_ctx->dri_context,
> > -                                     bufobj, user_data);
> > -   return ret;
> > -}
> > -
> > -static EGLBoolean
> > -dri2_release_buffer_object(_EGLDisplay *disp, _EGLContext *ctx, const
> > EGLint *attr_list)
> > -{
> > -   struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx);
> > -   struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
> > -   GLuint bufobj = 0;
> > -   GLboolean ret;
> > -
> > -   if (_eglParseBufferObjAttribList(&bufobj, attr_list) != EGL_SUCCESS)
> > -      return EGL_FALSE;
> > -
> > -   ret = cl_gl_release_buffer_object(dri2_dpy->driver,
> > -                                     dri2_ctx->dri_context,
> > -                                     bufobj);
> > -   return ret;
> > -}
> > -
> > -static EGLBoolean
> > -dri2_acquire_render_buffer(_EGLDisplay *disp,
> > -                           _EGLContext *ctx,
> > -                           const EGLint *attr_list,
> > -                           void *user_data)
> > -{
> > -   struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx);
> > -   struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
> > -   GLuint rb = 0;
> > -   GLboolean ret;
> > -
> > -   if (_eglParseBufferObjAttribList(&rb, attr_list) != EGL_SUCCESS)
> > -      return EGL_FALSE;
> > -
> > -   ret = cl_gl_acquire_render_buffer(dri2_dpy->driver,
> > -                                     dri2_ctx->dri_context,
> > -                                     rb, user_data);
> > -   return ret;
> > -}
> > -
> > -static EGLBoolean
> > -dri2_release_render_buffer(_EGLDisplay *disp, _EGLContext *ctx, const
> > EGLint *attr_list)
> > -{
> > -   struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx);
> > -   struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
> > -   GLuint rb = 0;
> > -   GLboolean ret;
> > -
> > -   if (_eglParseBufferObjAttribList(&rb, attr_list) != EGL_SUCCESS)
> > -      return EGL_FALSE;
> > -
> > -   ret = cl_gl_release_render_buffer(dri2_dpy->driver,
> > -                                     dri2_ctx->dri_context,
> > -                                     rb);
> > -   return ret;
> > -}
> > -
> > -static EGLBoolean
> > -dri2_acquire_resource_mesa(_EGLDisplay *disp, _EGLContext *ctx, const
> > EGLenum target,
> > -                           const EGLint *attrib_list, void *user_data)
> > -{
> > -   switch (target) {
> > -   case EGL_GL_TEXTURE_MESA:
> > -     return dri2_acquire_texture(disp, ctx, attrib_list, user_data);
> > -   case EGL_GL_BUFFER_OBJECT_MESA:
> > -     return dri2_acquire_buffer_object(disp, ctx, attrib_list, user_data);
> > -   case EGL_GL_RENDER_BUFFER_MESA:
> > -     return dri2_acquire_render_buffer(disp, ctx, attrib_list, user_data);
> > -   default:
> > -      fprintf(stderr, "bad resource target value 0x%04x",
> > -              target);
> > -   }
> > -   return EGL_FALSE;
> > -}
> > -
> > -static EGLBoolean
> > -dri2_release_resource_mesa(_EGLDisplay *disp, _EGLContext *ctx, const
> > EGLenum target,
> > -                           const EGLint *attrib_list)
> > -{
> > -   switch (target) {
> > -   case EGL_GL_TEXTURE_MESA:
> > -     return dri2_release_texture(disp, ctx, attrib_list);
> > -   case EGL_GL_BUFFER_OBJECT_MESA:
> > -     return dri2_release_buffer_object(disp, ctx, attrib_list);
> > -   case EGL_GL_RENDER_BUFFER_MESA:
> > -     return dri2_release_render_buffer(disp, ctx, attrib_list);
> > -   default:
> > -      fprintf(stderr, "bad resource target value 0x%04x",
> > -              target);
> > -   }
> > -   return EGL_FALSE;
> > -}
> > -
> > -EGLBoolean
> > -eglAcquireResourceMESA(EGLDisplay dpy, EGLContext ctx, EGLenum
> target,
> > const EGLint *attrib_list, void *user)
> > -{
> > -   _EGLDisplay *disp = _eglLockDisplay(dpy);
> > -   _EGLContext *context = _eglLookupContext(ctx, disp);
> > -
> > -   return dri2_acquire_resource_mesa(disp, context, target, attrib_list,
> user);
> > -}
> > -
> > -EGLBoolean
> > -eglReleaseResourceMESA(EGLDisplay dpy, EGLContext ctx, EGLenum
> target,
> > const EGLint *attrib_list)
> > -{
> > -   _EGLDisplay *disp = _eglLockDisplay(dpy);
> > -   _EGLContext *context = _eglLookupContext(ctx, disp);
> > -
> > -   return dri2_release_resource_mesa(disp, context, target, attrib_list);
> > -}
> > diff --git a/src/x11/mesa_egl_extension.h
> b/src/x11/mesa_egl_extension.h
> > deleted file mode 100644
> > index 39ea134..0000000
> > --- a/src/x11/mesa_egl_extension.h
> > +++ /dev/null
> > @@ -1,20 +0,0 @@
> > -#ifndef __MESA_EGL_EXTENSION_H__
> > -#define __MESA_EGL_EXTENSION_H__
> > -
> > -#include <EGL/egl.h>
> > -#include <GL/gl.h>
> > -#include <GL/internal/dri_interface.h>
> > -
> > -#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_MESA    0x3306  /*
> eglAcuireResource
> > attribute */
> > -#define EGL_GL_RENDER_BUFFER_ID_MESA    0x3307  /*
> > eglAcuireResource attribute */
> > -
> > -EGLBoolean eglAcquireResourceMESA(EGLDisplay dpy, EGLContext ctx,
> > EGLenum target, const EGLint *attrib_list, void * user_data);
> > -EGLBoolean eglReleaseResourceMESA(EGLDisplay dpy, EGLContext ctx,
> > EGLenum target, const EGLint *attrib_list);
> > -
> > -#endif
> > diff --git a/src/x11/mesa_egl_res_share.c b/src/x11/mesa_egl_res_share.c
> > deleted file mode 100644
> > index 93e9454..0000000
> > --- a/src/x11/mesa_egl_res_share.c
> > +++ /dev/null
> > @@ -1,135 +0,0 @@
> > -
> >
> /**********************************************************
> > ****************
> > - *
> > - * Copyright 2013-2014 Zhigang Gong <zhigang.gong at linux.intel.com>
> > - * Copyright 2013-2014 Intel, Inc.
> > - * 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 NONINFRINGEMENT.  IN NO
> > EVENT SHALL
> > - * THE AUTHORS OR COPYRIGHT HOLDERS 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 <assert.h>
> > -#include <string.h>
> > -
> > -#include "mesa_egl_extension.h"
> > -#include "mesa_egl_res_share.h"
> > -
> > -/**
> > - * Parse the list of share texture attributes and return the proper error
> code.
> > - */
> > -EGLint
> > -_eglParseTextureAttribList(unsigned int *texture, EGLenum *gl_target,
> > EGLint *level,
> > -                           const EGLint *attrib_list)
> > -{
> > -   EGLint i, err = EGL_SUCCESS;
> > -
> > -   *texture = 0;
> > -   *gl_target = 0;
> > -   *level = 0;
> > -
> > -   if (!attrib_list)
> > -      return EGL_BAD_ATTRIBUTE;
> > -
> > -   for (i = 0; attrib_list[i] != EGL_NONE; i++) {
> > -      EGLint attr = attrib_list[i++];
> > -      EGLint val = attrib_list[i];
> > -
> > -      switch (attr) {
> > -      case EGL_GL_TEXTURE_LEVEL_MESA:
> > -         *level = val;
> > -         break;
> > -      case EGL_GL_TEXTURE_ID_MESA:
> > -         *texture = val;
> > -         break;
> > -      case EGL_GL_TEXTURE_TARGET_MESA:
> > -         *gl_target = val;
> > -         break;
> > -      default:
> > -         /* unknown attrs are ignored */
> > -         break;
> > -      }
> > -   }
> > -
> > -   return err;
> > -}
> > -
> > -/**
> > - * Parse the list of share texture attributes and return the proper error
> code.
> > - */
> > -EGLint
> > -_eglParseBufferObjAttribList(unsigned int *bufobj, const EGLint
> *attrib_list)
> > -{
> > -   EGLint i, err = EGL_SUCCESS;
> > -   *bufobj = 0;
> > -
> > -   if (!attrib_list)
> > -      return EGL_BAD_ATTRIBUTE;
> > -
> > -   for (i = 0; attrib_list[i] != EGL_NONE; i++) {
> > -      EGLint attr = attrib_list[i++];
> > -      EGLint val = attrib_list[i];
> > -
> > -      switch (attr) {
> > -      case EGL_GL_BUFFER_OBJECT_ID_MESA:
> > -         *bufobj = val;
> > -         break;
> > -      default:
> > -         /* unknown attrs are ignored */
> > -         break;
> > -      }
> > -   }
> > -   if (*bufobj == 0)
> > -      err = EGL_BAD_ATTRIBUTE;
> > -
> > -   return err;
> > -}
> > -
> > -/**
> > - * Parse the list of share texture attributes and return the proper error
> code.
> > - */
> > -EGLint
> > -_eglParseRenderBufferAttribList(unsigned int *rb, const EGLint *attrib_list)
> > -{
> > -   EGLint i, err = EGL_SUCCESS;
> > -   *rb = 0;
> > -
> > -   if (!attrib_list)
> > -      return EGL_BAD_ATTRIBUTE;
> > -
> > -   for (i = 0; attrib_list[i] != EGL_NONE; i++) {
> > -      EGLint attr = attrib_list[i++];
> > -      EGLint val = attrib_list[i];
> > -
> > -      switch (attr) {
> > -      case EGL_GL_RENDER_BUFFER_ID_MESA:
> > -         *rb = val;
> > -         break;
> > -      default:
> > -         /* unknown attrs are ignored */
> > -         break;
> > -      }
> > -   }
> > -   if (*rb == 0)
> > -      err = EGL_BAD_ATTRIBUTE;
> > -
> > -   return err;
> > -}
> > diff --git a/src/x11/mesa_egl_res_share.h
> b/src/x11/mesa_egl_res_share.h
> > deleted file mode 100644
> > index 43e746e..0000000
> > --- a/src/x11/mesa_egl_res_share.h
> > +++ /dev/null
> > @@ -1,44 +0,0 @@
> > -
> >
> /**********************************************************
> > ****************
> > - *
> > - * Copyright 2013-2014 Zhigang Gong <zhigang.gong at linux.intel.com>
> > - * Copyright 2013-2014 Intel, Inc.
> > - * 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 NONINFRINGEMENT.  IN NO
> > EVENT SHALL
> > - * THE AUTHORS OR COPYRIGHT HOLDERS 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.
> > - *
> > -
> >
> **********************************************************
> > ****************/
> > -
> > -
> > -#ifndef EGLRESSHARE_INCLUDED
> > -#define EGLRESSHARE_INCLUDED
> > -
> > -#include <EGL/egl.h>
> > -
> > -EGLint
> > -_eglParseTextureAttribList(unsigned int *texture, EGLenum *gl_target,
> > -                           EGLint *level, const EGLint *attrib_list);
> > -EGLint
> > -_eglParseBufferObjAttribList(unsigned int *bufobj,
> > -                             const EGLint *attrib_list);
> > -
> > -EGLint
> > -_eglParseRenderBufferAttribList(unsigned int *rb, const EGLint
> *attrib_list);
> > -#endif
> > diff --git a/utests/CMakeLists.txt b/utests/CMakeLists.txt
> > index 0c3cb00..e7da976 100644
> > --- a/utests/CMakeLists.txt
> > +++ b/utests/CMakeLists.txt
> > @@ -340,7 +340,7 @@ add_custom_target(utest_generator
> >      WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
> >      )
> >
> > -if (EGL_FOUND AND MESA_SOURCE_FOUND)
> > +if (EGL_FOUND)
> >    SET(utests_sources ${utests_sources} compiler_fill_gl_image.cpp)
> >    SET(CMAKE_CXX_FLAGS "-DHAS_EGL ${CMAKE_CXX_FLAGS}
> > ${DEF_OCL_PCH_PCM_PATH}")
> >    SET(CMAKE_C_FLAGS "-DHAS_EGL ${CMAKE_C_FLAGS}
> > ${DEF_OCL_PCH_PCM_PATH}")
> > diff --git a/utests/compiler_fill_gl_image.cpp
> > b/utests/compiler_fill_gl_image.cpp
> > index f1eb8e7..b9d74d1 100644
> > --- a/utests/compiler_fill_gl_image.cpp
> > +++ b/utests/compiler_fill_gl_image.cpp
> > @@ -1,36 +1,14 @@
> >  #include "utest_helper.hpp"
> >
> > -static void read_back(int tex, int width, int height, uint32_t * resultColor)
> > -{
> > -  float vertices[8] = {-1, 1, 1, 1, 1, -1, -1, -1};
> > -  float tex_coords[8] = {0, 0, 1, 0, 1, 1, 0, 1};
> > -
> > -  glBindTexture(GL_TEXTURE_2D, tex);
> > -  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
> > -  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
> > -  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
> > GL_NEAREST);
> > -  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
> > GL_NEAREST);
> > -  glEnable(GL_TEXTURE_2D);
> > -  glDisable(GL_BLEND);
> > -  glVertexPointer(2, GL_FLOAT, sizeof(float) * 2, vertices);
> > -  glEnableClientState(GL_VERTEX_ARRAY);
> > -  glClientActiveTexture(GL_TEXTURE0);
> > -  glTexCoordPointer(2, GL_FLOAT, sizeof(float) * 2, tex_coords);
> > -  glEnableClientState(GL_TEXTURE_COORD_ARRAY);
> > -  glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
> > -  glFlush();
> > -  OCL_SWAP_EGL_BUFFERS();
> > -
> > -  glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8,
> > resultColor);
> > -}
> > -
> >
> >  static void compiler_fill_gl_image(void)
> >  {
> >    const size_t w = EGL_WINDOW_WIDTH;
> >    const size_t h = EGL_WINDOW_HEIGHT;
> > -  uint32_t color = 0x123456FF;
> > -  uint32_t *resultColor;
> > +  uint32_t color0 = 0x123456FF;
> > +  uint32_t color1 = 0x789ABCDE;
> > +  uint32_t *resultColor0;
> > +  uint32_t *resultColor1;
> >    GLuint tex;
> >
> >    if (eglContext == EGL_NO_CONTEXT) {
> > @@ -44,13 +22,15 @@ static void compiler_fill_gl_image(void)
> >    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
> > GL_NEAREST);
> >    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
> > GL_NEAREST);
> >    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA,
> > GL_UNSIGNED_INT_8_8_8_8, NULL);
> > +  glGenerateMipmap(GL_TEXTURE_2D);
> > +  glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, w/2, h/2, 0, GL_RGBA,
> > GL_UNSIGNED_INT_8_8_8_8, NULL);
> >
> >    OCL_CREATE_KERNEL("test_fill_gl_image");
> > +  //Create cl image from miplevel 0
> >    OCL_CREATE_GL_IMAGE(buf[0], 0, GL_TEXTURE_2D, 0, tex);
> > -
> >    // Run the kernel
> >    OCL_SET_ARG(0, sizeof(cl_mem), &buf[0]);
> > -  OCL_SET_ARG(1, sizeof(color), &color);
> > +  OCL_SET_ARG(1, sizeof(color0), &color0);
> >    globals[0] = w;
> >    globals[1] = h;
> >    locals[0] = 16;
> > @@ -59,18 +39,37 @@ static void compiler_fill_gl_image(void)
> >    OCL_ENQUEUE_ACQUIRE_GL_OBJECTS(0);
> >    OCL_NDRANGE(2);
> >    OCL_FLUSH();
> > +  OCL_ENQUEUE_RELEASE_GL_OBJECTS(0);
> >
> >    // Check result
> > -  resultColor = new uint32_t[w * h * 4];
> > -  if (resultColor == NULL)
> > +  resultColor0 = new uint32_t[w * h];
> > +  if (resultColor0 == NULL)
> >      assert(0);
> > -
> > -  read_back(tex, w, h, resultColor);
> > +  glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA,
> > GL_UNSIGNED_INT_8_8_8_8, resultColor0);
> >    for (uint32_t j = 0; j < h; ++j)
> >      for (uint32_t i = 0; i < w; i++)
> > -      OCL_ASSERT(resultColor[j * w + i] == color);
> > -  OCL_UNMAP_BUFFER(0);
> > -  delete[] resultColor;
> > +      OCL_ASSERT(resultColor0[j * w + i] == color0);
> > +
> > +
> > +  //Create cl image from miplevel 1
> > +  OCL_CREATE_GL_IMAGE(buf[1], 0, GL_TEXTURE_2D, 1, tex);
> > +  OCL_SET_ARG(0, sizeof(cl_mem), &buf[1]);
> > +  OCL_SET_ARG(1, sizeof(color1), &color1);
> > +  globals[0] = w/2;
> > +  globals[1] = h/2;
> > +  OCL_ENQUEUE_ACQUIRE_GL_OBJECTS(1);
> > +  OCL_NDRANGE(2);
> > +  OCL_FLUSH();
> > +  OCL_ENQUEUE_RELEASE_GL_OBJECTS(1);
> > +
> > +  // Check result
> > +  resultColor1 = new uint32_t[(w/2)*(h/2)];
> > +  glGetTexImage(GL_TEXTURE_2D, 1, GL_RGBA,
> > GL_UNSIGNED_INT_8_8_8_8, resultColor1);
> > +  for (uint32_t j = 0; j < h/2; ++j)
> > +    for (uint32_t i = 0; i < w/2; i++)
> > +      OCL_ASSERT(resultColor1[j * (w/2) + i] == color1);
> > +  delete[] resultColor0;
> > +  delete[] resultColor1;
> >  }
> >
> >  MAKE_UTEST_FROM_FUNCTION(compiler_fill_gl_image);
> > diff --git a/utests/utest_helper.hpp b/utests/utest_helper.hpp
> > index 5f2fea6..213766f 100644
> > --- a/utests/utest_helper.hpp
> > +++ b/utests/utest_helper.hpp
> > @@ -42,10 +42,12 @@
> >  #ifdef HAS_EGL
> >  #define EGL_WINDOW_WIDTH 256
> >  #define EGL_WINDOW_HEIGHT 256
> > +#define GL_GLEXT_PROTOTYPES
> >  #include  <GL/gl.h>
> > +#include  <GL/glext.h>
> >  #include  <EGL/egl.h>
> >  #include  <EGL/eglext.h>
> > -#include <CL/cl_gl.h>
> > +#include  <CL/cl_gl.h>
> >
> >  extern EGLDisplay  eglDisplay;
> >  extern EGLContext  eglContext;
> > @@ -126,6 +128,9 @@ union uint32_cast {
> >  #define OCL_ENQUEUE_ACQUIRE_GL_OBJECTS(ID) \
> >      OCL_CALL(clEnqueueAcquireGLObjects, queue, 1, &buf[ID], 0, 0, 0)
> >
> > +#define OCL_ENQUEUE_RELEASE_GL_OBJECTS(ID) \
> > +    OCL_CALL(clEnqueueReleaseGLObjects, queue, 1, &buf[ID], 0, 0, 0)
> > +
> >  #define OCL_SWAP_EGL_BUFFERS() \
> >    eglSwapBuffers(eglDisplay, eglSurface);
> >
> > --
> > 1.9.1
> >
> > _______________________________________________
> > Beignet mailing list
> > Beignet at lists.freedesktop.org
> > https://lists.freedesktop.org/mailman/listinfo/beignet


More information about the Beignet mailing list