2 * Copyright 2014 Advanced Micro Devices, Inc.
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.
23 * Authors: Tom Stellard <thomas.stellard@amd.com>
27 #include "piglit-framework-cl-api.h"
28 #include "piglit-util-cl.h"
31 PIGLIT_CL_API_TEST_CONFIG_BEGIN
33 config
.name
= "clEnqueueCopyBufferRect";
34 config
.version_min
= 10;
36 config
.run_per_platform
= true;
37 config
.create_context
= true;
39 PIGLIT_CL_API_TEST_CONFIG_END
41 #define BUFFER_SIZE 672
44 piglit_cl_test(const int argc
,
46 const struct piglit_cl_api_test_config
* config
,
47 const struct piglit_cl_api_test_env
* env
)
49 char *host_src_buffer
= malloc(BUFFER_SIZE
);
50 char *host_dst_buffer
= malloc(BUFFER_SIZE
);
51 cl_mem device_src_buffer
, device_dst_buffer
;
52 cl_command_queue queue
= env
->context
->command_queues
[0];
55 size_t src_origin
[3] = {0, 0, 0};
56 size_t dst_origin
[3] = {1, 0, 0};
57 size_t region
[3] = {1, 21, 1};
58 size_t src_row_pitch
= 32;
59 size_t src_slice_pitch
= 0;
60 size_t dst_row_pitch
= 32;
61 size_t dst_slice_pitch
= 0;
63 memset(host_src_buffer
, 0, BUFFER_SIZE
);
64 memset(host_dst_buffer
, 0xff, BUFFER_SIZE
);
66 device_src_buffer
= piglit_cl_create_buffer(
67 env
->context
, CL_MEM_READ_WRITE
, BUFFER_SIZE
);
68 device_dst_buffer
= piglit_cl_create_buffer(
69 env
->context
, CL_MEM_READ_WRITE
, BUFFER_SIZE
);
70 if (!piglit_cl_write_whole_buffer(queue
,
71 device_src_buffer
, host_src_buffer
) ||
72 !piglit_cl_write_whole_buffer(queue
,
73 device_dst_buffer
, host_dst_buffer
)) {
77 err
= clEnqueueCopyBufferRect(queue
, device_src_buffer
, device_dst_buffer
,
78 src_origin
, dst_origin
, region
, src_row_pitch
,
79 src_slice_pitch
, dst_row_pitch
, dst_slice_pitch
,
81 if (!piglit_cl_check_error(err
, CL_SUCCESS
)) {
87 if (!piglit_cl_read_whole_buffer(queue
, device_dst_buffer
,
92 // Check that bytes were written to the correct locations.
93 for (i
= 0; i
< region
[1]; i
++) {
94 unsigned dst_idx
= (i
* dst_row_pitch
) + dst_origin
[0];
95 char dst_value
= host_dst_buffer
[dst_idx
];
96 char src_value
= host_src_buffer
[(i
* src_row_pitch
) + src_origin
[0]];
97 if (!piglit_cl_probe_integer(dst_value
, src_value
, 0)){
98 printf("Error at %d\n", dst_idx
);
103 // Check that bytes weren't written to any wrong places
104 for (i
= 0; i
< BUFFER_SIZE
; i
++) {
105 if (i
< dst_origin
[0] || (i
- dst_origin
[0]) % dst_row_pitch
== 0) {
108 if (!piglit_cl_probe_integer(host_dst_buffer
[i
], (char)0xff, 0)) {
109 printf("Error at %d\n", i
);