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 extern int test_copy_image_generic( cl_context context, cl_command_queue queue, image_descriptor *srcImageInfo, image_descriptor *dstImageInfo,
19 const size_t sourcePos[], const size_t destPos[], const size_t regionSize[], MTdata d );
20
test_copy_image_size_1D_array(cl_context context,cl_command_queue queue,image_descriptor * imageInfo,MTdata d)21 int test_copy_image_size_1D_array( cl_context context, cl_command_queue queue, image_descriptor *imageInfo, MTdata d )
22 {
23 size_t sourcePos[ 3 ], destPos[ 3 ], regionSize[ 3 ];
24 int ret = 0, retCode;
25 size_t src_lod = 0, src_width_lod = imageInfo->width, src_row_pitch_lod;
26 size_t dst_lod = 0, dst_width_lod = imageInfo->width, dst_row_pitch_lod;
27 size_t width_lod = imageInfo->width;
28 size_t max_mip_level;
29
30 if( gTestMipmaps )
31 {
32 max_mip_level = imageInfo->num_mip_levels;
33 // Work at a random mip level
34 src_lod = (size_t)random_in_range( 0, max_mip_level ? max_mip_level - 1 : 0, d );
35 dst_lod = (size_t)random_in_range( 0, max_mip_level ? max_mip_level - 1 : 0, d );
36 src_width_lod = ( imageInfo->width >> src_lod )? ( imageInfo->width >> src_lod ) : 1;
37 dst_width_lod = ( imageInfo->width >> dst_lod )? ( imageInfo->width >> dst_lod ) : 1;
38 width_lod = ( src_width_lod > dst_width_lod ) ? dst_width_lod : src_width_lod;
39 src_row_pitch_lod = src_width_lod * get_pixel_size( imageInfo->format );
40 dst_row_pitch_lod = dst_width_lod * get_pixel_size( imageInfo->format );
41 }
42
43 // First, try just a full covering region
44 sourcePos[ 0 ] = sourcePos[ 1 ] = sourcePos[ 2 ] = 0;
45 destPos[ 0 ] = destPos[ 1 ] = destPos[ 2 ] = 0;
46 regionSize[ 0 ] = imageInfo->width;
47 regionSize[ 1 ] = imageInfo->arraySize;
48 regionSize[ 2 ] = 1;
49
50 if(gTestMipmaps)
51 {
52 sourcePos[ 2 ] = src_lod;
53 destPos[ 2 ] = dst_lod;
54 regionSize[ 0 ] = width_lod;
55 }
56
57 retCode = test_copy_image_generic( context, queue, imageInfo, imageInfo, sourcePos, destPos, regionSize, d );
58 if( retCode < 0 )
59 return retCode;
60 else
61 ret += retCode;
62
63 // Now try a sampling of different random regions
64 for( int i = 0; i < 8; i++ )
65 {
66 if( gTestMipmaps )
67 {
68 // Work at a random mip level
69 src_lod = (size_t) ( max_mip_level > 1 )? random_in_range( 0, max_mip_level - 1 , d ) : 0;
70 dst_lod = (size_t) ( max_mip_level > 1 )? random_in_range( 0, max_mip_level - 1 , d ) : 0;
71 src_width_lod = ( imageInfo->width >> src_lod )? ( imageInfo->width >> src_lod ) : 1;
72 dst_width_lod = ( imageInfo->width >> dst_lod )? ( imageInfo->width >> dst_lod ) : 1;
73 width_lod = ( src_width_lod > dst_width_lod ) ? dst_width_lod : src_width_lod;
74 sourcePos[ 2 ] = src_lod;
75 destPos[ 2 ] = dst_lod;
76 }
77 // Pick a random size
78 regionSize[ 0 ] = ( width_lod > 8 ) ? (size_t)random_in_range( 8, (int)width_lod - 1, d ) : (int)width_lod;
79 regionSize[ 1 ] = ( imageInfo->arraySize > 8 ) ? (size_t)random_in_range( 8, (int)imageInfo->arraySize - 1, d ) : imageInfo->arraySize;
80
81 // Now pick positions within valid ranges
82 sourcePos[ 0 ] = ( width_lod > regionSize[ 0 ] ) ? (size_t)random_in_range( 0, (int)( width_lod - regionSize[ 0 ] - 1 ), d ) : 0;
83 sourcePos[ 1 ] = ( imageInfo->arraySize > regionSize[ 1 ] ) ? (size_t)random_in_range( 0, (int)( imageInfo->arraySize - regionSize[ 1 ] - 1 ), d ) : 0;
84
85
86 destPos[ 0 ] = ( width_lod > regionSize[ 0 ] ) ? (size_t)random_in_range( 0, (int)( width_lod - regionSize[ 0 ] - 1 ), d ) : 0;
87 destPos[ 1 ] = ( imageInfo->arraySize > regionSize[ 1 ] ) ? (size_t)random_in_range( 0, (int)( imageInfo->arraySize - regionSize[ 1 ] - 1 ), d ) : 0;
88
89
90 // Go for it!
91 retCode = test_copy_image_generic( context, queue, imageInfo, imageInfo, sourcePos, destPos, regionSize, d );
92 if( retCode < 0 )
93 return retCode;
94 else
95 ret += retCode;
96 }
97
98 return ret;
99 }
100
test_copy_image_set_1D_array(cl_device_id device,cl_context context,cl_command_queue queue,cl_image_format * format)101 int test_copy_image_set_1D_array( cl_device_id device, cl_context context, cl_command_queue queue, cl_image_format *format )
102 {
103 size_t maxWidth, maxArraySize;
104 cl_ulong maxAllocSize, memSize;
105 image_descriptor imageInfo = { 0 };
106 RandomSeed seed(gRandomSeed);
107 size_t pixelSize;
108
109 imageInfo.format = format;
110 imageInfo.type = CL_MEM_OBJECT_IMAGE1D_ARRAY;
111 pixelSize = get_pixel_size( imageInfo.format );
112
113 int error = clGetDeviceInfo( device, CL_DEVICE_IMAGE2D_MAX_WIDTH, sizeof( maxWidth ), &maxWidth, NULL );
114 error |= clGetDeviceInfo( device, CL_DEVICE_IMAGE_MAX_ARRAY_SIZE, sizeof( maxArraySize ), &maxArraySize, NULL );
115 error |= clGetDeviceInfo( device, CL_DEVICE_MAX_MEM_ALLOC_SIZE, sizeof( maxAllocSize ), &maxAllocSize, NULL );
116 error |= clGetDeviceInfo( device, CL_DEVICE_GLOBAL_MEM_SIZE, sizeof( memSize ), &memSize, NULL );
117 test_error( error, "Unable to get max image 1D array size from device" );
118
119 if (memSize > (cl_ulong)SIZE_MAX) {
120 memSize = (cl_ulong)SIZE_MAX;
121 maxAllocSize = (cl_ulong)SIZE_MAX;
122 }
123
124 if( gTestSmallImages )
125 {
126 for( imageInfo.width = 1; imageInfo.width < 13; imageInfo.width++ )
127 {
128 size_t rowPadding = gEnablePitch ? 48 : 0;
129
130 imageInfo.rowPitch = imageInfo.width * pixelSize + rowPadding;
131
132 if (gTestMipmaps)
133 imageInfo.num_mip_levels = (cl_uint) random_log_in_range(2, (int)compute_max_mip_levels(imageInfo.width, 0, 0), seed);
134
135 if (gEnablePitch)
136 {
137 do {
138 rowPadding++;
139 imageInfo.rowPitch = imageInfo.width * pixelSize + rowPadding;
140 } while ((imageInfo.rowPitch % pixelSize) != 0);
141 }
142
143 imageInfo.slicePitch = imageInfo.rowPitch;
144 for( imageInfo.arraySize = 2; imageInfo.arraySize < 9; imageInfo.arraySize++ )
145 {
146 if( gDebugTrace )
147 log_info( " at size %d,%d\n", (int)imageInfo.width, (int)imageInfo.arraySize );
148
149 int ret = test_copy_image_size_1D_array( context, queue, &imageInfo, seed );
150 if( ret )
151 return -1;
152 }
153 }
154 }
155 else if( gTestMaxImages )
156 {
157 // Try a specific set of maximum sizes
158 size_t numbeOfSizes;
159 size_t sizes[100][3];
160
161 get_max_sizes(&numbeOfSizes, 100, sizes, maxWidth, 1, 1, maxArraySize, maxAllocSize, memSize, CL_MEM_OBJECT_IMAGE1D_ARRAY, imageInfo.format);
162
163 for( size_t idx = 0; idx < numbeOfSizes; idx++ )
164 {
165 size_t rowPadding = gEnablePitch ? 48 : 0;
166
167 imageInfo.width = sizes[ idx ][ 0 ];
168 imageInfo.arraySize = sizes[ idx ][ 2 ];
169 imageInfo.rowPitch = imageInfo.width * pixelSize + rowPadding;
170
171 if (gTestMipmaps)
172 imageInfo.num_mip_levels = (cl_uint) random_log_in_range(2, (int)compute_max_mip_levels(imageInfo.width, 0, 0), seed);
173
174 if (gEnablePitch)
175 {
176 do {
177 rowPadding++;
178 imageInfo.rowPitch = imageInfo.width * pixelSize + rowPadding;
179 } while ((imageInfo.rowPitch % pixelSize) != 0);
180 }
181
182 imageInfo.slicePitch = imageInfo.rowPitch;
183 log_info( "Testing %d x %d\n", (int)sizes[ idx ][ 0 ], (int)sizes[ idx ][ 2 ] );
184 if( gDebugTrace )
185 log_info( " at max size %d,%d\n", (int)sizes[ idx ][ 0 ], (int)sizes[ idx ][ 2 ] );
186 if( test_copy_image_size_1D_array( context, queue, &imageInfo, seed ) )
187 return -1;
188 }
189 }
190 else
191 {
192 for( int i = 0; i < NUM_IMAGE_ITERATIONS; i++ )
193 {
194 cl_ulong size;
195 size_t rowPadding = gEnablePitch ? 48 : 0;
196 // Loop until we get a size that a) will fit in the max alloc size and b) that an allocation of that
197 // image, the result array, plus offset arrays, will fit in the global ram space
198 do
199 {
200 imageInfo.width = (size_t)random_log_in_range( 16, (int)maxWidth / 32, seed );
201 imageInfo.arraySize = (size_t)random_log_in_range( 16, (int)maxArraySize / 32, seed );
202 imageInfo.height = imageInfo.depth = 0;
203
204 if (gTestMipmaps)
205 {
206 imageInfo.num_mip_levels = (cl_uint) random_log_in_range(2, (int)compute_max_mip_levels(imageInfo.width, 0, 0), seed);
207 imageInfo.rowPitch = imageInfo.width * get_pixel_size( imageInfo.format );
208 imageInfo.slicePitch = imageInfo.rowPitch;
209 size = compute_mipmapped_image_size( imageInfo );
210 size = size*4;
211 }
212 else
213 {
214 imageInfo.rowPitch = imageInfo.width * pixelSize + rowPadding;
215
216 if (gEnablePitch)
217 {
218 do {
219 rowPadding++;
220 imageInfo.rowPitch = imageInfo.width * pixelSize + rowPadding;
221 } while ((imageInfo.rowPitch % pixelSize) != 0);
222 }
223
224 imageInfo.slicePitch = imageInfo.rowPitch;
225
226 size = (size_t)imageInfo.rowPitch * (size_t)imageInfo.arraySize * 4;
227 }
228 } while( size > maxAllocSize || ( size * 3 ) > memSize );
229
230 if( gDebugTrace )
231 log_info( " at size %d,%d (row pitch %d) out of %d,%d\n", (int)imageInfo.width, (int)imageInfo.arraySize, (int)imageInfo.rowPitch, (int)maxWidth, (int)maxArraySize );
232 int ret = test_copy_image_size_1D_array( context, queue, &imageInfo, seed );
233 if( ret )
234 return -1;
235 }
236 }
237
238 return 0;
239 }
240