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