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