• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright (c) 2017 The Khronos Group Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //    http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 #include "../testBase.h"
17 #include "../common.h"
18 
19 extern int test_copy_image_generic( cl_context context, cl_command_queue queue, image_descriptor *srcImageInfo, image_descriptor *dstImageInfo,
20                                    const size_t sourcePos[], const size_t destPos[], const size_t regionSize[], MTdata d );
21 
set_image_dimensions(image_descriptor * imageInfo,size_t width,size_t height,size_t depth,size_t arraySize,size_t rowPadding,size_t slicePadding)22 static void set_image_dimensions( image_descriptor *imageInfo, size_t width, size_t height, size_t depth, size_t arraySize, size_t rowPadding, size_t slicePadding )
23 {
24     size_t pixelSize = get_pixel_size( imageInfo->format );
25 
26     imageInfo->width = width;
27     imageInfo->height = height;
28     imageInfo->depth = depth;
29     imageInfo->arraySize = arraySize;
30     imageInfo->rowPitch = imageInfo->width * pixelSize + rowPadding;
31 
32     if (gEnablePitch)
33     {
34         do {
35             rowPadding++;
36             imageInfo->rowPitch = imageInfo->width * pixelSize + rowPadding;
37         } while ((imageInfo->rowPitch % pixelSize) != 0);
38     }
39 
40     imageInfo->slicePitch = imageInfo->rowPitch * (imageInfo->height + slicePadding);
41 
42     if (arraySize == 0)
43         imageInfo->type = CL_MEM_OBJECT_IMAGE3D;
44     else
45         imageInfo->type = CL_MEM_OBJECT_IMAGE2D_ARRAY;
46 }
47 
48 
test_copy_image_size_3D_2D_array(cl_context context,cl_command_queue queue,image_descriptor * srcImageInfo,image_descriptor * dstImageInfo,MTdata d)49 int test_copy_image_size_3D_2D_array( cl_context context, cl_command_queue queue, image_descriptor *srcImageInfo, image_descriptor *dstImageInfo, MTdata d )
50 {
51     size_t sourcePos[ 4 ], destPos[ 4 ], regionSize[ 3 ];
52     int ret = 0, retCode;
53 
54     image_descriptor *threeImage, *twoImage;
55 
56     if( srcImageInfo->arraySize == 0 )
57     {
58         threeImage = srcImageInfo;
59         twoImage = dstImageInfo;
60     }
61     else
62     {
63         threeImage = dstImageInfo;
64         twoImage = srcImageInfo;
65     }
66 
67     size_t twoImage_width_lod = twoImage->width, twoImage_height_lod = twoImage->height;
68     size_t threeImage_width_lod = threeImage->width, threeImage_height_lod = threeImage->height;
69     size_t twoImage_lod = 0, threeImage_lod = 0;
70     size_t width_lod = 0, height_lod = 0, depth_lod = 0;
71     size_t twoImage_max_mip_level,threeImage_max_mip_level;
72 
73     if( gTestMipmaps )
74     {
75         twoImage_max_mip_level = twoImage->num_mip_levels;
76         threeImage_max_mip_level = threeImage->num_mip_levels;
77         // Work at random mip levels
78         twoImage_lod = (size_t)random_in_range( 0, twoImage_max_mip_level ? twoImage_max_mip_level - 1 : 0, d );
79         threeImage_lod = (size_t)random_in_range( 0, threeImage_max_mip_level ? threeImage_max_mip_level - 1 : 0, d );
80         twoImage_width_lod = ( twoImage->width >> twoImage_lod )? ( twoImage->width >> twoImage_lod ) : 1;
81         threeImage_width_lod = ( threeImage->width >> threeImage_lod )? ( threeImage->width >> threeImage_lod ) : 1;
82         twoImage_height_lod = ( twoImage->height >> twoImage_lod )? ( twoImage->height >> twoImage_lod ) : 1;
83         threeImage_height_lod = ( threeImage->height >> threeImage_lod )? ( threeImage->height >> threeImage_lod ) : 1;
84         depth_lod = ( threeImage->depth >> threeImage_lod )? ( threeImage->depth >> threeImage_lod ) : 1;
85     }
86     width_lod  = ( twoImage_width_lod > threeImage_width_lod ) ? threeImage_width_lod : twoImage_width_lod;
87     height_lod  = ( twoImage_height_lod > threeImage_height_lod ) ? threeImage_height_lod : twoImage_height_lod;
88     depth_lod = ( depth_lod > twoImage->arraySize ) ? twoImage->arraySize : depth_lod;
89 
90     // First, try just a full covering region
91     sourcePos[ 0 ] = sourcePos[ 1 ] = sourcePos[ 2 ] = 0;
92     destPos[ 0 ] = destPos[ 1 ] = destPos[ 2 ] = 0;
93     regionSize[ 0 ] = ( threeImage->width < twoImage->width ) ? threeImage->width : twoImage->width;
94     regionSize[ 1 ] = ( threeImage->height < twoImage->height ) ? threeImage->height : twoImage->height;
95     regionSize[ 2 ] = 1;
96 
97     if( srcImageInfo->type == CL_MEM_OBJECT_IMAGE3D )
98     {
99         // 3D to 2D array
100         sourcePos[ 2 ] = (size_t)random_in_range( 0, (int)srcImageInfo->depth - 1, d );
101         destPos[ 2 ] = (size_t)random_in_range( 0, (int)dstImageInfo->arraySize - 1, d );
102         if(gTestMipmaps)
103         {
104             sourcePos[ 2 ] = 0/*(size_t)random_in_range( 0, (int)depth_lod - 1, d )*/;
105             destPos[ 2 ] = ( twoImage->arraySize > depth_lod ) ? (size_t)random_in_range( 0, twoImage->arraySize - depth_lod, d) : 0;
106             sourcePos[ 3 ] = threeImage_lod;
107             destPos[ 3 ] = twoImage_lod;
108             regionSize[ 0 ] = width_lod;
109             regionSize[ 1 ] = height_lod;
110             regionSize[ 2 ] = depth_lod;
111         }
112     }
113     else
114     {
115         // 2D array to 3D
116         sourcePos[ 2 ] = (size_t)random_in_range( 0, (int)srcImageInfo->arraySize - 1, d );
117         destPos[ 2 ] = (size_t)random_in_range( 0, (int)dstImageInfo->depth - 1, d );
118         if(gTestMipmaps)
119         {
120             destPos[ 2 ] = 0 /*(size_t)random_in_range( 0, (int)depth_lod - 1, d )*/;
121             sourcePos[ 2 ] = ( twoImage->arraySize > depth_lod ) ? (size_t)random_in_range( 0, twoImage->arraySize - depth_lod, d) : 0;
122             sourcePos[ 3 ] = twoImage_lod;
123             destPos[ 3 ] = threeImage_lod;
124             regionSize[ 0 ] = width_lod;
125             regionSize[ 1 ] = height_lod;
126             regionSize[ 2 ] = depth_lod;
127         }
128     }
129 
130     retCode = test_copy_image_generic( context, queue, srcImageInfo, dstImageInfo, sourcePos, destPos, regionSize, d );
131     if( retCode < 0 )
132         return retCode;
133     else
134         ret += retCode;
135 
136     // Now try a sampling of different random regions
137     for( int i = 0; i < 8; i++ )
138     {
139         if( gTestMipmaps )
140         {
141             twoImage_max_mip_level = twoImage->num_mip_levels;
142             threeImage_max_mip_level = threeImage->num_mip_levels;
143             // Work at random mip levels
144             twoImage_lod = (size_t)random_in_range( 0, twoImage_max_mip_level ? twoImage_max_mip_level - 1 : 0, d );
145             threeImage_lod = (size_t)random_in_range( 0, threeImage_max_mip_level ? threeImage_max_mip_level - 1 : 0, d );
146             twoImage_width_lod = ( twoImage->width >> twoImage_lod )? ( twoImage->width >> twoImage_lod ) : 1;
147             threeImage_width_lod = ( threeImage->width >> threeImage_lod )? ( threeImage->width >> threeImage_lod ) : 1;
148             twoImage_height_lod = ( twoImage->height >> twoImage_lod )? ( twoImage->height >> twoImage_lod ) : 1;
149             threeImage_height_lod = ( threeImage->height >> threeImage_lod )? ( threeImage->height >> threeImage_lod ) : 1;
150             depth_lod = ( threeImage->depth >> threeImage_lod )? ( threeImage->depth >> threeImage_lod ) : 1;
151             width_lod  = ( twoImage_width_lod > threeImage_width_lod ) ? threeImage_width_lod : twoImage_width_lod;
152             height_lod  = ( twoImage_height_lod > threeImage_height_lod ) ? threeImage_height_lod : twoImage_height_lod;
153             depth_lod = ( twoImage->arraySize > depth_lod ) ? depth_lod : twoImage->arraySize;
154         }
155         // Pick a random size
156         regionSize[ 0 ] = random_in_ranges( 8, srcImageInfo->width, dstImageInfo->width, d );
157         regionSize[ 1 ] = random_in_ranges( 8, srcImageInfo->height, dstImageInfo->height, d );
158         if( gTestMipmaps )
159         {
160             regionSize[ 0 ] = random_in_range( 1, width_lod, d );
161             regionSize[ 1 ] = random_in_range( 1, height_lod, d );
162             regionSize[ 2 ] = depth_lod/*random_in_range( 0, depth_lod, d )*/;
163         }
164 
165         // Now pick positions within valid ranges
166         sourcePos[ 0 ] = ( srcImageInfo->width > regionSize[ 0 ] ) ? (size_t)random_in_range( 0, (int)( srcImageInfo->width - regionSize[ 0 ] - 1 ), d ) : 0;
167         sourcePos[ 1 ] = ( srcImageInfo->height > regionSize[ 1 ] ) ? (size_t)random_in_range( 0, (int)( srcImageInfo->height - regionSize[ 1 ] - 1 ), d ) : 0;
168 
169         if (srcImageInfo->type == CL_MEM_OBJECT_IMAGE3D)
170         {
171             sourcePos[ 2 ] = (size_t)random_in_range( 0, (int)( srcImageInfo->depth - 1 ), d );
172             if(gTestMipmaps)
173             {
174                 sourcePos[ 0 ] = ( threeImage_width_lod > regionSize[ 0 ] ) ? (size_t)random_in_range( 0, (int)( threeImage_width_lod - regionSize[ 0 ] - 1 ), d ) : 0;
175                 sourcePos[ 1 ] = ( threeImage_height_lod > regionSize[ 1 ] ) ? (size_t)random_in_range( 0, (int)( threeImage_height_lod - regionSize[ 1 ] - 1 ), d ) : 0;
176                 sourcePos[ 2 ] = 0 /*( depth_lod > regionSize[ 2 ] ) ? (size_t)random_in_range( 0, (int)( depth_lod - regionSize[ 2 ] - 1 ), d ) : 0*/;
177                 sourcePos[ 3 ] = threeImage_lod;
178             }
179         }
180         else
181         {
182             sourcePos[ 2 ] = (size_t)random_in_range( 0, (int)( srcImageInfo->arraySize - 1 ), d );
183             if(gTestMipmaps)
184             {
185                 sourcePos[ 0 ] = ( twoImage_width_lod > regionSize[ 0 ] ) ? (size_t)random_in_range( 0, (int)( twoImage_width_lod - regionSize[ 0 ] - 1 ), d ) : 0;
186                 sourcePos[ 1 ] = ( twoImage_height_lod > regionSize[ 1 ] ) ? (size_t)random_in_range( 0, (int)( twoImage_height_lod - regionSize[ 1 ] - 1 ), d ) : 0;
187                 sourcePos[ 2 ] = ( twoImage->arraySize > regionSize[ 2 ] ) ? (size_t)random_in_range( 0, (int)( twoImage->arraySize - regionSize[ 2 ] - 1 ), d ) : 0;
188                 sourcePos[ 3 ] = twoImage_lod;
189             }
190         }
191 
192         destPos[ 0 ] = ( dstImageInfo->width > regionSize[ 0 ] ) ? (size_t)random_in_range( 0, (int)( dstImageInfo->width - regionSize[ 0 ] - 1 ), d ) : 0;
193         destPos[ 1 ] = ( dstImageInfo->height > regionSize[ 1 ] ) ? (size_t)random_in_range( 0, (int)( dstImageInfo->height - regionSize[ 1 ] - 1 ), d ) : 0;
194         if (dstImageInfo->type == CL_MEM_OBJECT_IMAGE3D)
195         {
196             destPos[ 2 ] = (size_t)random_in_range( 0, (int)( dstImageInfo->depth - 1 ), d );
197             if(gTestMipmaps)
198             {
199                 destPos[ 0 ] = ( threeImage_width_lod > regionSize[ 0 ] ) ? (size_t)random_in_range( 0, (int)( threeImage_width_lod - regionSize[ 0 ] - 1 ), d ) : 0;
200                 destPos[ 1 ] = ( threeImage_height_lod > regionSize[ 1 ] ) ? (size_t)random_in_range( 0, (int)( threeImage_height_lod - regionSize[ 1 ] - 1 ), d ) : 0;
201                 destPos[ 2 ] = 0/*( depth_lod > regionSize[ 2 ] ) ? (size_t)random_in_range( 0, (int)( depth_lod - regionSize[ 2 ] - 1 ), d ) : 0*/;
202                 destPos[ 3 ] = threeImage_lod;
203             }
204         }
205         else
206         {
207             destPos[ 2 ] = (size_t)random_in_range( 0, (int)( dstImageInfo->arraySize - 1 ), d );
208             if(gTestMipmaps)
209             {
210                 destPos[ 0 ] = ( twoImage_width_lod > regionSize[ 0 ] ) ? (size_t)random_in_range( 0, (int)( twoImage_width_lod - regionSize[ 0 ] - 1 ), d ) : 0;
211                 destPos[ 1 ] = ( twoImage_height_lod > regionSize[ 1 ] ) ? (size_t)random_in_range( 0, (int)( twoImage_height_lod - regionSize[ 1 ] - 1 ), d ) : 0;
212                 destPos[ 2 ] = ( twoImage->arraySize > regionSize[ 2 ] ) ? (size_t)random_in_range( 0, (int)( twoImage->arraySize - regionSize[ 2 ] - 1 ), d ) : 0;
213                 destPos[ 3 ] = twoImage_lod;
214             }
215         }
216 
217 
218         // Go for it!
219         retCode = test_copy_image_generic( context, queue, srcImageInfo, dstImageInfo, sourcePos, destPos, regionSize, d );
220         if( retCode < 0 )
221             return retCode;
222         else
223             ret += retCode;
224     }
225 
226     return ret;
227 }
228 
229 
test_copy_image_set_3D_2D_array(cl_device_id device,cl_context context,cl_command_queue queue,cl_image_format * format,bool reverse=false)230 int test_copy_image_set_3D_2D_array(cl_device_id device, cl_context context, cl_command_queue queue, cl_image_format *format, bool reverse = false )
231 {
232     size_t maxWidth, maxHeight, max3DWidth, max3DHeight, maxDepth, maxArraySize;
233     cl_ulong maxAllocSize, memSize;
234     image_descriptor srcImageInfo = { 0 };
235     image_descriptor dstImageInfo = { 0 };
236     RandomSeed  seed( gRandomSeed );
237     size_t rowPadding = gEnablePitch ? 256 : 0;
238     size_t slicePadding = gEnablePitch ? 3 : 0;
239 
240     srcImageInfo.format = dstImageInfo.format = format;
241 
242     int error = clGetDeviceInfo( device, CL_DEVICE_IMAGE2D_MAX_WIDTH, sizeof( maxWidth ), &maxWidth, NULL );
243     error |= clGetDeviceInfo( device, CL_DEVICE_IMAGE2D_MAX_HEIGHT, sizeof( maxHeight ), &maxHeight, NULL );
244     error |= clGetDeviceInfo( device, CL_DEVICE_IMAGE_MAX_ARRAY_SIZE, sizeof( maxArraySize ), &maxArraySize, NULL );
245     error |= clGetDeviceInfo( device, CL_DEVICE_IMAGE3D_MAX_WIDTH, sizeof( max3DWidth ), &max3DWidth, NULL );
246     error |= clGetDeviceInfo( device, CL_DEVICE_IMAGE3D_MAX_HEIGHT, sizeof( max3DHeight ), &max3DHeight, NULL );
247     error |= clGetDeviceInfo( device, CL_DEVICE_IMAGE3D_MAX_DEPTH, sizeof( maxDepth ), &maxDepth, NULL );
248     error |= clGetDeviceInfo( device, CL_DEVICE_MAX_MEM_ALLOC_SIZE, sizeof( maxAllocSize ), &maxAllocSize, NULL );
249     error |= clGetDeviceInfo( device, CL_DEVICE_GLOBAL_MEM_SIZE, sizeof( memSize ), &memSize, NULL );
250     test_error( error, "Unable to get max image 2D image array or 3D size from device" );
251 
252     if (memSize > (cl_ulong)SIZE_MAX) {
253       memSize = (cl_ulong)SIZE_MAX;
254     }
255 
256     if( gTestSmallImages )
257     {
258         for( dstImageInfo.width = 4; dstImageInfo.width < 17; dstImageInfo.width++ )
259         {
260             for( dstImageInfo.height = 4; dstImageInfo.height < 13; dstImageInfo.height++ )
261             {
262                 for( dstImageInfo.arraySize = 4; dstImageInfo.arraySize < 9; dstImageInfo.arraySize++ )
263                 {
264                     set_image_dimensions( &dstImageInfo, dstImageInfo.width, dstImageInfo.height, 0, dstImageInfo.arraySize, rowPadding, slicePadding );
265                     set_image_dimensions( &srcImageInfo, dstImageInfo.width, dstImageInfo.height, dstImageInfo.arraySize, 0, rowPadding, slicePadding );
266 
267                     if (gTestMipmaps)
268                     {
269                       dstImageInfo.type = CL_MEM_OBJECT_IMAGE2D_ARRAY;
270                       dstImageInfo.num_mip_levels = (cl_uint) random_log_in_range(2, (int)compute_max_mip_levels(dstImageInfo.width, dstImageInfo.height, 0), seed);
271                       srcImageInfo.type = CL_MEM_OBJECT_IMAGE3D;
272                       srcImageInfo.num_mip_levels = (cl_uint) random_log_in_range(2, (int)compute_max_mip_levels(srcImageInfo.width, srcImageInfo.height, srcImageInfo.depth), seed);
273                       srcImageInfo.rowPitch = srcImageInfo.width * get_pixel_size( srcImageInfo.format );
274                       srcImageInfo.slicePitch = srcImageInfo.rowPitch * srcImageInfo.height;
275                       dstImageInfo.rowPitch = dstImageInfo.width * get_pixel_size( dstImageInfo.format );
276                       dstImageInfo.slicePitch = dstImageInfo.rowPitch * dstImageInfo.height;
277                     }
278 
279                     if( gDebugTrace )
280                     {
281                         if (reverse)
282                             log_info( "   at size %d,%d,%d to %d,%d,%d\n", (int)dstImageInfo.width, (int)dstImageInfo.height, (int)dstImageInfo.arraySize, (int)srcImageInfo.width, (int)srcImageInfo.height, (int)srcImageInfo.depth );
283                         else
284                             log_info( "   at size %d,%d,%d to %d,%d,%d\n", (int)srcImageInfo.width, (int)srcImageInfo.height, (int)srcImageInfo.depth, (int)dstImageInfo.width, (int)dstImageInfo.height, (int)dstImageInfo.arraySize );
285                     }
286                     int ret;
287                     if( reverse )
288                         ret = test_copy_image_size_3D_2D_array( context, queue, &dstImageInfo, &srcImageInfo, seed );
289                     else
290                         ret = test_copy_image_size_3D_2D_array( context, queue, &srcImageInfo, &dstImageInfo, seed );
291                     if( ret )
292                         return -1;
293                 }
294             }
295         }
296     }
297     else if( gTestMaxImages )
298     {
299         // Try a specific set of maximum sizes
300         size_t numbeOfSizes;
301         size_t sizes3D[100][3];
302         size_t sizes2Darray[100][3];
303 
304         // Try to allocate a bit smaller images because we need the 3D ones as well for the copy.
305         get_max_sizes(&numbeOfSizes, 100, sizes2Darray, maxWidth, maxHeight, maxDepth, maxArraySize, maxAllocSize/2, memSize/2, CL_MEM_OBJECT_IMAGE2D_ARRAY, srcImageInfo.format);
306         get_max_sizes(&numbeOfSizes, 100, sizes3D, max3DWidth, max3DHeight, maxDepth, maxArraySize, maxAllocSize/2, memSize/2, CL_MEM_OBJECT_IMAGE3D, dstImageInfo.format);
307 
308         for( size_t idx = 0; idx < numbeOfSizes; idx++ )
309         {
310             set_image_dimensions( &srcImageInfo, sizes3D[ idx ][ 0 ], sizes3D[ idx ][ 1 ], sizes3D[ idx ][ 2 ], 0, rowPadding, slicePadding );
311             set_image_dimensions( &dstImageInfo, sizes2Darray[ idx ][ 0 ], sizes2Darray[ idx ][ 1 ], 0, sizes2Darray[ idx ][ 2 ], rowPadding, slicePadding );
312 
313             cl_ulong dstSize = (cl_ulong)dstImageInfo.slicePitch * (cl_ulong)dstImageInfo.arraySize;
314             cl_ulong srcSize = (cl_ulong)srcImageInfo.slicePitch * (cl_ulong)srcImageInfo.depth;
315 
316             if (gTestMipmaps)
317             {
318               dstImageInfo.type = CL_MEM_OBJECT_IMAGE2D_ARRAY;
319               dstImageInfo.num_mip_levels = (cl_uint) random_log_in_range(2, (int)compute_max_mip_levels(dstImageInfo.width, dstImageInfo.height, 0), seed);
320               srcImageInfo.type = CL_MEM_OBJECT_IMAGE3D;
321               srcImageInfo.num_mip_levels = (cl_uint) random_log_in_range(2, (int)compute_max_mip_levels(srcImageInfo.width, srcImageInfo.height, srcImageInfo.depth), seed);
322               srcImageInfo.rowPitch = srcImageInfo.width * get_pixel_size( srcImageInfo.format );
323               srcImageInfo.slicePitch = srcImageInfo.rowPitch * srcImageInfo.height;
324               dstImageInfo.rowPitch = dstImageInfo.width * get_pixel_size( dstImageInfo.format );
325               dstImageInfo.slicePitch = dstImageInfo.rowPitch * dstImageInfo.height;
326               srcSize = 4 * compute_mipmapped_image_size( srcImageInfo );
327               dstSize = 4 * compute_mipmapped_image_size( dstImageInfo );
328             }
329 
330             if ( ( dstSize < maxAllocSize && dstSize < ( memSize / 3 ) ) &&
331                  ( srcSize < maxAllocSize && srcSize < ( memSize / 3 ) ) )
332             {
333                 if (reverse)
334                     log_info( "Testing %d x %d x %d to %d x %d x %d\n", (int)dstImageInfo.width, (int)dstImageInfo.height, (int)dstImageInfo.arraySize, (int)srcImageInfo.width, (int)srcImageInfo.height, (int)srcImageInfo.depth );
335                 else
336                     log_info( "Testing %d x %d x %d to %d x %d x %d\n", (int)srcImageInfo.width, (int)srcImageInfo.height, (int)srcImageInfo.depth, (int)dstImageInfo.width, (int)dstImageInfo.height, (int)dstImageInfo.arraySize );
337 
338                 if( gDebugTrace )
339                 {
340                     if (reverse)
341                         log_info( "   at max size %d,%d,%d to %d,%d,%d\n", (int)dstImageInfo.width, (int)dstImageInfo.height, (int)dstImageInfo.arraySize, (int)srcImageInfo.width, (int)srcImageInfo.height, (int)srcImageInfo.depth );
342                     else
343                         log_info( "   at max size %d,%d,%d to %d,%d,%d\n", (int)srcImageInfo.width, (int)srcImageInfo.height, (int)srcImageInfo.depth, (int)dstImageInfo.width, (int)dstImageInfo.height, (int)dstImageInfo.arraySize );
344                 }
345                 int ret;
346                 if( reverse )
347                     ret = test_copy_image_size_3D_2D_array( context, queue, &dstImageInfo, &srcImageInfo, seed );
348                 else
349                     ret = test_copy_image_size_3D_2D_array( context, queue, &srcImageInfo, &dstImageInfo, seed );
350                 if( ret )
351                     return -1;
352             }
353             else
354             {
355                 if (reverse)
356                     log_info("Not testing max size %d x %d x %d x %d to %d x %d due to memory constraints.\n",
357                              (int)dstImageInfo.width, (int)dstImageInfo.height, (int)dstImageInfo.arraySize, (int)srcImageInfo.width, (int)srcImageInfo.height, (int)srcImageInfo.depth);
358                 else
359                     log_info("Not testing max size %d x %d x %d to %d x %d x %d due to memory constraints.\n",
360                          (int)srcImageInfo.width, (int)srcImageInfo.height, (int)srcImageInfo.depth, (int)dstImageInfo.width, (int)dstImageInfo.height, (int)dstImageInfo.arraySize);
361             }
362 
363         }
364     }
365     else
366     {
367         for( int i = 0; i < NUM_IMAGE_ITERATIONS; i++ )
368         {
369             cl_ulong srcSize, dstSize;
370             // Loop until we get a size that a) will fit in the max alloc size and b) that an allocation of that
371             // image, the result array, plus offset arrays, will fit in the global ram space
372             do
373             {
374                 dstImageInfo.width = (size_t)random_log_in_range( 16, (int)maxWidth / 32, seed );
375                 dstImageInfo.height = (size_t)random_log_in_range( 16, (int)maxHeight / 32, seed );
376                 dstImageInfo.arraySize = (size_t)random_log_in_range( 16, (int)maxArraySize / 32, seed );
377                 srcImageInfo.width = (size_t)random_log_in_range( 16, (int)max3DWidth / 32, seed );
378                 srcImageInfo.height = (size_t)random_log_in_range( 16, (int)max3DHeight / 32, seed );
379                 srcImageInfo.depth = (size_t)random_log_in_range( 16, (int)maxDepth / 32, seed );
380 
381                 if (gTestMipmaps)
382                 {
383                     dstImageInfo.type = CL_MEM_OBJECT_IMAGE2D_ARRAY;
384                     dstImageInfo.num_mip_levels = (cl_uint) random_log_in_range(2, (int)compute_max_mip_levels(dstImageInfo.width, dstImageInfo.height, 0), seed);
385                     srcImageInfo.type = CL_MEM_OBJECT_IMAGE3D;
386                     srcImageInfo.num_mip_levels = (cl_uint) random_log_in_range(2, (int)compute_max_mip_levels(srcImageInfo.width, srcImageInfo.height, srcImageInfo.depth), seed);
387                     srcImageInfo.rowPitch = srcImageInfo.width * get_pixel_size( srcImageInfo.format );
388                     srcImageInfo.slicePitch = srcImageInfo.rowPitch * srcImageInfo.height;
389                     dstImageInfo.rowPitch = dstImageInfo.width * get_pixel_size( dstImageInfo.format );
390                     dstImageInfo.slicePitch = dstImageInfo.rowPitch * dstImageInfo.height;
391                     srcSize = 4 * compute_mipmapped_image_size( srcImageInfo );
392                     dstSize = 4 * compute_mipmapped_image_size( dstImageInfo );
393                 }
394                 else
395                 {
396                     set_image_dimensions( &srcImageInfo, srcImageInfo.width, srcImageInfo.height, srcImageInfo.depth, 0, rowPadding, slicePadding );
397                     set_image_dimensions( &dstImageInfo, dstImageInfo.width, dstImageInfo.height, 0, dstImageInfo.arraySize, rowPadding, slicePadding );
398 
399                     srcSize = (cl_ulong)srcImageInfo.slicePitch * (cl_ulong)srcImageInfo.depth * 4;
400                     dstSize = (cl_ulong)dstImageInfo.slicePitch * (cl_ulong)dstImageInfo.arraySize * 4;
401                 }
402             } while( srcSize > maxAllocSize || ( srcSize * 3 ) > memSize || dstSize > maxAllocSize || ( dstSize * 3 ) > memSize);
403 
404             if( gDebugTrace )
405             {
406                 if (reverse)
407                     log_info( "   at size %d,%d,%d to %d,%d,%d\n", (int)dstImageInfo.width, (int)dstImageInfo.height, (int)dstImageInfo.arraySize, (int)srcImageInfo.width, (int)srcImageInfo.height, (int)srcImageInfo.depth );
408                 else
409                     log_info( "   at size %d,%d,%d to %d,%d,%d\n", (int)srcImageInfo.width, (int)srcImageInfo.height, (int)srcImageInfo.depth, (int)dstImageInfo.width, (int)dstImageInfo.height, (int)dstImageInfo.arraySize );
410             }
411             int ret;
412             if( reverse )
413                 ret = test_copy_image_size_3D_2D_array( context, queue, &dstImageInfo, &srcImageInfo, seed );
414             else
415                 ret = test_copy_image_size_3D_2D_array( context, queue, &srcImageInfo, &dstImageInfo, seed );
416             if( ret )
417                 return -1;
418         }
419     }
420 
421     return 0;
422 }
423