diff options
author | Zhigang Gong <zhigang.gong@linux.intel.com> | 2013-07-11 19:09:51 +0800 |
---|---|---|
committer | Zhigang Gong <zhigang.gong@linux.intel.com> | 2013-07-16 10:05:49 +0800 |
commit | 383756960273191978c8588b652606ad1dda0e5d (patch) | |
tree | c880bb9549c663259defd30cc9e0c93db1149052 | |
parent | 26e38515493cb9de48a53d8cbe9b380a418e7c7c (diff) |
CL: Enalbe gl sharing with new egl extension.gl_sharing
Signed-off-by: Zhigang Gong <zhigang.gong@linux.intel.com>
-rw-r--r-- | CMake/FindEGL.cmake | 17 | ||||
-rw-r--r-- | src/CMakeLists.txt | 17 | ||||
-rw-r--r-- | src/cl_context.h | 3 | ||||
-rw-r--r-- | src/cl_driver.h | 38 | ||||
-rw-r--r-- | src/cl_driver_defs.c | 1 | ||||
-rw-r--r-- | src/cl_extensions.c | 15 | ||||
-rw-r--r-- | src/cl_extensions.h | 17 | ||||
-rw-r--r-- | src/cl_khr_icd.h | 4 | ||||
-rw-r--r-- | src/cl_mem.c | 8 | ||||
-rw-r--r-- | src/cl_mem.h | 10 | ||||
-rw-r--r-- | src/cl_mem_gl.c | 119 | ||||
-rw-r--r-- | src/gl_share.h | 38 | ||||
-rw-r--r-- | src/intel/intel_driver.c | 194 | ||||
-rw-r--r-- | src/intel/intel_driver.h | 6 | ||||
-rw-r--r-- | src/x11/dricommon.h | 5 | ||||
-rw-r--r-- | src/x11/gbm_deps/backend.h | 36 | ||||
-rw-r--r-- | src/x11/gbm_deps/common.h | 42 | ||||
-rw-r--r-- | src/x11/gbm_deps/common_drm.h | 48 | ||||
-rw-r--r-- | src/x11/gbm_deps/gbm.h | 292 | ||||
-rw-r--r-- | src/x11/gbm_deps/gbm_driint.h | 108 | ||||
-rw-r--r-- | src/x11/gbm_deps/gbmint.h | 116 | ||||
-rw-r--r-- | src/x11/gbm_dri2_x11_platform.c | 126 | ||||
-rw-r--r-- | utests/CMakeLists.txt | 4 | ||||
-rw-r--r-- | utests/utest_helper.cpp | 4 |
24 files changed, 260 insertions, 1008 deletions
diff --git a/CMake/FindEGL.cmake b/CMake/FindEGL.cmake index 69d4852f..49498b4e 100644 --- a/CMake/FindEGL.cmake +++ b/CMake/FindEGL.cmake @@ -34,3 +34,20 @@ ELSE(EGL_INCLUDE_PATH) ENDIF(EGL_INCLUDE_PATH) MARK_AS_ADVANCED(EGL_FOUND) + +FIND_PATH(INTEL_DRI_RESOURCE_SHARING_INCLUDE_PATH intel_dri_resource_sharing.h + ~/include/ + /usr/include/ + /usr/local/include/ + /sw/include/ + /opt/local/include/ + DOC "The directory where intel_dri_share.h resides") + +IF(INTEL_DRI_RESOURCE_SHARING_INCLUDE_PATH) + INCLUDE_DIRECTORIES(${INTEL_DRI_RESOURCE_SHARING_INCLUDE_PATH}) + SET(INTEL_DRI_RESOURCE_SHARING_FOUND 1 CACHE STRING "Set to 1 if Intel DRI resource share extension header file is found, 0 otherwise") +ELSE(INTEL_DRI_RESOURCE_SHARING_INCLUDE_PATH) + SET(INTEL_DRI_RESOURCE_SHARING_FOUND 0 CACHE STRING "Set to 1 if EGL is found, 0 otherwise") +ENDIF(INTEL_DRI_RESOURCE_SHARING_INCLUDE_PATH) + +MARK_AS_ADVANCED(INTEL_DRI_RESOURCE_SHARING_FOUND) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cea78c06..f27ccbe6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -28,16 +28,14 @@ set(OPENCL_SRC x11/dricommon.c x11/va_dri2.c) -if (EGL_FOUND AND GBM_FOUND) -set (OPENCL_SRC ${OPENCL_SRC} cl_mem_gl.c cl_gl_api.c x11/gbm_dri2_x11_platform.c) -SET(CMAKE_CXX_FLAGS "-DHAS_EGL ${CMAKE_CXX_FLAGS}") -SET(CMAKE_C_FLAGS "-DHAS_EGL ${CMAKE_C_FLAGS}") +if (EGL_FOUND AND INTEL_DRI_RESOURCE_SHARING_FOUND) +set (OPENCL_SRC ${OPENCL_SRC} cl_mem_gl.c cl_gl_api.c) +SET(CMAKE_CXX_FLAGS "-DHAS_EGL -DHAS_INTEL_DRI_RESOURCE_SHARING ${CMAKE_CXX_FLAGS}") +SET(CMAKE_C_FLAGS "-DHAS_EGL -DHAS_INTEL_DRI_RESOURCE_SHARING ${CMAKE_C_FLAGS}") SET(OPTIONAL_EGL_LIBRARY "${EGL_LIBRARY}") -SET(OPTIONAL_GBM_LIBRARY "${GBM_LIBRARY}") -else(EGL_FOUND AND GBM_FOUND) +else(EGL_FOUND AND INTEL_DRI_RESOURCE_SHARING_FOUND) SET(OPTIONAL_EGL_LIBRARY "") -SET(OPTIONAL_GBM_LIBRARY "") -endif (EGL_FOUND AND GBM_FOUND) +endif (EGL_FOUND AND INTEL_DRI_RESOURCE_SHARING_FOUND) if (OCLIcd_FOUND) set (OPENCL_SRC ${OPENCL_SRC} cl_khr_icd.c) @@ -58,6 +56,5 @@ target_link_libraries( ${DRM_INTEL_LIBRARY} ${DRM_LIBRARY} ${OPENGL_LIBRARIES} - ${OPTIONAL_EGL_LIBRARY} - ${OPTIONAL_GBM_LIBRARY}) + ${OPTIONAL_EGL_LIBRARY}) install (TARGETS cl LIBRARY DESTINATION lib) diff --git a/src/cl_context.h b/src/cl_context.h index 80bf777c..52477ae4 100644 --- a/src/cl_context.h +++ b/src/cl_context.h @@ -51,6 +51,9 @@ struct _cl_context_prop { }; }; +#define IS_EGL_CONTEXT(ctx) (ctx->props.gl_type == CL_GL_EGL_DISPLAY) +#define EGL_DISP(ctx) (EGLDisplay)(ctx->props.egl_display) +#define EGL_CTX(ctx) (EGLContext)(ctx->props.gl_context) /* Encapsulate the whole device */ struct _cl_context { DEFINE_ICD(dispatch) diff --git a/src/cl_driver.h b/src/cl_driver.h index 60218c71..ae033987 100644 --- a/src/cl_driver.h +++ b/src/cl_driver.h @@ -22,34 +22,12 @@ #include <stdint.h> #include <stdlib.h> - +#include "cl_driver_type.h" /* Various limitations we should remove actually */ #define GEN_MAX_SURFACES 128 #define GEN_MAX_SAMPLERS 16 /************************************************************************** - * cl_driver: - * Hide behind some call backs the buffer allocation / deallocation ... This - * will allow us to make the use of a software performance simulator easier and - * to minimize the code specific for the HW and for the simulator - **************************************************************************/ - -/* Encapsulates command buffer / data buffer / kernels */ -typedef struct _cl_buffer *cl_buffer; - -/* Encapsulates buffer manager */ -typedef struct _cl_buffer_mgr *cl_buffer_mgr; - -/* Encapsulates the driver backend functionalities */ -typedef struct _cl_driver *cl_driver; - -/* Encapsulates the gpgpu stream of commands */ -typedef struct _cl_gpgpu *cl_gpgpu; - -typedef struct _cl_context_prop *cl_context_prop; -typedef struct _cl_sampler *cl_sampler; - -/************************************************************************** * Driver **************************************************************************/ /* Create a new driver */ @@ -196,15 +174,18 @@ typedef cl_buffer (cl_buffer_set_tiling_cb)(cl_buffer, int tiling, size_t stride extern cl_buffer_set_tiling_cb *cl_buffer_set_tiling; #include "cl_context.h" -#include "gl_share.h" +#include "cl_mem.h" typedef struct _cl_context *cl_context; typedef cl_buffer (cl_buffer_alloc_from_texture_cb)(cl_context, unsigned int, int, unsigned int, - cl_gl_image_buffer_region *); + pcl_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); +extern cl_buffer_release_from_texture_cb *cl_buffer_release_from_texture; + /* Unref a buffer and destroy it if no more ref */ -typedef void (cl_buffer_unreference_cb)(cl_buffer); +typedef int (cl_buffer_unreference_cb)(cl_buffer); extern cl_buffer_unreference_cb *cl_buffer_unreference; /* Add one more ref on a buffer */ @@ -255,5 +236,10 @@ extern cl_buffer_wait_rendering_cb *cl_buffer_wait_rendering; typedef int (cl_driver_get_device_id_cb)(void); extern cl_driver_get_device_id_cb *cl_driver_get_device_id; +#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 bd06be32..18989989 100644 --- a/src/cl_driver_defs.c +++ b/src/cl_driver_defs.c @@ -31,6 +31,7 @@ LOCAL cl_driver_get_device_id_cb *cl_driver_get_device_id = NULL; LOCAL cl_buffer_alloc_cb *cl_buffer_alloc = NULL; LOCAL cl_buffer_set_tiling_cb *cl_buffer_set_tiling = NULL; LOCAL cl_buffer_alloc_from_texture_cb *cl_buffer_alloc_from_texture = NULL; +LOCAL cl_buffer_release_from_texture_cb *cl_buffer_release_from_texture = NULL; LOCAL cl_buffer_reference_cb *cl_buffer_reference = NULL; LOCAL cl_buffer_unreference_cb *cl_buffer_unreference = NULL; LOCAL cl_buffer_map_cb *cl_buffer_map = NULL; diff --git a/src/cl_extensions.c b/src/cl_extensions.c index 1ff81c13..d1faa338 100644 --- a/src/cl_extensions.c +++ b/src/cl_extensions.c @@ -39,19 +39,14 @@ void check_opt1_extension(cl_extensions_t *extensions) void check_gl_extension(cl_extensions_t *extensions) { -#ifdef HAS_EGL +#if defined(EGL_MESA_resource_sharing) && defined(HAS_INTEL_DRI_RESOURCE_SHARING) static struct cl_gl_ext_deps egl_funcs; int id; -#if defined(EGL_KHR_image) && defined(EGL_KHR_gl_texture_2D_image) && defined(HAS_GBM) - egl_funcs.eglCreateImageKHR_func = (PFNEGLCREATEIMAGEKHRPROC) eglGetProcAddress("eglCreateImageKHR"); - egl_funcs.eglDestroyImageKHR_func = (PFNEGLDESTROYIMAGEKHRPROC) eglGetProcAddress("eglDestroyImageKHR"); -#else - egl_funcs.eglCreateImageKHR_func = NULL; - egl_funcs.eglDestroyImageKHR_func = NULL; -#endif + egl_funcs.acquire = (PFNEGLACQUIRERESOURCEMESAPROC) eglGetProcAddress("eglAcquireResourceMESA"); + egl_funcs.release = (PFNEGLRELEASERESOURCEMESAPROC) eglGetProcAddress("eglReleaseResourceMESA"); - if (egl_funcs.eglCreateImageKHR_func != NULL - && egl_funcs.eglDestroyImageKHR_func != NULL) { + if (egl_funcs.acquire != NULL + && egl_funcs.release != NULL) { /* For now, we only support cl_khr_gl_sharing. */ for(id = GL_EXT_START_ID; id <= GL_EXT_END_ID; id++) if (id == EXT_ID(khr_gl_sharing)) { diff --git a/src/cl_extensions.h b/src/cl_extensions.h index 51eb8e05..6b131cc5 100644 --- a/src/cl_extensions.h +++ b/src/cl_extensions.h @@ -85,17 +85,12 @@ struct EXT_STRUCT_NAME(name) { \ }; struct cl_gl_ext_deps { -#ifdef HAS_EGL -#ifndef EGL_KHR_image -#define PFNEGLCREATEIMAGEKHRPROC void* -#define PFNEGLDESTROYIMAGEKHRPROC void* -#endif - PFNEGLCREATEIMAGEKHRPROC eglCreateImageKHR_func; - PFNEGLDESTROYIMAGEKHRPROC eglDestroyImageKHR_func; -#ifndef EGL_KHR_image -#undef PFNEGLCREATEIMAGEKHRPROC -#undef PFNEGLDESTROYIMAGEKHRPROC -#endif +#ifdef EGL_MESA_resource_sharing +PFNEGLACQUIRERESOURCEMESAPROC acquire; +PFNEGLRELEASERESOURCEMESAPROC release; +#else +void *acquire; +void *release; #endif }; diff --git a/src/cl_khr_icd.h b/src/cl_khr_icd.h index 6c8b9f4c..1e206b43 100644 --- a/src/cl_khr_icd.h +++ b/src/cl_khr_icd.h @@ -14,6 +14,8 @@ * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see <http://www.gnu.org/licenses/>. */ +#ifndef __CL_KHR_ICD_H__ +#define __CL_KHR_ICD_H__ #ifdef HAS_OCLIcd @@ -28,3 +30,5 @@ extern struct _cl_icd_dispatch const cl_khr_icd_dispatch; #define INIT_ICD(member) #define DEFINE_ICD(member) #endif + +#endif diff --git a/src/cl_mem.c b/src/cl_mem.c index c46a43d3..d00a6903 100644 --- a/src/cl_mem.c +++ b/src/cl_mem.c @@ -355,7 +355,9 @@ _cl_mem_new_image(cl_context ctx, slice_pitch = (image_type == CL_MEM_OBJECT_IMAGE1D || image_type == CL_MEM_OBJECT_IMAGE2D) ? 0 : aligned_pitch*aligned_h; - cl_mem_image_init(cl_mem_image(mem), w, h, image_type, depth, *fmt, intel_fmt, bpp, aligned_pitch, slice_pitch, tiling); + cl_mem_image_init(cl_mem_image(mem), w, h, image_type, depth, *fmt, + intel_fmt, bpp, aligned_pitch, slice_pitch, tiling, + 0, 0, 0); /* Copy the data if required */ if (flags & CL_MEM_COPY_HOST_PTR) @@ -406,13 +408,13 @@ cl_mem_delete(cl_mem mem) return; if (atomic_dec(&mem->ref_n) > 1) return; - if (LIKELY(mem->bo != NULL)) - cl_buffer_unreference(mem->bo); #ifdef HAS_EGL if (UNLIKELY(IS_GL_IMAGE(mem))) { cl_mem_gl_delete(cl_mem_gl_image(mem)); } #endif + if (LIKELY(mem->bo != NULL)) + cl_buffer_unreference(mem->bo); /* Remove it from the list */ assert(mem->ctx); diff --git a/src/cl_mem.h b/src/cl_mem.h index 343d7dc4..652b68ae 100644 --- a/src/cl_mem.h +++ b/src/cl_mem.h @@ -21,9 +21,9 @@ #define __CL_MEM_H__ #include "cl_internals.h" -#include "cl_driver.h" +#include "cl_driver_type.h" #include "CL/cl.h" -#include "gl_share.h" +#include "cl_khr_icd.h" #include <assert.h> #ifndef CL_VERSION_1_2 @@ -98,7 +98,9 @@ cl_mem_image_init(pcl_mem_image image, size_t w, size_t h, size_t depth, cl_image_format fmt, uint32_t intel_fmt, uint32_t bpp, size_t row_pitch, size_t slice_pitch, - cl_image_tiling_t tiling) + cl_image_tiling_t tiling, + size_t tile_x, size_t tile_y, + size_t offset) { image->w = w; image->h = h; @@ -110,6 +112,8 @@ cl_mem_image_init(pcl_mem_image image, size_t w, size_t h, image->row_pitch = row_pitch; image->slice_pitch = slice_pitch; image->tiling = tiling; + image->tile_x = tile_x; + image->tile_y = tile_y; } typedef struct _cl_mem_buffer { diff --git a/src/cl_mem_gl.c b/src/cl_mem_gl.c index ca3647f5..d3cfc281 100644 --- a/src/cl_mem_gl.c +++ b/src/cl_mem_gl.c @@ -37,92 +37,6 @@ #include "CL/cl_intel.h" #include "CL/cl_gl.h" -#ifndef CL_VERSION_1_2 -#define CL_INVALID_IMAGE_DESCRIPTOR -65 -#endif - -static int cl_get_clformat_from_texture(GLint tex_format, cl_image_format * cl_format) -{ - cl_int ret = CL_SUCCESS; - - switch (tex_format) { - case GL_RGBA8: - case GL_RGBA: - case GL_RGBA16: - case GL_RGBA8I: - case GL_RGBA16I: - case GL_RGBA32I: - case GL_RGBA8UI: - case GL_RGBA16UI: - case GL_RGBA32UI: - case GL_RGBA16F: - case GL_RGBA32F: - cl_format->image_channel_order = CL_RGBA; - break; - case GL_BGRA: - cl_format->image_channel_order = CL_BGRA; - break; - default: - ret = CL_INVALID_IMAGE_DESCRIPTOR; - goto error; - } - - switch (tex_format) { - case GL_RGBA8: - case GL_RGBA: - case GL_BGRA: - cl_format->image_channel_data_type = CL_UNORM_INT8; - break; - case GL_RGBA16: - cl_format->image_channel_data_type = CL_UNORM_INT16; - break; - case GL_RGBA8I: - cl_format->image_channel_data_type = CL_SIGNED_INT8; - break; - case GL_RGBA16I: - cl_format->image_channel_data_type = CL_SIGNED_INT16; - break; - case GL_RGBA32I: - cl_format->image_channel_data_type = CL_SIGNED_INT32; - break; - case GL_RGBA8UI: - cl_format->image_channel_data_type = CL_UNSIGNED_INT8; - break; - case GL_RGBA16UI: - cl_format->image_channel_data_type = CL_UNSIGNED_INT16; - break; - case GL_RGBA32UI: - cl_format->image_channel_data_type = CL_UNSIGNED_INT32; - break; - case GL_RGBA16F: - cl_format->image_channel_data_type = CL_HALF_FLOAT; - break; - case GL_RGBA32F: - cl_format->image_channel_order = CL_FLOAT; - break; - default: - ret = CL_INVALID_IMAGE_DESCRIPTOR; - goto error; - } - -error: - return ret; -} - -static cl_mem_object_type -get_mem_type_from_target(GLenum texture_target, cl_mem_object_type *type) -{ - switch(texture_target) { - case GL_TEXTURE_1D: *type = CL_MEM_OBJECT_IMAGE1D; break; - case GL_TEXTURE_2D: *type = CL_MEM_OBJECT_IMAGE2D; break; - case GL_TEXTURE_3D: *type = CL_MEM_OBJECT_IMAGE3D; break; - case GL_TEXTURE_1D_ARRAY: *type = CL_MEM_OBJECT_IMAGE1D_ARRAY; break; - case GL_TEXTURE_2D_ARRAY: *type = CL_MEM_OBJECT_IMAGE2D_ARRAY; break; - default: - return -1; - } - return 0; -} LOCAL cl_mem cl_mem_new_gl_buffer(cl_context ctx, @@ -143,10 +57,6 @@ cl_mem_new_gl_texture(cl_context ctx, { cl_int err = CL_SUCCESS; cl_mem mem = NULL; - int w, h, pitch, tiling; - unsigned int bpp, intel_fmt; - cl_image_format cl_format; - unsigned int gl_format; /* Check flags consistency */ if (UNLIKELY(flags & CL_MEM_COPY_HOST_PTR)) { err = CL_INVALID_ARG_VALUE; @@ -158,33 +68,13 @@ cl_mem_new_gl_texture(cl_context ctx, err = CL_OUT_OF_HOST_MEMORY; goto error; } - cl_gl_image_buffer_region region; - mem->bo = cl_buffer_alloc_from_texture(ctx, texture_target, miplevel, texture, ®ion); + + mem->bo = cl_buffer_alloc_from_texture(ctx, texture_target, miplevel, + texture, cl_mem_image(mem)); if (UNLIKELY(mem->bo == NULL)) { err = CL_MEM_OBJECT_ALLOCATION_FAILURE; goto error; } - cl_get_clformat_from_texture(region.gl_format, &cl_format); - - /* XXX Maybe we'd better to check the hw format in driver? */ - intel_fmt = cl_image_get_intel_format(&cl_format); - - if (intel_fmt == INTEL_UNSUPPORTED_FORMAT) { - err = CL_INVALID_IMAGE_DESCRIPTOR; - goto error; - } - cl_image_byte_per_pixel(&cl_format, &bpp); - - cl_mem_object_type image_type; - if (get_mem_type_from_target(texture_target, &image_type) != 0) { - err = CL_INVALID_IMAGE_DESCRIPTOR; - goto error; - } - - cl_mem_image_init(cl_mem_image(mem), region.w, region.h, - image_type, region.depth, cl_format, - intel_fmt, bpp, region.row_pitch, - region.slice_pitch, tiling); cl_mem_gl_image(mem)->target = texture_target; cl_mem_gl_image(mem)->miplevel = miplevel; @@ -203,4 +93,7 @@ error: LOCAL void cl_mem_gl_delete(pcl_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); } diff --git a/src/gl_share.h b/src/gl_share.h deleted file mode 100644 index 17382e9b..00000000 --- a/src/gl_share.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef __GL_SHARE_H__ -#define __GL_SHARE_H__ - -typedef struct _cl_gl_image_buffer_region { - 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; -} cl_gl_image_buffer_region, *pcl_gl_image_buffer_region; - -typedef struct _cl_gl_buffer_region { - size_t sz; - size_t offset; -} cl_gl_buffer_region, *pcl_gl_buffer_region; - -/* Acquire the texture for external access. */ -typedef int (acquire_texture_proc)(void *context, unsigned int target, int miplevel, unsigned int texture, cl_gl_image_buffer_region *region); -/* Release the texture from external side. */ -typedef int (release_texture_proc)(void *context, unsigned int bufobj); -/* Acquire the buffer object for external access. */ -typedef int (acquire_buffer_proc)(void *context, unsigned int bufobj, cl_gl_buffer_region *region); -/* Release the buffer object from external side. */ -typedef int (release_buffer_proc)(void *context, unsigned int bufobj); - -struct gl_sharing_tbl { - acquire_texture_proc *retain_texture; - release_texture_proc *release_texture; - acquire_buffer_proc *acquire_buffer; - release_buffer_proc *release_buffer; -}; -#endif diff --git a/src/intel/intel_driver.c b/src/intel/intel_driver.c index ccee7390..08daa3ca 100644 --- a/src/intel/intel_driver.c +++ b/src/intel/intel_driver.c @@ -45,6 +45,13 @@ * Zou Nan hai <nanhai.zou@intel.com> * */ + +#if defined(HAS_EGL) +#include "GL/gl.h" +#include "EGL/egl.h" +#include "EGL/eglext.h" +#endif + #include "intel_driver.h" #include "intel_gpgpu.h" #include "intel_batchbuffer.h" @@ -65,6 +72,8 @@ #include "cl_alloc.h" #include "cl_context.h" #include "cl_driver.h" +#include "cl_device_id.h" +#include "cl_platform_id.h" #define SET_BLOCKED_SIGSET(DRIVER) do { \ sigset_t bl_mask; \ @@ -169,6 +178,7 @@ static void intel_driver_open(intel_driver_t *intel, cl_context_prop props) { int cardi; + char *driver_name; if (props != NULL && props->gl_type != CL_GL_NOSHARE && props->gl_type != CL_GL_GLX_DISPLAY @@ -182,7 +192,7 @@ intel_driver_open(intel_driver_t *intel, cl_context_prop props) if(intel->x11_display) { if((intel->dri_ctx = getDRI2State(intel->x11_display, DefaultScreen(intel->x11_display), - NULL))) + &driver_name))) intel_driver_init_shared(intel, intel->dri_ctx); else printf("X server found. dri2 connection failed! \n"); @@ -216,8 +226,6 @@ intel_driver_open(intel_driver_t *intel, cl_context_prop props) static void intel_driver_close(intel_driver_t *intel) { -#ifdef HAS_GBM -#endif if(intel->dri_ctx) dri_state_release(intel->dri_ctx); if(intel->x11_display) XCloseDisplay(intel->x11_display); if(intel->fd) close(intel->fd); @@ -397,10 +405,9 @@ intel_driver_get_ver(struct intel_driver *drv) static size_t drm_intel_bo_get_size(drm_intel_bo *bo) { return bo->size; } static void* drm_intel_bo_get_virtual(drm_intel_bo *bo) { return bo->virtual; } -#if defined(HAS_EGL) && defined(HAS_GBM) -#include "GL/gl.h" -#include "EGL/egl.h" -#include "EGL/eglext.h" +#if defined(HAS_EGL) && defined(HAS_INTEL_DRI_RESOURCE_SHARING) +#include <intel_dri_resource_sharing.h> +#include "cl_image.h" static int get_cl_tiling(uint32_t drm_tiling) { switch(drm_tiling) { @@ -413,11 +420,172 @@ static int get_cl_tiling(uint32_t drm_tiling) return CL_NO_TILE; } -cl_buffer intel_alloc_buffer_from_texture(cl_context ctx, unsigned int target, - int miplevel, unsigned int texture, - cl_gl_image_buffer_region *region) +static int cl_get_clformat_from_texture(GLint tex_format, cl_image_format * cl_format) { - return (cl_buffer)NULL; + cl_int ret = CL_SUCCESS; + + switch (tex_format) { + case GL_RGBA8: + case GL_RGBA: + case GL_RGBA16: + case GL_RGBA8I: + case GL_RGBA16I: + case GL_RGBA32I: + case GL_RGBA8UI: + case GL_RGBA16UI: + case GL_RGBA32UI: + case GL_RGBA16F: + case GL_RGBA32F: + cl_format->image_channel_order = CL_RGBA; + break; + case GL_BGRA: + cl_format->image_channel_order = CL_BGRA; + break; + default: + ret = -1; + goto error; + } + + switch (tex_format) { + case GL_RGBA8: + case GL_RGBA: + case GL_BGRA: + cl_format->image_channel_data_type = CL_UNORM_INT8; + break; + case GL_RGBA16: + cl_format->image_channel_data_type = CL_UNORM_INT16; + break; + case GL_RGBA8I: + cl_format->image_channel_data_type = CL_SIGNED_INT8; + break; + case GL_RGBA16I: + cl_format->image_channel_data_type = CL_SIGNED_INT16; + break; + case GL_RGBA32I: + cl_format->image_channel_data_type = CL_SIGNED_INT32; + break; + case GL_RGBA8UI: + cl_format->image_channel_data_type = CL_UNSIGNED_INT8; + break; + case GL_RGBA16UI: + cl_format->image_channel_data_type = CL_UNSIGNED_INT16; + break; + case GL_RGBA32UI: + cl_format->image_channel_data_type = CL_UNSIGNED_INT32; + break; + case GL_RGBA16F: + cl_format->image_channel_data_type = CL_HALF_FLOAT; + break; + case GL_RGBA32F: + cl_format->image_channel_order = CL_FLOAT; + break; + default: + ret = -1; + goto error; + } + +error: + return ret; +} + +static int +get_mem_type_from_target(GLenum texture_target, cl_mem_object_type *type) +{ + switch(texture_target) { + case GL_TEXTURE_1D: *type = CL_MEM_OBJECT_IMAGE1D; break; + case GL_TEXTURE_2D: *type = CL_MEM_OBJECT_IMAGE2D; break; + case GL_TEXTURE_3D: *type = CL_MEM_OBJECT_IMAGE3D; break; + case GL_TEXTURE_1D_ARRAY: *type = CL_MEM_OBJECT_IMAGE1D_ARRAY; break; + case GL_TEXTURE_2D_ARRAY: *type = CL_MEM_OBJECT_IMAGE2D_ARRAY; break; + default: + return -1; + } + return CL_SUCCESS; +} + +static cl_buffer +intel_alloc_buffer_from_texture_egl(cl_context ctx, unsigned int target, + int miplevel, unsigned int texture, + pcl_mem_image image) +{ + cl_buffer bo = (cl_buffer) NULL; + struct _intel_dri_share_image_region region; + unsigned int bpp, intel_fmt; + cl_image_format cl_format; + EGLBoolean ret; + struct cl_gl_ext_deps *funcs = CL_EXTENSION_GET_FUNCS(ctx, khr_gl_sharing, gl_ext_deps); + EGLint attrib_list[] = { EGL_GL_TEXTURE_ID_MESA, texture, + EGL_GL_TEXTURE_LEVEL_MESA, miplevel, + EGL_GL_TEXTURE_TARGET_MESA, target, + EGL_NONE}; + if (funcs->acquire == NULL || funcs->release == NULL) + goto out; + ret = funcs->acquire(EGL_DISP(ctx), EGL_CTX(ctx), + EGL_GL_TEXTURE_MESA, + &attrib_list[0], ®ion); + if (!ret) + goto out; + + bo = (cl_buffer)intel_driver_share_buffer((intel_driver_t *)ctx->drv, region.name); + + if (bo == NULL) { + funcs->release(EGL_DISP(ctx), EGL_CTX(ctx), EGL_GL_TEXTURE_MESA, &attrib_list[0]); + goto out; + } + region.tiling = get_cl_tiling(region.tiling); + if (cl_get_clformat_from_texture(region.gl_format, &cl_format) != 0) + goto error; + intel_fmt = cl_image_get_intel_format(&cl_format); + if (intel_fmt == INTEL_UNSUPPORTED_FORMAT) + goto error; + cl_image_byte_per_pixel(&cl_format, &bpp); + cl_mem_object_type image_type; + 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; + +error: + cl_buffer_unreference(bo); + funcs->release(EGL_DISP(ctx), EGL_CTX(ctx), EGL_GL_TEXTURE_MESA, &attrib_list[0]); + return NULL; +} + +static cl_buffer +intel_alloc_buffer_from_texture(cl_context ctx, unsigned int target, + int miplevel, unsigned int texture, + pcl_mem_image image) +{ + + if (IS_EGL_CONTEXT(ctx)) + return intel_alloc_buffer_from_texture_egl(ctx, target, miplevel, texture, image); + + return NULL; +} + +static int +intel_release_buffer_from_texture(cl_context ctx, unsigned int target, + int miplevel, unsigned int texture) +{ + if (IS_EGL_CONTEXT(ctx)) { + struct cl_gl_ext_deps *funcs = CL_EXTENSION_GET_FUNCS(ctx, khr_gl_sharing, gl_ext_deps); + EGLint attrib_list[] = { EGL_GL_TEXTURE_ID_MESA, texture, + EGL_GL_TEXTURE_LEVEL_MESA, miplevel, + EGL_GL_TEXTURE_TARGET_MESA, target, + EGL_NONE}; + + if (funcs->acquire == NULL || funcs->release == NULL) + return -1; + funcs->release(EGL_DISP(ctx), EGL_CTX(ctx), EGL_GL_TEXTURE_MESA, &attrib_list[0]); + return CL_SUCCESS; + } + return -1; } #endif @@ -463,8 +631,9 @@ intel_setup_callbacks(void) cl_driver_get_device_id = (cl_driver_get_device_id_cb *) intel_get_device_id; cl_buffer_alloc = (cl_buffer_alloc_cb *) drm_intel_bo_alloc; cl_buffer_set_tiling = (cl_buffer_set_tiling_cb *) intel_buffer_set_tiling; -#ifdef HAS_EGL +#if defined(HAS_EGL) && defined(HAS_INTEL_DRI_RESOURCE_SHARING) 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; #endif cl_buffer_reference = (cl_buffer_reference_cb *) drm_intel_bo_reference; cl_buffer_unreference = (cl_buffer_unreference_cb *) drm_intel_bo_unreference; @@ -480,4 +649,3 @@ intel_setup_callbacks(void) cl_buffer_wait_rendering = (cl_buffer_wait_rendering_cb *) drm_intel_bo_wait_rendering; intel_set_gpgpu_callbacks(); } - diff --git a/src/intel/intel_driver.h b/src/intel/intel_driver.h index 56b2cdc5..8042059a 100644 --- a/src/intel/intel_driver.h +++ b/src/intel/intel_driver.h @@ -54,9 +54,6 @@ #include <drm.h> #include <i915_drm.h> #include <intel_bufmgr.h> -#ifdef HAS_EGL -#include "gl_share.h" -#endif #define CMD_MI (0x0 << 29) #define CMD_2D (0x2 << 29) @@ -90,9 +87,6 @@ typedef struct intel_driver int master; Display *x11_display; struct dri_state *dri_ctx; -#ifdef HAS_EGL - struct gl_sharing_tbl funcs; -#endif } intel_driver_t; /* device control */ diff --git a/src/x11/dricommon.h b/src/x11/dricommon.h index 08e66a5b..5a950b4b 100644 --- a/src/x11/dricommon.h +++ b/src/x11/dricommon.h @@ -94,11 +94,6 @@ void dri_state_release(dri_state_t*); // Create a dri2 state from dpy and screen dri_state_t *getDRI2State(Display* dpy, int screen, char **driver_name); -#ifdef HAS_GBM -#include<gbm.h> -void cl_gbm_set_image_extension(struct gbm_device *gbm, void *display); -int cl_gbm_bo_get_name(struct gbm_bo *bo); -#endif #endif /* _VA_DRICOMMON_H_ */ diff --git a/src/x11/gbm_deps/backend.h b/src/x11/gbm_deps/backend.h deleted file mode 100644 index 4a643750..00000000 --- a/src/x11/gbm_deps/backend.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright © 2011 Intel Corporation - * - * 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, sublicense, - * 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. - * - * Authors: - * Benjamin Franzke <benjaminfranzke@googlemail.com> - */ - -#ifndef MODULE_H_ -#define MODULE_H_ - -#include "gbmint.h" - -struct gbm_device * -_gbm_create_device(int fd); - -#endif diff --git a/src/x11/gbm_deps/common.h b/src/x11/gbm_deps/common.h deleted file mode 100644 index 1fcdfcac..00000000 --- a/src/x11/gbm_deps/common.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright © 2011 Intel Corporation - * - * 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, sublicense, - * 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. - * - * Authors: - * Benjamin Franzke <benjaminfranzke@googlemail.com> - */ - -#ifndef _COMMON_H_ -#define _COMMON_H_ - -#include <libudev.h> - -struct udev_device * -_gbm_udev_device_new_from_fd(struct udev *udev, int fd); - -char * -_gbm_fd_get_device_name(int fd); - -void -_gbm_log(const char *fmt_str, ...); - -#endif diff --git a/src/x11/gbm_deps/common_drm.h b/src/x11/gbm_deps/common_drm.h deleted file mode 100644 index d28c3f01..00000000 --- a/src/x11/gbm_deps/common_drm.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright © 2011 Intel Corporation - * - * 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, sublicense, - * 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. - * - * Authors: - * Benjamin Franzke <benjaminfranzke@googlemail.com> - */ - -#ifndef _COMMON_DRM_H_ -#define _COMMON_DRM_H_ - -#include "gbmint.h" - -enum gbm_drm_driver_type { - GBM_DRM_DRIVER_TYPE_DRI, - GBM_DRM_DRIVER_TYPE_GALLIUM, -}; - -struct gbm_drm_device { - struct gbm_device base; - enum gbm_drm_driver_type type; - char *driver_name; -}; - -struct gbm_drm_bo { - struct gbm_bo base; -}; - -#endif diff --git a/src/x11/gbm_deps/gbm.h b/src/x11/gbm_deps/gbm.h deleted file mode 100644 index e516df2b..00000000 --- a/src/x11/gbm_deps/gbm.h +++ /dev/null @@ -1,292 +0,0 @@ -/* - * Copyright © 2011 Intel Corporation - * - * 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, sublicense, - * 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. - * - * Authors: - * Benjamin Franzke <benjaminfranzke@googlemail.com> - */ - -#ifndef _GBM_H_ -#define _GBM_H_ - -#ifdef __cplusplus -extern "C" { -#endif - - -#define __GBM__ 1 - -#include <stdint.h> - -/** - * \file gbm.h - * \brief Generic Buffer Manager - */ - -struct gbm_device; -struct gbm_bo; -struct gbm_surface; - -/** - * \mainpage The Generic Buffer Manager - * - * This module provides an abstraction that the caller can use to request a - * buffer from the underlying memory management system for the platform. - * - * This allows the creation of portable code whilst still allowing access to - * the underlying memory manager. - */ - -/** - * Abstraction representing the handle to a buffer allocated by the - * manager - */ -union gbm_bo_handle { - void *ptr; - int32_t s32; - uint32_t u32; - int64_t s64; - uint64_t u64; -}; - -/** Format of the allocated buffer */ -enum gbm_bo_format { - /** RGB with 8 bits per channel in a 32 bit value */ - GBM_BO_FORMAT_XRGB8888, - /** ARGB with 8 bits per channel in a 32 bit value */ - GBM_BO_FORMAT_ARGB8888 -}; - -#define __gbm_fourcc_code(a,b,c,d) ((uint32_t)(a) | ((uint32_t)(b) << 8) | \ - ((uint32_t)(c) << 16) | ((uint32_t)(d) << 24)) - -#define GBM_FORMAT_BIG_ENDIAN (1<<31) /* format is big endian instead of little endian */ - -/* color index */ -#define GBM_FORMAT_C8 __gbm_fourcc_code('C', '8', ' ', ' ') /* [7:0] C */ - -/* 8 bpp RGB */ -#define GBM_FORMAT_RGB332 __gbm_fourcc_code('R', 'G', 'B', '8') /* [7:0] R:G:B 3:3:2 */ -#define GBM_FORMAT_BGR233 __gbm_fourcc_code('B', 'G', 'R', '8') /* [7:0] B:G:R 2:3:3 */ - -/* 16 bpp RGB */ -#define GBM_FORMAT_XRGB4444 __gbm_fourcc_code('X', 'R', '1', '2') /* [15:0] x:R:G:B 4:4:4:4 little endian */ -#define GBM_FORMAT_XBGR4444 __gbm_fourcc_code('X', 'B', '1', '2') /* [15:0] x:B:G:R 4:4:4:4 little endian */ -#define GBM_FORMAT_RGBX4444 __gbm_fourcc_code('R', 'X', '1', '2') /* [15:0] R:G:B:x 4:4:4:4 little endian */ -#define GBM_FORMAT_BGRX4444 __gbm_fourcc_code('B', 'X', '1', '2') /* [15:0] B:G:R:x 4:4:4:4 little endian */ - -#define GBM_FORMAT_ARGB4444 __gbm_fourcc_code('A', 'R', '1', '2') /* [15:0] A:R:G:B 4:4:4:4 little endian */ -#define GBM_FORMAT_ABGR4444 __gbm_fourcc_code('A', 'B', '1', '2') /* [15:0] A:B:G:R 4:4:4:4 little endian */ -#define GBM_FORMAT_RGBA4444 __gbm_fourcc_code('R', 'A', '1', '2') /* [15:0] R:G:B:A 4:4:4:4 little endian */ -#define GBM_FORMAT_BGRA4444 __gbm_fourcc_code('B', 'A', '1', '2') /* [15:0] B:G:R:A 4:4:4:4 little endian */ - -#define GBM_FORMAT_XRGB1555 __gbm_fourcc_code('X', 'R', '1', '5') /* [15:0] x:R:G:B 1:5:5:5 little endian */ -#define GBM_FORMAT_XBGR1555 __gbm_fourcc_code('X', 'B', '1', '5') /* [15:0] x:B:G:R 1:5:5:5 little endian */ -#define GBM_FORMAT_RGBX5551 __gbm_fourcc_code('R', 'X', '1', '5') /* [15:0] R:G:B:x 5:5:5:1 little endian */ -#define GBM_FORMAT_BGRX5551 __gbm_fourcc_code('B', 'X', '1', '5') /* [15:0] B:G:R:x 5:5:5:1 little endian */ - -#define GBM_FORMAT_ARGB1555 __gbm_fourcc_code('A', 'R', '1', '5') /* [15:0] A:R:G:B 1:5:5:5 little endian */ -#define GBM_FORMAT_ABGR1555 __gbm_fourcc_code('A', 'B', '1', '5') /* [15:0] A:B:G:R 1:5:5:5 little endian */ -#define GBM_FORMAT_RGBA5551 __gbm_fourcc_code('R', 'A', '1', '5') /* [15:0] R:G:B:A 5:5:5:1 little endian */ -#define GBM_FORMAT_BGRA5551 __gbm_fourcc_code('B', 'A', '1', '5') /* [15:0] B:G:R:A 5:5:5:1 little endian */ - -#define GBM_FORMAT_RGB565 __gbm_fourcc_code('R', 'G', '1', '6') /* [15:0] R:G:B 5:6:5 little endian */ -#define GBM_FORMAT_BGR565 __gbm_fourcc_code('B', 'G', '1', '6') /* [15:0] B:G:R 5:6:5 little endian */ - -/* 24 bpp RGB */ -#define GBM_FORMAT_RGB888 __gbm_fourcc_code('R', 'G', '2', '4') /* [23:0] R:G:B little endian */ -#define GBM_FORMAT_BGR888 __gbm_fourcc_code('B', 'G', '2', '4') /* [23:0] B:G:R little endian */ - -/* 32 bpp RGB */ -#define GBM_FORMAT_XRGB8888 __gbm_fourcc_code('X', 'R', '2', '4') /* [31:0] x:R:G:B 8:8:8:8 little endian */ -#define GBM_FORMAT_XBGR8888 __gbm_fourcc_code('X', 'B', '2', '4') /* [31:0] x:B:G:R 8:8:8:8 little endian */ -#define GBM_FORMAT_RGBX8888 __gbm_fourcc_code('R', 'X', '2', '4') /* [31:0] R:G:B:x 8:8:8:8 little endian */ -#define GBM_FORMAT_BGRX8888 __gbm_fourcc_code('B', 'X', '2', '4') /* [31:0] B:G:R:x 8:8:8:8 little endian */ - -#define GBM_FORMAT_ARGB8888 __gbm_fourcc_code('A', 'R', '2', '4') /* [31:0] A:R:G:B 8:8:8:8 little endian */ -#define GBM_FORMAT_ABGR8888 __gbm_fourcc_code('A', 'B', '2', '4') /* [31:0] A:B:G:R 8:8:8:8 little endian */ -#define GBM_FORMAT_RGBA8888 __gbm_fourcc_code('R', 'A', '2', '4') /* [31:0] R:G:B:A 8:8:8:8 little endian */ -#define GBM_FORMAT_BGRA8888 __gbm_fourcc_code('B', 'A', '2', '4') /* [31:0] B:G:R:A 8:8:8:8 little endian */ - -#define GBM_FORMAT_XRGB2101010 __gbm_fourcc_code('X', 'R', '3', '0') /* [31:0] x:R:G:B 2:10:10:10 little endian */ -#define GBM_FORMAT_XBGR2101010 __gbm_fourcc_code('X', 'B', '3', '0') /* [31:0] x:B:G:R 2:10:10:10 little endian */ -#define GBM_FORMAT_RGBX1010102 __gbm_fourcc_code('R', 'X', '3', '0') /* [31:0] R:G:B:x 10:10:10:2 little endian */ -#define GBM_FORMAT_BGRX1010102 __gbm_fourcc_code('B', 'X', '3', '0') /* [31:0] B:G:R:x 10:10:10:2 little endian */ - -#define GBM_FORMAT_ARGB2101010 __gbm_fourcc_code('A', 'R', '3', '0') /* [31:0] A:R:G:B 2:10:10:10 little endian */ -#define GBM_FORMAT_ABGR2101010 __gbm_fourcc_code('A', 'B', '3', '0') /* [31:0] A:B:G:R 2:10:10:10 little endian */ -#define GBM_FORMAT_RGBA1010102 __gbm_fourcc_code('R', 'A', '3', '0') /* [31:0] R:G:B:A 10:10:10:2 little endian */ -#define GBM_FORMAT_BGRA1010102 __gbm_fourcc_code('B', 'A', '3', '0') /* [31:0] B:G:R:A 10:10:10:2 little endian */ - -/* packed YCbCr */ -#define GBM_FORMAT_YUYV __gbm_fourcc_code('Y', 'U', 'Y', 'V') /* [31:0] Cr0:Y1:Cb0:Y0 8:8:8:8 little endian */ -#define GBM_FORMAT_YVYU __gbm_fourcc_code('Y', 'V', 'Y', 'U') /* [31:0] Cb0:Y1:Cr0:Y0 8:8:8:8 little endian */ -#define GBM_FORMAT_UYVY __gbm_fourcc_code('U', 'Y', 'V', 'Y') /* [31:0] Y1:Cr0:Y0:Cb0 8:8:8:8 little endian */ -#define GBM_FORMAT_VYUY __gbm_fourcc_code('V', 'Y', 'U', 'Y') /* [31:0] Y1:Cb0:Y0:Cr0 8:8:8:8 little endian */ - -#define GBM_FORMAT_AYUV __gbm_fourcc_code('A', 'Y', 'U', 'V') /* [31:0] A:Y:Cb:Cr 8:8:8:8 little endian */ - -/* - * 2 plane YCbCr - * index 0 = Y plane, [7:0] Y - * index 1 = Cr:Cb plane, [15:0] Cr:Cb little endian - * or - * index 1 = Cb:Cr plane, [15:0] Cb:Cr little endian - */ -#define GBM_FORMAT_NV12 __gbm_fourcc_code('N', 'V', '1', '2') /* 2x2 subsampled Cr:Cb plane */ -#define GBM_FORMAT_NV21 __gbm_fourcc_code('N', 'V', '2', '1') /* 2x2 subsampled Cb:Cr plane */ -#define GBM_FORMAT_NV16 __gbm_fourcc_code('N', 'V', '1', '6') /* 2x1 subsampled Cr:Cb plane */ -#define GBM_FORMAT_NV61 __gbm_fourcc_code('N', 'V', '6', '1') /* 2x1 subsampled Cb:Cr plane */ - -/* - * 3 plane YCbCr - * index 0: Y plane, [7:0] Y - * index 1: Cb plane, [7:0] Cb - * index 2: Cr plane, [7:0] Cr - * or - * index 1: Cr plane, [7:0] Cr - * index 2: Cb plane, [7:0] Cb - */ -#define GBM_FORMAT_YUV410 __gbm_fourcc_code('Y', 'U', 'V', '9') /* 4x4 subsampled Cb (1) and Cr (2) planes */ -#define GBM_FORMAT_YVU410 __gbm_fourcc_code('Y', 'V', 'U', '9') /* 4x4 subsampled Cr (1) and Cb (2) planes */ -#define GBM_FORMAT_YUV411 __gbm_fourcc_code('Y', 'U', '1', '1') /* 4x1 subsampled Cb (1) and Cr (2) planes */ -#define GBM_FORMAT_YVU411 __gbm_fourcc_code('Y', 'V', '1', '1') /* 4x1 subsampled Cr (1) and Cb (2) planes */ -#define GBM_FORMAT_YUV420 __gbm_fourcc_code('Y', 'U', '1', '2') /* 2x2 subsampled Cb (1) and Cr (2) planes */ -#define GBM_FORMAT_YVU420 __gbm_fourcc_code('Y', 'V', '1', '2') /* 2x2 subsampled Cr (1) and Cb (2) planes */ -#define GBM_FORMAT_YUV422 __gbm_fourcc_code('Y', 'U', '1', '6') /* 2x1 subsampled Cb (1) and Cr (2) planes */ -#define GBM_FORMAT_YVU422 __gbm_fourcc_code('Y', 'V', '1', '6') /* 2x1 subsampled Cr (1) and Cb (2) planes */ -#define GBM_FORMAT_YUV444 __gbm_fourcc_code('Y', 'U', '2', '4') /* non-subsampled Cb (1) and Cr (2) planes */ -#define GBM_FORMAT_YVU444 __gbm_fourcc_code('Y', 'V', '2', '4') /* non-subsampled Cr (1) and Cb (2) planes */ - - -/** - * Flags to indicate the intended use for the buffer - these are passed into - * gbm_bo_create(). The caller must set the union of all the flags that are - * appropriate - * - * \sa Use gbm_device_is_format_supported() to check if the combination of format - * and use flags are supported - */ -enum gbm_bo_flags { - /** - * Buffer is going to be presented to the screen using an API such as KMS - */ - GBM_BO_USE_SCANOUT = (1 << 0), - /** - * Buffer is going to be used as cursor - the dimensions for the buffer - * must be 64x64 if this flag is passed. - */ - GBM_BO_USE_CURSOR_64X64 = (1 << 1), - /** - * Buffer is to be used for rendering - for example it is going to be used - * as the storage for a color buffer - */ - GBM_BO_USE_RENDERING = (1 << 2), - /** - * Buffer can be used for gbm_bo_write. This is guaranteed to work - * with GBM_BO_USE_CURSOR_64X64. but may not work for other - * combinations. - */ - GBM_BO_USE_WRITE = (1 << 3), -}; - -int -gbm_device_get_fd(struct gbm_device *gbm); - -const char * -gbm_device_get_backend_name(struct gbm_device *gbm); - -int -gbm_device_is_format_supported(struct gbm_device *gbm, - uint32_t format, uint32_t usage); - -void -gbm_device_destroy(struct gbm_device *gbm); - -struct gbm_device * -gbm_create_device(int fd); - -struct gbm_bo * -gbm_bo_create(struct gbm_device *gbm, - uint32_t width, uint32_t height, - uint32_t format, uint32_t flags); - -#define GBM_BO_IMPORT_WL_BUFFER 0x5501 -#define GBM_BO_IMPORT_EGL_IMAGE 0x5502 - -struct gbm_bo * -gbm_bo_import(struct gbm_device *gbm, uint32_t type, - void *buffer, uint32_t usage); - -uint32_t -gbm_bo_get_width(struct gbm_bo *bo); - -uint32_t -gbm_bo_get_height(struct gbm_bo *bo); - -uint32_t -gbm_bo_get_stride(struct gbm_bo *bo); - -uint32_t -gbm_bo_get_format(struct gbm_bo *bo); - -struct gbm_device * -gbm_bo_get_device(struct gbm_bo *bo); - -union gbm_bo_handle -gbm_bo_get_handle(struct gbm_bo *bo); - -int -gbm_bo_write(struct gbm_bo *bo, const void *buf, size_t count); - -void -gbm_bo_set_user_data(struct gbm_bo *bo, void *data, - void (*destroy_user_data)(struct gbm_bo *, void *)); - -void * -gbm_bo_get_user_data(struct gbm_bo *bo); - -void -gbm_bo_destroy(struct gbm_bo *bo); - -struct gbm_surface * -gbm_surface_create(struct gbm_device *gbm, - uint32_t width, uint32_t height, - uint32_t format, uint32_t flags); - -struct gbm_bo * -gbm_surface_lock_front_buffer(struct gbm_surface *surface); - -void -gbm_surface_release_buffer(struct gbm_surface *surface, struct gbm_bo *bo); - -int -gbm_surface_has_free_buffers(struct gbm_surface *surface); - -void -gbm_surface_destroy(struct gbm_surface *surface); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/src/x11/gbm_deps/gbm_driint.h b/src/x11/gbm_deps/gbm_driint.h deleted file mode 100644 index 18fc3c09..00000000 --- a/src/x11/gbm_deps/gbm_driint.h +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright © 2011 Intel Corporation - * - * 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, sublicense, - * 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. - * - * Authors: - * Benjamin Franzke <benjaminfranzke@googlemail.com> - */ - -#ifndef _GBM_DRI_INTERNAL_H_ -#define _GBM_DRI_INTERNAL_H_ - -#include "gbmint.h" - -#include "common.h" -#include "common_drm.h" - -#include <GL/gl.h> /* dri_interface needs GL types */ -#include "GL/internal/dri_interface.h" - -struct gbm_dri_surface; - -struct gbm_dri_device { - struct gbm_drm_device base; - - void *driver; - - __DRIscreen *screen; - - __DRIcoreExtension *core; - __DRIdri2Extension *dri2; - __DRIimageExtension *image; - __DRI2flushExtension *flush; - __DRIdri2LoaderExtension *loader; - - const __DRIconfig **driver_configs; - const __DRIextension *extensions[4]; - - __DRIimage *(*lookup_image)(__DRIscreen *screen, void *image, void *data); - void *lookup_user_data; - - __DRIbuffer *(*get_buffers)(__DRIdrawable * driDrawable, - int *width, int *height, - unsigned int *attachments, int count, - int *out_count, void *data); - void (*flush_front_buffer)(__DRIdrawable * driDrawable, void *data); - __DRIbuffer *(*get_buffers_with_format)(__DRIdrawable * driDrawable, - int *width, int *height, - unsigned int *attachments, int count, - int *out_count, void *data); -}; - -struct gbm_dri_bo { - struct gbm_drm_bo base; - - __DRIimage *image; - - /* Only used for cursors */ - uint32_t handle, size; - void *map; -}; - -struct gbm_dri_surface { - struct gbm_surface base; - - void *dri_private; -}; - -static inline struct gbm_dri_device * -gbm_dri_device(struct gbm_device *gbm) -{ - return (struct gbm_dri_device *) gbm; -} - -static inline struct gbm_dri_bo * -gbm_dri_bo(struct gbm_bo *bo) -{ - return (struct gbm_dri_bo *) bo; -} - -static inline struct gbm_dri_surface * -gbm_dri_surface(struct gbm_surface *surface) -{ - return (struct gbm_dri_surface *) surface; -} - -char * -dri_fd_get_driver_name(int fd); - -#endif diff --git a/src/x11/gbm_deps/gbmint.h b/src/x11/gbm_deps/gbmint.h deleted file mode 100644 index a467beae..00000000 --- a/src/x11/gbm_deps/gbmint.h +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright © 2011 Intel Corporation - * - * 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, sublicense, - * 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. - * - * Authors: - * Benjamin Franzke <benjaminfranzke@googlemail.com> - */ - -#ifndef INTERNAL_H_ -#define INTERNAL_H_ - -#include "gbm.h" -#include <sys/stat.h> - -/* GCC visibility */ -#if defined(__GNUC__) && __GNUC__ >= 4 -#define GBM_EXPORT __attribute__ ((visibility("default"))) -#else -#define GBM_EXPORT -#endif - -/** - * \file gbmint.h - * \brief Internal implementation details of gbm - */ - -/** - * The device used for the memory allocation. - * - * The members of this structure should be not accessed directly - */ -struct gbm_device { - /* Hack to make a gbm_device detectable by its first element. */ - struct gbm_device *(*dummy)(int); - - int fd; - const char *name; - unsigned int refcount; - struct stat stat; - - void (*destroy)(struct gbm_device *gbm); - int (*is_format_supported)(struct gbm_device *gbm, - uint32_t format, - uint32_t usage); - - struct gbm_bo *(*bo_create)(struct gbm_device *gbm, - uint32_t width, uint32_t height, - uint32_t format, - uint32_t usage); - struct gbm_bo *(*bo_import)(struct gbm_device *gbm, uint32_t type, - void *buffer, uint32_t usage); - int (*bo_write)(struct gbm_bo *bo, const void *buf, size_t data); - void (*bo_destroy)(struct gbm_bo *bo); - - struct gbm_surface *(*surface_create)(struct gbm_device *gbm, - uint32_t width, uint32_t height, - uint32_t format, uint32_t flags); - struct gbm_bo *(*surface_lock_front_buffer)(struct gbm_surface *surface); - void (*surface_release_buffer)(struct gbm_surface *surface, - struct gbm_bo *bo); - int (*surface_has_free_buffers)(struct gbm_surface *surface); - void (*surface_destroy)(struct gbm_surface *surface); -}; - -/** - * The allocated buffer object. - * - * The members in this structure should not be accessed directly. - */ -struct gbm_bo { - struct gbm_device *gbm; - uint32_t width; - uint32_t height; - uint32_t stride; - uint32_t format; - union gbm_bo_handle handle; - void *user_data; - void (*destroy_user_data)(struct gbm_bo *, void *); -}; - -struct gbm_surface { - struct gbm_device *gbm; - uint32_t width; - uint32_t height; - uint32_t format; - uint32_t flags; -}; - -struct gbm_backend { - const char *backend_name; - struct gbm_device *(*create_device)(int fd); -}; - -GBM_EXPORT struct gbm_device * -_gbm_mesa_get_device(int fd); - -#endif diff --git a/src/x11/gbm_dri2_x11_platform.c b/src/x11/gbm_dri2_x11_platform.c deleted file mode 100644 index 481f4072..00000000 --- a/src/x11/gbm_dri2_x11_platform.c +++ /dev/null @@ -1,126 +0,0 @@ -#include <string.h> -#include "GL/gl.h" /* dri_interface need gl types definitions. */ -#include "GL/internal/dri_interface.h" -#include "gbm_deps/gbm_driint.h" -#include "gbm_deps/gbmint.h" -#include "dricommon.h" - -typedef struct EGLDisplay _EGLDisplay; -typedef struct EGLDriver _EGLDriver; -/* XXX should check whether we support pthread.*/ -typedef pthread_mutex_t _EGLMutex; - -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 unsigned int EGLBoolean; -typedef int32_t EGLint; - -struct _hack_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 */ - EGLint VersionMajor; /**< EGL major version */ - EGLint VersionMinor; /**< EGL minor version */ - EGLint ClientAPIs; /**< Bitmask of APIs supported (EGL_xxx_BIT) */ -}; - -struct _hack_dri2_egl_display -{ - int dri2_major; - int dri2_minor; - __DRIscreen *dri_screen; - int own_dri_screen; - const __DRIconfig **driver_configs; - void *driver; - __DRIcoreExtension *core; - __DRIdri2Extension *dri2; - __DRIswrastExtension *swrast; - __DRI2flushExtension *flush; - __DRItexBufferExtension *tex_buffer; - __DRIimageExtension *image; - __DRIrobustnessExtension *robustness; - __DRI2configQueryExtension *config; - int fd; - - int own_device; - int swap_available; - int invalidate_available; - int min_swap_interval; - int max_swap_interval; - int default_swap_interval; - struct gbm_dri_device *gbm_dri; - - char *device_name; - char *driver_name; - - __DRIdri2LoaderExtension dri2_loader_extension; - __DRIswrastLoaderExtension swrast_loader_extension; - const __DRIextension *extensions[4]; -}; - -static __DRIimageLookupExtension *image_lookup_extension; - -/* We are use DRI2 x11 platform, and by default, gbm doesn't register - * a valid image extension, and actually, it doesn't know how to register - * it based on current interface. We have to hack it here. */ -void cl_gbm_set_image_extension(struct gbm_device *gbm, void *display) -{ - struct gbm_dri_device *gbm_dri = gbm_dri_device(gbm); - struct _hack_egl_display *egl_dpy = (struct _hack_egl_display*)display; - struct _hack_dri2_egl_display *dri2_dpy = (struct _hack_dri2_egl_display*)egl_dpy->DriverData; - int i; - - if (gbm_dri->lookup_image == NULL - && egl_dpy->Platform == _EGL_PLATFORM_X11) { - for(i = 0; i < 4; i++) - if (dri2_dpy->extensions[i] - && ((strncmp(dri2_dpy->extensions[i]->name, - __DRI_IMAGE_LOOKUP, - sizeof(__DRI_IMAGE_LOOKUP))) == 0)) - break; - if (i >= 4) return; - image_lookup_extension = (__DRIimageLookupExtension*)dri2_dpy->extensions[i]; - gbm_dri->lookup_image = image_lookup_extension->lookupEGLImage; - gbm_dri->lookup_user_data = display; - } -} - -int cl_gbm_bo_get_name(struct gbm_bo *bo) -{ - int name; - struct gbm_dri_device *gbm_dri = gbm_dri_device(bo->gbm); - struct gbm_dri_bo *bo_dri = gbm_dri_bo(bo); - - gbm_dri->image->queryImage(bo_dri->image, __DRI_IMAGE_ATTRIB_NAME, - &name); - return name; -} diff --git a/utests/CMakeLists.txt b/utests/CMakeLists.txt index 621acad9..86c48e11 100644 --- a/utests/CMakeLists.txt +++ b/utests/CMakeLists.txt @@ -111,11 +111,11 @@ set (utests_sources utest_file_map.cpp utest_helper.cpp) -if (EGL_FOUND) +if (EGL_FOUND AND INTEL_DRI_RESOURCE_SHARING_FOUND) SET(utests_sources ${utests_sources} compiler_fill_gl_image.cpp) SET(CMAKE_CXX_FLAGS "-DHAS_EGL ${CMAKE_CXX_FLAGS}") SET(CMAKE_C_FLAGS "-DHAS_EGL ${CMAKE_C_FLAGS}") -endif (EGL_FOUND) +endif (EGL_FOUND AND INTEL_DRI_RESOURCE_SHARING_FOUND) ADD_LIBRARY(utests SHARED ${utests_sources}) diff --git a/utests/utest_helper.cpp b/utests/utest_helper.cpp index 504f80f4..76ffd06f 100644 --- a/utests/utest_helper.cpp +++ b/utests/utest_helper.cpp @@ -312,7 +312,9 @@ cl_ocl_init(void) cl_int status = CL_SUCCESS; cl_uint platform_n; size_t i; +#ifdef HAS_EGL bool hasGLExt = false; +#endif cl_context_properties *props = NULL; /* Get the platform number */ @@ -337,9 +339,11 @@ cl_ocl_init(void) GET_DEVICE_STR_INFO(vendor, VENDOR); GET_DEVICE_STR_INFO(version, VERSION); GET_DEVICE_STR_INFO(extensions, EXTENSIONS); +#ifdef HAS_EGL if (std::strstr(extensionsStr.c_str(), "cl_khr_gl_sharing")) { hasGLExt = true; } +#endif } #ifdef HAS_EGL |