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 gTypesToTest;
20
21 extern int test_fill_image_set_1D( cl_device_id device, cl_context context, cl_command_queue queue, cl_image_format *format, ExplicitType outputType );
22 extern int test_fill_image_set_2D( cl_device_id device, cl_context context, cl_command_queue queue, cl_image_format *format, ExplicitType outputType );
23 extern int test_fill_image_set_3D( cl_device_id device, cl_context context, cl_command_queue queue, cl_image_format *format, ExplicitType outputType );
24 extern int test_fill_image_set_1D_array( cl_device_id device, cl_context context, cl_command_queue queue, cl_image_format *format, ExplicitType outputType );
25 extern int test_fill_image_set_2D_array( cl_device_id device, cl_context context, cl_command_queue queue, cl_image_format *format, ExplicitType outputType );
26 typedef int (*test_func)(cl_device_id device, cl_context context,
27 cl_command_queue queue, cl_image_format *format,
28 ExplicitType outputType);
29
test_image_type(cl_device_id device,cl_context context,cl_command_queue queue,MethodsToTest testMethod,cl_mem_flags flags)30 int test_image_type( cl_device_id device, cl_context context, cl_command_queue queue, MethodsToTest testMethod, cl_mem_flags flags )
31 {
32 const char *name;
33 cl_mem_object_type imageType;
34 test_func test_fn;
35
36 if ( testMethod == k1D )
37 {
38 name = "1D Image Fill";
39 imageType = CL_MEM_OBJECT_IMAGE1D;
40 test_fn = &test_fill_image_set_1D;
41 }
42 else if ( testMethod == k2D )
43 {
44 name = "2D Image Fill";
45 imageType = CL_MEM_OBJECT_IMAGE2D;
46 test_fn = &test_fill_image_set_2D;
47 }
48 else if ( testMethod == k1DArray )
49 {
50 name = "1D Image Array Fill";
51 imageType = CL_MEM_OBJECT_IMAGE1D_ARRAY;
52 test_fn = &test_fill_image_set_1D_array;
53 }
54 else if ( testMethod == k2DArray )
55 {
56 name = "2D Image Array Fill";
57 imageType = CL_MEM_OBJECT_IMAGE2D_ARRAY;
58 test_fn = &test_fill_image_set_2D_array;
59 }
60 else if ( testMethod == k3D )
61 {
62 name = "3D Image Fill";
63 imageType = CL_MEM_OBJECT_IMAGE3D;
64 test_fn = &test_fill_image_set_3D;
65 }
66
67 log_info( "Running %s tests...\n", name );
68
69 int ret = 0;
70
71 // Grab the list of supported image formats
72 std::vector<cl_image_format> formatList;
73 if (get_format_list(context, imageType, formatList, flags)) return -1;
74
75 for (auto test : imageTestTypes)
76 {
77 if (gTypesToTest & test.type)
78 {
79 std::vector<bool> filterFlags(formatList.size(), false);
80 if (filter_formats(formatList, filterFlags, test.channelTypes) == 0)
81 {
82 log_info("No formats supported for %s type\n", test.name);
83 }
84 else
85 {
86 // Run the format list
87 for (unsigned int i = 0; i < formatList.size(); i++)
88 {
89 if (filterFlags[i])
90 {
91 continue;
92 }
93
94 print_header(&formatList[i], false);
95
96 gTestCount++;
97
98 int test_return =
99 test_fn(device, context, queue, &formatList[i],
100 test.explicitType);
101 if (test_return)
102 {
103 gFailCount++;
104 log_error("FAILED: ");
105 print_header(&formatList[i], true);
106 log_info("\n");
107 }
108
109 ret += test_return;
110 }
111 }
112 }
113 }
114
115 return ret;
116 }
117
118
test_image_set(cl_device_id device,cl_context context,cl_command_queue queue,MethodsToTest testMethod)119 int test_image_set( cl_device_id device, cl_context context, cl_command_queue queue, MethodsToTest testMethod )
120 {
121 int ret = 0;
122
123 ret += test_image_type( device, context, queue, testMethod, CL_MEM_READ_ONLY );
124
125 return ret;
126 }
127