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
filter_formats(const std::vector<cl_image_format> & formatList,std::vector<bool> & filterFlags,cl_channel_type * channelDataTypesToFilter,bool testMipmaps)61 int filter_formats(const std::vector<cl_image_format> &formatList,
62 std::vector<bool> &filterFlags,
63 cl_channel_type *channelDataTypesToFilter,
64 bool testMipmaps /*=false*/)
65 {
66 int numSupported = 0;
67 for (unsigned int j = 0; j < formatList.size(); j++)
68 {
69 // If this format has been previously filtered, remove the filter
70 if (filterFlags[j]) filterFlags[j] = false;
71
72 // skip mipmap tests for CL_DEPTH formats (re# Khronos Bug 13762)
73 if (testMipmaps && (formatList[j].image_channel_order == CL_DEPTH))
74 {
75 log_info("Skip mipmap tests for CL_DEPTH format\n");
76 filterFlags[j] = true;
77 continue;
78 }
79
80 // Have we already discarded the channel type via the command line?
81 if (gChannelTypeToUse != (cl_channel_type)-1
82 && gChannelTypeToUse != formatList[j].image_channel_data_type)
83 {
84 filterFlags[j] = true;
85 continue;
86 }
87
88 // Have we already discarded the channel order via the command line?
89 if (gChannelOrderToUse != (cl_channel_order)-1
90 && gChannelOrderToUse != formatList[j].image_channel_order)
91 {
92 filterFlags[j] = true;
93 continue;
94 }
95
96 // Is given format standard channel order and type given by spec. We
97 // don't want to test it if this is vendor extension
98 if (!IsChannelOrderSupported(formatList[j].image_channel_order)
99 || !IsChannelTypeSupported(formatList[j].image_channel_data_type))
100 {
101 filterFlags[j] = true;
102 continue;
103 }
104
105 if (!channelDataTypesToFilter)
106 {
107 numSupported++;
108 continue;
109 }
110
111 // Is the format supported?
112 int i;
113 for (i = 0; channelDataTypesToFilter[i] != (cl_channel_type)-1; i++)
114 {
115 if (formatList[j].image_channel_data_type
116 == channelDataTypesToFilter[i])
117 {
118 numSupported++;
119 break;
120 }
121 }
122 if (channelDataTypesToFilter[i] == (cl_channel_type)-1)
123 {
124 // Format is NOT supported, so mark it as such
125 filterFlags[j] = true;
126 }
127 }
128 return numSupported;
129 }
130
get_format_list(cl_context context,cl_mem_object_type imageType,std::vector<cl_image_format> & outFormatList,cl_mem_flags flags)131 int get_format_list(cl_context context, cl_mem_object_type imageType,
132 std::vector<cl_image_format> &outFormatList,
133 cl_mem_flags flags)
134 {
135 cl_uint formatCount;
136 int error = clGetSupportedImageFormats(context, flags, imageType, 0, NULL,
137 &formatCount);
138 test_error(error, "Unable to get count of supported image formats");
139
140 outFormatList.resize(formatCount);
141
142 error = clGetSupportedImageFormats(context, flags, imageType, formatCount,
143 outFormatList.data(), NULL);
144 test_error(error, "Unable to get list of supported image formats");
145 return 0;
146 }
147
random_in_ranges(size_t minimum,size_t rangeA,size_t rangeB,MTdata d)148 size_t random_in_ranges(size_t minimum, size_t rangeA, size_t rangeB, MTdata d)
149 {
150 if (rangeB < rangeA) rangeA = rangeB;
151 if (rangeA < minimum) return rangeA;
152 return (size_t)random_in_range((int)minimum, (int)rangeA - 1, d);
153 }
154