• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 extern cl_channel_type      gChannelTypeToUse;
21 extern cl_channel_order     gChannelOrderToUse;
22 
23 extern bool                 gDebugTrace;
24 extern bool                 gDeviceLt20;
25 
26 extern bool                 gTestReadWrite;
27 
28 extern int test_read_image_set_1D( cl_device_id device, cl_context context, cl_command_queue queue, cl_image_format *format, image_sampler_data *imageSampler, ExplicitType outputType );
29 extern int test_read_image_set_1D_buffer( cl_device_id device, cl_context context, cl_command_queue queue, cl_image_format *format, image_sampler_data *imageSampler, ExplicitType outputType );
30 extern int test_read_image_set_2D( cl_device_id device, cl_context context, cl_command_queue queue, cl_image_format *format, image_sampler_data *imageSampler, ExplicitType outputType );
31 extern int test_read_image_set_3D( cl_device_id device, cl_context context, cl_command_queue queue, cl_image_format *format, image_sampler_data *imageSampler, ExplicitType outputType );
32 extern int test_read_image_set_1D_array( cl_device_id device, cl_context context, cl_command_queue queue, cl_image_format *format, image_sampler_data *imageSampler, ExplicitType outputType );
33 extern int test_read_image_set_2D_array( cl_device_id device, cl_context context, cl_command_queue queue, cl_image_format *format, image_sampler_data *imageSampler, ExplicitType outputType );
34 
test_read_image_type(cl_device_id device,cl_context context,cl_command_queue queue,cl_image_format * format,image_sampler_data * imageSampler,ExplicitType outputType,cl_mem_object_type imageType)35 int test_read_image_type( cl_device_id device, cl_context context, cl_command_queue queue, cl_image_format *format,
36                           image_sampler_data *imageSampler, ExplicitType outputType, cl_mem_object_type imageType )
37 {
38     int ret = 0;
39     imageSampler->addressing_mode = CL_ADDRESS_NONE;
40 
41     print_read_header( format, imageSampler, false );
42 
43     gTestCount++;
44 
45     switch (imageType)
46     {
47         case CL_MEM_OBJECT_IMAGE1D:
48             ret = test_read_image_set_1D( device, context, queue, format, imageSampler, outputType );
49             break;
50         case CL_MEM_OBJECT_IMAGE1D_BUFFER:
51             ret += test_read_image_set_1D_buffer( device, context, queue, format, imageSampler, outputType );
52             break;
53         case CL_MEM_OBJECT_IMAGE2D:
54             ret = test_read_image_set_2D( device, context, queue, format, imageSampler, outputType );
55             break;
56         case CL_MEM_OBJECT_IMAGE3D:
57             ret = test_read_image_set_3D( device, context, queue, format, imageSampler, outputType );
58             break;
59         case CL_MEM_OBJECT_IMAGE1D_ARRAY:
60             ret = test_read_image_set_1D_array( device, context, queue, format, imageSampler, outputType );
61             break;
62         case CL_MEM_OBJECT_IMAGE2D_ARRAY:
63             ret = test_read_image_set_2D_array( device, context, queue, format, imageSampler, outputType );
64             break;
65     }
66 
67     if ( ret != 0 )
68     {
69         gFailCount++;
70         log_error( "FAILED: " );
71         print_read_header( format, imageSampler, true );
72         log_info( "\n" );
73     }
74     return ret;
75 }
76 
test_read_image_formats(cl_device_id device,cl_context context,cl_command_queue queue,cl_image_format * formatList,bool * filterFlags,unsigned int numFormats,image_sampler_data * imageSampler,ExplicitType outputType,cl_mem_object_type imageType)77 int test_read_image_formats( cl_device_id device, cl_context context, cl_command_queue queue, cl_image_format *formatList, bool *filterFlags, unsigned int numFormats,
78                              image_sampler_data *imageSampler, ExplicitType outputType, cl_mem_object_type imageType )
79 {
80     int ret = 0;
81     imageSampler->normalized_coords = false;
82     log_info( "read_image (%s coords, %s results) *****************************\n",
83               "integer", get_explicit_type_name( outputType ) );
84 
85     for ( unsigned int i = 0; i < numFormats; i++ )
86     {
87         if ( filterFlags[i] )
88             continue;
89 
90         cl_image_format &imageFormat = formatList[ i ];
91 
92         ret |= test_read_image_type( device, context, queue, &imageFormat, imageSampler, outputType, imageType );
93     }
94     return ret;
95 }
96 
97 
test_image_set(cl_device_id device,cl_context context,cl_command_queue queue,cl_mem_object_type imageType)98 int test_image_set( cl_device_id device, cl_context context, cl_command_queue queue, cl_mem_object_type imageType )
99 {
100     int ret = 0;
101     static int printedFormatList = -1;
102 
103     // Grab the list of supported image formats
104     cl_image_format *formatList;
105     bool *filterFlags;
106     unsigned int numFormats;
107     auto version = get_device_cl_version(device);
108     if (version < Version(2, 0)) {
109         gDeviceLt20 = true;
110     }
111 
112     if (gDeviceLt20 && gTestReadWrite) {
113         log_info("TEST skipped, Opencl 2.0 + requried for this test");
114         return ret;
115     }
116 
117     // This flag is only for querying the list of supported formats
118     // The flag for creating image will be set explicitly in test functions
119     cl_mem_flags flags = (gTestReadWrite)? CL_MEM_KERNEL_READ_AND_WRITE : CL_MEM_READ_ONLY;
120 
121     if ( get_format_list( context, imageType, formatList, numFormats, flags ) )
122         return -1;
123 
124     filterFlags = new bool[ numFormats ];
125     if ( filterFlags == NULL )
126     {
127         log_error( "ERROR: Out of memory allocating filter flags list!\n" );
128         return -1;
129     }
130     memset( filterFlags, 0, sizeof( bool ) * numFormats );
131 
132     // First time through, we'll go ahead and print the formats supported, regardless of type
133     if ( printedFormatList != (int)imageType )
134     {
135         log_info( "---- Supported %s read formats for this device ---- \n", convert_image_type_to_string(imageType) );
136         for ( unsigned int f = 0; f < numFormats; f++ )
137             log_info( "  %-7s %-24s %d\n", GetChannelOrderName( formatList[ f ].image_channel_order ),
138                       GetChannelTypeName( formatList[ f ].image_channel_data_type ),
139                       (int)get_format_channel_count( &formatList[ f ] ) );
140         log_info( "------------------------------------------- \n" );
141         printedFormatList = imageType;
142     }
143 
144     image_sampler_data imageSampler;
145 
146     for (auto test : imageTestTypes)
147     {
148         if (gTypesToTest & test.type)
149         {
150             if (filter_formats(formatList, filterFlags, numFormats,
151                                test.channelTypes)
152                 == 0)
153             {
154                 log_info("No formats supported for %s type\n", test.name);
155             }
156             else
157             {
158                 imageSampler.filter_mode = CL_FILTER_NEAREST;
159                 ret += test_read_image_formats(
160                     device, context, queue, formatList, filterFlags, numFormats,
161                     &imageSampler, test.explicitType, imageType);
162             }
163         }
164     }
165 
166     delete[] filterFlags;
167     delete[] formatList;
168 
169     return ret;
170 }
171