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