mirror of
https://github.com/KhronosGroup/OpenCL-CTS.git
synced 2026-03-26 08:49:02 +00:00
* imageHelpers: Created generic function that returns a vector of required image formats. An upcoming commit requires access to the vector of required image formats, separatley from check_minimum_supported. * imageHelpers: Added a new function is_image_format_required. This function can be used to determine for any given cl_image_format, whether the implementaion is required to support it. Conditionally test BGRA in Basic readimage3d (#623) This change adds checks to see if testing against an embedded implementation and if so, queries whether BGRA is supported or not. * Refactor based on PR review. * Update passed message code. * Changed scope of struct to be within test_readimage3d.
This commit is contained in:
@@ -21,7 +21,6 @@
|
|||||||
#if !defined (_WIN32) && !defined(__APPLE__)
|
#if !defined (_WIN32) && !defined(__APPLE__)
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#endif
|
#endif
|
||||||
#include <vector>
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#if !defined (_WIN32)
|
#if !defined (_WIN32)
|
||||||
@@ -3664,16 +3663,15 @@ bool find_format( cl_image_format *formatList, unsigned int numFormats, cl_image
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool check_minimum_supported(cl_image_format *formatList,
|
void build_required_image_formats(cl_mem_flags flags,
|
||||||
unsigned int numFormats,
|
|
||||||
cl_mem_flags flags,
|
|
||||||
cl_mem_object_type image_type,
|
cl_mem_object_type image_type,
|
||||||
cl_device_id device)
|
cl_device_id device,
|
||||||
|
std::vector<cl_image_format>& formatsToSupport)
|
||||||
{
|
{
|
||||||
bool passed = true;
|
|
||||||
std::vector<cl_image_format> formatsToSupport;
|
|
||||||
Version version = get_device_cl_version(device);
|
Version version = get_device_cl_version(device);
|
||||||
|
|
||||||
|
formatsToSupport.clear();
|
||||||
|
|
||||||
// Required embedded formats.
|
// Required embedded formats.
|
||||||
static std::vector<cl_image_format> embeddedProfReadOrWriteFormats
|
static std::vector<cl_image_format> embeddedProfReadOrWriteFormats
|
||||||
{
|
{
|
||||||
@@ -3810,18 +3808,26 @@ bool check_minimum_supported(cl_image_format *formatList,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (auto &format: formatsToSupport)
|
bool is_image_format_required(cl_image_format format,
|
||||||
|
cl_mem_flags flags,
|
||||||
|
cl_mem_object_type image_type,
|
||||||
|
cl_device_id device)
|
||||||
{
|
{
|
||||||
if( !find_format( formatList, numFormats, &format ) )
|
std::vector<cl_image_format> formatsToSupport;
|
||||||
|
build_required_image_formats(flags, image_type, device, formatsToSupport);
|
||||||
|
|
||||||
|
for (auto &formatItr: formatsToSupport)
|
||||||
{
|
{
|
||||||
log_error( "ERROR: Format required by OpenCL %s is not supported: ", version.to_string().c_str() );
|
if (formatItr.image_channel_order == format.image_channel_order &&
|
||||||
print_header( &format, true );
|
formatItr.image_channel_data_type == format.image_channel_data_type)
|
||||||
passed = false;
|
{
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return passed;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
cl_uint compute_max_mip_levels( size_t width, size_t height, size_t depth)
|
cl_uint compute_max_mip_levels( size_t width, size_t height, size_t depth)
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#if !defined(_WIN32)
|
#if !defined(_WIN32)
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@@ -71,11 +72,14 @@ extern void print_read_header( cl_image_format *format, image_sampler_data *samp
|
|||||||
extern void print_write_header( cl_image_format *format, bool err);
|
extern void print_write_header( cl_image_format *format, bool err);
|
||||||
extern void print_header( cl_image_format *format, bool err );
|
extern void print_header( cl_image_format *format, bool err );
|
||||||
extern bool find_format( cl_image_format *formatList, unsigned int numFormats, cl_image_format *formatToFind );
|
extern bool find_format( cl_image_format *formatList, unsigned int numFormats, cl_image_format *formatToFind );
|
||||||
extern bool check_minimum_supported(cl_image_format *formatList,
|
extern bool is_image_format_required(cl_image_format format,
|
||||||
unsigned int numFormats,
|
|
||||||
cl_mem_flags flags,
|
cl_mem_flags flags,
|
||||||
cl_mem_object_type image_type,
|
cl_mem_object_type image_type,
|
||||||
cl_device_id device);
|
cl_device_id device);
|
||||||
|
extern void build_required_image_formats(cl_mem_flags flags,
|
||||||
|
cl_mem_object_type image_type,
|
||||||
|
cl_device_id device,
|
||||||
|
std::vector<cl_image_format>& formatsToSupport);
|
||||||
|
|
||||||
extern size_t get_format_type_size( const cl_image_format *format );
|
extern size_t get_format_type_size( const cl_image_format *format );
|
||||||
extern size_t get_channel_data_type_size( cl_channel_type channelType );
|
extern size_t get_channel_data_type_size( cl_channel_type channelType );
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
//
|
//
|
||||||
#include "harness/compat.h"
|
#include "harness/compat.h"
|
||||||
|
#include "harness/imageHelpers.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -22,7 +23,6 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
|
||||||
#include "procs.h"
|
#include "procs.h"
|
||||||
|
|
||||||
static const char *bgra8888_kernel_code =
|
static const char *bgra8888_kernel_code =
|
||||||
@@ -43,7 +43,6 @@ static const char *bgra8888_kernel_code =
|
|||||||
"\n"
|
"\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
|
|
||||||
|
|
||||||
static const char *rgba8888_kernel_code =
|
static const char *rgba8888_kernel_code =
|
||||||
"\n"
|
"\n"
|
||||||
"__kernel void test_rgba8888(read_only image3d_t srcimg, __global float4 *dst, sampler_t sampler)\n"
|
"__kernel void test_rgba8888(read_only image3d_t srcimg, __global float4 *dst, sampler_t sampler)\n"
|
||||||
@@ -63,7 +62,6 @@ static const char *rgba8888_kernel_code =
|
|||||||
"\n"
|
"\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
|
|
||||||
|
|
||||||
static unsigned char *
|
static unsigned char *
|
||||||
generate_3d_image8(int w, int h, int d, MTdata data)
|
generate_3d_image8(int w, int h, int d, MTdata data)
|
||||||
{
|
{
|
||||||
@@ -110,16 +108,36 @@ prepare_reference(unsigned char * input_ptr, int w, int h, int d)
|
|||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int test_readimage3d(cl_device_id device, cl_context context, cl_command_queue queue, int num_elements)
|
int test_readimage3d(cl_device_id device, cl_context context, cl_command_queue queue, int num_elements)
|
||||||
{
|
{
|
||||||
cl_mem streams[3];
|
cl_mem streams[2];
|
||||||
cl_program program[2];
|
cl_program program;
|
||||||
cl_kernel kernel[2];
|
cl_kernel kernel;
|
||||||
cl_image_format img_format;
|
cl_sampler sampler;
|
||||||
unsigned char *input_ptr[2];
|
struct testFormat
|
||||||
|
{
|
||||||
|
const char* kernelName;
|
||||||
|
const char* kernelSourceString;
|
||||||
|
const cl_image_format img_format;
|
||||||
|
};
|
||||||
|
|
||||||
|
static testFormat formatsToTest[] =
|
||||||
|
{
|
||||||
|
{
|
||||||
|
"test_bgra8888",
|
||||||
|
bgra8888_kernel_code,
|
||||||
|
{CL_BGRA, CL_UNORM_INT8},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"test_rgba8888",
|
||||||
|
rgba8888_kernel_code,
|
||||||
|
{CL_RGBA, CL_UNORM_INT8},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
unsigned char *input_ptr;
|
||||||
float *output_ptr;
|
float *output_ptr;
|
||||||
double *ref_ptr[2];
|
double *ref_ptr;
|
||||||
size_t threads[3];
|
size_t threads[3];
|
||||||
int img_width = 64;
|
int img_width = 64;
|
||||||
int img_height = 64;
|
int img_height = 64;
|
||||||
@@ -129,104 +147,67 @@ int test_readimage3d(cl_device_id device, cl_context context, cl_command_queue q
|
|||||||
size_t region[3] = {img_width, img_height, img_depth};
|
size_t region[3] = {img_width, img_height, img_depth};
|
||||||
size_t length = img_width * img_height * img_depth * 4 * sizeof(float);
|
size_t length = img_width * img_height * img_depth * 4 * sizeof(float);
|
||||||
|
|
||||||
|
|
||||||
PASSIVE_REQUIRE_3D_IMAGE_SUPPORT( device )
|
PASSIVE_REQUIRE_3D_IMAGE_SUPPORT( device )
|
||||||
|
|
||||||
|
for (uint32_t i = 0; i < ARRAY_SIZE(formatsToTest); i++)
|
||||||
|
{
|
||||||
|
if (!is_image_format_required(formatsToTest[i].img_format, CL_MEM_READ_ONLY, CL_MEM_OBJECT_IMAGE3D, device))
|
||||||
|
continue;
|
||||||
|
|
||||||
MTdata d = init_genrand( gRandomSeed );
|
MTdata d = init_genrand( gRandomSeed );
|
||||||
input_ptr[0] = generate_3d_image8(img_width, img_height, img_depth, d);
|
input_ptr = generate_3d_image8(img_width, img_height, img_depth, d);
|
||||||
input_ptr[1] = generate_3d_image8(img_width, img_height, img_depth, d);
|
ref_ptr = prepare_reference(input_ptr, img_width, img_height, img_depth);
|
||||||
ref_ptr[0] = prepare_reference(input_ptr[0], img_width, img_height, img_depth);
|
|
||||||
ref_ptr[1] = prepare_reference(input_ptr[1], img_width, img_height, img_depth);
|
|
||||||
free_mtdata(d); d = NULL;
|
|
||||||
output_ptr = (float*)malloc(length);
|
output_ptr = (float*)malloc(length);
|
||||||
|
|
||||||
img_format.image_channel_order = CL_BGRA;
|
streams[0] = create_image_3d(context, CL_MEM_READ_ONLY, &formatsToTest[i].img_format, img_width, img_height, img_depth, 0, 0, NULL, &err);
|
||||||
img_format.image_channel_data_type = CL_UNORM_INT8;
|
|
||||||
streams[0] = create_image_3d(context, CL_MEM_READ_ONLY, &img_format, img_width, img_height, img_depth, 0, 0, NULL, &err);
|
|
||||||
test_error(err, "create_image_3d failed");
|
test_error(err, "create_image_3d failed");
|
||||||
|
|
||||||
img_format.image_channel_order = CL_RGBA;
|
streams[1] = clCreateBuffer(context, CL_MEM_READ_WRITE, length, NULL, &err);
|
||||||
img_format.image_channel_data_type = CL_UNORM_INT8;
|
|
||||||
streams[1] = create_image_3d(context, CL_MEM_READ_ONLY, &img_format, img_width, img_height, img_depth, 0, 0, NULL, &err);
|
|
||||||
test_error(err, "create_image_3d failed");
|
|
||||||
|
|
||||||
streams[2] = clCreateBuffer(context, CL_MEM_READ_WRITE, length, NULL, &err);
|
|
||||||
test_error(err, "clCreateBuffer failed");
|
test_error(err, "clCreateBuffer failed");
|
||||||
|
|
||||||
err = clEnqueueWriteImage(queue, streams[0], CL_TRUE, origin, region, 0, 0, input_ptr[0], 0, NULL, NULL);
|
sampler = clCreateSampler(context, CL_FALSE, CL_ADDRESS_CLAMP_TO_EDGE, CL_FILTER_NEAREST, &err);
|
||||||
test_error(err, "clEnqueueWriteImage failed");
|
|
||||||
|
|
||||||
err = clEnqueueWriteImage(queue, streams[1], CL_TRUE, origin, region, 0, 0, input_ptr[1], 0, NULL, NULL);
|
|
||||||
test_error(err, "clEnqueueWriteImage failed");
|
|
||||||
|
|
||||||
err = create_single_kernel_helper(context, &program[0], &kernel[0], 1, &bgra8888_kernel_code, "test_bgra8888" );
|
|
||||||
if (err)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
err = create_single_kernel_helper(context, &program[1], &kernel[1], 1, &rgba8888_kernel_code, "test_rgba8888" );
|
|
||||||
if (err)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
cl_sampler sampler = clCreateSampler(context, CL_FALSE, CL_ADDRESS_CLAMP_TO_EDGE, CL_FILTER_NEAREST, &err);
|
|
||||||
test_error(err, "clCreateSampler failed");
|
test_error(err, "clCreateSampler failed");
|
||||||
|
|
||||||
err = clSetKernelArg(kernel[0], 0, sizeof streams[0], &streams[0]);
|
err = clEnqueueWriteImage(queue, streams[0], CL_TRUE, origin, region, 0, 0, input_ptr, 0, NULL, NULL);
|
||||||
err |= clSetKernelArg(kernel[0], 1, sizeof streams[2], &streams[2]);
|
test_error(err, "clEnqueueWriteImage failed");
|
||||||
err |= clSetKernelArg(kernel[0], 2, sizeof sampler, &sampler);
|
|
||||||
test_error(err, "clSetKernelArg failed");
|
|
||||||
|
|
||||||
err = clSetKernelArg(kernel[1], 0, sizeof streams[1], &streams[1]);
|
err = create_single_kernel_helper(context, &program, &kernel, 1, &formatsToTest[i].kernelSourceString, formatsToTest[i].kernelName);
|
||||||
err |= clSetKernelArg(kernel[1], 1, sizeof streams[2], &streams[2]);
|
test_error(err, "create_single_kernel_helper failed");
|
||||||
err |= clSetKernelArg(kernel[1], 2, sizeof sampler, &sampler);
|
|
||||||
|
err = clSetKernelArg(kernel, 0, sizeof streams[0], &streams[0]);
|
||||||
|
err |= clSetKernelArg(kernel, 1, sizeof streams[1], &streams[1]);
|
||||||
|
err |= clSetKernelArg(kernel, 2, sizeof sampler, &sampler);
|
||||||
test_error(err, "clSetKernelArg failed");
|
test_error(err, "clSetKernelArg failed");
|
||||||
|
|
||||||
threads[0] = (unsigned int)img_width;
|
threads[0] = (unsigned int)img_width;
|
||||||
threads[1] = (unsigned int)img_height;
|
threads[1] = (unsigned int)img_height;
|
||||||
threads[2] = (unsigned int)img_depth;
|
threads[2] = (unsigned int)img_depth;
|
||||||
|
|
||||||
for (i=0; i<2; i++)
|
err = clEnqueueNDRangeKernel(queue, kernel, 3, NULL, threads, NULL, 0, NULL, NULL);
|
||||||
{
|
|
||||||
err = clEnqueueNDRangeKernel(queue, kernel[i], 3, NULL, threads, NULL, 0, NULL, NULL);
|
|
||||||
test_error(err, "clEnqueueNDRangeKernel failed");
|
test_error(err, "clEnqueueNDRangeKernel failed");
|
||||||
|
|
||||||
err = clEnqueueReadBuffer(queue, streams[2], CL_TRUE, 0, length, output_ptr, 0, NULL, NULL);
|
err = clEnqueueReadBuffer(queue, streams[1], CL_TRUE, 0, length, output_ptr, 0, NULL, NULL);
|
||||||
test_error(err, "clEnqueueReadBuffer failed");
|
test_error(err, "clEnqueueReadBuffer failed");
|
||||||
|
|
||||||
switch (i)
|
err = verify_3d_image8(ref_ptr, output_ptr, img_width, img_height, img_depth);
|
||||||
|
if ( err == 0 )
|
||||||
{
|
{
|
||||||
case 0:
|
log_info("READ_IMAGE3D_%s_%s test passed\n",
|
||||||
err = verify_3d_image8(ref_ptr[i], output_ptr, img_width, img_height, img_depth);
|
GetChannelTypeName(formatsToTest[i].img_format.image_channel_data_type),
|
||||||
if ( err != 0 )
|
GetChannelOrderName(formatsToTest[i].img_format.image_channel_order));
|
||||||
log_info("READ_IMAGE3D_BGRA_UNORM_INT8 test passed\n");
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
err = verify_3d_image8(ref_ptr[i], output_ptr, img_width, img_height, img_depth);
|
|
||||||
if ( err != 0 )
|
|
||||||
log_info("READ_IMAGE3D_RGBA_UNORM_INT8 test passed\n");
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (err)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// cleanup
|
|
||||||
clReleaseSampler(sampler);
|
clReleaseSampler(sampler);
|
||||||
clReleaseMemObject(streams[0]);
|
clReleaseMemObject(streams[0]);
|
||||||
clReleaseMemObject(streams[1]);
|
clReleaseMemObject(streams[1]);
|
||||||
clReleaseMemObject(streams[2]);
|
clReleaseKernel(kernel);
|
||||||
for (i=0; i<2; i++)
|
clReleaseProgram(program);
|
||||||
{
|
free_mtdata(d);
|
||||||
clReleaseKernel(kernel[i]);
|
d = NULL;
|
||||||
clReleaseProgram(program[i]);
|
free(input_ptr);
|
||||||
}
|
free(ref_ptr);
|
||||||
free(input_ptr[0]);
|
|
||||||
free(input_ptr[1]);
|
|
||||||
free(output_ptr);
|
free(output_ptr);
|
||||||
free(ref_ptr[0]);
|
}
|
||||||
free(ref_ptr[1]);
|
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,9 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
//
|
//
|
||||||
#include "../testBase.h"
|
#include "../testBase.h"
|
||||||
|
#include "harness/imageHelpers.h"
|
||||||
|
#include <algorithm>
|
||||||
|
#include <iterator>
|
||||||
|
|
||||||
extern cl_filter_mode gFilterModeToUse;
|
extern cl_filter_mode gFilterModeToUse;
|
||||||
extern cl_addressing_mode gAddressModeToUse;
|
extern cl_addressing_mode gAddressModeToUse;
|
||||||
@@ -36,6 +39,30 @@ static const char *str_3d_image = "3D";
|
|||||||
static const char *str_1d_image_array = "1D array";
|
static const char *str_1d_image_array = "1D array";
|
||||||
static const char *str_2d_image_array = "2D 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,
|
||||||
|
cl_mem_object_type image_type,
|
||||||
|
cl_device_id device)
|
||||||
|
{
|
||||||
|
bool passed = true;
|
||||||
|
Version version = get_device_cl_version(device);
|
||||||
|
std::vector<cl_image_format> formatsToSupport;
|
||||||
|
build_required_image_formats(flags, image_type, device, formatsToSupport);
|
||||||
|
|
||||||
|
for (auto &format: formatsToSupport)
|
||||||
|
{
|
||||||
|
if( !find_format( formatList, numFormats, &format ) )
|
||||||
|
{
|
||||||
|
log_error( "ERROR: Format required by OpenCL %s is not supported: ", version.to_string().c_str() );
|
||||||
|
print_header( &format, true );
|
||||||
|
passed = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return passed;
|
||||||
|
}
|
||||||
|
|
||||||
static const char *convert_image_type_to_string(cl_mem_object_type image_type)
|
static const char *convert_image_type_to_string(cl_mem_object_type image_type)
|
||||||
{
|
{
|
||||||
const char *p;
|
const char *p;
|
||||||
|
|||||||
Reference in New Issue
Block a user