[Beignet] [PATCH 1/6 newRT] Refine intel_driver file.
junyan.he at inbox.com
junyan.he at inbox.com
Tue Mar 28 08:25:32 UTC 2017
From: Junyan He <junyan.he at intel.com>
Delete some verbose logic and make create/delete the only API
for creating and destroy the intel_driver.
Signed-off-by: Junyan He <junyan.he at intel.com>
---
src/gen/intel_driver.c | 734 ++++++++++++++++++++++++-------------------------
src/gen/intel_driver.h | 24 +-
2 files changed, 370 insertions(+), 388 deletions(-)
diff --git a/src/gen/intel_driver.c b/src/gen/intel_driver.c
index bce1894..5161bee 100644
--- a/src/gen/intel_driver.c
+++ b/src/gen/intel_driver.c
@@ -80,33 +80,95 @@
#include "cl_device_id.h"
#include "cl_platform_id.h"
+/********************************* DRI Context *********************************/
static void
+intel_driver_close(intel_driver_t *intel)
+{
+ //Due to the drm change about the test usrptr, we need to destroy the bufmgr
+ //befor the driver was closed, otherwise the test usrptr will not be freed.
+ if (intel->bufmgr)
+ drm_intel_bufmgr_destroy(intel->bufmgr);
+
+#ifdef HAS_X11
+ if (intel->dri_ctx)
+ dri_state_release(intel->dri_ctx);
+ if (intel->x11_display)
+ XCloseDisplay(intel->x11_display);
+#endif
+
+ if (intel->need_close) {
+ close(intel->fd);
+ intel->need_close = 0;
+ }
+ intel->dri_ctx = NULL;
+ intel->x11_display = NULL;
+ intel->fd = -1;
+}
+
+static void
+intel_driver_context_destroy(intel_driver_t *driver)
+{
+ if (driver->null_bo)
+ drm_intel_bo_unreference(driver->null_bo);
+ if (driver->ctx)
+ drm_intel_gem_context_destroy(driver->ctx);
+ driver->ctx = NULL;
+}
+
+static int
+intel_driver_terminate(intel_driver_t *driver)
+{
+ pthread_mutex_destroy(&driver->ctxmutex);
+
+ if (driver->need_close) {
+ close(driver->fd);
+ driver->need_close = 0;
+ }
+
+ driver->fd = -1;
+ return 1;
+}
+
+LOCAL void
intel_driver_delete(intel_driver_t *driver)
{
if (driver == NULL)
return;
+ intel_driver_context_destroy(driver);
+ intel_driver_close(driver);
+ intel_driver_terminate(driver);
+
CL_FREE(driver);
}
static intel_driver_t *
intel_driver_new(void)
{
- intel_driver_t *driver = NULL;
+ intel_driver_t *driver = CL_CALLOC(1, sizeof(intel_driver_t));
+ if (driver == NULL)
+ return NULL;
- TRY_ALLOC_NO_ERR(driver, CL_CALLOC(1, sizeof(intel_driver_t)));
driver->fd = -1;
-
-exit:
return driver;
-error:
- intel_driver_delete(driver);
- driver = NULL;
- goto exit;
}
-/* just used for maximum relocation number in drm_intel */
-#define BATCH_SIZE 0x4000
+static void
+intel_driver_context_init(intel_driver_t *driver)
+{
+ driver->ctx = drm_intel_gem_context_create(driver->bufmgr);
+ assert(driver->ctx);
+ driver->null_bo = NULL;
+
+#ifdef HAS_BO_SET_SOFTPIN
+ drm_intel_bo *bo = dri_bo_alloc(driver->bufmgr, "null_bo", 64 * 1024, 4096);
+ drm_intel_bo_set_softpin_offset(bo, 0);
+ // don't reuse it, that would make two bo trying to bind to same address,
+ // which is un-reasonable.
+ drm_intel_bo_disable_reuse(bo);
+ driver->null_bo = bo;
+#endif
+}
/* set OCL_DUMP_AUB=1 to get aub file */
static void
@@ -117,18 +179,20 @@ intel_driver_aub_dump(intel_driver_t *driver)
if (!val)
return;
if (atoi(val) != 0) {
- drm_intel_bufmgr_gem_set_aub_filename(driver->bufmgr,
- "beignet.aub");
+ drm_intel_bufmgr_gem_set_aub_filename(driver->bufmgr, "beignet.aub");
drm_intel_bufmgr_gem_set_aub_dump(driver->bufmgr, 1);
}
}
+/* just used for maximum relocation number in drm_intel */
+#define BATCH_SIZE 0x4000
static int
intel_driver_memman_init(intel_driver_t *driver)
{
driver->bufmgr = drm_intel_bufmgr_gem_init(driver->fd, BATCH_SIZE);
if (!driver->bufmgr)
return 0;
+
drm_intel_bufmgr_gem_enable_reuse(driver->bufmgr);
driver->device_id = drm_intel_bufmgr_gem_get_devid(driver->bufmgr);
intel_driver_aub_dump(driver);
@@ -136,34 +200,6 @@ intel_driver_memman_init(intel_driver_t *driver)
}
static int
-intel_driver_context_init(intel_driver_t *driver)
-{
- driver->ctx = drm_intel_gem_context_create(driver->bufmgr);
- if (!driver->ctx)
- return 0;
- driver->null_bo = NULL;
-#ifdef HAS_BO_SET_SOFTPIN
- drm_intel_bo *bo = dri_bo_alloc(driver->bufmgr, "null_bo", 64 * 1024, 4096);
- drm_intel_bo_set_softpin_offset(bo, 0);
- // don't reuse it, that would make two bo trying to bind to same address,
- // which is un-reasonable.
- drm_intel_bo_disable_reuse(bo);
- driver->null_bo = bo;
-#endif
- return 1;
-}
-
-static void
-intel_driver_context_destroy(intel_driver_t *driver)
-{
- if (driver->null_bo)
- drm_intel_bo_unreference(driver->null_bo);
- if (driver->ctx)
- drm_intel_gem_context_destroy(driver->ctx);
- driver->ctx = NULL;
-}
-
-static int
intel_driver_init(intel_driver_t *driver, int dev_fd)
{
driver->fd = dev_fd;
@@ -172,8 +208,7 @@ intel_driver_init(intel_driver_t *driver, int dev_fd)
if (!intel_driver_memman_init(driver))
return 0;
- if (!intel_driver_context_init(driver))
- return 0;
+ intel_driver_context_init(driver);
#if EMULATE_GEN
driver->gen_ver = EMULATE_GEN;
@@ -204,6 +239,76 @@ intel_driver_init(intel_driver_t *driver, int dev_fd)
return 1;
}
+static int
+intel_driver_init_master(intel_driver_t *driver, const char *dev_name)
+{
+ int dev_fd, ret;
+
+ drm_client_t client;
+
+ // usually dev_name = "/dev/dri/card%d"
+ dev_fd = open(dev_name, O_RDWR);
+ if (dev_fd == -1) {
+ fprintf(stderr, "open(\"%s\", O_RDWR) failed: %s\n", dev_name, strerror(errno));
+ return 0;
+ }
+
+ // Check that we're authenticated
+ memset(&client, 0, sizeof(drm_client_t));
+ ret = ioctl(dev_fd, DRM_IOCTL_GET_CLIENT, &client);
+ if (ret == -1) {
+ fprintf(stderr, "ioctl(dev_fd, DRM_IOCTL_GET_CLIENT, &client) failed: %s\n", strerror(errno));
+ close(dev_fd);
+ return 0;
+ }
+
+ if (!client.auth) {
+ fprintf(stderr, "%s not authenticated\n", dev_name);
+ close(dev_fd);
+ return 0;
+ }
+
+ ret = intel_driver_init(driver, dev_fd);
+ driver->need_close = 1;
+
+ return ret;
+}
+
+static int
+intel_driver_init_render(intel_driver_t *driver, const char *dev_name)
+{
+ int dev_fd, ret;
+
+ dev_fd = open(dev_name, O_RDWR);
+ if (dev_fd == -1)
+ return 0;
+
+ ret = intel_driver_init(driver, dev_fd);
+ driver->need_close = 1;
+
+ return ret;
+}
+
+#ifdef HAS_X11
+static int
+intel_driver_init_shared(intel_driver_t *driver, dri_state_t *state)
+{
+ int ret;
+ assert(state);
+ if (state->driConnectedFlag != DRI2)
+ return 0;
+ ret = intel_driver_init(driver, state->fd);
+ driver->need_close = 0; // close dri2 will close it.
+ return ret;
+}
+#endif
+
+static int
+intel_driver_is_active(intel_driver_t *driver)
+{
+ return driver->fd >= 0;
+}
+
static cl_int
intel_driver_open(intel_driver_t *intel, cl_context_prop props)
{
@@ -211,7 +316,8 @@ intel_driver_open(intel_driver_t *intel, cl_context_prop props)
#ifdef HAS_X11
char *driver_name;
#endif
- if (props != NULL && props->gl_type != CL_GL_NOSHARE && props->gl_type != CL_GL_GLX_DISPLAY && props->gl_type != CL_GL_EGL_DISPLAY) {
+ if (props != NULL && props->gl_type != CL_GL_NOSHARE &&
+ props->gl_type != CL_GL_GLX_DISPLAY && props->gl_type != CL_GL_EGL_DISPLAY) {
fprintf(stderr, "Unsupported gl share type %d.\n", props->gl_type);
return CL_INVALID_OPERATION;
}
@@ -265,109 +371,19 @@ intel_driver_open(intel_driver_t *intel, cl_context_prop props)
return CL_SUCCESS;
}
-static void
-intel_driver_close(intel_driver_t *intel)
-{
- //Due to the drm change about the test usrptr, we need to destroy the bufmgr
- //befor the driver was closed, otherwise the test usrptr will not be freed.
- if (intel->bufmgr)
- drm_intel_bufmgr_destroy(intel->bufmgr);
-#ifdef HAS_X11
- if (intel->dri_ctx)
- dri_state_release(intel->dri_ctx);
- if (intel->x11_display)
- XCloseDisplay(intel->x11_display);
-#endif
- if (intel->need_close) {
- close(intel->fd);
- intel->need_close = 0;
- }
- intel->dri_ctx = NULL;
- intel->x11_display = NULL;
- intel->fd = -1;
-}
-
-LOCAL int
-intel_driver_is_active(intel_driver_t *driver)
+LOCAL intel_driver_t *
+intel_driver_create(cl_context_prop props)
{
- return driver->fd >= 0;
-}
-
-#ifdef HAS_X11
-LOCAL int
-intel_driver_init_shared(intel_driver_t *driver, dri_state_t *state)
-{
- int ret;
- assert(state);
- if (state->driConnectedFlag != DRI2)
- return 0;
- ret = intel_driver_init(driver, state->fd);
- driver->need_close = 0;
- return ret;
-}
-#endif
-
-LOCAL int
-intel_driver_init_master(intel_driver_t *driver, const char *dev_name)
-{
- int dev_fd, ret;
-
- drm_client_t client;
-
- // usually dev_name = "/dev/dri/card%d"
- dev_fd = open(dev_name, O_RDWR);
- if (dev_fd == -1) {
- fprintf(stderr, "open(\"%s\", O_RDWR) failed: %s\n", dev_name, strerror(errno));
- return 0;
- }
-
- // Check that we're authenticated
- memset(&client, 0, sizeof(drm_client_t));
- ret = ioctl(dev_fd, DRM_IOCTL_GET_CLIENT, &client);
- if (ret == -1) {
- fprintf(stderr, "ioctl(dev_fd, DRM_IOCTL_GET_CLIENT, &client) failed: %s\n", strerror(errno));
- close(dev_fd);
- return 0;
- }
+ intel_driver_t *driver = intel_driver_new();
+ if (driver == NULL)
+ return NULL;
- if (!client.auth) {
- fprintf(stderr, "%s not authenticated\n", dev_name);
- close(dev_fd);
- return 0;
+ if (intel_driver_open(driver, props) != CL_SUCCESS) {
+ intel_driver_delete(driver);
+ driver = NULL;
}
- ret = intel_driver_init(driver, dev_fd);
- driver->need_close = 1;
-
- return ret;
-}
-
-LOCAL int
-intel_driver_init_render(intel_driver_t *driver, const char *dev_name)
-{
- int dev_fd, ret;
-
- dev_fd = open(dev_name, O_RDWR);
- if (dev_fd == -1)
- return 0;
-
- ret = intel_driver_init(driver, dev_fd);
- driver->need_close = 1;
-
- return ret;
-}
-
-LOCAL int
-intel_driver_terminate(intel_driver_t *driver)
-{
- pthread_mutex_destroy(&driver->ctxmutex);
-
- if (driver->need_close) {
- close(driver->fd);
- driver->need_close = 0;
- }
- driver->fd = -1;
- return 1;
+ return driver;
}
LOCAL void
@@ -386,14 +402,25 @@ intel_driver_unlock_hardware(intel_driver_t *driver)
PPTHREAD_MUTEX_UNLOCK(driver);
}
+/********************************* DRI Buffer *********************************/
+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;
+}
+
LOCAL dri_bo *
intel_driver_share_buffer_from_name(intel_driver_t *driver, const char *sname, uint32_t name)
{
- dri_bo *bo = intel_bo_gem_create_from_name(driver->bufmgr,
- sname,
- name);
+ dri_bo *bo = intel_bo_gem_create_from_name(driver->bufmgr, sname, name);
if (bo == NULL) {
- fprintf(stderr, "intel_bo_gem_create_from_name create \"%s\" bo from name %d failed: %s\n", sname, name, strerror(errno));
+ fprintf(stderr, "intel_bo_gem_create_from_name create \"%s\" bo from name %d failed: %s\n",
+ sname, name, strerror(errno));
return NULL;
}
return bo;
@@ -402,105 +429,26 @@ intel_driver_share_buffer_from_name(intel_driver_t *driver, const char *sname, u
LOCAL dri_bo *
intel_driver_share_buffer_from_fd(intel_driver_t *driver, int fd, int size)
{
- dri_bo *bo = drm_intel_bo_gem_create_from_prime(driver->bufmgr,
- fd,
- size);
+ dri_bo *bo = drm_intel_bo_gem_create_from_prime(driver->bufmgr, fd, size);
if (bo == NULL) {
- fprintf(stderr, "drm_intel_bo_gem_create_from_prime create bo(size %d) from fd %d failed: %s\n", size, fd, strerror(errno));
+ fprintf(stderr, "drm_intel_bo_gem_create_from_prime create bo(size %d) from fd %d failed: %s\n",
+ size, fd, strerror(errno));
return NULL;
}
- return bo;
-}
-
-LOCAL uint32_t
-intel_driver_shared_name(intel_driver_t *driver, dri_bo *bo)
-{
- uint32_t name;
- assert(bo);
- dri_bo_flink(bo, &name);
- return name;
-}
-/* XXX a null props is ok? */
-static int
-intel_get_device_id(void)
-{
- intel_driver_t *driver = NULL;
- int intel_device_id;
-
- driver = intel_driver_new();
- assert(driver != NULL);
- if (UNLIKELY(intel_driver_open(driver, NULL) != CL_SUCCESS))
- return INVALID_CHIP_ID;
- intel_device_id = driver->device_id;
- intel_driver_context_destroy(driver);
- intel_driver_close(driver);
- intel_driver_terminate(driver);
- intel_driver_delete(driver);
-
- return intel_device_id;
-}
-
-extern void intel_gpgpu_delete_all(intel_driver_t *driver);
-static void
-cl_intel_driver_delete(intel_driver_t *driver)
-{
- if (driver == NULL)
- return;
- intel_gpgpu_delete_all(driver);
- intel_driver_context_destroy(driver);
- intel_driver_close(driver);
- intel_driver_terminate(driver);
- intel_driver_delete(driver);
-}
-
-#include "cl_gbe_loader.h"
-static intel_driver_t *
-cl_intel_driver_new(cl_context_prop props)
-{
- intel_driver_t *driver = NULL;
- TRY_ALLOC_NO_ERR(driver, intel_driver_new());
- if (UNLIKELY(intel_driver_open(driver, props) != CL_SUCCESS))
- goto error;
-exit:
- return driver;
-error:
- cl_intel_driver_delete(driver);
- driver = NULL;
- goto exit;
-}
-
-static drm_intel_bufmgr *
-intel_driver_get_bufmgr(intel_driver_t *drv)
-{
- return drv->bufmgr;
-}
-
-static uint32_t
-intel_driver_get_ver(struct intel_driver *drv)
-{
- return drv->gen_ver;
-}
-
-static void
-intel_driver_enlarge_stack_size(struct intel_driver *drv, int32_t *stack_size)
-{
- if (drv->gen_ver == 75)
- *stack_size = *stack_size * 4;
- else if (drv->device_id == PCI_CHIP_BROXTON_1 || drv->device_id == PCI_CHIP_BROXTON_3 ||
- IS_CHERRYVIEW(drv->device_id))
- *stack_size = *stack_size * 2;
-}
-
-static void
-intel_driver_set_atomic_flag(intel_driver_t *drv, int atomic_flag)
-{
- drv->atomic_test_result = atomic_flag;
+ return bo;
}
-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; }
+LOCAL uint32_t
+intel_driver_shared_name(intel_driver_t *driver, dri_bo *bo)
+{
+ uint32_t name;
+ assert(bo);
+ dri_bo_flink(bo, &name);
+ return name;
+}
-static int get_cl_tiling(uint32_t drm_tiling)
+static int
+get_cl_tiling(uint32_t drm_tiling)
{
switch (drm_tiling) {
case I915_TILING_X:
@@ -515,7 +463,28 @@ static int get_cl_tiling(uint32_t drm_tiling)
return CL_NO_TILE;
}
-static uint32_t intel_buffer_get_tiling_align(cl_context ctx, uint32_t tiling_mode, uint32_t dim)
+static int32_t
+get_intel_tiling(cl_int tiling, uint32_t *intel_tiling)
+{
+ switch (tiling) {
+ case CL_NO_TILE:
+ *intel_tiling = I915_TILING_NONE;
+ break;
+ case CL_TILE_X:
+ *intel_tiling = I915_TILING_X;
+ break;
+ case CL_TILE_Y:
+ *intel_tiling = I915_TILING_Y;
+ break;
+ default:
+ assert(0);
+ return -1;
+ }
+ return 0;
+}
+
+static uint32_t
+intel_buffer_get_tiling_align(cl_context ctx, uint32_t tiling_mode, uint32_t dim)
{
uint32_t gen_ver = ((intel_driver_t *)ctx->drv)->gen_ver;
uint32_t ret = 0;
@@ -567,6 +536,105 @@ static uint32_t intel_buffer_get_tiling_align(cl_context ctx, uint32_t tiling_mo
return ret;
}
+static int
+intel_buffer_set_tiling(cl_buffer bo, cl_image_tiling_t tiling, size_t stride)
+{
+ uint32_t intel_tiling;
+ int ret;
+ if (get_intel_tiling(tiling, &intel_tiling) < 0)
+ return -1;
+
+#ifndef NDEBUG
+ uint32_t required_tiling;
+ required_tiling = intel_tiling;
+#endif
+
+ ret = drm_intel_bo_set_tiling((drm_intel_bo *)bo, &intel_tiling, stride);
+ assert(intel_tiling == required_tiling);
+ return ret;
+}
+
+static cl_buffer
+intel_buffer_alloc_userptr(cl_buffer_mgr bufmgr, const char *name,
+ void *data, size_t size, unsigned long flags)
+{
+#ifdef HAS_USERPTR
+ drm_intel_bo *bo;
+ bo = drm_intel_bo_alloc_userptr((drm_intel_bufmgr *)bufmgr, name, data,
+ I915_TILING_NONE, 0, size, flags);
+ /* Fallback to unsynchronized userptr allocation if kernel has no MMU notifier enabled. */
+ if (bo == NULL)
+ bo = drm_intel_bo_alloc_userptr((drm_intel_bufmgr *)bufmgr, name, data,
+ I915_TILING_NONE, 0, size, flags | I915_USERPTR_UNSYNCHRONIZED);
+ return (cl_buffer)bo;
+#else
+ return NULL;
+#endif
+}
+
+static cl_buffer
+intel_share_buffer_from_libva(cl_context ctx, unsigned int bo_name, size_t *sz)
+{
+ drm_intel_bo *intel_bo;
+
+ intel_bo = intel_driver_share_buffer_from_name((intel_driver_t *)ctx->drv, "shared from libva", bo_name);
+
+ if (intel_bo == NULL)
+ return NULL;
+
+ if (sz)
+ *sz = intel_bo->size;
+
+ return (cl_buffer)intel_bo;
+}
+
+static cl_buffer
+intel_share_image_from_libva(cl_context ctx, unsigned int bo_name, struct _cl_mem_image *image)
+{
+ drm_intel_bo *intel_bo;
+ uint32_t intel_tiling, intel_swizzle_mode;
+
+ intel_bo = intel_driver_share_buffer_from_name((intel_driver_t *)ctx->drv, "shared from libva", bo_name);
+ if (intel_bo == NULL)
+ return NULL;
+
+ drm_intel_bo_get_tiling(intel_bo, &intel_tiling, &intel_swizzle_mode);
+ image->tiling = get_cl_tiling(intel_tiling);
+
+ return (cl_buffer)intel_bo;
+}
+
+static cl_buffer
+intel_share_buffer_from_fd(cl_context ctx, int fd, int buffer_size)
+{
+ drm_intel_bo *intel_bo;
+
+ intel_bo = intel_driver_share_buffer_from_fd((intel_driver_t *)ctx->drv, fd, buffer_size);
+
+ if (intel_bo == NULL)
+ return NULL;
+
+ return (cl_buffer)intel_bo;
+}
+
+static cl_buffer
+intel_share_image_from_fd(cl_context ctx, int fd, int image_size, struct _cl_mem_image *image)
+{
+ drm_intel_bo *intel_bo;
+ uint32_t intel_tiling, intel_swizzle_mode;
+
+ intel_bo = intel_driver_share_buffer_from_fd((intel_driver_t *)ctx->drv, fd, image_size);
+
+ if (intel_bo == NULL)
+ return NULL;
+
+ drm_intel_bo_get_tiling(intel_bo, &intel_tiling, &intel_swizzle_mode);
+ image->tiling = get_cl_tiling(intel_tiling);
+
+ return (cl_buffer)intel_bo;
+}
+
+/********************************* DRI Buffer of EGL *********************************/
#if defined(HAS_GL_EGL)
#include "intel_cl_gl_share_image_info.h"
#include "cl_image.h"
@@ -587,7 +655,8 @@ get_required_egl_extensions()
return 0;
}
-static int cl_get_clformat_from_texture(GLint tex_format, cl_image_format *cl_format)
+static int
+cl_get_clformat_from_texture(GLint tex_format, cl_image_format *cl_format)
{
cl_int ret = CL_SUCCESS;
@@ -701,8 +770,7 @@ intel_alloc_buffer_from_texture_egl(cl_context ctx, unsigned int target,
if (get_required_egl_extensions() != 0)
return NULL;
- EGLAttrib attrib_list[] = {EGL_GL_TEXTURE_LEVEL, miplevel,
- EGL_NONE};
+ 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)
@@ -717,8 +785,8 @@ intel_alloc_buffer_from_texture_egl(cl_context ctx, unsigned int target,
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.
- */
+ * 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);
@@ -758,10 +826,8 @@ 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, info.w, info.h,
- image_type, info.depth, cl_format,
- intel_fmt, bpp, info.row_pitch,
- info.slice_pitch, info.tiling,
+ 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;
@@ -801,126 +867,28 @@ intel_release_buffer_from_texture(cl_context ctx, struct _cl_mem_gl_image *gl_im
}
#endif
-cl_buffer intel_share_buffer_from_libva(cl_context ctx,
- unsigned int bo_name,
- size_t *sz)
-{
- drm_intel_bo *intel_bo;
-
- intel_bo = intel_driver_share_buffer_from_name((intel_driver_t *)ctx->drv, "shared from libva", bo_name);
-
- if (intel_bo == NULL)
- return NULL;
-
- if (sz)
- *sz = intel_bo->size;
-
- return (cl_buffer)intel_bo;
-}
-
-cl_buffer intel_share_image_from_libva(cl_context ctx,
- unsigned int bo_name,
- struct _cl_mem_image *image)
-{
- drm_intel_bo *intel_bo;
- uint32_t intel_tiling, intel_swizzle_mode;
-
- intel_bo = intel_driver_share_buffer_from_name((intel_driver_t *)ctx->drv, "shared from libva", bo_name);
-
- if (intel_bo == NULL)
- return NULL;
-
- drm_intel_bo_get_tiling(intel_bo, &intel_tiling, &intel_swizzle_mode);
- image->tiling = get_cl_tiling(intel_tiling);
-
- return (cl_buffer)intel_bo;
-}
-
-cl_buffer intel_share_buffer_from_fd(cl_context ctx,
- int fd,
- int buffer_size)
-{
- drm_intel_bo *intel_bo;
-
- intel_bo = intel_driver_share_buffer_from_fd((intel_driver_t *)ctx->drv, fd, buffer_size);
-
- if (intel_bo == NULL)
- return NULL;
-
- return (cl_buffer)intel_bo;
-}
-
-cl_buffer intel_share_image_from_fd(cl_context ctx,
- int fd,
- int image_size,
- struct _cl_mem_image *image)
+/********************************* DRI Device *********************************/
+LOCAL int
+intel_get_device_id(void)
{
- drm_intel_bo *intel_bo;
- uint32_t intel_tiling, intel_swizzle_mode;
-
- intel_bo = intel_driver_share_buffer_from_fd((intel_driver_t *)ctx->drv, fd, image_size);
-
- if (intel_bo == NULL)
- return NULL;
-
- drm_intel_bo_get_tiling(intel_bo, &intel_tiling, &intel_swizzle_mode);
- image->tiling = get_cl_tiling(intel_tiling);
-
- return (cl_buffer)intel_bo;
-}
+ intel_driver_t *driver = NULL;
+ int intel_device_id;
-static cl_buffer intel_buffer_alloc_userptr(cl_buffer_mgr bufmgr, const char *name, void *data, size_t size, unsigned long flags)
-{
-#ifdef HAS_USERPTR
- drm_intel_bo *bo;
- bo = drm_intel_bo_alloc_userptr((drm_intel_bufmgr *)bufmgr, name, data, I915_TILING_NONE, 0, size, flags);
- /* Fallback to unsynchronized userptr allocation if kernel has no MMU notifier enabled. */
- if (bo == NULL)
- bo = drm_intel_bo_alloc_userptr((drm_intel_bufmgr *)bufmgr, name, data, I915_TILING_NONE, 0, size, flags | I915_USERPTR_UNSYNCHRONIZED);
- return (cl_buffer)bo;
-#else
- return NULL;
-#endif
-}
+ driver = intel_driver_new();
+ assert(driver != NULL);
+ if (intel_driver_open(driver, NULL) != CL_SUCCESS)
+ return INVALID_CHIP_ID;
-static int32_t get_intel_tiling(cl_int tiling, uint32_t *intel_tiling)
-{
- switch (tiling) {
- case CL_NO_TILE:
- *intel_tiling = I915_TILING_NONE;
- break;
- case CL_TILE_X:
- *intel_tiling = I915_TILING_X;
- break;
- case CL_TILE_Y:
- *intel_tiling = I915_TILING_Y;
- break;
- default:
- assert(0);
- return -1;
- }
- return 0;
-}
+ intel_device_id = driver->device_id;
+ intel_driver_delete(driver);
-static int intel_buffer_set_tiling(cl_buffer bo,
- cl_image_tiling_t tiling, size_t stride)
-{
- uint32_t intel_tiling;
- int ret;
- if (UNLIKELY((get_intel_tiling(tiling, &intel_tiling)) < 0))
- return -1;
-#ifndef NDEBUG
- uint32_t required_tiling;
- required_tiling = intel_tiling;
-#endif
- ret = drm_intel_bo_set_tiling((drm_intel_bo *)bo, &intel_tiling, stride);
- assert(intel_tiling == required_tiling);
- return ret;
+ return intel_device_id;
}
-#define CHV_CONFIG_WARNING \
- "Warning: can't get GPU's configurations, will use the minimal one. Please update your drm to 2.4.59+ and linux kernel to 4.0.0+.\n"
-static void
+#define CHV_CONFIG_WARNING \
+ "Warning: can't get GPU's configurations, will use the minimal one. " \
+ "Please update your drm to 2.4.59+ and linux kernel to 4.0.0+.\n"
+LOCAL void
intel_update_device_info(cl_device_id device)
{
intel_driver_t *driver;
@@ -1005,17 +973,45 @@ intel_update_device_info(cl_device_id device)
if (drm_intel_get_aperture_sizes(driver->fd, &map_mem, &total_mem) == 0)
device->global_mem_size = (cl_ulong)total_mem;
- intel_driver_context_destroy(driver);
- intel_driver_close(driver);
- intel_driver_terminate(driver);
intel_driver_delete(driver);
}
+/********************************* To be deleted *********************************/
+#include "cl_gbe_loader.h"
+
+static drm_intel_bufmgr *
+intel_driver_get_bufmgr(intel_driver_t *drv)
+{
+ return drv->bufmgr;
+}
+
+static uint32_t
+intel_driver_get_ver(struct intel_driver *drv)
+{
+ return drv->gen_ver;
+}
+
+static void
+intel_driver_enlarge_stack_size(struct intel_driver *drv, int32_t *stack_size)
+{
+ if (drv->gen_ver == 75)
+ *stack_size = *stack_size * 4;
+ else if (drv->device_id == PCI_CHIP_BROXTON_1 || drv->device_id == PCI_CHIP_BROXTON_3 ||
+ IS_CHERRYVIEW(drv->device_id))
+ *stack_size = *stack_size * 2;
+}
+
+static void
+intel_driver_set_atomic_flag(intel_driver_t *drv, int atomic_flag)
+{
+ drv->atomic_test_result = atomic_flag;
+}
+
LOCAL void
intel_setup_callbacks(void)
{
- cl_driver_new = (cl_driver_new_cb *)cl_intel_driver_new;
- cl_driver_delete = (cl_driver_delete_cb *)cl_intel_driver_delete;
+ cl_driver_new = (cl_driver_new_cb *)intel_driver_create;
+ cl_driver_delete = (cl_driver_delete_cb *)intel_driver_delete;
cl_driver_get_ver = (cl_driver_get_ver_cb *)intel_driver_get_ver;
cl_driver_enlarge_stack_size = (cl_driver_enlarge_stack_size_cb *)intel_driver_enlarge_stack_size;
cl_driver_set_atomic_flag = (cl_driver_set_atomic_flag_cb *)intel_driver_set_atomic_flag;
@@ -1028,7 +1024,6 @@ intel_setup_callbacks(void)
cl_buffer_set_softpin_offset = (cl_buffer_set_softpin_offset_cb *)drm_intel_bo_set_softpin_offset;
cl_buffer_set_bo_use_full_range = (cl_buffer_set_bo_use_full_range_cb *)drm_intel_bo_use_48b_address_range;
#endif
- cl_buffer_disable_reuse = (cl_buffer_disable_reuse_cb *)drm_intel_bo_disable_reuse;
cl_buffer_set_tiling = (cl_buffer_set_tiling_cb *)intel_buffer_set_tiling;
#if defined(HAS_GL_EGL)
cl_buffer_alloc_from_texture = (cl_buffer_alloc_from_texture_cb *)intel_alloc_buffer_from_texture;
@@ -1054,5 +1049,6 @@ intel_setup_callbacks(void)
cl_buffer_get_tiling_align = (cl_buffer_get_tiling_align_cb *)intel_buffer_get_tiling_align;
cl_buffer_get_buffer_from_fd = (cl_buffer_get_buffer_from_fd_cb *)intel_share_buffer_from_fd;
cl_buffer_get_image_from_fd = (cl_buffer_get_image_from_fd_cb *)intel_share_image_from_fd;
+ cl_buffer_disable_reuse = (cl_buffer_disable_reuse_cb *)drm_intel_bo_disable_reuse;
intel_set_gpgpu_callbacks(intel_get_device_id());
}
diff --git a/src/gen/intel_driver.h b/src/gen/intel_driver.h
index 0b54689..bb517d5 100644
--- a/src/gen/intel_driver.h
+++ b/src/gen/intel_driver.h
@@ -45,6 +45,7 @@
#define _INTEL_DRIVER_H_
#include "cl_device_data.h"
+#include "cl_context.h"
#include <stdint.h>
#include <pthread.h>
@@ -54,7 +55,6 @@
#include <drm.h>
#include <i915_drm.h>
#include <intel_bufmgr.h>
-#include <intel/intel_gpgpu.h>
#define CMD_MI (0x0 << 29)
#define CMD_2D (0x2 << 29)
@@ -121,31 +121,17 @@ typedef struct intel_driver {
RESTORE_BLOCKED_SIGSET(DRIVER); \
} while (0)
-/* device control */
extern void intel_driver_lock_hardware(intel_driver_t *);
extern void intel_driver_unlock_hardware(intel_driver_t *);
+extern intel_driver_t *intel_driver_create(cl_context_prop props);
+extern void intel_driver_delete(intel_driver_t *driver);
+extern void intel_update_device_info(cl_device_id device);
+extern int intel_get_device_id(void);
/* methods working in shared mode */
extern dri_bo *intel_driver_share_buffer(intel_driver_t *, const char *sname, uint32_t name);
extern uint32_t intel_driver_shared_name(intel_driver_t *, dri_bo *);
-/* init driver shared with X using dri state, acquired from X Display */
-extern int intel_driver_init_shared(intel_driver_t *, struct dri_state *);
-
-/* init driver in master mode (when X is not using the card)
- * usually dev_name = "/dev/dri/card0"
- */
-extern int intel_driver_init_master(intel_driver_t *, const char *dev_name);
-
-/* init driver for render node */
-extern int intel_driver_init_render(intel_driver_t *, const char *dev_name);
-
-/* terminate driver and all underlying structures */
-extern int intel_driver_terminate(intel_driver_t *);
-
-/* simple check if driver was initialized (checking fd should suffice) */
-extern int intel_driver_is_active(intel_driver_t *);
-
/* init the call backs used by the ocl driver */
extern void intel_setup_callbacks(void);
--
2.7.4
More information about the Beignet
mailing list