func CLCreateImage2D(context CL_context, flags CL_mem_flags, image_format *CL_image_format, image_width CL_size_t, image_height CL_size_t, image_row_pitch CL_size_t, host_ptr unsafe.Pointer, errcode_ret *CL_int) CL_mem { var c_image_format C.cl_image_format var c_errcode_ret C.cl_int var c_image C.cl_mem c_image_format.image_channel_order = C.cl_channel_order(image_format.Image_channel_order) c_image_format.image_channel_data_type = C.cl_channel_type(image_format.Image_channel_data_type) c_image = C.clCreateImage2D(context.cl_context, C.cl_mem_flags(flags), &c_image_format, C.size_t(image_width), C.size_t(image_height), C.size_t(image_row_pitch), host_ptr, &c_errcode_ret) if errcode_ret != nil { *errcode_ret = CL_int(c_errcode_ret) } return CL_mem{c_image} }
func (ctx *Context) CreateImage(flags MemFlag, imageFormat ImageFormat, imageDesc ImageDescription, data []byte) (*MemObject, error) { format := imageFormat.toCl() desc := imageDesc.toCl() var dataPtr unsafe.Pointer if data != nil { dataPtr = unsafe.Pointer(&data[0]) } var err C.cl_int clBuffer := C.clCreateImage(ctx.clContext, C.cl_mem_flags(flags), &format, &desc, dataPtr, &err) if err == C.CL_INVALID_OPERATION { // retry with deprecated functions switch imageDesc.Type { case MemObjectTypeImage2D: clBuffer = C.clCreateImage2D(ctx.clContext, C.cl_mem_flags(flags), &format, C.size_t(imageDesc.Width), C.size_t(imageDesc.Height), C.size_t(imageDesc.RowPitch), dataPtr, &err) } } if err != C.CL_SUCCESS { return nil, toError(err) } if clBuffer == nil { return nil, ErrUnknown } return newMemObject(clBuffer, len(data)), nil }
func (ctx *Context) CreateImage2D(flags MemFlag, imageFormat ImageFormat, width, height, rowPitch int, data []byte) (*MemObject, error) { format := imageFormat.toCl() var dataPtr unsafe.Pointer if data != nil { dataPtr = unsafe.Pointer(&data[0]) } var err C.cl_int clBuffer := C.clCreateImage2D(ctx.clContext, C.cl_mem_flags(flags), &format, C.size_t(width), C.size_t(height), C.size_t(rowPitch), dataPtr, &err) if err != C.CL_SUCCESS { return nil, toError(err) } if clBuffer == nil { return nil, ErrUnknown } return newMemObject(clBuffer, len(data)), nil }
func (c *Context) NewImage2D(flags MemFlags, order ChannelOrder, dataType ChannelType, width, height, rowPitch uint32, data *byte) (*Image, error) { var c_buffer C.cl_mem var err C.cl_int format := new(C.cl_image_format) format.image_channel_order = C.cl_channel_order(order) format.image_channel_data_type = C.cl_channel_type(dataType) if c_buffer = C.clCreateImage2D(c.id, C.cl_mem_flags(flags), format, C.size_t(width), C.size_t(height), C.size_t(rowPitch), unsafe.Pointer(data), &err); err != C.CL_SUCCESS { return nil, Cl_error(err) } image := &Image{id: c_buffer, w: width, h: height, hostptr: data} runtime.SetFinalizer(image, (*Image).release) return image, nil }
func (c *Context) NewImage2D(flags MemoryFlags, format ImageFormat, width, height, rowPitch uint32, data *byte) (*Image, error) { var c_buffer C.cl_mem var err C.cl_int c_format := &C.cl_image_format{ image_channel_order: C.cl_channel_order(format.ChannelOrder), image_channel_data_type: C.cl_channel_type(format.ChannelDataType)} if c_buffer = C.clCreateImage2D(c.id, C.cl_mem_flags(flags), c_format, C.size_t(width), C.size_t(height), C.size_t(rowPitch), unsafe.Pointer(data), &err); err != C.CL_SUCCESS { return nil, Cl_error(err) } image := &Image{id: c_buffer, format: format, properties: make(map[ImageProperty]Size)} runtime.SetFinalizer(image, (*Image).release) return image, nil }
// see https://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateImage2D.html func CreateImage2D(context Context, flags MemFlags, imageFormat ImageFormat, imageWidth, imageHeight, imageRowPitch uint64, hostptr unsafe.Pointer, errcode *ErrorCode) Mem { return Mem(C.clCreateImage2D(context.clContext, C.cl_mem_flags(flags), imageFormat.toC(), C.size_t(imageWidth), C.size_t(imageHeight), C.size_t(imageRowPitch), hostptr, (*C.cl_int)(unsafe.Pointer(errcode)))) }