2 * Copyright © 2015 Serge Martin <edb+piglit@sigluy.net>
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
25 * @file enqueue-fill-image.c
30 * clEnqueueFillImage(cl_command_queue command_queue, cl_mem image,
31 * const void *fill_color, size_t *origin, size_t *region
32 * cl_uint num_events_in_wait_list,
33 * const cl_event *event_wait_list,
37 #include "piglit-framework-cl-api.h"
40 PIGLIT_CL_API_TEST_CONFIG_BEGIN
42 config
.name
= "clEnqueueFillImage";
43 config
.version_min
= 12;
45 config
.run_per_device
= true;
46 config
.create_context
= true;
48 PIGLIT_CL_API_TEST_CONFIG_END
51 #if defined(CL_VERSION_1_2)
53 test(cl_command_queue queue
, cl_mem image
,
54 const void *fill_color
, size_t *origin
, size_t *region
,
55 cl_uint num_events_in_wait_list
,
56 const cl_event
*event_wait_list
,
58 cl_int expected_error
, enum piglit_result
* result
,
59 const char* test_str
) {
62 errNo
= clEnqueueFillImage(queue
, image
,
63 fill_color
, origin
, region
,
64 num_events_in_wait_list
, event_wait_list
,
67 if(!piglit_cl_check_error(errNo
, expected_error
)) {
68 fprintf(stderr
, "Failed (error code: %s): %s.\n",
69 piglit_cl_get_error_name(errNo
), test_str
);
70 piglit_merge_result(result
, PIGLIT_FAIL
);
79 piglit_cl_test(const int argc
,
81 const struct piglit_cl_api_test_config
* config
,
82 const struct piglit_cl_api_test_env
* env
)
84 #if defined(CL_VERSION_1_2)
85 enum piglit_result result
= PIGLIT_PASS
;
90 #define IMG_DATA_SIZE 4
91 #define IMG_BUFFER_SIZE IMG_WIDTH * IMG_HEIGHT * IMG_DATA_SIZE
93 unsigned char img_buf
[IMG_BUFFER_SIZE
] = {0};
94 unsigned char dst_buf
[IMG_BUFFER_SIZE
] = {0};
95 unsigned char exp_buf
[IMG_BUFFER_SIZE
] = {0};
96 int pattern
[4] = {129, 33, 77, 255};
97 size_t origin
[3] = {0, 0, 0};
98 size_t region
[3] = {2, 2, 1};
102 cl_image_format img_format
;
103 cl_image_desc img_desc
= {0};
104 cl_command_queue queue
= env
->context
->command_queues
[0];
107 if (!piglit_cl_get_device_image_support(env
->context
->device_ids
[0])) {
108 fprintf(stderr
, "No image support\n");
112 img_format
.image_channel_order
= CL_RGBA
;
113 img_format
.image_channel_data_type
= CL_UNSIGNED_INT8
;
114 img_desc
.image_type
= CL_MEM_OBJECT_IMAGE2D
;
115 img_desc
.image_width
= IMG_WIDTH
;
116 img_desc
.image_height
= IMG_HEIGHT
;
117 img_desc
.buffer
= NULL
;
119 /*** Normal usage ***/
120 image
= clCreateImage(env
->context
->cl_ctx
,
121 CL_MEM_READ_ONLY
| CL_MEM_COPY_HOST_PTR
,
122 &img_format
, &img_desc
, &img_buf
, &err
);
124 if(!piglit_cl_check_error(err
, CL_SUCCESS
)) {
125 fprintf(stderr
, "Failed (error code: %s): Creating an image\n",
126 piglit_cl_get_error_name(err
));
130 if (!test(queue
, image
, pattern
, origin
, region
,
132 CL_SUCCESS
, &result
, "Enqueuing the image to be filled")) {
136 region
[0] = IMG_WIDTH
;
137 region
[1] = IMG_HEIGHT
;
138 err
= clEnqueueReadImage(queue
, image
, 1, origin
, region
, 0, 0,
139 dst_buf
, 0, NULL
, NULL
);
140 if(!piglit_cl_check_error(err
, CL_SUCCESS
)) {
141 fprintf(stderr
, "Failed (error code: %s): Reading image\n",
142 piglit_cl_get_error_name(err
));
147 * fill the host buffer with the pattern
148 * for example : pattern == 1234
155 exp_buf
[0] = pattern
[0];
156 exp_buf
[1] = pattern
[1];
157 exp_buf
[2] = pattern
[2];
158 exp_buf
[3] = pattern
[3];
159 memcpy(exp_buf
+ (IMG_DATA_SIZE
* 1), exp_buf
, IMG_DATA_SIZE
);
160 memcpy(exp_buf
+ (IMG_DATA_SIZE
* 4), exp_buf
, IMG_DATA_SIZE
);
161 memcpy(exp_buf
+ (IMG_DATA_SIZE
* 5), exp_buf
, IMG_DATA_SIZE
);
163 for (i
= 0; i
< sizeof(dst_buf
) / sizeof(dst_buf
[0]); ++i
) {
164 if (!piglit_cl_probe_integer(dst_buf
[i
], exp_buf
[i
], 0)) {
165 fprintf(stderr
, "Error at %d: got %d, expected %d\n",
166 i
, dst_buf
[i
], exp_buf
[i
]);
174 * CL_INVALID_COMMAND_QUEUE if command_queue is not a valid command-queue.
176 test(NULL
, image
, pattern
, origin
, region
,
178 CL_INVALID_COMMAND_QUEUE
, &result
,
179 "CL_INVALID_COMMAND_QUEUE if command_queue is not a valid command-queue");
182 * CL_INVALID_CONTEXT if the context associated with command_queue and
183 * image are not the same or if the context associated with command_queue
184 * and events in event_wait_list are not the same.
187 piglit_cl_context context
;
189 context
= piglit_cl_create_context(env
->platform_id
,
190 env
->context
->device_ids
, 1);
192 event
= clCreateUserEvent(context
->cl_ctx
, &err
);
193 if (err
== CL_SUCCESS
) {
194 err
= clSetUserEventStatus(event
, CL_COMPLETE
);
195 if (err
== CL_SUCCESS
) {
196 test(context
->command_queues
[0], image
, pattern
, origin
, region
,
198 CL_INVALID_CONTEXT
, &result
,
199 "CL_INVALID_CONTEXT if the context associated with command_queue and image are not the same");
201 test(queue
, image
, pattern
, origin
, region
,
203 CL_INVALID_CONTEXT
, &result
,
204 "CL_INVALID_CONTEXT if the context associated with command_queue and events in event_wait_list are not the same");
206 fprintf(stderr
, "Could not set event status.\n");
207 piglit_merge_result(&result
, PIGLIT_WARN
);
209 clReleaseEvent(event
);
211 fprintf(stderr
, "Could not create user event.\n");
212 piglit_merge_result(&result
, PIGLIT_WARN
);
215 piglit_cl_release_context(context
);
217 fprintf(stderr
, "Could not test triggering CL_INVALID_CONTEXT.\n");
218 piglit_merge_result(&result
, PIGLIT_WARN
);
223 * CL_INVALID_MEM_OBJECT if image is not a valid buffer object.
225 test(queue
, NULL
, pattern
, origin
, region
,
227 CL_INVALID_MEM_OBJECT
, &result
,
228 "CL_INVALID_MEM_OBJECT if image is not a valid buffer object");
231 * CL_INVALID_VALUE if fill_color is NULL.
233 test(queue
, image
, NULL
, origin
, region
,
235 CL_INVALID_VALUE
, &result
,
236 "CL_INVALID_VALUE if fill_color is NULL");
239 * CL_INVALID_VALUE if the region being written specified by origin and
240 * region is out of bounds or if ptr is a NULL value.
243 origin
[0] = IMG_WIDTH
+ 1;
244 test(queue
, image
, pattern
, origin
, region
,
246 CL_INVALID_VALUE
, &result
,
247 "CL_INVALID_VALUE if the region being written specified by origin and region is out of bounds (origin)");
251 region
[0] = IMG_WIDTH
+ 1;
252 test(queue
, image
, pattern
, origin
, region
,
254 CL_INVALID_VALUE
, &result
,
255 "CL_INVALID_VALUE if the region being written specified by origin and region is out of bounds (region)");
258 test(queue
, image
, pattern
, NULL
, region
,
260 CL_INVALID_VALUE
, &result
,
261 "CL_INVALID_VALUE if ptr is a NULL value (origin)");
263 test(queue
, image
, pattern
, origin
, NULL
,
265 CL_INVALID_VALUE
, &result
,
266 "CL_INVALID_VALUE if ptr is a NULL value (region)");
269 * CL_INVALID_VALUE if values in origin and region do not follow rules
270 * described in the argument description for origin and region.
274 test(queue
, image
, pattern
, origin
, region
,
276 CL_INVALID_VALUE
, &result
,
277 "CL_INVALID_VALUE if values in origin do not follow rules described in the argument description for origin");
282 test(queue
, image
, pattern
, origin
, region
,
284 CL_INVALID_VALUE
, &result
,
285 "CL_INVALID_VALUE if values in region do not follow rules described in the argument description for region");
289 * CL_INVALID_EVENT_WAIT_LIST if event_wait_list is NULL and
290 * num_events_in_wait_list > 0, or event_wait_list is not NULL and
291 * num_events_in_wait_list is 0, or if event objects in event_wait_list
292 * are not valid events.
295 test(queue
, image
, pattern
, origin
, region
,
297 CL_INVALID_EVENT_WAIT_LIST
, &result
,
298 "CL_INVALID_EVENT_WAIT_LIST if event_wait_list is NULL and num_events_in_wait_list > 0");
300 test(queue
, image
, pattern
, origin
, region
,
302 CL_INVALID_EVENT_WAIT_LIST
, &result
,
303 "CL_INVALID_EVENT_WAIT_LIST if event_wait_list is not NULL and num_events_in_wait_list is 0");
305 test(queue
, image
, pattern
, origin
, region
,
307 CL_INVALID_EVENT_WAIT_LIST
, &result
,
308 "CL_INVALID_EVENT_WAIT_LIST if event objects in event_wait_list are not valid events");
311 * CL_INVALID_IMAGE_SIZE if image dimensions (image width, height, specified
312 * or compute row and/or slice pitch) for image are not supported by device
313 * associated with queue.
315 /* This is a per device test, clCreateImage would have failed before */
318 * CL_INVALID_IMAGE_FORMAT if image format (image channel order and data type)
319 * for image are not supported by device associated with queue.
321 /* This is a per device test, clCreateImage would have failed before */
323 clReleaseMemObject(image
);