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 maxAllocSize = (cl_ulong)SIZE_MAX;
75 }
76
77 if( gTestSmallImages )
78 {
79 for( imageInfo.width = 1; imageInfo.width < 13; imageInfo.width++ )
80 {
81 size_t rowPadding = gEnablePitch ? 80 : 0;
82 size_t slicePadding = gEnablePitch ? 3 : 0;
83
84 imageInfo.rowPitch = imageInfo.width * pixelSize + rowPadding;
85
86 if (gTestMipmaps)
87 imageInfo.num_mip_levels = (cl_uint) random_log_in_range(2, (int)compute_max_mip_levels(imageInfo.width, imageInfo.height, 0), seed);
88
89 if (gEnablePitch)
90 {
91 do {
92 rowPadding++;
93 imageInfo.rowPitch = imageInfo.width * pixelSize + rowPadding;
94 } while ((imageInfo.rowPitch % pixelSize) != 0);
95 }
96
97 for( imageInfo.height = 1; imageInfo.height < 9; imageInfo.height++ )
98 {
99 imageInfo.slicePitch = imageInfo.rowPitch * (imageInfo.height + slicePadding);
100
101 for( imageInfo.arraySize = 2; imageInfo.arraySize < 9; imageInfo.arraySize++ )
102 {
103 if( gDebugTrace )
104 log_info( " at size %d,%d,%d\n", (int)imageInfo.width, (int)imageInfo.height, (int)imageInfo.arraySize );
105 int ret = test_copy_image_2D_array( context, queue, &imageInfo, seed );
106 if( ret )
107 return -1;
108 }
109 }
110 }
111 }
112 else if( gTestMaxImages )
113 {
114 // Try a specific set of maximum sizes
115 size_t numbeOfSizes;
116 size_t sizes[100][3];
117 get_max_sizes(&numbeOfSizes, 100, sizes, maxWidth, maxHeight, 1, maxArraySize, maxAllocSize, memSize, imageInfo.type, imageInfo.format);
118
119 for( size_t idx = 0; idx < numbeOfSizes; idx++ )
120 {
121 size_t rowPadding = gEnablePitch ? 80 : 0;
122 size_t slicePadding = gEnablePitch ? 3 : 0;
123
124 imageInfo.width = sizes[ idx ][ 0 ];
125 imageInfo.height = sizes[ idx ][ 1 ];
126 imageInfo.arraySize = sizes[ idx ][ 2 ];
127 imageInfo.rowPitch = imageInfo.width * pixelSize + rowPadding;
128
129 if (gTestMipmaps)
130 imageInfo.num_mip_levels = (cl_uint) random_log_in_range(2, (int)compute_max_mip_levels(imageInfo.width, imageInfo.height, 0), seed);
131
132 if (gEnablePitch)
133 {
134 do {
135 rowPadding++;
136 imageInfo.rowPitch = imageInfo.width * pixelSize + rowPadding;
137 } while ((imageInfo.rowPitch % pixelSize) != 0);
138 }
139
140 imageInfo.slicePitch = imageInfo.rowPitch * (imageInfo.height + slicePadding);
141 log_info( "Testing %d x %d x %d\n", (int)sizes[ idx ][ 0 ], (int)sizes[ idx ][ 1 ], (int)sizes[ idx ][ 2 ] );
142 if( gDebugTrace )
143 log_info( " at max size %d,%d,%d\n", (int)sizes[ idx ][ 0 ], (int)sizes[ idx ][ 1 ], (int)sizes[ idx ][ 2 ] );
144 if( test_copy_image_2D_array( context, queue, &imageInfo, seed ) )
145 return -1;
146 }
147 }
148 else
149 {
150 for( int i = 0; i < NUM_IMAGE_ITERATIONS; i++ )
151 {
152 cl_ulong size;
153 size_t rowPadding = gEnablePitch ? 80 : 0;
154 size_t slicePadding = gEnablePitch ? 3 : 0;
155 // Loop until we get a size that a) will fit in the max alloc size and b) that an allocation of that
156 // image, the result array, plus offset arrays, will fit in the global ram space
157 do
158 {
159 imageInfo.width = (size_t)random_log_in_range( 16, (int)maxWidth / 32, seed );
160 imageInfo.height = (size_t)random_log_in_range( 16, (int)maxHeight / 32, seed );
161 imageInfo.arraySize = (size_t)random_log_in_range( 16, (int)maxArraySize / 32, seed );
162
163 if (gTestMipmaps)
164 {
165 imageInfo.num_mip_levels = (cl_uint) random_log_in_range(2, (int)compute_max_mip_levels(imageInfo.width, imageInfo.height, 0), seed);
166 imageInfo.rowPitch = imageInfo.width * get_pixel_size( imageInfo.format );
167 imageInfo.slicePitch = imageInfo.rowPitch * imageInfo.height;
168 size = compute_mipmapped_image_size( imageInfo );
169 size = size*4;
170 }
171 else
172 {
173 imageInfo.rowPitch = imageInfo.width * pixelSize + rowPadding;
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 * (imageInfo.height + slicePadding);
183
184 size = (cl_ulong)imageInfo.slicePitch * (cl_ulong)imageInfo.arraySize * 4 * 4;
185 }
186 } while( size > maxAllocSize || ( size * 3 ) > memSize );
187
188 if( gDebugTrace )
189 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 );
190 int ret = test_copy_image_2D_array( context, queue, &imageInfo,seed );
191 if( ret )
192 return -1;
193 }
194 }
195
196 return 0;
197 }
198