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 cl_filter_mode gFilterModeToUse;
20 extern cl_addressing_mode gAddressModeToUse;
21 extern int gTypesToTest;
22 extern int gNormalizedModeToUse;
23 extern cl_channel_type gChannelTypeToUse;
24 extern bool gDeviceLt20;
25
26 extern bool gDebugTrace;
27
28 extern int test_get_image_info_1D( cl_device_id device, cl_context context, cl_command_queue queue, cl_image_format *format );
29 extern int test_get_image_info_2D( cl_device_id device, cl_context context, cl_command_queue queue, cl_image_format *format );
30 extern int test_get_image_info_3D( cl_device_id device, cl_context context, cl_command_queue queue, cl_image_format *format );
31 extern int test_get_image_info_1D_array( cl_device_id device, cl_context context, cl_command_queue queue, cl_image_format *format );
32 extern int test_get_image_info_2D_array( cl_device_id device, cl_context context, cl_command_queue queue, cl_image_format *format );
33
test_image_type(cl_device_id device,cl_context context,cl_command_queue queue,cl_mem_object_type imageType,cl_mem_flags flags)34 int test_image_type( cl_device_id device, cl_context context, cl_command_queue queue, cl_mem_object_type imageType, cl_mem_flags flags )
35 {
36 log_info( "Running %s %s-only tests...\n", convert_image_type_to_string(imageType), flags == CL_MEM_READ_ONLY ? "read" : "write" );
37
38 int ret = 0;
39
40 // Grab the list of supported image formats for integer reads
41 cl_image_format *formatList;
42 bool *filterFlags;
43 unsigned int numFormats;
44
45 if( get_format_list( context, imageType, formatList, numFormats, flags ) )
46 return -1;
47
48 filterFlags = new bool[ numFormats ];
49 if( filterFlags == NULL )
50 {
51 log_error( "ERROR: Out of memory allocating filter flags list!\n" );
52 return -1;
53 }
54 memset( filterFlags, 0, sizeof( bool ) * numFormats );
55 filter_formats( formatList, filterFlags, numFormats, 0 );
56
57 // Run the format list
58 for( unsigned int i = 0; i < numFormats; i++ )
59 {
60 int test_return = 0;
61 if( filterFlags[i] )
62 {
63 log_info( "NOT RUNNING: " );
64 print_header( &formatList[ i ], false );
65 continue;
66 }
67
68 print_header( &formatList[ i ], false );
69
70 gTestCount++;
71
72 switch (imageType) {
73 case CL_MEM_OBJECT_IMAGE1D:
74 test_return = test_get_image_info_1D( device, context, queue, &formatList[ i ] );
75 break;
76 case CL_MEM_OBJECT_IMAGE2D:
77 test_return = test_get_image_info_2D( device, context, queue, &formatList[ i ] );
78 break;
79 case CL_MEM_OBJECT_IMAGE3D:
80 test_return = test_get_image_info_3D( device, context, queue, &formatList[ i ] );
81 break;
82 case CL_MEM_OBJECT_IMAGE1D_ARRAY:
83 test_return = test_get_image_info_1D_array( device, context, queue, &formatList[ i ] );
84 break;
85 case CL_MEM_OBJECT_IMAGE2D_ARRAY:
86 test_return = test_get_image_info_2D_array( device, context, queue, &formatList[ i ] );
87 break;
88 }
89
90 if (test_return) {
91 gFailCount++;
92 log_error( "FAILED: " );
93 print_header( &formatList[ i ], true );
94 log_info( "\n" );
95 }
96
97 ret += test_return;
98 }
99
100 delete filterFlags;
101 delete formatList;
102
103 return ret;
104 }
105
test_image_set(cl_device_id device,cl_context context,cl_command_queue queue,cl_mem_object_type imageType)106 int test_image_set( cl_device_id device, cl_context context, cl_command_queue queue, cl_mem_object_type imageType )
107 {
108 int version_check;
109 auto version = get_device_cl_version(device);
110 if (version < Version(2, 0)) {
111 gDeviceLt20 = true;
112 }
113
114 if ((version_check = (version < Version(1, 2))))
115 {
116 switch (imageType) {
117 case CL_MEM_OBJECT_IMAGE1D:
118 test_missing_feature(version_check, "image_1D");
119 case CL_MEM_OBJECT_IMAGE1D_ARRAY:
120 test_missing_feature(version_check, "image_1D_array");
121 case CL_MEM_OBJECT_IMAGE2D_ARRAY:
122 test_missing_feature(version_check, "image_2D_array");
123 }
124 }
125
126 int ret = 0;
127 ret += test_image_type( device, context, queue, imageType, CL_MEM_READ_ONLY );
128 ret += test_image_type( device, context, queue, imageType, CL_MEM_WRITE_ONLY );
129
130 return ret;
131 }
132