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