• 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 
18 // Defined in test_copy_generic.cpp
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 
test_copy_image_2D_array(cl_context context,cl_command_queue queue,image_descriptor * imageInfo,MTdata d)22 int test_copy_image_2D_array( cl_context context, cl_command_queue queue, image_descriptor *imageInfo, MTdata d )
23 {
24     size_t srcPos[] = { 0, 0, 0, 0}, dstPos[] = {0, 0, 0, 0};
25     size_t region[] = { imageInfo->width, imageInfo->height, imageInfo->arraySize };
26 
27     size_t src_lod = 0, src_width_lod = imageInfo->width, src_height_lod = imageInfo->height;
28     size_t dst_lod = 0, dst_width_lod = imageInfo->width, dst_height_lod = imageInfo->height;
29     size_t width_lod = imageInfo->width, height_lod = imageInfo->height;
30     size_t max_mip_level;
31 
32     if( gTestMipmaps )
33     {
34         max_mip_level = imageInfo->num_mip_levels;
35         // Work at a random mip level
36         src_lod = (size_t)random_in_range( 0, max_mip_level ? max_mip_level - 1 : 0, d );
37         dst_lod = (size_t)random_in_range( 0, max_mip_level ? max_mip_level - 1 : 0, d );
38         src_width_lod = ( imageInfo->width >> src_lod )? ( imageInfo->width >> src_lod ) : 1;
39         dst_width_lod = ( imageInfo->width >> dst_lod )? ( imageInfo->width >> dst_lod ) : 1;
40         src_height_lod = ( imageInfo->height >> src_lod )? ( imageInfo->height >> src_lod ) : 1;
41         dst_height_lod = ( imageInfo->height >> dst_lod )? ( imageInfo->height >> dst_lod ) : 1;
42         width_lod  = ( src_width_lod > dst_width_lod ) ? dst_width_lod : src_width_lod;
43         height_lod  = ( src_height_lod > dst_height_lod ) ? dst_height_lod : src_height_lod;
44 
45         region[ 0 ] = width_lod;
46         region[ 1 ] = height_lod;
47         srcPos[ 3 ] = src_lod;
48         dstPos[ 3 ] = dst_lod;
49 }
50     return test_copy_image_generic( context, queue, imageInfo, imageInfo, srcPos, dstPos, region, d );
51 }
52 
test_copy_image_set_2D_array(cl_device_id device,cl_context context,cl_command_queue queue,cl_image_format * format)53 int test_copy_image_set_2D_array( cl_device_id device, cl_context context, cl_command_queue queue, cl_image_format *format )
54 {
55     size_t maxWidth, maxHeight, maxArraySize;
56     cl_ulong maxAllocSize, memSize;
57     image_descriptor imageInfo = { 0 };
58     RandomSeed seed( gRandomSeed );
59     size_t pixelSize;
60 
61     imageInfo.format = format;
62     imageInfo.type = CL_MEM_OBJECT_IMAGE2D_ARRAY;
63     pixelSize = get_pixel_size( imageInfo.format );
64 
65     int error = clGetDeviceInfo( device, CL_DEVICE_IMAGE3D_MAX_WIDTH, sizeof( maxWidth ), &maxWidth, NULL );
66     error |= clGetDeviceInfo( device, CL_DEVICE_IMAGE3D_MAX_HEIGHT, sizeof( maxHeight ), &maxHeight, NULL );
67     error |= clGetDeviceInfo( device, CL_DEVICE_IMAGE_MAX_ARRAY_SIZE, sizeof( maxArraySize ), &maxArraySize, NULL );
68     error |= clGetDeviceInfo( device, CL_DEVICE_MAX_MEM_ALLOC_SIZE, sizeof( maxAllocSize ), &maxAllocSize, NULL );
69     error |= clGetDeviceInfo( device, CL_DEVICE_GLOBAL_MEM_SIZE, sizeof( memSize ), &memSize, NULL );
70     test_error( error, "Unable to get max image 2D array size from device" );
71 
72     if (memSize > (cl_ulong)SIZE_MAX) {
73       memSize = (cl_ulong)SIZE_MAX;
74     }
75 
76     if( gTestSmallImages )
77     {
78         for( imageInfo.width = 1; imageInfo.width < 13; imageInfo.width++ )
79         {
80             size_t rowPadding = gEnablePitch ? 80 : 0;
81             size_t slicePadding = gEnablePitch ? 3 : 0;
82 
83             imageInfo.rowPitch = imageInfo.width * pixelSize + rowPadding;
84 
85             if (gTestMipmaps)
86               imageInfo.num_mip_levels = (cl_uint) random_log_in_range(2, (int)compute_max_mip_levels(imageInfo.width, imageInfo.height, 0), seed);
87 
88             if (gEnablePitch)
89             {
90                 do {
91                     rowPadding++;
92                     imageInfo.rowPitch = imageInfo.width * pixelSize + rowPadding;
93                 } while ((imageInfo.rowPitch % pixelSize) != 0);
94             }
95 
96             for( imageInfo.height = 1; imageInfo.height < 9; imageInfo.height++ )
97             {
98                 imageInfo.slicePitch = imageInfo.rowPitch * (imageInfo.height + slicePadding);
99 
100                 for( imageInfo.arraySize = 2; imageInfo.arraySize < 9; imageInfo.arraySize++ )
101                 {
102                     if( gDebugTrace )
103                         log_info( "   at size %d,%d,%d\n", (int)imageInfo.width, (int)imageInfo.height, (int)imageInfo.arraySize );
104                     int ret = test_copy_image_2D_array( context, queue, &imageInfo, seed );
105                     if( ret )
106                         return -1;
107                 }
108             }
109         }
110     }
111     else if( gTestMaxImages )
112     {
113         // Try a specific set of maximum sizes
114         size_t numbeOfSizes;
115         size_t sizes[100][3];
116         get_max_sizes(&numbeOfSizes, 100, sizes, maxWidth, maxHeight, 1, maxArraySize, maxAllocSize, memSize, imageInfo.type, imageInfo.format);
117 
118         for( size_t idx = 0; idx < numbeOfSizes; idx++ )
119         {
120             size_t rowPadding = gEnablePitch ? 80 : 0;
121             size_t slicePadding = gEnablePitch ? 3 : 0;
122 
123             imageInfo.width = sizes[ idx ][ 0 ];
124             imageInfo.height = sizes[ idx ][ 1 ];
125             imageInfo.arraySize = sizes[ idx ][ 2 ];
126             imageInfo.rowPitch = imageInfo.width * pixelSize + rowPadding;
127 
128             if (gTestMipmaps)
129               imageInfo.num_mip_levels = (cl_uint) random_log_in_range(2, (int)compute_max_mip_levels(imageInfo.width, imageInfo.height, 0), seed);
130 
131             if (gEnablePitch)
132             {
133                 do {
134                     rowPadding++;
135                     imageInfo.rowPitch = imageInfo.width * pixelSize + rowPadding;
136                 } while ((imageInfo.rowPitch % pixelSize) != 0);
137             }
138 
139             imageInfo.slicePitch = imageInfo.rowPitch * (imageInfo.height + slicePadding);
140             log_info( "Testing %d x %d x %d\n", (int)sizes[ idx ][ 0 ], (int)sizes[ idx ][ 1 ], (int)sizes[ idx ][ 2 ] );
141             if( gDebugTrace )
142                 log_info( "   at max size %d,%d,%d\n", (int)sizes[ idx ][ 0 ], (int)sizes[ idx ][ 1 ], (int)sizes[ idx ][ 2 ] );
143             if( test_copy_image_2D_array( context, queue, &imageInfo, seed ) )
144                 return -1;
145         }
146     }
147     else
148     {
149         for( int i = 0; i < NUM_IMAGE_ITERATIONS; i++ )
150         {
151             cl_ulong size;
152             size_t rowPadding = gEnablePitch ? 80 : 0;
153             size_t slicePadding = gEnablePitch ? 3 : 0;
154             // Loop until we get a size that a) will fit in the max alloc size and b) that an allocation of that
155             // image, the result array, plus offset arrays, will fit in the global ram space
156             do
157             {
158                 imageInfo.width = (size_t)random_log_in_range( 16, (int)maxWidth / 32, seed );
159                 imageInfo.height = (size_t)random_log_in_range( 16, (int)maxHeight / 32, seed );
160                 imageInfo.arraySize = (size_t)random_log_in_range( 16, (int)maxArraySize / 32, seed );
161 
162                 if (gTestMipmaps)
163                 {
164                     imageInfo.num_mip_levels = (cl_uint) random_log_in_range(2, (int)compute_max_mip_levels(imageInfo.width, imageInfo.height, 0), seed);
165                     imageInfo.rowPitch = imageInfo.width * get_pixel_size( imageInfo.format );
166                     imageInfo.slicePitch = imageInfo.rowPitch * imageInfo.height;
167                     size = compute_mipmapped_image_size( imageInfo );
168                     size = size*4;
169                 }
170                 else
171                 {
172                   imageInfo.rowPitch = imageInfo.width * pixelSize + rowPadding;
173                   if (gEnablePitch)
174                   {
175                     do {
176                       rowPadding++;
177                       imageInfo.rowPitch = imageInfo.width * pixelSize + rowPadding;
178                     } while ((imageInfo.rowPitch % pixelSize) != 0);
179                   }
180 
181                   imageInfo.slicePitch = imageInfo.rowPitch * (imageInfo.height + slicePadding);
182 
183                   size = (cl_ulong)imageInfo.slicePitch * (cl_ulong)imageInfo.arraySize * 4 * 4;
184                 }
185             } while(  size > maxAllocSize || ( size * 3 ) > memSize );
186 
187             if( gDebugTrace )
188                 log_info( "   at size %d,%d,%d (pitch %d,%d) out of %d,%d,%d\n", (int)imageInfo.width, (int)imageInfo.height, (int)imageInfo.arraySize, (int)imageInfo.rowPitch, (int)imageInfo.slicePitch, (int)maxWidth, (int)maxHeight, (int)maxArraySize );
189             int ret = test_copy_image_2D_array( context, queue, &imageInfo,seed );
190             if( ret )
191                 return -1;
192         }
193     }
194 
195     return 0;
196 }
197