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 #include "../common.h"
18
19 extern int test_copy_image_set_1D( cl_device_id device, cl_context context, cl_command_queue queue, cl_image_format *format );
20 extern int test_copy_image_set_2D( cl_device_id device, cl_context context, cl_command_queue queue, cl_image_format *format );
21 extern int test_copy_image_set_3D( cl_device_id device, cl_context context, cl_command_queue queue, cl_image_format *format );
22 extern int test_copy_image_set_1D_array( cl_device_id device, cl_context context, cl_command_queue queue, cl_image_format *format );
23 extern int test_copy_image_set_2D_array( cl_device_id device, cl_context context, cl_command_queue queue, cl_image_format *format );
24 extern int test_copy_image_set_2D_3D( cl_device_id device, cl_context context, cl_command_queue queue, cl_image_format *format, bool reverse );
25 extern int test_copy_image_set_2D_2D_array( cl_device_id device, cl_context context, cl_command_queue queue, cl_image_format *format, bool reverse );
26 extern int test_copy_image_set_3D_2D_array( cl_device_id device, cl_context context, cl_command_queue queue, cl_image_format *format, bool reverse );
27
test_image_type(cl_device_id device,cl_context context,cl_command_queue queue,MethodsToTest testMethod,cl_mem_flags flags)28 int test_image_type( cl_device_id device, cl_context context, cl_command_queue queue, MethodsToTest testMethod, cl_mem_flags flags )
29 {
30 const char *name;
31 cl_mem_object_type imageType;
32
33 if ( gTestMipmaps )
34 {
35 if ( 0 == is_extension_available( device, "cl_khr_mipmap_image" ))
36 {
37 log_info( "-----------------------------------------------------\n" );
38 log_info( "This device does not support cl_khr_mipmap_image.\nSkipping mipmapped image test. \n" );
39 log_info( "-----------------------------------------------------\n\n" );
40 return 0;
41 }
42 }
43
44 if( testMethod == k1D )
45 {
46 name = "1D -> 1D";
47 imageType = CL_MEM_OBJECT_IMAGE1D;
48 }
49 else if( testMethod == k2D )
50 {
51 name = "2D -> 2D";
52 imageType = CL_MEM_OBJECT_IMAGE2D;
53 }
54 else if( testMethod == k3D )
55 {
56 name = "3D -> 3D";
57 imageType = CL_MEM_OBJECT_IMAGE3D;
58 }
59 else if( testMethod == k1DArray )
60 {
61 name = "1D array -> 1D array";
62 imageType = CL_MEM_OBJECT_IMAGE1D_ARRAY;
63 }
64 else if( testMethod == k2DArray )
65 {
66 name = "2D array -> 2D array";
67 imageType = CL_MEM_OBJECT_IMAGE2D_ARRAY;
68 }
69 else if( testMethod == k2DTo3D )
70 {
71 name = "2D -> 3D";
72 imageType = CL_MEM_OBJECT_IMAGE3D;
73 }
74 else if( testMethod == k3DTo2D )
75 {
76 name = "3D -> 2D";
77 imageType = CL_MEM_OBJECT_IMAGE3D;
78 }
79 else if( testMethod == k2DArrayTo2D )
80 {
81 name = "2D array -> 2D";
82 imageType = CL_MEM_OBJECT_IMAGE2D_ARRAY;
83 }
84 else if( testMethod == k2DTo2DArray )
85 {
86 name = "2D -> 2D array";
87 imageType = CL_MEM_OBJECT_IMAGE2D_ARRAY;
88 }
89 else if( testMethod == k2DArrayTo3D )
90 {
91 name = "2D array -> 3D";
92 imageType = CL_MEM_OBJECT_IMAGE3D;
93 }
94 else if( testMethod == k3DTo2DArray )
95 {
96 name = "3D -> 2D array";
97 imageType = CL_MEM_OBJECT_IMAGE3D;
98 }
99
100 if(gTestMipmaps)
101 log_info( "Running mipmapped %s tests...\n", name );
102 else
103 log_info( "Running %s tests...\n", name );
104
105 int ret = 0;
106
107 // Grab the list of supported image formats for integer reads
108 std::vector<cl_image_format> formatList;
109 if (get_format_list(context, imageType, formatList, flags)) return -1;
110
111 std::vector<bool> filterFlags(formatList.size(), false);
112 filter_formats(formatList, filterFlags, nullptr);
113
114 // Run the format list
115 for (unsigned int i = 0; i < formatList.size(); i++)
116 {
117 int test_return = 0;
118 if( filterFlags[i] )
119 {
120 continue;
121 }
122
123 print_header( &formatList[ i ], false );
124
125 gTestCount++;
126
127 if( testMethod == k1D )
128 test_return = test_copy_image_set_1D( device, context, queue, &formatList[ i ] );
129 else if( testMethod == k2D )
130 test_return = test_copy_image_set_2D( device, context, queue, &formatList[ i ] );
131 else if( testMethod == k3D )
132 test_return = test_copy_image_set_3D( device, context, queue,&formatList[ i ] );
133 else if( testMethod == k1DArray )
134 test_return = test_copy_image_set_1D_array( device, context, queue, &formatList[ i ] );
135 else if( testMethod == k2DArray )
136 test_return = test_copy_image_set_2D_array( device, context, queue, &formatList[ i ] );
137 else if( testMethod == k2DTo3D )
138 test_return = test_copy_image_set_2D_3D( device, context, queue, &formatList[ i ], false );
139 else if( testMethod == k3DTo2D )
140 test_return = test_copy_image_set_2D_3D( device, context, queue, &formatList[ i ], true );
141 else if( testMethod == k2DArrayTo2D)
142 test_return = test_copy_image_set_2D_2D_array( device, context, queue, &formatList[ i ], true);
143 else if( testMethod == k2DTo2DArray)
144 test_return = test_copy_image_set_2D_2D_array( device, context, queue, &formatList[ i ], false);
145 else if( testMethod == k2DArrayTo3D)
146 test_return = test_copy_image_set_3D_2D_array( device, context, queue, &formatList[ i ], true);
147 else if( testMethod == k3DTo2DArray)
148 test_return = test_copy_image_set_3D_2D_array( device, context, queue, &formatList[ i ], false);
149
150 if (test_return) {
151 gFailCount++;
152 log_error( "FAILED: " );
153 print_header( &formatList[ i ], true );
154 log_info( "\n" );
155 }
156
157 ret += test_return;
158 }
159
160 return ret;
161 }
162
test_image_set(cl_device_id device,cl_context context,cl_command_queue queue,MethodsToTest testMethod)163 int test_image_set( cl_device_id device, cl_context context, cl_command_queue queue, MethodsToTest testMethod )
164 {
165 int ret = 0;
166
167 ret += test_image_type( device, context, queue, testMethod, CL_MEM_READ_ONLY );
168
169 return ret;
170 }
171
172
173
174
175