1 //
2 // Copyright (c) 2020 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 "common.h"
17
18 cl_channel_type floatFormats[] = {
19 CL_UNORM_SHORT_565,
20 CL_UNORM_SHORT_555,
21 CL_UNORM_INT_101010,
22 #ifdef OBSOLETE_FORAMT
23 CL_UNORM_SHORT_565_REV,
24 CL_UNORM_SHORT_555_REV,
25 CL_UNORM_INT_8888,
26 CL_UNORM_INT_8888_REV,
27 CL_UNORM_INT_101010_REV,
28 #endif
29 #ifdef CL_SFIXED14_APPLE
30 CL_SFIXED14_APPLE,
31 #endif
32 CL_UNORM_INT8,
33 CL_SNORM_INT8,
34 CL_UNORM_INT16,
35 CL_SNORM_INT16,
36 CL_FLOAT,
37 CL_HALF_FLOAT,
38 (cl_channel_type)-1,
39 };
40
41 cl_channel_type intFormats[] = {
42 CL_SIGNED_INT8,
43 CL_SIGNED_INT16,
44 CL_SIGNED_INT32,
45 (cl_channel_type)-1,
46 };
47
48 cl_channel_type uintFormats[] = {
49 CL_UNSIGNED_INT8,
50 CL_UNSIGNED_INT16,
51 CL_UNSIGNED_INT32,
52 (cl_channel_type)-1,
53 };
54
55 std::array<ImageTestTypes, 3> imageTestTypes = { {
56 { kTestInt, kInt, intFormats, "int" },
57 { kTestUInt, kUInt, uintFormats, "uint" },
58 { kTestFloat, kFloat, floatFormats, "float" },
59 } };
60
convert_image_type_to_string(cl_mem_object_type image_type)61 const char *convert_image_type_to_string(cl_mem_object_type image_type)
62 {
63 switch (image_type)
64 {
65 case CL_MEM_OBJECT_IMAGE1D: return "1D";
66 case CL_MEM_OBJECT_IMAGE2D: return "2D";
67 case CL_MEM_OBJECT_IMAGE3D: return "3D";
68 case CL_MEM_OBJECT_IMAGE1D_ARRAY: return "1D array";
69 case CL_MEM_OBJECT_IMAGE2D_ARRAY: return "2D array";
70 case CL_MEM_OBJECT_IMAGE1D_BUFFER: return "1D image buffer";
71 default: return "unrecognized object type";
72 }
73 }
74
filter_formats(cl_image_format * formatList,bool * filterFlags,unsigned int formatCount,cl_channel_type * channelDataTypesToFilter,bool testMipmaps)75 int filter_formats(cl_image_format *formatList, bool *filterFlags,
76 unsigned int formatCount,
77 cl_channel_type *channelDataTypesToFilter,
78 bool testMipmaps /*=false*/)
79 {
80 int numSupported = 0;
81 for (unsigned int j = 0; j < formatCount; j++)
82 {
83 // If this format has been previously filtered, remove the filter
84 if (filterFlags[j]) filterFlags[j] = false;
85
86 // skip mipmap tests for CL_DEPTH formats (re# Khronos Bug 13762)
87 if (testMipmaps && (formatList[j].image_channel_order == CL_DEPTH))
88 {
89 log_info("Skip mipmap tests for CL_DEPTH format\n");
90 filterFlags[j] = true;
91 continue;
92 }
93
94 // Have we already discarded the channel type via the command line?
95 if (gChannelTypeToUse != (cl_channel_type)-1
96 && gChannelTypeToUse != formatList[j].image_channel_data_type)
97 {
98 filterFlags[j] = true;
99 continue;
100 }
101
102 // Have we already discarded the channel order via the command line?
103 if (gChannelOrderToUse != (cl_channel_order)-1
104 && gChannelOrderToUse != formatList[j].image_channel_order)
105 {
106 filterFlags[j] = true;
107 continue;
108 }
109
110 // Is given format standard channel order and type given by spec. We
111 // don't want to test it if this is vendor extension
112 if (!IsChannelOrderSupported(formatList[j].image_channel_order)
113 || !IsChannelTypeSupported(formatList[j].image_channel_data_type))
114 {
115 filterFlags[j] = true;
116 continue;
117 }
118
119 if (!channelDataTypesToFilter)
120 {
121 numSupported++;
122 continue;
123 }
124
125 // Is the format supported?
126 int i;
127 for (i = 0; channelDataTypesToFilter[i] != (cl_channel_type)-1; i++)
128 {
129 if (formatList[j].image_channel_data_type
130 == channelDataTypesToFilter[i])
131 {
132 numSupported++;
133 break;
134 }
135 }
136 if (channelDataTypesToFilter[i] == (cl_channel_type)-1)
137 {
138 // Format is NOT supported, so mark it as such
139 filterFlags[j] = true;
140 }
141 }
142 return numSupported;
143 }
144
get_format_list(cl_context context,cl_mem_object_type imageType,cl_image_format * & outFormatList,unsigned int & outFormatCount,cl_mem_flags flags)145 int get_format_list(cl_context context, cl_mem_object_type imageType,
146 cl_image_format *&outFormatList,
147 unsigned int &outFormatCount, cl_mem_flags flags)
148 {
149 int error = clGetSupportedImageFormats(context, flags, imageType, 0, NULL,
150 &outFormatCount);
151 test_error(error, "Unable to get count of supported image formats");
152
153 outFormatList =
154 (outFormatCount > 0) ? new cl_image_format[outFormatCount] : NULL;
155
156 error = clGetSupportedImageFormats(context, flags, imageType,
157 outFormatCount, outFormatList, NULL);
158 test_error(error, "Unable to get list of supported image formats");
159 return 0;
160 }
161
random_in_ranges(size_t minimum,size_t rangeA,size_t rangeB,MTdata d)162 size_t random_in_ranges(size_t minimum, size_t rangeA, size_t rangeB, MTdata d)
163 {
164 if (rangeB < rangeA) rangeA = rangeB;
165 if (rangeA < minimum) return rangeA;
166 return (size_t)random_in_range((int)minimum, (int)rangeA - 1, d);
167 }
168