• 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 #include "harness/imageHelpers.h"
19 #include <algorithm>
20 #include <iterator>
21 
22 extern cl_filter_mode     gFilterModeToUse;
23 extern cl_addressing_mode gAddressModeToUse;
24 extern int                gTypesToTest;
25 extern int                gNormalizedModeToUse;
26 extern cl_channel_type      gChannelTypeToUse;
27 
28 
29 extern bool gDebugTrace;
30 
31 extern int test_get_image_info_1D( cl_device_id device, cl_context context, cl_image_format *format, cl_mem_flags flags );
32 extern int test_get_image_info_2D( cl_device_id device, cl_context context, cl_image_format *format, cl_mem_flags flags );
33 extern int test_get_image_info_3D( cl_device_id device, cl_context context, cl_image_format *format, cl_mem_flags flags );
34 extern int test_get_image_info_1D_array( cl_device_id device, cl_context context, cl_image_format *format, cl_mem_flags flags );
35 extern int test_get_image_info_2D_array( cl_device_id device, cl_context context, cl_image_format *format, cl_mem_flags flags );
36 
check_minimum_supported(cl_image_format * formatList,unsigned int numFormats,cl_mem_flags flags,cl_mem_object_type image_type,cl_device_id device)37 static bool check_minimum_supported(cl_image_format *formatList,
38                                     unsigned int numFormats,
39                                     cl_mem_flags flags,
40                                     cl_mem_object_type image_type,
41                                     cl_device_id device)
42 {
43 	bool passed = true;
44 	Version version = get_device_cl_version(device);
45 	std::vector<cl_image_format> formatsToSupport;
46 	build_required_image_formats(flags, image_type, device, formatsToSupport);
47 
48 	for (auto &format: formatsToSupport)
49 	{
50 		if( !find_format( formatList, numFormats, &format ) )
51 		{
52 			log_error( "ERROR: Format required by OpenCL %s is not supported: ", version.to_string().c_str() );
53 			print_header( &format, true );
54 			passed = false;
55 		}
56 	}
57 
58 	return passed;
59 }
60 
test_image_type(cl_device_id device,cl_context context,cl_mem_object_type image_type,cl_mem_flags flags)61 int test_image_type( cl_device_id device, cl_context context, cl_mem_object_type image_type, cl_mem_flags flags )
62 {
63     log_info( "Running %s %s-only tests...\n", convert_image_type_to_string(image_type), flags == CL_MEM_READ_ONLY ? "read" : "write" );
64 
65     int ret = 0;
66 
67     // Grab the list of supported image formats for integer reads
68     cl_image_format *formatList;
69     bool *filterFlags;
70     unsigned int numFormats;
71 
72     if ( get_format_list( context, image_type, formatList, numFormats, flags ) )
73         return -1;
74 
75     BufferOwningPtr<cl_image_format> formatListBuf(formatList);
76 
77     if ((image_type == CL_MEM_OBJECT_IMAGE3D) && (flags != CL_MEM_READ_ONLY)) {
78         log_info("No requirement for 3D write in OpenCL 1.2. Not checking formats.\n");
79     } else {
80         log_info("Checking for required OpenCL 1.2 formats.\n");
81         if (check_minimum_supported( formatList, numFormats, flags, image_type, device ) == false) {
82             ret++;
83         } else {
84             log_info("All required formats present.\n");
85         }
86     }
87 
88     filterFlags = new bool[ numFormats ];
89     BufferOwningPtr<bool> filterFlagsBuf(filterFlags);
90 
91     if( filterFlags == NULL )
92     {
93         log_error( "ERROR: Out of memory allocating filter flags list!\n" );
94         return -1;
95     }
96     memset( filterFlags, 0, sizeof( bool ) * numFormats );
97     filter_formats( formatList, filterFlags, numFormats, 0 );
98 
99     // Run the format list
100     for( unsigned int i = 0; i < numFormats; i++ )
101     {
102         int test_return = 0;
103         if( filterFlags[i] )
104         {
105             log_info( "NOT RUNNING: " );
106             print_header( &formatList[ i ], false );
107             continue;
108         }
109 
110         print_header( &formatList[ i ], false );
111 
112         gTestCount++;
113 
114         switch (image_type) {
115           case CL_MEM_OBJECT_IMAGE1D:
116             test_return = test_get_image_info_1D( device, context, &formatList[ i ], flags );
117             break;
118           case CL_MEM_OBJECT_IMAGE2D:
119             test_return = test_get_image_info_2D( device, context,&formatList[ i ], flags );
120             break;
121           case CL_MEM_OBJECT_IMAGE3D:
122             test_return = test_get_image_info_3D( device, context, &formatList[ i ], flags );
123             break;
124           case CL_MEM_OBJECT_IMAGE1D_ARRAY:
125             test_return = test_get_image_info_1D_array( device, context, &formatList[ i ], flags );
126             break;
127           case CL_MEM_OBJECT_IMAGE2D_ARRAY:
128             test_return = test_get_image_info_2D_array( device, context, &formatList[ i ], flags );
129             break;
130         }
131 
132         if (test_return) {
133             gFailCount++;
134             log_error( "FAILED: " );
135             print_header( &formatList[ i ], true );
136             log_info( "\n" );
137         }
138 
139         ret += test_return;
140     }
141 
142     return ret;
143 }
144 
test_image_set(cl_device_id device,cl_context context,cl_mem_object_type image_type)145 int test_image_set( cl_device_id device, cl_context context, cl_mem_object_type image_type )
146 {
147     int ret = 0;
148 
149     ret += test_image_type( device, context, image_type, CL_MEM_READ_ONLY );
150     ret += test_image_type( device, context, image_type, CL_MEM_WRITE_ONLY );
151 
152     return ret;
153 }
154 
155 
156 
157 
158