diff options
author | Denis Steckelmacher <steckdenis@yahoo.fr> | 2011-07-27 20:16:06 +0200 |
---|---|---|
committer | Denis Steckelmacher <steckdenis@yahoo.fr> | 2011-07-27 20:16:06 +0200 |
commit | 1eaf54d98364b275fb33b7b4671b2fe660cb678b (patch) | |
tree | 639090a6a0339f83cc29c7ae226766fddf7e2819 | |
parent | 9846ba66a2652fcac682daf961f7c059ea2df2e6 (diff) |
Implement clCreateImage3D
-rw-r--r-- | src/api/api_memory.cpp | 26 | ||||
-rw-r--r-- | src/core/memobject.cpp | 39 | ||||
-rw-r--r-- | tests/test_mem.cpp | 24 |
3 files changed, 76 insertions, 13 deletions
diff --git a/src/api/api_memory.cpp b/src/api/api_memory.cpp index 602b9b1..91b2271 100644 --- a/src/api/api_memory.cpp +++ b/src/api/api_memory.cpp @@ -139,7 +139,31 @@ clCreateImage3D(cl_context context, void * host_ptr, cl_int * errcode_ret) { - return 0; + cl_int dummy_errcode; + + if (!errcode_ret) + errcode_ret = &dummy_errcode; + + if (!context) + { + *errcode_ret = CL_INVALID_CONTEXT; + return 0; + } + + *errcode_ret = CL_SUCCESS; + + Coal::Image3D *image = new Coal::Image3D(context, image_width, image_height, + image_depth, image_row_pitch, + image_slice_pitch, image_format, + host_ptr, flags, errcode_ret); + + if (*errcode_ret != CL_SUCCESS || (*errcode_ret = image->init()) != CL_SUCCESS) + { + delete image; + return 0; + } + + return (cl_mem)image; } cl_int diff --git a/src/core/memobject.cpp b/src/core/memobject.cpp index 1213282..048e4e0 100644 --- a/src/core/memobject.cpp +++ b/src/core/memobject.cpp @@ -671,20 +671,43 @@ Image3D::Image3D(Context *ctx, size_t width, size_t height, size_t depth, const cl_image_format *format, void *host_ptr, cl_mem_flags flags, cl_int *errcode_ret) : Image2D(ctx, width, height, row_pitch, format, host_ptr, flags, errcode_ret), - p_depth(depth), p_slice_pitch(slice_pitch) + p_depth(depth) { + if (depth <= 1) + { + *errcode_ret = CL_INVALID_IMAGE_SIZE; + return; + } + + // Slice pitch + p_slice_pitch = height * this->row_pitch(); + + if (slice_pitch) + { + if (!host_ptr) + { + // slice_pitch must be 0 if host_ptr is null + *errcode_ret = CL_INVALID_IMAGE_SIZE; + return; + } + if (slice_pitch < p_slice_pitch) + { + *errcode_ret = CL_INVALID_IMAGE_SIZE; + return; + } + if (slice_pitch % this->row_pitch() != 0) + { + *errcode_ret = CL_INVALID_IMAGE_SIZE; + return; + } + p_slice_pitch = slice_pitch; + } } size_t Image3D::size() const { - if (slice_pitch()) - return depth() * slice_pitch(); - else - if (row_pitch()) - return depth() * height() * row_pitch(); - else - return depth() * height() * width() * pixel_size(format()); + return depth() * slice_pitch(); } MemObject::Type Image3D::type() const diff --git a/tests/test_mem.cpp b/tests/test_mem.cpp index 7b2f935..18b5d04 100644 --- a/tests/test_mem.cpp +++ b/tests/test_mem.cpp @@ -251,18 +251,26 @@ END_TEST START_TEST (test_images) { cl_context ctx; - cl_mem image2d; + cl_mem image2d, image3d; cl_int result; unsigned char image2d_data_24bpp[] = { - 255, 0, 0, 0, 255, 0, - 0, 0, 255, 255, 255, 0 + 255, 0, 0, 0, 0, 255, 0, 0, + 0, 0, 255, 0, 255, 255, 0, 0 + }; + + unsigned char image3d_data_24bpp[] = { + 255, 0, 0, 0, 0, 255, 0, 0, + 0, 0, 255, 0, 255, 255, 0, 0, + + 128, 0, 0, 0, 0, 128, 0, 0, + 0, 0, 128, 0, 128, 128, 0, 0 }; cl_image_format fmt; fmt.image_channel_data_type = CL_UNORM_INT8; - fmt.image_channel_order = CL_RGB; + fmt.image_channel_order = CL_RGBx; ctx = clCreateContextFromType(0, CL_DEVICE_TYPE_CPU, 0, 0, &result); fail_if( @@ -284,6 +292,14 @@ START_TEST (test_images) "cannot create a valid 2x2 image2D" ); + image3d = clCreateImage3D(ctx, CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR, &fmt, + 2, 2, 2, 0, 0, image3d_data_24bpp, &result); + fail_if( + result != CL_SUCCESS || image3d == 0, + "cannot create a valid 2x2x2 image3D" + ); + + clReleaseMemObject(image3d); clReleaseMemObject(image2d); clReleaseContext(ctx); } |