}
cl_mem
+clCreateImage(cl_context context,
+ cl_mem_flags flags,
+ const cl_image_format *image_format,
+ const cl_image_desc *image_desc,
+ void *host_ptr,
+ cl_int * errcode_ret)
+{
+ cl_mem mem = NULL;
+ cl_int err = CL_SUCCESS;
+ CHECK_CONTEXT (context);
+
+ mem = cl_mem_new_image(context,
+ flags,
+ image_format,
+ image_desc,
+ host_ptr,
+ errcode_ret);
+error:
+ if (errcode_ret)
+ *errcode_ret = err;
+ return mem;
+}
+
+cl_mem
clCreateImage2D(cl_context context,
cl_mem_flags flags,
const cl_image_format * image_format,
cl_mem mem = NULL;
cl_int err = CL_SUCCESS;
CHECK_CONTEXT (context);
-
- mem = cl_mem_new_image2D(context,
- flags,
- image_format,
- image_width,
- image_height,
- image_row_pitch,
- host_ptr,
- errcode_ret);
+ cl_image_desc image_desc;
+
+ image_desc.image_type = CL_MEM_OBJECT_IMAGE2D;
+ image_desc.image_width = image_width;
+ image_desc.image_height = image_height;
+ image_desc.image_row_pitch = image_row_pitch;
+
+ mem = cl_mem_new_image(context,
+ flags,
+ image_format,
+ &image_desc,
+ host_ptr,
+ errcode_ret);
error:
if (errcode_ret)
*errcode_ret = err;
offset = gbe_kernel_get_curbe_offset(k->opaque, GBE_CURBE_KERNEL_ARGUMENT, i);
if (arg_type == GBE_ARG_IMAGE) {
uint32_t *curbe_index = (uint32_t*)(k->curbe + offset);
- cl_gpgpu_bind_image2D(queue->gpgpu, curbe_index, k->args[i].mem->bo,
- k->args[i].mem->intel_fmt, k->args[i].mem->w,
- k->args[i].mem->h, k->args[i].mem->pitch,
- k->args[i].mem->tiling);
+ cl_gpgpu_bind_image(queue->gpgpu, curbe_index, k->args[i].mem->bo,
+ k->args[i].mem->intel_fmt, k->args[i].mem->type,
+ k->args[i].mem->w, k->args[i].mem->h,
+ k->args[i].mem->pitch, k->args[i].mem->tiling);
} else if (arg_type == GBE_ARG_SAMPLER) {
uint32_t *curbe_index = (uint32_t*)(k->curbe + offset);
cl_gpgpu_insert_sampler(queue->gpgpu, curbe_index, k->args[i].sampler);
extern cl_gpgpu_insert_sampler_cb *cl_gpgpu_insert_sampler;
/* Set a 2d texture */
-typedef void (cl_gpgpu_bind_image2D_cb)(cl_gpgpu state,
+typedef void (cl_gpgpu_bind_image_cb)(cl_gpgpu state,
uint32_t *curbe_index,
cl_buffer obj_bo,
uint32_t format,
+ uint32_t type,
int32_t w,
int32_t h,
int pitch,
cl_gpgpu_tiling tiling);
-extern cl_gpgpu_bind_image2D_cb *cl_gpgpu_bind_image2D;
+extern cl_gpgpu_bind_image_cb *cl_gpgpu_bind_image;
/* Setup a stack */
typedef void (cl_gpgpu_set_stack_cb)(cl_gpgpu, uint32_t offset, uint32_t size, uint32_t cchint);
#include <GL/gl.h>
#include "CL/cl.h"
-typedef cl_buffer (cl_buffer_alloc_from_texture_cb)(cl_context, cl_mem_flags, GLenum, GLint, GLuint, GLuint);
+typedef cl_buffer (cl_buffer_alloc_from_texture_cb)(cl_context, cl_mem_flags, GLenum, GLint, GLuint);
extern cl_buffer_alloc_from_texture_cb *cl_buffer_alloc_from_texture;
/* Unref a buffer and destroy it if no more ref */
LOCAL cl_gpgpu_delete_cb *cl_gpgpu_delete = NULL;
LOCAL cl_gpgpu_bind_buf_cb *cl_gpgpu_bind_buf = NULL;
LOCAL cl_gpgpu_set_stack_cb *cl_gpgpu_set_stack = NULL;
-LOCAL cl_gpgpu_bind_image2D_cb *cl_gpgpu_bind_image2D = NULL;
+LOCAL cl_gpgpu_bind_image_cb *cl_gpgpu_bind_image = NULL;
LOCAL cl_gpgpu_state_init_cb *cl_gpgpu_state_init = NULL;
LOCAL cl_gpgpu_set_perf_counters_cb *cl_gpgpu_set_perf_counters = NULL;
LOCAL cl_gpgpu_upload_constants_cb *cl_gpgpu_upload_constants = NULL;
} \
} while (0)
-
cl_mem
clCreateFromGLBuffer(cl_context context,
cl_mem_flags flags,
CHECK_CONTEXT (context);
CHECK_GL_CONTEXT (context);
- mem = cl_mem_new_gl_texture(context, flags, texture_target, miplevel, texture, 2, &err);
+ mem = cl_mem_new_gl_texture(context, flags, texture_target, miplevel, texture, &err);
error:
if (errcode_ret)
*errcode_ret = err;
CHECK_CONTEXT (context);
CHECK_GL_CONTEXT (context);
- mem = cl_mem_new_gl_texture(context, flags, texture_target, miplevel, texture, 3, &err);
+ mem = cl_mem_new_gl_texture(context, flags, texture_target, miplevel, texture, &err);
error:
if (errcode_ret)
*errcode_ret = err;
return mem;
}
+cl_mem
+clCreateFromGLTexture(cl_context context,
+ cl_mem_flags flags,
+ cl_GLenum target,
+ cl_GLint miplevel,
+ cl_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, target, miplevel, texture, &err);
+error:
+ if (errcode_ret)
+ *errcode_ret = err;
+ return mem;
+
+}
+
/* XXX NULL function currently. */
cl_int clEnqueueAcquireGLObjects (cl_command_queue command_queue,
cl_uint num_objects,
cl_buffer_unmap(mem->bo);
}
-LOCAL cl_mem
-cl_mem_new_image2D(cl_context ctx,
- cl_mem_flags flags,
- const cl_image_format *fmt,
- size_t w,
- size_t h,
- size_t pitch,
- void *data,
- cl_int *errcode_ret)
+static cl_mem
+_cl_mem_new_image(cl_context ctx,
+ cl_mem_flags flags,
+ const cl_image_format *fmt,
+ const cl_mem_object_type image_type,
+ size_t w,
+ size_t h,
+ size_t pitch,
+ int depth,
+ void *data,
+ cl_int *errcode_ret)
{
cl_int err = CL_SUCCESS;
cl_mem mem = NULL;
} while (0);
if (UNLIKELY(w == 0)) DO_IMAGE_ERROR;
if (UNLIKELY(h == 0)) DO_IMAGE_ERROR;
- if (UNLIKELY(w > ctx->device->image2d_max_width)) DO_IMAGE_ERROR;
- if (UNLIKELY(h > ctx->device->image2d_max_height)) DO_IMAGE_ERROR;
- if (UNLIKELY(bpp*w > pitch)) DO_IMAGE_ERROR;
-#undef DO_IMAGE_ERROR
- /* Pick up tiling mode (we do only linear on SNB) */
- if (cl_driver_get_ver(ctx->drv) != 6)
- tiling = CL_TILE_Y;
+ if (image_type == CL_MEM_OBJECT_IMAGE2D) {
+ if (UNLIKELY(w > ctx->device->image2d_max_width)) DO_IMAGE_ERROR;
+ if (UNLIKELY(h > ctx->device->image2d_max_height)) DO_IMAGE_ERROR;
+ if (UNLIKELY(data && (bpp*w > pitch))) DO_IMAGE_ERROR;
+
+ /* Pick up tiling mode (we do only linear on SNB) */
+ if (cl_driver_get_ver(ctx->drv) != 6)
+ tiling = CL_TILE_Y;
+ }
+#undef DO_IMAGE_ERROR
/* Tiling requires to align both pitch and height */
if (tiling == CL_NO_TILE) {
mem->is_image = 1;
mem->pitch = aligned_pitch;
mem->tiling = tiling;
+ mem->type = image_type;
exit:
if (errcode_ret)
goto exit;
}
+LOCAL cl_mem
+cl_mem_new_image(cl_context context,
+ cl_mem_flags flags,
+ const cl_image_format *image_format,
+ const cl_image_desc *image_desc,
+ void *host_ptr,
+ cl_int *errcode_ret)
+{
+ switch (image_desc->image_type) {
+ case CL_MEM_OBJECT_IMAGE1D:
+ case CL_MEM_OBJECT_IMAGE2D:
+ return _cl_mem_new_image(context, flags, image_format, image_desc->image_type,
+ image_desc->image_width, image_desc->image_height,
+ image_desc->image_row_pitch, image_desc->image_depth,
+ host_ptr, errcode_ret);
+ case CL_MEM_OBJECT_IMAGE3D:
+ case CL_MEM_OBJECT_IMAGE2D_ARRAY:
+ case CL_MEM_OBJECT_IMAGE1D_ARRAY:
+ case CL_MEM_OBJECT_IMAGE1D_BUFFER:
+ NOT_IMPLEMENTED;
+ break;
+ case CL_MEM_OBJECT_BUFFER:
+ default:
+ assert(0);
+ }
+ return NULL;
+}
+
LOCAL void
cl_mem_delete(cl_mem mem)
{
cl_mem_flags flags; /* Flags specified at the creation time */
uint32_t is_image; /* Indicate if this is an image or not */
cl_image_format fmt; /* only for images */
+ cl_mem_object_type type; /* only for images 1D/2D...*/
size_t w,h,depth,pitch; /* only for images (depth is only for 3d images) */
uint32_t intel_fmt; /* format to provide in the surface state */
uint32_t bpp; /* number of bytes per pixel */
extern cl_mem cl_mem_new(cl_context, cl_mem_flags, size_t, void*, cl_int*);
/* Idem but this is an image */
-extern cl_mem cl_mem_new_image2D(cl_context,
- cl_mem_flags,
- const cl_image_format*,
- size_t w,
- size_t h,
- size_t pitch,
- void *,
- cl_int *);
+extern cl_mem
+cl_mem_new_image(cl_context context,
+ cl_mem_flags flags,
+ const cl_image_format *image_format,
+ const cl_image_desc *image_desc,
+ void *host_ptr,
+ cl_int *errcode_ret);
cl_mem cl_mem_new_gl_buffer(cl_context ctx,
cl_mem_flags flags,
GLenum texture_target,
GLint miplevel,
GLuint texture,
- GLuint dim,
cl_int *errcode_ret);
/* Unref the object and delete it if no more reference */
*
* Author: Zhigang Gong <zhigang.gong@intel.com>
*/
-
#include "cl_mem.h"
#include "cl_image.h"
#include "cl_context.h"
return ret;
}
+static cl_mem_object_type
+get_mem_type_from_target(GLenum texture_target)
+{
+ switch(texture_target) {
+ case GL_TEXTURE_1D: return CL_MEM_OBJECT_IMAGE1D;
+ case GL_TEXTURE_2D: return CL_MEM_OBJECT_IMAGE2D;
+ case GL_TEXTURE_3D: return CL_MEM_OBJECT_IMAGE3D;
+ case GL_TEXTURE_1D_ARRAY: return CL_MEM_OBJECT_IMAGE1D_ARRAY;
+ case GL_TEXTURE_2D_ARRAY: return CL_MEM_OBJECT_IMAGE2D_ARRAY;
+ default:
+ assert(0);
+ }
+ return 0;
+}
+
static int cl_mem_process_texture(cl_context ctx,
cl_mem_flags flags,
GLenum texture_target,
GLint miplevel,
GLuint texture,
- GLuint dim,
cl_mem mem)
{
cl_int err = CL_SUCCESS;
uint32_t intel_fmt, bpp, aligned_pitch;
int w,h;
- if ((dim == 2 && texture_target != GL_TEXTURE_2D)
- || (dim == 3 && texture_target != GL_TEXTURE_3D)) {
- err = CL_INVALID_IMAGE_DESCRIPTOR;
- goto error;
- }
-
- if (dim == 2)
- glBindTexture(GL_TEXTURE_2D, texture);
- else if (dim == 3)
- glBindTexture(GL_TEXTURE_3D, texture);
-
- glTexParameteri(GL_TEXTURE_2D,
- GL_TEXTURE_MIN_FILTER,
- GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D,
- GL_TEXTURE_MAG_FILTER,
- GL_NEAREST);
-
+ glBindTexture(texture_target, texture);
glGetTexLevelParameteriv(texture_target, miplevel, GL_TEXTURE_WIDTH, &w);
glGetTexLevelParameteriv(texture_target, miplevel, GL_TEXTURE_HEIGHT, &h);
glGetTexLevelParameteriv(texture_target, miplevel, GL_TEXTURE_INTERNAL_FORMAT, &tex_format);
cl_get_clformat_from_texture(tex_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) {
cl_image_byte_per_pixel(&cl_format, &bpp);
/* XXX What's the tiling? */
- aligned_pitch = w * bpp;
+ mem->type = get_mem_type_from_target(texture_target);
+ aligned_pitch = ALIGN(w * bpp, 512); /*default tile format is tilex, the width should be 512 alignment.*/
mem->w = w;
mem->h = h;
mem->fmt = cl_format;
LOCAL cl_mem cl_mem_new_gl_texture(cl_context ctx,
- cl_mem_flags flags,
- GLenum texture_target,
- GLint miplevel,
- GLuint texture,
- GLuint dim,
- cl_int *errcode_ret)
+ cl_mem_flags flags,
+ GLenum texture_target,
+ GLint miplevel,
+ GLuint texture,
+ cl_int *errcode_ret)
{
cl_int err = CL_SUCCESS;
cl_mem mem = NULL;
}
TRY_ALLOC (mem, CALLOC(struct _cl_mem));
- if (cl_mem_process_texture(ctx, flags, texture_target, miplevel, texture, dim, mem) != CL_SUCCESS) {
+ if (cl_mem_process_texture(ctx, flags, texture_target, miplevel, texture, mem) != CL_SUCCESS) {
printf("invalid texture.\n");
err = CL_INVALID_IMAGE_DESCRIPTOR;
goto error;
}
- mem->bo = cl_buffer_alloc_from_texture(ctx, flags, texture_target, miplevel, texture, dim);
+ mem->bo = cl_buffer_alloc_from_texture(ctx, flags, texture_target, miplevel, texture);
if (UNLIKELY(mem->bo == NULL)) {
err = CL_MEM_OBJECT_ALLOCATION_FAILURE;
cl_mem_flags flags,
GLenum texture_target,
GLint miplevel,
- GLuint texture,
- GLuint dim)
+ GLuint texture)
{
GLuint name;
drm_intel_bo *bo;
return slot - max_sampler_n;
}
+static int
+intel_get_surface_type(cl_mem_object_type type)
+{
+ switch (type) {
+ case CL_MEM_OBJECT_IMAGE1D: return I965_SURFACE_1D;
+ case CL_MEM_OBJECT_IMAGE2D: return I965_SURFACE_2D;
+ case CL_MEM_OBJECT_IMAGE3D: return I965_SURFACE_3D;
+ case CL_MEM_OBJECT_IMAGE1D_BUFFER:
+ case CL_MEM_OBJECT_IMAGE2D_ARRAY:
+ case CL_MEM_OBJECT_IMAGE1D_ARRAY:
+ NOT_IMPLEMENTED;
+ break;
+ default:
+ assert(0);
+ }
+}
+
static void
-intel_gpgpu_bind_image2D_gen7(intel_gpgpu_t *gpgpu,
+intel_gpgpu_bind_image_gen7(intel_gpgpu_t *gpgpu,
uint32_t *curbe_index,
dri_bo* obj_bo,
uint32_t format,
+ cl_mem_object_type type,
int32_t w,
int32_t h,
int32_t pitch,
gen7_surface_state_t *ss = (gen7_surface_state_t *) heap->surface[index];
memset(ss, 0, sizeof(*ss));
- ss->ss0.surface_type = I965_SURFACE_2D;
+
+ ss->ss0.surface_type = intel_get_surface_type(type);
ss->ss0.surface_format = format;
ss->ss1.base_addr = obj_bo->offset;
ss->ss2.width = w - 1;
}
static void
-intel_gpgpu_bind_image2D(intel_gpgpu_t *gpgpu,
- uint32_t *index,
- cl_buffer *obj_bo,
- uint32_t format,
- int32_t w,
- int32_t h,
- int32_t pitch,
- cl_gpgpu_tiling tiling)
-{
- intel_gpgpu_bind_image2D_gen7(gpgpu, index, (drm_intel_bo*) obj_bo, format, w, h, pitch, tiling);
+intel_gpgpu_bind_image(intel_gpgpu_t *gpgpu,
+ uint32_t *index,
+ cl_buffer *obj_bo,
+ uint32_t format,
+ cl_mem_object_type type,
+ int32_t w,
+ int32_t h,
+ int32_t pitch,
+ cl_gpgpu_tiling tiling)
+{
+ intel_gpgpu_bind_image_gen7(gpgpu, index, (drm_intel_bo*) obj_bo, format, type, w, h, pitch, tiling);
assert(*index < GEN_MAX_SURFACES);
}
{
cl_gpgpu_new = (cl_gpgpu_new_cb *) intel_gpgpu_new;
cl_gpgpu_delete = (cl_gpgpu_delete_cb *) intel_gpgpu_delete;
- cl_gpgpu_bind_image2D = (cl_gpgpu_bind_image2D_cb *) intel_gpgpu_bind_image2D;
+ cl_gpgpu_bind_image = (cl_gpgpu_bind_image_cb *) intel_gpgpu_bind_image;
cl_gpgpu_bind_buf = (cl_gpgpu_bind_buf_cb *) intel_gpgpu_bind_buf;
cl_gpgpu_set_stack = (cl_gpgpu_set_stack_cb *) intel_gpgpu_set_stack;
cl_gpgpu_state_init = (cl_gpgpu_state_init_cb *) intel_gpgpu_state_init;