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