Remove duplicate format functions (#738)

This moves the filter_formats and get_format_list functions to a common
file. These functions were roughly the same, with an optional filtering
in some tests for testing mipmaps.

Signed-off-by: Radek Szymanski <radek.szymanski@arm.com>
This commit is contained in:
Radek Szymanski
2020-04-17 10:55:17 +01:00
committed by GitHub
parent d59808ceda
commit e72cff3e7d
19 changed files with 177 additions and 658 deletions

View File

@@ -7,6 +7,7 @@ set(${MODULE_NAME}_SOURCES
test_2D.cpp
test_loops.cpp
test_3D.cpp
../common.cpp
)
include(../../CMakeCommon.txt)

View File

@@ -30,6 +30,7 @@ bool gTestSmallImages;
bool gTestMaxImages;
int gTypesToTest;
cl_channel_type gChannelTypeToUse = (cl_channel_type)-1;
cl_channel_order gChannelOrderToUse = (cl_channel_order)-1;
extern int test_image_set( cl_device_id device, cl_context context, cl_mem_object_type image_type );
static void printUsage( const char *execName );

View File

@@ -14,6 +14,7 @@
// limitations under the License.
//
#include "../testBase.h"
#include "../common.h"
#include "harness/imageHelpers.h"
#include <algorithm>
#include <iterator>
@@ -33,12 +34,6 @@ extern int test_get_image_info_3D( cl_device_id device, cl_context context, cl_i
extern int test_get_image_info_1D_array( cl_device_id device, cl_context context, cl_image_format *format, cl_mem_flags flags );
extern int test_get_image_info_2D_array( cl_device_id device, cl_context context, cl_image_format *format, cl_mem_flags flags );
static const char *str_1d_image = "1D";
static const char *str_2d_image = "2D";
static const char *str_3d_image = "3D";
static const char *str_1d_image_array = "1D array";
static const char *str_2d_image_array = "2D array";
static bool check_minimum_supported(cl_image_format *formatList,
unsigned int numFormats,
cl_mem_flags flags,
@@ -63,97 +58,6 @@ static bool check_minimum_supported(cl_image_format *formatList,
return passed;
}
static const char *convert_image_type_to_string(cl_mem_object_type image_type)
{
const char *p;
switch (image_type)
{
case CL_MEM_OBJECT_IMAGE1D:
p = str_1d_image;
break;
case CL_MEM_OBJECT_IMAGE2D:
p = str_2d_image;
break;
case CL_MEM_OBJECT_IMAGE3D:
p = str_3d_image;
break;
case CL_MEM_OBJECT_IMAGE1D_ARRAY:
p = str_1d_image_array;
break;
case CL_MEM_OBJECT_IMAGE2D_ARRAY:
p = str_2d_image_array;
break;
}
return p;
}
int filter_formats( cl_image_format *formatList, bool *filterFlags, unsigned int formatCount, cl_channel_type *channelDataTypesToFilter )
{
int numSupported = 0;
for( unsigned int j = 0; j < formatCount; j++ )
{
// If this format has been previously filtered, remove the filter
if( filterFlags[ j ] )
filterFlags[ j ] = false;
// Have we already discarded this via the command line?
if( gChannelTypeToUse != (cl_channel_type)-1 && gChannelTypeToUse != formatList[ j ].image_channel_data_type )
{
filterFlags[ j ] = true;
continue;
}
// Is given format standard channel order and type given by spec. We don't want to test it if this is vendor extension
if( !IsChannelOrderSupported( formatList[ j ].image_channel_order ) || !IsChannelTypeSupported( formatList[ j ].image_channel_data_type ) )
{
filterFlags[ j ] = true;
continue;
}
// We don't filter by channel type
if( !channelDataTypesToFilter )
{
numSupported++;
continue;
}
// Is the format supported?
int i;
for( i = 0; channelDataTypesToFilter[ i ] != (cl_channel_type)-1; i++ )
{
if( formatList[ j ].image_channel_data_type == channelDataTypesToFilter[ i ] )
{
numSupported++;
break;
}
}
if( channelDataTypesToFilter[ i ] == (cl_channel_type)-1 )
{
// Format is NOT supported, so mark it as such
filterFlags[ j ] = true;
}
}
return numSupported;
}
int get_format_list( cl_context context, cl_mem_object_type image_type, cl_image_format * &outFormatList,
unsigned int &outFormatCount, cl_mem_flags flags )
{
int error;
cl_image_format tempList[ 128 ];
error = clGetSupportedImageFormats( context, (cl_mem_flags)flags,
image_type, 128, tempList, &outFormatCount );
test_error( error, "Unable to get count of supported image formats" );
outFormatList = new cl_image_format[ outFormatCount ];
error = clGetSupportedImageFormats( context, (cl_mem_flags)flags,
image_type, outFormatCount, outFormatList, NULL );
test_error( error, "Unable to get list of supported image formats" );
return 0;
}
int test_image_type( cl_device_id device, cl_context context, cl_mem_object_type image_type, cl_mem_flags flags )
{
log_info( "Running %s %s-only tests...\n", convert_image_type_to_string(image_type), flags == CL_MEM_READ_ONLY ? "read" : "write" );