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