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 }
122
123 if( gTestSmallImages )
124 {
125 for( imageInfo.width = 1; imageInfo.width < 13; imageInfo.width++ )
126 {
127 size_t rowPadding = gEnablePitch ? 48 : 0;
128
129 imageInfo.rowPitch = imageInfo.width * pixelSize + rowPadding;
130
131 if (gTestMipmaps)
132 imageInfo.num_mip_levels = (cl_uint) random_log_in_range(2, (int)compute_max_mip_levels(imageInfo.width, 0, 0), seed);
133
134 if (gEnablePitch)
135 {
136 do {
137 rowPadding++;
138 imageInfo.rowPitch = imageInfo.width * pixelSize + rowPadding;
139 } while ((imageInfo.rowPitch % pixelSize) != 0);
140 }
141
142 imageInfo.slicePitch = imageInfo.rowPitch;
143 for( imageInfo.arraySize = 2; imageInfo.arraySize < 9; imageInfo.arraySize++ )
144 {
145 if( gDebugTrace )
146 log_info( " at size %d,%d\n", (int)imageInfo.width, (int)imageInfo.arraySize );
147
148 int ret = test_copy_image_size_1D_array( context, queue, &imageInfo, seed );
149 if( ret )
150 return -1;
151 }
152 }
153 }
154 else if( gTestMaxImages )
155 {
156 // Try a specific set of maximum sizes
157 size_t numbeOfSizes;
158 size_t sizes[100][3];
159
160 get_max_sizes(&numbeOfSizes, 100, sizes, maxWidth, 1, 1, maxArraySize, maxAllocSize, memSize, CL_MEM_OBJECT_IMAGE1D_ARRAY, imageInfo.format);
161
162 for( size_t idx = 0; idx < numbeOfSizes; idx++ )
163 {
164 size_t rowPadding = gEnablePitch ? 48 : 0;
165
166 imageInfo.width = sizes[ idx ][ 0 ];
167 imageInfo.arraySize = sizes[ idx ][ 2 ];
168 imageInfo.rowPitch = imageInfo.width * pixelSize + rowPadding;
169
170 if (gTestMipmaps)
171 imageInfo.num_mip_levels = (cl_uint) random_log_in_range(2, (int)compute_max_mip_levels(imageInfo.width, 0, 0), seed);
172
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;
182 log_info( "Testing %d x %d\n", (int)sizes[ idx ][ 0 ], (int)sizes[ idx ][ 2 ] );
183 if( gDebugTrace )
184 log_info( " at max size %d,%d\n", (int)sizes[ idx ][ 0 ], (int)sizes[ idx ][ 2 ] );
185 if( test_copy_image_size_1D_array( context, queue, &imageInfo, seed ) )
186 return -1;
187 }
188 }
189 else
190 {
191 for( int i = 0; i < NUM_IMAGE_ITERATIONS; i++ )
192 {
193 cl_ulong size;
194 size_t rowPadding = gEnablePitch ? 48 : 0;
195 // Loop until we get a size that a) will fit in the max alloc size and b) that an allocation of that
196 // image, the result array, plus offset arrays, will fit in the global ram space
197 do
198 {
199 imageInfo.width = (size_t)random_log_in_range( 16, (int)maxWidth / 32, seed );
200 imageInfo.arraySize = (size_t)random_log_in_range( 16, (int)maxArraySize / 32, seed );
201 imageInfo.height = imageInfo.depth = 0;
202
203 if (gTestMipmaps)
204 {
205 imageInfo.num_mip_levels = (cl_uint) random_log_in_range(2, (int)compute_max_mip_levels(imageInfo.width, 0, 0), seed);
206 imageInfo.rowPitch = imageInfo.width * get_pixel_size( imageInfo.format );
207 imageInfo.slicePitch = imageInfo.rowPitch;
208 size = compute_mipmapped_image_size( imageInfo );
209 size = size*4;
210 }
211 else
212 {
213 imageInfo.rowPitch = imageInfo.width * pixelSize + rowPadding;
214
215 if (gEnablePitch)
216 {
217 do {
218 rowPadding++;
219 imageInfo.rowPitch = imageInfo.width * pixelSize + rowPadding;
220 } while ((imageInfo.rowPitch % pixelSize) != 0);
221 }
222
223 imageInfo.slicePitch = imageInfo.rowPitch;
224
225 size = (size_t)imageInfo.rowPitch * (size_t)imageInfo.arraySize * 4;
226 }
227 } while( size > maxAllocSize || ( size * 3 ) > memSize );
228
229 if( gDebugTrace )
230 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 );
231 int ret = test_copy_image_size_1D_array( context, queue, &imageInfo, seed );
232 if( ret )
233 return -1;
234 }
235 }
236
237 return 0;
238 }
239