mirror of
https://github.com/KhronosGroup/OpenCL-CTS.git
synced 2026-03-19 06:09:01 +00:00
Initial open source release of OpenCL 2.2 CTS.
This commit is contained in:
24
test_conformance/images/clReadWriteImage/CMakeLists.txt
Normal file
24
test_conformance/images/clReadWriteImage/CMakeLists.txt
Normal file
@@ -0,0 +1,24 @@
|
||||
set(MODULE_NAME CL_READ_WRITE_IMAGES)
|
||||
|
||||
set(${MODULE_NAME}_SOURCES
|
||||
main.cpp
|
||||
test_read_1D.cpp
|
||||
test_read_1D_array.cpp
|
||||
test_read_2D.cpp
|
||||
test_read_2D_array.cpp
|
||||
test_loops.cpp
|
||||
test_read_3D.cpp
|
||||
../../../test_common/harness/errorHelpers.c
|
||||
../../../test_common/harness/threadTesting.c
|
||||
../../../test_common/harness/kernelHelpers.c
|
||||
../../../test_common/harness/imageHelpers.cpp
|
||||
../../../test_common/harness/mt19937.c
|
||||
../../../test_common/harness/conversions.c
|
||||
../../../test_common/harness/testHarness.c
|
||||
../../../test_common/harness/typeWrappers.cpp
|
||||
../../../test_common/harness/msvc9.c
|
||||
../../../test_common/harness/parseParameters.cpp
|
||||
)
|
||||
|
||||
include(../../CMakeCommon.txt)
|
||||
|
||||
18
test_conformance/images/clReadWriteImage/Jamfile
Normal file
18
test_conformance/images/clReadWriteImage/Jamfile
Normal file
@@ -0,0 +1,18 @@
|
||||
project
|
||||
: requirements
|
||||
# <toolset>gcc:<cflags>-xc++
|
||||
# <toolset>msvc:<cflags>"/TP"
|
||||
;
|
||||
|
||||
exe test_cl_read_write_images
|
||||
: main.cpp
|
||||
test_read_2D.cpp
|
||||
test_read_3D.cpp
|
||||
test_loops.cpp
|
||||
;
|
||||
|
||||
install dist
|
||||
: test_cl_read_write_images
|
||||
: <variant>debug:<location>$(DIST)/debug/tests/test_conformance/images/clReadWriteImage
|
||||
<variant>release:<location>$(DIST)/release/tests/test_conformance/images/clReadWriteImage
|
||||
;
|
||||
51
test_conformance/images/clReadWriteImage/Makefile
Normal file
51
test_conformance/images/clReadWriteImage/Makefile
Normal file
@@ -0,0 +1,51 @@
|
||||
ifdef BUILD_WITH_ATF
|
||||
ATF = -framework ATF
|
||||
USE_ATF = -DUSE_ATF
|
||||
endif
|
||||
|
||||
SRCS = main.cpp \
|
||||
test_read_1D.cpp \
|
||||
test_read_1D_array.cpp \
|
||||
test_read_2D.cpp \
|
||||
test_read_2D_array.cpp \
|
||||
test_loops.cpp \
|
||||
test_read_3D.cpp \
|
||||
../../../test_common/harness/errorHelpers.c \
|
||||
../../../test_common/harness/threadTesting.c \
|
||||
../../../test_common/harness/kernelHelpers.c \
|
||||
../../../test_common/harness/imageHelpers.cpp \
|
||||
../../../test_common/harness/conversions.c \
|
||||
../../../test_common/harness/testHarness.c \
|
||||
../../../test_common/harness/mt19937.c \
|
||||
../../../test_common/harness/typeWrappers.cpp
|
||||
|
||||
DEFINES = DONT_TEST_GARBAGE_POINTERS
|
||||
|
||||
SOURCES = $(abspath $(SRCS))
|
||||
LIBPATH += -L/System/Library/Frameworks/OpenCL.framework/Libraries
|
||||
LIBPATH += -L.
|
||||
FRAMEWORK =
|
||||
HEADERS =
|
||||
TARGET = test_cl_read_write_images
|
||||
INCLUDE =
|
||||
COMPILERFLAGS = -c -Wall -g -Wshorten-64-to-32 -Os
|
||||
CC = c++
|
||||
CXX = c++
|
||||
CFLAGS = $(COMPILERFLAGS) ${RC_CFLAGS} ${USE_ATF} $(DEFINES:%=-D%) $(INCLUDE)
|
||||
CXXFLAGS = $(COMPILERFLAGS) ${RC_CFLAGS} ${USE_ATF} $(DEFINES:%=-D%) $(INCLUDE)
|
||||
LIBRARIES = -framework OpenCL -framework OpenGL -framework GLUT -framework AppKit ${ATF}
|
||||
|
||||
OBJECTS := ${SOURCES:.c=.o}
|
||||
OBJECTS := ${OBJECTS:.cpp=.o}
|
||||
|
||||
TARGETOBJECT =
|
||||
all: $(TARGET)
|
||||
|
||||
$(TARGET): $(OBJECTS)
|
||||
$(CC) $(RC_CFLAGS) $(OBJECTS) -o $@ $(LIBPATH) $(LIBRARIES)
|
||||
|
||||
clean:
|
||||
rm -f $(TARGET) $(OBJECTS)
|
||||
|
||||
.DEFAULT:
|
||||
@echo The target \"$@\" does not exist in Makefile.
|
||||
265
test_conformance/images/clReadWriteImage/main.cpp
Normal file
265
test_conformance/images/clReadWriteImage/main.cpp
Normal file
@@ -0,0 +1,265 @@
|
||||
//
|
||||
// Copyright (c) 2017 The Khronos Group Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#include "../../../test_common/harness/compat.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#if !defined(_WIN32)
|
||||
#include <unistd.h>
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
#include "../testBase.h"
|
||||
|
||||
bool gDebugTrace = false, gTestSmallImages = false, gTestMaxImages = false, gUseRamp = false, gTestRounding = false, gTestMipmaps = false;
|
||||
int gTypesToTest = 0;
|
||||
cl_channel_type gChannelTypeToUse = (cl_channel_type)-1;
|
||||
bool gEnablePitch = false;
|
||||
cl_device_type gDeviceType = CL_DEVICE_TYPE_DEFAULT;
|
||||
cl_command_queue queue;
|
||||
cl_context context;
|
||||
|
||||
#define MAX_ALLOWED_STD_DEVIATION_IN_MB 8.0
|
||||
|
||||
void printUsage( const char *execName )
|
||||
{
|
||||
const char *p = strrchr( execName, '/' );
|
||||
if( p != NULL )
|
||||
execName = p + 1;
|
||||
|
||||
log_info( "Usage: %s [debug_trace] [small_images]\n", execName );
|
||||
log_info( "Where:\n" );
|
||||
log_info( "\t1D - Only test 1D images\n" );
|
||||
log_info( "\t2D - Only test 2D images\n" );
|
||||
log_info( "\t3D - Only test 3D images\n" );
|
||||
log_info( "\t1Darray - Only test 1D image arrays\n" );
|
||||
log_info( "\t2Darray - Only test 2D image arrays\n" );
|
||||
log_info( "\n" );
|
||||
log_info( "\tdebug_trace - Enables additional debug info logging\n" );
|
||||
log_info( "\tsmall_images - Runs every format through a loop of widths 1-13 and heights 1-9, instead of random sizes\n" );
|
||||
log_info( "\tmax_images - Runs every format through a set of size combinations with the max values, max values - 1, and max values / 128\n" );
|
||||
log_info( "\trounding - Runs every format through a single image filled with every possible value for that image format, to verify rounding works properly\n" );
|
||||
log_info( "\tuse_pitches - Enables row and slice pitches\n" );
|
||||
log_info( "\tuse_ramp - Instead of random data, uses images filled with ramps (and 0xff on any padding pixels) to ease debugging\n" );
|
||||
log_info( "\ttest_mipmaps - Test mipmapped images\n" );
|
||||
}
|
||||
|
||||
|
||||
extern int test_image_set( cl_device_id device, cl_mem_object_type image_type );
|
||||
|
||||
int main(int argc, const char *argv[])
|
||||
{
|
||||
cl_platform_id platform;
|
||||
cl_device_id device;
|
||||
cl_channel_type chanType;
|
||||
char str[ 128 ];
|
||||
bool randomize = false;
|
||||
int testMethods = 0;
|
||||
|
||||
test_start();
|
||||
|
||||
checkDeviceTypeOverride( &gDeviceType );
|
||||
|
||||
// Parse arguments
|
||||
for( int i = 1; i < argc; i++ )
|
||||
{
|
||||
strncpy( str, argv[ i ], sizeof( str ) - 1 );
|
||||
|
||||
if( strcmp( str, "cpu" ) == 0 || strcmp( str, "CL_DEVICE_TYPE_CPU" ) == 0 )
|
||||
gDeviceType = CL_DEVICE_TYPE_CPU;
|
||||
else if( strcmp( str, "gpu" ) == 0 || strcmp( str, "CL_DEVICE_TYPE_GPU" ) == 0 )
|
||||
gDeviceType = CL_DEVICE_TYPE_GPU;
|
||||
else if( strcmp( str, "accelerator" ) == 0 || strcmp( str, "CL_DEVICE_TYPE_ACCELERATOR" ) == 0 )
|
||||
gDeviceType = CL_DEVICE_TYPE_ACCELERATOR;
|
||||
else if( strcmp( str, "CL_DEVICE_TYPE_DEFAULT" ) == 0 )
|
||||
gDeviceType = CL_DEVICE_TYPE_DEFAULT;
|
||||
|
||||
else if( strcmp( str, "debug_trace" ) == 0 )
|
||||
gDebugTrace = true;
|
||||
|
||||
else if( strcmp( str, "small_images" ) == 0 )
|
||||
gTestSmallImages = true;
|
||||
else if( strcmp( str, "max_images" ) == 0 )
|
||||
gTestMaxImages = true;
|
||||
else if( strcmp( str, "use_pitches" ) == 0 )
|
||||
gEnablePitch = true;
|
||||
else if( strcmp( str, "use_ramps" ) == 0 )
|
||||
gUseRamp = true;
|
||||
else if( strcmp(str, "test_mipmaps") == 0 ) {
|
||||
gTestMipmaps = true;
|
||||
// Don't test pitches with mipmaps right now.
|
||||
gEnablePitch = false;
|
||||
}
|
||||
else if( strcmp( str, "randomize" ) == 0 )
|
||||
randomize = true;
|
||||
|
||||
else if( strcmp( str, "1D" ) == 0 )
|
||||
testMethods |= k1D;
|
||||
else if( strcmp( str, "2D" ) == 0 )
|
||||
testMethods |= k2D;
|
||||
else if( strcmp( str, "3D" ) == 0 )
|
||||
testMethods |= k3D;
|
||||
else if( strcmp( str, "1Darray" ) == 0 )
|
||||
testMethods |= k1DArray;
|
||||
else if( strcmp( str, "2Darray" ) == 0 )
|
||||
testMethods |= k2DArray;
|
||||
|
||||
else if( strcmp( str, "help" ) == 0 || strcmp( str, "?" ) == 0 )
|
||||
{
|
||||
printUsage( argv[ 0 ] );
|
||||
return -1;
|
||||
}
|
||||
else if( ( chanType = get_channel_type_from_name( str ) ) != (cl_channel_type)-1 )
|
||||
gChannelTypeToUse = chanType;
|
||||
else
|
||||
{
|
||||
log_error( "ERROR: Unknown argument %d: %s. Exiting....\n", i, str );
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (testMethods == 0)
|
||||
testMethods = k1D | k2D | k3D | k1DArray | k2DArray;
|
||||
|
||||
// Seed the random # generators
|
||||
if( randomize )
|
||||
{
|
||||
gRandomSeed = (cl_uint) time( NULL );
|
||||
log_info( "Random seed: %u.\n", gRandomSeed );
|
||||
gReSeed = 1;
|
||||
}
|
||||
|
||||
int error;
|
||||
// Get our platform
|
||||
error = clGetPlatformIDs(1, &platform, NULL);
|
||||
if( error )
|
||||
{
|
||||
print_error( error, "Unable to get platform" );
|
||||
test_finish();
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Get our device
|
||||
unsigned int num_devices;
|
||||
error = clGetDeviceIDs(platform, gDeviceType, 0, NULL, &num_devices);
|
||||
if( error )
|
||||
{
|
||||
print_error( error, "Unable to get number of devices" );
|
||||
test_finish();
|
||||
return -1;
|
||||
}
|
||||
|
||||
uint32_t gDeviceIndex = 0;
|
||||
const char* device_index_env = getenv("CL_DEVICE_INDEX");
|
||||
if (device_index_env) {
|
||||
if (device_index_env) {
|
||||
gDeviceIndex = atoi(device_index_env);
|
||||
}
|
||||
|
||||
if (gDeviceIndex >= num_devices) {
|
||||
vlog("Specified CL_DEVICE_INDEX=%d out of range, using index 0.\n", gDeviceIndex);
|
||||
gDeviceIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
cl_device_id *gDeviceList = (cl_device_id *)malloc( num_devices * sizeof( cl_device_id ) );
|
||||
error = clGetDeviceIDs(platform, gDeviceType, num_devices, gDeviceList, NULL);
|
||||
if( error )
|
||||
{
|
||||
print_error( error, "Unable to get devices" );
|
||||
free( gDeviceList );
|
||||
test_finish();
|
||||
return -1;
|
||||
}
|
||||
|
||||
device = gDeviceList[gDeviceIndex];
|
||||
free( gDeviceList );
|
||||
|
||||
log_info( "Using " );
|
||||
if( printDeviceHeader( device ) != CL_SUCCESS )
|
||||
{
|
||||
test_finish();
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Check for image support
|
||||
if(checkForImageSupport( device ) == CL_IMAGE_FORMAT_NOT_SUPPORTED) {
|
||||
log_info("Device does not support images. Skipping test.\n");
|
||||
test_finish();
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Create a context to test with
|
||||
context = clCreateContext( NULL, 1, &device, notify_callback, NULL, &error );
|
||||
if( error != CL_SUCCESS )
|
||||
{
|
||||
print_error( error, "Unable to create testing context" );
|
||||
test_finish();
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Create a queue against the context
|
||||
queue = clCreateCommandQueueWithProperties( context, device, 0, &error );
|
||||
if( error != CL_SUCCESS )
|
||||
{
|
||||
print_error( error, "Unable to create testing command queue" );
|
||||
test_finish();
|
||||
return -1;
|
||||
}
|
||||
|
||||
if( gTestSmallImages )
|
||||
log_info( "Note: Using small test images\n" );
|
||||
|
||||
// Run the test now
|
||||
int ret = 0;
|
||||
if (testMethods & k1D)
|
||||
ret += test_image_set( device, CL_MEM_OBJECT_IMAGE1D );
|
||||
if (testMethods & k2D)
|
||||
ret += test_image_set( device, CL_MEM_OBJECT_IMAGE2D );
|
||||
if (testMethods & k3D)
|
||||
ret += test_image_set( device, CL_MEM_OBJECT_IMAGE3D );
|
||||
if (testMethods & k1DArray)
|
||||
ret += test_image_set( device, CL_MEM_OBJECT_IMAGE1D_ARRAY );
|
||||
if (testMethods & k2DArray)
|
||||
ret += test_image_set( device, CL_MEM_OBJECT_IMAGE2D_ARRAY );
|
||||
|
||||
error = clFinish(queue);
|
||||
if (error)
|
||||
print_error(error, "clFinish failed.");
|
||||
|
||||
if (gTestFailure == 0) {
|
||||
if (gTestCount > 1)
|
||||
log_info("PASSED %d of %d tests.\n", gTestCount, gTestCount);
|
||||
else
|
||||
log_info("PASSED test.\n");
|
||||
} else if (gTestFailure > 0) {
|
||||
if (gTestCount > 1)
|
||||
log_error("FAILED %d of %d tests.\n", gTestFailure, gTestCount);
|
||||
else
|
||||
log_error("FAILED test.\n");
|
||||
}
|
||||
|
||||
// Clean up
|
||||
clReleaseCommandQueue(queue);
|
||||
clReleaseContext(context);
|
||||
test_finish();
|
||||
|
||||
if (gTestFailure > 0)
|
||||
return gTestFailure;
|
||||
|
||||
return ret;
|
||||
}
|
||||
227
test_conformance/images/clReadWriteImage/test_loops.cpp
Normal file
227
test_conformance/images/clReadWriteImage/test_loops.cpp
Normal file
@@ -0,0 +1,227 @@
|
||||
//
|
||||
// Copyright (c) 2017 The Khronos Group Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#include "../testBase.h"
|
||||
|
||||
extern cl_filter_mode gFilterModeToUse;
|
||||
extern cl_addressing_mode gAddressModeToUse;
|
||||
extern int gTypesToTest;
|
||||
extern int gNormalizedModeToUse;
|
||||
extern cl_channel_type gChannelTypeToUse;
|
||||
extern cl_command_queue queue;
|
||||
extern cl_context context;
|
||||
|
||||
|
||||
extern bool gDebugTrace;
|
||||
extern bool gTestMipmaps;
|
||||
|
||||
extern int test_read_image_set_1D( cl_device_id device, cl_image_format *format );
|
||||
extern int test_read_image_set_2D( cl_device_id device, cl_image_format *format );
|
||||
extern int test_read_image_set_3D( cl_device_id device, cl_image_format *format );
|
||||
extern int test_read_image_set_1D_array( cl_device_id device, cl_image_format *format );
|
||||
extern int test_read_image_set_2D_array( cl_device_id device, cl_image_format *format );
|
||||
|
||||
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 const char *convert_image_type_to_string(cl_mem_object_type imageType)
|
||||
{
|
||||
const char *p;
|
||||
switch (imageType)
|
||||
{
|
||||
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_device_id device, cl_mem_object_type imageType, 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,
|
||||
imageType, 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,
|
||||
imageType, 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_mem_object_type imageType, cl_mem_flags flags )
|
||||
{
|
||||
log_info( "Running %s %s %s-only tests...\n", gTestMipmaps?"mipmapped":"",convert_image_type_to_string(imageType), flags == CL_MEM_READ_ONLY ? "read" : "write" );
|
||||
|
||||
int ret = 0;
|
||||
|
||||
// Grab the list of supported image formats for integer reads
|
||||
cl_image_format *formatList;
|
||||
bool *filterFlags;
|
||||
unsigned int numFormats;
|
||||
|
||||
if ( gTestMipmaps )
|
||||
{
|
||||
if ( 0 == is_extension_available( device, "cl_khr_mipmap_image" ))
|
||||
{
|
||||
log_info( "-----------------------------------------------------\n" );
|
||||
log_info( "This device does not support cl_khr_mipmap_image.\nSkipping mipmapped image test. \n" );
|
||||
log_info( "-----------------------------------------------------\n\n" );
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if( get_format_list( device, imageType, formatList, numFormats, flags ) )
|
||||
return -1;
|
||||
|
||||
filterFlags = new bool[ numFormats ];
|
||||
if( filterFlags == NULL )
|
||||
{
|
||||
log_error( "ERROR: Out of memory allocating filter flags list!\n" );
|
||||
return -1;
|
||||
}
|
||||
memset( filterFlags, 0, sizeof( bool ) * numFormats );
|
||||
filter_formats( formatList, filterFlags, numFormats, 0 );
|
||||
|
||||
// Run the format list
|
||||
for( unsigned int i = 0; i < numFormats; i++ )
|
||||
{
|
||||
int test_return = 0;
|
||||
if( filterFlags[i] )
|
||||
{
|
||||
log_info( "NOT RUNNING: " );
|
||||
print_header( &formatList[ i ], false );
|
||||
continue;
|
||||
}
|
||||
|
||||
print_header( &formatList[ i ], false );
|
||||
|
||||
gTestCount++;
|
||||
|
||||
switch (imageType) {
|
||||
case CL_MEM_OBJECT_IMAGE1D:
|
||||
test_return = test_read_image_set_1D( device, &formatList[ i ] );
|
||||
break;
|
||||
case CL_MEM_OBJECT_IMAGE2D:
|
||||
test_return = test_read_image_set_2D( device, &formatList[ i ] );
|
||||
break;
|
||||
case CL_MEM_OBJECT_IMAGE3D:
|
||||
test_return = test_read_image_set_3D( device, &formatList[ i ] );
|
||||
break;
|
||||
case CL_MEM_OBJECT_IMAGE1D_ARRAY:
|
||||
test_return = test_read_image_set_1D_array( device, &formatList[ i ] );
|
||||
break;
|
||||
case CL_MEM_OBJECT_IMAGE2D_ARRAY:
|
||||
test_return = test_read_image_set_2D_array( device, &formatList[ i ] );
|
||||
break;
|
||||
}
|
||||
|
||||
if (test_return) {
|
||||
gTestFailure++;
|
||||
log_error( "FAILED: " );
|
||||
print_header( &formatList[ i ], true );
|
||||
log_info( "\n" );
|
||||
}
|
||||
|
||||
ret += test_return;
|
||||
}
|
||||
|
||||
delete filterFlags;
|
||||
delete formatList;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int test_image_set( cl_device_id device, cl_mem_object_type imageType )
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
ret += test_image_type( device, imageType, CL_MEM_READ_ONLY );
|
||||
ret += test_image_type( device, imageType, CL_MEM_WRITE_ONLY );
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
273
test_conformance/images/clReadWriteImage/test_read_1D.cpp
Normal file
273
test_conformance/images/clReadWriteImage/test_read_1D.cpp
Normal file
@@ -0,0 +1,273 @@
|
||||
//
|
||||
// Copyright (c) 2017 The Khronos Group Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#include "../testBase.h"
|
||||
|
||||
#define MAX_ERR 0.005f
|
||||
#define MAX_HALF_LINEAR_ERR 0.3f
|
||||
|
||||
extern bool gDebugTrace, gDisableOffsets, gTestSmallImages, gEnablePitch, gTestMaxImages, gTestRounding, gTestMipmaps;
|
||||
extern cl_filter_mode gFilterModeToUse;
|
||||
extern cl_addressing_mode gAddressModeToUse;
|
||||
extern uint64_t gRoundingStartValue;
|
||||
extern cl_command_queue queue;
|
||||
extern cl_context context;
|
||||
|
||||
|
||||
int test_read_image_1D( cl_device_id device, image_descriptor *imageInfo, MTdata d )
|
||||
{
|
||||
int error;
|
||||
|
||||
clMemWrapper image;
|
||||
|
||||
// Generate some data to test against
|
||||
BufferOwningPtr<char> imageValues;
|
||||
generate_random_image_data( imageInfo, imageValues, d );
|
||||
|
||||
if( gDebugTrace )
|
||||
{
|
||||
log_info( " - Creating %s 1D image %d...\n", gTestMipmaps?"mipmapped":"", (int)imageInfo->width );
|
||||
log_info( " with %llu mip levels\n", (unsigned long long) imageInfo->num_mip_levels );
|
||||
}
|
||||
|
||||
// Construct testing sources
|
||||
if(!gTestMipmaps)
|
||||
{
|
||||
image = create_image_1d( context, (cl_mem_flags)(CL_MEM_READ_ONLY), imageInfo->format, imageInfo->width, 0, NULL, NULL, &error );
|
||||
if( image == NULL )
|
||||
{
|
||||
log_error( "ERROR: Unable to create 1D image of size %d (%s)", (int)imageInfo->width, IGetErrorString( error ) );
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cl_image_desc image_desc = {0};
|
||||
image_desc.image_type = CL_MEM_OBJECT_IMAGE1D;
|
||||
image_desc.image_width = imageInfo->width;
|
||||
image_desc.num_mip_levels = imageInfo->num_mip_levels;
|
||||
|
||||
image = clCreateImage( context, CL_MEM_READ_ONLY, imageInfo->format, &image_desc, NULL, &error);
|
||||
if( error != CL_SUCCESS )
|
||||
{
|
||||
log_error( "ERROR: Unable to create %d level mipmapped 1D image of size %d x %d (pitch %d ) (%s)",(int)imageInfo->num_mip_levels, (int)imageInfo->width, (int)imageInfo->height, (int)imageInfo->rowPitch, IGetErrorString( error ) );
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
if( gDebugTrace )
|
||||
log_info( " - Writing image...\n" );
|
||||
|
||||
size_t origin[ 3 ] = { 0, 0, 0 };
|
||||
size_t region[ 3 ] = { 0, 1, 1 };
|
||||
size_t fullImageSize;
|
||||
if( gTestMipmaps )
|
||||
{
|
||||
fullImageSize = (size_t)compute_mipmapped_image_size( *imageInfo );
|
||||
}
|
||||
else
|
||||
{
|
||||
fullImageSize = imageInfo->rowPitch;
|
||||
}
|
||||
|
||||
BufferOwningPtr<char> resultValues(malloc(fullImageSize));
|
||||
size_t imgValMipLevelOffset = 0;
|
||||
|
||||
for( size_t lod = 0; (gTestMipmaps && lod < imageInfo->num_mip_levels) || (!gTestMipmaps && lod < 1); lod++)
|
||||
{
|
||||
float lod_float = (float) lod;
|
||||
origin[1] = lod;
|
||||
size_t width_lod, row_pitch_lod;
|
||||
|
||||
width_lod = (imageInfo->width >> lod) ? (imageInfo->width >> lod) : 1;
|
||||
row_pitch_lod = gTestMipmaps ? (width_lod * get_pixel_size( imageInfo->format )): imageInfo->rowPitch;
|
||||
|
||||
region[0] = width_lod;
|
||||
|
||||
if ( gDebugTrace )
|
||||
if ( gTestMipmaps) {
|
||||
log_info(" - Working at mipLevel :%llu\n", (unsigned long long)lod);
|
||||
}
|
||||
error = clEnqueueWriteImage(queue, image, CL_FALSE,
|
||||
origin, region, ( gEnablePitch ? row_pitch_lod : 0 ), 0,
|
||||
(char*)imageValues + imgValMipLevelOffset, 0, NULL, NULL);
|
||||
if (error != CL_SUCCESS) {
|
||||
log_error( "ERROR: Unable to write to 1D image of size %d \n", (int)width_lod );
|
||||
return -1;
|
||||
}
|
||||
|
||||
// To verify, we just read the results right back and see whether they match the input
|
||||
if( gDebugTrace )
|
||||
{
|
||||
log_info( " - Initing result array...\n" );
|
||||
}
|
||||
|
||||
// Note: we read back without any pitch, to verify pitch actually WORKED
|
||||
size_t scanlineSize = width_lod * get_pixel_size( imageInfo->format );
|
||||
size_t imageSize = scanlineSize;
|
||||
memset( resultValues, 0xff, imageSize );
|
||||
|
||||
if( gDebugTrace )
|
||||
log_info( " - Reading results...\n" );
|
||||
|
||||
error = clEnqueueReadImage( queue, image, CL_TRUE, origin, region, 0, 0, resultValues, 0, NULL, NULL );
|
||||
test_error( error, "Unable to read image values" );
|
||||
|
||||
// Verify scanline by scanline, since the pitches are different
|
||||
char *sourcePtr = (char*)imageValues + imgValMipLevelOffset;
|
||||
char *destPtr = resultValues;
|
||||
|
||||
if( memcmp( sourcePtr, destPtr, scanlineSize ) != 0 )
|
||||
{
|
||||
log_error( "ERROR: Scanline did not verify for image size %d pitch %d (extra %d bytes)\n", (int)width_lod, (int)row_pitch_lod, (int)row_pitch_lod - (int)width_lod * (int)get_pixel_size( imageInfo->format ) );
|
||||
|
||||
log_error( "First few values: \n" );
|
||||
log_error( " Input: " );
|
||||
uint32_t *s = (uint32_t *)sourcePtr;
|
||||
uint32_t *d = (uint32_t *)destPtr;
|
||||
for( int q = 0; q < 12; q++ )
|
||||
log_error( "%08x ", s[ q ] );
|
||||
log_error( "\nOutput: " );
|
||||
for( int q = 0; q < 12; q++ )
|
||||
log_error( "%08x ", d[ q ] );
|
||||
log_error( "\n" );
|
||||
|
||||
int outX;
|
||||
int offset = (int)get_pixel_size( imageInfo->format ) * (int)( width_lod - 16 );
|
||||
if( offset < 0 )
|
||||
offset = 0;
|
||||
int foundCount = debug_find_vector_in_image( (char*)imageValues + imgValMipLevelOffset, imageInfo, destPtr + offset, get_pixel_size( imageInfo->format ), &outX, NULL, NULL );
|
||||
if( foundCount > 0 )
|
||||
{
|
||||
int returnedOffset = ( offset / (int)get_pixel_size( imageInfo->format ) ) - outX;
|
||||
|
||||
if( memcmp( sourcePtr + returnedOffset * get_pixel_size( imageInfo->format ), destPtr, get_pixel_size( imageInfo->format ) * 8 ) == 0 )
|
||||
log_error( " Values appear to be offsetted by %d\n", returnedOffset );
|
||||
else
|
||||
log_error( " Calculated offset is %d but unable to verify\n", returnedOffset );
|
||||
}
|
||||
else
|
||||
{
|
||||
log_error( " Unable to determine offset\n" );
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
imgValMipLevelOffset += width_lod * get_pixel_size( imageInfo->format );
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int test_read_image_set_1D( cl_device_id device, cl_image_format *format )
|
||||
{
|
||||
size_t maxWidth;
|
||||
cl_ulong maxAllocSize, memSize;
|
||||
image_descriptor imageInfo = { 0 };
|
||||
RandomSeed seed( gRandomSeed );
|
||||
size_t pixelSize;
|
||||
|
||||
imageInfo.type = CL_MEM_OBJECT_IMAGE1D;
|
||||
imageInfo.format = format;
|
||||
imageInfo.height = imageInfo.depth = imageInfo.slicePitch = 0;
|
||||
pixelSize = get_pixel_size( imageInfo.format );
|
||||
|
||||
int error = clGetDeviceInfo( device, CL_DEVICE_IMAGE2D_MAX_WIDTH, sizeof( maxWidth ), &maxWidth, NULL );
|
||||
error |= clGetDeviceInfo( device, CL_DEVICE_MAX_MEM_ALLOC_SIZE, sizeof( maxAllocSize ), &maxAllocSize, NULL );
|
||||
error |= clGetDeviceInfo( device, CL_DEVICE_GLOBAL_MEM_SIZE, sizeof( memSize ), &memSize, NULL );
|
||||
test_error( error, "Unable to get max image 2D size from device" );
|
||||
|
||||
if (memSize > (cl_ulong)SIZE_MAX) {
|
||||
memSize = (cl_ulong)SIZE_MAX;
|
||||
}
|
||||
|
||||
if( gTestSmallImages )
|
||||
{
|
||||
for( imageInfo.width = 1; imageInfo.width < 13; imageInfo.width++ )
|
||||
{
|
||||
imageInfo.rowPitch = imageInfo.width * pixelSize;
|
||||
|
||||
if (gTestMipmaps)
|
||||
imageInfo.num_mip_levels = (cl_uint) random_log_in_range(2, (int)compute_max_mip_levels(imageInfo.width, 0, 0), seed);
|
||||
|
||||
if( gDebugTrace )
|
||||
log_info( " at size %d\n", (int)imageInfo.width );
|
||||
|
||||
int ret = test_read_image_1D( device, &imageInfo, seed );
|
||||
if( ret )
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else if( gTestMaxImages )
|
||||
{
|
||||
// Try a specific set of maximum sizes
|
||||
size_t numbeOfSizes;
|
||||
size_t sizes[100][3];
|
||||
|
||||
get_max_sizes(&numbeOfSizes, 100, sizes, maxWidth, 1, 1, 1, maxAllocSize, memSize, CL_MEM_OBJECT_IMAGE1D, imageInfo.format);
|
||||
|
||||
for( size_t idx = 0; idx < numbeOfSizes; idx++ )
|
||||
{
|
||||
imageInfo.width = sizes[idx][0];
|
||||
imageInfo.rowPitch = imageInfo.width * pixelSize;
|
||||
|
||||
if (gTestMipmaps)
|
||||
imageInfo.num_mip_levels = (cl_uint) random_log_in_range(2, (int)compute_max_mip_levels(imageInfo.width, 0, 0), seed);
|
||||
|
||||
log_info("Testing %d\n", (int)imageInfo.width);
|
||||
if( gDebugTrace )
|
||||
log_info( " at max size %d\n", (int)maxWidth );
|
||||
if( test_read_image_1D( device, &imageInfo, seed ) )
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for( int i = 0; i < NUM_IMAGE_ITERATIONS; i++ )
|
||||
{
|
||||
cl_ulong size;
|
||||
// Loop until we get a size that a) will fit in the max alloc size and b) that an allocation of that
|
||||
// image, the result array, plus offset arrays, will fit in the global ram space
|
||||
do
|
||||
{
|
||||
imageInfo.width = (size_t)random_log_in_range( 16, (int)maxWidth / 32, seed );
|
||||
|
||||
if (gTestMipmaps)
|
||||
{
|
||||
imageInfo.num_mip_levels = (cl_uint) random_log_in_range(2, (int)compute_max_mip_levels(imageInfo.width, 0, 0), seed);
|
||||
imageInfo.rowPitch = imageInfo.width * get_pixel_size( imageInfo.format );
|
||||
size = compute_mipmapped_image_size( imageInfo );
|
||||
}
|
||||
else
|
||||
{
|
||||
imageInfo.rowPitch = imageInfo.width * pixelSize;
|
||||
if( gEnablePitch )
|
||||
{
|
||||
size_t extraWidth = (int)random_log_in_range( 0, 64, seed );
|
||||
imageInfo.rowPitch += extraWidth * pixelSize;
|
||||
}
|
||||
|
||||
size = (size_t)imageInfo.rowPitch * 4;
|
||||
}
|
||||
} while( size > maxAllocSize || ( size / 3 ) > memSize );
|
||||
|
||||
if( gDebugTrace )
|
||||
log_info( " at size %d (row pitch %d) out of %d\n", (int)imageInfo.width, (int)imageInfo.rowPitch, (int)maxWidth );
|
||||
int ret = test_read_image_1D( device, &imageInfo, seed );
|
||||
if( ret )
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
287
test_conformance/images/clReadWriteImage/test_read_1D_array.cpp
Normal file
287
test_conformance/images/clReadWriteImage/test_read_1D_array.cpp
Normal file
@@ -0,0 +1,287 @@
|
||||
//
|
||||
// Copyright (c) 2017 The Khronos Group Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#include "../testBase.h"
|
||||
|
||||
#define MAX_ERR 0.005f
|
||||
#define MAX_HALF_LINEAR_ERR 0.3f
|
||||
|
||||
extern bool gDebugTrace, gDisableOffsets, gTestSmallImages, gEnablePitch, gTestMaxImages, gTestRounding, gTestMipmaps;
|
||||
extern cl_filter_mode gFilterModeToUse;
|
||||
extern cl_addressing_mode gAddressModeToUse;
|
||||
extern uint64_t gRoundingStartValue;
|
||||
extern cl_command_queue queue;
|
||||
extern cl_context context;
|
||||
|
||||
|
||||
int test_read_image_1D_array( cl_device_id device, image_descriptor *imageInfo, MTdata d )
|
||||
{
|
||||
int error;
|
||||
|
||||
clMemWrapper image;
|
||||
|
||||
// Generate some data to test against
|
||||
BufferOwningPtr<char> imageValues;
|
||||
generate_random_image_data( imageInfo, imageValues, d );
|
||||
|
||||
if( gDebugTrace )
|
||||
{
|
||||
log_info( " - Creating %s image array of size %d by %d...\n", gTestMipmaps?"mipmapped":"", (int)imageInfo->width, (int)imageInfo->arraySize );
|
||||
if( gTestMipmaps )
|
||||
log_info( " with %llu mip levels\n", (unsigned long long) imageInfo->num_mip_levels );
|
||||
}
|
||||
|
||||
// Construct testing sources
|
||||
if(!gTestMipmaps)
|
||||
{
|
||||
image = create_image_1d_array( context, (cl_mem_flags)(CL_MEM_READ_ONLY), imageInfo->format, imageInfo->width, imageInfo->arraySize, 0, 0, NULL, &error );
|
||||
if( image == NULL )
|
||||
{
|
||||
log_error( "ERROR: Unable to create 1D image array of size %d x %d (%s)", (int)imageInfo->width, (int)imageInfo->arraySize, IGetErrorString( error ) );
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cl_image_desc image_desc = {0};
|
||||
image_desc.image_type = CL_MEM_OBJECT_IMAGE1D_ARRAY;
|
||||
image_desc.image_width = imageInfo->width;
|
||||
image_desc.image_array_size = imageInfo->arraySize;
|
||||
image_desc.num_mip_levels = imageInfo->num_mip_levels;
|
||||
|
||||
image = clCreateImage( context, CL_MEM_READ_ONLY, imageInfo->format, &image_desc, NULL, &error);
|
||||
if( error != CL_SUCCESS )
|
||||
{
|
||||
log_error( "ERROR: Unable to create %d level mipmapped 1D image of width %d and array size %d (pitch %d ) (%s)",(int)imageInfo->num_mip_levels, (int)imageInfo->width, (int)imageInfo->arraySize, (int)imageInfo->rowPitch, IGetErrorString( error ) );
|
||||
return error;
|
||||
}
|
||||
}
|
||||
if( gDebugTrace )
|
||||
log_info( " - Writing image...\n" );
|
||||
|
||||
size_t origin[ 3 ] = { 0, 0, 0 };
|
||||
size_t region[ 3 ] = { 0, 0, 1 };
|
||||
size_t fullImageSize;
|
||||
if( gTestMipmaps )
|
||||
{
|
||||
fullImageSize = (size_t)compute_mipmapped_image_size( *imageInfo );
|
||||
}
|
||||
else
|
||||
{
|
||||
fullImageSize = imageInfo->arraySize * imageInfo->slicePitch;
|
||||
}
|
||||
|
||||
size_t imgValMipLevelOffset = 0;
|
||||
BufferOwningPtr<char> resultValues(malloc(fullImageSize));
|
||||
|
||||
for( size_t lod = 0; (gTestMipmaps && lod < imageInfo->num_mip_levels) || (!gTestMipmaps && lod < 1); lod++)
|
||||
{
|
||||
float lod_float = (float) lod;
|
||||
size_t width_lod, row_pitch_lod, slice_pitch_lod;
|
||||
if( gTestMipmaps )
|
||||
origin[2] = lod;
|
||||
|
||||
width_lod = (imageInfo->width >> lod) ? (imageInfo->width >> lod) : 1;
|
||||
row_pitch_lod = gTestMipmaps ? (width_lod * get_pixel_size( imageInfo->format )): imageInfo->rowPitch;
|
||||
slice_pitch_lod = row_pitch_lod;
|
||||
|
||||
region[0] = width_lod;
|
||||
region[1] = imageInfo->arraySize;
|
||||
|
||||
if ( gDebugTrace && gTestMipmaps )
|
||||
log_info("Working at mip level %llu\n", (unsigned long long) lod);
|
||||
|
||||
error = clEnqueueWriteImage(queue, image, CL_FALSE,
|
||||
origin, region, ( gEnablePitch ? row_pitch_lod : 0 ), 0,
|
||||
(char*)imageValues + imgValMipLevelOffset, 0, NULL, NULL);
|
||||
if (error != CL_SUCCESS) {
|
||||
log_error( "ERROR: Unable to write to 1D image array of width %d and size %d\n", (int)width_lod, (int)imageInfo->arraySize );
|
||||
return -1;
|
||||
}
|
||||
|
||||
// To verify, we just read the results right back and see whether they match the input
|
||||
if( gDebugTrace )
|
||||
log_info( " - Initing result array...\n" );
|
||||
|
||||
// Note: we read back without any pitch, to verify pitch actually WORKED
|
||||
size_t scanlineSize = width_lod * get_pixel_size( imageInfo->format );
|
||||
size_t imageSize = scanlineSize * imageInfo->arraySize;
|
||||
memset( resultValues, 0xff, imageSize );
|
||||
|
||||
if( gDebugTrace )
|
||||
log_info( " - Reading results...\n" );
|
||||
|
||||
error = clEnqueueReadImage( queue, image, CL_TRUE, origin, region, 0, 0, resultValues, 0, NULL, NULL );
|
||||
test_error( error, "Unable to read image values" );
|
||||
|
||||
// Verify scanline by scanline, since the pitches are different
|
||||
char *sourcePtr = (char *)imageValues + imgValMipLevelOffset;
|
||||
char *destPtr = resultValues;
|
||||
|
||||
for( size_t y = 0; y < imageInfo->arraySize; y++ )
|
||||
{
|
||||
if( memcmp( sourcePtr, destPtr, scanlineSize ) != 0 )
|
||||
{
|
||||
log_error( "ERROR: Image array index %d did not verify for image size %d,%d pitch %d (extra %d bytes)\n", (int)y, (int)width_lod, (int)imageInfo->arraySize, (int)row_pitch_lod, (int)row_pitch_lod - (int)width_lod * (int)get_pixel_size( imageInfo->format ) );
|
||||
|
||||
log_error( "First few values: \n" );
|
||||
log_error( " Input: " );
|
||||
uint32_t *s = (uint32_t *)sourcePtr;
|
||||
uint32_t *d = (uint32_t *)destPtr;
|
||||
for( int q = 0; q < 12; q++ )
|
||||
log_error( "%08x ", s[ q ] );
|
||||
log_error( "\nOutput: " );
|
||||
for( int q = 0; q < 12; q++ )
|
||||
log_error( "%08x ", d[ q ] );
|
||||
log_error( "\n" );
|
||||
|
||||
int outX, outY;
|
||||
int offset = (int)get_pixel_size( imageInfo->format ) * (int)( width_lod - 16 );
|
||||
if( offset < 0 )
|
||||
offset = 0;
|
||||
int foundCount = debug_find_vector_in_image( imageValues + imgValMipLevelOffset, imageInfo, destPtr + offset, get_pixel_size( imageInfo->format ), &outX, &outY, NULL );
|
||||
if( foundCount > 0 )
|
||||
{
|
||||
int returnedOffset = ( (int)y * (int)width_lod + offset / (int)get_pixel_size( imageInfo->format ) ) - ( outY * (int)width_lod + outX );
|
||||
|
||||
if( memcmp( sourcePtr + returnedOffset * get_pixel_size( imageInfo->format ), destPtr, get_pixel_size( imageInfo->format ) * 8 ) == 0 )
|
||||
log_error( " Values appear to be offsetted by %d\n", returnedOffset );
|
||||
else
|
||||
log_error( " Calculated offset is %d but unable to verify\n", returnedOffset );
|
||||
}
|
||||
else
|
||||
{
|
||||
log_error( " Unable to determine offset\n" );
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
sourcePtr += row_pitch_lod;
|
||||
destPtr += scanlineSize;
|
||||
}
|
||||
imgValMipLevelOffset += width_lod * imageInfo->arraySize * get_pixel_size( imageInfo->format );
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int test_read_image_set_1D_array( cl_device_id device, cl_image_format *format )
|
||||
{
|
||||
size_t maxWidth, maxArraySize;
|
||||
cl_ulong maxAllocSize, memSize;
|
||||
image_descriptor imageInfo = { 0 };
|
||||
RandomSeed seed( gRandomSeed );
|
||||
size_t pixelSize;
|
||||
|
||||
imageInfo.type = CL_MEM_OBJECT_IMAGE1D_ARRAY;
|
||||
imageInfo.format = format;
|
||||
imageInfo.height = imageInfo.depth = 0;
|
||||
pixelSize = get_pixel_size( imageInfo.format );
|
||||
|
||||
int error = clGetDeviceInfo( device, CL_DEVICE_IMAGE2D_MAX_WIDTH, sizeof( maxWidth ), &maxWidth, NULL );
|
||||
error |= clGetDeviceInfo( device, CL_DEVICE_IMAGE_MAX_ARRAY_SIZE, sizeof( maxArraySize ), &maxArraySize, NULL );
|
||||
error |= clGetDeviceInfo( device, CL_DEVICE_MAX_MEM_ALLOC_SIZE, sizeof( maxAllocSize ), &maxAllocSize, NULL );
|
||||
error |= clGetDeviceInfo( device, CL_DEVICE_GLOBAL_MEM_SIZE, sizeof( memSize ), &memSize, NULL );
|
||||
test_error( error, "Unable to get max image 2D size from device" );
|
||||
|
||||
if (memSize > (cl_ulong)SIZE_MAX) {
|
||||
memSize = (cl_ulong)SIZE_MAX;
|
||||
}
|
||||
|
||||
if( gTestSmallImages )
|
||||
{
|
||||
for( imageInfo.width = 1; imageInfo.width < 13; imageInfo.width++ )
|
||||
{
|
||||
imageInfo.rowPitch = imageInfo.width * pixelSize;
|
||||
imageInfo.slicePitch = imageInfo.rowPitch;
|
||||
for( imageInfo.arraySize = 2; imageInfo.arraySize < 9; imageInfo.arraySize++ )
|
||||
{
|
||||
if (gTestMipmaps)
|
||||
imageInfo.num_mip_levels = (cl_uint) random_log_in_range(2, (int)compute_max_mip_levels(imageInfo.width, 0, 0), seed);
|
||||
|
||||
if( gDebugTrace )
|
||||
log_info( " at size %d,%d\n", (int)imageInfo.width, (int)imageInfo.arraySize );
|
||||
|
||||
int ret = test_read_image_1D_array( device, &imageInfo, seed );
|
||||
if( ret )
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if( gTestMaxImages )
|
||||
{
|
||||
// Try a specific set of maximum sizes
|
||||
size_t numbeOfSizes;
|
||||
size_t sizes[100][3];
|
||||
|
||||
get_max_sizes(&numbeOfSizes, 100, sizes, maxWidth, 1, 1, maxArraySize, maxAllocSize, memSize, CL_MEM_OBJECT_IMAGE1D_ARRAY, imageInfo.format);
|
||||
|
||||
for( size_t idx = 0; idx < numbeOfSizes; idx++ )
|
||||
{
|
||||
imageInfo.width = sizes[idx][0];
|
||||
imageInfo.arraySize = sizes[idx][2];
|
||||
imageInfo.rowPitch = imageInfo.width * pixelSize;
|
||||
imageInfo.slicePitch = imageInfo.rowPitch;
|
||||
|
||||
if (gTestMipmaps)
|
||||
imageInfo.num_mip_levels = (cl_uint) random_log_in_range(2, (int)compute_max_mip_levels(imageInfo.width, 0, 0), seed);
|
||||
|
||||
log_info("Testing %d x %d\n", (int)imageInfo.width, (int)imageInfo.arraySize);
|
||||
if( gDebugTrace )
|
||||
log_info( " at max size %d,%d\n", (int)maxWidth, (int)maxArraySize );
|
||||
if( test_read_image_1D_array( device, &imageInfo, seed ) )
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for( int i = 0; i < NUM_IMAGE_ITERATIONS; i++ )
|
||||
{
|
||||
cl_ulong size;
|
||||
// Loop until we get a size that a) will fit in the max alloc size and b) that an allocation of that
|
||||
// image, the result array, plus offset arrays, will fit in the global ram space
|
||||
do
|
||||
{
|
||||
imageInfo.width = (size_t)random_log_in_range( 16, (int)maxWidth / 32, seed );
|
||||
imageInfo.arraySize = (size_t)random_log_in_range( 16, (int)maxArraySize / 32, seed );
|
||||
if (gTestMipmaps)
|
||||
{
|
||||
imageInfo.num_mip_levels = (cl_uint) random_log_in_range(2, (int)compute_max_mip_levels(imageInfo.width, 0, 0), seed);
|
||||
imageInfo.rowPitch = imageInfo.width * get_pixel_size( imageInfo.format );
|
||||
imageInfo.slicePitch = imageInfo.rowPitch;
|
||||
size = compute_mipmapped_image_size( imageInfo );
|
||||
}
|
||||
else
|
||||
{
|
||||
imageInfo.rowPitch = imageInfo.width * pixelSize;
|
||||
if( gEnablePitch )
|
||||
{
|
||||
size_t extraWidth = (int)random_log_in_range( 0, 64, seed );
|
||||
imageInfo.rowPitch += extraWidth * pixelSize;
|
||||
}
|
||||
imageInfo.slicePitch = imageInfo.rowPitch;
|
||||
|
||||
size = (size_t)imageInfo.rowPitch * (size_t)imageInfo.arraySize * 4;
|
||||
}
|
||||
} while( size > maxAllocSize || ( size * 3 ) > memSize );
|
||||
|
||||
if( gDebugTrace )
|
||||
log_info( " at size %d,%d (row pitch %d) out of %d,%d\n", (int)imageInfo.width, (int)imageInfo.arraySize, (int)imageInfo.rowPitch, (int)maxWidth, (int)maxArraySize );
|
||||
int ret = test_read_image_1D_array( device, &imageInfo, seed );
|
||||
if( ret )
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
286
test_conformance/images/clReadWriteImage/test_read_2D.cpp
Normal file
286
test_conformance/images/clReadWriteImage/test_read_2D.cpp
Normal file
@@ -0,0 +1,286 @@
|
||||
//
|
||||
// Copyright (c) 2017 The Khronos Group Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#include "../testBase.h"
|
||||
|
||||
#define MAX_ERR 0.005f
|
||||
#define MAX_HALF_LINEAR_ERR 0.3f
|
||||
|
||||
extern bool gDebugTrace, gDisableOffsets, gTestSmallImages, gEnablePitch, gTestMaxImages, gTestRounding, gTestMipmaps;
|
||||
extern cl_filter_mode gFilterModeToUse;
|
||||
extern cl_addressing_mode gAddressModeToUse;
|
||||
extern uint64_t gRoundingStartValue;
|
||||
extern cl_command_queue queue;
|
||||
extern cl_context context;
|
||||
|
||||
|
||||
int test_read_image_2D( cl_device_id device, image_descriptor *imageInfo, MTdata d )
|
||||
{
|
||||
int error;
|
||||
|
||||
clMemWrapper image;
|
||||
|
||||
// Generate some data to test against
|
||||
BufferOwningPtr<char> imageValues;
|
||||
generate_random_image_data( imageInfo, imageValues, d );
|
||||
|
||||
if( gDebugTrace )
|
||||
{
|
||||
log_info( " - Creating %s image %d by %d...\n", gTestMipmaps?"mipmapped":"", (int)imageInfo->width, (int)imageInfo->height );
|
||||
if( gTestMipmaps )
|
||||
log_info( " with %llu mip levels\n", (unsigned long long) imageInfo->num_mip_levels );
|
||||
}
|
||||
|
||||
// Construct testing sources
|
||||
if(!gTestMipmaps)
|
||||
{
|
||||
image = create_image_2d( context, (cl_mem_flags)(CL_MEM_READ_ONLY), imageInfo->format, imageInfo->width, imageInfo->height, 0, NULL, &error );
|
||||
if( image == NULL )
|
||||
{
|
||||
log_error( "ERROR: Unable to create 2D image of size %d x %d (%s)", (int)imageInfo->width, (int)imageInfo->height, IGetErrorString( error ) );
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cl_image_desc image_desc = {0};
|
||||
image_desc.image_type = CL_MEM_OBJECT_IMAGE2D;
|
||||
image_desc.image_width = imageInfo->width;
|
||||
image_desc.image_height = imageInfo->height;
|
||||
image_desc.num_mip_levels = imageInfo->num_mip_levels;
|
||||
|
||||
image = clCreateImage( context, CL_MEM_READ_ONLY, imageInfo->format, &image_desc, NULL, &error);
|
||||
if( error != CL_SUCCESS )
|
||||
{
|
||||
log_error( "ERROR: Unable to create %d level mipmapped 2D image of size %d x %d (pitch %d ) (%s)",(int)imageInfo->num_mip_levels, (int)imageInfo->width, (int)imageInfo->height, (int)imageInfo->rowPitch, IGetErrorString( error ) );
|
||||
return error;
|
||||
}
|
||||
}
|
||||
if( gDebugTrace )
|
||||
log_info( " - Writing image...\n" );
|
||||
|
||||
size_t origin[ 3 ] = { 0, 0, 0 };
|
||||
size_t region[ 3 ] = { 0, 0, 1 };
|
||||
size_t fullImageSize;
|
||||
if( gTestMipmaps )
|
||||
{
|
||||
fullImageSize = (size_t)compute_mipmapped_image_size( *imageInfo );
|
||||
}
|
||||
else
|
||||
{
|
||||
fullImageSize = imageInfo->height * imageInfo->rowPitch;
|
||||
}
|
||||
BufferOwningPtr<char> resultValues(malloc(fullImageSize));
|
||||
size_t imgValMipLevelOffset = 0;
|
||||
|
||||
for( size_t lod = 0; (gTestMipmaps && lod < imageInfo->num_mip_levels) || (!gTestMipmaps && lod < 1); lod++)
|
||||
{
|
||||
float lod_float = (float) lod;
|
||||
origin[2] = lod;
|
||||
size_t width_lod, height_lod, row_pitch_lod;
|
||||
|
||||
width_lod = (imageInfo->width >> lod) ? (imageInfo->width >> lod) : 1;
|
||||
height_lod = (imageInfo->height >> lod) ? (imageInfo->height >> lod) : 1;
|
||||
row_pitch_lod = gTestMipmaps ? (width_lod * get_pixel_size( imageInfo->format )): imageInfo->rowPitch;
|
||||
|
||||
region[0] = width_lod;
|
||||
region[1] = height_lod;
|
||||
|
||||
if ( gDebugTrace && gTestMipmaps) {
|
||||
log_info(" - Working at mipLevel :%llu\n", (unsigned long long)lod);
|
||||
}
|
||||
error = clEnqueueWriteImage(queue, image, CL_FALSE,
|
||||
origin, region, ( gEnablePitch ? row_pitch_lod : 0 ), 0,
|
||||
(char*)imageValues + imgValMipLevelOffset, 0, NULL, NULL);
|
||||
if (error != CL_SUCCESS) {
|
||||
log_error( "ERROR: Unable to write to 2D image of size %d x %d \n", (int)width_lod, (int)height_lod );
|
||||
return -1;
|
||||
}
|
||||
|
||||
// To verify, we just read the results right back and see whether they match the input
|
||||
if( gDebugTrace ) {
|
||||
log_info( " - Initing result array...\n" );
|
||||
}
|
||||
|
||||
// Note: we read back without any pitch, to verify pitch actually WORKED
|
||||
size_t scanlineSize = width_lod * get_pixel_size( imageInfo->format );
|
||||
size_t imageSize = scanlineSize * height_lod;
|
||||
memset( resultValues, 0xff, imageSize );
|
||||
|
||||
if( gDebugTrace )
|
||||
log_info( " - Reading results...\n" );
|
||||
|
||||
error = clEnqueueReadImage( queue, image, CL_TRUE, origin, region, 0, 0, resultValues, 0, NULL, NULL );
|
||||
test_error( error, "Unable to read image values" );
|
||||
|
||||
// Verify scanline by scanline, since the pitches are different
|
||||
char *sourcePtr = (char *)imageValues + imgValMipLevelOffset;
|
||||
char *destPtr = resultValues;
|
||||
|
||||
for( size_t y = 0; y < height_lod; y++ )
|
||||
{
|
||||
if( memcmp( sourcePtr, destPtr, scanlineSize ) != 0 )
|
||||
{
|
||||
if(gTestMipmaps)
|
||||
{
|
||||
log_error("At mip level %llu\n",(unsigned long long) lod);
|
||||
}
|
||||
log_error( "ERROR: Scanline %d did not verify for image size %d,%d pitch %d (extra %d bytes)\n", (int)y, (int)width_lod, (int)height_lod, (int)row_pitch_lod, (int)row_pitch_lod - (int)width_lod * (int)get_pixel_size( imageInfo->format ) );
|
||||
|
||||
log_error( "First few values: \n" );
|
||||
log_error( " Input: " );
|
||||
uint32_t *s = (uint32_t *)sourcePtr;
|
||||
uint32_t *d = (uint32_t *)destPtr;
|
||||
for( int q = 0; q < 12; q++ )
|
||||
log_error( "%08x ", s[ q ] );
|
||||
log_error( "\nOutput: " );
|
||||
for( int q = 0; q < 12; q++ )
|
||||
log_error( "%08x ", d[ q ] );
|
||||
log_error( "\n" );
|
||||
|
||||
int outX, outY;
|
||||
int offset = (int)get_pixel_size( imageInfo->format ) * (int)( width_lod - 16 );
|
||||
if( offset < 0 )
|
||||
offset = 0;
|
||||
int foundCount = debug_find_vector_in_image( (char*)imageValues + imgValMipLevelOffset, imageInfo, destPtr + offset, get_pixel_size( imageInfo->format ), &outX, &outY, NULL );
|
||||
if( foundCount > 0 )
|
||||
{
|
||||
int returnedOffset = ( (int)y * (int)width_lod + offset / (int)get_pixel_size( imageInfo->format ) ) - ( outY * (int)width_lod + outX );
|
||||
|
||||
if( memcmp( sourcePtr + returnedOffset * get_pixel_size( imageInfo->format ), destPtr, get_pixel_size( imageInfo->format ) * 8 ) == 0 )
|
||||
log_error( " Values appear to be offsetted by %d\n", returnedOffset );
|
||||
else
|
||||
log_error( " Calculated offset is %d but unable to verify\n", returnedOffset );
|
||||
}
|
||||
else
|
||||
{
|
||||
log_error( " Unable to determine offset\n" );
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
sourcePtr += row_pitch_lod;
|
||||
destPtr += scanlineSize;
|
||||
}
|
||||
imgValMipLevelOffset += width_lod * height_lod * get_pixel_size( imageInfo->format );
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int test_read_image_set_2D( cl_device_id device, cl_image_format *format )
|
||||
{
|
||||
size_t maxWidth, maxHeight;
|
||||
cl_ulong maxAllocSize, memSize;
|
||||
image_descriptor imageInfo = { 0 };
|
||||
RandomSeed seed( gRandomSeed );
|
||||
size_t pixelSize;
|
||||
|
||||
imageInfo.type = CL_MEM_OBJECT_IMAGE2D;
|
||||
imageInfo.format = format;
|
||||
imageInfo.depth = imageInfo.slicePitch = 0;
|
||||
pixelSize = get_pixel_size( imageInfo.format );
|
||||
|
||||
int error = clGetDeviceInfo( device, CL_DEVICE_IMAGE2D_MAX_WIDTH, sizeof( maxWidth ), &maxWidth, NULL );
|
||||
error |= clGetDeviceInfo( device, CL_DEVICE_IMAGE2D_MAX_HEIGHT, sizeof( maxHeight ), &maxHeight, NULL );
|
||||
error |= clGetDeviceInfo( device, CL_DEVICE_MAX_MEM_ALLOC_SIZE, sizeof( maxAllocSize ), &maxAllocSize, NULL );
|
||||
error |= clGetDeviceInfo( device, CL_DEVICE_GLOBAL_MEM_SIZE, sizeof( memSize ), &memSize, NULL );
|
||||
test_error( error, "Unable to get max image 2D size from device" );
|
||||
|
||||
if (memSize > (cl_ulong)SIZE_MAX) {
|
||||
memSize = (cl_ulong)SIZE_MAX;
|
||||
}
|
||||
|
||||
if( gTestSmallImages )
|
||||
{
|
||||
for( imageInfo.width = 1; imageInfo.width < 13; imageInfo.width++ )
|
||||
{
|
||||
imageInfo.rowPitch = imageInfo.width * pixelSize;
|
||||
for( imageInfo.height = 1; imageInfo.height < 9; imageInfo.height++ )
|
||||
{
|
||||
if (gTestMipmaps)
|
||||
imageInfo.num_mip_levels = (cl_uint) random_log_in_range(2, (int)compute_max_mip_levels(imageInfo.width, imageInfo.height, 0), seed);
|
||||
|
||||
if( gDebugTrace )
|
||||
log_info( " at size %d,%d\n", (int)imageInfo.width, (int)imageInfo.height );
|
||||
|
||||
int ret = test_read_image_2D( device, &imageInfo, seed );
|
||||
if( ret )
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if( gTestMaxImages )
|
||||
{
|
||||
// Try a specific set of maximum sizes
|
||||
size_t numbeOfSizes;
|
||||
size_t sizes[100][3];
|
||||
|
||||
get_max_sizes(&numbeOfSizes, 100, sizes, maxWidth, maxHeight, 1, 1, maxAllocSize, memSize, CL_MEM_OBJECT_IMAGE2D, imageInfo.format);
|
||||
|
||||
for( size_t idx = 0; idx < numbeOfSizes; idx++ )
|
||||
{
|
||||
imageInfo.width = sizes[idx][0];
|
||||
imageInfo.height = sizes[idx][1];
|
||||
imageInfo.rowPitch = imageInfo.width * pixelSize;
|
||||
|
||||
if (gTestMipmaps)
|
||||
imageInfo.num_mip_levels = (cl_uint) random_log_in_range(2, (int)compute_max_mip_levels(imageInfo.width, imageInfo.height, 0), seed);
|
||||
|
||||
log_info("Testing %d x %d\n", (int)imageInfo.width, (int)imageInfo.height);
|
||||
if( gDebugTrace )
|
||||
log_info( " at max size %d,%d\n", (int)maxWidth, (int)maxHeight );
|
||||
if( test_read_image_2D( device, &imageInfo, seed ) )
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for( int i = 0; i < NUM_IMAGE_ITERATIONS; i++ )
|
||||
{
|
||||
cl_ulong size;
|
||||
// Loop until we get a size that a) will fit in the max alloc size and b) that an allocation of that
|
||||
// image, the result array, plus offset arrays, will fit in the global ram space
|
||||
do
|
||||
{
|
||||
imageInfo.width = (size_t)random_log_in_range( 16, (int)maxWidth / 32, seed );
|
||||
imageInfo.height = (size_t)random_log_in_range( 16, (int)maxHeight / 32, seed );
|
||||
if (gTestMipmaps)
|
||||
{
|
||||
imageInfo.num_mip_levels = (cl_uint) random_log_in_range(2, (int)compute_max_mip_levels(imageInfo.width, imageInfo.height, 0), seed);
|
||||
imageInfo.rowPitch = imageInfo.width * get_pixel_size( imageInfo.format );
|
||||
size = compute_mipmapped_image_size( imageInfo );
|
||||
}
|
||||
else
|
||||
{
|
||||
imageInfo.rowPitch = imageInfo.width * pixelSize;
|
||||
if( gEnablePitch )
|
||||
{
|
||||
size_t extraWidth = (int)random_log_in_range( 0, 64, seed );
|
||||
imageInfo.rowPitch += extraWidth * pixelSize;
|
||||
}
|
||||
|
||||
size = (size_t)imageInfo.rowPitch * (size_t)imageInfo.height * 4;
|
||||
}
|
||||
} while( size > maxAllocSize || ( size / 3 ) > memSize );
|
||||
|
||||
if( gDebugTrace )
|
||||
log_info( " at size %d,%d (row pitch %d) out of %d,%d\n", (int)imageInfo.width, (int)imageInfo.height, (int)imageInfo.rowPitch, (int)maxWidth, (int)maxHeight );
|
||||
int ret = test_read_image_2D( device, &imageInfo, seed );
|
||||
if( ret )
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
272
test_conformance/images/clReadWriteImage/test_read_2D_array.cpp
Normal file
272
test_conformance/images/clReadWriteImage/test_read_2D_array.cpp
Normal file
@@ -0,0 +1,272 @@
|
||||
//
|
||||
// Copyright (c) 2017 The Khronos Group Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#include "../testBase.h"
|
||||
|
||||
#define MAX_ERR 0.005f
|
||||
#define MAX_HALF_LINEAR_ERR 0.3f
|
||||
|
||||
extern bool gDebugTrace, gDisableOffsets, gTestSmallImages, gEnablePitch, gTestMaxImages, gTestRounding, gTestMipmaps;
|
||||
extern cl_filter_mode gFilterModeToUse;
|
||||
extern cl_addressing_mode gAddressModeToUse;
|
||||
extern cl_command_queue queue;
|
||||
extern cl_context context;
|
||||
|
||||
int test_read_image_2D_array( cl_device_id device, image_descriptor *imageInfo, MTdata d )
|
||||
{
|
||||
int error;
|
||||
|
||||
clMemWrapper image;
|
||||
|
||||
// Create some data to test against
|
||||
BufferOwningPtr<char> imageValues;
|
||||
generate_random_image_data( imageInfo, imageValues, d );
|
||||
|
||||
if( gDebugTrace )
|
||||
{
|
||||
log_info( " - Creating %s image %d by %d by %d...\n", gTestMipmaps?"mipmapped":"", (int)imageInfo->width, (int)imageInfo->height, (int)imageInfo->arraySize );
|
||||
if( gTestMipmaps )
|
||||
log_info( " with %llu mip levels\n", (unsigned long long) imageInfo->num_mip_levels );
|
||||
}
|
||||
|
||||
// Construct testing sources
|
||||
if(!gTestMipmaps)
|
||||
{
|
||||
image = create_image_2d_array( context, (cl_mem_flags)(CL_MEM_READ_ONLY), imageInfo->format, imageInfo->width, imageInfo->height, imageInfo->arraySize, 0, 0, NULL, &error );
|
||||
if( image == NULL )
|
||||
{
|
||||
log_error( "ERROR: Unable to create 2D image array of size %d x %d x %d (%s)", (int)imageInfo->width, (int)imageInfo->height, (int)imageInfo->arraySize, IGetErrorString( error ) );
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cl_image_desc image_desc = {0};
|
||||
image_desc.image_type = CL_MEM_OBJECT_IMAGE2D_ARRAY;
|
||||
image_desc.image_width = imageInfo->width;
|
||||
image_desc.image_height = imageInfo->height;
|
||||
image_desc.image_array_size = imageInfo->arraySize;
|
||||
image_desc.num_mip_levels = imageInfo->num_mip_levels;
|
||||
|
||||
image = clCreateImage( context, CL_MEM_READ_ONLY, imageInfo->format, &image_desc, NULL, &error);
|
||||
if( error != CL_SUCCESS )
|
||||
{
|
||||
log_error( "ERROR: Unable to create %d level mipmapped 3D image of size %d x %d x %d (pitch %d, %d ) (%s)",(int)imageInfo->num_mip_levels, (int)imageInfo->width, (int)imageInfo->height, (int)imageInfo->depth, (int)imageInfo->rowPitch, (int)imageInfo->slicePitch, IGetErrorString( error ) );
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
if( gDebugTrace )
|
||||
log_info( " - Writing image...\n" );
|
||||
|
||||
size_t origin[ 4 ] = { 0, 0, 0, 0 };
|
||||
size_t region[ 3 ] = { 0, 0, 0 };
|
||||
size_t fullImageSize;
|
||||
if( gTestMipmaps )
|
||||
{
|
||||
fullImageSize = (size_t)compute_mipmapped_image_size( *imageInfo );
|
||||
}
|
||||
else
|
||||
{
|
||||
fullImageSize = imageInfo->arraySize * imageInfo->slicePitch;
|
||||
}
|
||||
BufferOwningPtr<char> resultValues(malloc(fullImageSize));
|
||||
size_t imgValMipLevelOffset = 0;
|
||||
|
||||
for(size_t lod = 0; (gTestMipmaps && lod < imageInfo->num_mip_levels) || (!gTestMipmaps && lod < 1); lod++)
|
||||
{
|
||||
float lod_float = (float) lod;
|
||||
origin[3] = lod;
|
||||
size_t width_lod, height_lod, depth_lod, row_pitch_lod, slice_pitch_lod;
|
||||
|
||||
width_lod = (imageInfo->width >> lod) ? (imageInfo->width >> lod) : 1;
|
||||
height_lod = (imageInfo->height >> lod) ? (imageInfo->height >> lod) : 1;
|
||||
row_pitch_lod = gTestMipmaps ? (width_lod * get_pixel_size( imageInfo->format )): imageInfo->rowPitch;
|
||||
slice_pitch_lod = gTestMipmaps ? (row_pitch_lod * height_lod): imageInfo->slicePitch;
|
||||
region[0] = width_lod;
|
||||
region[1] = height_lod;
|
||||
region[2] = imageInfo->arraySize;
|
||||
|
||||
if ( gDebugTrace && gTestMipmaps) {
|
||||
log_info(" - Working at mipLevel :%llu\n", (unsigned long long)lod);
|
||||
}
|
||||
|
||||
error = clEnqueueWriteImage(queue, image, CL_FALSE,
|
||||
origin, region, ( gEnablePitch ? row_pitch_lod : 0 ), ( gEnablePitch ? slice_pitch_lod : 0 ),
|
||||
(char*)imageValues + imgValMipLevelOffset, 0, NULL, NULL);
|
||||
if (error != CL_SUCCESS) {
|
||||
log_error( "ERROR: Unable to write to 2D image array of size %d x %d x %d\n", (int)width_lod, (int)height_lod, (int)imageInfo->arraySize );
|
||||
return -1;
|
||||
}
|
||||
|
||||
// To verify, we just read the results right back and see whether they match the input
|
||||
if( gDebugTrace )
|
||||
log_info( " - Initing result array...\n" );
|
||||
|
||||
// Note: we read back without any pitch, to verify pitch actually WORKED
|
||||
size_t scanlineSize = width_lod * get_pixel_size( imageInfo->format );
|
||||
size_t pageSize = scanlineSize * height_lod;
|
||||
size_t imageSize = pageSize * imageInfo->arraySize;
|
||||
memset( resultValues, 0xff, imageSize );
|
||||
|
||||
if( gDebugTrace )
|
||||
log_info( " - Reading results...\n" );
|
||||
|
||||
error = clEnqueueReadImage( queue, image, CL_TRUE, origin, region, 0, 0, resultValues, 0, NULL, NULL );
|
||||
test_error( error, "Unable to read image values" );
|
||||
|
||||
// Verify scanline by scanline, since the pitches are different
|
||||
char *sourcePtr = (char *)imageValues + imgValMipLevelOffset;
|
||||
char *destPtr = resultValues;
|
||||
|
||||
for( size_t z = 0; z < imageInfo->arraySize; z++ )
|
||||
{
|
||||
for( size_t y = 0; y < height_lod; y++ )
|
||||
{
|
||||
if( memcmp( sourcePtr, destPtr, scanlineSize ) != 0 )
|
||||
{
|
||||
log_error( "ERROR: Scanline %d,%d did not verify for image size %d,%d,%d pitch %d,%d\n", (int)y, (int)z, (int)width_lod, (int)height_lod, (int)imageInfo->arraySize, (int)row_pitch_lod, (int)slice_pitch_lod );
|
||||
return -1;
|
||||
}
|
||||
sourcePtr += row_pitch_lod;
|
||||
destPtr += scanlineSize;
|
||||
}
|
||||
sourcePtr += slice_pitch_lod - ( row_pitch_lod * height_lod );
|
||||
destPtr += pageSize - scanlineSize * height_lod;
|
||||
}
|
||||
imgValMipLevelOffset += width_lod * height_lod * imageInfo->arraySize * get_pixel_size( imageInfo->format );
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int test_read_image_set_2D_array( cl_device_id device, cl_image_format *format )
|
||||
{
|
||||
size_t maxWidth, maxHeight, maxArraySize;
|
||||
cl_ulong maxAllocSize, memSize;
|
||||
image_descriptor imageInfo = { 0 };
|
||||
RandomSeed seed( gRandomSeed );
|
||||
size_t pixelSize;
|
||||
|
||||
imageInfo.type = CL_MEM_OBJECT_IMAGE2D_ARRAY;
|
||||
imageInfo.format = format;
|
||||
pixelSize = get_pixel_size( imageInfo.format );
|
||||
|
||||
int error = clGetDeviceInfo( device, CL_DEVICE_IMAGE2D_MAX_WIDTH, sizeof( maxWidth ), &maxWidth, NULL );
|
||||
error |= clGetDeviceInfo( device, CL_DEVICE_IMAGE2D_MAX_HEIGHT, sizeof( maxHeight ), &maxHeight, NULL );
|
||||
error |= clGetDeviceInfo( device, CL_DEVICE_IMAGE_MAX_ARRAY_SIZE, sizeof( maxArraySize ), &maxArraySize, NULL );
|
||||
error |= clGetDeviceInfo( device, CL_DEVICE_MAX_MEM_ALLOC_SIZE, sizeof( maxAllocSize ), &maxAllocSize, NULL );
|
||||
error |= clGetDeviceInfo( device, CL_DEVICE_GLOBAL_MEM_SIZE, sizeof( memSize ), &memSize, NULL );
|
||||
test_error( error, "Unable to get max image 3D size from device" );
|
||||
|
||||
if (memSize > (cl_ulong)SIZE_MAX) {
|
||||
memSize = (cl_ulong)SIZE_MAX;
|
||||
}
|
||||
|
||||
if( gTestSmallImages )
|
||||
{
|
||||
for( imageInfo.width = 1; imageInfo.width < 13; imageInfo.width++ )
|
||||
{
|
||||
imageInfo.rowPitch = imageInfo.width * pixelSize;
|
||||
|
||||
for( imageInfo.height = 1; imageInfo.height < 9; imageInfo.height++ )
|
||||
{
|
||||
imageInfo.slicePitch = imageInfo.rowPitch * imageInfo.height;
|
||||
for( imageInfo.arraySize = 2; imageInfo.arraySize < 9; imageInfo.arraySize++ )
|
||||
{
|
||||
if (gTestMipmaps)
|
||||
imageInfo.num_mip_levels = (cl_uint) random_log_in_range(2, (int)compute_max_mip_levels(imageInfo.width, imageInfo.height, 0), seed);
|
||||
|
||||
if( gDebugTrace )
|
||||
log_info( " at size %d,%d,%d\n", (int)imageInfo.width, (int)imageInfo.height, (int)imageInfo.arraySize );
|
||||
int ret = test_read_image_2D_array( device, &imageInfo, seed );
|
||||
if( ret )
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if( gTestMaxImages )
|
||||
{
|
||||
// Try a specific set of maximum sizes
|
||||
size_t numbeOfSizes;
|
||||
size_t sizes[100][3];
|
||||
|
||||
get_max_sizes(&numbeOfSizes, 100, sizes, maxWidth, maxHeight, 1, maxArraySize, maxAllocSize, memSize, CL_MEM_OBJECT_IMAGE2D_ARRAY, imageInfo.format);
|
||||
|
||||
for( size_t idx = 0; idx < numbeOfSizes; idx++ )
|
||||
{
|
||||
// Try a specific set of maximum sizes
|
||||
imageInfo.width = sizes[idx][0];
|
||||
imageInfo.height = sizes[idx][1];
|
||||
imageInfo.arraySize = sizes[idx][2];
|
||||
imageInfo.rowPitch = imageInfo.width * pixelSize;
|
||||
imageInfo.slicePitch = imageInfo.height * imageInfo.rowPitch;
|
||||
|
||||
if (gTestMipmaps)
|
||||
imageInfo.num_mip_levels = (cl_uint) random_log_in_range(2, (int)compute_max_mip_levels(imageInfo.width, imageInfo.height, 0), seed);
|
||||
|
||||
log_info("Testing %d x %d x %d\n", (int)imageInfo.width, (int)imageInfo.height, (int)imageInfo.arraySize);
|
||||
if( test_read_image_2D_array( device, &imageInfo, seed ) )
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for( int i = 0; i < NUM_IMAGE_ITERATIONS; i++ )
|
||||
{
|
||||
cl_ulong size;
|
||||
// Loop until we get a size that a) will fit in the max alloc size and b) that an allocation of that
|
||||
// image, the result array, plus offset arrays, will fit in the global ram space
|
||||
do
|
||||
{
|
||||
imageInfo.width = (size_t)random_log_in_range( 16, (int)maxWidth / 32, seed );
|
||||
imageInfo.height = (size_t)random_log_in_range( 16, (int)maxHeight / 32, seed );
|
||||
imageInfo.arraySize = (size_t)random_log_in_range( 16, (int)maxArraySize / 32, seed );
|
||||
|
||||
if (gTestMipmaps)
|
||||
{
|
||||
imageInfo.num_mip_levels = (cl_uint) random_log_in_range(2, (int)compute_max_mip_levels(imageInfo.width, imageInfo.height, 0), seed);
|
||||
imageInfo.rowPitch = imageInfo.width * get_pixel_size( imageInfo.format );
|
||||
imageInfo.slicePitch = imageInfo.rowPitch * imageInfo.height;
|
||||
size = compute_mipmapped_image_size( imageInfo ) * 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
imageInfo.rowPitch = imageInfo.width * pixelSize;
|
||||
imageInfo.slicePitch = imageInfo.rowPitch * imageInfo.height;
|
||||
|
||||
if( gEnablePitch )
|
||||
{
|
||||
size_t extraWidth = (int)random_log_in_range( 0, 64, seed );
|
||||
imageInfo.rowPitch += extraWidth * pixelSize;
|
||||
|
||||
size_t extraHeight = (int)random_log_in_range( 0, 8, seed );
|
||||
imageInfo.slicePitch = imageInfo.rowPitch * (imageInfo.height + extraHeight);
|
||||
}
|
||||
|
||||
size = (cl_ulong)imageInfo.slicePitch * (cl_ulong)imageInfo.arraySize * 4 * 4;
|
||||
}
|
||||
} while( size > maxAllocSize || ( size * 3 ) > memSize );
|
||||
|
||||
if( gDebugTrace )
|
||||
log_info( " at size %d,%d,%d (pitch %d,%d) out of %d,%d,%d\n", (int)imageInfo.width, (int)imageInfo.height, (int)imageInfo.arraySize, (int)imageInfo.rowPitch, (int)imageInfo.slicePitch, (int)maxWidth, (int)maxHeight, (int)maxArraySize );
|
||||
int ret = test_read_image_2D_array( device, &imageInfo, seed );
|
||||
if( ret )
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
276
test_conformance/images/clReadWriteImage/test_read_3D.cpp
Normal file
276
test_conformance/images/clReadWriteImage/test_read_3D.cpp
Normal file
@@ -0,0 +1,276 @@
|
||||
//
|
||||
// Copyright (c) 2017 The Khronos Group Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#include "../testBase.h"
|
||||
|
||||
#define MAX_ERR 0.005f
|
||||
#define MAX_HALF_LINEAR_ERR 0.3f
|
||||
|
||||
extern bool gDebugTrace, gDisableOffsets, gTestSmallImages, gEnablePitch, gTestMaxImages, gTestRounding, gTestMipmaps;
|
||||
extern cl_filter_mode gFilterModeToUse;
|
||||
extern cl_addressing_mode gAddressModeToUse;
|
||||
extern cl_command_queue queue;
|
||||
extern cl_context context;
|
||||
|
||||
int test_read_image_3D( cl_device_id device, image_descriptor *imageInfo, MTdata d )
|
||||
{
|
||||
int error;
|
||||
|
||||
clMemWrapper image;
|
||||
|
||||
// Create some data to test against
|
||||
BufferOwningPtr<char> imageValues;
|
||||
generate_random_image_data( imageInfo, imageValues, d );
|
||||
|
||||
if( gDebugTrace )
|
||||
{
|
||||
log_info( " - Creating %s image %d by %d by %d...\n", gTestMipmaps?"mipmapped":"", (int)imageInfo->width, (int)imageInfo->height, (int)imageInfo->depth );
|
||||
if( gTestMipmaps )
|
||||
log_info( " with %llu mip levels\n", (unsigned long long) imageInfo->num_mip_levels );
|
||||
}
|
||||
// Construct testing sources
|
||||
if(!gTestMipmaps)
|
||||
{
|
||||
image = create_image_3d( context, (cl_mem_flags)(CL_MEM_READ_ONLY), imageInfo->format, imageInfo->width, imageInfo->height, imageInfo->depth, 0, 0, NULL, &error );
|
||||
if( image == NULL )
|
||||
{
|
||||
log_error( "ERROR: Unable to create 2D image of size %d x %d x %d (%s)", (int)imageInfo->width, (int)imageInfo->height, (int)imageInfo->depth, IGetErrorString( error ) );
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cl_image_desc image_desc = {0};
|
||||
image_desc.image_type = CL_MEM_OBJECT_IMAGE3D;
|
||||
image_desc.image_width = imageInfo->width;
|
||||
image_desc.image_height = imageInfo->height;
|
||||
image_desc.image_depth = imageInfo->depth;
|
||||
image_desc.num_mip_levels = imageInfo->num_mip_levels;
|
||||
|
||||
image = clCreateImage( context, CL_MEM_READ_ONLY, imageInfo->format, &image_desc, NULL, &error);
|
||||
if( error != CL_SUCCESS )
|
||||
{
|
||||
log_error( "ERROR: Unable to create %d level mipmapped 3D image of size %d x %d x %d (pitch %d, %d ) (%s)",(int)imageInfo->num_mip_levels, (int)imageInfo->width, (int)imageInfo->height, (int)imageInfo->depth, (int)imageInfo->rowPitch, (int)imageInfo->slicePitch, IGetErrorString( error ) );
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
if( gDebugTrace )
|
||||
log_info( " - Writing image...\n" );
|
||||
|
||||
size_t origin[ 4 ] = { 0, 0, 0, 0 };
|
||||
size_t region[ 3 ] = { 0, 0, 0 };
|
||||
size_t fullImageSize;
|
||||
if( gTestMipmaps )
|
||||
{
|
||||
fullImageSize = (size_t)compute_mipmapped_image_size( *imageInfo );
|
||||
}
|
||||
else
|
||||
{
|
||||
fullImageSize = imageInfo->depth * imageInfo->slicePitch;
|
||||
}
|
||||
|
||||
BufferOwningPtr<char> resultValues(malloc(fullImageSize));
|
||||
size_t imgValMipLevelOffset = 0;
|
||||
|
||||
for(size_t lod = 0; (gTestMipmaps && lod < imageInfo->num_mip_levels) || (!gTestMipmaps && lod < 1); lod++)
|
||||
{
|
||||
float lod_float = (float) lod;
|
||||
origin[3] = lod;
|
||||
size_t width_lod, height_lod, depth_lod, row_pitch_lod, slice_pitch_lod;
|
||||
|
||||
width_lod = (imageInfo->width >> lod) ? (imageInfo->width >> lod) : 1;
|
||||
height_lod = (imageInfo->height >> lod) ? (imageInfo->height >> lod) : 1;
|
||||
depth_lod = (imageInfo->depth >> lod) ? (imageInfo->depth >> lod) : 1;
|
||||
row_pitch_lod = gTestMipmaps ? (width_lod * get_pixel_size( imageInfo->format )): imageInfo->rowPitch;
|
||||
slice_pitch_lod = gTestMipmaps ? (row_pitch_lod * height_lod): imageInfo->slicePitch;
|
||||
region[0] = width_lod;
|
||||
region[1] = height_lod;
|
||||
region[2] = depth_lod;
|
||||
|
||||
if ( gDebugTrace && gTestMipmaps) {
|
||||
log_info(" - Working at mipLevel :%llu\n", (unsigned long long)lod);
|
||||
}
|
||||
error = clEnqueueWriteImage(queue, image, CL_FALSE,
|
||||
origin, region, ( gEnablePitch ? imageInfo->rowPitch : 0 ), ( gEnablePitch ? imageInfo->slicePitch : 0 ),
|
||||
(char*)imageValues + imgValMipLevelOffset, 0, NULL, NULL);
|
||||
if (error != CL_SUCCESS) {
|
||||
log_error( "ERROR: Unable to write to %s 3D image of size %d x %d x %d\n", gTestMipmaps?"mipmapped":"", (int)width_lod, (int)height_lod, (int)depth_lod );
|
||||
return -1;
|
||||
}
|
||||
|
||||
// To verify, we just read the results right back and see whether they match the input
|
||||
if( gDebugTrace ) {
|
||||
log_info( " - Initing result array...\n" );
|
||||
}
|
||||
|
||||
// Note: we read back without any pitch, to verify pitch actually WORKED
|
||||
size_t scanlineSize = width_lod * get_pixel_size( imageInfo->format );
|
||||
size_t pageSize = scanlineSize * height_lod;
|
||||
size_t imageSize = pageSize * depth_lod;
|
||||
memset( resultValues, 0xff, imageSize );
|
||||
|
||||
if( gDebugTrace )
|
||||
log_info( " - Reading results...\n" );
|
||||
|
||||
error = clEnqueueReadImage( queue, image, CL_TRUE, origin, region, 0, 0, resultValues, 0, NULL, NULL );
|
||||
test_error( error, "Unable to read image values" );
|
||||
|
||||
// Verify scanline by scanline, since the pitches are different
|
||||
char *sourcePtr = (char *)imageValues + imgValMipLevelOffset;
|
||||
char *destPtr = resultValues;
|
||||
|
||||
for( size_t z = 0; z < depth_lod; z++ )
|
||||
{
|
||||
for( size_t y = 0; y < height_lod; y++ )
|
||||
{
|
||||
if( memcmp( sourcePtr, destPtr, scanlineSize ) != 0 )
|
||||
{
|
||||
if(gTestMipmaps)
|
||||
{
|
||||
log_error("At mip level %llu\n",(unsigned long long) lod);
|
||||
}
|
||||
log_error( "ERROR: Scanline %d,%d did not verify for image size %d,%d,%d pitch %d,%d\n", (int)y, (int)z, (int)width_lod, (int)height_lod, (int)depth_lod, (int)row_pitch_lod, (int)slice_pitch_lod );
|
||||
return -1;
|
||||
}
|
||||
sourcePtr += row_pitch_lod;
|
||||
destPtr += scanlineSize;
|
||||
}
|
||||
sourcePtr += slice_pitch_lod - ( row_pitch_lod * height_lod );
|
||||
destPtr += pageSize - scanlineSize * height_lod;
|
||||
}
|
||||
imgValMipLevelOffset += width_lod * height_lod * depth_lod * get_pixel_size( imageInfo->format );
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int test_read_image_set_3D( cl_device_id device, cl_image_format *format )
|
||||
{
|
||||
size_t maxWidth, maxHeight, maxDepth;
|
||||
cl_ulong maxAllocSize, memSize;
|
||||
image_descriptor imageInfo = { 0 };
|
||||
RandomSeed seed( gRandomSeed );
|
||||
size_t pixelSize;
|
||||
|
||||
imageInfo.type = CL_MEM_OBJECT_IMAGE3D;
|
||||
imageInfo.format = format;
|
||||
pixelSize = get_pixel_size( imageInfo.format );
|
||||
|
||||
int error = clGetDeviceInfo( device, CL_DEVICE_IMAGE3D_MAX_WIDTH, sizeof( maxWidth ), &maxWidth, NULL );
|
||||
error |= clGetDeviceInfo( device, CL_DEVICE_IMAGE3D_MAX_HEIGHT, sizeof( maxHeight ), &maxHeight, NULL );
|
||||
error |= clGetDeviceInfo( device, CL_DEVICE_IMAGE3D_MAX_DEPTH, sizeof( maxDepth ), &maxDepth, NULL );
|
||||
error |= clGetDeviceInfo( device, CL_DEVICE_MAX_MEM_ALLOC_SIZE, sizeof( maxAllocSize ), &maxAllocSize, NULL );
|
||||
error |= clGetDeviceInfo( device, CL_DEVICE_GLOBAL_MEM_SIZE, sizeof( memSize ), &memSize, NULL );
|
||||
test_error( error, "Unable to get max image 3D size from device" );
|
||||
|
||||
if (memSize > (cl_ulong)SIZE_MAX) {
|
||||
memSize = (cl_ulong)SIZE_MAX;
|
||||
}
|
||||
|
||||
if( gTestSmallImages )
|
||||
{
|
||||
for( imageInfo.width = 1; imageInfo.width < 13; imageInfo.width++ )
|
||||
{
|
||||
imageInfo.rowPitch = imageInfo.width * pixelSize;
|
||||
|
||||
for( imageInfo.height = 1; imageInfo.height < 9; imageInfo.height++ )
|
||||
{
|
||||
imageInfo.slicePitch = imageInfo.rowPitch * imageInfo.height;
|
||||
for( imageInfo.depth = 2; imageInfo.depth < 9; imageInfo.depth++ )
|
||||
{
|
||||
if (gTestMipmaps)
|
||||
imageInfo.num_mip_levels = (cl_uint) random_log_in_range(2, (int)compute_max_mip_levels(imageInfo.width, imageInfo.height, imageInfo.depth), seed);
|
||||
|
||||
if( gDebugTrace )
|
||||
log_info( " at size %d,%d,%d\n", (int)imageInfo.width, (int)imageInfo.height, (int)imageInfo.depth );
|
||||
int ret = test_read_image_3D( device, &imageInfo, seed );
|
||||
if( ret )
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if( gTestMaxImages )
|
||||
{
|
||||
// Try a specific set of maximum sizes
|
||||
size_t numbeOfSizes;
|
||||
size_t sizes[100][3];
|
||||
|
||||
get_max_sizes(&numbeOfSizes, 100, sizes, maxWidth, maxHeight, maxDepth, 1, maxAllocSize, memSize, CL_MEM_OBJECT_IMAGE3D, imageInfo.format);
|
||||
|
||||
for( size_t idx = 0; idx < numbeOfSizes; idx++ )
|
||||
{
|
||||
// Try a specific set of maximum sizes
|
||||
imageInfo.width = sizes[idx][0];
|
||||
imageInfo.height = sizes[idx][1];
|
||||
imageInfo.depth = sizes[idx][2];
|
||||
imageInfo.rowPitch = imageInfo.width * pixelSize;
|
||||
imageInfo.slicePitch = imageInfo.height * imageInfo.rowPitch;
|
||||
|
||||
if (gTestMipmaps)
|
||||
imageInfo.num_mip_levels = (cl_uint) random_log_in_range(2, (int)compute_max_mip_levels(imageInfo.width, imageInfo.height, imageInfo.depth), seed);
|
||||
|
||||
log_info("Testing %d x %d x %d\n", (int)imageInfo.width, (int)imageInfo.height, (int)imageInfo.depth);
|
||||
if( test_read_image_3D( device, &imageInfo, seed ) )
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for( int i = 0; i < NUM_IMAGE_ITERATIONS; i++ )
|
||||
{
|
||||
cl_ulong size;
|
||||
// Loop until we get a size that a) will fit in the max alloc size and b) that an allocation of that
|
||||
// image, the result array, plus offset arrays, will fit in the global ram space
|
||||
do
|
||||
{
|
||||
imageInfo.width = (size_t)random_log_in_range( 16, (int)maxWidth / 32, seed );
|
||||
imageInfo.height = (size_t)random_log_in_range( 16, (int)maxHeight / 32, seed );
|
||||
imageInfo.depth = (size_t)random_log_in_range( 16, (int)maxDepth / 32, seed );
|
||||
if (gTestMipmaps)
|
||||
{
|
||||
imageInfo.num_mip_levels = (cl_uint) random_log_in_range(2, (int)compute_max_mip_levels(imageInfo.width, imageInfo.height, imageInfo.depth), seed);
|
||||
imageInfo.rowPitch = imageInfo.width * get_pixel_size( imageInfo.format );
|
||||
imageInfo.slicePitch = imageInfo.rowPitch * imageInfo.height;
|
||||
size = compute_mipmapped_image_size( imageInfo );
|
||||
}
|
||||
else
|
||||
{
|
||||
imageInfo.rowPitch = imageInfo.width * pixelSize;
|
||||
imageInfo.slicePitch = imageInfo.rowPitch * imageInfo.height;
|
||||
|
||||
if( gEnablePitch )
|
||||
{
|
||||
size_t extraWidth = (int)random_log_in_range( 0, 64, seed );
|
||||
imageInfo.rowPitch += extraWidth * pixelSize;
|
||||
|
||||
size_t extraHeight = (int)random_log_in_range( 0, 8, seed );
|
||||
imageInfo.slicePitch = imageInfo.rowPitch * (imageInfo.height + extraHeight);
|
||||
}
|
||||
|
||||
size = (cl_ulong)imageInfo.slicePitch * (cl_ulong)imageInfo.depth * 4 * 4;
|
||||
}
|
||||
} while( size > maxAllocSize || ( size * 3 ) > memSize );
|
||||
|
||||
if( gDebugTrace )
|
||||
log_info( " at size %d,%d,%d (pitch %d,%d) out of %d,%d,%d\n", (int)imageInfo.width, (int)imageInfo.height, (int)imageInfo.depth, (int)imageInfo.rowPitch, (int)imageInfo.slicePitch, (int)maxWidth, (int)maxHeight, (int)maxDepth );
|
||||
int ret = test_read_image_3D( device, &imageInfo, seed );
|
||||
if( ret )
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user