From: Yang Rong Date: Thu, 26 Jun 2014 13:31:23 +0000 (+0800) Subject: Fix call cl_mem_copy_image_region bug. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2e23c56325168ef5bf73e6d5ce0ccef439f36dc2;p=contrib%2Fbeignet.git Fix call cl_mem_copy_image_region bug. When call cl_mem_copy_image_region, sometimes need add offset to src or dst address, sometimes need not add. Add two parameter to indicate it. Also fix the wrong offset when clEnqueueMapImage of CL_MEM_USE_HOST_PTR. Signed-off-by: Yang Rong Reviewed-by: Zhigang Gong --- diff --git a/src/cl_api.c b/src/cl_api.c index 6f3f67b..d54ada6 100644 --- a/src/cl_api.c +++ b/src/cl_api.c @@ -2550,7 +2550,7 @@ static cl_int _cl_map_mem(cl_mem mem, void *ptr, void **mem_ptr, if(mem->flags & CL_MEM_USE_HOST_PTR) { assert(mem->host_ptr); //only calc ptr here, will do memcpy in enqueue - *mem_ptr = mem->host_ptr + offset + sub_offset; + *mem_ptr = (char *)mem->host_ptr + offset + sub_offset; } else { *mem_ptr = ptr; } @@ -2700,6 +2700,7 @@ clEnqueueMapImage(cl_command_queue command_queue, cl_int err = CL_SUCCESS; void *ptr = NULL; void *mem_ptr = NULL; + size_t offset = 0; enqueue_data *data, no_wait_data = { 0 }; CHECK_QUEUE(command_queue); @@ -2730,8 +2731,6 @@ clEnqueueMapImage(cl_command_queue command_queue, goto error; } - size_t offset = image->bpp*origin[0] + image->row_pitch*origin[1] + image->slice_pitch*origin[2]; - TRY(cl_event_check_waitlist, num_events_in_wait_list, event_wait_list, event, mem->ctx); data = &no_wait_data; @@ -2740,7 +2739,6 @@ clEnqueueMapImage(cl_command_queue command_queue, data->origin[0] = origin[0]; data->origin[1] = origin[1]; data->origin[2] = origin[2]; data->region[0] = region[0]; data->region[1] = region[1]; data->region[2] = region[2]; data->ptr = ptr; - data->offset = offset; data->unsync_map = 1; if(handle_events(command_queue, num_events_in_wait_list, event_wait_list, @@ -2757,14 +2755,13 @@ clEnqueueMapImage(cl_command_queue command_queue, goto error; } } - err = _cl_map_mem(mem, ptr, &mem_ptr, offset, 0, origin, region); - if (err != CL_SUCCESS) - goto error; if(mem->flags & CL_MEM_USE_HOST_PTR) { if (image_slice_pitch) *image_slice_pitch = image->host_slice_pitch; *image_row_pitch = image->host_row_pitch; + + offset = image->bpp*origin[0] + image->host_row_pitch*origin[1] + image->host_slice_pitch*origin[2]; } else { if (image_slice_pitch) *image_slice_pitch = image->slice_pitch; @@ -2772,7 +2769,10 @@ clEnqueueMapImage(cl_command_queue command_queue, *image_row_pitch = image->slice_pitch; else *image_row_pitch = image->row_pitch; + + offset = image->bpp*origin[0] + image->row_pitch*origin[1] + image->slice_pitch*origin[2]; } + err = _cl_map_mem(mem, ptr, &mem_ptr, offset, 0, origin, region); error: if (errcode_ret) diff --git a/src/cl_enqueue.c b/src/cl_enqueue.c index 11f1680..7fa44ff 100644 --- a/src/cl_enqueue.c +++ b/src/cl_enqueue.c @@ -235,11 +235,11 @@ cl_int cl_enqueue_write_image(enqueue_data *data) err = CL_MAP_FAILURE; goto error; } - + //dst need to add offset cl_mem_copy_image_region(data->origin, data->region, dst_ptr, image->row_pitch, image->slice_pitch, data->const_ptr, data->row_pitch, - data->slice_pitch, image); + data->slice_pitch, image, CL_TRUE, CL_FALSE); err = cl_mem_unmap_auto(mem); error: @@ -304,9 +304,10 @@ cl_int cl_enqueue_map_image(enqueue_data *data) if(mem->flags & CL_MEM_USE_HOST_PTR) { assert(mem->host_ptr); + //src and dst need add offset in function cl_mem_copy_image_region cl_mem_copy_image_region(data->origin, data->region, mem->host_ptr, image->host_row_pitch, image->host_slice_pitch, - data->ptr, row_pitch, image->slice_pitch, image); + data->ptr, row_pitch, image->slice_pitch, image, CL_TRUE, CL_TRUE); } error: @@ -355,13 +356,15 @@ cl_int cl_enqueue_unmap_mem_object(enqueue_data *data) memcpy(v_ptr, mapped_ptr, mapped_size); } else { CHECK_IMAGE(memobj, image); + if (image->image_type == CL_MEM_OBJECT_IMAGE1D_ARRAY) row_pitch = image->slice_pitch; else row_pitch = image->row_pitch; + //v_ptr have added offset, host_ptr have not added offset. cl_mem_copy_image_region(origin, region, v_ptr, row_pitch, image->slice_pitch, memobj->host_ptr, image->host_row_pitch, image->host_slice_pitch, - image); + image, CL_FALSE, CL_TRUE); } } else { assert(v_ptr == mapped_ptr); diff --git a/src/cl_mem.c b/src/cl_mem.c index ff128af..70bc3eb 100644 --- a/src/cl_mem.c +++ b/src/cl_mem.c @@ -521,10 +521,16 @@ void cl_mem_copy_image_region(const size_t *origin, const size_t *region, void *dst, size_t dst_row_pitch, size_t dst_slice_pitch, const void *src, size_t src_row_pitch, size_t src_slice_pitch, - const struct _cl_mem_image *image) + const struct _cl_mem_image *image, cl_bool offset_dst, cl_bool offset_src) { - size_t offset = image->bpp * origin[0] + dst_row_pitch * origin[1] + dst_slice_pitch * origin[2]; - dst = (char*)dst + offset; + if(offset_dst) { + size_t dst_offset = image->bpp * origin[0] + dst_row_pitch * origin[1] + dst_slice_pitch * origin[2]; + dst = (char*)dst + dst_offset; + } + if(offset_src) { + size_t src_offset = image->bpp * origin[0] + src_row_pitch * origin[1] + src_slice_pitch * origin[2]; + src = (char*)src + src_offset; + } if (!origin[0] && region[0] == image->w && dst_row_pitch == src_row_pitch && (region[2] == 1 || (!origin[1] && region[1] == image->h && dst_slice_pitch == src_slice_pitch))) { @@ -585,7 +591,7 @@ cl_mem_copy_image(struct _cl_mem_image *image, size_t region[3] = {image->w, image->h, image->depth}; cl_mem_copy_image_region(origin, region, dst_ptr, image->row_pitch, image->slice_pitch, - host_ptr, row_pitch, slice_pitch, image); + host_ptr, row_pitch, slice_pitch, image, CL_FALSE, CL_FALSE); //offset is 0 cl_mem_unmap_auto((cl_mem)image); } diff --git a/src/cl_mem.h b/src/cl_mem.h index 7e9aa83..4477240 100644 --- a/src/cl_mem.h +++ b/src/cl_mem.h @@ -264,7 +264,7 @@ void cl_mem_copy_image_region(const size_t *origin, const size_t *region, void *dst, size_t dst_row_pitch, size_t dst_slice_pitch, const void *src, size_t src_row_pitch, size_t src_slice_pitch, - const struct _cl_mem_image *image); + const struct _cl_mem_image *image, cl_bool offset_dst, cl_bool offset_src); void cl_mem_copy_image_to_image(const size_t *dst_origin,const size_t *src_origin, const size_t *region,