diff --git a/CMakeLists.txt b/CMakeLists.txt index 844283aa..5d32692c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -223,7 +223,6 @@ endif(CMAKE_BUILD_TYPE STREQUAL "release") add_subdirectory(test_common) add_subdirectory(test_conformance) -add_subdirectory(test_extensions) # Support both VS2008 and VS2012. set (DLL_FILES "${VS_BUILD_DIR}/Debug/*.dll") diff --git a/test_conformance/extensions/CMakeLists.txt b/test_conformance/extensions/CMakeLists.txt index c917eb30..53d77ee5 100644 --- a/test_conformance/extensions/CMakeLists.txt +++ b/test_conformance/extensions/CMakeLists.txt @@ -1 +1,2 @@ add_subdirectory( cl_ext_cxx_for_opencl ) +add_subdirectory( cl_khr_dx9_media_sharing ) diff --git a/test_extensions/media_sharing/CMakeLists.txt b/test_conformance/extensions/cl_khr_dx9_media_sharing/CMakeLists.txt similarity index 92% rename from test_extensions/media_sharing/CMakeLists.txt rename to test_conformance/extensions/cl_khr_dx9_media_sharing/CMakeLists.txt index 9fdde1c7..1ec2a338 100644 --- a/test_extensions/media_sharing/CMakeLists.txt +++ b/test_conformance/extensions/cl_khr_dx9_media_sharing/CMakeLists.txt @@ -21,5 +21,5 @@ set_source_files_properties( include_directories(${CMAKE_CURRENT_SOURCE_DIR}) -include(../../test_conformance/CMakeCommon.txt) +include(../../CMakeCommon.txt) endif(WIN32) diff --git a/test_conformance/extensions/cl_khr_dx9_media_sharing/main.cpp b/test_conformance/extensions/cl_khr_dx9_media_sharing/main.cpp new file mode 100644 index 00000000..8b709173 --- /dev/null +++ b/test_conformance/extensions/cl_khr_dx9_media_sharing/main.cpp @@ -0,0 +1,231 @@ +// +// 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 +#include + +#include "harness/testHarness.h" +#include "utils.h" +#include "procs.h" + + +test_definition test_list[] = { ADD_TEST(context_create), + ADD_TEST(get_device_ids), + ADD_TEST(api), + ADD_TEST(kernel), + ADD_TEST(other_data_types), + ADD_TEST(memory_access), + ADD_TEST(interop_user_sync) }; + +const int test_num = ARRAY_SIZE(test_list); + +clGetDeviceIDsFromDX9MediaAdapterKHR_fn clGetDeviceIDsFromDX9MediaAdapterKHR = + NULL; +clCreateFromDX9MediaSurfaceKHR_fn clCreateFromDX9MediaSurfaceKHR = NULL; +clEnqueueAcquireDX9MediaSurfacesKHR_fn clEnqueueAcquireDX9MediaSurfacesKHR = + NULL; +clEnqueueReleaseDX9MediaSurfacesKHR_fn clEnqueueReleaseDX9MediaSurfacesKHR = + NULL; + +cl_platform_id gPlatformIDdetected; +cl_device_id gDeviceIDdetected; +cl_device_type gDeviceTypeSelected = CL_DEVICE_TYPE_DEFAULT; + +bool MediaSurfaceSharingExtensionInit() +{ + clGetDeviceIDsFromDX9MediaAdapterKHR = + (clGetDeviceIDsFromDX9MediaAdapterKHR_fn) + clGetExtensionFunctionAddressForPlatform( + gPlatformIDdetected, "clGetDeviceIDsFromDX9MediaAdapterKHR"); + if (clGetDeviceIDsFromDX9MediaAdapterKHR == NULL) + { + log_error("clGetExtensionFunctionAddressForPlatform(" + "clGetDeviceIDsFromDX9MediaAdapterKHR) returned NULL.\n"); + return false; + } + + clCreateFromDX9MediaSurfaceKHR = (clCreateFromDX9MediaSurfaceKHR_fn) + clGetExtensionFunctionAddressForPlatform( + gPlatformIDdetected, "clCreateFromDX9MediaSurfaceKHR"); + if (clCreateFromDX9MediaSurfaceKHR == NULL) + { + log_error("clGetExtensionFunctionAddressForPlatform(" + "clCreateFromDX9MediaSurfaceKHR) returned NULL.\n"); + return false; + } + + clEnqueueAcquireDX9MediaSurfacesKHR = + (clEnqueueAcquireDX9MediaSurfacesKHR_fn) + clGetExtensionFunctionAddressForPlatform( + gPlatformIDdetected, "clEnqueueAcquireDX9MediaSurfacesKHR"); + if (clEnqueueAcquireDX9MediaSurfacesKHR == NULL) + { + log_error("clGetExtensionFunctionAddressForPlatform(" + "clEnqueueAcquireDX9MediaSurfacesKHR) returned NULL.\n"); + return false; + } + + clEnqueueReleaseDX9MediaSurfacesKHR = + (clEnqueueReleaseDX9MediaSurfacesKHR_fn) + clGetExtensionFunctionAddressForPlatform( + gPlatformIDdetected, "clEnqueueReleaseDX9MediaSurfacesKHR"); + if (clEnqueueReleaseDX9MediaSurfacesKHR == NULL) + { + log_error("clGetExtensionFunctionAddressForPlatform(" + "clEnqueueReleaseDX9MediaSurfacesKHR) returned NULL.\n"); + return false; + } + + return true; +} + +bool DetectPlatformAndDevice() +{ + std::vector platforms; + cl_uint platformsNum = 0; + cl_int error = clGetPlatformIDs(0, 0, &platformsNum); + if (error != CL_SUCCESS) + { + print_error(error, "clGetPlatformIDs failed\n"); + return false; + } + + platforms.resize(platformsNum); + error = clGetPlatformIDs(platformsNum, &platforms[0], 0); + if (error != CL_SUCCESS) + { + print_error(error, "clGetPlatformIDs failed\n"); + return false; + } + + bool found = false; + for (size_t i = 0; i < platformsNum; ++i) + { + std::vector devices; + cl_uint devicesNum = 0; + error = clGetDeviceIDs(platforms[i], gDeviceTypeSelected, 0, 0, + &devicesNum); + if (error != CL_SUCCESS) + { + print_error(error, "clGetDeviceIDs failed\n"); + return false; + } + + devices.resize(devicesNum); + error = clGetDeviceIDs(platforms[i], gDeviceTypeSelected, devicesNum, + &devices[0], 0); + if (error != CL_SUCCESS) + { + print_error(error, "clGetDeviceIDs failed\n"); + return false; + } + + for (size_t j = 0; j < devicesNum; ++j) + { + if (is_extension_available(devices[j], "cl_khr_dx9_media_sharing")) + { + gPlatformIDdetected = platforms[i]; + gDeviceIDdetected = devices[j]; + found = true; + break; + } + } + } + + if (!found) + { + log_info("Test was not run, because the media surface sharing " + "extension is not supported for any devices.\n"); + return false; + } + + return true; +} + +bool CmdlineParse(int argc, const char *argv[]) +{ + char *env_mode = getenv("CL_DEVICE_TYPE"); + if (env_mode != NULL) + { + if (strcmp(env_mode, "gpu") == 0 + || strcmp(env_mode, "CL_DEVICE_TYPE_GPU") == 0) + gDeviceTypeSelected = CL_DEVICE_TYPE_GPU; + else if (strcmp(env_mode, "cpu") == 0 + || strcmp(env_mode, "CL_DEVICE_TYPE_CPU") == 0) + gDeviceTypeSelected = CL_DEVICE_TYPE_CPU; + else if (strcmp(env_mode, "accelerator") == 0 + || strcmp(env_mode, "CL_DEVICE_TYPE_ACCELERATOR") == 0) + gDeviceTypeSelected = CL_DEVICE_TYPE_ACCELERATOR; + else if (strcmp(env_mode, "default") == 0 + || strcmp(env_mode, "CL_DEVICE_TYPE_DEFAULT") == 0) + gDeviceTypeSelected = CL_DEVICE_TYPE_DEFAULT; + else + { + log_error("Unknown CL_DEVICE_TYPE env variable setting: " + "%s.\nAborting...\n", + env_mode); + return false; + } + } + + for (int i = 0; i < argc; ++i) + { + if (strcmp(argv[i], "gpu") == 0 + || strcmp(argv[i], "CL_DEVICE_TYPE_GPU") == 0) + { + gDeviceTypeSelected = CL_DEVICE_TYPE_GPU; + continue; + } + else if (strcmp(argv[i], "cpu") == 0 + || strcmp(argv[i], "CL_DEVICE_TYPE_CPU") == 0) + { + gDeviceTypeSelected = CL_DEVICE_TYPE_CPU; + continue; + } + else if (strcmp(argv[i], "accelerator") == 0 + || strcmp(argv[i], "CL_DEVICE_TYPE_ACCELERATOR") == 0) + { + gDeviceTypeSelected = CL_DEVICE_TYPE_ACCELERATOR; + continue; + } + else if (strcmp(argv[i], "CL_DEVICE_TYPE_DEFAULT") == 0) + { + gDeviceTypeSelected = CL_DEVICE_TYPE_DEFAULT; + continue; + } + else if (strcmp(argv[i], "sw") == 0 || strcmp(argv[i], "software") == 0) + { + CDeviceWrapper::AccelerationType(CDeviceWrapper::ACCELERATION_SW); + } + } + + return true; +} + +int main(int argc, const char *argv[]) +{ + if (!CmdlineParse(argc, argv)) return TEST_FAIL; + + if (!DetectPlatformAndDevice()) + { + log_info("Test was not run, because the media surface sharing " + "extension is not supported\n"); + return TEST_SKIP; + } + + if (!MediaSurfaceSharingExtensionInit()) return TEST_FAIL; + + return runTestHarness(argc, argv, test_num, test_list, true, 0); +} diff --git a/test_extensions/media_sharing/procs.h b/test_conformance/extensions/cl_khr_dx9_media_sharing/procs.h similarity index 61% rename from test_extensions/media_sharing/procs.h rename to test_conformance/extensions/cl_khr_dx9_media_sharing/procs.h index 6b577990..e7fd785e 100644 --- a/test_extensions/media_sharing/procs.h +++ b/test_conformance/extensions/cl_khr_dx9_media_sharing/procs.h @@ -19,13 +19,20 @@ #define __MEDIA_SHARING_PROCS_H__ -extern int test_context_create(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements); -extern int test_get_device_ids(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements); -extern int test_api(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements); -extern int test_kernel(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements); -extern int test_other_data_types(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements); -extern int test_memory_access(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements); -extern int test_interop_user_sync(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements); +extern int test_context_create(cl_device_id deviceID, cl_context context, + cl_command_queue queue, int num_elements); +extern int test_get_device_ids(cl_device_id deviceID, cl_context context, + cl_command_queue queue, int num_elements); +extern int test_api(cl_device_id deviceID, cl_context context, + cl_command_queue queue, int num_elements); +extern int test_kernel(cl_device_id deviceID, cl_context context, + cl_command_queue queue, int num_elements); +extern int test_other_data_types(cl_device_id deviceID, cl_context context, + cl_command_queue queue, int num_elements); +extern int test_memory_access(cl_device_id deviceID, cl_context context, + cl_command_queue queue, int num_elements); +extern int test_interop_user_sync(cl_device_id deviceID, cl_context context, + cl_command_queue queue, int num_elements); -#endif // #ifndef __MEDIA_SHARING_PROCS_H__ \ No newline at end of file +#endif // #ifndef __MEDIA_SHARING_PROCS_H__ \ No newline at end of file diff --git a/test_conformance/extensions/cl_khr_dx9_media_sharing/test_create_context.cpp b/test_conformance/extensions/cl_khr_dx9_media_sharing/test_create_context.cpp new file mode 100644 index 00000000..6033ce9b --- /dev/null +++ b/test_conformance/extensions/cl_khr_dx9_media_sharing/test_create_context.cpp @@ -0,0 +1,373 @@ +// +// 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 "utils.h" + +int context_create(cl_device_id deviceID, cl_context context, + cl_command_queue queue, int num_elements, unsigned int width, + unsigned int height, TContextFuncType functionCreate, + cl_dx9_media_adapter_type_khr adapterType, + TSurfaceFormat surfaceFormat, TSharedHandleType sharedHandle) +{ + CResult result; + + // create device + std::auto_ptr deviceWrapper; + if (!DeviceCreate(adapterType, deviceWrapper)) + { + result.ResultSub(CResult::TEST_ERROR); + return result.Result(); + } + + // generate input data + std::vector bufferIn(width * height * 3 / 2, 0); + if (!YUVGenerate(surfaceFormat, bufferIn, width, height, 0, 255)) + { + result.ResultSub(CResult::TEST_ERROR); + return result.Result(); + } + + while (deviceWrapper->AdapterNext()) + { + cl_int error; + // check if the test can be run on the adapter + if (CL_SUCCESS + != (error = deviceExistForCLTest(gPlatformIDdetected, adapterType, + deviceWrapper->Device(), result, + sharedHandle))) + { + return result.Result(); + } + + if (surfaceFormat != SURFACE_FORMAT_NV12 + && !SurfaceFormatCheck(adapterType, *deviceWrapper, surfaceFormat)) + { + std::string sharedHandleStr = + (sharedHandle == SHARED_HANDLE_ENABLED) ? "yes" : "no"; + std::string formatStr; + std::string adapterStr; + SurfaceFormatToString(surfaceFormat, formatStr); + AdapterToString(adapterType, adapterStr); + log_info( + "Skipping test case, image format is not supported by a device " + "(adapter type: %s, format: %s, shared handle: %s)\n", + adapterStr.c_str(), formatStr.c_str(), sharedHandleStr.c_str()); + return result.Result(); + } + + void *objectSharedHandle = 0; + std::auto_ptr surface; + if (!MediaSurfaceCreate( + adapterType, width, height, surfaceFormat, *deviceWrapper, + surface, (sharedHandle == SHARED_HANDLE_ENABLED) ? true : false, + &objectSharedHandle)) + { + log_error("Media surface creation failed for %i adapter\n", + deviceWrapper->AdapterIdx()); + result.ResultSub(CResult::TEST_ERROR); + return result.Result(); + } + + cl_context_properties contextProperties[] = { + CL_CONTEXT_PLATFORM, + (cl_context_properties)gPlatformIDdetected, + AdapterTypeToContextInfo(adapterType), + (cl_context_properties)deviceWrapper->Device(), + 0, + }; + + clContextWrapper ctx; + switch (functionCreate) + { + case CONTEXT_CREATE_DEFAULT: + ctx = clCreateContext(&contextProperties[0], 1, + &gDeviceIDdetected, NULL, NULL, &error); + break; + case CONTEXT_CREATE_FROM_TYPE: + ctx = clCreateContextFromType(&contextProperties[0], + gDeviceTypeSelected, NULL, NULL, + &error); + break; + default: + log_error("Unknown context creation function enum\n"); + result.ResultSub(CResult::TEST_ERROR); + return result.Result(); + break; + } + + if (error != CL_SUCCESS) + { + std::string functionName; + FunctionContextCreateToString(functionCreate, functionName); + log_error("%s failed: %s\n", functionName.c_str(), + IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + return result.Result(); + } + + if (!YUVSurfaceSet(surfaceFormat, surface, bufferIn, width, height)) + { + result.ResultSub(CResult::TEST_ERROR); + return result.Result(); + } + +#if defined(_WIN32) + cl_dx9_surface_info_khr surfaceInfo; + surfaceInfo.resource = + *(static_cast(surface.get())); + surfaceInfo.shared_handle = objectSharedHandle; +#else + void *surfaceInfo = 0; + return TEST_NOT_IMPLEMENTED; +#endif + + std::vector memObjList; + unsigned int planesNum = PlanesNum(surfaceFormat); + std::vector planesList(planesNum); + for (unsigned int planeIdx = 0; planeIdx < planesNum; ++planeIdx) + { + planesList[planeIdx] = clCreateFromDX9MediaSurfaceKHR( + ctx, CL_MEM_READ_WRITE, adapterType, &surfaceInfo, planeIdx, + &error); + if (error != CL_SUCCESS) + { + log_error( + "clCreateFromDX9MediaSurfaceKHR failed for plane %i: %s\n", + planeIdx, IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + return result.Result(); + } + memObjList.push_back(planesList[planeIdx]); + } + + clCommandQueueWrapper cmdQueue = clCreateCommandQueueWithProperties( + ctx, gDeviceIDdetected, 0, &error); + if (error != CL_SUCCESS) + { + log_error("Unable to create command queue: %s\n", + IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + return result.Result(); + } + + if (!ImageInfoVerify(adapterType, memObjList, width, height, surface, + objectSharedHandle)) + { + log_error("Image info verification failed\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + cl_event event; + error = clEnqueueAcquireDX9MediaSurfacesKHR( + cmdQueue, static_cast(memObjList.size()), + &memObjList.at(0), 0, NULL, &event); + if (error != CL_SUCCESS) + { + log_error("clEnqueueAcquireDX9MediaSurfacesKHR failed: %s\n", + IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + return result.Result(); + } + + cl_uint eventType = 0; + error = clGetEventInfo(event, CL_EVENT_COMMAND_TYPE, sizeof(eventType), + &eventType, NULL); + if (error != CL_SUCCESS) + { + log_error("clGetEventInfo failed: %s\n", IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + } + + if (eventType != CL_COMMAND_ACQUIRE_DX9_MEDIA_SURFACES_KHR) + { + log_error( + "Invalid event != CL_COMMAND_ACQUIRE_DX9_MEDIA_SURFACES_KHR\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + clReleaseEvent(event); + + size_t origin[3] = { 0, 0, 0 }; + size_t offset = 0; + size_t frameSize = width * height * 3 / 2; + std::vector out(frameSize, 0); + for (size_t i = 0; i < memObjList.size(); ++i) + { + size_t planeWidth = (i == 0) ? width : width / 2; + size_t planeHeight = (i == 0) ? height : height / 2; + size_t regionPlane[3] = { planeWidth, planeHeight, 1 }; + + error = + clEnqueueReadImage(cmdQueue, memObjList.at(i), CL_TRUE, origin, + regionPlane, 0, 0, &out.at(offset), 0, 0, 0); + if (error != CL_SUCCESS) + { + log_error("clEnqueueReadImage failed: %s\n", + IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + } + + offset += planeWidth * planeHeight; + } + + if (!YUVCompare(surfaceFormat, out, bufferIn, width, height)) + { + log_error("OCL object verification failed - clEnqueueReadImage\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + error = clEnqueueReleaseDX9MediaSurfacesKHR( + cmdQueue, static_cast(memObjList.size()), + &memObjList.at(0), 0, NULL, &event); + if (error != CL_SUCCESS) + { + log_error("clEnqueueReleaseDX9MediaSurfacesKHR failed: %s\n", + IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + } + + eventType = 0; + error = clGetEventInfo(event, CL_EVENT_COMMAND_TYPE, sizeof(eventType), + &eventType, NULL); + if (error != CL_SUCCESS) + { + log_error("clGetEventInfo failed: %s\n", IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + } + + if (eventType != CL_COMMAND_RELEASE_DX9_MEDIA_SURFACES_KHR) + { + log_error( + "Invalid event != CL_COMMAND_RELEASE_DX9_MEDIA_SURFACES_KHR\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + clReleaseEvent(event); + + // object verification + std::vector bufferOut(frameSize, 0); + if (!YUVSurfaceGet(surfaceFormat, surface, bufferOut, width, height)) + { + result.ResultSub(CResult::TEST_FAIL); + return result.Result(); + } + + if (!YUVCompare(surfaceFormat, bufferOut, bufferIn, width, height)) + { + log_error("Media surface is different than expected\n"); + result.ResultSub(CResult::TEST_FAIL); + return result.Result(); + } + } + + if (deviceWrapper->Status() != DEVICE_PASS) + { + std::string adapterName; + AdapterToString(adapterType, adapterName); + if (deviceWrapper->Status() == DEVICE_FAIL) + { + log_error("%s init failed\n", adapterName.c_str()); + result.ResultSub(CResult::TEST_FAIL); + } + else + { + log_error("%s init incomplete due to unsupported device\n", + adapterName.c_str()); + result.ResultSub(CResult::TEST_NOTSUPPORTED); + } + } + + return result.Result(); +} + +int test_context_create(cl_device_id deviceID, cl_context context, + cl_command_queue queue, int num_elements) +{ + const unsigned int WIDTH = 256; + const unsigned int HEIGHT = 256; + + std::vector adapterTypes; +#if defined(_WIN32) + adapterTypes.push_back(CL_ADAPTER_D3D9_KHR); + adapterTypes.push_back(CL_ADAPTER_D3D9EX_KHR); + adapterTypes.push_back(CL_ADAPTER_DXVA_KHR); +#endif + + std::vector contextFuncs; + contextFuncs.push_back(CONTEXT_CREATE_DEFAULT); + contextFuncs.push_back(CONTEXT_CREATE_FROM_TYPE); + + std::vector formats; + formats.push_back(SURFACE_FORMAT_NV12); + formats.push_back(SURFACE_FORMAT_YV12); + + std::vector sharedHandleTypes; + sharedHandleTypes.push_back(SHARED_HANDLE_DISABLED); +#if defined(_WIN32) + sharedHandleTypes.push_back(SHARED_HANDLE_ENABLED); +#endif + + CResult result; + for (size_t adapterTypeIdx = 0; adapterTypeIdx < adapterTypes.size(); + ++adapterTypeIdx) + { + // iteration through all create context functions + for (size_t contextFuncIdx = 0; contextFuncIdx < contextFuncs.size(); + ++contextFuncIdx) + { + // iteration through surface formats + for (size_t formatIdx = 0; formatIdx < formats.size(); ++formatIdx) + { + // shared handle enabled or disabled + for (size_t sharedHandleIdx = 0; + sharedHandleIdx < sharedHandleTypes.size(); + ++sharedHandleIdx) + { + if (adapterTypes[adapterTypeIdx] == CL_ADAPTER_D3D9_KHR + && sharedHandleTypes[sharedHandleIdx] + == SHARED_HANDLE_ENABLED) + continue; + + if (context_create( + deviceID, context, queue, num_elements, WIDTH, + HEIGHT, contextFuncs[contextFuncIdx], + adapterTypes[adapterTypeIdx], formats[formatIdx], + sharedHandleTypes[sharedHandleIdx]) + != 0) + { + std::string sharedHandle = + (sharedHandleTypes[sharedHandleIdx] + == SHARED_HANDLE_ENABLED) + ? "shared handle" + : "no shared handle"; + std::string formatStr; + std::string adapterTypeStr; + SurfaceFormatToString(formats[formatIdx], formatStr); + AdapterToString(adapterTypes[adapterTypeIdx], + adapterTypeStr); + + log_error("\nTest case - clCreateContext (%s, %s, %s) " + "failed\n\n", + adapterTypeStr.c_str(), formatStr.c_str(), + sharedHandle.c_str()); + result.ResultSub(CResult::TEST_FAIL); + } + } + } + } + } + + return result.Result(); +} diff --git a/test_conformance/extensions/cl_khr_dx9_media_sharing/test_functions_api.cpp b/test_conformance/extensions/cl_khr_dx9_media_sharing/test_functions_api.cpp new file mode 100644 index 00000000..ab92cb89 --- /dev/null +++ b/test_conformance/extensions/cl_khr_dx9_media_sharing/test_functions_api.cpp @@ -0,0 +1,781 @@ +// +// 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 "utils.h" + +int api_functions(cl_device_id deviceID, cl_context context, + cl_command_queue queue, int num_elements, + unsigned int iterationNum, unsigned int width, + unsigned int height, + cl_dx9_media_adapter_type_khr adapterType, + TSurfaceFormat surfaceFormat, TSharedHandleType sharedHandle) +{ + const unsigned int FRAME_NUM = 2; + const cl_uchar MAX_VALUE = 255 / 2; + CResult result; + + // create device + std::auto_ptr deviceWrapper; + if (!DeviceCreate(adapterType, deviceWrapper)) + { + result.ResultSub(CResult::TEST_ERROR); + return result.Result(); + } + + // generate input and expected data + std::vector> bufferRef1(FRAME_NUM); + std::vector> bufferRef2(FRAME_NUM); + std::vector> bufferRef3(FRAME_NUM); + size_t frameSize = width * height * 3 / 2; + cl_uchar step = MAX_VALUE / FRAME_NUM; + for (size_t i = 0; i < FRAME_NUM; ++i) + { + if (!YUVGenerate(surfaceFormat, bufferRef1[i], width, height, + static_cast(step * i), + static_cast(step * (i + 1))) + || !YUVGenerate(surfaceFormat, bufferRef2[i], width, height, + static_cast(step * i), + static_cast(step * (i + 1)), 0.2) + || !YUVGenerate(surfaceFormat, bufferRef3[i], width, height, + static_cast(step * i), + static_cast(step * (i + 1)), 0.4)) + { + result.ResultSub(CResult::TEST_ERROR); + return result.Result(); + } + } + + // iterates through all devices + while (deviceWrapper->AdapterNext()) + { + cl_int error; + // check if the test can be run on the adapter + if (CL_SUCCESS + != (error = deviceExistForCLTest(gPlatformIDdetected, adapterType, + deviceWrapper->Device(), result, + sharedHandle))) + { + return result.Result(); + } + + if (surfaceFormat != SURFACE_FORMAT_NV12 + && !SurfaceFormatCheck(adapterType, *deviceWrapper, surfaceFormat)) + { + std::string sharedHandleStr = + (sharedHandle == SHARED_HANDLE_ENABLED) ? "yes" : "no"; + std::string formatStr; + std::string adapterStr; + SurfaceFormatToString(surfaceFormat, formatStr); + AdapterToString(adapterType, adapterStr); + log_info( + "Skipping test case, image format is not supported by a device " + "(adapter type: %s, format: %s, shared handle: %s)\n", + adapterStr.c_str(), formatStr.c_str(), sharedHandleStr.c_str()); + return result.Result(); + } + + void *objectSharedHandle = 0; + std::auto_ptr surface; + + // create surface + if (!MediaSurfaceCreate( + adapterType, width, height, surfaceFormat, *deviceWrapper, + surface, (sharedHandle == SHARED_HANDLE_ENABLED) ? true : false, + &objectSharedHandle)) + { + log_error("Media surface creation failed for %i adapter\n", + deviceWrapper->AdapterIdx()); + result.ResultSub(CResult::TEST_ERROR); + return result.Result(); + } + + cl_context_properties contextProperties[] = { + CL_CONTEXT_PLATFORM, + (cl_context_properties)gPlatformIDdetected, + AdapterTypeToContextInfo(adapterType), + (cl_context_properties)deviceWrapper->Device(), + 0, + }; + + clContextWrapper ctx = clCreateContext( + &contextProperties[0], 1, &gDeviceIDdetected, NULL, NULL, &error); + if (error != CL_SUCCESS) + { + log_error("clCreateContext failed: %s\n", IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + return result.Result(); + } + +#if defined(_WIN32) + cl_dx9_surface_info_khr surfaceInfo; + surfaceInfo.resource = + *(static_cast(surface.get())); + surfaceInfo.shared_handle = objectSharedHandle; +#else + void *surfaceInfo = 0; + return TEST_NOT_IMPLEMENTED; +#endif + + std::vector memObjList; + unsigned int planesNum = PlanesNum(surfaceFormat); + std::vector planesList(planesNum); + for (unsigned int planeIdx = 0; planeIdx < planesNum; ++planeIdx) + { + planesList[planeIdx] = clCreateFromDX9MediaSurfaceKHR( + ctx, CL_MEM_READ_WRITE, adapterType, &surfaceInfo, planeIdx, + &error); + if (error != CL_SUCCESS) + { + log_error( + "clCreateFromDX9MediaSurfaceKHR failed for plane %i: %s\n", + planeIdx, IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + return result.Result(); + } + memObjList.push_back(planesList[planeIdx]); + } + + clCommandQueueWrapper cmdQueue = clCreateCommandQueueWithProperties( + ctx, gDeviceIDdetected, 0, &error); + if (error != CL_SUCCESS) + { + log_error("Unable to create command queue: %s\n", + IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + return result.Result(); + } + + if (!ImageInfoVerify(adapterType, memObjList, width, height, surface, + objectSharedHandle)) + { + log_error("Image info verification failed\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + for (size_t frameIdx = 0; frameIdx < iterationNum; ++frameIdx) + { + if (!YUVSurfaceSet(surfaceFormat, surface, + bufferRef1[frameIdx % FRAME_NUM], width, height)) + { + result.ResultSub(CResult::TEST_ERROR); + return result.Result(); + } + + error = clEnqueueAcquireDX9MediaSurfacesKHR( + cmdQueue, static_cast(memObjList.size()), + &memObjList[0], 0, 0, 0); + if (error != CL_SUCCESS) + { + log_error("clEnqueueAcquireDX9MediaSurfacesKHR failed: %s\n", + IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + return result.Result(); + } + + { // read operation + std::vector out(frameSize, 0); + size_t offset = 0; + size_t origin[3] = { 0, 0, 0 }; + + for (size_t i = 0; i < memObjList.size(); ++i) + { + size_t planeWidth = (i == 0) ? width : width / 2; + size_t planeHeight = (i == 0) ? height : height / 2; + size_t regionPlane[3] = { planeWidth, planeHeight, 1 }; + + error = clEnqueueReadImage(cmdQueue, memObjList[i], CL_TRUE, + origin, regionPlane, 0, 0, + &out[offset], 0, 0, 0); + if (error != CL_SUCCESS) + { + log_error("clEnqueueReadImage failed: %s\n", + IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + } + + offset += planeWidth * planeHeight; + } + + if (!YUVCompare(surfaceFormat, out, + bufferRef1[frameIdx % FRAME_NUM], width, + height)) + { + log_error("Frame idx: %i, OCL image is different then " + "shared OCL object: clEnqueueReadImage\n", + frameIdx); + result.ResultSub(CResult::TEST_FAIL); + } + } + + { // write operation + size_t offset = 0; + size_t origin[3] = { 0, 0, 0 }; + for (size_t i = 0; i < memObjList.size(); ++i) + { + size_t planeWidth = (i == 0) ? width : width / 2; + size_t planeHeight = (i == 0) ? height : height / 2; + size_t regionPlane[3] = { planeWidth, planeHeight, 1 }; + + error = clEnqueueWriteImage( + cmdQueue, memObjList[i], CL_TRUE, origin, regionPlane, + 0, 0, &bufferRef2[frameIdx % FRAME_NUM][offset], 0, 0, + 0); + if (error != CL_SUCCESS) + { + log_error("clEnqueueWriteImage failed: %s\n", + IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + } + + offset += planeWidth * planeHeight; + } + } + + { // read operation + std::vector out(frameSize, 0); + size_t offset = 0; + size_t origin[3] = { 0, 0, 0 }; + + for (size_t i = 0; i < memObjList.size(); ++i) + { + size_t planeWidth = (i == 0) ? width : width / 2; + size_t planeHeight = (i == 0) ? height : height / 2; + size_t regionPlane[3] = { planeWidth, planeHeight, 1 }; + + error = clEnqueueReadImage(cmdQueue, memObjList[i], CL_TRUE, + origin, regionPlane, 0, 0, + &out[offset], 0, 0, 0); + if (error != CL_SUCCESS) + { + log_error("clEnqueueReadImage failed: %s\n", + IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + } + + offset += planeWidth * planeHeight; + } + + if (!YUVCompare(surfaceFormat, out, + bufferRef2[frameIdx % FRAME_NUM], width, + height)) + { + log_error("Frame idx: %i, Shared OCL image verification " + "after clEnqueueWriteImage failed\n", + frameIdx); + result.ResultSub(CResult::TEST_FAIL); + } + } + + { // copy operation (shared OCL to OCL) + size_t offset = 0; + size_t origin[3] = { 0, 0, 0 }; + std::vector out(frameSize, 0); + for (size_t i = 0; i < memObjList.size(); ++i) + { + size_t planeWidth = (i == 0) ? width : width / 2; + size_t planeHeight = (i == 0) ? height : height / 2; + size_t regionPlane[3] = { planeWidth, planeHeight, 1 }; + + cl_image_format formatPlane; + formatPlane.image_channel_data_type = CL_UNORM_INT8; + formatPlane.image_channel_order = + (surfaceFormat == SURFACE_FORMAT_NV12 && i > 0) ? CL_RG + : CL_R; + + cl_image_desc imageDesc = { 0 }; + imageDesc.image_type = CL_MEM_OBJECT_IMAGE2D; + imageDesc.image_width = planeWidth; + imageDesc.image_height = planeHeight; + + clMemWrapper planeOCL = + clCreateImage(ctx, CL_MEM_READ_WRITE, &formatPlane, + &imageDesc, 0, &error); + if (error != CL_SUCCESS) + { + log_error("clCreateImage failed: %s\n", + IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + } + + error = clEnqueueCopyImage(cmdQueue, memObjList[i], + planeOCL, origin, origin, + regionPlane, 0, 0, 0); + if (error != CL_SUCCESS) + { + log_error("clEnqueueCopyImage failed: %s\n", + IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + } + + error = clEnqueueReadImage(cmdQueue, planeOCL, CL_TRUE, + origin, regionPlane, 0, 0, + &out[offset], 0, 0, 0); + if (error != CL_SUCCESS) + { + log_error("clEnqueueReadImage failed: %s\n", + IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + } + + offset += planeWidth * planeHeight; + } + + if (!YUVCompare(surfaceFormat, out, + bufferRef2[frameIdx % FRAME_NUM], width, + height)) + { + log_error( + "Frame idx: %i, OCL image verification after " + "clEnqueueCopyImage (from shared OCL to OCL) failed\n", + frameIdx); + result.ResultSub(CResult::TEST_FAIL); + } + } + + { // copy operation (OCL to shared OCL) + size_t offset = 0; + size_t origin[3] = { 0, 0, 0 }; + std::vector out(frameSize, 0); + for (size_t i = 0; i < memObjList.size(); ++i) + { + size_t planeWidth = (i == 0) ? width : width / 2; + size_t planeHeight = (i == 0) ? height : height / 2; + size_t regionPlane[3] = { planeWidth, planeHeight, 1 }; + size_t pitchSize = + ((surfaceFormat == SURFACE_FORMAT_NV12 && i > 0) + ? width + : planeWidth) + * sizeof(cl_uchar); + + cl_image_format formatPlane; + formatPlane.image_channel_data_type = CL_UNORM_INT8; + formatPlane.image_channel_order = + (surfaceFormat == SURFACE_FORMAT_NV12 && i > 0) ? CL_RG + : CL_R; + + cl_image_desc imageDesc = { 0 }; + imageDesc.image_type = CL_MEM_OBJECT_IMAGE2D; + imageDesc.image_width = planeWidth; + imageDesc.image_height = planeHeight; + imageDesc.image_row_pitch = pitchSize; + + clMemWrapper planeOCL = clCreateImage( + ctx, CL_MEM_COPY_HOST_PTR, &formatPlane, &imageDesc, + &bufferRef1[frameIdx % FRAME_NUM][offset], &error); + if (error != CL_SUCCESS) + { + log_error("clCreateImage failed: %s\n", + IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + } + + error = clEnqueueCopyImage(cmdQueue, planeOCL, + memObjList[i], origin, origin, + regionPlane, 0, 0, 0); + if (error != CL_SUCCESS) + { + log_error("clEnqueueCopyImage failed: %s\n", + IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + } + + error = clEnqueueReadImage(cmdQueue, memObjList[i], CL_TRUE, + origin, regionPlane, 0, 0, + &out[offset], 0, 0, 0); + if (error != CL_SUCCESS) + { + log_error("clEnqueueReadImage failed: %s\n", + IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + } + + offset += planeWidth * planeHeight; + } + + if (!YUVCompare(surfaceFormat, out, + bufferRef1[frameIdx % FRAME_NUM], width, + height)) + { + log_error( + "Frame idx: %i, OCL image verification after " + "clEnqueueCopyImage (from OCL to shared OCL) failed\n", + frameIdx); + result.ResultSub(CResult::TEST_FAIL); + } + } + + { // copy from image to buffer + size_t offset = 0; + size_t origin[3] = { 0, 0, 0 }; + size_t bufferSize = sizeof(cl_uchar) * frameSize; + clMemWrapper buffer = clCreateBuffer(ctx, CL_MEM_READ_WRITE, + bufferSize, NULL, &error); + if (error != CL_SUCCESS) + { + log_error("clCreateBuffer failed: %s\n", + IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + } + + for (size_t i = 0; i < memObjList.size(); ++i) + { + size_t planeWidth = (i == 0) ? width : width / 2; + size_t planeHeight = (i == 0) ? height : height / 2; + size_t regionPlane[3] = { planeWidth, planeHeight, 1 }; + + error = clEnqueueCopyImageToBuffer( + cmdQueue, memObjList[i], buffer, origin, regionPlane, + offset, 0, 0, 0); + if (error != CL_SUCCESS) + { + log_error("clEnqueueCopyImageToBuffer failed: %s\n", + IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + } + + offset += planeWidth * planeHeight * sizeof(cl_uchar); + } + + std::vector out(frameSize, 0); + error = clEnqueueReadBuffer(cmdQueue, buffer, CL_TRUE, 0, + bufferSize, &out[0], 0, NULL, NULL); + if (error != CL_SUCCESS) + { + log_error("Unable to read buffer"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (!YUVCompare(surfaceFormat, out, + bufferRef1[frameIdx % FRAME_NUM], width, + height)) + { + log_error("Frame idx: %i, OCL buffer verification after " + "clEnqueueCopyImageToBuffer (from shared OCL " + "image to OCL buffer) failed\n", + frameIdx); + result.ResultSub(CResult::TEST_FAIL); + } + } + + { // copy buffer to image + size_t bufferSize = sizeof(cl_uchar) * frameSize; + clMemWrapper buffer = clCreateBuffer( + ctx, CL_MEM_COPY_HOST_PTR, bufferSize, + &bufferRef2[frameIdx % FRAME_NUM][0], &error); + if (error != CL_SUCCESS) + { + log_error("clCreateBuffer failed: %s\n", + IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + } + + size_t offset = 0; + size_t origin[3] = { 0, 0, 0 }; + std::vector out(frameSize, 0); + for (size_t i = 0; i < memObjList.size(); ++i) + { + size_t planeWidth = (i == 0) ? width : width / 2; + size_t planeHeight = (i == 0) ? height : height / 2; + size_t regionPlane[3] = { planeWidth, planeHeight, 1 }; + + error = clEnqueueCopyBufferToImage( + cmdQueue, buffer, memObjList[i], offset, origin, + regionPlane, 0, 0, 0); + if (error != CL_SUCCESS) + { + log_error("clEnqueueCopyBufferToImage failed: %s\n", + IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + } + + error = clEnqueueReadImage(cmdQueue, memObjList[i], CL_TRUE, + origin, regionPlane, 0, 0, + &out[offset], 0, 0, 0); + if (error != CL_SUCCESS) + { + log_error("clEnqueueReadImage failed: %s\n", + IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + } + + offset += planeWidth * planeHeight * sizeof(cl_uchar); + } + + if (!YUVCompare(surfaceFormat, out, + bufferRef2[frameIdx % FRAME_NUM], width, + height)) + { + log_error("Frame idx: %i, OCL image verification after " + "clEnqueueCopyBufferToImage (from OCL buffer to " + "shared OCL image) failed\n", + frameIdx); + result.ResultSub(CResult::TEST_FAIL); + } + } + + { // map operation to read + size_t offset = 0; + size_t origin[3] = { 0, 0, 0 }; + std::vector out(frameSize, 0); + for (size_t i = 0; i < memObjList.size(); ++i) + { + size_t planeWidth = (i == 0) ? width : width / 2; + size_t planeHeight = (i == 0) ? height : height / 2; + size_t regionPlane[3] = { planeWidth, planeHeight, 1 }; + size_t pitchSize = + ((surfaceFormat == SURFACE_FORMAT_NV12 && i > 0) + ? width + : planeWidth); + + size_t rowPitch = 0; + size_t slicePitch = 0; + void *mapPtr = clEnqueueMapImage( + cmdQueue, memObjList[i], CL_TRUE, CL_MAP_READ, origin, + regionPlane, &rowPitch, &slicePitch, 0, 0, 0, &error); + if (error != CL_SUCCESS) + { + log_error("clEnqueueMapImage failed: %s\n", + IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + } + + for (size_t y = 0; y < planeHeight; ++y) + memcpy(&out[offset + y * pitchSize], + static_cast(mapPtr) + + y * rowPitch / sizeof(cl_uchar), + pitchSize * sizeof(cl_uchar)); + + error = clEnqueueUnmapMemObject(cmdQueue, memObjList[i], + mapPtr, 0, 0, 0); + if (error != CL_SUCCESS) + { + log_error("clEnqueueUnmapMemObject failed: %s\n", + IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + } + + offset += pitchSize * planeHeight; + } + + if (!YUVCompare(surfaceFormat, out, + bufferRef2[frameIdx % FRAME_NUM], width, + height)) + { + log_error("Frame idx: %i, Mapped shared OCL image is " + "different then expected\n", + frameIdx); + result.ResultSub(CResult::TEST_FAIL); + } + } + + { // map operation to write + size_t offset = 0; + size_t origin[3] = { 0, 0, 0 }; + for (size_t i = 0; i < memObjList.size(); ++i) + { + size_t planeWidth = (i == 0) ? width : width / 2; + size_t planeHeight = (i == 0) ? height : height / 2; + size_t regionPlane[3] = { planeWidth, planeHeight, 1 }; + size_t pitchSize = + ((surfaceFormat == SURFACE_FORMAT_NV12 && i > 0) + ? width + : planeWidth); + + size_t rowPitch = 0; + size_t slicePitch = 0; + void *mapPtr = clEnqueueMapImage( + cmdQueue, memObjList[i], CL_TRUE, CL_MAP_WRITE, origin, + regionPlane, &rowPitch, &slicePitch, 0, 0, 0, &error); + if (error != CL_SUCCESS) + { + log_error("clEnqueueMapImage failed: %s\n", + IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + } + + for (size_t y = 0; y < planeHeight; ++y) + memcpy(static_cast(mapPtr) + + y * rowPitch / sizeof(cl_uchar), + &bufferRef3[frameIdx % FRAME_NUM] + [offset + y * pitchSize], + pitchSize * sizeof(cl_uchar)); + + error = clEnqueueUnmapMemObject(cmdQueue, memObjList[i], + mapPtr, 0, 0, 0); + if (error != CL_SUCCESS) + { + log_error("clEnqueueUnmapMemObject failed: %s\n", + IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + } + + offset += pitchSize * planeHeight; + } + } + + error = clEnqueueReleaseDX9MediaSurfacesKHR( + cmdQueue, static_cast(memObjList.size()), + &memObjList[0], 0, 0, 0); + if (error != CL_SUCCESS) + { + log_error("clEnqueueReleaseDX9MediaSurfacesKHR failed: %s\n", + IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + } + + std::vector bufferOut(frameSize, 0); + if (!YUVSurfaceGet(surfaceFormat, surface, bufferOut, width, + height)) + { + result.ResultSub(CResult::TEST_FAIL); + return result.Result(); + } + + if (!YUVCompare(surfaceFormat, bufferOut, + bufferRef3[frameIdx % FRAME_NUM], width, height)) + { + log_error( + "Frame idx: %i, media surface is different than expected\n", + frameIdx); + result.ResultSub(CResult::TEST_FAIL); + } + } + } + + if (deviceWrapper->Status() != DEVICE_PASS) + { + std::string adapterName; + AdapterToString(adapterType, adapterName); + if (deviceWrapper->Status() == DEVICE_FAIL) + { + log_error("%s init failed\n", adapterName.c_str()); + result.ResultSub(CResult::TEST_FAIL); + } + else + { + log_error("%s init incomplete due to unsupported device\n", + adapterName.c_str()); + result.ResultSub(CResult::TEST_NOTSUPPORTED); + } + } + + return result.Result(); +} + +int test_api(cl_device_id deviceID, cl_context context, cl_command_queue queue, + int num_elements) +{ + CResult result; + +#if defined(_WIN32) + // D3D9 + if (api_functions(deviceID, context, queue, num_elements, 10, 256, 256, + CL_ADAPTER_D3D9_KHR, SURFACE_FORMAT_NV12, + SHARED_HANDLE_DISABLED) + != 0) + { + log_error("\nTest case (D3D9, NV12, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (api_functions(deviceID, context, queue, num_elements, 3, 512, 256, + CL_ADAPTER_D3D9_KHR, SURFACE_FORMAT_YV12, + SHARED_HANDLE_DISABLED) + != 0) + { + log_error("\nTest case (D3D9, YV12, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + // D3D9EX + if (api_functions(deviceID, context, queue, num_elements, 5, 256, 512, + CL_ADAPTER_D3D9EX_KHR, SURFACE_FORMAT_NV12, + SHARED_HANDLE_DISABLED) + != 0) + { + log_error("\nTest case (D3D9EX, NV12, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (api_functions(deviceID, context, queue, num_elements, 7, 512, 256, + CL_ADAPTER_D3D9EX_KHR, SURFACE_FORMAT_NV12, + SHARED_HANDLE_ENABLED) + != 0) + { + log_error("\nTest case (D3D9EX, NV12, shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (api_functions(deviceID, context, queue, num_elements, 10, 256, 256, + CL_ADAPTER_D3D9EX_KHR, SURFACE_FORMAT_YV12, + SHARED_HANDLE_DISABLED) + != 0) + { + log_error("\nTest case (D3D9EX, YV12, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (api_functions(deviceID, context, queue, num_elements, 15, 128, 128, + CL_ADAPTER_D3D9EX_KHR, SURFACE_FORMAT_YV12, + SHARED_HANDLE_ENABLED) + != 0) + { + log_error("\nTest case (D3D9EX, YV12, shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + // DXVA + if (api_functions(deviceID, context, queue, num_elements, 20, 128, 128, + CL_ADAPTER_DXVA_KHR, SURFACE_FORMAT_NV12, + SHARED_HANDLE_DISABLED) + != 0) + { + log_error("\nTest case (DXVA, NV12, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (api_functions(deviceID, context, queue, num_elements, 40, 64, 64, + CL_ADAPTER_DXVA_KHR, SURFACE_FORMAT_NV12, + SHARED_HANDLE_ENABLED) + != 0) + { + log_error("\nTest case (DXVA, NV12, shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (api_functions(deviceID, context, queue, num_elements, 5, 512, 512, + CL_ADAPTER_DXVA_KHR, SURFACE_FORMAT_YV12, + SHARED_HANDLE_DISABLED) + != 0) + { + log_error("\nTest case (DXVA, YV12, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (api_functions(deviceID, context, queue, num_elements, 2, 1024, 1024, + CL_ADAPTER_DXVA_KHR, SURFACE_FORMAT_YV12, + SHARED_HANDLE_ENABLED) + != 0) + { + log_error("\nTest case (DXVA, YV12, shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + +#else + return TEST_NOT_IMPLEMENTED; +#endif + + return result.Result(); +} diff --git a/test_conformance/extensions/cl_khr_dx9_media_sharing/test_functions_kernel.cpp b/test_conformance/extensions/cl_khr_dx9_media_sharing/test_functions_kernel.cpp new file mode 100644 index 00000000..a204440d --- /dev/null +++ b/test_conformance/extensions/cl_khr_dx9_media_sharing/test_functions_kernel.cpp @@ -0,0 +1,541 @@ +// +// 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 +#include + +#include "harness/errorHelpers.h" +#include "harness/kernelHelpers.h" + +#include "utils.h" + +int kernel_functions(cl_device_id deviceID, cl_context context, + cl_command_queue queue, int num_elements, + unsigned int iterationNum, unsigned int width, + unsigned int height, + cl_dx9_media_adapter_type_khr adapterType, + TSurfaceFormat surfaceFormat, + TSharedHandleType sharedHandle) +{ + const unsigned int FRAME_NUM = 2; + const cl_uchar MAX_VALUE = 255 / 2; + const std::string PROGRAM_STR = + "__kernel void TestFunction( read_only image2d_t planeIn, write_only " + "image2d_t planeOut, " NL " sampler_t " + "sampler, __global int *planeRes)" NL "{" NL + " int w = get_global_id(0);" NL " int h = get_global_id(1);" NL + " int width = get_image_width(planeIn);" NL + " int height = get_image_height(planeOut);" NL + " float4 color0 = read_imagef(planeIn, sampler, (int2)(w,h)) + " + "0.2f;" NL " float4 color1 = read_imagef(planeIn, sampler, " + "(float2)(w,h)) + 0.2f;" NL + " color0 = (color0 == color1) ? color0: (float4)(0.5, 0.5, 0.5, " + "0.5);" NL " write_imagef(planeOut, (int2)(w,h), color0);" NL + " if(w == 0 && h == 0)" NL " {" NL " planeRes[0] = width;" NL + " planeRes[1] = height;" NL " }" NL "}"; + + CResult result; + + std::auto_ptr deviceWrapper; + if (!DeviceCreate(adapterType, deviceWrapper)) + { + result.ResultSub(CResult::TEST_ERROR); + return result.Result(); + } + + std::vector> bufferIn(FRAME_NUM); + std::vector> bufferExp(FRAME_NUM); + size_t frameSize = width * height * 3 / 2; + cl_uchar step = MAX_VALUE / FRAME_NUM; + for (size_t i = 0; i < FRAME_NUM; ++i) + { + if (!YUVGenerate(surfaceFormat, bufferIn[i], width, height, + static_cast(step * i), + static_cast(step * (i + 1))) + || !YUVGenerate(surfaceFormat, bufferExp[i], width, height, + static_cast(step * i), + static_cast(step * (i + 1)), 0.2)) + { + result.ResultSub(CResult::TEST_ERROR); + return result.Result(); + } + } + + while (deviceWrapper->AdapterNext()) + { + cl_int error; + // check if the test can be run on the adapter + if (CL_SUCCESS + != (error = deviceExistForCLTest(gPlatformIDdetected, adapterType, + deviceWrapper->Device(), result, + sharedHandle))) + { + return result.Result(); + } + + if (surfaceFormat != SURFACE_FORMAT_NV12 + && !SurfaceFormatCheck(adapterType, *deviceWrapper, surfaceFormat)) + { + std::string sharedHandleStr = + (sharedHandle == SHARED_HANDLE_ENABLED) ? "yes" : "no"; + std::string formatStr; + std::string adapterStr; + SurfaceFormatToString(surfaceFormat, formatStr); + AdapterToString(adapterType, adapterStr); + log_info( + "Skipping test case, image format is not supported by a device " + "(adapter type: %s, format: %s, shared handle: %s)\n", + adapterStr.c_str(), formatStr.c_str(), sharedHandleStr.c_str()); + return result.Result(); + } + + void *objectSrcHandle = 0; + std::auto_ptr surfaceSrc; + if (!MediaSurfaceCreate(adapterType, width, height, surfaceFormat, + *deviceWrapper, surfaceSrc, + (sharedHandle == SHARED_HANDLE_ENABLED) ? true + : false, + &objectSrcHandle)) + { + log_error("Media surface creation failed for %i adapter\n", + deviceWrapper->AdapterIdx()); + result.ResultSub(CResult::TEST_ERROR); + return result.Result(); + } + + void *objectDstHandle = 0; + std::auto_ptr surfaceDst; + if (!MediaSurfaceCreate(adapterType, width, height, surfaceFormat, + *deviceWrapper, surfaceDst, + (sharedHandle == SHARED_HANDLE_ENABLED) ? true + : false, + &objectDstHandle)) + { + log_error("Media surface creation failed for %i adapter\n", + deviceWrapper->AdapterIdx()); + result.ResultSub(CResult::TEST_ERROR); + return result.Result(); + } + + cl_context_properties contextProperties[] = { + CL_CONTEXT_PLATFORM, + (cl_context_properties)gPlatformIDdetected, + AdapterTypeToContextInfo(adapterType), + (cl_context_properties)deviceWrapper->Device(), + 0, + }; + + clContextWrapper ctx = clCreateContext( + &contextProperties[0], 1, &gDeviceIDdetected, NULL, NULL, &error); + if (error != CL_SUCCESS) + { + log_error("clCreateContext failed: %s\n", IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + return result.Result(); + } + +#if defined(_WIN32) + cl_dx9_surface_info_khr surfaceInfoSrc; + surfaceInfoSrc.resource = + *(static_cast(surfaceSrc.get())); + surfaceInfoSrc.shared_handle = objectSrcHandle; + + cl_dx9_surface_info_khr surfaceInfoDst; + surfaceInfoDst.resource = + *(static_cast(surfaceDst.get())); + surfaceInfoDst.shared_handle = objectDstHandle; +#else + void *surfaceInfoSrc = 0; + void *surfaceInfoDst = 0; + return TEST_NOT_IMPLEMENTED; +#endif + + std::vector memObjSrcList; + std::vector memObjDstList; + unsigned int planesNum = PlanesNum(surfaceFormat); + std::vector planeSrcList(planesNum); + std::vector planeDstList(planesNum); + for (unsigned int planeIdx = 0; planeIdx < planesNum; ++planeIdx) + { + planeSrcList[planeIdx] = clCreateFromDX9MediaSurfaceKHR( + ctx, CL_MEM_READ_WRITE, adapterType, &surfaceInfoSrc, planeIdx, + &error); + if (error != CL_SUCCESS) + { + log_error( + "clCreateFromDX9MediaSurfaceKHR failed for plane %i: %s\n", + planeIdx, IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + return result.Result(); + } + memObjSrcList.push_back(planeSrcList[planeIdx]); + + planeDstList[planeIdx] = clCreateFromDX9MediaSurfaceKHR( + ctx, CL_MEM_READ_WRITE, adapterType, &surfaceInfoDst, planeIdx, + &error); + if (error != CL_SUCCESS) + { + log_error( + "clCreateFromDX9MediaSurfaceKHR failed for plane %i: %s\n", + planeIdx, IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + return result.Result(); + } + memObjDstList.push_back(planeDstList[planeIdx]); + } + + clCommandQueueWrapper cmdQueue = clCreateCommandQueueWithProperties( + ctx, gDeviceIDdetected, 0, &error); + if (error != CL_SUCCESS) + { + log_error("Unable to create command queue: %s\n", + IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + return result.Result(); + } + + if (!ImageInfoVerify(adapterType, memObjSrcList, width, height, + surfaceSrc, objectSrcHandle)) + { + log_error("Image info verification failed\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + for (size_t frameIdx = 0; frameIdx < iterationNum; ++frameIdx) + { + if (!YUVSurfaceSet(surfaceFormat, surfaceSrc, + bufferIn[frameIdx % FRAME_NUM], width, height)) + { + result.ResultSub(CResult::TEST_ERROR); + return result.Result(); + } + + error = clEnqueueAcquireDX9MediaSurfacesKHR( + cmdQueue, static_cast(memObjSrcList.size()), + &memObjSrcList[0], 0, 0, 0); + if (error != CL_SUCCESS) + { + log_error("clEnqueueAcquireDX9MediaSurfacesKHR failed: %s\n", + IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + return result.Result(); + } + + error = clEnqueueAcquireDX9MediaSurfacesKHR( + cmdQueue, static_cast(memObjDstList.size()), + &memObjDstList[0], 0, 0, 0); + if (error != CL_SUCCESS) + { + log_error("clEnqueueAcquireDX9MediaSurfacesKHR failed: %s\n", + IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + return result.Result(); + } + + clSamplerWrapper sampler = clCreateSampler( + ctx, CL_FALSE, CL_ADDRESS_NONE, CL_FILTER_NEAREST, &error); + if (error != CL_SUCCESS) + { + log_error("Unable to create sampler\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + clProgramWrapper program; + clKernelWrapper kernel; + const char *progPtr = PROGRAM_STR.c_str(); + if (create_single_kernel_helper(ctx, &program, &kernel, 1, + (const char **)&progPtr, + "TestFunction")) + result.ResultSub(CResult::TEST_FAIL); + + size_t bufferSize = sizeof(cl_int) * 2; + clMemWrapper imageRes = clCreateBuffer(ctx, CL_MEM_READ_WRITE, + bufferSize, NULL, &error); + if (error != CL_SUCCESS) + { + log_error("clCreateBuffer failed: %s\n", + IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + } + + size_t offset = 0; + size_t origin[3] = { 0, 0, 0 }; + std::vector out(frameSize, 0); + for (size_t i = 0; i < memObjSrcList.size(); ++i) + { + size_t planeWidth = (i == 0) ? width : width / 2; + size_t planeHeight = (i == 0) ? height : height / 2; + size_t regionPlane[3] = { planeWidth, planeHeight, 1 }; + size_t threads[2] = { planeWidth, planeHeight }; + + error = clSetKernelArg(kernel, 0, sizeof(memObjSrcList[i]), + &memObjSrcList[i]); + if (error != CL_SUCCESS) + { + log_error("Unable to set kernel arguments"); + result.ResultSub(CResult::TEST_FAIL); + } + + error = clSetKernelArg(kernel, 1, sizeof(memObjDstList[i]), + &memObjDstList[i]); + if (error != CL_SUCCESS) + { + log_error("Unable to set kernel arguments"); + result.ResultSub(CResult::TEST_FAIL); + } + + error = clSetKernelArg(kernel, 2, sizeof(sampler), &sampler); + if (error != CL_SUCCESS) + { + log_error("Unable to set kernel arguments"); + result.ResultSub(CResult::TEST_FAIL); + } + + error = clSetKernelArg(kernel, 3, sizeof(imageRes), &imageRes); + if (error != CL_SUCCESS) + { + log_error("Unable to set kernel arguments"); + result.ResultSub(CResult::TEST_FAIL); + } + + size_t localThreads[2]; + error = get_max_common_2D_work_group_size(ctx, kernel, threads, + localThreads); + if (error != CL_SUCCESS) + { + log_error("Unable to get work group size to use"); + result.ResultSub(CResult::TEST_FAIL); + } + + error = + clEnqueueNDRangeKernel(cmdQueue, kernel, 2, NULL, threads, + localThreads, 0, NULL, NULL); + if (error != CL_SUCCESS) + { + log_error("Unable to execute test kernel"); + result.ResultSub(CResult::TEST_FAIL); + } + + std::vector imageResOut(2, 0); + error = clEnqueueReadBuffer(cmdQueue, imageRes, CL_TRUE, 0, + bufferSize, &imageResOut[0], 0, + NULL, NULL); + if (error != CL_SUCCESS) + { + log_error("Unable to read buffer"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (imageResOut[0] != planeWidth) + { + log_error("Invalid width value, test = %i, expected = %i\n", + imageResOut[0], planeWidth); + result.ResultSub(CResult::TEST_FAIL); + } + + if (imageResOut[1] != planeHeight) + { + log_error( + "Invalid height value, test = %i, expected = %i\n", + imageResOut[1], planeHeight); + result.ResultSub(CResult::TEST_FAIL); + } + + error = clEnqueueReadImage(cmdQueue, memObjDstList[i], CL_TRUE, + origin, regionPlane, 0, 0, + &out[offset], 0, 0, 0); + if (error != CL_SUCCESS) + { + log_error("clEnqueueReadImage failed: %s\n", + IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + } + + offset += planeWidth * planeHeight; + } + + if (!YUVCompare(surfaceFormat, out, bufferExp[frameIdx % FRAME_NUM], + width, height)) + { + log_error( + "Frame idx: %i, OCL objects are different than expected\n", + frameIdx); + result.ResultSub(CResult::TEST_FAIL); + } + + error = clEnqueueReleaseDX9MediaSurfacesKHR( + cmdQueue, static_cast(memObjSrcList.size()), + &memObjSrcList[0], 0, 0, 0); + if (error != CL_SUCCESS) + { + log_error("clEnqueueReleaseDX9MediaSurfacesKHR failed: %s\n", + IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + } + + error = clEnqueueReleaseDX9MediaSurfacesKHR( + cmdQueue, static_cast(memObjDstList.size()), + &memObjDstList[0], 0, 0, 0); + if (error != CL_SUCCESS) + { + log_error("clEnqueueReleaseDX9MediaSurfacesKHR failed: %s\n", + IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + } + + std::vector bufferOut(frameSize, 0); + if (!YUVSurfaceGet(surfaceFormat, surfaceDst, bufferOut, width, + height)) + { + result.ResultSub(CResult::TEST_FAIL); + return result.Result(); + } + + if (!YUVCompare(surfaceFormat, bufferOut, + bufferExp[frameIdx % FRAME_NUM], width, height)) + { + log_error( + "Frame idx: %i, media surface is different than expected\n", + frameIdx); + result.ResultSub(CResult::TEST_FAIL); + } + } + } + + if (deviceWrapper->Status() != DEVICE_PASS) + { + std::string adapterName; + AdapterToString(adapterType, adapterName); + if (deviceWrapper->Status() == DEVICE_FAIL) + { + log_error("%s init failed\n", adapterName.c_str()); + result.ResultSub(CResult::TEST_FAIL); + } + else + { + log_error("%s init incomplete due to unsupported device\n", + adapterName.c_str()); + result.ResultSub(CResult::TEST_NOTSUPPORTED); + } + } + + return result.Result(); +} + +int test_kernel(cl_device_id deviceID, cl_context context, + cl_command_queue queue, int num_elements) +{ + CResult result; + +#if defined(_WIN32) + // D3D9 + if (kernel_functions(deviceID, context, queue, num_elements, 10, 256, 256, + CL_ADAPTER_D3D9_KHR, SURFACE_FORMAT_NV12, + SHARED_HANDLE_DISABLED) + != 0) + { + log_error("\nTest case (D3D9, NV12, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (kernel_functions(deviceID, context, queue, num_elements, 3, 256, 256, + CL_ADAPTER_D3D9_KHR, SURFACE_FORMAT_YV12, + SHARED_HANDLE_DISABLED) + != 0) + { + log_error("\nTest case (D3D9, YV12, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + // D3D9EX + if (kernel_functions(deviceID, context, queue, num_elements, 5, 256, 512, + CL_ADAPTER_D3D9EX_KHR, SURFACE_FORMAT_NV12, + SHARED_HANDLE_DISABLED) + != 0) + { + log_error("\nTest case (D3D9EX, NV12, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (kernel_functions(deviceID, context, queue, num_elements, 7, 512, 256, + CL_ADAPTER_D3D9EX_KHR, SURFACE_FORMAT_NV12, + SHARED_HANDLE_ENABLED) + != 0) + { + log_error("\nTest case (D3D9EX, NV12, shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (kernel_functions(deviceID, context, queue, num_elements, 10, 256, 256, + CL_ADAPTER_D3D9EX_KHR, SURFACE_FORMAT_YV12, + SHARED_HANDLE_DISABLED) + != 0) + { + log_error("\nTest case (D3D9EX, YV12, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (kernel_functions(deviceID, context, queue, num_elements, 15, 128, 128, + CL_ADAPTER_D3D9EX_KHR, SURFACE_FORMAT_YV12, + SHARED_HANDLE_ENABLED) + != 0) + { + log_error("\nTest case (D3D9EX, YV12, shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + // DXVA + if (kernel_functions(deviceID, context, queue, num_elements, 20, 128, 128, + CL_ADAPTER_DXVA_KHR, SURFACE_FORMAT_NV12, + SHARED_HANDLE_DISABLED) + != 0) + { + log_error("\nTest case (DXVA, NV12, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (kernel_functions(deviceID, context, queue, num_elements, 40, 64, 64, + CL_ADAPTER_DXVA_KHR, SURFACE_FORMAT_NV12, + SHARED_HANDLE_ENABLED) + != 0) + { + log_error("\nTest case (DXVA, NV12, shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (kernel_functions(deviceID, context, queue, num_elements, 5, 512, 512, + CL_ADAPTER_DXVA_KHR, SURFACE_FORMAT_YV12, + SHARED_HANDLE_DISABLED) + != 0) + { + log_error("\nTest case (DXVA, YV12, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (kernel_functions(deviceID, context, queue, num_elements, 2, 1024, 1024, + CL_ADAPTER_DXVA_KHR, SURFACE_FORMAT_YV12, + SHARED_HANDLE_ENABLED) + != 0) + { + log_error("\nTest case (DXVA, YV12, shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + +#else + return TEST_NOT_IMPLEMENTED; +#endif + + return result.Result(); +} diff --git a/test_conformance/extensions/cl_khr_dx9_media_sharing/test_get_device_ids.cpp b/test_conformance/extensions/cl_khr_dx9_media_sharing/test_get_device_ids.cpp new file mode 100644 index 00000000..613a602c --- /dev/null +++ b/test_conformance/extensions/cl_khr_dx9_media_sharing/test_get_device_ids.cpp @@ -0,0 +1,220 @@ +// +// 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 "utils.h" + +int get_device_ids(cl_device_id deviceID, cl_context context, + cl_command_queue queue, int num_elements, + cl_dx9_media_adapter_type_khr adapterType) +{ + CResult result; + + std::auto_ptr deviceWrapper; + if (!DeviceCreate(adapterType, deviceWrapper)) + { + result.ResultSub(CResult::TEST_ERROR); + return result.Result(); + } + + cl_uint devicesExpectedNum = 0; + cl_int error = clGetDeviceIDs(gPlatformIDdetected, CL_DEVICE_TYPE_ALL, 0, 0, + &devicesExpectedNum); + if (error != CL_SUCCESS || devicesExpectedNum < 1) + { + log_error("clGetDeviceIDs failed: %s\n", IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + return result.Result(); + } + + std::vector devicesExpected(devicesExpectedNum); + error = clGetDeviceIDs(gPlatformIDdetected, CL_DEVICE_TYPE_ALL, + devicesExpectedNum, &devicesExpected[0], 0); + if (error != CL_SUCCESS) + { + log_error("clGetDeviceIDs failed: %s\n", IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + return result.Result(); + } + + while (deviceWrapper->AdapterNext()) + { + std::vector mediaAdapterTypes; + mediaAdapterTypes.push_back(adapterType); + + std::vector mediaDevices; + mediaDevices.push_back(deviceWrapper->Device()); + + // check if the test can be run on the adapter + if (CL_SUCCESS + != (error = deviceExistForCLTest(gPlatformIDdetected, adapterType, + deviceWrapper->Device(), result))) + { + return result.Result(); + } + + cl_uint devicesAllNum = 0; + error = clGetDeviceIDsFromDX9MediaAdapterKHR( + gPlatformIDdetected, 1, &mediaAdapterTypes[0], &mediaDevices[0], + CL_ALL_DEVICES_FOR_DX9_MEDIA_ADAPTER_KHR, 0, 0, &devicesAllNum); + if (error != CL_SUCCESS && error != CL_DEVICE_NOT_FOUND) + { + log_error("clGetDeviceIDsFromDX9MediaAdapterKHR failed: %s\n", + IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + return result.Result(); + } + + std::vector devicesAll; + if (devicesAllNum > 0) + { + devicesAll.resize(devicesAllNum); + error = clGetDeviceIDsFromDX9MediaAdapterKHR( + gPlatformIDdetected, 1, &mediaAdapterTypes[0], &mediaDevices[0], + CL_ALL_DEVICES_FOR_DX9_MEDIA_ADAPTER_KHR, devicesAllNum, + &devicesAll[0], 0); + if (error != CL_SUCCESS) + { + log_error("clGetDeviceIDsFromDX9MediaAdapterKHR failed: %s\n", + IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + return result.Result(); + } + } + + cl_uint devicesPreferredNum = 0; + error = clGetDeviceIDsFromDX9MediaAdapterKHR( + gPlatformIDdetected, 1, &mediaAdapterTypes[0], &mediaDevices[0], + CL_PREFERRED_DEVICES_FOR_DX9_MEDIA_ADAPTER_KHR, 0, 0, + &devicesPreferredNum); + if (error != CL_SUCCESS && error != CL_DEVICE_NOT_FOUND) + { + log_error("clGetDeviceIDsFromDX9MediaAdapterKHR failed: %s\n", + IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + return result.Result(); + } + + std::vector devicesPreferred; + if (devicesPreferredNum > 0) + { + devicesPreferred.resize(devicesPreferredNum); + error = clGetDeviceIDsFromDX9MediaAdapterKHR( + gPlatformIDdetected, 1, &mediaAdapterTypes[0], &mediaDevices[0], + CL_PREFERRED_DEVICES_FOR_DX9_MEDIA_ADAPTER_KHR, + devicesPreferredNum, &devicesPreferred[0], 0); + if (error != CL_SUCCESS) + { + log_error("clGetDeviceIDsFromDX9MediaAdapterKHR failed: %s\n", + IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + return result.Result(); + } + } + + if (devicesAllNum < devicesPreferredNum) + { + log_error("Invalid number of preferred devices. It should be a " + "subset of all devices\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + for (cl_uint i = 0; i < devicesPreferredNum; ++i) + { + cl_uint j = 0; + for (; j < devicesAllNum; ++j) + { + if (devicesPreferred[i] == devicesAll[j]) break; + } + + if (j == devicesAllNum) + { + log_error("Preferred device is not a subset of all devices\n"); + result.ResultSub(CResult::TEST_FAIL); + } + } + + for (cl_uint i = 0; i < devicesAllNum; ++i) + { + cl_uint j = 0; + for (; j < devicesExpectedNum; ++j) + { + if (devicesAll[i] == devicesExpected[j]) break; + } + + if (j == devicesExpectedNum) + { + log_error("CL_ALL_DEVICES_FOR_MEDIA_ADAPTER_KHR should be a " + "subset of all devices for selected platform\n"); + result.ResultSub(CResult::TEST_FAIL); + } + } + } + + if (deviceWrapper->Status() != DEVICE_PASS) + { + std::string adapterName; + AdapterToString(adapterType, adapterName); + if (deviceWrapper->Status() == DEVICE_FAIL) + { + log_error("%s init failed\n", adapterName.c_str()); + result.ResultSub(CResult::TEST_FAIL); + } + else + { + log_error("%s init incomplete due to unsupported device\n", + adapterName.c_str()); + result.ResultSub(CResult::TEST_NOTSUPPORTED); + } + } + + return result.Result(); +} + +int test_get_device_ids(cl_device_id deviceID, cl_context context, + cl_command_queue queue, int num_elements) +{ + CResult result; + +#if defined(_WIN32) + if (get_device_ids(deviceID, context, queue, num_elements, + CL_ADAPTER_D3D9_KHR) + != 0) + { + log_error("\nTest case (D3D9) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (get_device_ids(deviceID, context, queue, num_elements, + CL_ADAPTER_D3D9EX_KHR) + != 0) + { + log_error("\nTest case (D3D9EX) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (get_device_ids(deviceID, context, queue, num_elements, + CL_ADAPTER_DXVA_KHR) + != 0) + { + log_error("\nTest case (DXVA) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + +#else + return TEST_NOT_IMPLEMENTED; +#endif + + return result.Result(); +} diff --git a/test_conformance/extensions/cl_khr_dx9_media_sharing/test_interop_sync.cpp b/test_conformance/extensions/cl_khr_dx9_media_sharing/test_interop_sync.cpp new file mode 100644 index 00000000..fbc616e2 --- /dev/null +++ b/test_conformance/extensions/cl_khr_dx9_media_sharing/test_interop_sync.cpp @@ -0,0 +1,419 @@ +// +// 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 "utils.h" + +int interop_user_sync(cl_device_id deviceID, cl_context context, + cl_command_queue queue, int num_elements, + unsigned int width, unsigned int height, + TContextFuncType functionCreate, + cl_dx9_media_adapter_type_khr adapterType, + TSurfaceFormat surfaceFormat, + TSharedHandleType sharedHandle, cl_bool userSync) +{ + CResult result; + + // create device + std::auto_ptr deviceWrapper; + if (!DeviceCreate(adapterType, deviceWrapper)) + { + result.ResultSub(CResult::TEST_ERROR); + return result.Result(); + } + + // generate input data + std::vector bufferIn(width * height * 3 / 2, 0); + if (!YUVGenerate(surfaceFormat, bufferIn, width, height, 0, 255)) + { + result.ResultSub(CResult::TEST_ERROR); + return result.Result(); + } + + while (deviceWrapper->AdapterNext()) + { + cl_int error; + // check if the test can be run on the adapter + if (CL_SUCCESS + != (error = deviceExistForCLTest(gPlatformIDdetected, adapterType, + deviceWrapper->Device(), result, + sharedHandle))) + { + return result.Result(); + } + + if (surfaceFormat != SURFACE_FORMAT_NV12 + && !SurfaceFormatCheck(adapterType, *deviceWrapper, surfaceFormat)) + { + std::string sharedHandleStr = + (sharedHandle == SHARED_HANDLE_ENABLED) ? "yes" : "no"; + std::string syncStr = (userSync == CL_TRUE) ? "yes" : "no"; + std::string formatStr; + std::string adapterStr; + SurfaceFormatToString(surfaceFormat, formatStr); + AdapterToString(adapterType, adapterStr); + log_info("Skipping test case, image format is not supported by a " + "device (adapter type: %s, format: %s, shared handle: %s, " + "user sync: %s)\n", + adapterStr.c_str(), formatStr.c_str(), + sharedHandleStr.c_str(), syncStr.c_str()); + return result.Result(); + } + + void *objectSharedHandle = 0; + std::auto_ptr surface; + if (!MediaSurfaceCreate( + adapterType, width, height, surfaceFormat, *deviceWrapper, + surface, (sharedHandle == SHARED_HANDLE_ENABLED) ? true : false, + &objectSharedHandle)) + { + log_error("Media surface creation failed for %i adapter\n", + deviceWrapper->AdapterIdx()); + result.ResultSub(CResult::TEST_ERROR); + return result.Result(); + } + + cl_context_properties contextProperties[] = { + CL_CONTEXT_PLATFORM, + (cl_context_properties)gPlatformIDdetected, + AdapterTypeToContextInfo(adapterType), + (cl_context_properties)deviceWrapper->Device(), + CL_CONTEXT_INTEROP_USER_SYNC, + userSync, + 0, + }; + + + clContextWrapper ctx; + switch (functionCreate) + { + case CONTEXT_CREATE_DEFAULT: + ctx = clCreateContext(&contextProperties[0], 1, + &gDeviceIDdetected, NULL, NULL, &error); + break; + case CONTEXT_CREATE_FROM_TYPE: + ctx = clCreateContextFromType(&contextProperties[0], + gDeviceTypeSelected, NULL, NULL, + &error); + break; + default: + log_error("Unknown context creation function enum\n"); + result.ResultSub(CResult::TEST_ERROR); + return result.Result(); + break; + } + + if (error != CL_SUCCESS) + { + std::string functionName; + FunctionContextCreateToString(functionCreate, functionName); + log_error("%s failed: %s\n", functionName.c_str(), + IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + return result.Result(); + } + + if (!YUVSurfaceSet(surfaceFormat, surface, bufferIn, width, height)) + { + result.ResultSub(CResult::TEST_ERROR); + return result.Result(); + } + +#if defined(_WIN32) + cl_dx9_surface_info_khr surfaceInfo; + surfaceInfo.resource = + *(static_cast(surface.get())); + surfaceInfo.shared_handle = objectSharedHandle; +#else + void *surfaceInfo = 0; + return TEST_NOT_IMPLEMENTED; +#endif + + std::vector memObjList; + unsigned int planesNum = PlanesNum(surfaceFormat); + std::vector planesList(planesNum); + for (unsigned int planeIdx = 0; planeIdx < planesNum; ++planeIdx) + { + planesList[planeIdx] = clCreateFromDX9MediaSurfaceKHR( + ctx, CL_MEM_READ_WRITE, adapterType, &surfaceInfo, planeIdx, + &error); + if (error != CL_SUCCESS) + { + log_error( + "clCreateFromDX9MediaSurfaceKHR failed for plane %i: %s\n", + planeIdx, IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + return result.Result(); + } + memObjList.push_back(planesList[planeIdx]); + } + + clCommandQueueWrapper cmdQueue = clCreateCommandQueueWithProperties( + ctx, gDeviceIDdetected, 0, &error); + if (error != CL_SUCCESS) + { + log_error("Unable to create command queue: %s\n", + IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + return result.Result(); + } + + if (!ImageInfoVerify(adapterType, memObjList, width, height, surface, + objectSharedHandle)) + { + log_error("Image info verification failed\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (userSync == CL_TRUE) + { +#if defined(_WIN32) + IDirect3DQuery9 *eventQuery = NULL; + switch (adapterType) + { + case CL_ADAPTER_D3D9_KHR: { + LPDIRECT3DDEVICE9 device = + (LPDIRECT3DDEVICE9)deviceWrapper->Device(); + device->CreateQuery(D3DQUERYTYPE_EVENT, &eventQuery); + eventQuery->Issue(D3DISSUE_END); + + while (S_FALSE + == eventQuery->GetData(NULL, 0, D3DGETDATA_FLUSH)) + ; + } + break; + case CL_ADAPTER_D3D9EX_KHR: { + LPDIRECT3DDEVICE9EX device = + (LPDIRECT3DDEVICE9EX)deviceWrapper->Device(); + device->CreateQuery(D3DQUERYTYPE_EVENT, &eventQuery); + eventQuery->Issue(D3DISSUE_END); + + while (S_FALSE + == eventQuery->GetData(NULL, 0, D3DGETDATA_FLUSH)) + ; + } + break; + case CL_ADAPTER_DXVA_KHR: { + CDXVAWrapper *DXVADevice = + dynamic_cast(&(*deviceWrapper)); + LPDIRECT3DDEVICE9EX device = + (LPDIRECT3DDEVICE9EX)(DXVADevice->D3D9()).Device(); + device->CreateQuery(D3DQUERYTYPE_EVENT, &eventQuery); + eventQuery->Issue(D3DISSUE_END); + + while (S_FALSE + == eventQuery->GetData(NULL, 0, D3DGETDATA_FLUSH)) + ; + } + break; + default: + log_error("Unknown adapter type\n"); + return false; + break; + } + if (eventQuery) + { + eventQuery->Release(); + } +#else + return TEST_NOT_IMPLEMENTED; +#endif + } + + error = clEnqueueAcquireDX9MediaSurfacesKHR( + cmdQueue, static_cast(memObjList.size()), + &memObjList.at(0), 0, 0, 0); + if (error != CL_SUCCESS) + { + log_error("clEnqueueAcquireDX9MediaSurfacesKHR failed: %s\n", + IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + return result.Result(); + } + + size_t origin[3] = { 0, 0, 0 }; + size_t offset = 0; + size_t frameSize = width * height * 3 / 2; + std::vector out(frameSize, 0); + for (size_t i = 0; i < memObjList.size(); ++i) + { + size_t planeWidth = (i == 0) ? width : width / 2; + size_t planeHeight = (i == 0) ? height : height / 2; + size_t regionPlane[3] = { planeWidth, planeHeight, 1 }; + + error = + clEnqueueReadImage(cmdQueue, memObjList.at(i), CL_TRUE, origin, + regionPlane, 0, 0, &out.at(offset), 0, 0, 0); + if (error != CL_SUCCESS) + { + log_error("clEnqueueReadImage failed: %s\n", + IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + } + + offset += planeWidth * planeHeight; + } + + if (!YUVCompare(surfaceFormat, out, bufferIn, width, height)) + { + log_error("OCL object verification failed - clEnqueueReadImage\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + error = clEnqueueReleaseDX9MediaSurfacesKHR( + cmdQueue, static_cast(memObjList.size()), + &memObjList.at(0), 0, 0, 0); + if (error != CL_SUCCESS) + { + log_error("clEnqueueReleaseDX9MediaSurfacesKHR failed: %s\n", + IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + } + + if (userSync == CL_TRUE) + { + error = clFinish(cmdQueue); + if (error != CL_SUCCESS) + { + log_error("clFinish failed: %s\n", IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + } + } + + // shared object verification + std::vector bufferOut(frameSize, 0); + if (!YUVSurfaceGet(surfaceFormat, surface, bufferOut, width, height)) + { + result.ResultSub(CResult::TEST_FAIL); + return result.Result(); + } + + if (!YUVCompare(surfaceFormat, bufferOut, bufferIn, width, height)) + { + log_error("Media surface is different than expected\n"); + result.ResultSub(CResult::TEST_FAIL); + } + } + + if (deviceWrapper->Status() != DEVICE_PASS) + { + std::string adapterName; + AdapterToString(adapterType, adapterName); + + if (deviceWrapper->Status() == DEVICE_FAIL) + { + log_error("%s init failed\n", adapterName.c_str()); + result.ResultSub(CResult::TEST_FAIL); + } + else + { + log_error("%s init incomplete due to unsupported device\n", + adapterName.c_str()); + result.ResultSub(CResult::TEST_NOTSUPPORTED); + } + } + + return result.Result(); +} + +int test_interop_user_sync(cl_device_id deviceID, cl_context context, + cl_command_queue queue, int num_elements) +{ + const unsigned int WIDTH = 256; + const unsigned int HEIGHT = 256; + + std::vector adapters; +#if defined(_WIN32) + adapters.push_back(CL_ADAPTER_D3D9_KHR); + adapters.push_back(CL_ADAPTER_D3D9EX_KHR); + adapters.push_back(CL_ADAPTER_DXVA_KHR); +#else + return TEST_NOT_IMPLEMENTED; +#endif + + std::vector contextFuncs; + contextFuncs.push_back(CONTEXT_CREATE_DEFAULT); + contextFuncs.push_back(CONTEXT_CREATE_FROM_TYPE); + + std::vector formats; + formats.push_back(SURFACE_FORMAT_NV12); + formats.push_back(SURFACE_FORMAT_YV12); + + std::vector sharedHandleTypes; + sharedHandleTypes.push_back(SHARED_HANDLE_DISABLED); + sharedHandleTypes.push_back(SHARED_HANDLE_ENABLED); + + std::vector sync; + sync.push_back(CL_FALSE); + sync.push_back(CL_TRUE); + + CResult result; + for (size_t adapterIdx = 0; adapterIdx < adapters.size(); ++adapterIdx) + { + // iteration through all create context functions + for (size_t contextFuncIdx = 0; contextFuncIdx < contextFuncs.size(); + ++contextFuncIdx) + { + // iteration through YUV formats + for (size_t formatIdx = 0; formatIdx < formats.size(); ++formatIdx) + { + // shared handle enabled or disabled + for (size_t sharedHandleIdx = 0; + sharedHandleIdx < sharedHandleTypes.size(); + ++sharedHandleIdx) + { + // user sync interop disabled or enabled + for (size_t syncIdx = 0; syncIdx < sync.size(); ++syncIdx) + { + if (adapters[adapterIdx] == CL_ADAPTER_D3D9_KHR + && sharedHandleTypes[sharedHandleIdx] + == SHARED_HANDLE_ENABLED) + continue; + + if (interop_user_sync( + deviceID, context, queue, num_elements, WIDTH, + HEIGHT, contextFuncs[contextFuncIdx], + adapters[adapterIdx], formats[formatIdx], + sharedHandleTypes[sharedHandleIdx], + sync[syncIdx]) + != 0) + { + std::string syncStr = (sync[syncIdx] == CL_TRUE) + ? "user sync enabled" + : "user sync disabled"; + std::string sharedHandle = + (sharedHandleTypes[sharedHandleIdx] + == SHARED_HANDLE_ENABLED) + ? "shared handle" + : "no shared handle"; + std::string adapterStr; + std::string formatStr; + SurfaceFormatToString(formats[formatIdx], + formatStr); + AdapterToString(adapters[adapterIdx], adapterStr); + + log_error("\nTest case - clCreateContext (%s, %s, " + "%s, %s) failed\n\n", + adapterStr.c_str(), formatStr.c_str(), + sharedHandle.c_str(), syncStr.c_str()); + result.ResultSub(CResult::TEST_FAIL); + } + } + } + } + } + } + + return result.Result(); +} diff --git a/test_conformance/extensions/cl_khr_dx9_media_sharing/test_memory_access.cpp b/test_conformance/extensions/cl_khr_dx9_media_sharing/test_memory_access.cpp new file mode 100644 index 00000000..1e4e2c4e --- /dev/null +++ b/test_conformance/extensions/cl_khr_dx9_media_sharing/test_memory_access.cpp @@ -0,0 +1,549 @@ +// +// 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 "utils.h" + +int memory_access(cl_device_id deviceID, cl_context context, + cl_command_queue queue, int num_elements, unsigned int width, + unsigned int height, + cl_dx9_media_adapter_type_khr adapterType, + TSurfaceFormat surfaceFormat, TSharedHandleType sharedHandle) +{ + CResult result; + + std::auto_ptr deviceWrapper; + // creates device + if (!DeviceCreate(adapterType, deviceWrapper)) + { + result.ResultSub(CResult::TEST_ERROR); + return result.Result(); + } + + // generate input and expected data + size_t frameSize = width * height * 3 / 2; + std::vector bufferRef0(frameSize, 0); + std::vector bufferRef1(frameSize, 0); + std::vector bufferRef2(frameSize, 0); + if (!YUVGenerate(surfaceFormat, bufferRef0, width, height, 0, 90) + || !YUVGenerate(surfaceFormat, bufferRef1, width, height, 91, 180) + || !YUVGenerate(surfaceFormat, bufferRef2, width, height, 181, 255)) + { + result.ResultSub(CResult::TEST_ERROR); + return result.Result(); + } + + // iterates through all devices + while (deviceWrapper->AdapterNext()) + { + cl_int error; + // check if the test can be run on the adapter + if (CL_SUCCESS + != (error = deviceExistForCLTest(gPlatformIDdetected, adapterType, + deviceWrapper->Device(), result, + sharedHandle))) + { + return result.Result(); + } + + if (surfaceFormat != SURFACE_FORMAT_NV12 + && !SurfaceFormatCheck(adapterType, *deviceWrapper, surfaceFormat)) + { + std::string sharedHandleStr = + (sharedHandle == SHARED_HANDLE_ENABLED) ? "yes" : "no"; + std::string formatStr; + std::string adapterStr; + SurfaceFormatToString(surfaceFormat, formatStr); + AdapterToString(adapterType, adapterStr); + log_info( + "Skipping test case, image format is not supported by a device " + "(adapter type: %s, format: %s, shared handle: %s)\n", + adapterStr.c_str(), formatStr.c_str(), sharedHandleStr.c_str()); + return result.Result(); + } + + void *objectSharedHandle = 0; + std::auto_ptr surface; + + // creates surface + if (!MediaSurfaceCreate( + adapterType, width, height, surfaceFormat, *deviceWrapper, + surface, (sharedHandle == SHARED_HANDLE_ENABLED) ? true : false, + &objectSharedHandle)) + { + log_error("Media surface creation failed for %i adapter\n", + deviceWrapper->AdapterIdx()); + result.ResultSub(CResult::TEST_ERROR); + return result.Result(); + } + + if (!YUVSurfaceSet(surfaceFormat, surface, bufferRef0, width, height)) + { + result.ResultSub(CResult::TEST_ERROR); + return result.Result(); + } + + cl_context_properties contextProperties[] = { + CL_CONTEXT_PLATFORM, + (cl_context_properties)gPlatformIDdetected, + AdapterTypeToContextInfo(adapterType), + (cl_context_properties)deviceWrapper->Device(), + 0, + }; + + clContextWrapper ctx = clCreateContext( + &contextProperties[0], 1, &gDeviceIDdetected, NULL, NULL, &error); + if (error != CL_SUCCESS) + { + log_error("clCreateContext failed: %s\n", IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + return result.Result(); + } + + clCommandQueueWrapper cmdQueue = clCreateCommandQueueWithProperties( + ctx, gDeviceIDdetected, 0, &error); + if (error != CL_SUCCESS) + { + log_error("Unable to create command queue: %s\n", + IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + return result.Result(); + } + + { // memory access write +#if defined(_WIN32) + cl_dx9_surface_info_khr surfaceInfo; + surfaceInfo.resource = + *(static_cast(surface.get())); + surfaceInfo.shared_handle = objectSharedHandle; +#else + void *surfaceInfo = 0; + return TEST_NOT_IMPLEMENTED; +#endif + + std::vector memObjList; + unsigned int planesNum = PlanesNum(surfaceFormat); + std::vector planesList(planesNum); + for (unsigned int planeIdx = 0; planeIdx < planesNum; ++planeIdx) + { + planesList[planeIdx] = clCreateFromDX9MediaSurfaceKHR( + ctx, CL_MEM_WRITE_ONLY, adapterType, &surfaceInfo, planeIdx, + &error); + if (error != CL_SUCCESS) + { + log_error("clCreateFromDX9MediaSurfaceKHR failed for " + "WRITE_ONLY plane %i: %s\n", + planeIdx, IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + return result.Result(); + } + memObjList.push_back(planesList[planeIdx]); + } + + error = clEnqueueAcquireDX9MediaSurfacesKHR( + cmdQueue, static_cast(memObjList.size()), + &memObjList[0], 0, 0, 0); + if (error != CL_SUCCESS) + { + log_error("clEnqueueAcquireDX9MediaSurfacesKHR failed: %s\n", + IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + return result.Result(); + } + + size_t offset = 0; + size_t origin[3] = { 0, 0, 0 }; + for (size_t i = 0; i < memObjList.size(); ++i) + { + size_t planeWidth = (i == 0) ? width : width / 2; + size_t planeHeight = (i == 0) ? height : height / 2; + size_t regionPlane[3] = { planeWidth, planeHeight, 1 }; + + error = clEnqueueWriteImage(cmdQueue, memObjList[i], CL_TRUE, + origin, regionPlane, 0, 0, + &bufferRef1[offset], 0, 0, 0); + if (error != CL_SUCCESS) + { + log_error("clEnqueueWriteImage failed: %s\n", + IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + } + + offset += planeWidth * planeHeight; + } + + error = clEnqueueReleaseDX9MediaSurfacesKHR( + cmdQueue, static_cast(memObjList.size()), + &memObjList[0], 0, 0, 0); + if (error != CL_SUCCESS) + { + log_error("clEnqueueReleaseDX9MediaSurfacesKHR failed: %s\n", + IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + } + } + + std::vector bufferOut0(frameSize, 0); + if (!YUVSurfaceGet(surfaceFormat, surface, bufferOut0, width, height)) + { + result.ResultSub(CResult::TEST_FAIL); + return result.Result(); + } + + if (!YUVCompare(surfaceFormat, bufferOut0, bufferRef1, width, height)) + { + log_error("Media surface is different than expected\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + { // memory access read +#if defined(_WIN32) + cl_dx9_surface_info_khr surfaceInfo; + surfaceInfo.resource = + *(static_cast(surface.get())); + surfaceInfo.shared_handle = objectSharedHandle; +#else + void *surfaceInfo = 0; + return TEST_NOT_IMPLEMENTED; +#endif + + std::vector memObjList; + unsigned int planesNum = PlanesNum(surfaceFormat); + std::vector planesList(planesNum); + for (unsigned int planeIdx = 0; planeIdx < planesNum; ++planeIdx) + { + planesList[planeIdx] = clCreateFromDX9MediaSurfaceKHR( + ctx, CL_MEM_READ_ONLY, adapterType, &surfaceInfo, planeIdx, + &error); + if (error != CL_SUCCESS) + { + log_error("clCreateFromDX9MediaSurfaceKHR failed for " + "READ_ONLY plane %i: %s\n", + planeIdx, IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + return result.Result(); + } + memObjList.push_back(planesList[planeIdx]); + } + + error = clEnqueueAcquireDX9MediaSurfacesKHR( + cmdQueue, static_cast(memObjList.size()), + &memObjList[0], 0, 0, 0); + if (error != CL_SUCCESS) + { + log_error("clEnqueueAcquireDX9MediaSurfacesKHR failed: %s\n", + IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + return result.Result(); + } + + std::vector out(frameSize, 0); + size_t offset = 0; + size_t origin[3] = { 0, 0, 0 }; + + for (size_t i = 0; i < memObjList.size(); ++i) + { + size_t planeWidth = (i == 0) ? width : width / 2; + size_t planeHeight = (i == 0) ? height : height / 2; + size_t regionPlane[3] = { planeWidth, planeHeight, 1 }; + + error = clEnqueueReadImage(cmdQueue, memObjList[i], CL_TRUE, + origin, regionPlane, 0, 0, + &out[offset], 0, 0, 0); + if (error != CL_SUCCESS) + { + log_error("clEnqueueReadImage failed: %s\n", + IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + } + + offset += planeWidth * planeHeight; + } + + if (!YUVCompare(surfaceFormat, out, bufferRef1, width, height)) + { + log_error("OCL image (READ_ONLY) is different then expected\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + error = clEnqueueReleaseDX9MediaSurfacesKHR( + cmdQueue, static_cast(memObjList.size()), + &memObjList[0], 0, 0, 0); + if (error != CL_SUCCESS) + { + log_error("clEnqueueReleaseDX9MediaSurfacesKHR failed: %s\n", + IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + } + } + + std::vector bufferOut1(frameSize, 0); + if (!YUVSurfaceGet(surfaceFormat, surface, bufferOut1, width, height)) + { + result.ResultSub(CResult::TEST_FAIL); + return result.Result(); + } + + if (!YUVCompare(surfaceFormat, bufferOut1, bufferRef1, width, height)) + { + log_error("Media surface is different than expected\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + { // memory access read write +#if defined(_WIN32) + cl_dx9_surface_info_khr surfaceInfo; + surfaceInfo.resource = + *(static_cast(surface.get())); + surfaceInfo.shared_handle = objectSharedHandle; +#else + void *surfaceInfo = 0; + return TEST_NOT_IMPLEMENTED; +#endif + + std::vector memObjList; + unsigned int planesNum = PlanesNum(surfaceFormat); + std::vector planesList(planesNum); + for (unsigned int planeIdx = 0; planeIdx < planesNum; ++planeIdx) + { + planesList[planeIdx] = clCreateFromDX9MediaSurfaceKHR( + ctx, CL_MEM_READ_WRITE, adapterType, &surfaceInfo, planeIdx, + &error); + if (error != CL_SUCCESS) + { + log_error("clCreateFromDX9MediaSurfaceKHR failed for " + "READ_WRITE plane %i: %s\n", + planeIdx, IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + return result.Result(); + } + memObjList.push_back(planesList[planeIdx]); + } + + error = clEnqueueAcquireDX9MediaSurfacesKHR( + cmdQueue, static_cast(memObjList.size()), + &memObjList[0], 0, 0, 0); + if (error != CL_SUCCESS) + { + log_error("clEnqueueAcquireDX9MediaSurfacesKHR failed: %s\n", + IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + return result.Result(); + } + + { // read + std::vector out(frameSize, 0); + size_t offset = 0; + size_t origin[3] = { 0, 0, 0 }; + + for (size_t i = 0; i < memObjList.size(); ++i) + { + size_t planeWidth = (i == 0) ? width : width / 2; + size_t planeHeight = (i == 0) ? height : height / 2; + size_t regionPlane[3] = { planeWidth, planeHeight, 1 }; + + error = clEnqueueReadImage(cmdQueue, memObjList[i], CL_TRUE, + origin, regionPlane, 0, 0, + &out[offset], 0, 0, 0); + if (error != CL_SUCCESS) + { + log_error("clEnqueueReadImage failed: %s\n", + IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + } + + offset += planeWidth * planeHeight; + } + + if (!YUVCompare(surfaceFormat, out, bufferRef1, width, height)) + { + log_error( + "OCL image (READ_WRITE) is different then expected\n"); + result.ResultSub(CResult::TEST_FAIL); + } + } + + { // write + size_t offset = 0; + size_t origin[3] = { 0, 0, 0 }; + for (size_t i = 0; i < memObjList.size(); ++i) + { + size_t planeWidth = (i == 0) ? width : width / 2; + size_t planeHeight = (i == 0) ? height : height / 2; + size_t regionPlane[3] = { planeWidth, planeHeight, 1 }; + + error = clEnqueueWriteImage( + cmdQueue, memObjList[i], CL_TRUE, origin, regionPlane, + 0, 0, &bufferRef2[offset], 0, 0, 0); + if (error != CL_SUCCESS) + { + log_error("clEnqueueWriteImage failed: %s\n", + IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + } + + offset += planeWidth * planeHeight; + } + } + + error = clEnqueueReleaseDX9MediaSurfacesKHR( + cmdQueue, static_cast(memObjList.size()), + &memObjList[0], 0, 0, 0); + if (error != CL_SUCCESS) + { + log_error("clEnqueueReleaseDX9MediaSurfacesKHR failed: %s\n", + IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + } + } + + std::vector bufferOut2(frameSize, 0); + if (!YUVSurfaceGet(surfaceFormat, surface, bufferOut2, width, height)) + { + result.ResultSub(CResult::TEST_FAIL); + return result.Result(); + } + + if (!YUVCompare(surfaceFormat, bufferOut2, bufferRef2, width, height)) + { + log_error("Media surface is different than expected\n"); + result.ResultSub(CResult::TEST_FAIL); + } + } + + if (deviceWrapper->Status() != DEVICE_PASS) + { + std::string adapterName; + AdapterToString(adapterType, adapterName); + if (deviceWrapper->Status() == DEVICE_FAIL) + { + log_error("%s init failed\n", adapterName.c_str()); + result.ResultSub(CResult::TEST_FAIL); + } + else + { + log_error("%s init incomplete due to unsupported device\n", + adapterName.c_str()); + result.ResultSub(CResult::TEST_NOTSUPPORTED); + } + } + + return result.Result(); +} + +int test_memory_access(cl_device_id deviceID, cl_context context, + cl_command_queue queue, int num_elements) +{ + CResult result; + +#if defined(_WIN32) + // D3D9 + if (memory_access(deviceID, context, queue, num_elements, 256, 256, + CL_ADAPTER_D3D9_KHR, SURFACE_FORMAT_NV12, + SHARED_HANDLE_DISABLED) + != 0) + { + log_error("\nTest case (D3D9, NV12, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (memory_access(deviceID, context, queue, num_elements, 512, 256, + CL_ADAPTER_D3D9_KHR, SURFACE_FORMAT_YV12, + SHARED_HANDLE_DISABLED) + != 0) + { + log_error("\nTest case (D3D9, YV12, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + // D3D9EX + if (memory_access(deviceID, context, queue, num_elements, 256, 512, + CL_ADAPTER_D3D9EX_KHR, SURFACE_FORMAT_NV12, + SHARED_HANDLE_DISABLED) + != 0) + { + log_error("\nTest case (D3D9EX, NV12, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (memory_access(deviceID, context, queue, num_elements, 512, 256, + CL_ADAPTER_D3D9EX_KHR, SURFACE_FORMAT_NV12, + SHARED_HANDLE_ENABLED) + != 0) + { + log_error("\nTest case (D3D9EX, NV12, shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (memory_access(deviceID, context, queue, num_elements, 256, 256, + CL_ADAPTER_D3D9EX_KHR, SURFACE_FORMAT_YV12, + SHARED_HANDLE_DISABLED) + != 0) + { + log_error("\nTest case (D3D9EX, YV12, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (memory_access(deviceID, context, queue, num_elements, 128, 128, + CL_ADAPTER_D3D9EX_KHR, SURFACE_FORMAT_YV12, + SHARED_HANDLE_ENABLED) + != 0) + { + log_error("\nTest case (D3D9EX, YV12, shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + // DXVA + if (memory_access(deviceID, context, queue, num_elements, 128, 128, + CL_ADAPTER_DXVA_KHR, SURFACE_FORMAT_NV12, + SHARED_HANDLE_DISABLED) + != 0) + { + log_error("\nTest case (DXVA, NV12, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (memory_access(deviceID, context, queue, num_elements, 64, 64, + CL_ADAPTER_DXVA_KHR, SURFACE_FORMAT_NV12, + SHARED_HANDLE_ENABLED) + != 0) + { + log_error("\nTest case (DXVA, NV12, shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (memory_access(deviceID, context, queue, num_elements, 512, 512, + CL_ADAPTER_DXVA_KHR, SURFACE_FORMAT_YV12, + SHARED_HANDLE_DISABLED) + != 0) + { + log_error("\nTest case (DXVA, YV12, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (memory_access(deviceID, context, queue, num_elements, 1024, 1024, + CL_ADAPTER_DXVA_KHR, SURFACE_FORMAT_YV12, + SHARED_HANDLE_ENABLED) + != 0) + { + log_error("\nTest case (DXVA, YV12, shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + +#else + return TEST_NOT_IMPLEMENTED; +#endif + + return result.Result(); +} diff --git a/test_conformance/extensions/cl_khr_dx9_media_sharing/test_other_data_types.cpp b/test_conformance/extensions/cl_khr_dx9_media_sharing/test_other_data_types.cpp new file mode 100644 index 00000000..0e5d1d12 --- /dev/null +++ b/test_conformance/extensions/cl_khr_dx9_media_sharing/test_other_data_types.cpp @@ -0,0 +1,1319 @@ +// +// 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 +#include + +#include "harness/errorHelpers.h" +#include "harness/imageHelpers.h" +#include "harness/kernelHelpers.h" + +#include "utils.h" + +template +int other_data_types(cl_device_id deviceID, cl_context context, + cl_command_queue queue, int num_elements, + unsigned int iterationNum, unsigned int width, + unsigned int height, + cl_dx9_media_adapter_type_khr adapterType, + TSurfaceFormat surfaceFormat, + TSharedHandleType sharedHandle) +{ + const unsigned int FRAME_NUM = 2; + const float MAX_VALUE = 0.6f; + const std::string PROGRAM_STR = + "__kernel void TestFunction( read_only image2d_t imageIn, write_only " + "image2d_t imageOut, " NL " sampler_t " + "sampler, __global int *imageRes)" NL "{" NL + " int w = get_global_id(0);" NL " int h = get_global_id(1);" NL + " int width = get_image_width(imageIn);" NL + " int height = get_image_height(imageOut);" NL + " float4 color0 = read_imagef(imageIn, sampler, (int2)(w,h)) - " + "0.2f;" NL " float4 color1 = read_imagef(imageIn, sampler, " + "(float2)(w,h)) - 0.2f;" NL + " color0 = (color0 == color1) ? color0: (float4)(0.5, 0.5, 0.5, " + "0.5);" NL " write_imagef(imageOut, (int2)(w,h), color0);" NL + " if(w == 0 && h == 0)" NL " {" NL " imageRes[0] = width;" NL + " imageRes[1] = height;" NL " }" NL "}"; + + CResult result; + + cl_image_format format; + if (!SurfaceFormatToOCL(surfaceFormat, format)) + { + result.ResultSub(CResult::TEST_ERROR); + return result.Result(); + } + + std::auto_ptr deviceWrapper; + if (!DeviceCreate(adapterType, deviceWrapper)) + { + result.ResultSub(CResult::TEST_ERROR); + return result.Result(); + } + + while (deviceWrapper->AdapterNext()) + { + cl_int error; + // check if the test can be run on the adapter + if (CL_SUCCESS + != (error = deviceExistForCLTest(gPlatformIDdetected, adapterType, + deviceWrapper->Device(), result, + sharedHandle))) + { + return result.Result(); + } + + cl_context_properties contextProperties[] = { + CL_CONTEXT_PLATFORM, + (cl_context_properties)gPlatformIDdetected, + AdapterTypeToContextInfo(adapterType), + (cl_context_properties)deviceWrapper->Device(), + 0, + }; + + clContextWrapper ctx = clCreateContext( + &contextProperties[0], 1, &gDeviceIDdetected, NULL, NULL, &error); + if (error != CL_SUCCESS) + { + log_error("clCreateContext failed: %s\n", IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + return result.Result(); + } + + clCommandQueueWrapper cmdQueue = clCreateCommandQueueWithProperties( + ctx, gDeviceIDdetected, 0, &error); + if (error != CL_SUCCESS) + { + log_error("Unable to create command queue: %s\n", + IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + return result.Result(); + } + + if (!SurfaceFormatCheck(adapterType, *deviceWrapper, surfaceFormat)) + { + std::string sharedHandleStr = + (sharedHandle == SHARED_HANDLE_ENABLED) ? "yes" : "no"; + std::string formatStr; + std::string adapterStr; + SurfaceFormatToString(surfaceFormat, formatStr); + AdapterToString(adapterType, adapterStr); + log_info( + "Skipping test case, image format is not supported by a device " + "(adapter type: %s, format: %s, shared handle: %s)\n", + adapterStr.c_str(), formatStr.c_str(), sharedHandleStr.c_str()); + return result.Result(); + } + + if (!ImageFormatCheck(ctx, CL_MEM_OBJECT_IMAGE2D, format)) + { + std::string sharedHandleStr = + (sharedHandle == SHARED_HANDLE_ENABLED) ? "yes" : "no"; + std::string formatStr; + std::string adapterStr; + SurfaceFormatToString(surfaceFormat, formatStr); + AdapterToString(adapterType, adapterStr); + log_info("Skipping test case, image format is not supported by OCL " + "(adapter type: %s, format: %s, shared handle: %s)\n", + adapterStr.c_str(), formatStr.c_str(), + sharedHandleStr.c_str()); + return result.Result(); + } + + if (format.image_channel_data_type == CL_HALF_FLOAT) + { + if (DetectFloatToHalfRoundingMode(cmdQueue)) + { + log_error("Unable to detect rounding mode\n"); + result.ResultSub(CResult::TEST_FAIL); + return result.Result(); + } + } + + std::vector> bufferIn(FRAME_NUM); + std::vector> bufferExp(FRAME_NUM); + float step = MAX_VALUE / static_cast(FRAME_NUM); + unsigned int planeNum = ChannelNum(surfaceFormat); + for (size_t i = 0; i < FRAME_NUM; ++i) + { + DataGenerate(surfaceFormat, format.image_channel_data_type, + bufferIn[i], width, height, planeNum, step * i, + step * (i + 1)); + DataGenerate(surfaceFormat, format.image_channel_data_type, + bufferExp[i], width, height, planeNum, step * i, + step * (i + 1), 0.2f); + } + + void *objectSrcHandle = 0; + std::auto_ptr surfaceSrc; + if (!MediaSurfaceCreate(adapterType, width, height, surfaceFormat, + *deviceWrapper, surfaceSrc, + (sharedHandle == SHARED_HANDLE_ENABLED) ? true + : false, + &objectSrcHandle)) + { + log_error("Media surface creation failed for %i adapter\n", + deviceWrapper->AdapterIdx()); + result.ResultSub(CResult::TEST_ERROR); + return result.Result(); + } + + void *objectDstHandle = 0; + std::auto_ptr surfaceDst; + if (!MediaSurfaceCreate(adapterType, width, height, surfaceFormat, + *deviceWrapper, surfaceDst, + (sharedHandle == SHARED_HANDLE_ENABLED) ? true + : false, + &objectDstHandle)) + { + log_error("Media surface creation failed for %i adapter\n", + deviceWrapper->AdapterIdx()); + result.ResultSub(CResult::TEST_ERROR); + return result.Result(); + } + +#if defined(_WIN32) + cl_dx9_surface_info_khr surfaceSrcInfo; + CD3D9SurfaceWrapper *dx9SurfaceSrc = + (static_cast(surfaceSrc.get())); + surfaceSrcInfo.resource = *dx9SurfaceSrc; + surfaceSrcInfo.shared_handle = objectSrcHandle; + + cl_dx9_surface_info_khr surfaceDstInfo; + CD3D9SurfaceWrapper *dx9SurfaceDst = + (static_cast(surfaceDst.get())); + surfaceDstInfo.resource = *dx9SurfaceDst; + surfaceDstInfo.shared_handle = objectDstHandle; +#else + void *surfaceSrcInfo = 0; + void *surfaceDstInfo = 0; + return TEST_NOT_IMPLEMENTED; +#endif + + // create OCL shared object + clMemWrapper objectSrcShared = clCreateFromDX9MediaSurfaceKHR( + ctx, CL_MEM_READ_WRITE, adapterType, &surfaceSrcInfo, 0, &error); + if (error != CL_SUCCESS) + { + log_error("clCreateFromDX9MediaSurfaceKHR failed: %s\n", + IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + return result.Result(); + } + + clMemWrapper objectDstShared = clCreateFromDX9MediaSurfaceKHR( + ctx, CL_MEM_READ_WRITE, adapterType, &surfaceDstInfo, 0, &error); + if (error != CL_SUCCESS) + { + log_error("clCreateFromDX9MediaSurfaceKHR failed: %s\n", + IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + return result.Result(); + } + + std::vector memObjList; + memObjList.push_back(objectSrcShared); + memObjList.push_back(objectDstShared); + + if (!GetMemObjInfo(objectSrcShared, adapterType, surfaceSrc, + objectSrcHandle)) + { + log_error("Invalid memory object info\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (!GetImageInfo(objectSrcShared, format, sizeof(T) * planeNum, + width * sizeof(T) * planeNum, 0, width, height, 0, 0)) + { + log_error("clGetImageInfo failed\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + for (size_t frameIdx = 0; frameIdx < iterationNum; ++frameIdx) + { + // surface set +#if defined(_WIN32) + D3DLOCKED_RECT rect; + if (FAILED((*dx9SurfaceSrc)->LockRect(&rect, NULL, 0))) + { + log_error("Surface lock failed\n"); + result.ResultSub(CResult::TEST_ERROR); + return result.Result(); + } + + size_t pitch = rect.Pitch / sizeof(T); + size_t lineSize = width * planeNum * sizeof(T); + T *ptr = static_cast(rect.pBits); + + for (size_t y = 0; y < height; ++y) + memcpy(ptr + y * pitch, + &bufferIn[frameIdx % FRAME_NUM][y * width * planeNum], + lineSize); + + (*dx9SurfaceSrc)->UnlockRect(); +#else + void *surfaceInfo = 0; + return TEST_NOT_IMPLEMENTED; +#endif + + error = clEnqueueAcquireDX9MediaSurfacesKHR( + cmdQueue, static_cast(memObjList.size()), + &memObjList[0], 0, 0, 0); + if (error != CL_SUCCESS) + { + log_error("clEnqueueAcquireMediaSurfaceKHR failed: %s\n", + IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + return result.Result(); + } + + size_t origin[3] = { 0, 0, 0 }; + size_t region[3] = { width, height, 1 }; + + { // read operation + std::vector out(planeNum * width * height, 0); + error = + clEnqueueReadImage(cmdQueue, objectSrcShared, CL_TRUE, + origin, region, 0, 0, &out[0], 0, 0, 0); + if (error != CL_SUCCESS) + { + log_error("clEnqueueReadImage failed: %s\n", + IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + } + + if (!DataCompare(surfaceFormat, format.image_channel_data_type, + out, bufferIn[frameIdx % FRAME_NUM], width, + height, planeNum)) + { + log_error("Frame idx: %i, OCL object is different then " + "expected\n", + frameIdx); + result.ResultSub(CResult::TEST_FAIL); + } + } + + { // write operation + error = clEnqueueWriteImage( + cmdQueue, objectSrcShared, CL_TRUE, origin, region, 0, 0, + &bufferExp[frameIdx % FRAME_NUM][0], 0, 0, 0); + if (error != CL_SUCCESS) + { + log_error("clEnqueueWriteImage failed: %s\n", + IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + } + } + + { // kernel operations + clSamplerWrapper sampler = clCreateSampler( + ctx, CL_FALSE, CL_ADDRESS_NONE, CL_FILTER_NEAREST, &error); + if (error != CL_SUCCESS) + { + log_error("Unable to create sampler\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + size_t threads[2] = { width, height }; + clProgramWrapper program; + clKernelWrapper kernel; + const char *progPtr = PROGRAM_STR.c_str(); + if (create_single_kernel_helper(ctx, &program, &kernel, 1, + (const char **)&progPtr, + "TestFunction")) + result.ResultSub(CResult::TEST_FAIL); + + error = clSetKernelArg(kernel, 0, sizeof(objectSrcShared), + &(objectSrcShared)); + if (error != CL_SUCCESS) + { + log_error("Unable to set kernel arguments"); + result.ResultSub(CResult::TEST_FAIL); + } + + error = clSetKernelArg(kernel, 1, sizeof(objectDstShared), + &(objectDstShared)); + if (error != CL_SUCCESS) + { + log_error("Unable to set kernel arguments"); + result.ResultSub(CResult::TEST_FAIL); + } + + error = clSetKernelArg(kernel, 2, sizeof(sampler), &sampler); + if (error != CL_SUCCESS) + { + log_error("Unable to set kernel arguments"); + result.ResultSub(CResult::TEST_FAIL); + } + + size_t bufferSize = sizeof(cl_int) * 2; + clMemWrapper imageRes = clCreateBuffer( + ctx, CL_MEM_READ_WRITE, bufferSize, NULL, &error); + if (error != CL_SUCCESS) + { + log_error("clCreateBuffer failed: %s\n", + IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + } + + error = clSetKernelArg(kernel, 3, sizeof(imageRes), &imageRes); + + size_t localThreads[2]; + error = get_max_common_2D_work_group_size(ctx, kernel, threads, + localThreads); + if (error != CL_SUCCESS) + { + log_error("Unable to get work group size to use"); + result.ResultSub(CResult::TEST_FAIL); + } + + error = + clEnqueueNDRangeKernel(cmdQueue, kernel, 2, NULL, threads, + localThreads, 0, NULL, NULL); + if (error != CL_SUCCESS) + { + log_error("Unable to execute test kernel"); + result.ResultSub(CResult::TEST_FAIL); + } + + std::vector imageResOut(2, 0); + error = clEnqueueReadBuffer(cmdQueue, imageRes, CL_TRUE, 0, + bufferSize, &imageResOut[0], 0, + NULL, NULL); + if (error != CL_SUCCESS) + { + log_error("Unable to read buffer"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (imageResOut[0] != width) + { + log_error("Invalid width value, test = %i, expected = %i\n", + imageResOut[0], width); + result.ResultSub(CResult::TEST_FAIL); + } + + if (imageResOut[1] != height) + { + log_error( + "Invalid height value, test = %i, expected = %i\n", + imageResOut[1], height); + result.ResultSub(CResult::TEST_FAIL); + } + } + + { // map operation + size_t mapOrigin[3] = { 0, 0, 0 }; + size_t mapRegion[3] = { width, height, 1 }; + + std::vector out(width * height * planeNum, 0); + size_t rowPitch = 0; + size_t slicePitch = 0; + void *mapPtr = clEnqueueMapImage( + cmdQueue, objectDstShared, CL_TRUE, + CL_MAP_READ | CL_MAP_WRITE, mapOrigin, mapRegion, &rowPitch, + &slicePitch, 0, 0, 0, &error); + if (error != CL_SUCCESS) + { + log_error("clEnqueueMapImage failed: %s\n", + IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + } + + for (size_t y = 0; y < height; ++y) + memcpy(&out[y * width * planeNum], + static_cast(mapPtr) + y * rowPitch / sizeof(T), + width * planeNum * sizeof(T)); + + if (!DataCompare(surfaceFormat, format.image_channel_data_type, + out, bufferIn[frameIdx % FRAME_NUM], width, + height, planeNum)) + { + log_error("Frame idx: %i, Mapped OCL object is different " + "then expected\n", + frameIdx); + result.ResultSub(CResult::TEST_FAIL); + } + + for (size_t y = 0; y < height; ++y) + memcpy( + static_cast(mapPtr) + y * rowPitch / sizeof(T), + &bufferExp[frameIdx % FRAME_NUM][y * width * planeNum], + width * planeNum * sizeof(T)); + + error = clEnqueueUnmapMemObject(cmdQueue, objectDstShared, + mapPtr, 0, 0, 0); + if (error != CL_SUCCESS) + { + log_error("clEnqueueUnmapMemObject failed: %s\n", + IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + } + } + + error = clEnqueueReleaseDX9MediaSurfacesKHR( + cmdQueue, static_cast(memObjList.size()), + &memObjList[0], 0, 0, 0); + if (error != CL_SUCCESS) + { + log_error("clEnqueueReleaseMediaSurfaceKHR failed: %s\n", + IGetErrorString(error)); + result.ResultSub(CResult::TEST_FAIL); + } + + std::vector out(width * height * planeNum, 0); + // surface get +#if defined(_WIN32) + if (FAILED((*dx9SurfaceDst)->LockRect(&rect, NULL, 0))) + { + log_error("Surface lock failed\n"); + result.ResultSub(CResult::TEST_ERROR); + return result.Result(); + } + + pitch = rect.Pitch / sizeof(T); + lineSize = width * planeNum * sizeof(T); + ptr = static_cast(rect.pBits); + for (size_t y = 0; y < height; ++y) + memcpy(&out[y * width * planeNum], ptr + y * pitch, lineSize); + + (*dx9SurfaceDst)->UnlockRect(); +#else + return TEST_NOT_IMPLEMENTED; +#endif + + if (!DataCompare(surfaceFormat, format.image_channel_data_type, out, + bufferExp[frameIdx % FRAME_NUM], width, height, + planeNum)) + { + log_error( + "Frame idx: %i, media object is different then expected\n", + frameIdx); + result.ResultSub(CResult::TEST_FAIL); + } + } + } + + if (deviceWrapper->Status() != DEVICE_PASS) + { + std::string adapterName; + AdapterToString(adapterType, adapterName); + if (deviceWrapper->Status() == DEVICE_FAIL) + { + log_error("%s init failed\n", adapterName.c_str()); + result.ResultSub(CResult::TEST_FAIL); + } + else + { + log_error("%s init incomplete due to unsupported device\n", + adapterName.c_str()); + result.ResultSub(CResult::TEST_NOTSUPPORTED); + } + } + + return result.Result(); +} + +int test_other_data_types(cl_device_id deviceID, cl_context context, + cl_command_queue queue, int num_elements) +{ + CResult result; + +#if defined(_WIN32) + // D3D9 + if (other_data_types(deviceID, context, queue, num_elements, 10, + 64, 256, CL_ADAPTER_D3D9_KHR, + SURFACE_FORMAT_R32F, SHARED_HANDLE_DISABLED) + != 0) + { + log_error("\nTest case (D3D9, R32F, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 256, 128, CL_ADAPTER_D3D9_KHR, + SURFACE_FORMAT_R16F, SHARED_HANDLE_DISABLED) + != 0) + { + log_error("\nTest case (D3D9, R16F, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 512, 256, CL_ADAPTER_D3D9_KHR, + SURFACE_FORMAT_L16, SHARED_HANDLE_DISABLED) + != 0) + { + log_error("\nTest case (D3D9, L16, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 256, 512, CL_ADAPTER_D3D9_KHR, + SURFACE_FORMAT_A8, SHARED_HANDLE_DISABLED) + != 0) + { + log_error("\nTest case (D3D9, A8, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 1024, 32, CL_ADAPTER_D3D9_KHR, + SURFACE_FORMAT_L8, SHARED_HANDLE_DISABLED) + != 0) + { + log_error("\nTest case (D3D9, L8, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types( + deviceID, context, queue, num_elements, 10, 32, 1024, + CL_ADAPTER_D3D9_KHR, SURFACE_FORMAT_G32R32F, SHARED_HANDLE_DISABLED) + != 0) + { + log_error("\nTest case (D3D9, G32R32F, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types( + deviceID, context, queue, num_elements, 10, 64, 64, + CL_ADAPTER_D3D9_KHR, SURFACE_FORMAT_G16R16F, SHARED_HANDLE_DISABLED) + != 0) + { + log_error("\nTest case (D3D9, G16R16F, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types( + deviceID, context, queue, num_elements, 10, 256, 256, + CL_ADAPTER_D3D9_KHR, SURFACE_FORMAT_G16R16, SHARED_HANDLE_DISABLED) + != 0) + { + log_error("\nTest case (D3D9, G16R16, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 512, 128, CL_ADAPTER_D3D9_KHR, + SURFACE_FORMAT_A8L8, SHARED_HANDLE_DISABLED) + != 0) + { + log_error("\nTest case (D3D9, A8L8, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 128, 512, CL_ADAPTER_D3D9_KHR, + SURFACE_FORMAT_A32B32G32R32F, + SHARED_HANDLE_DISABLED) + != 0) + { + log_error( + "\nTest case (D3D9, A32B32G32R32F, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 128, 128, CL_ADAPTER_D3D9_KHR, + SURFACE_FORMAT_A16B16G16R16F, + SHARED_HANDLE_DISABLED) + != 0) + { + log_error( + "\nTest case (D3D9, A16B16G16R16F, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 64, 128, CL_ADAPTER_D3D9_KHR, + SURFACE_FORMAT_A16B16G16R16, + SHARED_HANDLE_DISABLED) + != 0) + { + log_error( + "\nTest case (D3D9, A16B16G16R16, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 128, 64, CL_ADAPTER_D3D9_KHR, + SURFACE_FORMAT_A8B8G8R8, + SHARED_HANDLE_DISABLED) + != 0) + { + log_error("\nTest case (D3D9, A8B8G8R8, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 16, 512, CL_ADAPTER_D3D9_KHR, + SURFACE_FORMAT_X8B8G8R8, + SHARED_HANDLE_DISABLED) + != 0) + { + log_error("\nTest case (D3D9, X8B8G8R8, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 512, 16, CL_ADAPTER_D3D9_KHR, + SURFACE_FORMAT_A8R8G8B8, + SHARED_HANDLE_DISABLED) + != 0) + { + log_error("\nTest case (D3D9, A8R8G8B8, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 256, 256, CL_ADAPTER_D3D9_KHR, + SURFACE_FORMAT_X8R8G8B8, + SHARED_HANDLE_DISABLED) + != 0) + { + log_error("\nTest case (D3D9, X8R8G8B8, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + // D3D9EX + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 64, 256, CL_ADAPTER_D3D9EX_KHR, + SURFACE_FORMAT_R32F, SHARED_HANDLE_DISABLED) + != 0) + { + log_error("\nTest case (D3D9EX, R32F, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 64, 256, CL_ADAPTER_D3D9EX_KHR, + SURFACE_FORMAT_R32F, SHARED_HANDLE_ENABLED) + != 0) + { + log_error("\nTest case (D3D9EX, R32F, shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 256, 128, CL_ADAPTER_D3D9EX_KHR, + SURFACE_FORMAT_R16F, SHARED_HANDLE_DISABLED) + != 0) + { + log_error("\nTest case (D3D9EX, R16F, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 256, 128, CL_ADAPTER_D3D9EX_KHR, + SURFACE_FORMAT_R16F, SHARED_HANDLE_ENABLED) + != 0) + { + log_error("\nTest case (D3D9EX, R16F, shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 512, 256, CL_ADAPTER_D3D9EX_KHR, + SURFACE_FORMAT_L16, SHARED_HANDLE_DISABLED) + != 0) + { + log_error("\nTest case (D3D9EX, L16, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 512, 256, CL_ADAPTER_D3D9EX_KHR, + SURFACE_FORMAT_L16, SHARED_HANDLE_ENABLED) + != 0) + { + log_error("\nTest case (D3D9EX, L16, shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 256, 512, CL_ADAPTER_D3D9EX_KHR, + SURFACE_FORMAT_A8, SHARED_HANDLE_DISABLED) + != 0) + { + log_error("\nTest case (D3D9EX, A8, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 256, 512, CL_ADAPTER_D3D9EX_KHR, + SURFACE_FORMAT_A8, SHARED_HANDLE_ENABLED) + != 0) + { + log_error("\nTest case (D3D9EX, A8, shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 1024, 32, CL_ADAPTER_D3D9EX_KHR, + SURFACE_FORMAT_L8, SHARED_HANDLE_DISABLED) + != 0) + { + log_error("\nTest case (D3D9EX, L8, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 1024, 32, CL_ADAPTER_D3D9EX_KHR, + SURFACE_FORMAT_L8, SHARED_HANDLE_ENABLED) + != 0) + { + log_error("\nTest case (D3D9EX, L8, shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 32, 1024, CL_ADAPTER_D3D9EX_KHR, + SURFACE_FORMAT_G32R32F, + SHARED_HANDLE_DISABLED) + != 0) + { + log_error("\nTest case (D3D9EX, G32R32F, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 32, 1024, CL_ADAPTER_D3D9EX_KHR, + SURFACE_FORMAT_G32R32F, + SHARED_HANDLE_ENABLED) + != 0) + { + log_error("\nTest case (D3D9EX, G32R32F, shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 64, 64, CL_ADAPTER_D3D9EX_KHR, + SURFACE_FORMAT_G16R16F, + SHARED_HANDLE_DISABLED) + != 0) + { + log_error("\nTest case (D3D9EX, G16R16F, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 64, 64, CL_ADAPTER_D3D9EX_KHR, + SURFACE_FORMAT_G16R16F, SHARED_HANDLE_ENABLED) + != 0) + { + log_error("\nTest case (D3D9EX, G16R16F, shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 256, 256, CL_ADAPTER_D3D9EX_KHR, + SURFACE_FORMAT_G16R16, + SHARED_HANDLE_DISABLED) + != 0) + { + log_error("\nTest case (D3D9EX, G16R16, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types( + deviceID, context, queue, num_elements, 10, 256, 256, + CL_ADAPTER_D3D9EX_KHR, SURFACE_FORMAT_G16R16, SHARED_HANDLE_ENABLED) + != 0) + { + log_error("\nTest case (D3D9EX, G16R16, shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 512, 128, CL_ADAPTER_D3D9EX_KHR, + SURFACE_FORMAT_A8L8, SHARED_HANDLE_DISABLED) + != 0) + { + log_error("\nTest case (D3D9EX, A8L8, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 512, 128, CL_ADAPTER_D3D9EX_KHR, + SURFACE_FORMAT_A8L8, SHARED_HANDLE_ENABLED) + != 0) + { + log_error("\nTest case (D3D9EX, A8L8, shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 128, 512, CL_ADAPTER_D3D9EX_KHR, + SURFACE_FORMAT_A32B32G32R32F, + SHARED_HANDLE_DISABLED) + != 0) + { + log_error( + "\nTest case (D3D9EX, A32B32G32R32F, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 128, 512, CL_ADAPTER_D3D9EX_KHR, + SURFACE_FORMAT_A32B32G32R32F, + SHARED_HANDLE_ENABLED) + != 0) + { + log_error( + "\nTest case (D3D9EX, A32B32G32R32F, shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 128, 128, CL_ADAPTER_D3D9EX_KHR, + SURFACE_FORMAT_A16B16G16R16F, + SHARED_HANDLE_DISABLED) + != 0) + { + log_error( + "\nTest case (D3D9EX, A16B16G16R16F, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 128, 128, CL_ADAPTER_D3D9EX_KHR, + SURFACE_FORMAT_A16B16G16R16F, + SHARED_HANDLE_ENABLED) + != 0) + { + log_error( + "\nTest case (D3D9EX, A16B16G16R16F, shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 64, 128, CL_ADAPTER_D3D9EX_KHR, + SURFACE_FORMAT_A16B16G16R16, + SHARED_HANDLE_DISABLED) + != 0) + { + log_error( + "\nTest case (D3D9EX, A16B16G16R16, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 64, 128, CL_ADAPTER_D3D9EX_KHR, + SURFACE_FORMAT_A16B16G16R16, + SHARED_HANDLE_ENABLED) + != 0) + { + log_error( + "\nTest case (D3D9EX, A16B16G16R16, shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 128, 64, CL_ADAPTER_D3D9EX_KHR, + SURFACE_FORMAT_A8B8G8R8, + SHARED_HANDLE_DISABLED) + != 0) + { + log_error( + "\nTest case (D3D9EX, A8B8G8R8, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 128, 64, CL_ADAPTER_D3D9EX_KHR, + SURFACE_FORMAT_A8B8G8R8, + SHARED_HANDLE_ENABLED) + != 0) + { + log_error("\nTest case (D3D9EX, A8B8G8R8, shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 16, 512, CL_ADAPTER_D3D9EX_KHR, + SURFACE_FORMAT_X8B8G8R8, + SHARED_HANDLE_DISABLED) + != 0) + { + log_error( + "\nTest case (D3D9EX, X8B8G8R8, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 16, 512, CL_ADAPTER_D3D9EX_KHR, + SURFACE_FORMAT_X8B8G8R8, + SHARED_HANDLE_ENABLED) + != 0) + { + log_error("\nTest case (D3D9EX, X8B8G8R8, shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 512, 16, CL_ADAPTER_D3D9EX_KHR, + SURFACE_FORMAT_A8R8G8B8, + SHARED_HANDLE_DISABLED) + != 0) + { + log_error( + "\nTest case (D3D9EX, A8R8G8B8, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 512, 16, CL_ADAPTER_D3D9EX_KHR, + SURFACE_FORMAT_A8R8G8B8, + SHARED_HANDLE_ENABLED) + != 0) + { + log_error("\nTest case (D3D9EX, A8R8G8B8, shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 256, 256, CL_ADAPTER_D3D9EX_KHR, + SURFACE_FORMAT_X8R8G8B8, + SHARED_HANDLE_DISABLED) + != 0) + { + log_error( + "\nTest case (D3D9EX, X8R8G8B8, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 256, 256, CL_ADAPTER_D3D9EX_KHR, + SURFACE_FORMAT_X8R8G8B8, + SHARED_HANDLE_ENABLED) + != 0) + { + log_error("\nTest case (D3D9EX, X8R8G8B8, shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + // DXVA + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 64, 256, CL_ADAPTER_DXVA_KHR, + SURFACE_FORMAT_R32F, SHARED_HANDLE_DISABLED) + != 0) + { + log_error("\nTest case (DXVA, R32F, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 64, 256, CL_ADAPTER_DXVA_KHR, + SURFACE_FORMAT_R32F, SHARED_HANDLE_ENABLED) + != 0) + { + log_error("\nTest case (DXVA, R32F, shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 256, 128, CL_ADAPTER_DXVA_KHR, + SURFACE_FORMAT_R16F, SHARED_HANDLE_DISABLED) + != 0) + { + log_error("\nTest case (DXVA, R16F, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 256, 128, CL_ADAPTER_DXVA_KHR, + SURFACE_FORMAT_R16F, SHARED_HANDLE_ENABLED) + != 0) + { + log_error("\nTest case (DXVA, R16F, shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 512, 256, CL_ADAPTER_DXVA_KHR, + SURFACE_FORMAT_L16, SHARED_HANDLE_DISABLED) + != 0) + { + log_error("\nTest case (DXVA, L16, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 512, 256, CL_ADAPTER_DXVA_KHR, + SURFACE_FORMAT_L16, SHARED_HANDLE_ENABLED) + != 0) + { + log_error("\nTest case (DXVA, L16, shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 256, 512, CL_ADAPTER_DXVA_KHR, + SURFACE_FORMAT_A8, SHARED_HANDLE_DISABLED) + != 0) + { + log_error("\nTest case (DXVA, A8, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 256, 512, CL_ADAPTER_DXVA_KHR, + SURFACE_FORMAT_A8, SHARED_HANDLE_ENABLED) + != 0) + { + log_error("\nTest case (DXVA, A8, shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 1024, 32, CL_ADAPTER_DXVA_KHR, + SURFACE_FORMAT_L8, SHARED_HANDLE_DISABLED) + != 0) + { + log_error("\nTest case (DXVA, L8, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 1024, 32, CL_ADAPTER_DXVA_KHR, + SURFACE_FORMAT_L8, SHARED_HANDLE_ENABLED) + != 0) + { + log_error("\nTest case (DXVA, L8, shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types( + deviceID, context, queue, num_elements, 10, 32, 1024, + CL_ADAPTER_DXVA_KHR, SURFACE_FORMAT_G32R32F, SHARED_HANDLE_DISABLED) + != 0) + { + log_error("\nTest case (DXVA, G32R32F, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types( + deviceID, context, queue, num_elements, 10, 32, 1024, + CL_ADAPTER_DXVA_KHR, SURFACE_FORMAT_G32R32F, SHARED_HANDLE_ENABLED) + != 0) + { + log_error("\nTest case (DXVA, G32R32F, shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types( + deviceID, context, queue, num_elements, 10, 64, 64, + CL_ADAPTER_DXVA_KHR, SURFACE_FORMAT_G16R16F, SHARED_HANDLE_DISABLED) + != 0) + { + log_error("\nTest case (DXVA, G16R16F, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 64, 64, CL_ADAPTER_DXVA_KHR, + SURFACE_FORMAT_G16R16F, SHARED_HANDLE_ENABLED) + != 0) + { + log_error("\nTest case (DXVA, G16R16F, shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types( + deviceID, context, queue, num_elements, 10, 256, 256, + CL_ADAPTER_DXVA_KHR, SURFACE_FORMAT_G16R16, SHARED_HANDLE_DISABLED) + != 0) + { + log_error("\nTest case (DXVA, G16R16, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types( + deviceID, context, queue, num_elements, 10, 256, 256, + CL_ADAPTER_DXVA_KHR, SURFACE_FORMAT_G16R16, SHARED_HANDLE_ENABLED) + != 0) + { + log_error("\nTest case (DXVA, G16R16, shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 512, 128, CL_ADAPTER_DXVA_KHR, + SURFACE_FORMAT_A8L8, SHARED_HANDLE_DISABLED) + != 0) + { + log_error("\nTest case (DXVA, A8L8, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 512, 128, CL_ADAPTER_DXVA_KHR, + SURFACE_FORMAT_A8L8, SHARED_HANDLE_ENABLED) + != 0) + { + log_error("\nTest case (DXVA, A8L8, shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 128, 512, CL_ADAPTER_DXVA_KHR, + SURFACE_FORMAT_A32B32G32R32F, + SHARED_HANDLE_DISABLED) + != 0) + { + log_error( + "\nTest case (DXVA, A32B32G32R32F, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 128, 512, CL_ADAPTER_DXVA_KHR, + SURFACE_FORMAT_A32B32G32R32F, + SHARED_HANDLE_ENABLED) + != 0) + { + log_error( + "\nTest case (DXVA, A32B32G32R32F, shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 128, 128, CL_ADAPTER_DXVA_KHR, + SURFACE_FORMAT_A16B16G16R16F, + SHARED_HANDLE_DISABLED) + != 0) + { + log_error( + "\nTest case (DXVA, A16B16G16R16F, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 128, 128, CL_ADAPTER_DXVA_KHR, + SURFACE_FORMAT_A16B16G16R16F, + SHARED_HANDLE_ENABLED) + != 0) + { + log_error( + "\nTest case (DXVA, A16B16G16R16F, shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 64, 128, CL_ADAPTER_DXVA_KHR, + SURFACE_FORMAT_A16B16G16R16, + SHARED_HANDLE_DISABLED) + != 0) + { + log_error( + "\nTest case (DXVA, A16B16G16R16, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 64, 128, CL_ADAPTER_DXVA_KHR, + SURFACE_FORMAT_A16B16G16R16, + SHARED_HANDLE_ENABLED) + != 0) + { + log_error("\nTest case (DXVA, A16B16G16R16, shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 128, 64, CL_ADAPTER_DXVA_KHR, + SURFACE_FORMAT_A8B8G8R8, + SHARED_HANDLE_DISABLED) + != 0) + { + log_error("\nTest case (DXVA, A8B8G8R8, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types( + deviceID, context, queue, num_elements, 10, 128, 64, + CL_ADAPTER_DXVA_KHR, SURFACE_FORMAT_A8B8G8R8, SHARED_HANDLE_ENABLED) + != 0) + { + log_error("\nTest case (DXVA, A8B8G8R8, shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 16, 512, CL_ADAPTER_DXVA_KHR, + SURFACE_FORMAT_X8B8G8R8, + SHARED_HANDLE_DISABLED) + != 0) + { + log_error("\nTest case (DXVA, X8B8G8R8, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types( + deviceID, context, queue, num_elements, 10, 16, 512, + CL_ADAPTER_DXVA_KHR, SURFACE_FORMAT_X8B8G8R8, SHARED_HANDLE_ENABLED) + != 0) + { + log_error("\nTest case (DXVA, X8B8G8R8, shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 512, 16, CL_ADAPTER_DXVA_KHR, + SURFACE_FORMAT_A8R8G8B8, + SHARED_HANDLE_DISABLED) + != 0) + { + log_error("\nTest case (DXVA, A8R8G8B8, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types( + deviceID, context, queue, num_elements, 10, 512, 16, + CL_ADAPTER_DXVA_KHR, SURFACE_FORMAT_A8R8G8B8, SHARED_HANDLE_ENABLED) + != 0) + { + log_error("\nTest case (DXVA, A8R8G8B8, shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types(deviceID, context, queue, num_elements, 10, + 256, 256, CL_ADAPTER_DXVA_KHR, + SURFACE_FORMAT_X8R8G8B8, + SHARED_HANDLE_DISABLED) + != 0) + { + log_error("\nTest case (DXVA, X8R8G8B8, no shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + + if (other_data_types( + deviceID, context, queue, num_elements, 10, 256, 256, + CL_ADAPTER_DXVA_KHR, SURFACE_FORMAT_X8R8G8B8, SHARED_HANDLE_ENABLED) + != 0) + { + log_error("\nTest case (DXVA, X8R8G8B8, shared handle) failed\n\n"); + result.ResultSub(CResult::TEST_FAIL); + } + +#else + return TEST_NOT_IMPLEMENTED; +#endif + + return result.Result(); +} diff --git a/test_conformance/extensions/cl_khr_dx9_media_sharing/utils.cpp b/test_conformance/extensions/cl_khr_dx9_media_sharing/utils.cpp new file mode 100644 index 00000000..87eb13c3 --- /dev/null +++ b/test_conformance/extensions/cl_khr_dx9_media_sharing/utils.cpp @@ -0,0 +1,1664 @@ +// +// 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 "utils.h" + +#include "harness/errorHelpers.h" +#include "harness/imageHelpers.h" +#include "harness/rounding_mode.h" + +#include + +#include + +static RoundingMode gFloatToHalfRoundingMode = kDefaultRoundingMode; + + +CResult::CResult(): _result(TEST_PASS), _resultLast(TEST_NORESULT) {} + +CResult::~CResult() {} + +CResult::TTestResult CResult::ResultLast() const { return _resultLast; } + +int CResult::Result() const +{ + switch (_result) + { + case TEST_NORESULT: + case TEST_NOTSUPPORTED: + case TEST_PASS: return 0; break; + case TEST_FAIL: return 1; break; + case TEST_ERROR: return 2; break; + default: return -1; break; + } +} + +void CResult::ResultSub(TTestResult result) +{ + _resultLast = result; + if (static_cast(result) > static_cast(_result)) _result = result; +} + +void FunctionContextCreateToString(TContextFuncType contextCreateFunction, + std::string &contextFunction) +{ + switch (contextCreateFunction) + { + case CONTEXT_CREATE_DEFAULT: contextFunction = "CreateContext"; break; + case CONTEXT_CREATE_FROM_TYPE: + contextFunction = "CreateContextFromType"; + break; + default: + contextFunction = "Unknown"; + log_error("FunctionContextCreateToString(): Unknown create " + "function enum!"); + break; + } +} + +void AdapterToString(cl_dx9_media_adapter_type_khr adapterType, + std::string &adapter) +{ + switch (adapterType) + { + case CL_ADAPTER_D3D9_KHR: adapter = "D3D9"; break; + case CL_ADAPTER_D3D9EX_KHR: adapter = "D3D9EX"; break; + case CL_ADAPTER_DXVA_KHR: adapter = "DXVA"; break; + default: + adapter = "Unknown"; + log_error("AdapterToString(): Unknown adapter type!"); + break; + } +} + +cl_context_info +AdapterTypeToContextInfo(cl_dx9_media_adapter_type_khr adapterType) +{ + switch (adapterType) + { + case CL_ADAPTER_D3D9_KHR: return CL_CONTEXT_ADAPTER_D3D9_KHR; break; + case CL_ADAPTER_D3D9EX_KHR: return CL_CONTEXT_ADAPTER_D3D9EX_KHR; break; + case CL_ADAPTER_DXVA_KHR: return CL_CONTEXT_ADAPTER_DXVA_KHR; break; + default: + log_error("AdapterTypeToContextInfo(): Unknown adapter type!"); + return 0; + break; + } +} + +void YUVGenerateNV12(std::vector &yuv, unsigned int width, + unsigned int height, cl_uchar valueMin, cl_uchar valueMax, + double valueAdd) +{ + yuv.clear(); + yuv.resize(width * height * 3 / 2, 0); + + double min = static_cast(valueMin); + double max = static_cast(valueMax); + double range = 255; + double add = static_cast(valueAdd * range); + double stepX = (max - min) / static_cast(width); + double stepY = (max - min) / static_cast(height); + + // generate Y plane + for (unsigned int i = 0; i < height; ++i) + { + unsigned int offset = i * width; + double valueYPlane0 = static_cast(stepY * i); + for (unsigned int j = 0; j < width; ++j) + { + double valueXPlane0 = static_cast(stepX * j); + yuv.at(offset + j) = static_cast( + min + valueXPlane0 / 2 + valueYPlane0 / 2 + add); + } + } + + // generate UV planes + for (unsigned int i = 0; i < height / 2; ++i) + { + unsigned int offset = width * height + i * width; + double valueYPlane1 = static_cast(stepY * i); + double valueYPlane2 = static_cast(stepY * (height / 2 + i)); + for (unsigned int j = 0; j < width / 2; ++j) + { + double valueXPlane1 = static_cast(stepX * j); + double valueXPlane2 = static_cast(stepX * (width / 2 + j)); + + yuv.at(offset + j * 2) = static_cast( + min + valueXPlane1 / 2 + valueYPlane1 / 2 + add); + yuv.at(offset + j * 2 + 1) = static_cast( + min + valueXPlane2 / 2 + valueYPlane2 / 2 + add); + } + } +} + +void YUVGenerateYV12(std::vector &yuv, unsigned int width, + unsigned int height, cl_uchar valueMin, cl_uchar valueMax, + double valueAdd /*= 0.0*/) +{ + yuv.clear(); + yuv.resize(width * height * 3 / 2, 0); + + double min = static_cast(valueMin); + double max = static_cast(valueMax); + double range = 255; + double add = static_cast(valueAdd * range); + double stepX = (max - min) / static_cast(width); + double stepY = (max - min) / static_cast(height); + + unsigned offset = 0; + + // generate Y plane + for (unsigned int i = 0; i < height; ++i) + { + unsigned int plane0Offset = offset + i * width; + double valueYPlane0 = static_cast(stepY * i); + for (unsigned int j = 0; j < width; ++j) + { + double valueXPlane0 = static_cast(stepX * j); + yuv.at(plane0Offset + j) = static_cast( + min + valueXPlane0 / 2 + valueYPlane0 / 2 + add); + } + } + + // generate V plane + offset += width * height; + for (unsigned int i = 0; i < height / 2; ++i) + { + unsigned int plane1Offset = offset + i * width / 2; + double valueYPlane1 = static_cast(stepY * i); + for (unsigned int j = 0; j < width / 2; ++j) + { + double valueXPlane1 = static_cast(stepX * j); + yuv.at(plane1Offset + j) = static_cast( + min + valueXPlane1 / 2 + valueYPlane1 / 2 + add); + } + } + + // generate U plane + offset += width * height / 4; + for (unsigned int i = 0; i < height / 2; ++i) + { + unsigned int plane2Offset = offset + i * width / 2; + double valueYPlane2 = static_cast(stepY * (height / 2 + i)); + for (unsigned int j = 0; j < width / 2; ++j) + { + double valueXPlane2 = static_cast(stepX * j); + yuv.at(plane2Offset + j) = static_cast( + min + valueXPlane2 / 2 + valueYPlane2 / 2 + add); + } + } +} + + +bool YUVGenerate(TSurfaceFormat surfaceFormat, std::vector &yuv, + unsigned int width, unsigned int height, cl_uchar valueMin, + cl_uchar valueMax, double valueAdd /*= 0.0*/) +{ + switch (surfaceFormat) + { + case SURFACE_FORMAT_NV12: + YUVGenerateNV12(yuv, width, height, valueMin, valueMax, valueAdd); + break; + case SURFACE_FORMAT_YV12: + YUVGenerateYV12(yuv, width, height, valueMin, valueMax, valueAdd); + break; + default: + log_error("YUVGenerate(): Invalid surface type\n"); + return false; + break; + } + + return true; +} + +bool YUVSurfaceSetNV12(std::auto_ptr &surface, + const std::vector &yuv, unsigned int width, + unsigned int height) +{ +#if defined(_WIN32) + CD3D9SurfaceWrapper *d3dSurface = + static_cast(surface.get()); + D3DLOCKED_RECT rect; + if (FAILED((*d3dSurface)->LockRect(&rect, NULL, 0))) + { + log_error("YUVSurfaceSetNV12(): Surface lock failed\n"); + return false; + } + + size_t pitch = rect.Pitch / sizeof(cl_uchar); + size_t lineSize = width * sizeof(cl_uchar); + cl_uchar *ptr = static_cast(rect.pBits); + for (size_t y = 0; y < height; ++y) + memcpy(ptr + y * pitch, &yuv.at(y * width), lineSize); + + for (size_t y = 0; y < height / 2; ++y) + memcpy(ptr + height * pitch + y * pitch, + &yuv.at(width * height + y * width), lineSize); + + (*d3dSurface)->UnlockRect(); + + return true; + +#else + return false; +#endif +} + +bool YUVSurfaceSetYV12(std::auto_ptr &surface, + const std::vector &yuv, unsigned int width, + unsigned int height) +{ +#if defined(_WIN32) + CD3D9SurfaceWrapper *d3dSurface = + static_cast(surface.get()); + D3DLOCKED_RECT rect; + if (FAILED((*d3dSurface)->LockRect(&rect, NULL, 0))) + { + log_error("YUVSurfaceSetYV12(): Surface lock failed!\n"); + return false; + } + + size_t pitch = rect.Pitch / sizeof(cl_uchar); + size_t pitchHalf = pitch / 2; + size_t lineSize = width * sizeof(cl_uchar); + size_t lineHalfSize = lineSize / 2; + size_t surfaceOffset = 0; + size_t yuvOffset = 0; + cl_uchar *ptr = static_cast(rect.pBits); + + for (size_t y = 0; y < height; ++y) + memcpy(ptr + surfaceOffset + y * pitch, &yuv.at(yuvOffset + y * width), + lineSize); + + surfaceOffset += height * pitch; + yuvOffset += width * height; + for (size_t y = 0; y < height / 2; ++y) + memcpy(ptr + surfaceOffset + y * pitchHalf, + &yuv.at(yuvOffset + y * lineHalfSize), lineHalfSize); + + surfaceOffset += pitchHalf * height / 2; + yuvOffset += width * height / 4; + for (size_t y = 0; y < height / 2; ++y) + memcpy(ptr + surfaceOffset + y * pitchHalf, + &yuv.at(yuvOffset + y * lineHalfSize), lineHalfSize); + + (*d3dSurface)->UnlockRect(); + + return true; + +#else + return false; +#endif +} + +bool YUVSurfaceSet(TSurfaceFormat surfaceFormat, + std::auto_ptr &surface, + const std::vector &yuv, unsigned int width, + unsigned int height) +{ + switch (surfaceFormat) + { + case SURFACE_FORMAT_NV12: + if (!YUVSurfaceSetNV12(surface, yuv, width, height)) return false; + break; + case SURFACE_FORMAT_YV12: + if (!YUVSurfaceSetYV12(surface, yuv, width, height)) return false; + break; + default: + log_error("YUVSurfaceSet(): Invalid surface type!\n"); + return false; + break; + } + + return true; +} + +bool YUVSurfaceGetNV12(std::auto_ptr &surface, + std::vector &yuv, unsigned int width, + unsigned int height) +{ +#if defined(_WIN32) + CD3D9SurfaceWrapper *d3dSurface = + static_cast(surface.get()); + D3DLOCKED_RECT rect; + if (FAILED((*d3dSurface)->LockRect(&rect, NULL, 0))) + { + log_error("YUVSurfaceGetNV12(): Surface lock failed!\n"); + return false; + } + + size_t pitch = rect.Pitch / sizeof(cl_uchar); + size_t lineSize = width * sizeof(cl_uchar); + cl_uchar *ptr = static_cast(rect.pBits); + size_t yuvOffset = 0; + size_t surfaceOffset = 0; + for (size_t y = 0; y < height; ++y) + memcpy(&yuv.at(yuvOffset + y * width), ptr + y * pitch, lineSize); + + yuvOffset += width * height; + surfaceOffset += pitch * height; + for (size_t y = 0; y < height / 2; ++y) + memcpy(&yuv.at(yuvOffset + y * width), ptr + surfaceOffset + y * pitch, + lineSize); + + (*d3dSurface)->UnlockRect(); + + return true; + +#else + return false; +#endif +} + +bool YUVSurfaceGetYV12(std::auto_ptr &surface, + std::vector &yuv, unsigned int width, + unsigned int height) +{ +#if defined(_WIN32) + CD3D9SurfaceWrapper *d3dSurface = + static_cast(surface.get()); + D3DLOCKED_RECT rect; + if (FAILED((*d3dSurface)->LockRect(&rect, NULL, 0))) + { + log_error("YUVSurfaceGetYV12(): Surface lock failed!\n"); + return false; + } + + size_t pitch = rect.Pitch / sizeof(cl_uchar); + size_t pitchHalf = pitch / 2; + size_t lineSize = width * sizeof(cl_uchar); + size_t lineHalfSize = lineSize / 2; + size_t surfaceOffset = 0; + size_t yuvOffset = 0; + cl_uchar *ptr = static_cast(rect.pBits); + + for (size_t y = 0; y < height; ++y) + memcpy(&yuv.at(yuvOffset + y * width), ptr + surfaceOffset + y * pitch, + lineSize); + + surfaceOffset += pitch * height; + yuvOffset += width * height; + for (size_t y = 0; y < height / 2; ++y) + memcpy(&yuv.at(yuvOffset + y * lineHalfSize), + ptr + surfaceOffset + y * pitchHalf, lineHalfSize); + + surfaceOffset += pitchHalf * height / 2; + yuvOffset += width * height / 4; + for (size_t y = 0; y < height / 2; ++y) + memcpy(&yuv.at(yuvOffset + y * lineHalfSize), + ptr + surfaceOffset + y * pitchHalf, lineHalfSize); + + (*d3dSurface)->UnlockRect(); + + return true; + +#else + return false; +#endif +} + +bool YUVSurfaceGet(TSurfaceFormat surfaceFormat, + std::auto_ptr &surface, + std::vector &yuv, unsigned int width, + unsigned int height) +{ + switch (surfaceFormat) + { + case SURFACE_FORMAT_NV12: + if (!YUVSurfaceGetNV12(surface, yuv, width, height)) return false; + break; + case SURFACE_FORMAT_YV12: + if (!YUVSurfaceGetYV12(surface, yuv, width, height)) return false; + break; + default: + log_error("YUVSurfaceGet(): Invalid surface type!\n"); + return false; + break; + } + + return true; +} + +bool YUVCompareNV12(const std::vector &yuvTest, + const std::vector &yuvRef, unsigned int width, + unsigned int height) +{ + // plane 0 verification + size_t offset = 0; + for (size_t y = 0; y < height; ++y) + { + size_t plane0Offset = offset + width * y; + for (size_t x = 0; x < width; ++x) + { + if (yuvTest[plane0Offset + x] != yuvRef[plane0Offset + x]) + { + log_error("Plane 0 (Y) is different than expected, reference " + "value: %i, test value: %i, x: %i, y: %i\n", + yuvRef[plane0Offset + x], yuvTest[plane0Offset + x], + x, y); + return false; + } + } + } + + // plane 1 and 2 verification + offset += width * height; + for (size_t y = 0; y < height / 2; ++y) + { + size_t plane12Offset = offset + width * y; + for (size_t x = 0; x < width / 2; ++x) + { + if (yuvTest.at(plane12Offset + 2 * x) + != yuvRef.at(plane12Offset + 2 * x)) + { + log_error("Plane 1 (U) is different than expected, reference " + "value: %i, test value: %i, x: %i, y: %i\n", + yuvRef[plane12Offset + 2 * x], + yuvTest[plane12Offset + 2 * x], x, y); + return false; + } + + if (yuvTest.at(plane12Offset + 2 * x + 1) + != yuvRef.at(plane12Offset + 2 * x + 1)) + { + log_error("Plane 2 (V) is different than expected, reference " + "value: %i, test value: %i, x: %i, y: %i\n", + yuvRef[plane12Offset + 2 * x + 1], + yuvTest[plane12Offset + 2 * x + 1], x, y); + return false; + } + } + } + + return true; +} + +bool YUVCompareYV12(const std::vector &yuvTest, + const std::vector &yuvRef, unsigned int width, + unsigned int height) +{ + // plane 0 verification + size_t offset = 0; + for (size_t y = 0; y < height; ++y) + { + size_t plane0Offset = width * y; + for (size_t x = 0; x < width; ++x) + { + if (yuvTest.at(plane0Offset + x) != yuvRef.at(plane0Offset + x)) + { + log_error("Plane 0 (Y) is different than expected, reference " + "value: %i, test value: %i, x: %i, y: %i\n", + yuvRef[plane0Offset + x], yuvTest[plane0Offset + x], + x, y); + return false; + } + } + } + + // plane 1 verification + offset += width * height; + for (size_t y = 0; y < height / 2; ++y) + { + size_t plane1Offset = offset + width * y / 2; + for (size_t x = 0; x < width / 2; ++x) + { + if (yuvTest.at(plane1Offset + x) != yuvRef.at(plane1Offset + x)) + { + log_error("Plane 1 (V) is different than expected, reference " + "value: %i, test value: %i, x: %i, y: %i\n", + yuvRef[plane1Offset + x], yuvTest[plane1Offset + x], + x, y); + return false; + } + } + } + + // plane 2 verification + offset += width * height / 4; + for (size_t y = 0; y < height / 2; ++y) + { + size_t plane2Offset = offset + width * y / 2; + for (size_t x = 0; x < width / 2; ++x) + { + if (yuvTest.at(plane2Offset + x) != yuvRef.at(plane2Offset + x)) + { + log_error("Plane 2 (U) is different than expected, reference " + "value: %i, test value: %i, x: %i, y: %i\n", + yuvRef[plane2Offset + x], yuvTest[plane2Offset + x], + x, y); + return false; + } + } + } + + return true; +} + +bool YUVCompare(TSurfaceFormat surfaceFormat, + const std::vector &yuvTest, + const std::vector &yuvRef, unsigned int width, + unsigned int height) +{ + switch (surfaceFormat) + { + case SURFACE_FORMAT_NV12: + if (!YUVCompareNV12(yuvTest, yuvRef, width, height)) + { + log_error("OCL object is different than expected!\n"); + return false; + } + break; + case SURFACE_FORMAT_YV12: + if (!YUVCompareYV12(yuvTest, yuvRef, width, height)) + { + log_error("OCL object is different than expected!\n"); + return false; + } + break; + default: + log_error("YUVCompare(): Invalid surface type!\n"); + return false; + break; + } + + return true; +} + +void DataGenerate(TSurfaceFormat surfaceFormat, cl_channel_type type, + std::vector &data, unsigned int width, + unsigned int height, unsigned int channelNum, + float cmin /*= 0.0f*/, float cmax /*= 1.0f*/, + float add /*= 0.0f*/) +{ + data.clear(); + data.reserve(width * height * channelNum); + + double valueMin = static_cast(cmin); + double valueMax = static_cast(cmax); + double stepX = (valueMax - valueMin) / static_cast(width); + double stepY = (valueMax - valueMin) / static_cast(height); + double valueAdd = static_cast(add); + for (unsigned int i = 0; i < height; ++i) + { + double valueY = static_cast(stepY * i); + for (unsigned int j = 0; j < width; ++j) + { + double valueX = static_cast(stepX * j); + switch (channelNum) + { + case 1: + data.push_back(static_cast(valueMin + valueX / 2 + + valueY / 2 + valueAdd)); + break; + case 2: + data.push_back( + static_cast(valueMin + valueX + valueAdd)); + data.push_back( + static_cast(valueMin + valueY + valueAdd)); + break; + case 4: + data.push_back( + static_cast(valueMin + valueX + valueAdd)); + data.push_back( + static_cast(valueMin + valueY + valueAdd)); + data.push_back( + static_cast(valueMin + valueX / 2 + valueAdd)); + data.push_back( + static_cast(valueMin + valueY / 2 + valueAdd)); + break; + default: + log_error("DataGenerate(): invalid channel number!"); + return; + break; + } + } + } +} + +void DataGenerate(TSurfaceFormat surfaceFormat, cl_channel_type type, + std::vector &data, unsigned int width, + unsigned int height, unsigned int channelNum, + float cmin /*= 0.0f*/, float cmax /*= 1.0f*/, + float add /*= 0.0f*/) +{ + data.clear(); + data.reserve(width * height * channelNum); + + double valueMin = static_cast(cmin); + double valueMax = static_cast(cmax); + double stepX = (valueMax - valueMin) / static_cast(width); + double stepY = (valueMax - valueMin) / static_cast(height); + + switch (type) + { + case CL_HALF_FLOAT: { + double valueAdd = static_cast(add); + + for (unsigned int i = 0; i < height; ++i) + { + double valueY = static_cast(stepY * i); + for (unsigned int j = 0; j < width; ++j) + { + double valueX = static_cast(stepX * j); + switch (channelNum) + { + case 1: + data.push_back(convert_float_to_half( + static_cast(valueMin + valueX / 2 + + valueY / 2 + valueAdd))); + break; + case 2: + data.push_back( + convert_float_to_half(static_cast( + valueMin + valueX + valueAdd))); + data.push_back( + convert_float_to_half(static_cast( + valueMin + valueY + valueAdd))); + break; + case 4: + data.push_back( + convert_float_to_half(static_cast( + valueMin + valueX + valueAdd))); + data.push_back( + convert_float_to_half(static_cast( + valueMin + valueY + valueAdd))); + data.push_back( + convert_float_to_half(static_cast( + valueMin + valueX / 2 + valueAdd))); + data.push_back( + convert_float_to_half(static_cast( + valueMin + valueY / 2 + valueAdd))); + break; + default: + log_error( + "DataGenerate(): invalid channel number!"); + return; + break; + } + } + } + break; + } + case CL_UNORM_INT16: { + double range = 65535; + double valueAdd = static_cast(add * range); + + for (unsigned int i = 0; i < height; ++i) + { + double valueY = static_cast(stepY * i * range); + for (unsigned int j = 0; j < width; ++j) + { + double valueX = static_cast(stepX * j * range); + switch (channelNum) + { + case 1: + data.push_back(static_cast( + valueMin + valueX / 2 + valueY / 2 + valueAdd)); + break; + case 2: + data.push_back(static_cast( + valueMin + valueX + valueAdd)); + data.push_back(static_cast( + valueMin + valueY + valueAdd)); + break; + case 4: + data.push_back(static_cast( + valueMin + valueX + valueAdd)); + data.push_back(static_cast( + valueMin + valueY + valueAdd)); + data.push_back(static_cast( + valueMin + valueX / 2 + valueAdd)); + data.push_back(static_cast( + valueMin + valueY / 2 + valueAdd)); + break; + default: + log_error( + "DataGenerate(): invalid channel number!"); + return; + break; + } + } + } + } + break; + default: + log_error("DataGenerate(): unknown data type!"); + return; + break; + } +} + +void DataGenerate(TSurfaceFormat surfaceFormat, cl_channel_type type, + std::vector &data, unsigned int width, + unsigned int height, unsigned int channelNum, + float cmin /*= 0.0f*/, float cmax /*= 1.0f*/, + float add /*= 0.0f*/) +{ + data.clear(); + data.reserve(width * height * channelNum); + + double valueMin = static_cast(cmin); + double valueMax = static_cast(cmax); + double stepX = (valueMax - valueMin) / static_cast(width); + double stepY = (valueMax - valueMin) / static_cast(height); + + double range = 255; + double valueAdd = static_cast(add * range); + + for (unsigned int i = 0; i < height; ++i) + { + double valueY = static_cast(stepY * i * range); + for (unsigned int j = 0; j < width; ++j) + { + double valueX = static_cast(stepX * j * range); + switch (channelNum) + { + case 1: + data.push_back(static_cast( + valueMin + valueX / 2 + valueY / 2 + valueAdd)); + break; + case 2: + data.push_back( + static_cast(valueMin + valueX + valueAdd)); + data.push_back( + static_cast(valueMin + valueY + valueAdd)); + break; + case 4: + data.push_back( + static_cast(valueMin + valueX + valueAdd)); + data.push_back( + static_cast(valueMin + valueY + valueAdd)); + data.push_back(static_cast(valueMin + valueX / 2 + + valueAdd)); + if (surfaceFormat == SURFACE_FORMAT_X8R8G8B8) + data.push_back(static_cast(0xff)); + else + data.push_back(static_cast( + valueMin + valueY / 2 + valueAdd)); + break; + default: + log_error("DataGenerate(): invalid channel number!"); + return; + break; + } + } + } +} + +bool DataCompare(TSurfaceFormat surfaceFormat, cl_channel_type type, + const std::vector &dataTest, + const std::vector &dataExp, unsigned int width, + unsigned int height, unsigned int channelNum) +{ + float epsilon = 0.000001f; + for (unsigned int i = 0; i < height; ++i) + { + unsigned int offset = i * width * channelNum; + for (unsigned int j = 0; j < width; ++j) + { + for (unsigned planeIdx = 0; planeIdx < channelNum; ++planeIdx) + { + if (abs(dataTest.at(offset + j * channelNum + planeIdx) + - dataExp.at(offset + j * channelNum + planeIdx)) + > epsilon) + { + log_error( + "Tested image is different than reference (x,y,plane) " + "= (%i,%i,%i), test value = %f, expected value = %f\n", + j, i, planeIdx, + dataTest[offset + j * channelNum + planeIdx], + dataExp[offset + j * channelNum + planeIdx]); + return false; + } + } + } + } + + return true; +} + +bool DataCompare(TSurfaceFormat surfaceFormat, cl_channel_type type, + const std::vector &dataTest, + const std::vector &dataExp, unsigned int width, + unsigned int height, unsigned int channelNum) +{ + switch (type) + { + case CL_HALF_FLOAT: { + float epsilon = 0.001f; + for (unsigned int i = 0; i < height; ++i) + { + unsigned int offset = i * width * channelNum; + for (unsigned int j = 0; j < width; ++j) + { + for (unsigned planeIdx = 0; planeIdx < channelNum; + ++planeIdx) + { + float test = cl_half_to_float( + dataTest.at(offset + j * channelNum + planeIdx)); + float ref = cl_half_to_float( + dataExp.at(offset + j * channelNum + planeIdx)); + if (abs(test - ref) > epsilon) + { + log_error("Tested image is different than " + "reference (x,y,plane) = " + "(%i,%i,%i), test value = %f, expected " + "value = %f\n", + j, i, planeIdx, test, ref); + return false; + } + } + } + } + } + break; + case CL_UNORM_INT16: { + cl_ushort epsilon = 1; + for (unsigned int i = 0; i < height; ++i) + { + unsigned int offset = i * width * channelNum; + for (unsigned int j = 0; j < width; ++j) + { + for (unsigned planeIdx = 0; planeIdx < channelNum; + ++planeIdx) + { + cl_ushort test = + dataTest.at(offset + j * channelNum + planeIdx); + cl_ushort ref = + dataExp.at(offset + j * channelNum + planeIdx); + if (abs(test - ref) > epsilon) + { + log_error("Tested image is different than " + "reference (x,y,plane) = (%i,%i,%i), " + "test value = %i, expected value = %i\n", + j, i, planeIdx, test, ref); + return false; + } + } + } + } + } + break; + default: + log_error("DataCompare(): Invalid data format!"); + return false; + break; + } + + return true; +} + +bool DataCompare(TSurfaceFormat surfaceFormat, cl_channel_type type, + const std::vector &dataTest, + const std::vector &dataExp, unsigned int width, + unsigned int height, unsigned int planeNum) +{ + for (unsigned int i = 0; i < height; ++i) + { + unsigned int offset = i * width * planeNum; + for (unsigned int j = 0; j < width; ++j) + { + for (unsigned planeIdx = 0; planeIdx < planeNum; ++planeIdx) + { + if (surfaceFormat == SURFACE_FORMAT_X8R8G8B8 && planeIdx == 3) + continue; + + cl_uchar test = dataTest.at(offset + j * planeNum + planeIdx); + cl_uchar ref = dataExp.at(offset + j * planeNum + planeIdx); + if (test != ref) + { + log_error( + "Tested image is different than reference (x,y,plane) " + "= (%i,%i,%i), test value = %i, expected value = %i\n", + j, i, planeIdx, test, ref); + return false; + } + } + } + } + + return true; +} + +bool GetImageInfo(cl_mem object, cl_image_format formatExp, + size_t elementSizeExp, size_t rowPitchExp, + size_t slicePitchExp, size_t widthExp, size_t heightExp, + size_t depthExp, unsigned int planeExp) +{ + bool result = true; + + cl_image_format format; + if (clGetImageInfo(object, CL_IMAGE_FORMAT, sizeof(cl_image_format), + &format, 0) + != CL_SUCCESS) + { + log_error("clGetImageInfo(CL_IMAGE_FORMAT) failed\n"); + result = false; + } + + if (formatExp.image_channel_order != format.image_channel_order + || formatExp.image_channel_data_type != format.image_channel_data_type) + { + log_error("Value of CL_IMAGE_FORMAT is different than expected\n"); + result = false; + } + + size_t elementSize = 0; + if (clGetImageInfo(object, CL_IMAGE_ELEMENT_SIZE, sizeof(size_t), + &elementSize, 0) + != CL_SUCCESS) + { + log_error("clGetImageInfo(CL_IMAGE_ELEMENT_SIZE) failed\n"); + result = false; + } + + if (elementSizeExp != elementSize) + { + log_error("Value of CL_IMAGE_ELEMENT_SIZE is different than expected " + "(size: %i, exp size: %i)\n", + elementSize, elementSizeExp); + result = false; + } + + size_t rowPitch = 0; + if (clGetImageInfo(object, CL_IMAGE_ROW_PITCH, sizeof(size_t), &rowPitch, 0) + != CL_SUCCESS) + { + log_error("clGetImageInfo(CL_IMAGE_ROW_PITCH) failed\n"); + result = false; + } + + if ((rowPitchExp == 0 && rowPitchExp != rowPitch) + || (rowPitchExp > 0 && rowPitchExp > rowPitch)) + { + log_error("Value of CL_IMAGE_ROW_PITCH is different than expected " + "(size: %i, exp size: %i)\n", + rowPitch, rowPitchExp); + result = false; + } + + size_t slicePitch = 0; + if (clGetImageInfo(object, CL_IMAGE_SLICE_PITCH, sizeof(size_t), + &slicePitch, 0) + != CL_SUCCESS) + { + log_error("clGetImageInfo(CL_IMAGE_SLICE_PITCH) failed\n"); + result = false; + } + + if ((slicePitchExp == 0 && slicePitchExp != slicePitch) + || (slicePitchExp > 0 && slicePitchExp > slicePitch)) + { + log_error("Value of CL_IMAGE_SLICE_PITCH is different than expected " + "(size: %i, exp size: %i)\n", + slicePitch, slicePitchExp); + result = false; + } + + size_t width = 0; + if (clGetImageInfo(object, CL_IMAGE_WIDTH, sizeof(size_t), &width, 0) + != CL_SUCCESS) + { + log_error("clGetImageInfo(CL_IMAGE_WIDTH) failed\n"); + result = false; + } + + if (widthExp != width) + { + log_error("Value of CL_IMAGE_WIDTH is different than expected (size: " + "%i, exp size: %i)\n", + width, widthExp); + result = false; + } + + size_t height = 0; + if (clGetImageInfo(object, CL_IMAGE_HEIGHT, sizeof(size_t), &height, 0) + != CL_SUCCESS) + { + log_error("clGetImageInfo(CL_IMAGE_HEIGHT) failed\n"); + result = false; + } + + if (heightExp != height) + { + log_error("Value of CL_IMAGE_HEIGHT is different than expected (size: " + "%i, exp size: %i)\n", + height, heightExp); + result = false; + } + + size_t depth = 0; + if (clGetImageInfo(object, CL_IMAGE_DEPTH, sizeof(size_t), &depth, 0) + != CL_SUCCESS) + { + log_error("clGetImageInfo(CL_IMAGE_DEPTH) failed\n"); + result = false; + } + + if (depthExp != depth) + { + log_error("Value of CL_IMAGE_DEPTH is different than expected (size: " + "%i, exp size: %i)\n", + depth, depthExp); + result = false; + } + + unsigned int plane = 99; + size_t paramSize = 0; + if (clGetImageInfo(object, CL_IMAGE_DX9_MEDIA_PLANE_KHR, + sizeof(unsigned int), &plane, ¶mSize) + != CL_SUCCESS) + { + log_error("clGetImageInfo(CL_IMAGE_MEDIA_SURFACE_PLANE_KHR) failed\n"); + result = false; + } + + if (planeExp != plane) + { + log_error("Value of CL_IMAGE_MEDIA_SURFACE_PLANE_KHR is different than " + "expected (plane: %i, exp plane: %i)\n", + plane, planeExp); + result = false; + } + + return result; +} + +bool GetMemObjInfo(cl_mem object, cl_dx9_media_adapter_type_khr adapterType, + std::auto_ptr &surface, + void *shareHandleExp) +{ + bool result = true; + switch (adapterType) + { + case CL_ADAPTER_D3D9_KHR: + case CL_ADAPTER_D3D9EX_KHR: + case CL_ADAPTER_DXVA_KHR: { +#if defined(_WIN32) + cl_dx9_surface_info_khr surfaceInfo; +#else + void *surfaceInfo = 0; + return false; +#endif + size_t paramSize = 0; + if (clGetMemObjectInfo(object, CL_MEM_DX9_MEDIA_SURFACE_INFO_KHR, + sizeof(surfaceInfo), &surfaceInfo, + ¶mSize) + != CL_SUCCESS) + { + log_error("clGetImageInfo(CL_MEM_DX9_MEDIA_SURFACE_INFO_KHR) " + "failed\n"); + result = false; + } + +#if defined(_WIN32) + CD3D9SurfaceWrapper *d3d9Surface = + static_cast(surface.get()); + if (*d3d9Surface != surfaceInfo.resource) + { + log_error( + "Invalid resource for CL_MEM_DX9_MEDIA_SURFACE_INFO_KHR\n"); + result = false; + } + + if (shareHandleExp != surfaceInfo.shared_handle) + { + log_error("Invalid shared handle for " + "CL_MEM_DX9_MEDIA_SURFACE_INFO_KHR\n"); + result = false; + } +#else + return false; +#endif + + if (paramSize != sizeof(surfaceInfo)) + { + log_error("Invalid CL_MEM_DX9_MEDIA_SURFACE_INFO_KHR parameter " + "size: %i, expected: %i\n", + paramSize, sizeof(surfaceInfo)); + result = false; + } + + paramSize = 0; + cl_dx9_media_adapter_type_khr mediaAdapterType; + if (clGetMemObjectInfo(object, CL_MEM_DX9_MEDIA_ADAPTER_TYPE_KHR, + sizeof(mediaAdapterType), &mediaAdapterType, + ¶mSize) + != CL_SUCCESS) + { + log_error("clGetImageInfo(CL_MEM_DX9_MEDIA_ADAPTER_TYPE_KHR) " + "failed\n"); + result = false; + } + + if (adapterType != mediaAdapterType) + { + log_error("Invalid media adapter type for " + "CL_MEM_DX9_MEDIA_ADAPTER_TYPE_KHR\n"); + result = false; + } + + if (paramSize != sizeof(mediaAdapterType)) + { + log_error("Invalid CL_MEM_DX9_MEDIA_ADAPTER_TYPE_KHR parameter " + "size: %i, expected: %i\n", + paramSize, sizeof(mediaAdapterType)); + result = false; + } + } + break; + default: + log_error("GetMemObjInfo(): Unknown adapter type!\n"); + return false; + break; + } + + return result; +} + +bool ImageInfoVerify(cl_dx9_media_adapter_type_khr adapterType, + const std::vector &memObjList, unsigned int width, + unsigned int height, + std::auto_ptr &surface, + void *sharedHandle) +{ + if (memObjList.size() != 2 && memObjList.size() != 3) + { + log_error("ImageInfoVerify(): Invalid object list parameter\n"); + return false; + } + + cl_image_format formatPlane; + formatPlane.image_channel_data_type = CL_UNORM_INT8; + formatPlane.image_channel_order = CL_R; + + // plane 0 verification + if (!GetImageInfo(memObjList[0], formatPlane, sizeof(cl_uchar), + width * sizeof(cl_uchar), 0, width, height, 0, 0)) + { + log_error("clGetImageInfo failed\n"); + return false; + } + + switch (memObjList.size()) + { + case 2: { + formatPlane.image_channel_data_type = CL_UNORM_INT8; + formatPlane.image_channel_order = CL_RG; + if (!GetImageInfo(memObjList[1], formatPlane, sizeof(cl_uchar) * 2, + width * sizeof(cl_uchar), 0, width / 2, + height / 2, 0, 1)) + { + log_error("clGetImageInfo failed\n"); + return false; + } + } + break; + case 3: { + if (!GetImageInfo(memObjList[1], formatPlane, sizeof(cl_uchar), + width * sizeof(cl_uchar) / 2, 0, width / 2, + height / 2, 0, 1)) + { + log_error("clGetImageInfo failed\n"); + return false; + } + + if (!GetImageInfo(memObjList[2], formatPlane, sizeof(cl_uchar), + width * sizeof(cl_uchar) / 2, 0, width / 2, + height / 2, 0, 2)) + { + log_error("clGetImageInfo failed\n"); + return false; + } + } + break; + default: + log_error("ImageInfoVerify(): Invalid object list parameter\n"); + return false; + break; + } + + for (size_t i = 0; i < memObjList.size(); ++i) + { + if (!GetMemObjInfo(memObjList[i], adapterType, surface, sharedHandle)) + { + log_error("clGetMemObjInfo(%i) failed\n", i); + return false; + } + } + + return true; +} + +bool ImageFormatCheck(cl_context context, cl_mem_object_type imageType, + const cl_image_format imageFormatCheck) +{ + cl_uint imageFormatsNum = 0; + cl_int error = clGetSupportedImageFormats( + context, CL_MEM_READ_WRITE, imageType, 0, 0, &imageFormatsNum); + if (error != CL_SUCCESS) + { + log_error("clGetSupportedImageFormats failed\n"); + return false; + } + + if (imageFormatsNum < 1) + { + log_error("Invalid image format number returned by " + "clGetSupportedImageFormats\n"); + return false; + } + + std::vector imageFormats(imageFormatsNum); + error = clGetSupportedImageFormats(context, CL_MEM_READ_WRITE, imageType, + imageFormatsNum, &imageFormats[0], 0); + if (error != CL_SUCCESS) + { + log_error("clGetSupportedImageFormats failed\n"); + return false; + } + + for (cl_uint i = 0; i < imageFormatsNum; ++i) + { + if (imageFormats[i].image_channel_data_type + == imageFormatCheck.image_channel_data_type + && imageFormats[i].image_channel_order + == imageFormatCheck.image_channel_order) + { + return true; + } + } + + return false; +} + +unsigned int ChannelNum(TSurfaceFormat surfaceFormat) +{ + switch (surfaceFormat) + { + case SURFACE_FORMAT_R32F: + case SURFACE_FORMAT_R16F: + case SURFACE_FORMAT_L16: + case SURFACE_FORMAT_A8: + case SURFACE_FORMAT_L8: return 1; break; + case SURFACE_FORMAT_G32R32F: + case SURFACE_FORMAT_G16R16F: + case SURFACE_FORMAT_G16R16: + case SURFACE_FORMAT_A8L8: return 2; break; + case SURFACE_FORMAT_NV12: + case SURFACE_FORMAT_YV12: return 3; break; + case SURFACE_FORMAT_A32B32G32R32F: + case SURFACE_FORMAT_A16B16G16R16F: + case SURFACE_FORMAT_A16B16G16R16: + case SURFACE_FORMAT_A8B8G8R8: + case SURFACE_FORMAT_X8B8G8R8: + case SURFACE_FORMAT_A8R8G8B8: + case SURFACE_FORMAT_X8R8G8B8: return 4; break; + default: + log_error("ChannelNum(): unknown surface format!\n"); + return 0; + break; + } +} + +unsigned int PlanesNum(TSurfaceFormat surfaceFormat) +{ + switch (surfaceFormat) + { + case SURFACE_FORMAT_R32F: + case SURFACE_FORMAT_R16F: + case SURFACE_FORMAT_L16: + case SURFACE_FORMAT_A8: + case SURFACE_FORMAT_L8: + case SURFACE_FORMAT_G32R32F: + case SURFACE_FORMAT_G16R16F: + case SURFACE_FORMAT_G16R16: + case SURFACE_FORMAT_A8L8: + case SURFACE_FORMAT_A32B32G32R32F: + case SURFACE_FORMAT_A16B16G16R16F: + case SURFACE_FORMAT_A16B16G16R16: + case SURFACE_FORMAT_A8B8G8R8: + case SURFACE_FORMAT_X8B8G8R8: + case SURFACE_FORMAT_A8R8G8B8: + case SURFACE_FORMAT_X8R8G8B8: return 1; break; + case SURFACE_FORMAT_NV12: return 2; break; + case SURFACE_FORMAT_YV12: return 3; break; + default: + log_error("PlanesNum(): unknown surface format!\n"); + return 0; + break; + } +} + +#if defined(_WIN32) +D3DFORMAT SurfaceFormatToD3D(TSurfaceFormat surfaceFormat) +{ + switch (surfaceFormat) + { + case SURFACE_FORMAT_R32F: return D3DFMT_R32F; break; + case SURFACE_FORMAT_R16F: return D3DFMT_R16F; break; + case SURFACE_FORMAT_L16: return D3DFMT_L16; break; + case SURFACE_FORMAT_A8: return D3DFMT_A8; break; + case SURFACE_FORMAT_L8: return D3DFMT_L8; break; + case SURFACE_FORMAT_G32R32F: return D3DFMT_G32R32F; break; + case SURFACE_FORMAT_G16R16F: return D3DFMT_G16R16F; break; + case SURFACE_FORMAT_G16R16: return D3DFMT_G16R16; break; + case SURFACE_FORMAT_A8L8: return D3DFMT_A8L8; break; + case SURFACE_FORMAT_A32B32G32R32F: return D3DFMT_A32B32G32R32F; break; + case SURFACE_FORMAT_A16B16G16R16F: return D3DFMT_A16B16G16R16F; break; + case SURFACE_FORMAT_A16B16G16R16: return D3DFMT_A16B16G16R16; break; + case SURFACE_FORMAT_A8B8G8R8: return D3DFMT_A8B8G8R8; break; + case SURFACE_FORMAT_X8B8G8R8: return D3DFMT_X8B8G8R8; break; + case SURFACE_FORMAT_A8R8G8B8: return D3DFMT_A8R8G8B8; break; + case SURFACE_FORMAT_X8R8G8B8: return D3DFMT_X8R8G8B8; break; + case SURFACE_FORMAT_NV12: + return static_cast(MAKEFOURCC('N', 'V', '1', '2')); + break; + case SURFACE_FORMAT_YV12: + return static_cast(MAKEFOURCC('Y', 'V', '1', '2')); + break; + default: + log_error("SurfaceFormatToD3D(): unknown surface format!\n"); + return D3DFMT_R32F; + break; + } +} +#endif + +bool DeviceCreate(cl_dx9_media_adapter_type_khr adapterType, + std::auto_ptr &device) +{ + switch (adapterType) + { +#if defined(_WIN32) + case CL_ADAPTER_D3D9_KHR: + device = std::auto_ptr(new CD3D9Wrapper()); + break; + case CL_ADAPTER_D3D9EX_KHR: + device = std::auto_ptr(new CD3D9ExWrapper()); + break; + case CL_ADAPTER_DXVA_KHR: + device = std::auto_ptr(new CDXVAWrapper()); + break; +#endif + default: + log_error("DeviceCreate(): Unknown adapter type!\n"); + return false; + break; + } + + return device->Status(); +} + +bool SurfaceFormatCheck(cl_dx9_media_adapter_type_khr adapterType, + const CDeviceWrapper &device, + TSurfaceFormat surfaceFormat) +{ + switch (adapterType) + { +#if defined(_WIN32) + case CL_ADAPTER_D3D9_KHR: + case CL_ADAPTER_D3D9EX_KHR: + case CL_ADAPTER_DXVA_KHR: { + D3DFORMAT d3dFormat = SurfaceFormatToD3D(surfaceFormat); + LPDIRECT3D9 d3d9 = static_cast(device.D3D()); + D3DDISPLAYMODE d3ddm; + d3d9->GetAdapterDisplayMode(device.AdapterIdx(), &d3ddm); + + if (FAILED(d3d9->CheckDeviceFormat(D3DADAPTER_DEFAULT, + D3DDEVTYPE_HAL, d3ddm.Format, 0, + D3DRTYPE_SURFACE, d3dFormat))) + return false; + } + break; +#endif + default: + log_error("SurfaceFormatCheck(): Unknown adapter type!\n"); + return false; + break; + } + + return true; +} + +bool SurfaceFormatToOCL(TSurfaceFormat surfaceFormat, cl_image_format &format) +{ + switch (surfaceFormat) + { + case SURFACE_FORMAT_R32F: + format.image_channel_order = CL_R; + format.image_channel_data_type = CL_FLOAT; + break; + case SURFACE_FORMAT_R16F: + format.image_channel_order = CL_R; + format.image_channel_data_type = CL_HALF_FLOAT; + break; + case SURFACE_FORMAT_L16: + format.image_channel_order = CL_R; + format.image_channel_data_type = CL_UNORM_INT16; + break; + case SURFACE_FORMAT_A8: + format.image_channel_order = CL_A; + format.image_channel_data_type = CL_UNORM_INT8; + break; + case SURFACE_FORMAT_L8: + format.image_channel_order = CL_R; + format.image_channel_data_type = CL_UNORM_INT8; + break; + case SURFACE_FORMAT_G32R32F: + format.image_channel_order = CL_RG; + format.image_channel_data_type = CL_FLOAT; + break; + case SURFACE_FORMAT_G16R16F: + format.image_channel_order = CL_RG; + format.image_channel_data_type = CL_HALF_FLOAT; + break; + case SURFACE_FORMAT_G16R16: + format.image_channel_order = CL_RG; + format.image_channel_data_type = CL_UNORM_INT16; + break; + case SURFACE_FORMAT_A8L8: + format.image_channel_order = CL_RG; + format.image_channel_data_type = CL_UNORM_INT8; + break; + case SURFACE_FORMAT_A32B32G32R32F: + format.image_channel_order = CL_RGBA; + format.image_channel_data_type = CL_FLOAT; + break; + case SURFACE_FORMAT_A16B16G16R16F: + format.image_channel_order = CL_RGBA; + format.image_channel_data_type = CL_HALF_FLOAT; + break; + case SURFACE_FORMAT_A16B16G16R16: + format.image_channel_order = CL_RGBA; + format.image_channel_data_type = CL_UNORM_INT16; + break; + case SURFACE_FORMAT_A8B8G8R8: + format.image_channel_order = CL_RGBA; + format.image_channel_data_type = CL_UNORM_INT8; + break; + case SURFACE_FORMAT_X8B8G8R8: + format.image_channel_order = CL_RGBA; + format.image_channel_data_type = CL_UNORM_INT8; + break; + case SURFACE_FORMAT_A8R8G8B8: + format.image_channel_order = CL_BGRA; + format.image_channel_data_type = CL_UNORM_INT8; + break; + case SURFACE_FORMAT_X8R8G8B8: + format.image_channel_order = CL_BGRA; + format.image_channel_data_type = CL_UNORM_INT8; + break; + case SURFACE_FORMAT_NV12: + format.image_channel_order = CL_R; + format.image_channel_data_type = CL_UNORM_INT8; + break; + case SURFACE_FORMAT_YV12: + format.image_channel_order = CL_R; + format.image_channel_data_type = CL_UNORM_INT8; + break; + default: + log_error("SurfaceFormatToOCL(): Unknown surface format!\n"); + return false; + break; + } + + return true; +} + +void SurfaceFormatToString(TSurfaceFormat surfaceFormat, std::string &str) +{ + switch (surfaceFormat) + { + case SURFACE_FORMAT_R32F: str = "R32F"; break; + case SURFACE_FORMAT_R16F: str = "R16F"; break; + case SURFACE_FORMAT_L16: str = "L16"; break; + case SURFACE_FORMAT_A8: str = "A8"; break; + case SURFACE_FORMAT_L8: str = "L8"; break; + case SURFACE_FORMAT_G32R32F: str = "G32R32F"; break; + case SURFACE_FORMAT_G16R16F: str = "G16R16F"; break; + case SURFACE_FORMAT_G16R16: str = "G16R16"; break; + case SURFACE_FORMAT_A8L8: str = "A8L8"; break; + case SURFACE_FORMAT_A32B32G32R32F: str = "A32B32G32R32F"; break; + case SURFACE_FORMAT_A16B16G16R16F: str = "A16B16G16R16F"; break; + case SURFACE_FORMAT_A16B16G16R16: str = "A16B16G16R16"; break; + case SURFACE_FORMAT_A8B8G8R8: str = "A8B8G8R8"; break; + case SURFACE_FORMAT_X8B8G8R8: str = "X8B8G8R8"; break; + case SURFACE_FORMAT_A8R8G8B8: str = "A8R8G8B8"; break; + case SURFACE_FORMAT_X8R8G8B8: str = "X8R8G8B8"; break; + case SURFACE_FORMAT_NV12: str = "NV12"; break; + case SURFACE_FORMAT_YV12: str = "YV12"; break; + default: + log_error("SurfaceFormatToString(): unknown surface format!\n"); + str = "unknown"; + break; + } +} + +bool MediaSurfaceCreate(cl_dx9_media_adapter_type_khr adapterType, + unsigned int width, unsigned int height, + TSurfaceFormat surfaceFormat, CDeviceWrapper &device, + std::auto_ptr &surface, + bool sharedHandle, void **objectSharedHandle) +{ + switch (adapterType) + { +#if defined(_WIN32) + case CL_ADAPTER_D3D9_KHR: { + surface = + std::auto_ptr(new CD3D9SurfaceWrapper); + CD3D9SurfaceWrapper *d3dSurface = + static_cast(surface.get()); + HRESULT hr = 0; + D3DFORMAT d3dFormat = SurfaceFormatToD3D(surfaceFormat); + LPDIRECT3DDEVICE9 d3d9Device = (LPDIRECT3DDEVICE9)device.Device(); + hr = d3d9Device->CreateOffscreenPlainSurface( + width, height, d3dFormat, D3DPOOL_DEFAULT, &(*d3dSurface), + sharedHandle ? objectSharedHandle : 0); + + if (FAILED(hr)) + { + log_error("CreateOffscreenPlainSurface failed\n"); + return false; + } + } + break; + case CL_ADAPTER_D3D9EX_KHR: { + surface = + std::auto_ptr(new CD3D9SurfaceWrapper); + CD3D9SurfaceWrapper *d3dSurface = + static_cast(surface.get()); + HRESULT hr = 0; + D3DFORMAT d3dFormat = SurfaceFormatToD3D(surfaceFormat); + LPDIRECT3DDEVICE9EX d3d9ExDevice = + (LPDIRECT3DDEVICE9EX)device.Device(); + hr = d3d9ExDevice->CreateOffscreenPlainSurface( + width, height, d3dFormat, D3DPOOL_DEFAULT, &(*d3dSurface), + sharedHandle ? objectSharedHandle : 0); + + if (FAILED(hr)) + { + log_error("CreateOffscreenPlainSurface failed\n"); + return false; + } + } + break; + case CL_ADAPTER_DXVA_KHR: { + surface = + std::auto_ptr(new CD3D9SurfaceWrapper); + CD3D9SurfaceWrapper *d3dSurface = + static_cast(surface.get()); + HRESULT hr = 0; + D3DFORMAT d3dFormat = SurfaceFormatToD3D(surfaceFormat); + IDXVAHD_Device *dxvaDevice = (IDXVAHD_Device *)device.Device(); + hr = dxvaDevice->CreateVideoSurface( + width, height, d3dFormat, D3DPOOL_DEFAULT, 0, + DXVAHD_SURFACE_TYPE_VIDEO_INPUT, 1, &(*d3dSurface), + sharedHandle ? objectSharedHandle : 0); + + if (FAILED(hr)) + { + log_error("CreateVideoSurface failed\n"); + return false; + } + } + break; +#endif + default: + log_error("MediaSurfaceCreate(): Unknown adapter type!\n"); + return false; + break; + } + + return true; +} + +cl_int deviceExistForCLTest( + cl_platform_id platform, cl_dx9_media_adapter_type_khr media_adapters_type, + void *media_adapters, CResult &result, + TSharedHandleType sharedHandle /*default SHARED_HANDLE_ENABLED*/ +) +{ + cl_int _error; + cl_uint devicesAllNum = 0; + std::string sharedHandleStr = + (sharedHandle == SHARED_HANDLE_ENABLED) ? "yes" : "no"; + std::string adapterStr; + AdapterToString(media_adapters_type, adapterStr); + + _error = clGetDeviceIDsFromDX9MediaAdapterKHR( + platform, 1, &media_adapters_type, &media_adapters, + CL_PREFERRED_DEVICES_FOR_DX9_MEDIA_ADAPTER_KHR, 0, 0, &devicesAllNum); + + if (_error != CL_SUCCESS) + { + if (_error != CL_DEVICE_NOT_FOUND) + { + log_error("clGetDeviceIDsFromDX9MediaAdapterKHR failed: %s\n", + IGetErrorString(_error)); + result.ResultSub(CResult::TEST_ERROR); + } + else + { + log_info("Skipping test case, device type is not supported by a " + "device (adapter type: %s, shared handle: %s)\n", + adapterStr.c_str(), sharedHandleStr.c_str()); + result.ResultSub(CResult::TEST_NOTSUPPORTED); + } + } + + return _error; +} diff --git a/test_conformance/extensions/cl_khr_dx9_media_sharing/utils.h b/test_conformance/extensions/cl_khr_dx9_media_sharing/utils.h new file mode 100644 index 00000000..56c0fc2c --- /dev/null +++ b/test_conformance/extensions/cl_khr_dx9_media_sharing/utils.h @@ -0,0 +1,215 @@ +// +// 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. +// +#ifndef __UTILS_KHR_MEDIA_H +#define __UTILS_KHR_MEDIA_H + +#include +#include +#include +#include +#include "wrappers.h" +#include "CL/cl_dx9_media_sharing.h" + +#include "harness/typeWrappers.h" + + +extern clGetDeviceIDsFromDX9MediaAdapterKHR_fn + clGetDeviceIDsFromDX9MediaAdapterKHR; +extern clCreateFromDX9MediaSurfaceKHR_fn clCreateFromDX9MediaSurfaceKHR; +extern clEnqueueAcquireDX9MediaSurfacesKHR_fn + clEnqueueAcquireDX9MediaSurfacesKHR; +extern clEnqueueReleaseDX9MediaSurfacesKHR_fn + clEnqueueReleaseDX9MediaSurfacesKHR; + +extern cl_platform_id gPlatformIDdetected; +extern cl_device_id gDeviceIDdetected; +extern cl_device_type gDeviceTypeSelected; + +#define NL "\n" +#define TEST_NOT_IMPLEMENTED -1 +#define TEST_NOT_SUPPORTED -2 + +enum TSurfaceFormat +{ + SURFACE_FORMAT_NV12, + SURFACE_FORMAT_YV12, + SURFACE_FORMAT_R32F, + SURFACE_FORMAT_R16F, + SURFACE_FORMAT_L16, + SURFACE_FORMAT_A8, + SURFACE_FORMAT_L8, + SURFACE_FORMAT_G32R32F, + SURFACE_FORMAT_G16R16F, + SURFACE_FORMAT_G16R16, + SURFACE_FORMAT_A8L8, + SURFACE_FORMAT_A32B32G32R32F, + SURFACE_FORMAT_A16B16G16R16F, + SURFACE_FORMAT_A16B16G16R16, + SURFACE_FORMAT_A8B8G8R8, + SURFACE_FORMAT_X8B8G8R8, + SURFACE_FORMAT_A8R8G8B8, + SURFACE_FORMAT_X8R8G8B8, +}; + +enum TContextFuncType +{ + CONTEXT_CREATE_DEFAULT, + CONTEXT_CREATE_FROM_TYPE, +}; + +enum TSharedHandleType +{ + SHARED_HANDLE_ENABLED, + SHARED_HANDLE_DISABLED, +}; + +class CResult { +public: + enum TTestResult + { + TEST_NORESULT, + TEST_NOTSUPPORTED, + TEST_PASS, + TEST_FAIL, + TEST_ERROR, + }; + + CResult(); + ~CResult(); + + void ResultSub(TTestResult result); + TTestResult ResultLast() const; + int Result() const; + +private: + TTestResult _result; + TTestResult _resultLast; +}; + +void FunctionContextCreateToString(TContextFuncType contextCreateFunction, + std::string &contextFunction); +void AdapterToString(cl_dx9_media_adapter_type_khr adapterType, + std::string &adapter); +cl_context_info +AdapterTypeToContextInfo(cl_dx9_media_adapter_type_khr adapterType); + +// YUV utils +void YUVGenerateNV12(std::vector &yuv, unsigned int width, + unsigned int height, cl_uchar valueMin, cl_uchar valueMax, + double valueAdd = 0.0); +void YUVGenerateYV12(std::vector &yuv, unsigned int width, + unsigned int height, cl_uchar valueMin, cl_uchar valueMax, + double valueAdd = 0.0); +bool YUVGenerate(TSurfaceFormat surfaceFormat, std::vector &yuv, + unsigned int width, unsigned int height, cl_uchar valueMin, + cl_uchar valueMax, double valueAdd = 0.0); +bool YUVSurfaceSetNV12(std::auto_ptr &surface, + const std::vector &yuv, unsigned int width, + unsigned int height); +bool YUVSurfaceSetYV12(std::auto_ptr &surface, + const std::vector &yuv, unsigned int width, + unsigned int height); +bool YUVSurfaceSet(TSurfaceFormat surfaceFormat, + std::auto_ptr &surface, + const std::vector &yuv, unsigned int width, + unsigned int height); +bool YUVSurfaceGetNV12(std::auto_ptr &surface, + std::vector &yuv, unsigned int width, + unsigned int height); +bool YUVSurfaceGetYV12(std::auto_ptr &surface, + std::vector &yuv, unsigned int width, + unsigned int height); +bool YUVSurfaceGet(TSurfaceFormat surfaceFormat, + std::auto_ptr &surface, + std::vector &yuv, unsigned int width, + unsigned int height); +bool YUVCompareNV12(const std::vector &yuvTest, + const std::vector &yuvRef, unsigned int width, + unsigned int height); +bool YUVCompareYV12(const std::vector &yuvTest, + const std::vector &yuvRef, unsigned int width, + unsigned int height); +bool YUVCompare(TSurfaceFormat surfaceFormat, + const std::vector &yuvTest, + const std::vector &yuvRef, unsigned int width, + unsigned int height); + +// other types utils +void DataGenerate(TSurfaceFormat surfaceFormat, cl_channel_type type, + std::vector &data, unsigned int width, + unsigned int height, unsigned int channelNum, + float cmin = 0.0f, float cmax = 1.0f, float add = 0.0f); +void DataGenerate(TSurfaceFormat surfaceFormat, cl_channel_type type, + std::vector &data, unsigned int width, + unsigned int height, unsigned int channelNum, + float cmin = 0.0f, float cmax = 1.0f, float add = 0.0f); +void DataGenerate(TSurfaceFormat surfaceFormat, cl_channel_type type, + std::vector &data, unsigned int width, + unsigned int height, unsigned int channelNum, + float cmin = 0.0f, float cmax = 1.0f, float add = 0.0f); +bool DataCompare(TSurfaceFormat surfaceFormat, cl_channel_type type, + const std::vector &dataTest, + const std::vector &dataExp, unsigned int width, + unsigned int height, unsigned int channelNum); +bool DataCompare(TSurfaceFormat surfaceFormat, cl_channel_type type, + const std::vector &dataTest, + const std::vector &dataExp, unsigned int width, + unsigned int height, unsigned int channelNum); +bool DataCompare(TSurfaceFormat surfaceFormat, cl_channel_type type, + const std::vector &dataTest, + const std::vector &dataExp, unsigned int width, + unsigned int height, unsigned int channelNum); + +bool GetImageInfo(cl_mem object, cl_image_format formatExp, + size_t elementSizeExp, size_t rowPitchExp, + size_t slicePitchExp, size_t widthExp, size_t heightExp, + size_t depthExp, unsigned int planeExp); +bool GetMemObjInfo(cl_mem object, cl_dx9_media_adapter_type_khr adapterType, + std::auto_ptr &surface, + void *shareHandleExp); +bool ImageInfoVerify(cl_dx9_media_adapter_type_khr adapterType, + const std::vector &memObjList, unsigned int width, + unsigned int height, + std::auto_ptr &surface, + void *sharedHandle); +bool ImageFormatCheck(cl_context context, cl_mem_object_type imageType, + const cl_image_format imageFormatCheck); +unsigned int ChannelNum(TSurfaceFormat surfaceFormat); +unsigned int PlanesNum(TSurfaceFormat surfaceFormat); + +#if defined(_WIN32) +D3DFORMAT SurfaceFormatToD3D(TSurfaceFormat surfaceFormat); +#endif + +bool DeviceCreate(cl_dx9_media_adapter_type_khr adapterType, + std::auto_ptr &device); +bool SurfaceFormatCheck(cl_dx9_media_adapter_type_khr adapterType, + const CDeviceWrapper &device, + TSurfaceFormat surfaceFormat); +bool SurfaceFormatToOCL(TSurfaceFormat surfaceFormat, cl_image_format &format); +void SurfaceFormatToString(TSurfaceFormat surfaceFormat, std::string &str); +bool MediaSurfaceCreate(cl_dx9_media_adapter_type_khr adapterType, + unsigned int width, unsigned int height, + TSurfaceFormat surfaceFormat, CDeviceWrapper &device, + std::auto_ptr &surface, + bool sharedHandle, void **objectSharedHandle); + +cl_int +deviceExistForCLTest(cl_platform_id platform, + cl_dx9_media_adapter_type_khr media_adapters_type, + void *media_adapters, CResult &result, + TSharedHandleType sharedHandle = SHARED_HANDLE_DISABLED); +#endif // __UTILS_KHR_MEDIA_H diff --git a/test_conformance/extensions/cl_khr_dx9_media_sharing/wrappers.cpp b/test_conformance/extensions/cl_khr_dx9_media_sharing/wrappers.cpp new file mode 100644 index 00000000..e156584e --- /dev/null +++ b/test_conformance/extensions/cl_khr_dx9_media_sharing/wrappers.cpp @@ -0,0 +1,463 @@ +// +// 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 "wrappers.h" +#include "harness/errorHelpers.h" + +LPCTSTR CDeviceWrapper::WINDOW_TITLE = _T( "cl_khr_dx9_media_sharing" ); +const int CDeviceWrapper::WINDOW_WIDTH = 256; +const int CDeviceWrapper::WINDOW_HEIGHT = 256; +CDeviceWrapper::TAccelerationType CDeviceWrapper::accelerationType = + CDeviceWrapper::ACCELERATION_HW; + +#if defined(_WIN32) +const D3DFORMAT CDXVAWrapper::RENDER_TARGET_FORMAT = D3DFMT_X8R8G8B8; +const D3DFORMAT CDXVAWrapper::VIDEO_FORMAT = D3DFMT_X8R8G8B8; +const unsigned int CDXVAWrapper::VIDEO_FPS = 60; +#endif + +#if defined(_WIN32) +static LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + switch (msg) + { + case WM_DESTROY: PostQuitMessage(0); return 0; + case WM_PAINT: ValidateRect(hWnd, 0); return 0; + default: break; + } + + return DefWindowProc(hWnd, msg, wParam, lParam); +} +#endif + +CDeviceWrapper::CDeviceWrapper() +#if defined(_WIN32) + : _hInstance(NULL), _hWnd(NULL) +#endif +{} + +void CDeviceWrapper::WindowInit() +{ +#if defined(_WIN32) + _hInstance = GetModuleHandle(NULL); + static WNDCLASSEX wc = { + sizeof(WNDCLASSEX), CS_CLASSDC, WndProc, 0L, 0L, + _hInstance, NULL, NULL, NULL, NULL, + WINDOW_TITLE, NULL + }; + + RegisterClassEx(&wc); + + _hWnd = CreateWindow(WINDOW_TITLE, WINDOW_TITLE, WS_OVERLAPPEDWINDOW, 0, 0, + WINDOW_WIDTH, WINDOW_HEIGHT, NULL, NULL, wc.hInstance, + NULL); + + if (!_hWnd) + { + log_error("Failed to create window"); + return; + } + + ShowWindow(_hWnd, SW_SHOWDEFAULT); + UpdateWindow(_hWnd); +#endif +} + +void CDeviceWrapper::WindowDestroy() +{ +#if defined(_WIN32) + if (_hWnd) DestroyWindow(_hWnd); + _hWnd = NULL; +#endif +} + +#if defined(_WIN32) +HWND CDeviceWrapper::WindowHandle() const { return _hWnd; } +#endif + +int CDeviceWrapper::WindowWidth() const { return WINDOW_WIDTH; } + +int CDeviceWrapper::WindowHeight() const { return WINDOW_HEIGHT; } + +CDeviceWrapper::TAccelerationType CDeviceWrapper::AccelerationType() +{ + return accelerationType; +} + +void CDeviceWrapper::AccelerationType(TAccelerationType accelerationTypeNew) +{ + accelerationType = accelerationTypeNew; +} + +CDeviceWrapper::~CDeviceWrapper() { WindowDestroy(); } + +#if defined(_WIN32) +CD3D9Wrapper::CD3D9Wrapper() + : _d3d9(NULL), _d3dDevice(NULL), _status(DEVICE_PASS), _adapterIdx(0), + _adapterFound(false) +{ + WindowInit(); + + _d3d9 = Direct3DCreate9(D3D_SDK_VERSION); + if (!_d3d9) + { + log_error("Direct3DCreate9 failed\n"); + _status = DEVICE_FAIL; + } +} + +CD3D9Wrapper::~CD3D9Wrapper() +{ + Destroy(); + + if (_d3d9) _d3d9->Release(); + _d3d9 = 0; +} + +void CD3D9Wrapper::Destroy() +{ + if (_d3dDevice) _d3dDevice->Release(); + _d3dDevice = 0; +} + +cl_int CD3D9Wrapper::Init() +{ + if (!WindowHandle()) + { + log_error("D3D9: Window is not created\n"); + _status = DEVICE_FAIL; + return DEVICE_FAIL; + } + + if (!_d3d9 || DEVICE_PASS != _status || !_adapterFound) return false; + + _d3d9->GetAdapterDisplayMode(_adapterIdx - 1, &_d3ddm); + + D3DPRESENT_PARAMETERS d3dParams; + ZeroMemory(&d3dParams, sizeof(d3dParams)); + + d3dParams.Windowed = TRUE; + d3dParams.BackBufferCount = 1; + d3dParams.SwapEffect = D3DSWAPEFFECT_DISCARD; + d3dParams.hDeviceWindow = WindowHandle(); + d3dParams.BackBufferWidth = WindowWidth(); + d3dParams.BackBufferHeight = WindowHeight(); + d3dParams.BackBufferFormat = _d3ddm.Format; + + DWORD processingType = (AccelerationType() == ACCELERATION_HW) + ? D3DCREATE_HARDWARE_VERTEXPROCESSING + : D3DCREATE_SOFTWARE_VERTEXPROCESSING; + + if (FAILED(_d3d9->CreateDevice(_adapterIdx - 1, D3DDEVTYPE_HAL, + WindowHandle(), processingType, &d3dParams, + &_d3dDevice))) + { + log_error("CreateDevice failed\n"); + _status = DEVICE_FAIL; + return DEVICE_FAIL; + } + + _d3dDevice->BeginScene(); + _d3dDevice->Clear(0, NULL, D3DCLEAR_TARGET, 0, 1.0f, 0); + _d3dDevice->EndScene(); + + return true; +} + +void *CD3D9Wrapper::D3D() const { return _d3d9; } + +void *CD3D9Wrapper::Device() const { return _d3dDevice; } + +D3DFORMAT CD3D9Wrapper::Format() { return _d3ddm.Format; } + +D3DADAPTER_IDENTIFIER9 CD3D9Wrapper::Adapter() { return _adapter; } + +TDeviceStatus CD3D9Wrapper::Status() const { return _status; } + +bool CD3D9Wrapper::AdapterNext() +{ + if (DEVICE_PASS != _status) return false; + + _adapterFound = false; + for (; _adapterIdx < _d3d9->GetAdapterCount();) + { + ++_adapterIdx; + D3DCAPS9 caps; + if (FAILED( + _d3d9->GetDeviceCaps(_adapterIdx - 1, D3DDEVTYPE_HAL, &caps))) + continue; + + if (FAILED(_d3d9->GetAdapterIdentifier(_adapterIdx - 1, 0, &_adapter))) + { + log_error("D3D9: GetAdapterIdentifier failed\n"); + _status = DEVICE_FAIL; + return false; + } + + _adapterFound = true; + + Destroy(); + if (!Init()) + { + _status = DEVICE_FAIL; + _adapterFound = false; + } + break; + } + + return _adapterFound; +} + +unsigned int CD3D9Wrapper::AdapterIdx() const { return _adapterIdx - 1; } + + +CD3D9ExWrapper::CD3D9ExWrapper() + : _d3d9Ex(NULL), _d3dDeviceEx(NULL), _status(DEVICE_PASS), _adapterIdx(0), + _adapterFound(false) +{ + WindowInit(); + + HRESULT result = Direct3DCreate9Ex(D3D_SDK_VERSION, &_d3d9Ex); + if (FAILED(result) || !_d3d9Ex) + { + log_error("Direct3DCreate9Ex failed\n"); + _status = DEVICE_FAIL; + } +} + +CD3D9ExWrapper::~CD3D9ExWrapper() +{ + Destroy(); + + if (_d3d9Ex) _d3d9Ex->Release(); + _d3d9Ex = 0; +} + +void *CD3D9ExWrapper::D3D() const { return _d3d9Ex; } + +void *CD3D9ExWrapper::Device() const { return _d3dDeviceEx; } + +D3DFORMAT CD3D9ExWrapper::Format() { return _d3ddmEx.Format; } + +D3DADAPTER_IDENTIFIER9 CD3D9ExWrapper::Adapter() { return _adapter; } + +cl_int CD3D9ExWrapper::Init() +{ + if (!WindowHandle()) + { + log_error("D3D9EX: Window is not created\n"); + _status = DEVICE_FAIL; + return DEVICE_FAIL; + } + + if (!_d3d9Ex || DEVICE_FAIL == _status || !_adapterFound) + return DEVICE_FAIL; + + RECT rect; + GetClientRect(WindowHandle(), &rect); + + D3DPRESENT_PARAMETERS d3dParams; + ZeroMemory(&d3dParams, sizeof(d3dParams)); + + d3dParams.Windowed = TRUE; + d3dParams.SwapEffect = D3DSWAPEFFECT_FLIP; + d3dParams.BackBufferFormat = D3DFMT_X8R8G8B8; + d3dParams.BackBufferWidth = WindowWidth(); + d3dParams.BackBufferHeight = WindowHeight(); + + d3dParams.BackBufferCount = 1; + d3dParams.hDeviceWindow = WindowHandle(); + + DWORD processingType = (AccelerationType() == ACCELERATION_HW) + ? D3DCREATE_HARDWARE_VERTEXPROCESSING + : D3DCREATE_SOFTWARE_VERTEXPROCESSING; + + if (FAILED(_d3d9Ex->CreateDeviceEx(_adapterIdx - 1, D3DDEVTYPE_HAL, + WindowHandle(), processingType, + &d3dParams, NULL, &_d3dDeviceEx))) + { + log_error("CreateDeviceEx failed\n"); + _status = DEVICE_FAIL; + return DEVICE_FAIL; + } + + _d3dDeviceEx->BeginScene(); + _d3dDeviceEx->Clear(0, NULL, D3DCLEAR_TARGET, 0, 1.0f, 0); + _d3dDeviceEx->EndScene(); + + return DEVICE_PASS; +} + +void CD3D9ExWrapper::Destroy() +{ + if (_d3dDeviceEx) _d3dDeviceEx->Release(); + _d3dDeviceEx = 0; +} + +TDeviceStatus CD3D9ExWrapper::Status() const { return _status; } + +bool CD3D9ExWrapper::AdapterNext() +{ + if (DEVICE_FAIL == _status) return false; + + _adapterFound = false; + for (; _adapterIdx < _d3d9Ex->GetAdapterCount();) + { + ++_adapterIdx; + D3DCAPS9 caps; + if (FAILED( + _d3d9Ex->GetDeviceCaps(_adapterIdx - 1, D3DDEVTYPE_HAL, &caps))) + continue; + + if (FAILED( + _d3d9Ex->GetAdapterIdentifier(_adapterIdx - 1, 0, &_adapter))) + { + log_error("D3D9EX: GetAdapterIdentifier failed\n"); + _status = DEVICE_FAIL; + return false; + } + + _adapterFound = true; + Destroy(); + if (!Init()) + { + _status = DEVICE_FAIL; + _adapterFound = _status; + } + + break; + } + + return _adapterFound; +} + +unsigned int CD3D9ExWrapper::AdapterIdx() const { return _adapterIdx - 1; } + +CDXVAWrapper::CDXVAWrapper() + : _dxvaDevice(NULL), _status(DEVICE_PASS), _adapterFound(false) +{ + _status = _d3d9.Status(); +} + +CDXVAWrapper::~CDXVAWrapper() { DXVAHDDestroy(); } + +void *CDXVAWrapper::Device() const { return _dxvaDevice; } + +TDeviceStatus CDXVAWrapper::Status() const +{ + if (_status == DEVICE_FAIL || _d3d9.Status() == DEVICE_FAIL) + return DEVICE_FAIL; + else if (_status == DEVICE_NOTSUPPORTED + || _d3d9.Status() == DEVICE_NOTSUPPORTED) + return DEVICE_NOTSUPPORTED; + else + return DEVICE_PASS; +} + +bool CDXVAWrapper::AdapterNext() +{ + if (DEVICE_PASS != _status) return false; + + _adapterFound = _d3d9.AdapterNext(); + _status = _d3d9.Status(); + if (DEVICE_PASS != _status) + { + _adapterFound = false; + return false; + } + + if (!_adapterFound) return false; + + DXVAHDDestroy(); + _status = DXVAHDInit(); + if (DEVICE_PASS != _status) + { + _adapterFound = false; + return false; + } + + return true; +} + +TDeviceStatus CDXVAWrapper::DXVAHDInit() +{ + if ((_status == DEVICE_FAIL) || (_d3d9.Status() == DEVICE_FAIL) + || !_adapterFound) + return DEVICE_FAIL; + + DXVAHD_RATIONAL fps = { VIDEO_FPS, 1 }; + + DXVAHD_CONTENT_DESC desc; + desc.InputFrameFormat = DXVAHD_FRAME_FORMAT_PROGRESSIVE; + desc.InputFrameRate = fps; + desc.InputWidth = WindowWidth(); + desc.InputHeight = WindowHeight(); + desc.OutputFrameRate = fps; + desc.OutputWidth = WindowWidth(); + desc.OutputHeight = WindowHeight(); + +#ifdef USE_SOFTWARE_PLUGIN + _status = DEVICE_FAIL; + return DEVICE_FAIL; +#endif + + HRESULT hr = DXVAHD_CreateDevice( + static_cast(_d3d9.Device()), &desc, + DXVAHD_DEVICE_USAGE_PLAYBACK_NORMAL, NULL, &_dxvaDevice); + if (FAILED(hr)) + { + if (hr == E_NOINTERFACE) + { + log_error( + "DXVAHD_CreateDevice skipped due to no supported devices!\n"); + _status = DEVICE_NOTSUPPORTED; + } + else + { + log_error("DXVAHD_CreateDevice failed\n"); + _status = DEVICE_FAIL; + } + } + + return _status; +} + +void CDXVAWrapper::DXVAHDDestroy() +{ + if (_dxvaDevice) _dxvaDevice->Release(); + _dxvaDevice = 0; +} + +void *CDXVAWrapper::D3D() const { return _d3d9.D3D(); } + +unsigned int CDXVAWrapper::AdapterIdx() const { return _d3d9.AdapterIdx(); } + +const CD3D9ExWrapper &CDXVAWrapper::D3D9() const { return _d3d9; } + +CD3D9SurfaceWrapper::CD3D9SurfaceWrapper(): mMem(NULL) {} + +CD3D9SurfaceWrapper::CD3D9SurfaceWrapper(IDirect3DSurface9 *mem): mMem(mem) {} + +CD3D9SurfaceWrapper::~CD3D9SurfaceWrapper() +{ + if (mMem != NULL) mMem->Release(); + mMem = NULL; +} + +#endif + +CSurfaceWrapper::CSurfaceWrapper() {} + +CSurfaceWrapper::~CSurfaceWrapper() {} diff --git a/test_conformance/extensions/cl_khr_dx9_media_sharing/wrappers.h b/test_conformance/extensions/cl_khr_dx9_media_sharing/wrappers.h new file mode 100644 index 00000000..e3a7c6d8 --- /dev/null +++ b/test_conformance/extensions/cl_khr_dx9_media_sharing/wrappers.h @@ -0,0 +1,195 @@ +// +// 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. +// +#ifndef __WRAPPERS_H +#define __WRAPPERS_H + +#if defined(_WIN32) +#include +#if defined(__MINGW32__) +#include +typedef unsigned char UINT8; +#define __out +#define __in +#define __inout +#define __out_bcount(size) +#define __out_bcount_opt(size) +#define __in_opt +#define __in_ecount(size) +#define __in_ecount_opt(size) +#define __out_opt +#define __out_ecount(size) +#define __out_ecount_opt(size) +#define __in_bcount_opt(size) +#define __inout_opt +#define __inout_bcount(size) +#define __in_bcount(size) +#define __deref_out +#endif +#include +#include +#endif + +enum TDeviceStatus +{ + DEVICE_NOTSUPPORTED, + DEVICE_PASS, + DEVICE_FAIL, +}; + +class CDeviceWrapper { +public: + enum TAccelerationType + { + ACCELERATION_HW, + ACCELERATION_SW, + }; + + CDeviceWrapper(); + virtual ~CDeviceWrapper(); + + virtual bool AdapterNext() = 0; + virtual unsigned int AdapterIdx() const = 0; + virtual void *Device() const = 0; + virtual TDeviceStatus Status() const = 0; + virtual void *D3D() const = 0; + +#if defined(_WIN32) + HWND WindowHandle() const; +#endif + int WindowWidth() const; + int WindowHeight() const; + void WindowInit(); + + + static TAccelerationType AccelerationType(); + static void AccelerationType(TAccelerationType accelerationTypeNew); + +private: + static LPCTSTR WINDOW_TITLE; + static const int WINDOW_WIDTH; + static const int WINDOW_HEIGHT; + static TAccelerationType accelerationType; + +#if defined(_WIN32) + HMODULE _hInstance; + HWND _hWnd; +#endif + + void WindowDestroy(); +}; + +class CSurfaceWrapper { +public: + CSurfaceWrapper(); + virtual ~CSurfaceWrapper(); +}; + +#if defined(_WIN32) +// windows specific wrappers +class CD3D9Wrapper : public CDeviceWrapper { +public: + CD3D9Wrapper(); + ~CD3D9Wrapper(); + + virtual bool AdapterNext(); + virtual unsigned int AdapterIdx() const; + virtual void *Device() const; + virtual TDeviceStatus Status() const; + virtual void *D3D() const; + +private: + LPDIRECT3D9 _d3d9; + LPDIRECT3DDEVICE9 _d3dDevice; + D3DDISPLAYMODE _d3ddm; + D3DADAPTER_IDENTIFIER9 _adapter; + TDeviceStatus _status; + unsigned int _adapterIdx; + bool _adapterFound; + + D3DFORMAT Format(); + D3DADAPTER_IDENTIFIER9 Adapter(); + int Init(); + void Destroy(); +}; + +class CD3D9ExWrapper : public CDeviceWrapper { +public: + CD3D9ExWrapper(); + ~CD3D9ExWrapper(); + + virtual bool AdapterNext(); + virtual unsigned int AdapterIdx() const; + virtual void *Device() const; + virtual TDeviceStatus Status() const; + virtual void *D3D() const; + +private: + LPDIRECT3D9EX _d3d9Ex; + LPDIRECT3DDEVICE9EX _d3dDeviceEx; + D3DDISPLAYMODEEX _d3ddmEx; + D3DADAPTER_IDENTIFIER9 _adapter; + TDeviceStatus _status; + unsigned int _adapterIdx; + bool _adapterFound; + + D3DFORMAT Format(); + D3DADAPTER_IDENTIFIER9 Adapter(); + int Init(); + void Destroy(); +}; + +class CDXVAWrapper : public CDeviceWrapper { +public: + CDXVAWrapper(); + ~CDXVAWrapper(); + + virtual bool AdapterNext(); + virtual unsigned int AdapterIdx() const; + virtual void *Device() const; + virtual TDeviceStatus Status() const; + virtual void *D3D() const; + const CD3D9ExWrapper &D3D9() const; + +private: + CD3D9ExWrapper _d3d9; + IDXVAHD_Device *_dxvaDevice; + TDeviceStatus _status; + bool _adapterFound; + + static const D3DFORMAT RENDER_TARGET_FORMAT; + static const D3DFORMAT VIDEO_FORMAT; + static const unsigned int VIDEO_FPS; + + TDeviceStatus DXVAHDInit(); + void DXVAHDDestroy(); +}; + +class CD3D9SurfaceWrapper : public CSurfaceWrapper { +public: + CD3D9SurfaceWrapper(); + CD3D9SurfaceWrapper(IDirect3DSurface9 *mem); + ~CD3D9SurfaceWrapper(); + + operator IDirect3DSurface9 *() { return mMem; } + IDirect3DSurface9 **operator&() { return &mMem; } + IDirect3DSurface9 *operator->() const { return mMem; } + +private: + IDirect3DSurface9 *mMem; +}; +#endif + +#endif // __D3D_WRAPPERS diff --git a/test_extensions/CMakeLists.txt b/test_extensions/CMakeLists.txt deleted file mode 100644 index 3c48e186..00000000 --- a/test_extensions/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -set(HARNESS_LIB harness) -add_subdirectory( media_sharing ) diff --git a/test_extensions/media_sharing/main.cpp b/test_extensions/media_sharing/main.cpp deleted file mode 100644 index f0c3aff8..00000000 --- a/test_extensions/media_sharing/main.cpp +++ /dev/null @@ -1,204 +0,0 @@ -// -// 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 -#include - -#include "harness/testHarness.h" -#include "utils.h" -#include "procs.h" - - -test_definition test_list[] = { -ADD_TEST( context_create ), -ADD_TEST( get_device_ids ), -ADD_TEST( api ), -ADD_TEST( kernel ), -ADD_TEST( other_data_types ), -ADD_TEST( memory_access ), -ADD_TEST( interop_user_sync ) -}; - -const int test_num = ARRAY_SIZE(test_list); - -clGetDeviceIDsFromDX9MediaAdapterKHR_fn clGetDeviceIDsFromDX9MediaAdapterKHR = NULL; -clCreateFromDX9MediaSurfaceKHR_fn clCreateFromDX9MediaSurfaceKHR = NULL; -clEnqueueAcquireDX9MediaSurfacesKHR_fn clEnqueueAcquireDX9MediaSurfacesKHR = NULL; -clEnqueueReleaseDX9MediaSurfacesKHR_fn clEnqueueReleaseDX9MediaSurfacesKHR = NULL; - -cl_platform_id gPlatformIDdetected; -cl_device_id gDeviceIDdetected; -cl_device_type gDeviceTypeSelected = CL_DEVICE_TYPE_DEFAULT; - -bool MediaSurfaceSharingExtensionInit() -{ - clGetDeviceIDsFromDX9MediaAdapterKHR = (clGetDeviceIDsFromDX9MediaAdapterKHR_fn)clGetExtensionFunctionAddressForPlatform(gPlatformIDdetected, "clGetDeviceIDsFromDX9MediaAdapterKHR"); - if (clGetDeviceIDsFromDX9MediaAdapterKHR == NULL) - { - log_error("clGetExtensionFunctionAddressForPlatform(clGetDeviceIDsFromDX9MediaAdapterKHR) returned NULL.\n"); - return false; - } - - clCreateFromDX9MediaSurfaceKHR = (clCreateFromDX9MediaSurfaceKHR_fn)clGetExtensionFunctionAddressForPlatform(gPlatformIDdetected, "clCreateFromDX9MediaSurfaceKHR"); - if (clCreateFromDX9MediaSurfaceKHR == NULL) - { - log_error("clGetExtensionFunctionAddressForPlatform(clCreateFromDX9MediaSurfaceKHR) returned NULL.\n"); - return false; - } - - clEnqueueAcquireDX9MediaSurfacesKHR = (clEnqueueAcquireDX9MediaSurfacesKHR_fn)clGetExtensionFunctionAddressForPlatform(gPlatformIDdetected, "clEnqueueAcquireDX9MediaSurfacesKHR"); - if (clEnqueueAcquireDX9MediaSurfacesKHR == NULL) - { - log_error("clGetExtensionFunctionAddressForPlatform(clEnqueueAcquireDX9MediaSurfacesKHR) returned NULL.\n"); - return false; - } - - clEnqueueReleaseDX9MediaSurfacesKHR = (clEnqueueReleaseDX9MediaSurfacesKHR_fn)clGetExtensionFunctionAddressForPlatform(gPlatformIDdetected, "clEnqueueReleaseDX9MediaSurfacesKHR"); - if (clEnqueueReleaseDX9MediaSurfacesKHR == NULL) - { - log_error("clGetExtensionFunctionAddressForPlatform(clEnqueueReleaseDX9MediaSurfacesKHR) returned NULL.\n"); - return false; - } - - return true; -} - -bool DetectPlatformAndDevice() -{ - std::vector platforms; - cl_uint platformsNum = 0; - cl_int error = clGetPlatformIDs(0, 0, &platformsNum); - if (error != CL_SUCCESS) - { - print_error(error, "clGetPlatformIDs failed\n"); - return false; - } - - platforms.resize(platformsNum); - error = clGetPlatformIDs(platformsNum, &platforms[0], 0); - if (error != CL_SUCCESS) - { - print_error(error, "clGetPlatformIDs failed\n"); - return false; - } - - bool found = false; - for (size_t i = 0; i < platformsNum; ++i) - { - std::vector devices; - cl_uint devicesNum = 0; - error = clGetDeviceIDs(platforms[i], gDeviceTypeSelected, 0, 0, &devicesNum); - if (error != CL_SUCCESS) - { - print_error(error, "clGetDeviceIDs failed\n"); - return false; - } - - devices.resize(devicesNum); - error = clGetDeviceIDs(platforms[i], gDeviceTypeSelected, devicesNum, &devices[0], 0); - if (error != CL_SUCCESS) - { - print_error(error, "clGetDeviceIDs failed\n"); - return false; - } - - for (size_t j = 0; j < devicesNum; ++j) - { - if (is_extension_available(devices[j], "cl_khr_dx9_media_sharing")) - { - gPlatformIDdetected = platforms[i]; - gDeviceIDdetected = devices[j]; - found = true; - break; - } - } - } - - if (!found) - { - log_info("Test was not run, because the media surface sharing extension is not supported for any devices.\n"); - return false; - } - - return true; -} - -bool CmdlineParse(int argc, const char *argv[]) -{ - char *env_mode = getenv( "CL_DEVICE_TYPE" ); - if( env_mode != NULL ) - { - if(strcmp(env_mode, "gpu") == 0 || strcmp(env_mode, "CL_DEVICE_TYPE_GPU") == 0) - gDeviceTypeSelected = CL_DEVICE_TYPE_GPU; - else if(strcmp(env_mode, "cpu") == 0 || strcmp(env_mode, "CL_DEVICE_TYPE_CPU") == 0) - gDeviceTypeSelected = CL_DEVICE_TYPE_CPU; - else if(strcmp(env_mode, "accelerator") == 0 || strcmp(env_mode, "CL_DEVICE_TYPE_ACCELERATOR") == 0) - gDeviceTypeSelected = CL_DEVICE_TYPE_ACCELERATOR; - else if(strcmp(env_mode, "default") == 0 || strcmp(env_mode, "CL_DEVICE_TYPE_DEFAULT") == 0) - gDeviceTypeSelected = CL_DEVICE_TYPE_DEFAULT; - else - { - log_error("Unknown CL_DEVICE_TYPE env variable setting: %s.\nAborting...\n", env_mode); - return false; - } - } - - for (int i = 0; i < argc; ++i) - { - if(strcmp(argv[i], "gpu") == 0 || strcmp(argv[i], "CL_DEVICE_TYPE_GPU") == 0) - { - gDeviceTypeSelected = CL_DEVICE_TYPE_GPU; - continue; - } - else if(strcmp( argv[i], "cpu") == 0 || strcmp(argv[i], "CL_DEVICE_TYPE_CPU") == 0) - { - gDeviceTypeSelected = CL_DEVICE_TYPE_CPU; - continue; - } - else if(strcmp( argv[i], "accelerator") == 0 || strcmp(argv[i], "CL_DEVICE_TYPE_ACCELERATOR") == 0) - { - gDeviceTypeSelected = CL_DEVICE_TYPE_ACCELERATOR; - continue; - } - else if(strcmp(argv[i], "CL_DEVICE_TYPE_DEFAULT") == 0) - { - gDeviceTypeSelected = CL_DEVICE_TYPE_DEFAULT; - continue; - } - else if (strcmp(argv[i], "sw") == 0 || strcmp(argv[i], "software") == 0) - { - CDeviceWrapper::AccelerationType(CDeviceWrapper::ACCELERATION_SW); - } - } - - return true; -} - -int main(int argc, const char *argv[]) -{ - if (!CmdlineParse(argc, argv)) - return TEST_FAIL; - - if (!DetectPlatformAndDevice()) - { - log_info("Test was not run, because the media surface sharing extension is not supported\n"); - return TEST_SKIP; - } - - if (!MediaSurfaceSharingExtensionInit()) - return TEST_FAIL; - - return runTestHarness(argc, argv, test_num, test_list, true, 0); -} diff --git a/test_extensions/media_sharing/test_create_context.cpp b/test_extensions/media_sharing/test_create_context.cpp deleted file mode 100644 index 5637bc54..00000000 --- a/test_extensions/media_sharing/test_create_context.cpp +++ /dev/null @@ -1,318 +0,0 @@ -// -// 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 "utils.h" - -int context_create(cl_device_id deviceID, cl_context context, cl_command_queue queue, - int num_elements, unsigned int width, unsigned int height, - TContextFuncType functionCreate, cl_dx9_media_adapter_type_khr adapterType, - TSurfaceFormat surfaceFormat, TSharedHandleType sharedHandle) -{ - CResult result; - - //create device - std::auto_ptr deviceWrapper; - if (!DeviceCreate(adapterType, deviceWrapper)) - { - result.ResultSub(CResult::TEST_ERROR); - return result.Result(); - } - - //generate input data - std::vector bufferIn(width * height * 3 / 2, 0); - if(!YUVGenerate(surfaceFormat, bufferIn, width, height, 0, 255)) - { - result.ResultSub(CResult::TEST_ERROR); - return result.Result(); - } - - while (deviceWrapper->AdapterNext()) - { - cl_int error; - //check if the test can be run on the adapter - if (CL_SUCCESS != (error = deviceExistForCLTest(gPlatformIDdetected, adapterType, deviceWrapper->Device(), result, sharedHandle))) - { - return result.Result(); - } - - if (surfaceFormat != SURFACE_FORMAT_NV12 && !SurfaceFormatCheck(adapterType, *deviceWrapper, surfaceFormat)) - { - std::string sharedHandleStr = (sharedHandle == SHARED_HANDLE_ENABLED)? "yes": "no"; - std::string formatStr; - std::string adapterStr; - SurfaceFormatToString(surfaceFormat, formatStr); - AdapterToString(adapterType, adapterStr); - log_info("Skipping test case, image format is not supported by a device (adapter type: %s, format: %s, shared handle: %s)\n", - adapterStr.c_str(), formatStr.c_str(), sharedHandleStr.c_str()); - return result.Result(); - } - - void *objectSharedHandle = 0; - std::auto_ptr surface; - if (!MediaSurfaceCreate(adapterType, width, height, surfaceFormat, *deviceWrapper, surface, - (sharedHandle == SHARED_HANDLE_ENABLED) ? true: false, &objectSharedHandle)) - { - log_error("Media surface creation failed for %i adapter\n", deviceWrapper->AdapterIdx()); - result.ResultSub(CResult::TEST_ERROR); - return result.Result(); - } - - cl_context_properties contextProperties[] = { - CL_CONTEXT_PLATFORM, (cl_context_properties)gPlatformIDdetected, - AdapterTypeToContextInfo(adapterType), (cl_context_properties)deviceWrapper->Device(), - 0, - }; - - clContextWrapper ctx; - switch(functionCreate) - { - case CONTEXT_CREATE_DEFAULT: - ctx = clCreateContext(&contextProperties[0], 1, &gDeviceIDdetected, NULL, NULL, &error); - break; - case CONTEXT_CREATE_FROM_TYPE: - ctx = clCreateContextFromType(&contextProperties[0], gDeviceTypeSelected, NULL, NULL, &error); - break; - default: - log_error("Unknown context creation function enum\n"); - result.ResultSub(CResult::TEST_ERROR); - return result.Result(); - break; - } - - if (error != CL_SUCCESS) - { - std::string functionName; - FunctionContextCreateToString(functionCreate, functionName); - log_error("%s failed: %s\n", functionName.c_str(), IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - return result.Result(); - } - - if (!YUVSurfaceSet(surfaceFormat, surface, bufferIn, width, height)) - { - result.ResultSub(CResult::TEST_ERROR); - return result.Result(); - } - -#if defined(_WIN32) - cl_dx9_surface_info_khr surfaceInfo; - surfaceInfo.resource = *(static_cast(surface.get())); - surfaceInfo.shared_handle = objectSharedHandle; -#else - void *surfaceInfo = 0; - return TEST_NOT_IMPLEMENTED; -#endif - - std::vector memObjList; - unsigned int planesNum = PlanesNum(surfaceFormat); - std::vector planesList(planesNum); - for (unsigned int planeIdx = 0; planeIdx < planesNum; ++planeIdx) - { - planesList[planeIdx] = clCreateFromDX9MediaSurfaceKHR(ctx, CL_MEM_READ_WRITE, adapterType, &surfaceInfo, planeIdx, &error); - if (error != CL_SUCCESS) - { - log_error("clCreateFromDX9MediaSurfaceKHR failed for plane %i: %s\n", planeIdx, IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - return result.Result(); - } - memObjList.push_back(planesList[planeIdx]); - } - - clCommandQueueWrapper cmdQueue = clCreateCommandQueueWithProperties(ctx, gDeviceIDdetected, 0, &error ); - if (error != CL_SUCCESS) - { - log_error("Unable to create command queue: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - return result.Result(); - } - - if (!ImageInfoVerify(adapterType, memObjList, width, height, surface, objectSharedHandle)) - { - log_error("Image info verification failed\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - cl_event event; - error = clEnqueueAcquireDX9MediaSurfacesKHR(cmdQueue, static_cast(memObjList.size()), - &memObjList.at(0), 0, NULL, &event); - if (error != CL_SUCCESS) - { - log_error("clEnqueueAcquireDX9MediaSurfacesKHR failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - return result.Result(); - } - - cl_uint eventType = 0; - error = clGetEventInfo( event, CL_EVENT_COMMAND_TYPE, sizeof(eventType), &eventType, NULL); - if (error != CL_SUCCESS) - { - log_error("clGetEventInfo failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - } - - if(eventType != CL_COMMAND_ACQUIRE_DX9_MEDIA_SURFACES_KHR) - { - log_error("Invalid event != CL_COMMAND_ACQUIRE_DX9_MEDIA_SURFACES_KHR\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - clReleaseEvent(event); - - size_t origin[3] = {0,0,0}; - size_t offset = 0; - size_t frameSize = width * height * 3 / 2; - std::vector out( frameSize, 0 ); - for (size_t i = 0; i < memObjList.size(); ++i) - { - size_t planeWidth = (i == 0) ? width: width / 2; - size_t planeHeight = (i == 0) ? height: height / 2; - size_t regionPlane[3] = {planeWidth, planeHeight, 1}; - - error = clEnqueueReadImage(cmdQueue, memObjList.at(i), CL_TRUE, origin, regionPlane, 0, 0, &out.at(offset), 0, 0, 0); - if (error != CL_SUCCESS) - { - log_error("clEnqueueReadImage failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - } - - offset += planeWidth * planeHeight; - } - - if (!YUVCompare(surfaceFormat, out, bufferIn, width, height)) - { - log_error("OCL object verification failed - clEnqueueReadImage\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - error = clEnqueueReleaseDX9MediaSurfacesKHR(cmdQueue, static_cast(memObjList.size()), - &memObjList.at(0), 0, NULL, &event); - if (error != CL_SUCCESS) - { - log_error("clEnqueueReleaseDX9MediaSurfacesKHR failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - } - - eventType = 0; - error = clGetEventInfo( event, CL_EVENT_COMMAND_TYPE, sizeof(eventType), &eventType, NULL); - if (error != CL_SUCCESS) - { - log_error("clGetEventInfo failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - } - - if(eventType != CL_COMMAND_RELEASE_DX9_MEDIA_SURFACES_KHR) - { - log_error("Invalid event != CL_COMMAND_RELEASE_DX9_MEDIA_SURFACES_KHR\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - clReleaseEvent(event); - - //object verification - std::vector bufferOut(frameSize, 0); - if (!YUVSurfaceGet(surfaceFormat, surface, bufferOut, width, height)) - { - result.ResultSub(CResult::TEST_FAIL); - return result.Result(); - } - - if (!YUVCompare(surfaceFormat, bufferOut, bufferIn, width, height)) - { - log_error("Media surface is different than expected\n"); - result.ResultSub(CResult::TEST_FAIL); - return result.Result(); - } - } - - if (deviceWrapper->Status() != DEVICE_PASS) - { - std::string adapterName; - AdapterToString(adapterType, adapterName); - if (deviceWrapper->Status() == DEVICE_FAIL) - { - log_error("%s init failed\n", adapterName.c_str()); - result.ResultSub(CResult::TEST_FAIL); - } - else - { - log_error("%s init incomplete due to unsupported device\n", adapterName.c_str()); - result.ResultSub(CResult::TEST_NOTSUPPORTED); - } - } - - return result.Result(); -} - -int test_context_create(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) -{ - const unsigned int WIDTH = 256; - const unsigned int HEIGHT = 256; - - std::vector adapterTypes; -#if defined(_WIN32) - adapterTypes.push_back(CL_ADAPTER_D3D9_KHR); - adapterTypes.push_back(CL_ADAPTER_D3D9EX_KHR); - adapterTypes.push_back(CL_ADAPTER_DXVA_KHR); -#endif - - std::vector contextFuncs; - contextFuncs.push_back(CONTEXT_CREATE_DEFAULT); - contextFuncs.push_back(CONTEXT_CREATE_FROM_TYPE); - - std::vector formats; - formats.push_back(SURFACE_FORMAT_NV12); - formats.push_back(SURFACE_FORMAT_YV12); - - std::vector sharedHandleTypes; - sharedHandleTypes.push_back(SHARED_HANDLE_DISABLED); -#if defined(_WIN32) - sharedHandleTypes.push_back(SHARED_HANDLE_ENABLED); -#endif - - CResult result; - for (size_t adapterTypeIdx = 0; adapterTypeIdx < adapterTypes.size(); ++adapterTypeIdx) - { - //iteration through all create context functions - for (size_t contextFuncIdx = 0; contextFuncIdx < contextFuncs.size(); ++contextFuncIdx) - { - //iteration through surface formats - for (size_t formatIdx = 0; formatIdx < formats.size(); ++formatIdx) - { - //shared handle enabled or disabled - for (size_t sharedHandleIdx = 0; sharedHandleIdx < sharedHandleTypes.size(); ++sharedHandleIdx) - { - if (adapterTypes[adapterTypeIdx] == CL_ADAPTER_D3D9_KHR && sharedHandleTypes[sharedHandleIdx] == SHARED_HANDLE_ENABLED) - continue; - - if(context_create(deviceID, context, queue, num_elements, WIDTH, HEIGHT, - contextFuncs[contextFuncIdx], adapterTypes[adapterTypeIdx], formats[formatIdx], - sharedHandleTypes[sharedHandleIdx]) != 0) - { - std::string sharedHandle = (sharedHandleTypes[sharedHandleIdx] == SHARED_HANDLE_ENABLED)? "shared handle": "no shared handle"; - std::string formatStr; - std::string adapterTypeStr; - SurfaceFormatToString(formats[formatIdx], formatStr); - AdapterToString(adapterTypes[adapterTypeIdx], adapterTypeStr); - - log_error("\nTest case - clCreateContext (%s, %s, %s) failed\n\n", adapterTypeStr.c_str(), formatStr.c_str(), sharedHandle.c_str()); - result.ResultSub(CResult::TEST_FAIL); - } - } - } - } - } - - return result.Result(); -} diff --git a/test_extensions/media_sharing/test_functions_api.cpp b/test_extensions/media_sharing/test_functions_api.cpp deleted file mode 100644 index cdc6ce86..00000000 --- a/test_extensions/media_sharing/test_functions_api.cpp +++ /dev/null @@ -1,617 +0,0 @@ -// -// 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 "utils.h" - -int api_functions(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements, - unsigned int iterationNum, unsigned int width, unsigned int height, cl_dx9_media_adapter_type_khr adapterType, - TSurfaceFormat surfaceFormat, TSharedHandleType sharedHandle) -{ - const unsigned int FRAME_NUM = 2; - const cl_uchar MAX_VALUE = 255 / 2; - CResult result; - - //create device - std::auto_ptr deviceWrapper; - if (!DeviceCreate(adapterType, deviceWrapper)) - { - result.ResultSub(CResult::TEST_ERROR); - return result.Result(); - } - - //generate input and expected data - std::vector > bufferRef1(FRAME_NUM); - std::vector > bufferRef2(FRAME_NUM); - std::vector > bufferRef3(FRAME_NUM); - size_t frameSize = width * height * 3 / 2; - cl_uchar step = MAX_VALUE / FRAME_NUM; - for (size_t i = 0; i < FRAME_NUM; ++i) - { - if (!YUVGenerate(surfaceFormat, bufferRef1[i], width, height, static_cast(step * i), static_cast(step * (i + 1))) || - !YUVGenerate(surfaceFormat, bufferRef2[i], width, height, static_cast(step * i), static_cast(step * (i + 1)), 0.2) || - !YUVGenerate(surfaceFormat, bufferRef3[i], width, height, static_cast(step * i), static_cast(step * (i + 1)), 0.4)) - { - result.ResultSub(CResult::TEST_ERROR); - return result.Result(); - } - } - - //iterates through all devices - while (deviceWrapper->AdapterNext()) - { - cl_int error; - //check if the test can be run on the adapter - if (CL_SUCCESS != (error = deviceExistForCLTest(gPlatformIDdetected, adapterType, deviceWrapper->Device(), result, sharedHandle))) - { - return result.Result(); - } - - if (surfaceFormat != SURFACE_FORMAT_NV12 && !SurfaceFormatCheck(adapterType, *deviceWrapper, surfaceFormat)) - { - std::string sharedHandleStr = (sharedHandle == SHARED_HANDLE_ENABLED)? "yes": "no"; - std::string formatStr; - std::string adapterStr; - SurfaceFormatToString(surfaceFormat, formatStr); - AdapterToString(adapterType, adapterStr); - log_info("Skipping test case, image format is not supported by a device (adapter type: %s, format: %s, shared handle: %s)\n", - adapterStr.c_str(), formatStr.c_str(), sharedHandleStr.c_str()); - return result.Result(); - } - - void *objectSharedHandle = 0; - std::auto_ptr surface; - - //create surface - if (!MediaSurfaceCreate(adapterType, width, height, surfaceFormat, *deviceWrapper, surface, - (sharedHandle == SHARED_HANDLE_ENABLED) ? true: false, &objectSharedHandle)) - { - log_error("Media surface creation failed for %i adapter\n", deviceWrapper->AdapterIdx()); - result.ResultSub(CResult::TEST_ERROR); - return result.Result(); - } - - cl_context_properties contextProperties[] = { - CL_CONTEXT_PLATFORM, (cl_context_properties)gPlatformIDdetected, - AdapterTypeToContextInfo(adapterType), (cl_context_properties)deviceWrapper->Device(), - 0, - }; - - clContextWrapper ctx = clCreateContext(&contextProperties[0], 1, &gDeviceIDdetected, NULL, NULL, &error); - if (error != CL_SUCCESS) - { - log_error("clCreateContext failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - return result.Result(); - } - -#if defined(_WIN32) - cl_dx9_surface_info_khr surfaceInfo; - surfaceInfo.resource = *(static_cast(surface.get())); - surfaceInfo.shared_handle = objectSharedHandle; -#else - void *surfaceInfo = 0; - return TEST_NOT_IMPLEMENTED; -#endif - - std::vector memObjList; - unsigned int planesNum = PlanesNum(surfaceFormat); - std::vector planesList(planesNum); - for (unsigned int planeIdx = 0; planeIdx < planesNum; ++planeIdx) - { - planesList[planeIdx] = clCreateFromDX9MediaSurfaceKHR(ctx, CL_MEM_READ_WRITE, adapterType, &surfaceInfo, planeIdx, &error); - if (error != CL_SUCCESS) - { - log_error("clCreateFromDX9MediaSurfaceKHR failed for plane %i: %s\n", planeIdx, IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - return result.Result(); - } - memObjList.push_back(planesList[planeIdx]); - } - - clCommandQueueWrapper cmdQueue = clCreateCommandQueueWithProperties(ctx, gDeviceIDdetected, 0, &error ); - if (error != CL_SUCCESS) - { - log_error("Unable to create command queue: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - return result.Result(); - } - - if (!ImageInfoVerify(adapterType, memObjList, width, height, surface, objectSharedHandle)) - { - log_error("Image info verification failed\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - for (size_t frameIdx = 0; frameIdx < iterationNum; ++frameIdx) - { - if (!YUVSurfaceSet(surfaceFormat, surface, bufferRef1[frameIdx % FRAME_NUM], width, height)) - { - result.ResultSub(CResult::TEST_ERROR); - return result.Result(); - } - - error = clEnqueueAcquireDX9MediaSurfacesKHR(cmdQueue, static_cast(memObjList.size()), &memObjList[0], 0, 0, 0); - if (error != CL_SUCCESS) - { - log_error("clEnqueueAcquireDX9MediaSurfacesKHR failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - return result.Result(); - } - - { //read operation - std::vector out( frameSize, 0 ); - size_t offset = 0; - size_t origin[3] = {0,0,0}; - - for (size_t i = 0; i < memObjList.size(); ++i) - { - size_t planeWidth = (i == 0) ? width: width / 2; - size_t planeHeight = (i == 0) ? height: height / 2; - size_t regionPlane[3] = {planeWidth, planeHeight, 1}; - - error = clEnqueueReadImage(cmdQueue, memObjList[i], CL_TRUE, origin, regionPlane, 0, 0, - &out[offset], 0, 0, 0); - if (error != CL_SUCCESS) - { - log_error("clEnqueueReadImage failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - } - - offset += planeWidth * planeHeight; - } - - if (!YUVCompare(surfaceFormat, out, bufferRef1[frameIdx % FRAME_NUM], width, height)) - { - log_error("Frame idx: %i, OCL image is different then shared OCL object: clEnqueueReadImage\n", frameIdx); - result.ResultSub(CResult::TEST_FAIL); - } - } - - { //write operation - size_t offset = 0; - size_t origin[3] = {0,0,0}; - for (size_t i = 0; i < memObjList.size(); ++i) - { - size_t planeWidth = (i == 0) ? width: width / 2; - size_t planeHeight = (i == 0) ? height: height / 2; - size_t regionPlane[3] = {planeWidth, planeHeight, 1}; - - error = clEnqueueWriteImage(cmdQueue, memObjList[i], CL_TRUE, origin, regionPlane, - 0, 0, &bufferRef2[frameIdx % FRAME_NUM][offset], 0, 0, 0); - if (error != CL_SUCCESS) - { - log_error("clEnqueueWriteImage failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - } - - offset += planeWidth * planeHeight; - } - } - - { //read operation - std::vector out( frameSize, 0 ); - size_t offset = 0; - size_t origin[3] = {0,0,0}; - - for (size_t i = 0; i < memObjList.size(); ++i) - { - size_t planeWidth = (i == 0) ? width: width / 2; - size_t planeHeight = (i == 0) ? height: height / 2; - size_t regionPlane[3] = {planeWidth, planeHeight, 1}; - - error = clEnqueueReadImage(cmdQueue, memObjList[i], CL_TRUE, origin, regionPlane, 0, 0, - &out[offset], 0, 0, 0); - if (error != CL_SUCCESS) - { - log_error("clEnqueueReadImage failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - } - - offset += planeWidth * planeHeight; - } - - if (!YUVCompare(surfaceFormat, out, bufferRef2[frameIdx % FRAME_NUM], width, height)) - { - log_error("Frame idx: %i, Shared OCL image verification after clEnqueueWriteImage failed\n", frameIdx); - result.ResultSub(CResult::TEST_FAIL); - } - } - - { //copy operation (shared OCL to OCL) - size_t offset = 0; - size_t origin[3] = {0,0,0}; - std::vector out( frameSize, 0 ); - for (size_t i = 0; i < memObjList.size(); ++i) - { - size_t planeWidth = (i == 0) ? width: width / 2; - size_t planeHeight = (i == 0) ? height: height / 2; - size_t regionPlane[3] = {planeWidth, planeHeight, 1}; - - cl_image_format formatPlane; - formatPlane.image_channel_data_type = CL_UNORM_INT8; - formatPlane.image_channel_order = (surfaceFormat == SURFACE_FORMAT_NV12 && i > 0)? CL_RG: CL_R; - - cl_image_desc imageDesc = {0}; - imageDesc.image_type = CL_MEM_OBJECT_IMAGE2D; - imageDesc.image_width = planeWidth; - imageDesc.image_height = planeHeight; - - clMemWrapper planeOCL = clCreateImage(ctx, CL_MEM_READ_WRITE, &formatPlane, &imageDesc, 0, &error); - if (error != CL_SUCCESS) - { - log_error("clCreateImage failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - } - - error = clEnqueueCopyImage(cmdQueue, memObjList[i], planeOCL, origin, origin, regionPlane, 0, 0, 0); - if (error != CL_SUCCESS) - { - log_error("clEnqueueCopyImage failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - } - - error = clEnqueueReadImage(cmdQueue, planeOCL, CL_TRUE, origin, regionPlane, 0, 0, &out[offset], 0, 0, 0); - if (error != CL_SUCCESS) - { - log_error("clEnqueueReadImage failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - } - - offset += planeWidth * planeHeight; - } - - if (!YUVCompare(surfaceFormat, out, bufferRef2[frameIdx % FRAME_NUM], width, height)) - { - log_error("Frame idx: %i, OCL image verification after clEnqueueCopyImage (from shared OCL to OCL) failed\n", frameIdx); - result.ResultSub(CResult::TEST_FAIL); - } - } - - { //copy operation (OCL to shared OCL) - size_t offset = 0; - size_t origin[3] = {0,0,0}; - std::vector out( frameSize, 0 ); - for (size_t i = 0; i < memObjList.size(); ++i) - { - size_t planeWidth = (i == 0) ? width: width / 2; - size_t planeHeight = (i == 0) ? height: height / 2; - size_t regionPlane[3] = {planeWidth, planeHeight, 1}; - size_t pitchSize = ((surfaceFormat == SURFACE_FORMAT_NV12 && i > 0)? width: planeWidth) * sizeof(cl_uchar); - - cl_image_format formatPlane; - formatPlane.image_channel_data_type = CL_UNORM_INT8; - formatPlane.image_channel_order = (surfaceFormat == SURFACE_FORMAT_NV12 && i > 0)? CL_RG: CL_R; - - cl_image_desc imageDesc = {0}; - imageDesc.image_type = CL_MEM_OBJECT_IMAGE2D; - imageDesc.image_width = planeWidth; - imageDesc.image_height = planeHeight; - imageDesc.image_row_pitch = pitchSize; - - clMemWrapper planeOCL = clCreateImage(ctx, CL_MEM_COPY_HOST_PTR, &formatPlane, &imageDesc, &bufferRef1[frameIdx % FRAME_NUM][offset], &error); - if (error != CL_SUCCESS) - { - log_error("clCreateImage failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - } - - error = clEnqueueCopyImage(cmdQueue, planeOCL, memObjList[i], origin, origin, regionPlane, 0, 0, 0); - if (error != CL_SUCCESS) - { - log_error("clEnqueueCopyImage failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - } - - error = clEnqueueReadImage(cmdQueue, memObjList[i], CL_TRUE, origin, regionPlane, 0, 0, &out[offset], 0, 0, 0); - if (error != CL_SUCCESS) - { - log_error("clEnqueueReadImage failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - } - - offset += planeWidth * planeHeight; - } - - if (!YUVCompare(surfaceFormat, out, bufferRef1[frameIdx % FRAME_NUM], width, height)) - { - log_error("Frame idx: %i, OCL image verification after clEnqueueCopyImage (from OCL to shared OCL) failed\n", frameIdx); - result.ResultSub(CResult::TEST_FAIL); - } - } - - { //copy from image to buffer - size_t offset = 0; - size_t origin[3] = {0,0,0}; - size_t bufferSize = sizeof(cl_uchar) * frameSize; - clMemWrapper buffer = clCreateBuffer( ctx, CL_MEM_READ_WRITE, bufferSize, NULL, &error); - if (error != CL_SUCCESS) - { - log_error("clCreateBuffer failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - } - - for (size_t i = 0; i < memObjList.size(); ++i) - { - size_t planeWidth = (i == 0) ? width: width / 2; - size_t planeHeight = (i == 0) ? height: height / 2; - size_t regionPlane[3] = {planeWidth, planeHeight, 1}; - - error = clEnqueueCopyImageToBuffer(cmdQueue, memObjList[i], buffer, origin, regionPlane, offset, 0, 0, 0); - if (error != CL_SUCCESS) - { - log_error("clEnqueueCopyImageToBuffer failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - } - - offset += planeWidth * planeHeight * sizeof(cl_uchar); - } - - std::vector out( frameSize, 0 ); - error = clEnqueueReadBuffer( cmdQueue, buffer, CL_TRUE, 0, bufferSize, &out[0], 0, NULL, NULL ); - if (error != CL_SUCCESS) - { - log_error("Unable to read buffer"); - result.ResultSub(CResult::TEST_FAIL); - } - - if (!YUVCompare(surfaceFormat, out, bufferRef1[frameIdx % FRAME_NUM], width, height)) - { - log_error("Frame idx: %i, OCL buffer verification after clEnqueueCopyImageToBuffer (from shared OCL image to OCL buffer) failed\n", frameIdx); - result.ResultSub(CResult::TEST_FAIL); - } - } - - { //copy buffer to image - size_t bufferSize = sizeof(cl_uchar) * frameSize; - clMemWrapper buffer = clCreateBuffer( ctx, CL_MEM_COPY_HOST_PTR, bufferSize, &bufferRef2[frameIdx % FRAME_NUM][0], &error); - if (error != CL_SUCCESS) - { - log_error("clCreateBuffer failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - } - - size_t offset = 0; - size_t origin[3] = {0,0,0}; - std::vector out( frameSize, 0 ); - for (size_t i = 0; i < memObjList.size(); ++i) - { - size_t planeWidth = (i == 0) ? width: width / 2; - size_t planeHeight = (i == 0) ? height: height / 2; - size_t regionPlane[3] = {planeWidth, planeHeight, 1}; - - error = clEnqueueCopyBufferToImage(cmdQueue, buffer, memObjList[i], offset, origin, regionPlane, 0, 0, 0); - if (error != CL_SUCCESS) - { - log_error("clEnqueueCopyBufferToImage failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - } - - error = clEnqueueReadImage(cmdQueue, memObjList[i], CL_TRUE, origin, regionPlane, 0, 0, &out[offset], 0, 0, 0); - if (error != CL_SUCCESS) - { - log_error("clEnqueueReadImage failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - } - - offset += planeWidth * planeHeight * sizeof(cl_uchar); - } - - if (!YUVCompare(surfaceFormat, out, bufferRef2[frameIdx % FRAME_NUM], width, height)) - { - log_error("Frame idx: %i, OCL image verification after clEnqueueCopyBufferToImage (from OCL buffer to shared OCL image) failed\n", frameIdx); - result.ResultSub(CResult::TEST_FAIL); - } - } - - { //map operation to read - size_t offset = 0; - size_t origin[3] = {0,0,0}; - std::vector out( frameSize, 0 ); - for (size_t i = 0; i < memObjList.size(); ++i) - { - size_t planeWidth = (i == 0) ? width: width / 2; - size_t planeHeight = (i == 0) ? height: height / 2; - size_t regionPlane[3] = {planeWidth, planeHeight, 1}; - size_t pitchSize = ((surfaceFormat == SURFACE_FORMAT_NV12 && i > 0)? width: planeWidth); - - size_t rowPitch = 0; - size_t slicePitch = 0; - void *mapPtr = clEnqueueMapImage(cmdQueue, memObjList[i], CL_TRUE, CL_MAP_READ, origin, regionPlane, - &rowPitch, &slicePitch, 0, 0, 0, &error); - if (error != CL_SUCCESS) - { - log_error("clEnqueueMapImage failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - } - - for (size_t y = 0; y < planeHeight; ++y) - memcpy(&out[offset + y * pitchSize], static_cast(mapPtr) + y * rowPitch / sizeof(cl_uchar), pitchSize * sizeof(cl_uchar)); - - error = clEnqueueUnmapMemObject(cmdQueue, memObjList[i], mapPtr, 0, 0, 0); - if (error != CL_SUCCESS) - { - log_error("clEnqueueUnmapMemObject failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - } - - offset += pitchSize * planeHeight; - } - - if (!YUVCompare(surfaceFormat, out, bufferRef2[frameIdx % FRAME_NUM], width, height)) - { - log_error("Frame idx: %i, Mapped shared OCL image is different then expected\n", frameIdx); - result.ResultSub(CResult::TEST_FAIL); - } - } - - { //map operation to write - size_t offset = 0; - size_t origin[3] = {0,0,0}; - for (size_t i = 0; i < memObjList.size(); ++i) - { - size_t planeWidth = (i == 0) ? width: width / 2; - size_t planeHeight = (i == 0) ? height: height / 2; - size_t regionPlane[3] = {planeWidth, planeHeight, 1}; - size_t pitchSize = ((surfaceFormat == SURFACE_FORMAT_NV12 && i > 0)? width: planeWidth); - - size_t rowPitch = 0; - size_t slicePitch = 0; - void *mapPtr = clEnqueueMapImage(cmdQueue, memObjList[i], CL_TRUE, CL_MAP_WRITE, origin, regionPlane, - &rowPitch, &slicePitch, 0, 0, 0, &error); - if (error != CL_SUCCESS) - { - log_error("clEnqueueMapImage failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - } - - for (size_t y = 0; y < planeHeight; ++y) - memcpy(static_cast(mapPtr) + y * rowPitch / sizeof(cl_uchar), &bufferRef3[frameIdx % FRAME_NUM][offset + y * pitchSize], pitchSize * sizeof(cl_uchar)); - - error = clEnqueueUnmapMemObject(cmdQueue, memObjList[i], mapPtr, 0, 0, 0); - if (error != CL_SUCCESS) - { - log_error("clEnqueueUnmapMemObject failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - } - - offset += pitchSize * planeHeight; - } - } - - error = clEnqueueReleaseDX9MediaSurfacesKHR(cmdQueue, static_cast(memObjList.size()), &memObjList[0], 0, 0, 0); - if (error != CL_SUCCESS) - { - log_error("clEnqueueReleaseDX9MediaSurfacesKHR failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - } - - std::vector bufferOut(frameSize, 0); - if (!YUVSurfaceGet(surfaceFormat, surface, bufferOut, width, height)) - { - result.ResultSub(CResult::TEST_FAIL); - return result.Result(); - } - - if (!YUVCompare(surfaceFormat, bufferOut, bufferRef3[frameIdx % FRAME_NUM], width, height)) - { - log_error("Frame idx: %i, media surface is different than expected\n", frameIdx); - result.ResultSub(CResult::TEST_FAIL); - } - } - } - - if (deviceWrapper->Status() != DEVICE_PASS) - { - std::string adapterName; - AdapterToString(adapterType, adapterName); - if (deviceWrapper->Status() == DEVICE_FAIL) - { - log_error("%s init failed\n", adapterName.c_str()); - result.ResultSub(CResult::TEST_FAIL); - } - else - { - log_error("%s init incomplete due to unsupported device\n", adapterName.c_str()); - result.ResultSub(CResult::TEST_NOTSUPPORTED); - } - } - - return result.Result(); -} - -int test_api(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) -{ - CResult result; - -#if defined(_WIN32) - //D3D9 - if(api_functions(deviceID, context, queue, num_elements, 10, 256, 256, CL_ADAPTER_D3D9_KHR, - SURFACE_FORMAT_NV12, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (D3D9, NV12, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(api_functions(deviceID, context, queue, num_elements, 3, 512, 256, CL_ADAPTER_D3D9_KHR, - SURFACE_FORMAT_YV12, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (D3D9, YV12, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - //D3D9EX - if(api_functions(deviceID, context, queue, num_elements, 5, 256, 512, CL_ADAPTER_D3D9EX_KHR, - SURFACE_FORMAT_NV12, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (D3D9EX, NV12, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(api_functions(deviceID, context, queue, num_elements, 7, 512, 256, CL_ADAPTER_D3D9EX_KHR, - SURFACE_FORMAT_NV12, SHARED_HANDLE_ENABLED) != 0) - { - log_error("\nTest case (D3D9EX, NV12, shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(api_functions(deviceID, context, queue, num_elements, 10, 256, 256, CL_ADAPTER_D3D9EX_KHR, - SURFACE_FORMAT_YV12, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (D3D9EX, YV12, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(api_functions(deviceID, context, queue, num_elements, 15, 128, 128, CL_ADAPTER_D3D9EX_KHR, - SURFACE_FORMAT_YV12, SHARED_HANDLE_ENABLED) != 0) - { - log_error("\nTest case (D3D9EX, YV12, shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - //DXVA - if(api_functions(deviceID, context, queue, num_elements, 20, 128, 128, CL_ADAPTER_DXVA_KHR, - SURFACE_FORMAT_NV12, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (DXVA, NV12, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(api_functions(deviceID, context, queue, num_elements, 40, 64, 64, CL_ADAPTER_DXVA_KHR, - SURFACE_FORMAT_NV12, SHARED_HANDLE_ENABLED) != 0) - { - log_error("\nTest case (DXVA, NV12, shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(api_functions(deviceID, context, queue, num_elements, 5, 512, 512, CL_ADAPTER_DXVA_KHR, - SURFACE_FORMAT_YV12, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (DXVA, YV12, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(api_functions(deviceID, context, queue, num_elements, 2, 1024, 1024, CL_ADAPTER_DXVA_KHR, - SURFACE_FORMAT_YV12, SHARED_HANDLE_ENABLED) != 0) - { - log_error("\nTest case (DXVA, YV12, shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - -#else - return TEST_NOT_IMPLEMENTED; -#endif - - return result.Result(); -} diff --git a/test_extensions/media_sharing/test_functions_kernel.cpp b/test_extensions/media_sharing/test_functions_kernel.cpp deleted file mode 100644 index f5c3e2da..00000000 --- a/test_extensions/media_sharing/test_functions_kernel.cpp +++ /dev/null @@ -1,446 +0,0 @@ -// -// 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 -#include - -#include "harness/errorHelpers.h" -#include "harness/kernelHelpers.h" - -#include "utils.h" - -int kernel_functions(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements, - unsigned int iterationNum, unsigned int width, unsigned int height, cl_dx9_media_adapter_type_khr adapterType, - TSurfaceFormat surfaceFormat, TSharedHandleType sharedHandle) -{ - const unsigned int FRAME_NUM = 2; - const cl_uchar MAX_VALUE = 255 / 2; - const std::string PROGRAM_STR = - "__kernel void TestFunction( read_only image2d_t planeIn, write_only image2d_t planeOut, " - NL " sampler_t sampler, __global int *planeRes)" - NL "{" - NL " int w = get_global_id(0);" - NL " int h = get_global_id(1);" - NL " int width = get_image_width(planeIn);" - NL " int height = get_image_height(planeOut);" - NL " float4 color0 = read_imagef(planeIn, sampler, (int2)(w,h)) + 0.2f;" - NL " float4 color1 = read_imagef(planeIn, sampler, (float2)(w,h)) + 0.2f;" - NL " color0 = (color0 == color1) ? color0: (float4)(0.5, 0.5, 0.5, 0.5);" - NL " write_imagef(planeOut, (int2)(w,h), color0);" - NL " if(w == 0 && h == 0)" - NL " {" - NL " planeRes[0] = width;" - NL " planeRes[1] = height;" - NL " }" - NL "}"; - - CResult result; - - std::auto_ptr deviceWrapper; - if (!DeviceCreate(adapterType, deviceWrapper)) - { - result.ResultSub(CResult::TEST_ERROR); - return result.Result(); - } - - std::vector > bufferIn(FRAME_NUM); - std::vector > bufferExp(FRAME_NUM); - size_t frameSize = width * height * 3 / 2; - cl_uchar step = MAX_VALUE / FRAME_NUM; - for (size_t i = 0; i < FRAME_NUM; ++i) - { - if (!YUVGenerate(surfaceFormat, bufferIn[i], width, height, static_cast(step * i), static_cast(step * (i + 1))) || - !YUVGenerate(surfaceFormat, bufferExp[i], width, height, static_cast(step * i), static_cast(step * (i + 1)), 0.2)) - { - result.ResultSub(CResult::TEST_ERROR); - return result.Result(); - } - } - - while (deviceWrapper->AdapterNext()) - { - cl_int error; - //check if the test can be run on the adapter - if (CL_SUCCESS != (error = deviceExistForCLTest(gPlatformIDdetected, adapterType, deviceWrapper->Device(), result, sharedHandle))) - { - return result.Result(); - } - - if (surfaceFormat != SURFACE_FORMAT_NV12 && !SurfaceFormatCheck(adapterType, *deviceWrapper, surfaceFormat)) - { - std::string sharedHandleStr = (sharedHandle == SHARED_HANDLE_ENABLED)? "yes": "no"; - std::string formatStr; - std::string adapterStr; - SurfaceFormatToString(surfaceFormat, formatStr); - AdapterToString(adapterType, adapterStr); - log_info("Skipping test case, image format is not supported by a device (adapter type: %s, format: %s, shared handle: %s)\n", - adapterStr.c_str(), formatStr.c_str(), sharedHandleStr.c_str()); - return result.Result(); - } - - void *objectSrcHandle = 0; - std::auto_ptr surfaceSrc; - if (!MediaSurfaceCreate(adapterType, width, height, surfaceFormat, *deviceWrapper, surfaceSrc, - (sharedHandle == SHARED_HANDLE_ENABLED) ? true: false, &objectSrcHandle)) - { - log_error("Media surface creation failed for %i adapter\n", deviceWrapper->AdapterIdx()); - result.ResultSub(CResult::TEST_ERROR); - return result.Result(); - } - - void *objectDstHandle = 0; - std::auto_ptr surfaceDst; - if (!MediaSurfaceCreate(adapterType, width, height, surfaceFormat, *deviceWrapper, surfaceDst, - (sharedHandle == SHARED_HANDLE_ENABLED) ? true: false, &objectDstHandle)) - { - log_error("Media surface creation failed for %i adapter\n", deviceWrapper->AdapterIdx()); - result.ResultSub(CResult::TEST_ERROR); - return result.Result(); - } - - cl_context_properties contextProperties[] = { - CL_CONTEXT_PLATFORM, (cl_context_properties)gPlatformIDdetected, - AdapterTypeToContextInfo(adapterType), (cl_context_properties)deviceWrapper->Device(), - 0, - }; - - clContextWrapper ctx = clCreateContext(&contextProperties[0], 1, &gDeviceIDdetected, NULL, NULL, &error); - if (error != CL_SUCCESS) - { - log_error("clCreateContext failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - return result.Result(); - } - -#if defined(_WIN32) - cl_dx9_surface_info_khr surfaceInfoSrc; - surfaceInfoSrc.resource = *(static_cast(surfaceSrc.get())); - surfaceInfoSrc.shared_handle = objectSrcHandle; - - cl_dx9_surface_info_khr surfaceInfoDst; - surfaceInfoDst.resource = *(static_cast(surfaceDst.get())); - surfaceInfoDst.shared_handle = objectDstHandle; -#else - void *surfaceInfoSrc = 0; - void *surfaceInfoDst = 0; - return TEST_NOT_IMPLEMENTED; -#endif - - std::vector memObjSrcList; - std::vector memObjDstList; - unsigned int planesNum = PlanesNum(surfaceFormat); - std::vector planeSrcList(planesNum); - std::vector planeDstList(planesNum); - for (unsigned int planeIdx = 0; planeIdx < planesNum; ++planeIdx) - { - planeSrcList[planeIdx] = clCreateFromDX9MediaSurfaceKHR(ctx, CL_MEM_READ_WRITE, adapterType, &surfaceInfoSrc, planeIdx, &error); - if (error != CL_SUCCESS) - { - log_error("clCreateFromDX9MediaSurfaceKHR failed for plane %i: %s\n", planeIdx, IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - return result.Result(); - } - memObjSrcList.push_back(planeSrcList[planeIdx]); - - planeDstList[planeIdx] = clCreateFromDX9MediaSurfaceKHR(ctx, CL_MEM_READ_WRITE, adapterType, &surfaceInfoDst, planeIdx, &error); - if (error != CL_SUCCESS) - { - log_error("clCreateFromDX9MediaSurfaceKHR failed for plane %i: %s\n", planeIdx, IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - return result.Result(); - } - memObjDstList.push_back(planeDstList[planeIdx]); - } - - clCommandQueueWrapper cmdQueue = clCreateCommandQueueWithProperties(ctx, gDeviceIDdetected, 0, &error ); - if (error != CL_SUCCESS) - { - log_error("Unable to create command queue: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - return result.Result(); - } - - if (!ImageInfoVerify(adapterType, memObjSrcList, width, height, surfaceSrc, objectSrcHandle)) - { - log_error("Image info verification failed\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - for (size_t frameIdx = 0; frameIdx < iterationNum; ++frameIdx) - { - if (!YUVSurfaceSet(surfaceFormat, surfaceSrc, bufferIn[frameIdx % FRAME_NUM], width, height)) - { - result.ResultSub(CResult::TEST_ERROR); - return result.Result(); - } - - error = clEnqueueAcquireDX9MediaSurfacesKHR(cmdQueue, static_cast(memObjSrcList.size()), &memObjSrcList[0], 0, 0, 0); - if (error != CL_SUCCESS) - { - log_error("clEnqueueAcquireDX9MediaSurfacesKHR failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - return result.Result(); - } - - error = clEnqueueAcquireDX9MediaSurfacesKHR(cmdQueue, static_cast(memObjDstList.size()), &memObjDstList[0], 0, 0, 0); - if (error != CL_SUCCESS) - { - log_error("clEnqueueAcquireDX9MediaSurfacesKHR failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - return result.Result(); - } - - clSamplerWrapper sampler = clCreateSampler( ctx, CL_FALSE, CL_ADDRESS_NONE, CL_FILTER_NEAREST, &error ); - if(error != CL_SUCCESS) - { - log_error("Unable to create sampler\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - clProgramWrapper program; - clKernelWrapper kernel; - const char *progPtr = PROGRAM_STR.c_str(); - if(create_single_kernel_helper(ctx, &program, &kernel, 1, (const char **)&progPtr, "TestFunction")) - result.ResultSub(CResult::TEST_FAIL); - - size_t bufferSize = sizeof(cl_int) * 2; - clMemWrapper imageRes = clCreateBuffer( ctx, CL_MEM_READ_WRITE, bufferSize, NULL, &error); - if (error != CL_SUCCESS) - { - log_error("clCreateBuffer failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - } - - size_t offset = 0; - size_t origin[3] = {0,0,0}; - std::vector out( frameSize, 0 ); - for (size_t i = 0; i < memObjSrcList.size(); ++i) - { - size_t planeWidth = (i == 0) ? width: width / 2; - size_t planeHeight = (i == 0) ? height: height / 2; - size_t regionPlane[3] = {planeWidth, planeHeight, 1}; - size_t threads[ 2 ] = { planeWidth, planeHeight }; - - error = clSetKernelArg( kernel, 0, sizeof( memObjSrcList[i] ), &memObjSrcList[i] ); - if (error != CL_SUCCESS) - { - log_error("Unable to set kernel arguments" ); - result.ResultSub(CResult::TEST_FAIL); - } - - error = clSetKernelArg( kernel, 1, sizeof( memObjDstList[i] ), &memObjDstList[i] ); - if (error != CL_SUCCESS) - { - log_error("Unable to set kernel arguments" ); - result.ResultSub(CResult::TEST_FAIL); - } - - error = clSetKernelArg( kernel, 2, sizeof( sampler ), &sampler ); - if (error != CL_SUCCESS) - { - log_error("Unable to set kernel arguments" ); - result.ResultSub(CResult::TEST_FAIL); - } - - error = clSetKernelArg( kernel, 3, sizeof( imageRes ), &imageRes ); - if (error != CL_SUCCESS) - { - log_error("Unable to set kernel arguments" ); - result.ResultSub(CResult::TEST_FAIL); - } - - size_t localThreads[ 2 ]; - error = get_max_common_2D_work_group_size( ctx, kernel, threads, localThreads ); - if (error != CL_SUCCESS) - { - log_error("Unable to get work group size to use" ); - result.ResultSub(CResult::TEST_FAIL); - } - - error = clEnqueueNDRangeKernel( cmdQueue, kernel, 2, NULL, threads, localThreads, 0, NULL, NULL ); - if (error != CL_SUCCESS) - { - log_error("Unable to execute test kernel" ); - result.ResultSub(CResult::TEST_FAIL); - } - - std::vector imageResOut(2, 0); - error = clEnqueueReadBuffer( cmdQueue, imageRes, CL_TRUE, 0, bufferSize, &imageResOut[0], 0, NULL, NULL ); - if (error != CL_SUCCESS) - { - log_error("Unable to read buffer"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(imageResOut[0] != planeWidth) - { - log_error("Invalid width value, test = %i, expected = %i\n", imageResOut[0], planeWidth); - result.ResultSub(CResult::TEST_FAIL); - } - - if(imageResOut[1] != planeHeight) - { - log_error("Invalid height value, test = %i, expected = %i\n", imageResOut[1], planeHeight); - result.ResultSub(CResult::TEST_FAIL); - } - - error = clEnqueueReadImage(cmdQueue, memObjDstList[i], CL_TRUE, origin, regionPlane, 0, 0, &out[offset], 0, 0, 0); - if (error != CL_SUCCESS) - { - log_error("clEnqueueReadImage failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - } - - offset += planeWidth * planeHeight; - } - - if (!YUVCompare(surfaceFormat, out, bufferExp[frameIdx % FRAME_NUM], width, height)) - { - log_error("Frame idx: %i, OCL objects are different than expected\n", frameIdx); - result.ResultSub(CResult::TEST_FAIL); - } - - error = clEnqueueReleaseDX9MediaSurfacesKHR(cmdQueue, static_cast(memObjSrcList.size()), &memObjSrcList[0], 0, 0, 0); - if (error != CL_SUCCESS) - { - log_error("clEnqueueReleaseDX9MediaSurfacesKHR failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - } - - error = clEnqueueReleaseDX9MediaSurfacesKHR(cmdQueue, static_cast(memObjDstList.size()), &memObjDstList[0], 0, 0, 0); - if (error != CL_SUCCESS) - { - log_error("clEnqueueReleaseDX9MediaSurfacesKHR failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - } - - std::vector bufferOut(frameSize, 0); - if (!YUVSurfaceGet(surfaceFormat, surfaceDst, bufferOut, width, height)) - { - result.ResultSub(CResult::TEST_FAIL); - return result.Result(); - } - - if (!YUVCompare(surfaceFormat, bufferOut, bufferExp[frameIdx % FRAME_NUM], width, height)) - { - log_error("Frame idx: %i, media surface is different than expected\n", frameIdx); - result.ResultSub(CResult::TEST_FAIL); - } - } - } - - if (deviceWrapper->Status() != DEVICE_PASS) - { - std::string adapterName; - AdapterToString(adapterType, adapterName); - if (deviceWrapper->Status() == DEVICE_FAIL) - { - log_error("%s init failed\n", adapterName.c_str()); - result.ResultSub(CResult::TEST_FAIL); - } - else - { - log_error("%s init incomplete due to unsupported device\n", adapterName.c_str()); - result.ResultSub(CResult::TEST_NOTSUPPORTED); - } - } - - return result.Result(); -} - -int test_kernel(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) -{ - CResult result; - -#if defined(_WIN32) - //D3D9 - if(kernel_functions(deviceID, context, queue, num_elements, 10, 256, 256, CL_ADAPTER_D3D9_KHR, - SURFACE_FORMAT_NV12, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (D3D9, NV12, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(kernel_functions(deviceID, context, queue, num_elements, 3, 256, 256, CL_ADAPTER_D3D9_KHR, - SURFACE_FORMAT_YV12, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (D3D9, YV12, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - //D3D9EX - if(kernel_functions(deviceID, context, queue, num_elements, 5, 256, 512, CL_ADAPTER_D3D9EX_KHR, - SURFACE_FORMAT_NV12, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (D3D9EX, NV12, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(kernel_functions(deviceID, context, queue, num_elements, 7, 512, 256, CL_ADAPTER_D3D9EX_KHR, - SURFACE_FORMAT_NV12, SHARED_HANDLE_ENABLED) != 0) - { - log_error("\nTest case (D3D9EX, NV12, shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(kernel_functions(deviceID, context, queue, num_elements, 10, 256, 256, CL_ADAPTER_D3D9EX_KHR, - SURFACE_FORMAT_YV12, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (D3D9EX, YV12, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(kernel_functions(deviceID, context, queue, num_elements, 15, 128, 128, CL_ADAPTER_D3D9EX_KHR, - SURFACE_FORMAT_YV12, SHARED_HANDLE_ENABLED) != 0) - { - log_error("\nTest case (D3D9EX, YV12, shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - //DXVA - if(kernel_functions(deviceID, context, queue, num_elements, 20, 128, 128, CL_ADAPTER_DXVA_KHR, - SURFACE_FORMAT_NV12, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (DXVA, NV12, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(kernel_functions(deviceID, context, queue, num_elements, 40, 64, 64, CL_ADAPTER_DXVA_KHR, - SURFACE_FORMAT_NV12, SHARED_HANDLE_ENABLED) != 0) - { - log_error("\nTest case (DXVA, NV12, shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(kernel_functions(deviceID, context, queue, num_elements, 5, 512, 512, CL_ADAPTER_DXVA_KHR, - SURFACE_FORMAT_YV12, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (DXVA, YV12, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(kernel_functions(deviceID, context, queue, num_elements, 2, 1024, 1024, CL_ADAPTER_DXVA_KHR, - SURFACE_FORMAT_YV12, SHARED_HANDLE_ENABLED) != 0) - { - log_error("\nTest case (DXVA, YV12, shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - -#else - return TEST_NOT_IMPLEMENTED; -#endif - - return result.Result(); -} diff --git a/test_extensions/media_sharing/test_get_device_ids.cpp b/test_extensions/media_sharing/test_get_device_ids.cpp deleted file mode 100644 index f8947ea6..00000000 --- a/test_extensions/media_sharing/test_get_device_ids.cpp +++ /dev/null @@ -1,196 +0,0 @@ -// -// 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 "utils.h" - -int get_device_ids(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements, - cl_dx9_media_adapter_type_khr adapterType) -{ - CResult result; - - std::auto_ptr deviceWrapper; - if (!DeviceCreate(adapterType, deviceWrapper)) - { - result.ResultSub(CResult::TEST_ERROR); - return result.Result(); - } - - cl_uint devicesExpectedNum = 0; - cl_int error = clGetDeviceIDs(gPlatformIDdetected, CL_DEVICE_TYPE_ALL, 0, 0, &devicesExpectedNum); - if (error != CL_SUCCESS || devicesExpectedNum < 1) - { - log_error("clGetDeviceIDs failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - return result.Result(); - } - - std::vector devicesExpected(devicesExpectedNum); - error = clGetDeviceIDs(gPlatformIDdetected, CL_DEVICE_TYPE_ALL, devicesExpectedNum, &devicesExpected[0], 0); - if (error != CL_SUCCESS) - { - log_error("clGetDeviceIDs failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - return result.Result(); - } - - while (deviceWrapper->AdapterNext()) - { - std::vector mediaAdapterTypes; - mediaAdapterTypes.push_back(adapterType); - - std::vector mediaDevices; - mediaDevices.push_back(deviceWrapper->Device()); - - //check if the test can be run on the adapter - if (CL_SUCCESS != (error = deviceExistForCLTest(gPlatformIDdetected, adapterType, deviceWrapper->Device(), result))) - { - return result.Result(); - } - - cl_uint devicesAllNum = 0; - error = clGetDeviceIDsFromDX9MediaAdapterKHR(gPlatformIDdetected, 1, &mediaAdapterTypes[0], &mediaDevices[0], - CL_ALL_DEVICES_FOR_DX9_MEDIA_ADAPTER_KHR, 0, 0, &devicesAllNum); - if (error != CL_SUCCESS && error != CL_DEVICE_NOT_FOUND) - { - log_error("clGetDeviceIDsFromDX9MediaAdapterKHR failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - return result.Result(); - } - - std::vector devicesAll; - if (devicesAllNum > 0) - { - devicesAll.resize(devicesAllNum); - error = clGetDeviceIDsFromDX9MediaAdapterKHR(gPlatformIDdetected, 1, &mediaAdapterTypes[0], &mediaDevices[0], - CL_ALL_DEVICES_FOR_DX9_MEDIA_ADAPTER_KHR, devicesAllNum, &devicesAll[0], 0); - if (error != CL_SUCCESS) - { - log_error("clGetDeviceIDsFromDX9MediaAdapterKHR failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - return result.Result(); - } - } - - cl_uint devicesPreferredNum = 0; - error = clGetDeviceIDsFromDX9MediaAdapterKHR(gPlatformIDdetected, 1, &mediaAdapterTypes[0], &mediaDevices[0], - CL_PREFERRED_DEVICES_FOR_DX9_MEDIA_ADAPTER_KHR, 0, 0, &devicesPreferredNum); - if (error != CL_SUCCESS && error != CL_DEVICE_NOT_FOUND) - { - log_error("clGetDeviceIDsFromDX9MediaAdapterKHR failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - return result.Result(); - } - - std::vector devicesPreferred; - if (devicesPreferredNum > 0) - { - devicesPreferred.resize(devicesPreferredNum); - error = clGetDeviceIDsFromDX9MediaAdapterKHR(gPlatformIDdetected, 1, &mediaAdapterTypes[0], &mediaDevices[0], - CL_PREFERRED_DEVICES_FOR_DX9_MEDIA_ADAPTER_KHR, devicesPreferredNum, &devicesPreferred[0], 0); - if (error != CL_SUCCESS) - { - log_error("clGetDeviceIDsFromDX9MediaAdapterKHR failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - return result.Result(); - } - } - - if (devicesAllNum < devicesPreferredNum) - { - log_error("Invalid number of preferred devices. It should be a subset of all devices\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - for (cl_uint i = 0; i < devicesPreferredNum; ++i) - { - cl_uint j = 0; - for (; j < devicesAllNum; ++j) - { - if (devicesPreferred[i] == devicesAll[j]) - break; - } - - if (j == devicesAllNum) - { - log_error("Preferred device is not a subset of all devices\n"); - result.ResultSub(CResult::TEST_FAIL); - } - } - - for (cl_uint i = 0; i < devicesAllNum; ++i) - { - cl_uint j = 0; - for (; j < devicesExpectedNum; ++j) - { - if (devicesAll[i] == devicesExpected[j]) - break; - } - - if (j == devicesExpectedNum) - { - log_error("CL_ALL_DEVICES_FOR_MEDIA_ADAPTER_KHR should be a subset of all devices for selected platform\n"); - result.ResultSub(CResult::TEST_FAIL); - } - } - } - - if (deviceWrapper->Status() != DEVICE_PASS) - { - std::string adapterName; - AdapterToString(adapterType, adapterName); - if (deviceWrapper->Status() == DEVICE_FAIL) - { - log_error("%s init failed\n", adapterName.c_str()); - result.ResultSub(CResult::TEST_FAIL); - } - else - { - log_error("%s init incomplete due to unsupported device\n", adapterName.c_str()); - result.ResultSub(CResult::TEST_NOTSUPPORTED); - } - } - - return result.Result(); -} - -int test_get_device_ids(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) -{ - CResult result; - -#if defined(_WIN32) - if(get_device_ids(deviceID, context, queue, num_elements, CL_ADAPTER_D3D9_KHR) != 0) - { - log_error("\nTest case (D3D9) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(get_device_ids(deviceID, context, queue, num_elements, CL_ADAPTER_D3D9EX_KHR) != 0) - { - log_error("\nTest case (D3D9EX) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(get_device_ids(deviceID, context, queue, num_elements, CL_ADAPTER_DXVA_KHR) != 0) - { - log_error("\nTest case (DXVA) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - -#else - return TEST_NOT_IMPLEMENTED; -#endif - - return result.Result(); -} diff --git a/test_extensions/media_sharing/test_interop_sync.cpp b/test_extensions/media_sharing/test_interop_sync.cpp deleted file mode 100644 index 6831a14d..00000000 --- a/test_extensions/media_sharing/test_interop_sync.cpp +++ /dev/null @@ -1,357 +0,0 @@ -// -// 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 "utils.h" - -int interop_user_sync(cl_device_id deviceID, cl_context context, cl_command_queue queue, - int num_elements, unsigned int width, unsigned int height, - TContextFuncType functionCreate, cl_dx9_media_adapter_type_khr adapterType, - TSurfaceFormat surfaceFormat, TSharedHandleType sharedHandle, cl_bool userSync) -{ - CResult result; - - //create device - std::auto_ptr deviceWrapper; - if (!DeviceCreate(adapterType, deviceWrapper)) - { - result.ResultSub(CResult::TEST_ERROR); - return result.Result(); - } - - //generate input data - std::vector bufferIn(width * height * 3 / 2, 0); - if(!YUVGenerate(surfaceFormat, bufferIn, width, height, 0, 255)) - { - result.ResultSub(CResult::TEST_ERROR); - return result.Result(); - } - - while (deviceWrapper->AdapterNext()) - { - cl_int error; - //check if the test can be run on the adapter - if (CL_SUCCESS != (error = deviceExistForCLTest(gPlatformIDdetected, adapterType, deviceWrapper->Device(), result, sharedHandle))) - { - return result.Result(); - } - - if (surfaceFormat != SURFACE_FORMAT_NV12 && - !SurfaceFormatCheck(adapterType, *deviceWrapper, surfaceFormat)) - { - std::string sharedHandleStr = (sharedHandle == SHARED_HANDLE_ENABLED)? "yes": "no"; - std::string syncStr = (userSync == CL_TRUE) ? "yes": "no"; - std::string formatStr; - std::string adapterStr; - SurfaceFormatToString(surfaceFormat, formatStr); - AdapterToString(adapterType, adapterStr); - log_info("Skipping test case, image format is not supported by a device (adapter type: %s, format: %s, shared handle: %s, user sync: %s)\n", - adapterStr.c_str(), formatStr.c_str(), sharedHandleStr.c_str(), syncStr.c_str()); - return result.Result(); - } - - void *objectSharedHandle = 0; - std::auto_ptr surface; - if (!MediaSurfaceCreate(adapterType, width, height, surfaceFormat, *deviceWrapper, surface, - (sharedHandle == SHARED_HANDLE_ENABLED) ? true: false, &objectSharedHandle)) - { - log_error("Media surface creation failed for %i adapter\n", deviceWrapper->AdapterIdx()); - result.ResultSub(CResult::TEST_ERROR); - return result.Result(); - } - - cl_context_properties contextProperties[] = { - CL_CONTEXT_PLATFORM, (cl_context_properties)gPlatformIDdetected, - AdapterTypeToContextInfo(adapterType), (cl_context_properties)deviceWrapper->Device(), - CL_CONTEXT_INTEROP_USER_SYNC, userSync, - 0, - }; - - - clContextWrapper ctx; - switch(functionCreate) - { - case CONTEXT_CREATE_DEFAULT: - ctx = clCreateContext(&contextProperties[0], 1, &gDeviceIDdetected, NULL, NULL, &error); - break; - case CONTEXT_CREATE_FROM_TYPE: - ctx = clCreateContextFromType(&contextProperties[0], gDeviceTypeSelected, NULL, NULL, &error); - break; - default: - log_error("Unknown context creation function enum\n"); - result.ResultSub(CResult::TEST_ERROR); - return result.Result(); - break; - } - - if (error != CL_SUCCESS) - { - std::string functionName; - FunctionContextCreateToString(functionCreate, functionName); - log_error("%s failed: %s\n", functionName.c_str(), IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - return result.Result(); - } - - if (!YUVSurfaceSet(surfaceFormat, surface, bufferIn, width, height)) - { - result.ResultSub(CResult::TEST_ERROR); - return result.Result(); - } - -#if defined(_WIN32) - cl_dx9_surface_info_khr surfaceInfo; - surfaceInfo.resource = *(static_cast(surface.get())); - surfaceInfo.shared_handle = objectSharedHandle; -#else - void *surfaceInfo = 0; - return TEST_NOT_IMPLEMENTED; -#endif - - std::vector memObjList; - unsigned int planesNum = PlanesNum(surfaceFormat); - std::vector planesList(planesNum); - for (unsigned int planeIdx = 0; planeIdx < planesNum; ++planeIdx) - { - planesList[planeIdx] = clCreateFromDX9MediaSurfaceKHR(ctx, CL_MEM_READ_WRITE, adapterType, &surfaceInfo, planeIdx, &error); - if (error != CL_SUCCESS) - { - log_error("clCreateFromDX9MediaSurfaceKHR failed for plane %i: %s\n", planeIdx, IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - return result.Result(); - } - memObjList.push_back(planesList[planeIdx]); - } - - clCommandQueueWrapper cmdQueue = clCreateCommandQueueWithProperties(ctx, gDeviceIDdetected, 0, &error ); - if (error != CL_SUCCESS) - { - log_error("Unable to create command queue: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - return result.Result(); - } - - if (!ImageInfoVerify(adapterType, memObjList, width, height, surface, objectSharedHandle)) - { - log_error("Image info verification failed\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if (userSync == CL_TRUE) - { - #if defined(_WIN32) - IDirect3DQuery9* eventQuery = NULL; - switch (adapterType) - { - case CL_ADAPTER_D3D9_KHR: - { - LPDIRECT3DDEVICE9 device = (LPDIRECT3DDEVICE9)deviceWrapper->Device(); - device->CreateQuery(D3DQUERYTYPE_EVENT, &eventQuery); - eventQuery->Issue(D3DISSUE_END); - - while (S_FALSE == eventQuery->GetData(NULL, 0, D3DGETDATA_FLUSH)) - ; - } - break; - case CL_ADAPTER_D3D9EX_KHR: - { - LPDIRECT3DDEVICE9EX device = (LPDIRECT3DDEVICE9EX)deviceWrapper->Device(); - device->CreateQuery(D3DQUERYTYPE_EVENT, &eventQuery); - eventQuery->Issue(D3DISSUE_END); - - while (S_FALSE == eventQuery->GetData(NULL, 0, D3DGETDATA_FLUSH)) - ; - } - break; - case CL_ADAPTER_DXVA_KHR: - { - CDXVAWrapper *DXVADevice = dynamic_cast(&(*deviceWrapper)); - LPDIRECT3DDEVICE9EX device = (LPDIRECT3DDEVICE9EX)(DXVADevice->D3D9()).Device(); - device->CreateQuery(D3DQUERYTYPE_EVENT, &eventQuery); - eventQuery->Issue(D3DISSUE_END); - - while (S_FALSE == eventQuery->GetData(NULL, 0, D3DGETDATA_FLUSH)) - ; - } - break; - default: - log_error("Unknown adapter type\n"); - return false; - break; - } - if(eventQuery) - { - eventQuery->Release(); - } -#else - return TEST_NOT_IMPLEMENTED; -#endif - } - - error = clEnqueueAcquireDX9MediaSurfacesKHR(cmdQueue, static_cast(memObjList.size()), &memObjList.at(0), 0, 0, 0); - if (error != CL_SUCCESS) - { - log_error("clEnqueueAcquireDX9MediaSurfacesKHR failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - return result.Result(); - } - - size_t origin[3] = {0,0,0}; - size_t offset = 0; - size_t frameSize = width * height * 3 / 2; - std::vector out( frameSize, 0 ); - for (size_t i = 0; i < memObjList.size(); ++i) - { - size_t planeWidth = (i == 0) ? width: width / 2; - size_t planeHeight = (i == 0) ? height: height / 2; - size_t regionPlane[3] = {planeWidth, planeHeight, 1}; - - error = clEnqueueReadImage(cmdQueue, memObjList.at(i), CL_TRUE, origin, regionPlane, 0, 0, &out.at(offset), 0, 0, 0); - if (error != CL_SUCCESS) - { - log_error("clEnqueueReadImage failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - } - - offset += planeWidth * planeHeight; - } - - if (!YUVCompare(surfaceFormat, out, bufferIn, width, height)) - { - log_error("OCL object verification failed - clEnqueueReadImage\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - error = clEnqueueReleaseDX9MediaSurfacesKHR(cmdQueue, static_cast(memObjList.size()), &memObjList.at(0), 0, 0, 0); - if (error != CL_SUCCESS) - { - log_error("clEnqueueReleaseDX9MediaSurfacesKHR failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - } - - if (userSync == CL_TRUE) - { - error = clFinish(cmdQueue); - if (error != CL_SUCCESS) - { - log_error("clFinish failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - } - } - - //shared object verification - std::vector bufferOut(frameSize, 0); - if (!YUVSurfaceGet(surfaceFormat, surface, bufferOut, width, height)) - { - result.ResultSub(CResult::TEST_FAIL); - return result.Result(); - } - - if (!YUVCompare(surfaceFormat, bufferOut, bufferIn, width, height)) - { - log_error("Media surface is different than expected\n"); - result.ResultSub(CResult::TEST_FAIL); - } - } - - if (deviceWrapper->Status() != DEVICE_PASS) - { - std::string adapterName; - AdapterToString(adapterType, adapterName); - - if (deviceWrapper->Status() == DEVICE_FAIL) - { - log_error("%s init failed\n", adapterName.c_str()); - result.ResultSub(CResult::TEST_FAIL); - } - else - { - log_error("%s init incomplete due to unsupported device\n", adapterName.c_str()); - result.ResultSub(CResult::TEST_NOTSUPPORTED); - } - } - - return result.Result(); -} - -int test_interop_user_sync(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) -{ - const unsigned int WIDTH = 256; - const unsigned int HEIGHT = 256; - - std::vector adapters; -#if defined(_WIN32) - adapters.push_back(CL_ADAPTER_D3D9_KHR); - adapters.push_back(CL_ADAPTER_D3D9EX_KHR); - adapters.push_back(CL_ADAPTER_DXVA_KHR); -#else - return TEST_NOT_IMPLEMENTED; -#endif - - std::vector contextFuncs; - contextFuncs.push_back(CONTEXT_CREATE_DEFAULT); - contextFuncs.push_back(CONTEXT_CREATE_FROM_TYPE); - - std::vector formats; - formats.push_back(SURFACE_FORMAT_NV12); - formats.push_back(SURFACE_FORMAT_YV12); - - std::vector sharedHandleTypes; - sharedHandleTypes.push_back(SHARED_HANDLE_DISABLED); - sharedHandleTypes.push_back(SHARED_HANDLE_ENABLED); - - std::vector sync; - sync.push_back(CL_FALSE); - sync.push_back(CL_TRUE); - - CResult result; - for (size_t adapterIdx = 0; adapterIdx < adapters.size(); ++adapterIdx) - { - //iteration through all create context functions - for (size_t contextFuncIdx = 0; contextFuncIdx < contextFuncs.size(); ++contextFuncIdx) - { - //iteration through YUV formats - for (size_t formatIdx = 0; formatIdx < formats.size(); ++formatIdx) - { - //shared handle enabled or disabled - for (size_t sharedHandleIdx = 0; sharedHandleIdx < sharedHandleTypes.size(); ++sharedHandleIdx) - { - //user sync interop disabled or enabled - for (size_t syncIdx = 0; syncIdx < sync.size(); ++syncIdx) - { - if (adapters[adapterIdx] == CL_ADAPTER_D3D9_KHR && sharedHandleTypes[sharedHandleIdx] == SHARED_HANDLE_ENABLED) - continue; - - if(interop_user_sync(deviceID, context, queue, num_elements, WIDTH, HEIGHT, - contextFuncs[contextFuncIdx], adapters[adapterIdx], formats[formatIdx], - sharedHandleTypes[sharedHandleIdx], sync[syncIdx]) != 0) - { - std::string syncStr = (sync[syncIdx] == CL_TRUE) ? "user sync enabled": "user sync disabled"; - std::string sharedHandle = (sharedHandleTypes[sharedHandleIdx] == SHARED_HANDLE_ENABLED)? "shared handle": "no shared handle"; - std::string adapterStr; - std::string formatStr; - SurfaceFormatToString(formats[formatIdx], formatStr); - AdapterToString(adapters[adapterIdx], adapterStr); - - log_error("\nTest case - clCreateContext (%s, %s, %s, %s) failed\n\n", adapterStr.c_str(), formatStr.c_str(), sharedHandle.c_str(), syncStr.c_str()); - result.ResultSub(CResult::TEST_FAIL); - } - } - } - } - } - } - - return result.Result(); -} diff --git a/test_extensions/media_sharing/test_memory_access.cpp b/test_extensions/media_sharing/test_memory_access.cpp deleted file mode 100644 index 5aabaf6f..00000000 --- a/test_extensions/media_sharing/test_memory_access.cpp +++ /dev/null @@ -1,468 +0,0 @@ -// -// 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 "utils.h" - -int memory_access(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements, - unsigned int width, unsigned int height, cl_dx9_media_adapter_type_khr adapterType, - TSurfaceFormat surfaceFormat, TSharedHandleType sharedHandle) -{ - CResult result; - - std::auto_ptr deviceWrapper; - //creates device - if (!DeviceCreate(adapterType, deviceWrapper)) - { - result.ResultSub(CResult::TEST_ERROR); - return result.Result(); - } - - //generate input and expected data - size_t frameSize = width * height * 3 / 2; - std::vector bufferRef0(frameSize, 0); - std::vector bufferRef1(frameSize, 0); - std::vector bufferRef2(frameSize, 0); - if (!YUVGenerate(surfaceFormat, bufferRef0, width, height, 0, 90) || - !YUVGenerate(surfaceFormat, bufferRef1, width, height, 91, 180) || - !YUVGenerate(surfaceFormat, bufferRef2, width, height, 181, 255)) - { - result.ResultSub(CResult::TEST_ERROR); - return result.Result(); - } - - //iterates through all devices - while (deviceWrapper->AdapterNext()) - { - cl_int error; - //check if the test can be run on the adapter - if (CL_SUCCESS != (error = deviceExistForCLTest(gPlatformIDdetected, adapterType, deviceWrapper->Device(), result, sharedHandle))) - { - return result.Result(); - } - - if (surfaceFormat != SURFACE_FORMAT_NV12 && !SurfaceFormatCheck(adapterType, *deviceWrapper, surfaceFormat)) - { - std::string sharedHandleStr = (sharedHandle == SHARED_HANDLE_ENABLED)? "yes": "no"; - std::string formatStr; - std::string adapterStr; - SurfaceFormatToString(surfaceFormat, formatStr); - AdapterToString(adapterType, adapterStr); - log_info("Skipping test case, image format is not supported by a device (adapter type: %s, format: %s, shared handle: %s)\n", - adapterStr.c_str(), formatStr.c_str(), sharedHandleStr.c_str()); - return result.Result(); - } - - void *objectSharedHandle = 0; - std::auto_ptr surface; - - //creates surface - if (!MediaSurfaceCreate(adapterType, width, height, surfaceFormat, *deviceWrapper, surface, - (sharedHandle == SHARED_HANDLE_ENABLED) ? true: false, &objectSharedHandle)) - { - log_error("Media surface creation failed for %i adapter\n", deviceWrapper->AdapterIdx()); - result.ResultSub(CResult::TEST_ERROR); - return result.Result(); - } - - if (!YUVSurfaceSet(surfaceFormat, surface, bufferRef0, width, height)) - { - result.ResultSub(CResult::TEST_ERROR); - return result.Result(); - } - - cl_context_properties contextProperties[] = { - CL_CONTEXT_PLATFORM, (cl_context_properties)gPlatformIDdetected, - AdapterTypeToContextInfo(adapterType), (cl_context_properties)deviceWrapper->Device(), - 0, - }; - - clContextWrapper ctx = clCreateContext(&contextProperties[0], 1, &gDeviceIDdetected, NULL, NULL, &error); - if (error != CL_SUCCESS) - { - log_error("clCreateContext failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - return result.Result(); - } - - clCommandQueueWrapper cmdQueue = clCreateCommandQueueWithProperties(ctx, gDeviceIDdetected, 0, &error ); - if (error != CL_SUCCESS) - { - log_error("Unable to create command queue: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - return result.Result(); - } - - { //memory access write -#if defined(_WIN32) - cl_dx9_surface_info_khr surfaceInfo; - surfaceInfo.resource = *(static_cast(surface.get())); - surfaceInfo.shared_handle = objectSharedHandle; -#else - void *surfaceInfo = 0; - return TEST_NOT_IMPLEMENTED; -#endif - - std::vector memObjList; - unsigned int planesNum = PlanesNum(surfaceFormat); - std::vector planesList(planesNum); - for (unsigned int planeIdx = 0; planeIdx < planesNum; ++planeIdx) - { - planesList[planeIdx] = clCreateFromDX9MediaSurfaceKHR(ctx, CL_MEM_WRITE_ONLY, adapterType, &surfaceInfo, planeIdx, &error); - if (error != CL_SUCCESS) - { - log_error("clCreateFromDX9MediaSurfaceKHR failed for WRITE_ONLY plane %i: %s\n", planeIdx, IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - return result.Result(); - } - memObjList.push_back(planesList[planeIdx]); - } - - error = clEnqueueAcquireDX9MediaSurfacesKHR(cmdQueue, static_cast(memObjList.size()), &memObjList[0], 0, 0, 0); - if (error != CL_SUCCESS) - { - log_error("clEnqueueAcquireDX9MediaSurfacesKHR failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - return result.Result(); - } - - size_t offset = 0; - size_t origin[3] = {0,0,0}; - for (size_t i = 0; i < memObjList.size(); ++i) - { - size_t planeWidth = (i == 0) ? width: width / 2; - size_t planeHeight = (i == 0) ? height: height / 2; - size_t regionPlane[3] = {planeWidth, planeHeight, 1}; - - error = clEnqueueWriteImage(cmdQueue, memObjList[i], CL_TRUE, origin, regionPlane, - 0, 0, &bufferRef1[offset], 0, 0, 0); - if (error != CL_SUCCESS) - { - log_error("clEnqueueWriteImage failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - } - - offset += planeWidth * planeHeight; - } - - error = clEnqueueReleaseDX9MediaSurfacesKHR(cmdQueue, static_cast(memObjList.size()), &memObjList[0], 0, 0, 0); - if (error != CL_SUCCESS) - { - log_error("clEnqueueReleaseDX9MediaSurfacesKHR failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - } - } - - std::vector bufferOut0(frameSize, 0); - if (!YUVSurfaceGet(surfaceFormat, surface, bufferOut0, width, height)) - { - result.ResultSub(CResult::TEST_FAIL); - return result.Result(); - } - - if (!YUVCompare(surfaceFormat, bufferOut0, bufferRef1, width, height)) - { - log_error("Media surface is different than expected\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - { //memory access read -#if defined(_WIN32) - cl_dx9_surface_info_khr surfaceInfo; - surfaceInfo.resource = *(static_cast(surface.get())); - surfaceInfo.shared_handle = objectSharedHandle; -#else - void *surfaceInfo = 0; - return TEST_NOT_IMPLEMENTED; -#endif - - std::vector memObjList; - unsigned int planesNum = PlanesNum(surfaceFormat); - std::vector planesList(planesNum); - for (unsigned int planeIdx = 0; planeIdx < planesNum; ++planeIdx) - { - planesList[planeIdx] = clCreateFromDX9MediaSurfaceKHR(ctx, CL_MEM_READ_ONLY, adapterType, &surfaceInfo, planeIdx, &error); - if (error != CL_SUCCESS) - { - log_error("clCreateFromDX9MediaSurfaceKHR failed for READ_ONLY plane %i: %s\n", planeIdx, IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - return result.Result(); - } - memObjList.push_back(planesList[planeIdx]); - } - - error = clEnqueueAcquireDX9MediaSurfacesKHR(cmdQueue, static_cast(memObjList.size()), &memObjList[0], 0, 0, 0); - if (error != CL_SUCCESS) - { - log_error("clEnqueueAcquireDX9MediaSurfacesKHR failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - return result.Result(); - } - - std::vector out( frameSize, 0 ); - size_t offset = 0; - size_t origin[3] = {0,0,0}; - - for (size_t i = 0; i < memObjList.size(); ++i) - { - size_t planeWidth = (i == 0) ? width: width / 2; - size_t planeHeight = (i == 0) ? height: height / 2; - size_t regionPlane[3] = {planeWidth, planeHeight, 1}; - - error = clEnqueueReadImage(cmdQueue, memObjList[i], CL_TRUE, origin, regionPlane, 0, 0, - &out[offset], 0, 0, 0); - if (error != CL_SUCCESS) - { - log_error("clEnqueueReadImage failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - } - - offset += planeWidth * planeHeight; - } - - if (!YUVCompare(surfaceFormat, out, bufferRef1, width, height)) - { - log_error("OCL image (READ_ONLY) is different then expected\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - error = clEnqueueReleaseDX9MediaSurfacesKHR(cmdQueue, static_cast(memObjList.size()), &memObjList[0], 0, 0, 0); - if (error != CL_SUCCESS) - { - log_error("clEnqueueReleaseDX9MediaSurfacesKHR failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - } - } - - std::vector bufferOut1(frameSize, 0); - if (!YUVSurfaceGet(surfaceFormat, surface, bufferOut1, width, height)) - { - result.ResultSub(CResult::TEST_FAIL); - return result.Result(); - } - - if (!YUVCompare(surfaceFormat, bufferOut1, bufferRef1, width, height)) - { - log_error("Media surface is different than expected\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - { //memory access read write -#if defined(_WIN32) - cl_dx9_surface_info_khr surfaceInfo; - surfaceInfo.resource = *(static_cast(surface.get())); - surfaceInfo.shared_handle = objectSharedHandle; -#else - void *surfaceInfo = 0; - return TEST_NOT_IMPLEMENTED; -#endif - - std::vector memObjList; - unsigned int planesNum = PlanesNum(surfaceFormat); - std::vector planesList(planesNum); - for (unsigned int planeIdx = 0; planeIdx < planesNum; ++planeIdx) - { - planesList[planeIdx] = clCreateFromDX9MediaSurfaceKHR(ctx, CL_MEM_READ_WRITE, adapterType, &surfaceInfo, planeIdx, &error); - if (error != CL_SUCCESS) - { - log_error("clCreateFromDX9MediaSurfaceKHR failed for READ_WRITE plane %i: %s\n", planeIdx, IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - return result.Result(); - } - memObjList.push_back(planesList[planeIdx]); - } - - error = clEnqueueAcquireDX9MediaSurfacesKHR(cmdQueue, static_cast(memObjList.size()), &memObjList[0], 0, 0, 0); - if (error != CL_SUCCESS) - { - log_error("clEnqueueAcquireDX9MediaSurfacesKHR failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - return result.Result(); - } - - { //read - std::vector out( frameSize, 0 ); - size_t offset = 0; - size_t origin[3] = {0,0,0}; - - for (size_t i = 0; i < memObjList.size(); ++i) - { - size_t planeWidth = (i == 0) ? width: width / 2; - size_t planeHeight = (i == 0) ? height: height / 2; - size_t regionPlane[3] = {planeWidth, planeHeight, 1}; - - error = clEnqueueReadImage(cmdQueue, memObjList[i], CL_TRUE, origin, regionPlane, 0, 0, - &out[offset], 0, 0, 0); - if (error != CL_SUCCESS) - { - log_error("clEnqueueReadImage failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - } - - offset += planeWidth * planeHeight; - } - - if (!YUVCompare(surfaceFormat, out, bufferRef1, width, height)) - { - log_error("OCL image (READ_WRITE) is different then expected\n"); - result.ResultSub(CResult::TEST_FAIL); - } - } - - { //write - size_t offset = 0; - size_t origin[3] = {0,0,0}; - for (size_t i = 0; i < memObjList.size(); ++i) - { - size_t planeWidth = (i == 0) ? width: width / 2; - size_t planeHeight = (i == 0) ? height: height / 2; - size_t regionPlane[3] = {planeWidth, planeHeight, 1}; - - error = clEnqueueWriteImage(cmdQueue, memObjList[i], CL_TRUE, origin, regionPlane, - 0, 0, &bufferRef2[offset], 0, 0, 0); - if (error != CL_SUCCESS) - { - log_error("clEnqueueWriteImage failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - } - - offset += planeWidth * planeHeight; - } - } - - error = clEnqueueReleaseDX9MediaSurfacesKHR(cmdQueue, static_cast(memObjList.size()), &memObjList[0], 0, 0, 0); - if (error != CL_SUCCESS) - { - log_error("clEnqueueReleaseDX9MediaSurfacesKHR failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - } - } - - std::vector bufferOut2(frameSize, 0); - if (!YUVSurfaceGet(surfaceFormat, surface, bufferOut2, width, height)) - { - result.ResultSub(CResult::TEST_FAIL); - return result.Result(); - } - - if (!YUVCompare(surfaceFormat, bufferOut2, bufferRef2, width, height)) - { - log_error("Media surface is different than expected\n"); - result.ResultSub(CResult::TEST_FAIL); - } - } - - if (deviceWrapper->Status() != DEVICE_PASS) - { - std::string adapterName; - AdapterToString(adapterType, adapterName); - if (deviceWrapper->Status() == DEVICE_FAIL) - { - log_error("%s init failed\n", adapterName.c_str()); - result.ResultSub(CResult::TEST_FAIL); - } - else - { - log_error("%s init incomplete due to unsupported device\n", adapterName.c_str()); - result.ResultSub(CResult::TEST_NOTSUPPORTED); - } - } - - return result.Result(); -} - -int test_memory_access(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) -{ - CResult result; - -#if defined(_WIN32) - //D3D9 - if(memory_access(deviceID, context, queue, num_elements, 256, 256, CL_ADAPTER_D3D9_KHR, - SURFACE_FORMAT_NV12, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (D3D9, NV12, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(memory_access(deviceID, context, queue, num_elements, 512, 256, CL_ADAPTER_D3D9_KHR, - SURFACE_FORMAT_YV12, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (D3D9, YV12, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - //D3D9EX - if(memory_access(deviceID, context, queue, num_elements, 256, 512, CL_ADAPTER_D3D9EX_KHR, - SURFACE_FORMAT_NV12, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (D3D9EX, NV12, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(memory_access(deviceID, context, queue, num_elements, 512, 256, CL_ADAPTER_D3D9EX_KHR, - SURFACE_FORMAT_NV12, SHARED_HANDLE_ENABLED) != 0) - { - log_error("\nTest case (D3D9EX, NV12, shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(memory_access(deviceID, context, queue, num_elements, 256, 256, CL_ADAPTER_D3D9EX_KHR, - SURFACE_FORMAT_YV12, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (D3D9EX, YV12, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(memory_access(deviceID, context, queue, num_elements, 128, 128, CL_ADAPTER_D3D9EX_KHR, - SURFACE_FORMAT_YV12, SHARED_HANDLE_ENABLED) != 0) - { - log_error("\nTest case (D3D9EX, YV12, shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - //DXVA - if(memory_access(deviceID, context, queue, num_elements, 128, 128, CL_ADAPTER_DXVA_KHR, - SURFACE_FORMAT_NV12, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (DXVA, NV12, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(memory_access(deviceID, context, queue, num_elements, 64, 64, CL_ADAPTER_DXVA_KHR, - SURFACE_FORMAT_NV12, SHARED_HANDLE_ENABLED) != 0) - { - log_error("\nTest case (DXVA, NV12, shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(memory_access(deviceID, context, queue, num_elements, 512, 512, CL_ADAPTER_DXVA_KHR, - SURFACE_FORMAT_YV12, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (DXVA, YV12, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(memory_access(deviceID, context, queue, num_elements, 1024, 1024, CL_ADAPTER_DXVA_KHR, - SURFACE_FORMAT_YV12, SHARED_HANDLE_ENABLED) != 0) - { - log_error("\nTest case (DXVA, YV12, shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - -#else - return TEST_NOT_IMPLEMENTED; -#endif - - return result.Result(); -} diff --git a/test_extensions/media_sharing/test_other_data_types.cpp b/test_extensions/media_sharing/test_other_data_types.cpp deleted file mode 100644 index 8a73866e..00000000 --- a/test_extensions/media_sharing/test_other_data_types.cpp +++ /dev/null @@ -1,1023 +0,0 @@ -// -// 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 -#include - -#include "harness/errorHelpers.h" -#include "harness/imageHelpers.h" -#include "harness/kernelHelpers.h" - -#include "utils.h" - -template -int other_data_types(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements, - unsigned int iterationNum, unsigned int width, unsigned int height, cl_dx9_media_adapter_type_khr adapterType, - TSurfaceFormat surfaceFormat, TSharedHandleType sharedHandle) -{ - const unsigned int FRAME_NUM = 2; - const float MAX_VALUE = 0.6f; - const std::string PROGRAM_STR = - "__kernel void TestFunction( read_only image2d_t imageIn, write_only image2d_t imageOut, " - NL " sampler_t sampler, __global int *imageRes)" - NL "{" - NL " int w = get_global_id(0);" - NL " int h = get_global_id(1);" - NL " int width = get_image_width(imageIn);" - NL " int height = get_image_height(imageOut);" - NL " float4 color0 = read_imagef(imageIn, sampler, (int2)(w,h)) - 0.2f;" - NL " float4 color1 = read_imagef(imageIn, sampler, (float2)(w,h)) - 0.2f;" - NL " color0 = (color0 == color1) ? color0: (float4)(0.5, 0.5, 0.5, 0.5);" - NL " write_imagef(imageOut, (int2)(w,h), color0);" - NL " if(w == 0 && h == 0)" - NL " {" - NL " imageRes[0] = width;" - NL " imageRes[1] = height;" - NL " }" - NL "}"; - - CResult result; - - cl_image_format format; - if(!SurfaceFormatToOCL(surfaceFormat, format)) - { - result.ResultSub(CResult::TEST_ERROR); - return result.Result(); - } - - std::auto_ptr deviceWrapper; - if (!DeviceCreate(adapterType, deviceWrapper)) - { - result.ResultSub(CResult::TEST_ERROR); - return result.Result(); - } - - while (deviceWrapper->AdapterNext()) - { - cl_int error; - //check if the test can be run on the adapter - if (CL_SUCCESS != (error = deviceExistForCLTest(gPlatformIDdetected, adapterType, deviceWrapper->Device(), result, sharedHandle))) - { - return result.Result(); - } - - cl_context_properties contextProperties[] = { - CL_CONTEXT_PLATFORM, (cl_context_properties)gPlatformIDdetected, - AdapterTypeToContextInfo(adapterType), (cl_context_properties)deviceWrapper->Device(), - 0, - }; - - clContextWrapper ctx = clCreateContext(&contextProperties[0], 1, &gDeviceIDdetected, NULL, NULL, &error); - if (error != CL_SUCCESS) - { - log_error("clCreateContext failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - return result.Result(); - } - - clCommandQueueWrapper cmdQueue = clCreateCommandQueueWithProperties(ctx, gDeviceIDdetected, 0, &error ); - if (error != CL_SUCCESS) - { - log_error("Unable to create command queue: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - return result.Result(); - } - - if (!SurfaceFormatCheck(adapterType, *deviceWrapper, surfaceFormat)) - { - std::string sharedHandleStr = (sharedHandle == SHARED_HANDLE_ENABLED)? "yes": "no"; - std::string formatStr; - std::string adapterStr; - SurfaceFormatToString(surfaceFormat, formatStr); - AdapterToString(adapterType, adapterStr); - log_info("Skipping test case, image format is not supported by a device (adapter type: %s, format: %s, shared handle: %s)\n", - adapterStr.c_str(), formatStr.c_str(), sharedHandleStr.c_str()); - return result.Result(); - } - - if(!ImageFormatCheck(ctx, CL_MEM_OBJECT_IMAGE2D, format)) - { - std::string sharedHandleStr = (sharedHandle == SHARED_HANDLE_ENABLED)? "yes": "no"; - std::string formatStr; - std::string adapterStr; - SurfaceFormatToString(surfaceFormat, formatStr); - AdapterToString(adapterType, adapterStr); - log_info("Skipping test case, image format is not supported by OCL (adapter type: %s, format: %s, shared handle: %s)\n", - adapterStr.c_str(), formatStr.c_str(), sharedHandleStr.c_str()); - return result.Result(); - } - - if (format.image_channel_data_type == CL_HALF_FLOAT) - { - if (DetectFloatToHalfRoundingMode(cmdQueue)) - { - log_error("Unable to detect rounding mode\n"); - result.ResultSub(CResult::TEST_FAIL); - return result.Result(); - } - } - - std::vector > bufferIn(FRAME_NUM); - std::vector > bufferExp(FRAME_NUM); - float step = MAX_VALUE / static_cast(FRAME_NUM); - unsigned int planeNum = ChannelNum(surfaceFormat); - for (size_t i = 0; i < FRAME_NUM; ++i) - { - DataGenerate(surfaceFormat, format.image_channel_data_type, bufferIn[i], width, height, planeNum, step * i, step * (i + 1)); - DataGenerate(surfaceFormat, format.image_channel_data_type, bufferExp[i], width, height, planeNum, step * i, step * (i + 1), 0.2f); - } - - void *objectSrcHandle = 0; - std::auto_ptr surfaceSrc; - if (!MediaSurfaceCreate(adapterType, width, height, surfaceFormat, *deviceWrapper, surfaceSrc, - (sharedHandle == SHARED_HANDLE_ENABLED) ? true: false, &objectSrcHandle)) - { - log_error("Media surface creation failed for %i adapter\n", deviceWrapper->AdapterIdx()); - result.ResultSub(CResult::TEST_ERROR); - return result.Result(); - } - - void *objectDstHandle = 0; - std::auto_ptr surfaceDst; - if (!MediaSurfaceCreate(adapterType, width, height, surfaceFormat, *deviceWrapper, surfaceDst, - (sharedHandle == SHARED_HANDLE_ENABLED) ? true: false, &objectDstHandle)) - { - log_error("Media surface creation failed for %i adapter\n", deviceWrapper->AdapterIdx()); - result.ResultSub(CResult::TEST_ERROR); - return result.Result(); - } - -#if defined(_WIN32) - cl_dx9_surface_info_khr surfaceSrcInfo; - CD3D9SurfaceWrapper *dx9SurfaceSrc = (static_cast(surfaceSrc.get())); - surfaceSrcInfo.resource = *dx9SurfaceSrc; - surfaceSrcInfo.shared_handle = objectSrcHandle; - - cl_dx9_surface_info_khr surfaceDstInfo; - CD3D9SurfaceWrapper *dx9SurfaceDst = (static_cast(surfaceDst.get())); - surfaceDstInfo.resource = *dx9SurfaceDst; - surfaceDstInfo.shared_handle = objectDstHandle; -#else - void *surfaceSrcInfo = 0; - void *surfaceDstInfo = 0; - return TEST_NOT_IMPLEMENTED; -#endif - - //create OCL shared object - clMemWrapper objectSrcShared = clCreateFromDX9MediaSurfaceKHR(ctx, CL_MEM_READ_WRITE, adapterType, &surfaceSrcInfo, 0, &error); - if (error != CL_SUCCESS) - { - log_error("clCreateFromDX9MediaSurfaceKHR failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - return result.Result(); - } - - clMemWrapper objectDstShared = clCreateFromDX9MediaSurfaceKHR(ctx, CL_MEM_READ_WRITE, adapterType, &surfaceDstInfo, 0, &error); - if (error != CL_SUCCESS) - { - log_error("clCreateFromDX9MediaSurfaceKHR failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - return result.Result(); - } - - std::vector memObjList; - memObjList.push_back(objectSrcShared); - memObjList.push_back(objectDstShared); - - if (!GetMemObjInfo(objectSrcShared, adapterType, surfaceSrc, objectSrcHandle)) - { - log_error("Invalid memory object info\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if (!GetImageInfo(objectSrcShared, format, sizeof(T) * planeNum, - width * sizeof(T) * planeNum, 0, width, height, 0, 0)) - { - log_error("clGetImageInfo failed\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - for (size_t frameIdx = 0; frameIdx < iterationNum; ++frameIdx) - { - //surface set -#if defined(_WIN32) - D3DLOCKED_RECT rect; - if (FAILED((*dx9SurfaceSrc)->LockRect(&rect, NULL, 0))) - { - log_error("Surface lock failed\n"); - result.ResultSub(CResult::TEST_ERROR); - return result.Result(); - } - - size_t pitch = rect.Pitch / sizeof(T); - size_t lineSize = width * planeNum * sizeof(T); - T *ptr = static_cast(rect.pBits); - - for (size_t y = 0; y < height; ++y) - memcpy(ptr + y * pitch, &bufferIn[frameIdx % FRAME_NUM][y * width * planeNum], lineSize); - - (*dx9SurfaceSrc)->UnlockRect(); -#else - void *surfaceInfo = 0; - return TEST_NOT_IMPLEMENTED; -#endif - - error = clEnqueueAcquireDX9MediaSurfacesKHR(cmdQueue, static_cast(memObjList.size()), &memObjList[0], 0, 0, 0); - if (error != CL_SUCCESS) - { - log_error("clEnqueueAcquireMediaSurfaceKHR failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - return result.Result(); - } - - size_t origin[3] = {0,0,0}; - size_t region[3] = {width, height, 1}; - - { //read operation - std::vector out( planeNum * width * height, 0 ); - error = clEnqueueReadImage(cmdQueue, objectSrcShared, CL_TRUE, origin, region, 0, 0, &out[0], 0, 0, 0); - if (error != CL_SUCCESS) - { - log_error("clEnqueueReadImage failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - } - - if (!DataCompare(surfaceFormat, format.image_channel_data_type, out, bufferIn[frameIdx % FRAME_NUM], width, height, planeNum)) - { - log_error("Frame idx: %i, OCL object is different then expected\n", frameIdx); - result.ResultSub(CResult::TEST_FAIL); - } - } - - { //write operation - error = clEnqueueWriteImage(cmdQueue, objectSrcShared, CL_TRUE, origin, region, - 0, 0, &bufferExp[frameIdx % FRAME_NUM][0], 0, 0, 0); - if (error != CL_SUCCESS) - { - log_error("clEnqueueWriteImage failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - } - } - - { //kernel operations - clSamplerWrapper sampler = clCreateSampler( ctx, CL_FALSE, CL_ADDRESS_NONE, CL_FILTER_NEAREST, &error ); - if(error != CL_SUCCESS) - { - log_error("Unable to create sampler\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - size_t threads[ 2 ] = { width, height }; - clProgramWrapper program; - clKernelWrapper kernel; - const char *progPtr = PROGRAM_STR.c_str(); - if(create_single_kernel_helper(ctx, &program, &kernel, 1, (const char **)&progPtr, "TestFunction")) - result.ResultSub(CResult::TEST_FAIL); - - error = clSetKernelArg( kernel, 0, sizeof( objectSrcShared ), &(objectSrcShared) ); - if (error != CL_SUCCESS) - { - log_error("Unable to set kernel arguments" ); - result.ResultSub(CResult::TEST_FAIL); - } - - error = clSetKernelArg( kernel, 1, sizeof( objectDstShared ), &(objectDstShared) ); - if (error != CL_SUCCESS) - { - log_error("Unable to set kernel arguments" ); - result.ResultSub(CResult::TEST_FAIL); - } - - error = clSetKernelArg( kernel, 2, sizeof( sampler ), &sampler ); - if (error != CL_SUCCESS) - { - log_error("Unable to set kernel arguments" ); - result.ResultSub(CResult::TEST_FAIL); - } - - size_t bufferSize = sizeof(cl_int) * 2; - clMemWrapper imageRes = clCreateBuffer( ctx, CL_MEM_READ_WRITE, bufferSize, NULL, &error); - if (error != CL_SUCCESS) - { - log_error("clCreateBuffer failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - } - - error = clSetKernelArg( kernel, 3, sizeof( imageRes ), &imageRes ); - - size_t localThreads[ 2 ]; - error = get_max_common_2D_work_group_size( ctx, kernel, threads, localThreads ); - if (error != CL_SUCCESS) - { - log_error("Unable to get work group size to use" ); - result.ResultSub(CResult::TEST_FAIL); - } - - error = clEnqueueNDRangeKernel( cmdQueue, kernel, 2, NULL, threads, localThreads, 0, NULL, NULL ); - if (error != CL_SUCCESS) - { - log_error("Unable to execute test kernel" ); - result.ResultSub(CResult::TEST_FAIL); - } - - std::vector imageResOut(2, 0); - error = clEnqueueReadBuffer( cmdQueue, imageRes, CL_TRUE, 0, bufferSize, &imageResOut[0], 0, NULL, NULL ); - if (error != CL_SUCCESS) - { - log_error("Unable to read buffer"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(imageResOut[0] != width) - { - log_error("Invalid width value, test = %i, expected = %i\n", imageResOut[0], width); - result.ResultSub(CResult::TEST_FAIL); - } - - if(imageResOut[1] != height) - { - log_error("Invalid height value, test = %i, expected = %i\n", imageResOut[1], height); - result.ResultSub(CResult::TEST_FAIL); - } - } - - { //map operation - size_t mapOrigin[3] = {0,0,0}; - size_t mapRegion[3] = {width, height, 1}; - - std::vector out( width * height * planeNum, 0 ); - size_t rowPitch = 0; - size_t slicePitch = 0; - void *mapPtr = clEnqueueMapImage(cmdQueue, objectDstShared, CL_TRUE, CL_MAP_READ | CL_MAP_WRITE, mapOrigin, mapRegion, - &rowPitch, &slicePitch, 0, 0, 0, &error); - if (error != CL_SUCCESS) - { - log_error("clEnqueueMapImage failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - } - - for (size_t y = 0; y < height; ++y) - memcpy(&out[y * width * planeNum], static_cast(mapPtr) + y * rowPitch / sizeof(T), - width * planeNum * sizeof(T)); - - if (!DataCompare(surfaceFormat, format.image_channel_data_type, out, bufferIn[frameIdx % FRAME_NUM], width, height, planeNum)) - { - log_error("Frame idx: %i, Mapped OCL object is different then expected\n", frameIdx); - result.ResultSub(CResult::TEST_FAIL); - } - - for (size_t y = 0; y < height; ++y) - memcpy(static_cast(mapPtr) + y * rowPitch / sizeof(T), &bufferExp[frameIdx % FRAME_NUM][y * width * planeNum], - width * planeNum * sizeof(T)); - - error = clEnqueueUnmapMemObject(cmdQueue, objectDstShared, mapPtr, 0, 0, 0); - if (error != CL_SUCCESS) - { - log_error("clEnqueueUnmapMemObject failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - } - } - - error = clEnqueueReleaseDX9MediaSurfacesKHR(cmdQueue, static_cast(memObjList.size()), &memObjList[0], 0, 0, 0); - if (error != CL_SUCCESS) - { - log_error("clEnqueueReleaseMediaSurfaceKHR failed: %s\n", IGetErrorString(error)); - result.ResultSub(CResult::TEST_FAIL); - } - - std::vector out(width * height * planeNum, 0); - //surface get -#if defined(_WIN32) - if (FAILED((*dx9SurfaceDst)->LockRect(&rect, NULL, 0))) - { - log_error("Surface lock failed\n"); - result.ResultSub(CResult::TEST_ERROR); - return result.Result(); - } - - pitch = rect.Pitch / sizeof(T); - lineSize = width * planeNum * sizeof(T); - ptr = static_cast(rect.pBits); - for (size_t y = 0; y < height; ++y) - memcpy(&out[y * width * planeNum], ptr + y * pitch, lineSize); - - (*dx9SurfaceDst)->UnlockRect(); -#else - return TEST_NOT_IMPLEMENTED; -#endif - - if (!DataCompare(surfaceFormat, format.image_channel_data_type, out, bufferExp[frameIdx % FRAME_NUM], width, height, planeNum)) - { - log_error("Frame idx: %i, media object is different then expected\n", frameIdx); - result.ResultSub(CResult::TEST_FAIL); - } - } - } - - if (deviceWrapper->Status() != DEVICE_PASS) - { - std::string adapterName; - AdapterToString(adapterType, adapterName); - if (deviceWrapper->Status() == DEVICE_FAIL) - { - log_error("%s init failed\n", adapterName.c_str()); - result.ResultSub(CResult::TEST_FAIL); - } - else - { - log_error("%s init incomplete due to unsupported device\n", adapterName.c_str()); - result.ResultSub(CResult::TEST_NOTSUPPORTED); - } - } - - return result.Result(); -} - -int test_other_data_types(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) -{ - CResult result; - -#if defined(_WIN32) - //D3D9 - if(other_data_types(deviceID, context, queue, num_elements, 10, 64, 256, CL_ADAPTER_D3D9_KHR, - SURFACE_FORMAT_R32F, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (D3D9, R32F, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 256, 128, CL_ADAPTER_D3D9_KHR, - SURFACE_FORMAT_R16F, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (D3D9, R16F, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 512, 256, CL_ADAPTER_D3D9_KHR, - SURFACE_FORMAT_L16, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (D3D9, L16, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 256, 512, CL_ADAPTER_D3D9_KHR, - SURFACE_FORMAT_A8, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (D3D9, A8, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 1024, 32, CL_ADAPTER_D3D9_KHR, - SURFACE_FORMAT_L8, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (D3D9, L8, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 32, 1024, CL_ADAPTER_D3D9_KHR, - SURFACE_FORMAT_G32R32F, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (D3D9, G32R32F, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 64, 64, CL_ADAPTER_D3D9_KHR, - SURFACE_FORMAT_G16R16F, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (D3D9, G16R16F, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 256, 256, CL_ADAPTER_D3D9_KHR, - SURFACE_FORMAT_G16R16, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (D3D9, G16R16, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 512, 128, CL_ADAPTER_D3D9_KHR, - SURFACE_FORMAT_A8L8, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (D3D9, A8L8, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 128, 512, CL_ADAPTER_D3D9_KHR, - SURFACE_FORMAT_A32B32G32R32F, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (D3D9, A32B32G32R32F, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 128, 128, CL_ADAPTER_D3D9_KHR, - SURFACE_FORMAT_A16B16G16R16F, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (D3D9, A16B16G16R16F, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 64, 128, CL_ADAPTER_D3D9_KHR, - SURFACE_FORMAT_A16B16G16R16, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (D3D9, A16B16G16R16, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 128, 64, CL_ADAPTER_D3D9_KHR, - SURFACE_FORMAT_A8B8G8R8, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (D3D9, A8B8G8R8, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 16, 512, CL_ADAPTER_D3D9_KHR, - SURFACE_FORMAT_X8B8G8R8, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (D3D9, X8B8G8R8, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 512, 16, CL_ADAPTER_D3D9_KHR, - SURFACE_FORMAT_A8R8G8B8, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (D3D9, A8R8G8B8, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 256, 256, CL_ADAPTER_D3D9_KHR, - SURFACE_FORMAT_X8R8G8B8, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (D3D9, X8R8G8B8, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - //D3D9EX - - if(other_data_types(deviceID, context, queue, num_elements, 10, 64, 256, CL_ADAPTER_D3D9EX_KHR, - SURFACE_FORMAT_R32F, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (D3D9EX, R32F, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 64, 256, CL_ADAPTER_D3D9EX_KHR, - SURFACE_FORMAT_R32F, SHARED_HANDLE_ENABLED) != 0) - { - log_error("\nTest case (D3D9EX, R32F, shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 256, 128, CL_ADAPTER_D3D9EX_KHR, - SURFACE_FORMAT_R16F, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (D3D9EX, R16F, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 256, 128, CL_ADAPTER_D3D9EX_KHR, - SURFACE_FORMAT_R16F, SHARED_HANDLE_ENABLED) != 0) - { - log_error("\nTest case (D3D9EX, R16F, shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 512, 256, CL_ADAPTER_D3D9EX_KHR, - SURFACE_FORMAT_L16, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (D3D9EX, L16, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 512, 256, CL_ADAPTER_D3D9EX_KHR, - SURFACE_FORMAT_L16, SHARED_HANDLE_ENABLED) != 0) - { - log_error("\nTest case (D3D9EX, L16, shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 256, 512, CL_ADAPTER_D3D9EX_KHR, - SURFACE_FORMAT_A8, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (D3D9EX, A8, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 256, 512, CL_ADAPTER_D3D9EX_KHR, - SURFACE_FORMAT_A8, SHARED_HANDLE_ENABLED) != 0) - { - log_error("\nTest case (D3D9EX, A8, shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 1024, 32, CL_ADAPTER_D3D9EX_KHR, - SURFACE_FORMAT_L8, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (D3D9EX, L8, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 1024, 32, CL_ADAPTER_D3D9EX_KHR, - SURFACE_FORMAT_L8, SHARED_HANDLE_ENABLED) != 0) - { - log_error("\nTest case (D3D9EX, L8, shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 32, 1024, CL_ADAPTER_D3D9EX_KHR, - SURFACE_FORMAT_G32R32F, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (D3D9EX, G32R32F, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 32, 1024, CL_ADAPTER_D3D9EX_KHR, - SURFACE_FORMAT_G32R32F, SHARED_HANDLE_ENABLED) != 0) - { - log_error("\nTest case (D3D9EX, G32R32F, shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 64, 64, CL_ADAPTER_D3D9EX_KHR, - SURFACE_FORMAT_G16R16F, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (D3D9EX, G16R16F, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 64, 64, CL_ADAPTER_D3D9EX_KHR, - SURFACE_FORMAT_G16R16F, SHARED_HANDLE_ENABLED) != 0) - { - log_error("\nTest case (D3D9EX, G16R16F, shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 256, 256, CL_ADAPTER_D3D9EX_KHR, - SURFACE_FORMAT_G16R16, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (D3D9EX, G16R16, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 256, 256, CL_ADAPTER_D3D9EX_KHR, - SURFACE_FORMAT_G16R16, SHARED_HANDLE_ENABLED) != 0) - { - log_error("\nTest case (D3D9EX, G16R16, shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 512, 128, CL_ADAPTER_D3D9EX_KHR, - SURFACE_FORMAT_A8L8, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (D3D9EX, A8L8, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 512, 128, CL_ADAPTER_D3D9EX_KHR, - SURFACE_FORMAT_A8L8, SHARED_HANDLE_ENABLED) != 0) - { - log_error("\nTest case (D3D9EX, A8L8, shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 128, 512, CL_ADAPTER_D3D9EX_KHR, - SURFACE_FORMAT_A32B32G32R32F, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (D3D9EX, A32B32G32R32F, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 128, 512, CL_ADAPTER_D3D9EX_KHR, - SURFACE_FORMAT_A32B32G32R32F, SHARED_HANDLE_ENABLED) != 0) - { - log_error("\nTest case (D3D9EX, A32B32G32R32F, shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 128, 128, CL_ADAPTER_D3D9EX_KHR, - SURFACE_FORMAT_A16B16G16R16F, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (D3D9EX, A16B16G16R16F, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 128, 128, CL_ADAPTER_D3D9EX_KHR, - SURFACE_FORMAT_A16B16G16R16F, SHARED_HANDLE_ENABLED) != 0) - { - log_error("\nTest case (D3D9EX, A16B16G16R16F, shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 64, 128, CL_ADAPTER_D3D9EX_KHR, - SURFACE_FORMAT_A16B16G16R16, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (D3D9EX, A16B16G16R16, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 64, 128, CL_ADAPTER_D3D9EX_KHR, - SURFACE_FORMAT_A16B16G16R16, SHARED_HANDLE_ENABLED) != 0) - { - log_error("\nTest case (D3D9EX, A16B16G16R16, shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 128, 64, CL_ADAPTER_D3D9EX_KHR, - SURFACE_FORMAT_A8B8G8R8, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (D3D9EX, A8B8G8R8, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 128, 64, CL_ADAPTER_D3D9EX_KHR, - SURFACE_FORMAT_A8B8G8R8, SHARED_HANDLE_ENABLED) != 0) - { - log_error("\nTest case (D3D9EX, A8B8G8R8, shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 16, 512, CL_ADAPTER_D3D9EX_KHR, - SURFACE_FORMAT_X8B8G8R8, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (D3D9EX, X8B8G8R8, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 16, 512, CL_ADAPTER_D3D9EX_KHR, - SURFACE_FORMAT_X8B8G8R8, SHARED_HANDLE_ENABLED) != 0) - { - log_error("\nTest case (D3D9EX, X8B8G8R8, shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 512, 16, CL_ADAPTER_D3D9EX_KHR, - SURFACE_FORMAT_A8R8G8B8, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (D3D9EX, A8R8G8B8, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 512, 16, CL_ADAPTER_D3D9EX_KHR, - SURFACE_FORMAT_A8R8G8B8, SHARED_HANDLE_ENABLED) != 0) - { - log_error("\nTest case (D3D9EX, A8R8G8B8, shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 256, 256, CL_ADAPTER_D3D9EX_KHR, - SURFACE_FORMAT_X8R8G8B8, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (D3D9EX, X8R8G8B8, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 256, 256, CL_ADAPTER_D3D9EX_KHR, - SURFACE_FORMAT_X8R8G8B8, SHARED_HANDLE_ENABLED) != 0) - { - log_error("\nTest case (D3D9EX, X8R8G8B8, shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - //DXVA - - if(other_data_types(deviceID, context, queue, num_elements, 10, 64, 256, CL_ADAPTER_DXVA_KHR, - SURFACE_FORMAT_R32F, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (DXVA, R32F, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 64, 256, CL_ADAPTER_DXVA_KHR, - SURFACE_FORMAT_R32F, SHARED_HANDLE_ENABLED) != 0) - { - log_error("\nTest case (DXVA, R32F, shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 256, 128, CL_ADAPTER_DXVA_KHR, - SURFACE_FORMAT_R16F, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (DXVA, R16F, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 256, 128, CL_ADAPTER_DXVA_KHR, - SURFACE_FORMAT_R16F, SHARED_HANDLE_ENABLED) != 0) - { - log_error("\nTest case (DXVA, R16F, shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 512, 256, CL_ADAPTER_DXVA_KHR, - SURFACE_FORMAT_L16, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (DXVA, L16, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 512, 256, CL_ADAPTER_DXVA_KHR, - SURFACE_FORMAT_L16, SHARED_HANDLE_ENABLED) != 0) - { - log_error("\nTest case (DXVA, L16, shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 256, 512, CL_ADAPTER_DXVA_KHR, - SURFACE_FORMAT_A8, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (DXVA, A8, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 256, 512, CL_ADAPTER_DXVA_KHR, - SURFACE_FORMAT_A8, SHARED_HANDLE_ENABLED) != 0) - { - log_error("\nTest case (DXVA, A8, shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 1024, 32, CL_ADAPTER_DXVA_KHR, - SURFACE_FORMAT_L8, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (DXVA, L8, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 1024, 32, CL_ADAPTER_DXVA_KHR, - SURFACE_FORMAT_L8, SHARED_HANDLE_ENABLED) != 0) - { - log_error("\nTest case (DXVA, L8, shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 32, 1024, CL_ADAPTER_DXVA_KHR, - SURFACE_FORMAT_G32R32F, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (DXVA, G32R32F, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 32, 1024, CL_ADAPTER_DXVA_KHR, - SURFACE_FORMAT_G32R32F, SHARED_HANDLE_ENABLED) != 0) - { - log_error("\nTest case (DXVA, G32R32F, shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 64, 64, CL_ADAPTER_DXVA_KHR, - SURFACE_FORMAT_G16R16F, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (DXVA, G16R16F, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 64, 64, CL_ADAPTER_DXVA_KHR, - SURFACE_FORMAT_G16R16F, SHARED_HANDLE_ENABLED) != 0) - { - log_error("\nTest case (DXVA, G16R16F, shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 256, 256, CL_ADAPTER_DXVA_KHR, - SURFACE_FORMAT_G16R16, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (DXVA, G16R16, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 256, 256, CL_ADAPTER_DXVA_KHR, - SURFACE_FORMAT_G16R16, SHARED_HANDLE_ENABLED) != 0) - { - log_error("\nTest case (DXVA, G16R16, shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 512, 128, CL_ADAPTER_DXVA_KHR, - SURFACE_FORMAT_A8L8, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (DXVA, A8L8, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 512, 128, CL_ADAPTER_DXVA_KHR, - SURFACE_FORMAT_A8L8, SHARED_HANDLE_ENABLED) != 0) - { - log_error("\nTest case (DXVA, A8L8, shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 128, 512, CL_ADAPTER_DXVA_KHR, - SURFACE_FORMAT_A32B32G32R32F, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (DXVA, A32B32G32R32F, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 128, 512, CL_ADAPTER_DXVA_KHR, - SURFACE_FORMAT_A32B32G32R32F, SHARED_HANDLE_ENABLED) != 0) - { - log_error("\nTest case (DXVA, A32B32G32R32F, shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 128, 128, CL_ADAPTER_DXVA_KHR, - SURFACE_FORMAT_A16B16G16R16F, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (DXVA, A16B16G16R16F, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 128, 128, CL_ADAPTER_DXVA_KHR, - SURFACE_FORMAT_A16B16G16R16F, SHARED_HANDLE_ENABLED) != 0) - { - log_error("\nTest case (DXVA, A16B16G16R16F, shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 64, 128, CL_ADAPTER_DXVA_KHR, - SURFACE_FORMAT_A16B16G16R16, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (DXVA, A16B16G16R16, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 64, 128, CL_ADAPTER_DXVA_KHR, - SURFACE_FORMAT_A16B16G16R16, SHARED_HANDLE_ENABLED) != 0) - { - log_error("\nTest case (DXVA, A16B16G16R16, shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 128, 64, CL_ADAPTER_DXVA_KHR, - SURFACE_FORMAT_A8B8G8R8, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (DXVA, A8B8G8R8, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 128, 64, CL_ADAPTER_DXVA_KHR, - SURFACE_FORMAT_A8B8G8R8, SHARED_HANDLE_ENABLED) != 0) - { - log_error("\nTest case (DXVA, A8B8G8R8, shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 16, 512, CL_ADAPTER_DXVA_KHR, - SURFACE_FORMAT_X8B8G8R8, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (DXVA, X8B8G8R8, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 16, 512, CL_ADAPTER_DXVA_KHR, - SURFACE_FORMAT_X8B8G8R8, SHARED_HANDLE_ENABLED) != 0) - { - log_error("\nTest case (DXVA, X8B8G8R8, shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 512, 16, CL_ADAPTER_DXVA_KHR, - SURFACE_FORMAT_A8R8G8B8, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (DXVA, A8R8G8B8, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 512, 16, CL_ADAPTER_DXVA_KHR, - SURFACE_FORMAT_A8R8G8B8, SHARED_HANDLE_ENABLED) != 0) - { - log_error("\nTest case (DXVA, A8R8G8B8, shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 256, 256, CL_ADAPTER_DXVA_KHR, - SURFACE_FORMAT_X8R8G8B8, SHARED_HANDLE_DISABLED) != 0) - { - log_error("\nTest case (DXVA, X8R8G8B8, no shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - - if(other_data_types(deviceID, context, queue, num_elements, 10, 256, 256, CL_ADAPTER_DXVA_KHR, - SURFACE_FORMAT_X8R8G8B8, SHARED_HANDLE_ENABLED) != 0) - { - log_error("\nTest case (DXVA, X8R8G8B8, shared handle) failed\n\n"); - result.ResultSub(CResult::TEST_FAIL); - } - -#else - return TEST_NOT_IMPLEMENTED; -#endif - - return result.Result(); -} diff --git a/test_extensions/media_sharing/utils.cpp b/test_extensions/media_sharing/utils.cpp deleted file mode 100644 index 31296432..00000000 --- a/test_extensions/media_sharing/utils.cpp +++ /dev/null @@ -1,1595 +0,0 @@ -// -// 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 "utils.h" - -#include "harness/errorHelpers.h" -#include "harness/imageHelpers.h" -#include "harness/rounding_mode.h" - -#include - -#include - -static RoundingMode gFloatToHalfRoundingMode = kDefaultRoundingMode; - - -CResult::CResult(): -_result(TEST_PASS), _resultLast(TEST_NORESULT) -{ - -} - -CResult::~CResult() -{ - -} - -CResult::TTestResult CResult::ResultLast() const -{ - return _resultLast; -} - -int CResult::Result() const -{ - switch (_result) - { - case TEST_NORESULT: - case TEST_NOTSUPPORTED: - case TEST_PASS: - return 0; - break; - case TEST_FAIL: - return 1; - break; - case TEST_ERROR: - return 2; - break; - default: - return -1; - break; - } -} - -void CResult::ResultSub( TTestResult result ) -{ - _resultLast = result; - if (static_cast(result) > static_cast(_result)) - _result = result; -} - -void FunctionContextCreateToString(TContextFuncType contextCreateFunction, std::string &contextFunction) -{ - switch(contextCreateFunction) - { - case CONTEXT_CREATE_DEFAULT: - contextFunction = "CreateContext"; - break; - case CONTEXT_CREATE_FROM_TYPE: - contextFunction = "CreateContextFromType"; - break; - default: - contextFunction = "Unknown"; - log_error("FunctionContextCreateToString(): Unknown create function enum!"); - break; - } -} - -void AdapterToString(cl_dx9_media_adapter_type_khr adapterType, std::string &adapter) -{ - switch(adapterType) - { - case CL_ADAPTER_D3D9_KHR: - adapter = "D3D9"; - break; - case CL_ADAPTER_D3D9EX_KHR: - adapter = "D3D9EX"; - break; - case CL_ADAPTER_DXVA_KHR: - adapter = "DXVA"; - break; - default: - adapter = "Unknown"; - log_error("AdapterToString(): Unknown adapter type!"); - break; - } -} - -cl_context_info AdapterTypeToContextInfo( cl_dx9_media_adapter_type_khr adapterType ) -{ - switch (adapterType) - { - case CL_ADAPTER_D3D9_KHR: - return CL_CONTEXT_ADAPTER_D3D9_KHR; - break; - case CL_ADAPTER_D3D9EX_KHR: - return CL_CONTEXT_ADAPTER_D3D9EX_KHR; - break; - case CL_ADAPTER_DXVA_KHR: - return CL_CONTEXT_ADAPTER_DXVA_KHR; - break; - default: - log_error("AdapterTypeToContextInfo(): Unknown adapter type!"); - return 0; - break; - } -} - -void YUVGenerateNV12( std::vector &yuv, unsigned int width, unsigned int height, - cl_uchar valueMin, cl_uchar valueMax, double valueAdd ) -{ - yuv.clear(); - yuv.resize(width * height * 3 / 2, 0); - - double min = static_cast(valueMin); - double max = static_cast(valueMax); - double range = 255; - double add = static_cast(valueAdd * range); - double stepX = (max - min) / static_cast(width); - double stepY = (max - min) /static_cast(height); - - //generate Y plane - for (unsigned int i = 0; i < height; ++i) - { - unsigned int offset = i * width; - double valueYPlane0 = static_cast(stepY * i); - for (unsigned int j = 0; j < width; ++j) - { - double valueXPlane0 = static_cast(stepX * j); - yuv.at(offset + j) = static_cast(min + valueXPlane0 / 2 + valueYPlane0 / 2 + add); - } - } - - //generate UV planes - for (unsigned int i = 0; i < height / 2; ++i) - { - unsigned int offset = width * height + i * width; - double valueYPlane1 = static_cast(stepY * i); - double valueYPlane2 = static_cast(stepY * (height / 2 + i)); - for (unsigned int j = 0; j < width / 2; ++j) - { - double valueXPlane1 = static_cast(stepX * j); - double valueXPlane2 = static_cast(stepX * (width / 2 + j)); - - yuv.at(offset + j * 2) = static_cast(min + valueXPlane1 / 2 + valueYPlane1 / 2 + add); - yuv.at(offset + j * 2 + 1) = static_cast(min + valueXPlane2 / 2 + valueYPlane2 / 2 + add); - } - } -} - -void YUVGenerateYV12( std::vector &yuv, unsigned int width, unsigned int height, cl_uchar valueMin, cl_uchar valueMax, double valueAdd /*= 0.0*/ ) -{ - yuv.clear(); - yuv.resize(width * height * 3 / 2, 0); - - double min = static_cast(valueMin); - double max = static_cast(valueMax); - double range = 255; - double add = static_cast(valueAdd * range); - double stepX = (max - min) / static_cast(width); - double stepY = (max - min) /static_cast(height); - - unsigned offset = 0; - - //generate Y plane - for (unsigned int i = 0; i < height; ++i) - { - unsigned int plane0Offset = offset + i * width; - double valueYPlane0 = static_cast(stepY * i); - for (unsigned int j = 0; j < width; ++j) - { - double valueXPlane0 = static_cast(stepX * j); - yuv.at(plane0Offset + j) = static_cast(min + valueXPlane0 / 2 + valueYPlane0 / 2 + add); - } - } - - //generate V plane - offset += width * height; - for (unsigned int i = 0; i < height / 2; ++i) - { - unsigned int plane1Offset = offset + i * width / 2; - double valueYPlane1 = static_cast(stepY * i); - for (unsigned int j = 0; j < width / 2; ++j) - { - double valueXPlane1 = static_cast(stepX * j); - yuv.at(plane1Offset + j) = static_cast(min + valueXPlane1 / 2 + valueYPlane1 / 2 + add); - } - } - - //generate U plane - offset += width * height / 4; - for (unsigned int i = 0; i < height / 2; ++i) - { - unsigned int plane2Offset = offset + i * width / 2; - double valueYPlane2 = static_cast(stepY * (height / 2 + i)); - for (unsigned int j = 0; j < width / 2; ++j) - { - double valueXPlane2 = static_cast(stepX * j); - yuv.at(plane2Offset + j) = static_cast(min + valueXPlane2 / 2 + valueYPlane2 / 2 + add); - } - } -} - - -bool YUVGenerate( TSurfaceFormat surfaceFormat, std::vector &yuv, unsigned int width, unsigned int height, cl_uchar valueMin, cl_uchar valueMax, double valueAdd /*= 0.0*/ ) -{ - switch (surfaceFormat) - { - case SURFACE_FORMAT_NV12: - YUVGenerateNV12(yuv, width, height, valueMin, valueMax, valueAdd); - break; - case SURFACE_FORMAT_YV12: - YUVGenerateYV12(yuv, width, height, valueMin, valueMax, valueAdd); - break; - default: - log_error("YUVGenerate(): Invalid surface type\n"); - return false; - break; - } - - return true; -} - -bool YUVSurfaceSetNV12( std::auto_ptr &surface, const std::vector &yuv, - unsigned int width, unsigned int height ) -{ -#if defined(_WIN32) - CD3D9SurfaceWrapper *d3dSurface = static_cast(surface.get()); - D3DLOCKED_RECT rect; - if (FAILED((*d3dSurface)->LockRect(&rect, NULL, 0))) - { - log_error("YUVSurfaceSetNV12(): Surface lock failed\n"); - return false; - } - - size_t pitch = rect.Pitch / sizeof(cl_uchar); - size_t lineSize = width * sizeof(cl_uchar); - cl_uchar *ptr = static_cast(rect.pBits); - for (size_t y = 0; y < height; ++y) - memcpy(ptr + y * pitch, &yuv.at(y * width), lineSize); - - for (size_t y = 0; y < height / 2; ++y) - memcpy(ptr + height * pitch + y * pitch, &yuv.at(width * height + y * width), lineSize); - - (*d3dSurface)->UnlockRect(); - - return true; - -#else - return false; -#endif -} - -bool YUVSurfaceSetYV12( std::auto_ptr &surface, const std::vector &yuv, - unsigned int width, unsigned int height ) -{ -#if defined(_WIN32) - CD3D9SurfaceWrapper *d3dSurface = static_cast(surface.get()); - D3DLOCKED_RECT rect; - if (FAILED((*d3dSurface)->LockRect(&rect, NULL, 0))) - { - log_error("YUVSurfaceSetYV12(): Surface lock failed!\n"); - return false; - } - - size_t pitch = rect.Pitch / sizeof(cl_uchar); - size_t pitchHalf = pitch / 2; - size_t lineSize = width * sizeof(cl_uchar); - size_t lineHalfSize = lineSize / 2; - size_t surfaceOffset = 0; - size_t yuvOffset = 0; - cl_uchar *ptr = static_cast(rect.pBits); - - for (size_t y = 0; y < height; ++y) - memcpy(ptr + surfaceOffset + y * pitch, &yuv.at(yuvOffset + y * width), lineSize); - - surfaceOffset += height * pitch; - yuvOffset += width * height; - for (size_t y = 0; y < height / 2; ++y) - memcpy(ptr + surfaceOffset + y * pitchHalf, &yuv.at(yuvOffset + y * lineHalfSize), lineHalfSize); - - surfaceOffset += pitchHalf * height / 2; - yuvOffset += width * height / 4; - for (size_t y = 0; y < height / 2; ++y) - memcpy(ptr + surfaceOffset + y * pitchHalf, &yuv.at(yuvOffset + y * lineHalfSize), lineHalfSize); - - (*d3dSurface)->UnlockRect(); - - return true; - -#else - return false; -#endif -} - -bool YUVSurfaceSet(TSurfaceFormat surfaceFormat, std::auto_ptr &surface, const std::vector &yuv, unsigned int width, unsigned int height ) -{ - switch (surfaceFormat) - { - case SURFACE_FORMAT_NV12: - if(!YUVSurfaceSetNV12(surface, yuv, width, height)) - return false; - break; - case SURFACE_FORMAT_YV12: - if(!YUVSurfaceSetYV12(surface, yuv, width, height)) - return false; - break; - default: - log_error("YUVSurfaceSet(): Invalid surface type!\n"); - return false; - break; - } - - return true; -} - -bool YUVSurfaceGetNV12( std::auto_ptr &surface, std::vector &yuv, - unsigned int width, unsigned int height ) -{ -#if defined(_WIN32) - CD3D9SurfaceWrapper *d3dSurface = static_cast(surface.get()); - D3DLOCKED_RECT rect; - if (FAILED((*d3dSurface)->LockRect(&rect, NULL, 0))) - { - log_error("YUVSurfaceGetNV12(): Surface lock failed!\n"); - return false; - } - - size_t pitch = rect.Pitch / sizeof(cl_uchar); - size_t lineSize = width * sizeof(cl_uchar); - cl_uchar *ptr = static_cast(rect.pBits); - size_t yuvOffset = 0; - size_t surfaceOffset = 0; - for (size_t y = 0; y < height; ++y) - memcpy(&yuv.at(yuvOffset + y * width), ptr + y * pitch, lineSize); - - yuvOffset += width * height; - surfaceOffset += pitch * height; - for (size_t y = 0; y < height / 2; ++y) - memcpy(&yuv.at(yuvOffset + y * width), ptr + surfaceOffset + y * pitch, lineSize); - - (*d3dSurface)->UnlockRect(); - - return true; - -#else - return false; -#endif -} - -bool YUVSurfaceGetYV12( std::auto_ptr &surface, std::vector &yuv, unsigned int width, unsigned int height ) -{ -#if defined(_WIN32) - CD3D9SurfaceWrapper *d3dSurface = static_cast(surface.get()); - D3DLOCKED_RECT rect; - if (FAILED((*d3dSurface)->LockRect(&rect, NULL, 0))) - { - log_error("YUVSurfaceGetYV12(): Surface lock failed!\n"); - return false; - } - - size_t pitch = rect.Pitch / sizeof(cl_uchar); - size_t pitchHalf = pitch / 2; - size_t lineSize = width * sizeof(cl_uchar); - size_t lineHalfSize = lineSize / 2; - size_t surfaceOffset = 0; - size_t yuvOffset = 0; - cl_uchar *ptr = static_cast(rect.pBits); - - for (size_t y = 0; y < height; ++y) - memcpy(&yuv.at(yuvOffset + y * width), ptr + surfaceOffset + y * pitch, lineSize); - - surfaceOffset += pitch * height; - yuvOffset += width * height; - for (size_t y = 0; y < height / 2; ++y) - memcpy(&yuv.at(yuvOffset + y * lineHalfSize), ptr + surfaceOffset + y * pitchHalf, lineHalfSize); - - surfaceOffset += pitchHalf * height / 2; - yuvOffset += width * height / 4; - for (size_t y = 0; y < height / 2; ++y) - memcpy(&yuv.at(yuvOffset + y * lineHalfSize), ptr + surfaceOffset + y * pitchHalf, lineHalfSize); - - (*d3dSurface)->UnlockRect(); - - return true; - -#else - return false; -#endif -} - -bool YUVSurfaceGet(TSurfaceFormat surfaceFormat, std::auto_ptr &surface, std::vector &yuv, - unsigned int width, unsigned int height ) -{ - switch (surfaceFormat) - { - case SURFACE_FORMAT_NV12: - if(!YUVSurfaceGetNV12(surface, yuv, width, height)) - return false; - break; - case SURFACE_FORMAT_YV12: - if(!YUVSurfaceGetYV12(surface, yuv, width, height)) - return false; - break; - default: - log_error("YUVSurfaceGet(): Invalid surface type!\n"); - return false; - break; - } - - return true; -} - -bool YUVCompareNV12( const std::vector &yuvTest, const std::vector &yuvRef, - unsigned int width, unsigned int height ) -{ - //plane 0 verification - size_t offset = 0; - for (size_t y = 0; y < height; ++y) - { - size_t plane0Offset = offset + width * y; - for (size_t x = 0; x < width; ++x) - { - if (yuvTest[plane0Offset + x] != yuvRef[plane0Offset + x]) - { - log_error("Plane 0 (Y) is different than expected, reference value: %i, test value: %i, x: %i, y: %i\n", - yuvRef[plane0Offset + x], yuvTest[plane0Offset + x], x, y); - return false; - } - } - } - - //plane 1 and 2 verification - offset += width * height; - for (size_t y = 0; y < height / 2; ++y) - { - size_t plane12Offset = offset + width * y; - for (size_t x = 0; x < width / 2; ++x) - { - if (yuvTest.at(plane12Offset + 2 * x) != yuvRef.at(plane12Offset + 2 * x)) - { - log_error("Plane 1 (U) is different than expected, reference value: %i, test value: %i, x: %i, y: %i\n", - yuvRef[plane12Offset + 2 * x], yuvTest[plane12Offset + 2 * x], x, y); - return false; - } - - if (yuvTest.at(plane12Offset + 2 * x + 1) != yuvRef.at(plane12Offset + 2 * x + 1)) - { - log_error("Plane 2 (V) is different than expected, reference value: %i, test value: %i, x: %i, y: %i\n", - yuvRef[plane12Offset + 2 * x + 1], yuvTest[plane12Offset + 2 * x + 1], x, y); - return false; - } - } - } - - return true; -} - -bool YUVCompareYV12( const std::vector &yuvTest, const std::vector &yuvRef, - unsigned int width, unsigned int height ) -{ - //plane 0 verification - size_t offset = 0; - for (size_t y = 0; y < height; ++y) - { - size_t plane0Offset = width * y; - for (size_t x = 0; x < width; ++x) - { - if (yuvTest.at(plane0Offset + x) != yuvRef.at(plane0Offset + x)) - { - log_error("Plane 0 (Y) is different than expected, reference value: %i, test value: %i, x: %i, y: %i\n", - yuvRef[plane0Offset + x], yuvTest[plane0Offset + x], x ,y); - return false; - } - } - } - - //plane 1 verification - offset += width * height; - for (size_t y = 0; y < height / 2; ++y) - { - size_t plane1Offset = offset + width * y / 2; - for (size_t x = 0; x < width / 2; ++x) - { - if (yuvTest.at(plane1Offset + x) != yuvRef.at(plane1Offset + x)) - { - log_error("Plane 1 (V) is different than expected, reference value: %i, test value: %i, x: %i, y: %i\n", - yuvRef[plane1Offset + x], yuvTest[plane1Offset + x], x, y); - return false; - } - } - } - - //plane 2 verification - offset += width * height / 4; - for (size_t y = 0; y < height / 2; ++y) - { - size_t plane2Offset = offset + width * y / 2; - for (size_t x = 0; x < width / 2; ++x) - { - if (yuvTest.at(plane2Offset + x) != yuvRef.at(plane2Offset + x)) - { - log_error("Plane 2 (U) is different than expected, reference value: %i, test value: %i, x: %i, y: %i\n", - yuvRef[plane2Offset + x], yuvTest[plane2Offset + x], x, y); - return false; - } - } - } - - return true; -} - -bool YUVCompare( TSurfaceFormat surfaceFormat, const std::vector &yuvTest, const std::vector &yuvRef, - unsigned int width, unsigned int height ) -{ - switch (surfaceFormat) - { - case SURFACE_FORMAT_NV12: - if (!YUVCompareNV12(yuvTest, yuvRef, width, height)) - { - log_error("OCL object is different than expected!\n"); - return false; - } - break; - case SURFACE_FORMAT_YV12: - if (!YUVCompareYV12(yuvTest, yuvRef, width, height)) - { - log_error("OCL object is different than expected!\n"); - return false; - } - break; - default: - log_error("YUVCompare(): Invalid surface type!\n"); - return false; - break; - } - - return true; -} - -void DataGenerate( TSurfaceFormat surfaceFormat, cl_channel_type type, std::vector &data, unsigned int width, unsigned int height, - unsigned int channelNum, float cmin /*= 0.0f*/, float cmax /*= 1.0f*/, float add /*= 0.0f*/ ) -{ - data.clear(); - data.reserve(width * height * channelNum); - - double valueMin = static_cast(cmin); - double valueMax = static_cast(cmax); - double stepX = (valueMax - valueMin) / static_cast(width); - double stepY = (valueMax - valueMin) /static_cast(height); - double valueAdd = static_cast(add); - for (unsigned int i = 0; i < height; ++i) - { - double valueY = static_cast(stepY * i); - for (unsigned int j = 0; j < width; ++j) - { - double valueX = static_cast(stepX * j); - switch (channelNum) - { - case 1: - data.push_back(static_cast(valueMin + valueX / 2 + valueY / 2 + valueAdd)); - break; - case 2: - data.push_back(static_cast(valueMin + valueX + valueAdd)); - data.push_back(static_cast(valueMin + valueY + valueAdd)); - break; - case 4: - data.push_back(static_cast(valueMin + valueX + valueAdd)); - data.push_back(static_cast(valueMin + valueY + valueAdd)); - data.push_back(static_cast(valueMin + valueX / 2 + valueAdd)); - data.push_back(static_cast(valueMin + valueY / 2 + valueAdd)); - break; - default: - log_error("DataGenerate(): invalid channel number!"); - return; - break; - } - } - } -} - -void DataGenerate( TSurfaceFormat surfaceFormat, cl_channel_type type, std::vector &data, unsigned int width, unsigned int height, - unsigned int channelNum, float cmin /*= 0.0f*/, float cmax /*= 1.0f*/, float add /*= 0.0f*/ ) -{ - data.clear(); - data.reserve(width * height * channelNum); - - double valueMin = static_cast(cmin); - double valueMax = static_cast(cmax); - double stepX = (valueMax - valueMin) / static_cast(width); - double stepY = (valueMax - valueMin) /static_cast(height); - - switch(type) - { - case CL_HALF_FLOAT: - { - double valueAdd = static_cast(add); - - for (unsigned int i = 0; i < height; ++i) - { - double valueY = static_cast(stepY * i); - for (unsigned int j = 0; j < width; ++j) - { - double valueX = static_cast(stepX * j); - switch (channelNum) - { - case 1: - data.push_back(convert_float_to_half(static_cast(valueMin + valueX / 2 + valueY / 2 + valueAdd))); - break; - case 2: - data.push_back(convert_float_to_half(static_cast(valueMin + valueX + valueAdd))); - data.push_back(convert_float_to_half(static_cast(valueMin + valueY + valueAdd))); - break; - case 4: - data.push_back(convert_float_to_half(static_cast(valueMin + valueX + valueAdd))); - data.push_back(convert_float_to_half(static_cast(valueMin + valueY + valueAdd))); - data.push_back(convert_float_to_half(static_cast(valueMin + valueX / 2 + valueAdd))); - data.push_back(convert_float_to_half(static_cast(valueMin + valueY / 2 + valueAdd))); - break; - default: - log_error("DataGenerate(): invalid channel number!"); - return; - break; - } - } - } - break; - } - case CL_UNORM_INT16: - { - double range = 65535; - double valueAdd = static_cast(add * range); - - for (unsigned int i = 0; i < height; ++i) - { - double valueY = static_cast(stepY * i * range); - for (unsigned int j = 0; j < width; ++j) - { - double valueX = static_cast(stepX * j * range); - switch (channelNum) - { - case 1: - data.push_back(static_cast(valueMin + valueX / 2 + valueY / 2 + valueAdd)); - break; - case 2: - data.push_back(static_cast(valueMin + valueX + valueAdd)); - data.push_back(static_cast(valueMin + valueY + valueAdd)); - break; - case 4: - data.push_back(static_cast(valueMin + valueX + valueAdd)); - data.push_back(static_cast(valueMin + valueY + valueAdd)); - data.push_back(static_cast(valueMin + valueX / 2 + valueAdd)); - data.push_back(static_cast(valueMin + valueY / 2 + valueAdd)); - break; - default: - log_error("DataGenerate(): invalid channel number!"); - return; - break; - } - } - } - } - break; - default: - log_error("DataGenerate(): unknown data type!"); - return; - break; - } -} - -void DataGenerate( TSurfaceFormat surfaceFormat, cl_channel_type type, std::vector &data, unsigned int width, unsigned int height, - unsigned int channelNum, float cmin /*= 0.0f*/, float cmax /*= 1.0f*/, float add /*= 0.0f*/ ) -{ - data.clear(); - data.reserve(width * height * channelNum); - - double valueMin = static_cast(cmin); - double valueMax = static_cast(cmax); - double stepX = (valueMax - valueMin) / static_cast(width); - double stepY = (valueMax - valueMin) /static_cast(height); - - double range = 255; - double valueAdd = static_cast(add * range); - - for (unsigned int i = 0; i < height; ++i) - { - double valueY = static_cast(stepY * i * range); - for (unsigned int j = 0; j < width; ++j) - { - double valueX = static_cast(stepX * j * range); - switch (channelNum) - { - case 1: - data.push_back(static_cast(valueMin + valueX / 2 + valueY / 2 + valueAdd)); - break; - case 2: - data.push_back(static_cast(valueMin + valueX + valueAdd)); - data.push_back(static_cast(valueMin + valueY + valueAdd)); - break; - case 4: - data.push_back(static_cast(valueMin + valueX + valueAdd)); - data.push_back(static_cast(valueMin + valueY + valueAdd)); - data.push_back(static_cast(valueMin + valueX / 2 + valueAdd)); - if (surfaceFormat == SURFACE_FORMAT_X8R8G8B8) - data.push_back(static_cast(0xff)); - else - data.push_back(static_cast(valueMin + valueY / 2 + valueAdd)); - break; - default: - log_error("DataGenerate(): invalid channel number!"); - return; - break; - } - } - } -} - -bool DataCompare( TSurfaceFormat surfaceFormat, cl_channel_type type, const std::vector &dataTest, const std::vector &dataExp, - unsigned int width, unsigned int height, unsigned int channelNum) -{ - float epsilon = 0.000001f; - for (unsigned int i = 0; i < height; ++i) - { - unsigned int offset = i * width * channelNum; - for (unsigned int j = 0; j < width; ++j) - { - for(unsigned planeIdx = 0; planeIdx < channelNum; ++planeIdx) - { - if (abs(dataTest.at(offset + j * channelNum + planeIdx) - dataExp.at(offset + j * channelNum + planeIdx)) > epsilon) - { - log_error("Tested image is different than reference (x,y,plane) = (%i,%i,%i), test value = %f, expected value = %f\n", - j, i, planeIdx, dataTest[offset + j * channelNum + planeIdx], dataExp[offset + j * channelNum + planeIdx]); - return false; - } - } - } - } - - return true; -} - -bool DataCompare( TSurfaceFormat surfaceFormat, cl_channel_type type, const std::vector &dataTest, const std::vector &dataExp, - unsigned int width, unsigned int height, unsigned int channelNum) -{ - switch(type) - { - case CL_HALF_FLOAT: - { - float epsilon = 0.001f; - for (unsigned int i = 0; i < height; ++i) - { - unsigned int offset = i * width * channelNum; - for (unsigned int j = 0; j < width; ++j) - { - for(unsigned planeIdx = 0; planeIdx < channelNum; ++planeIdx) - { - float test = cl_half_to_float( - dataTest.at(offset + j * channelNum + planeIdx)); - float ref = cl_half_to_float( - dataExp.at(offset + j * channelNum + planeIdx)); - if (abs(test - ref) > epsilon) - { - log_error( - "Tested image is different than reference (x,y,plane) = " - "(%i,%i,%i), test value = %f, expected value = %f\n", - j, i, planeIdx, test, ref); - return false; - } - } - } - } - } - break; - case CL_UNORM_INT16: - { - cl_ushort epsilon = 1; - for (unsigned int i = 0; i < height; ++i) - { - unsigned int offset = i * width * channelNum; - for (unsigned int j = 0; j < width; ++j) - { - for(unsigned planeIdx = 0; planeIdx < channelNum; ++planeIdx) - { - cl_ushort test = dataTest.at(offset + j * channelNum + planeIdx); - cl_ushort ref = dataExp.at(offset + j * channelNum + planeIdx); - if (abs(test - ref) > epsilon) - { - log_error("Tested image is different than reference (x,y,plane) = (%i,%i,%i), test value = %i, expected value = %i\n", j, i, planeIdx, test, ref); - return false; - } - } - } - } - } - break; - default: - log_error("DataCompare(): Invalid data format!"); - return false; - break; - } - - return true; -} - -bool DataCompare( TSurfaceFormat surfaceFormat, cl_channel_type type, const std::vector &dataTest, const std::vector &dataExp, - unsigned int width, unsigned int height, unsigned int planeNum ) -{ - for (unsigned int i = 0; i < height; ++i) - { - unsigned int offset = i * width * planeNum; - for (unsigned int j = 0; j < width; ++j) - { - for(unsigned planeIdx = 0; planeIdx < planeNum; ++planeIdx) - { - if (surfaceFormat == SURFACE_FORMAT_X8R8G8B8 && planeIdx == 3) - continue; - - cl_uchar test = dataTest.at(offset + j * planeNum + planeIdx); - cl_uchar ref = dataExp.at(offset + j * planeNum + planeIdx); - if (test != ref) - { - log_error("Tested image is different than reference (x,y,plane) = (%i,%i,%i), test value = %i, expected value = %i\n", - j, i, planeIdx, test, ref); - return false; - } - } - } - } - - return true; -} - -bool GetImageInfo( cl_mem object, cl_image_format formatExp, size_t elementSizeExp, size_t rowPitchExp, - size_t slicePitchExp, size_t widthExp, size_t heightExp, size_t depthExp , unsigned int planeExp) -{ - bool result = true; - - cl_image_format format; - if (clGetImageInfo(object, CL_IMAGE_FORMAT, sizeof(cl_image_format), &format, 0) != CL_SUCCESS) - { - log_error("clGetImageInfo(CL_IMAGE_FORMAT) failed\n"); - result = false; - } - - if (formatExp.image_channel_order != format.image_channel_order || formatExp.image_channel_data_type != format.image_channel_data_type) - { - log_error("Value of CL_IMAGE_FORMAT is different than expected\n"); - result = false; - } - - size_t elementSize = 0; - if (clGetImageInfo(object, CL_IMAGE_ELEMENT_SIZE, sizeof(size_t), &elementSize, 0) != CL_SUCCESS) - { - log_error("clGetImageInfo(CL_IMAGE_ELEMENT_SIZE) failed\n"); - result = false; - } - - if (elementSizeExp != elementSize) - { - log_error("Value of CL_IMAGE_ELEMENT_SIZE is different than expected (size: %i, exp size: %i)\n", elementSize, elementSizeExp); - result = false; - } - - size_t rowPitch = 0; - if (clGetImageInfo(object, CL_IMAGE_ROW_PITCH, sizeof(size_t), &rowPitch, 0) != CL_SUCCESS) - { - log_error("clGetImageInfo(CL_IMAGE_ROW_PITCH) failed\n"); - result = false; - } - - if ((rowPitchExp == 0 && rowPitchExp != rowPitch) || (rowPitchExp > 0 && rowPitchExp > rowPitch)) - { - log_error("Value of CL_IMAGE_ROW_PITCH is different than expected (size: %i, exp size: %i)\n", rowPitch, rowPitchExp); - result = false; - } - - size_t slicePitch = 0; - if (clGetImageInfo(object, CL_IMAGE_SLICE_PITCH, sizeof(size_t), &slicePitch, 0) != CL_SUCCESS) - { - log_error("clGetImageInfo(CL_IMAGE_SLICE_PITCH) failed\n"); - result = false; - } - - if ((slicePitchExp == 0 && slicePitchExp != slicePitch) || (slicePitchExp > 0 && slicePitchExp > slicePitch)) - { - log_error("Value of CL_IMAGE_SLICE_PITCH is different than expected (size: %i, exp size: %i)\n", slicePitch, slicePitchExp); - result = false; - } - - size_t width = 0; - if (clGetImageInfo(object, CL_IMAGE_WIDTH, sizeof(size_t), &width, 0) != CL_SUCCESS) - { - log_error("clGetImageInfo(CL_IMAGE_WIDTH) failed\n"); - result = false; - } - - if (widthExp != width) - { - log_error("Value of CL_IMAGE_WIDTH is different than expected (size: %i, exp size: %i)\n", width, widthExp); - result = false; - } - - size_t height = 0; - if (clGetImageInfo(object, CL_IMAGE_HEIGHT, sizeof(size_t), &height, 0) != CL_SUCCESS) - { - log_error("clGetImageInfo(CL_IMAGE_HEIGHT) failed\n"); - result = false; - } - - if (heightExp != height) - { - log_error("Value of CL_IMAGE_HEIGHT is different than expected (size: %i, exp size: %i)\n", height, heightExp); - result = false; - } - - size_t depth = 0; - if (clGetImageInfo(object, CL_IMAGE_DEPTH, sizeof(size_t), &depth, 0) != CL_SUCCESS) - { - log_error("clGetImageInfo(CL_IMAGE_DEPTH) failed\n"); - result = false; - } - - if (depthExp != depth) - { - log_error("Value of CL_IMAGE_DEPTH is different than expected (size: %i, exp size: %i)\n", depth, depthExp); - result = false; - } - - unsigned int plane = 99; - size_t paramSize = 0; - if (clGetImageInfo(object, CL_IMAGE_DX9_MEDIA_PLANE_KHR, sizeof(unsigned int), &plane, ¶mSize) != CL_SUCCESS) - { - log_error("clGetImageInfo(CL_IMAGE_MEDIA_SURFACE_PLANE_KHR) failed\n"); - result = false; - } - - if (planeExp != plane) - { - log_error("Value of CL_IMAGE_MEDIA_SURFACE_PLANE_KHR is different than expected (plane: %i, exp plane: %i)\n", plane, planeExp); - result = false; - } - - return result; -} - -bool GetMemObjInfo( cl_mem object, cl_dx9_media_adapter_type_khr adapterType, std::auto_ptr &surface, void *shareHandleExp ) -{ - bool result = true; - switch(adapterType) - { - case CL_ADAPTER_D3D9_KHR: - case CL_ADAPTER_D3D9EX_KHR: - case CL_ADAPTER_DXVA_KHR: - { -#if defined(_WIN32) - cl_dx9_surface_info_khr surfaceInfo; -#else - void *surfaceInfo = 0; - return false; -#endif - size_t paramSize = 0; - if(clGetMemObjectInfo(object, CL_MEM_DX9_MEDIA_SURFACE_INFO_KHR, sizeof(surfaceInfo), &surfaceInfo, ¶mSize) != CL_SUCCESS) - { - log_error("clGetImageInfo(CL_MEM_DX9_MEDIA_SURFACE_INFO_KHR) failed\n"); - result = false; - } - -#if defined(_WIN32) - CD3D9SurfaceWrapper *d3d9Surface = static_cast(surface.get()); - if (*d3d9Surface != surfaceInfo.resource) - { - log_error("Invalid resource for CL_MEM_DX9_MEDIA_SURFACE_INFO_KHR\n"); - result = false; - } - - if (shareHandleExp != surfaceInfo.shared_handle) - { - log_error("Invalid shared handle for CL_MEM_DX9_MEDIA_SURFACE_INFO_KHR\n"); - result = false; - } -#else - return false; -#endif - - if (paramSize != sizeof(surfaceInfo)) - { - log_error("Invalid CL_MEM_DX9_MEDIA_SURFACE_INFO_KHR parameter size: %i, expected: %i\n", paramSize, sizeof(surfaceInfo)); - result = false; - } - - paramSize = 0; - cl_dx9_media_adapter_type_khr mediaAdapterType; - if(clGetMemObjectInfo(object, CL_MEM_DX9_MEDIA_ADAPTER_TYPE_KHR, sizeof(mediaAdapterType), &mediaAdapterType, ¶mSize) != CL_SUCCESS) - { - log_error("clGetImageInfo(CL_MEM_DX9_MEDIA_ADAPTER_TYPE_KHR) failed\n"); - result = false; - } - - if (adapterType != mediaAdapterType) - { - log_error("Invalid media adapter type for CL_MEM_DX9_MEDIA_ADAPTER_TYPE_KHR\n"); - result = false; - } - - if (paramSize != sizeof(mediaAdapterType)) - { - log_error("Invalid CL_MEM_DX9_MEDIA_ADAPTER_TYPE_KHR parameter size: %i, expected: %i\n", paramSize, sizeof(mediaAdapterType)); - result = false; - } - } - break; - default: - log_error("GetMemObjInfo(): Unknown adapter type!\n"); - return false; - break; - } - - return result; -} - -bool ImageInfoVerify( cl_dx9_media_adapter_type_khr adapterType, const std::vector &memObjList, unsigned int width, unsigned int height, - std::auto_ptr &surface, void *sharedHandle) -{ - if (memObjList.size() != 2 && memObjList.size() != 3) - { - log_error("ImageInfoVerify(): Invalid object list parameter\n"); - return false; - } - - cl_image_format formatPlane; - formatPlane.image_channel_data_type = CL_UNORM_INT8; - formatPlane.image_channel_order = CL_R; - - //plane 0 verification - if (!GetImageInfo(memObjList[0], formatPlane, sizeof(cl_uchar), - width * sizeof(cl_uchar), - 0, - width, height, 0, 0)) - { - log_error("clGetImageInfo failed\n"); - return false; - } - - switch (memObjList.size()) - { - case 2: - { - formatPlane.image_channel_data_type = CL_UNORM_INT8; - formatPlane.image_channel_order = CL_RG; - if (!GetImageInfo(memObjList[1], formatPlane, sizeof(cl_uchar) * 2, - width * sizeof(cl_uchar), - 0, - width / 2, height / 2, 0, 1)) - { - log_error("clGetImageInfo failed\n"); - return false; - } - } - break; - case 3: - { - if (!GetImageInfo(memObjList[1], formatPlane, sizeof(cl_uchar), - width * sizeof(cl_uchar) / 2, - 0, - width / 2, height / 2, 0, 1)) - { - log_error("clGetImageInfo failed\n"); - return false; - } - - if (!GetImageInfo(memObjList[2], formatPlane, sizeof(cl_uchar), - width * sizeof(cl_uchar) / 2, - 0, - width / 2, height / 2, 0, 2)) - { - log_error("clGetImageInfo failed\n"); - return false; - } - } - break; - default: - log_error("ImageInfoVerify(): Invalid object list parameter\n"); - return false; - break; - } - - for (size_t i = 0; i < memObjList.size(); ++i) - { - if (!GetMemObjInfo(memObjList[i], adapterType, surface, sharedHandle)) - { - log_error("clGetMemObjInfo(%i) failed\n", i); - return false; - } - } - - return true; -} - -bool ImageFormatCheck(cl_context context, cl_mem_object_type imageType, const cl_image_format imageFormatCheck) -{ - cl_uint imageFormatsNum = 0; - cl_int error = clGetSupportedImageFormats(context, CL_MEM_READ_WRITE, imageType, 0, 0, &imageFormatsNum); - if(error != CL_SUCCESS) - { - log_error("clGetSupportedImageFormats failed\n"); - return false; - } - - if(imageFormatsNum < 1) - { - log_error("Invalid image format number returned by clGetSupportedImageFormats\n"); - return false; - } - - std::vector imageFormats(imageFormatsNum); - error = clGetSupportedImageFormats(context, CL_MEM_READ_WRITE, imageType, imageFormatsNum, &imageFormats[0], 0); - if(error != CL_SUCCESS) - { - log_error("clGetSupportedImageFormats failed\n"); - return false; - } - - for(cl_uint i = 0; i < imageFormatsNum; ++i) - { - if(imageFormats[i].image_channel_data_type == imageFormatCheck.image_channel_data_type - && imageFormats[i].image_channel_order == imageFormatCheck.image_channel_order) - { - return true; - } - } - - return false; -} - -unsigned int ChannelNum( TSurfaceFormat surfaceFormat ) -{ - switch(surfaceFormat) - { - case SURFACE_FORMAT_R32F: - case SURFACE_FORMAT_R16F: - case SURFACE_FORMAT_L16: - case SURFACE_FORMAT_A8: - case SURFACE_FORMAT_L8: - return 1; - break; - case SURFACE_FORMAT_G32R32F: - case SURFACE_FORMAT_G16R16F: - case SURFACE_FORMAT_G16R16: - case SURFACE_FORMAT_A8L8: - return 2; - break; - case SURFACE_FORMAT_NV12: - case SURFACE_FORMAT_YV12: - return 3; - break; - case SURFACE_FORMAT_A32B32G32R32F: - case SURFACE_FORMAT_A16B16G16R16F: - case SURFACE_FORMAT_A16B16G16R16: - case SURFACE_FORMAT_A8B8G8R8: - case SURFACE_FORMAT_X8B8G8R8: - case SURFACE_FORMAT_A8R8G8B8: - case SURFACE_FORMAT_X8R8G8B8: - return 4; - break; - default: - log_error("ChannelNum(): unknown surface format!\n"); - return 0; - break; - } -} - -unsigned int PlanesNum( TSurfaceFormat surfaceFormat ) -{ - switch(surfaceFormat) - { - case SURFACE_FORMAT_R32F: - case SURFACE_FORMAT_R16F: - case SURFACE_FORMAT_L16: - case SURFACE_FORMAT_A8: - case SURFACE_FORMAT_L8: - case SURFACE_FORMAT_G32R32F: - case SURFACE_FORMAT_G16R16F: - case SURFACE_FORMAT_G16R16: - case SURFACE_FORMAT_A8L8: - case SURFACE_FORMAT_A32B32G32R32F: - case SURFACE_FORMAT_A16B16G16R16F: - case SURFACE_FORMAT_A16B16G16R16: - case SURFACE_FORMAT_A8B8G8R8: - case SURFACE_FORMAT_X8B8G8R8: - case SURFACE_FORMAT_A8R8G8B8: - case SURFACE_FORMAT_X8R8G8B8: - return 1; - break; - case SURFACE_FORMAT_NV12: - return 2; - break; - case SURFACE_FORMAT_YV12: - return 3; - break; - default: - log_error("PlanesNum(): unknown surface format!\n"); - return 0; - break; - } -} - -#if defined(_WIN32) -D3DFORMAT SurfaceFormatToD3D(TSurfaceFormat surfaceFormat) -{ - switch(surfaceFormat) - { - case SURFACE_FORMAT_R32F: - return D3DFMT_R32F; - break; - case SURFACE_FORMAT_R16F: - return D3DFMT_R16F; - break; - case SURFACE_FORMAT_L16: - return D3DFMT_L16; - break; - case SURFACE_FORMAT_A8: - return D3DFMT_A8; - break; - case SURFACE_FORMAT_L8: - return D3DFMT_L8; - break; - case SURFACE_FORMAT_G32R32F: - return D3DFMT_G32R32F; - break; - case SURFACE_FORMAT_G16R16F: - return D3DFMT_G16R16F; - break; - case SURFACE_FORMAT_G16R16: - return D3DFMT_G16R16; - break; - case SURFACE_FORMAT_A8L8: - return D3DFMT_A8L8; - break; - case SURFACE_FORMAT_A32B32G32R32F: - return D3DFMT_A32B32G32R32F; - break; - case SURFACE_FORMAT_A16B16G16R16F: - return D3DFMT_A16B16G16R16F; - break; - case SURFACE_FORMAT_A16B16G16R16: - return D3DFMT_A16B16G16R16; - break; - case SURFACE_FORMAT_A8B8G8R8: - return D3DFMT_A8B8G8R8; - break; - case SURFACE_FORMAT_X8B8G8R8: - return D3DFMT_X8B8G8R8; - break; - case SURFACE_FORMAT_A8R8G8B8: - return D3DFMT_A8R8G8B8; - break; - case SURFACE_FORMAT_X8R8G8B8: - return D3DFMT_X8R8G8B8; - break; - case SURFACE_FORMAT_NV12: - return static_cast(MAKEFOURCC('N', 'V', '1', '2')); - break; - case SURFACE_FORMAT_YV12: - return static_cast(MAKEFOURCC('Y', 'V', '1', '2')); - break; - default: - log_error("SurfaceFormatToD3D(): unknown surface format!\n"); - return D3DFMT_R32F; - break; - } -} -#endif - -bool DeviceCreate( cl_dx9_media_adapter_type_khr adapterType, std::auto_ptr &device ) -{ - switch (adapterType) - { -#if defined(_WIN32) - case CL_ADAPTER_D3D9_KHR: - device = std::auto_ptr(new CD3D9Wrapper()); - break; - case CL_ADAPTER_D3D9EX_KHR: - device = std::auto_ptr(new CD3D9ExWrapper()); - break; - case CL_ADAPTER_DXVA_KHR: - device = std::auto_ptr(new CDXVAWrapper()); - break; -#endif - default: - log_error("DeviceCreate(): Unknown adapter type!\n"); - return false; - break; - } - - return device->Status(); -} - -bool SurfaceFormatCheck( cl_dx9_media_adapter_type_khr adapterType, const CDeviceWrapper &device, TSurfaceFormat surfaceFormat ) -{ - switch (adapterType) - { -#if defined(_WIN32) - case CL_ADAPTER_D3D9_KHR: - case CL_ADAPTER_D3D9EX_KHR: - case CL_ADAPTER_DXVA_KHR: - { - D3DFORMAT d3dFormat = SurfaceFormatToD3D(surfaceFormat); - LPDIRECT3D9 d3d9 = static_cast(device.D3D()); - D3DDISPLAYMODE d3ddm; - d3d9->GetAdapterDisplayMode(device.AdapterIdx(), &d3ddm); - - if( FAILED(d3d9->CheckDeviceFormat(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, d3ddm.Format, 0, D3DRTYPE_SURFACE, d3dFormat)) ) - return false; - } - break; -#endif - default: - log_error("SurfaceFormatCheck(): Unknown adapter type!\n"); - return false; - break; - } - - return true; -} - -bool SurfaceFormatToOCL(TSurfaceFormat surfaceFormat, cl_image_format &format) -{ - switch(surfaceFormat) - { - case SURFACE_FORMAT_R32F: - format.image_channel_order = CL_R; - format.image_channel_data_type = CL_FLOAT; - break; - case SURFACE_FORMAT_R16F: - format.image_channel_order = CL_R; - format.image_channel_data_type = CL_HALF_FLOAT; - break; - case SURFACE_FORMAT_L16: - format.image_channel_order = CL_R; - format.image_channel_data_type = CL_UNORM_INT16; - break; - case SURFACE_FORMAT_A8: - format.image_channel_order = CL_A; - format.image_channel_data_type = CL_UNORM_INT8; - break; - case SURFACE_FORMAT_L8: - format.image_channel_order = CL_R; - format.image_channel_data_type = CL_UNORM_INT8; - break; - case SURFACE_FORMAT_G32R32F: - format.image_channel_order = CL_RG; - format.image_channel_data_type = CL_FLOAT; - break; - case SURFACE_FORMAT_G16R16F: - format.image_channel_order = CL_RG; - format.image_channel_data_type = CL_HALF_FLOAT; - break; - case SURFACE_FORMAT_G16R16: - format.image_channel_order = CL_RG; - format.image_channel_data_type = CL_UNORM_INT16; - break; - case SURFACE_FORMAT_A8L8: - format.image_channel_order = CL_RG; - format.image_channel_data_type = CL_UNORM_INT8; - break; - case SURFACE_FORMAT_A32B32G32R32F: - format.image_channel_order = CL_RGBA; - format.image_channel_data_type = CL_FLOAT; - break; - case SURFACE_FORMAT_A16B16G16R16F: - format.image_channel_order = CL_RGBA; - format.image_channel_data_type = CL_HALF_FLOAT; - break; - case SURFACE_FORMAT_A16B16G16R16: - format.image_channel_order = CL_RGBA; - format.image_channel_data_type = CL_UNORM_INT16; - break; - case SURFACE_FORMAT_A8B8G8R8: - format.image_channel_order = CL_RGBA; - format.image_channel_data_type = CL_UNORM_INT8; - break; - case SURFACE_FORMAT_X8B8G8R8: - format.image_channel_order = CL_RGBA; - format.image_channel_data_type = CL_UNORM_INT8; - break; - case SURFACE_FORMAT_A8R8G8B8: - format.image_channel_order = CL_BGRA; - format.image_channel_data_type = CL_UNORM_INT8; - break; - case SURFACE_FORMAT_X8R8G8B8: - format.image_channel_order = CL_BGRA; - format.image_channel_data_type = CL_UNORM_INT8; - break; - case SURFACE_FORMAT_NV12: - format.image_channel_order = CL_R; - format.image_channel_data_type = CL_UNORM_INT8; - break; - case SURFACE_FORMAT_YV12: - format.image_channel_order = CL_R; - format.image_channel_data_type = CL_UNORM_INT8; - break; - default: - log_error("SurfaceFormatToOCL(): Unknown surface format!\n"); - return false; - break; - } - - return true; -} - -void SurfaceFormatToString( TSurfaceFormat surfaceFormat, std::string &str ) -{ - switch(surfaceFormat) - { - case SURFACE_FORMAT_R32F: - str = "R32F"; - break; - case SURFACE_FORMAT_R16F: - str = "R16F"; - break; - case SURFACE_FORMAT_L16: - str = "L16"; - break; - case SURFACE_FORMAT_A8: - str = "A8"; - break; - case SURFACE_FORMAT_L8: - str = "L8"; - break; - case SURFACE_FORMAT_G32R32F: - str = "G32R32F"; - break; - case SURFACE_FORMAT_G16R16F: - str = "G16R16F"; - break; - case SURFACE_FORMAT_G16R16: - str = "G16R16"; - break; - case SURFACE_FORMAT_A8L8: - str = "A8L8"; - break; - case SURFACE_FORMAT_A32B32G32R32F: - str = "A32B32G32R32F"; - break; - case SURFACE_FORMAT_A16B16G16R16F: - str = "A16B16G16R16F"; - break; - case SURFACE_FORMAT_A16B16G16R16: - str = "A16B16G16R16"; - break; - case SURFACE_FORMAT_A8B8G8R8: - str = "A8B8G8R8"; - break; - case SURFACE_FORMAT_X8B8G8R8: - str = "X8B8G8R8"; - break; - case SURFACE_FORMAT_A8R8G8B8: - str = "A8R8G8B8"; - break; - case SURFACE_FORMAT_X8R8G8B8: - str = "X8R8G8B8"; - break; - case SURFACE_FORMAT_NV12: - str = "NV12"; - break; - case SURFACE_FORMAT_YV12: - str = "YV12"; - break; - default: - log_error("SurfaceFormatToString(): unknown surface format!\n"); - str = "unknown"; - break; - } -} - -bool MediaSurfaceCreate(cl_dx9_media_adapter_type_khr adapterType, unsigned int width, unsigned int height, TSurfaceFormat surfaceFormat, - CDeviceWrapper &device, std::auto_ptr &surface, bool sharedHandle, void **objectSharedHandle) -{ - switch (adapterType) - { -#if defined(_WIN32) - case CL_ADAPTER_D3D9_KHR: - { - surface = std::auto_ptr(new CD3D9SurfaceWrapper); - CD3D9SurfaceWrapper *d3dSurface = static_cast(surface.get()); - HRESULT hr = 0; - D3DFORMAT d3dFormat = SurfaceFormatToD3D(surfaceFormat); - LPDIRECT3DDEVICE9 d3d9Device = (LPDIRECT3DDEVICE9)device.Device(); - hr = d3d9Device->CreateOffscreenPlainSurface(width, height, d3dFormat, D3DPOOL_DEFAULT, &(*d3dSurface), - sharedHandle ? objectSharedHandle: 0); - - if ( FAILED(hr)) - { - log_error("CreateOffscreenPlainSurface failed\n"); - return false; - } - } - break; - case CL_ADAPTER_D3D9EX_KHR: - { - surface = std::auto_ptr(new CD3D9SurfaceWrapper); - CD3D9SurfaceWrapper *d3dSurface = static_cast(surface.get()); - HRESULT hr = 0; - D3DFORMAT d3dFormat = SurfaceFormatToD3D(surfaceFormat); - LPDIRECT3DDEVICE9EX d3d9ExDevice = (LPDIRECT3DDEVICE9EX)device.Device(); - hr = d3d9ExDevice->CreateOffscreenPlainSurface(width, height, d3dFormat, D3DPOOL_DEFAULT, &(*d3dSurface), - sharedHandle ? objectSharedHandle: 0); - - if ( FAILED(hr)) - { - log_error("CreateOffscreenPlainSurface failed\n"); - return false; - } - } - break; - case CL_ADAPTER_DXVA_KHR: - { - surface = std::auto_ptr(new CD3D9SurfaceWrapper); - CD3D9SurfaceWrapper *d3dSurface = static_cast(surface.get()); - HRESULT hr = 0; - D3DFORMAT d3dFormat = SurfaceFormatToD3D(surfaceFormat); - IDXVAHD_Device *dxvaDevice = (IDXVAHD_Device *)device.Device(); - hr = dxvaDevice->CreateVideoSurface(width, height, d3dFormat, D3DPOOL_DEFAULT, 0, - DXVAHD_SURFACE_TYPE_VIDEO_INPUT, 1, &(*d3dSurface), sharedHandle ? objectSharedHandle: 0); - - if ( FAILED(hr)) - { - log_error("CreateVideoSurface failed\n"); - return false; - } - } - break; -#endif - default: - log_error("MediaSurfaceCreate(): Unknown adapter type!\n"); - return false; - break; - } - - return true; -} - -cl_int deviceExistForCLTest(cl_platform_id platform, - cl_dx9_media_adapter_type_khr media_adapters_type, - void *media_adapters, - CResult &result, - TSharedHandleType sharedHandle /*default SHARED_HANDLE_ENABLED*/ - ) -{ - cl_int _error; - cl_uint devicesAllNum = 0; - std::string sharedHandleStr = (sharedHandle == SHARED_HANDLE_ENABLED)? "yes": "no"; - std::string adapterStr; - AdapterToString(media_adapters_type, adapterStr); - - _error = clGetDeviceIDsFromDX9MediaAdapterKHR(platform, 1, - &media_adapters_type, &media_adapters, CL_PREFERRED_DEVICES_FOR_DX9_MEDIA_ADAPTER_KHR, 0, 0, &devicesAllNum); - - if (_error != CL_SUCCESS) - { - if(_error != CL_DEVICE_NOT_FOUND) - { - log_error("clGetDeviceIDsFromDX9MediaAdapterKHR failed: %s\n", IGetErrorString(_error)); - result.ResultSub(CResult::TEST_ERROR); - } - else - { - log_info("Skipping test case, device type is not supported by a device (adapter type: %s, shared handle: %s)\n", adapterStr.c_str(), sharedHandleStr.c_str()); - result.ResultSub(CResult::TEST_NOTSUPPORTED); - } - } - - return _error; -} diff --git a/test_extensions/media_sharing/utils.h b/test_extensions/media_sharing/utils.h deleted file mode 100644 index f98090ca..00000000 --- a/test_extensions/media_sharing/utils.h +++ /dev/null @@ -1,167 +0,0 @@ -// -// 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. -// -#ifndef __UTILS_KHR_MEDIA_H -#define __UTILS_KHR_MEDIA_H - -#include -#include -#include -#include -#include "wrappers.h" -#include "CL/cl_dx9_media_sharing.h" - -#include "harness/typeWrappers.h" - - - - - -extern clGetDeviceIDsFromDX9MediaAdapterKHR_fn clGetDeviceIDsFromDX9MediaAdapterKHR; -extern clCreateFromDX9MediaSurfaceKHR_fn clCreateFromDX9MediaSurfaceKHR; -extern clEnqueueAcquireDX9MediaSurfacesKHR_fn clEnqueueAcquireDX9MediaSurfacesKHR; -extern clEnqueueReleaseDX9MediaSurfacesKHR_fn clEnqueueReleaseDX9MediaSurfacesKHR; - -extern cl_platform_id gPlatformIDdetected; -extern cl_device_id gDeviceIDdetected; -extern cl_device_type gDeviceTypeSelected; - -#define NL "\n" -#define TEST_NOT_IMPLEMENTED -1 -#define TEST_NOT_SUPPORTED -2 - -enum TSurfaceFormat -{ - SURFACE_FORMAT_NV12, - SURFACE_FORMAT_YV12, - SURFACE_FORMAT_R32F, - SURFACE_FORMAT_R16F, - SURFACE_FORMAT_L16, - SURFACE_FORMAT_A8, - SURFACE_FORMAT_L8, - SURFACE_FORMAT_G32R32F, - SURFACE_FORMAT_G16R16F, - SURFACE_FORMAT_G16R16, - SURFACE_FORMAT_A8L8, - SURFACE_FORMAT_A32B32G32R32F, - SURFACE_FORMAT_A16B16G16R16F, - SURFACE_FORMAT_A16B16G16R16, - SURFACE_FORMAT_A8B8G8R8, - SURFACE_FORMAT_X8B8G8R8, - SURFACE_FORMAT_A8R8G8B8, - SURFACE_FORMAT_X8R8G8B8, -}; - -enum TContextFuncType -{ - CONTEXT_CREATE_DEFAULT, - CONTEXT_CREATE_FROM_TYPE, -}; - -enum TSharedHandleType -{ - SHARED_HANDLE_ENABLED, - SHARED_HANDLE_DISABLED, -}; - -class CResult { -public: - enum TTestResult { - TEST_NORESULT, - TEST_NOTSUPPORTED, - TEST_PASS, - TEST_FAIL, - TEST_ERROR, - }; - - CResult(); - ~CResult(); - - void ResultSub(TTestResult result); - TTestResult ResultLast() const; - int Result() const; - -private: - TTestResult _result; - TTestResult _resultLast; -}; - -void FunctionContextCreateToString(TContextFuncType contextCreateFunction, std::string &contextFunction); -void AdapterToString(cl_dx9_media_adapter_type_khr adapterType, std::string &adapter); -cl_context_info AdapterTypeToContextInfo(cl_dx9_media_adapter_type_khr adapterType); - -//YUV utils -void YUVGenerateNV12(std::vector &yuv, unsigned int width, unsigned int height, - cl_uchar valueMin, cl_uchar valueMax, double valueAdd = 0.0); -void YUVGenerateYV12(std::vector &yuv, unsigned int width, unsigned int height, - cl_uchar valueMin, cl_uchar valueMax, double valueAdd = 0.0); -bool YUVGenerate(TSurfaceFormat surfaceFormat, std::vector &yuv, unsigned int width, unsigned int height, - cl_uchar valueMin, cl_uchar valueMax, double valueAdd = 0.0); -bool YUVSurfaceSetNV12(std::auto_ptr &surface, const std::vector &yuv, - unsigned int width, unsigned int height); -bool YUVSurfaceSetYV12(std::auto_ptr &surface, const std::vector &yuv, - unsigned int width, unsigned int height); -bool YUVSurfaceSet(TSurfaceFormat surfaceFormat, std::auto_ptr &surface, const std::vector &yuv, - unsigned int width, unsigned int height); -bool YUVSurfaceGetNV12(std::auto_ptr &surface, std::vector &yuv, - unsigned int width, unsigned int height); -bool YUVSurfaceGetYV12(std::auto_ptr &surface, std::vector &yuv, - unsigned int width, unsigned int height); -bool YUVSurfaceGet(TSurfaceFormat surfaceFormat, std::auto_ptr &surface, std::vector &yuv, - unsigned int width, unsigned int height); -bool YUVCompareNV12(const std::vector &yuvTest, const std::vector &yuvRef, - unsigned int width, unsigned int height); -bool YUVCompareYV12(const std::vector &yuvTest, const std::vector &yuvRef, - unsigned int width, unsigned int height); -bool YUVCompare(TSurfaceFormat surfaceFormat, const std::vector &yuvTest, const std::vector &yuvRef, - unsigned int width, unsigned int height); - -//other types utils -void DataGenerate(TSurfaceFormat surfaceFormat, cl_channel_type type, std::vector &data, unsigned int width, unsigned int height, - unsigned int channelNum, float cmin = 0.0f, float cmax = 1.0f, float add = 0.0f); -void DataGenerate(TSurfaceFormat surfaceFormat, cl_channel_type type, std::vector &data, unsigned int width, unsigned int height, - unsigned int channelNum, float cmin = 0.0f, float cmax = 1.0f, float add = 0.0f); -void DataGenerate(TSurfaceFormat surfaceFormat, cl_channel_type type, std::vector &data, unsigned int width, unsigned int height, - unsigned int channelNum, float cmin = 0.0f, float cmax = 1.0f, float add = 0.0f); -bool DataCompare(TSurfaceFormat surfaceFormat, cl_channel_type type, const std::vector &dataTest, const std::vector &dataExp, - unsigned int width, unsigned int height, unsigned int channelNum); -bool DataCompare(TSurfaceFormat surfaceFormat, cl_channel_type type, const std::vector &dataTest, const std::vector &dataExp, - unsigned int width, unsigned int height, unsigned int channelNum); -bool DataCompare(TSurfaceFormat surfaceFormat, cl_channel_type type, const std::vector &dataTest, const std::vector &dataExp, - unsigned int width, unsigned int height, unsigned int channelNum); - -bool GetImageInfo(cl_mem object, cl_image_format formatExp, size_t elementSizeExp, - size_t rowPitchExp, size_t slicePitchExp, size_t widthExp, - size_t heightExp, size_t depthExp, unsigned int planeExp); -bool GetMemObjInfo(cl_mem object, cl_dx9_media_adapter_type_khr adapterType, std::auto_ptr &surface, void *shareHandleExp); -bool ImageInfoVerify(cl_dx9_media_adapter_type_khr adapterType, const std::vector &memObjList, unsigned int width, unsigned int height, - std::auto_ptr &surface, void *sharedHandle); -bool ImageFormatCheck(cl_context context, cl_mem_object_type imageType, const cl_image_format imageFormatCheck); -unsigned int ChannelNum(TSurfaceFormat surfaceFormat); -unsigned int PlanesNum(TSurfaceFormat surfaceFormat); - -#if defined(_WIN32) -D3DFORMAT SurfaceFormatToD3D(TSurfaceFormat surfaceFormat); -#endif - -bool DeviceCreate(cl_dx9_media_adapter_type_khr adapterType, std::auto_ptr &device); -bool SurfaceFormatCheck(cl_dx9_media_adapter_type_khr adapterType, const CDeviceWrapper &device, TSurfaceFormat surfaceFormat); -bool SurfaceFormatToOCL(TSurfaceFormat surfaceFormat, cl_image_format &format); -void SurfaceFormatToString(TSurfaceFormat surfaceFormat, std::string &str ); -bool MediaSurfaceCreate(cl_dx9_media_adapter_type_khr adapterType, unsigned int width, unsigned int height, TSurfaceFormat surfaceFormat, - CDeviceWrapper &device, std::auto_ptr &surface, bool sharedHandle, void **objectSharedHandle); - -cl_int deviceExistForCLTest(cl_platform_id platform,cl_dx9_media_adapter_type_khr media_adapters_type,void *media_adapters,CResult &result,TSharedHandleType sharedHandle=SHARED_HANDLE_DISABLED); -#endif // __UTILS_KHR_MEDIA_H diff --git a/test_extensions/media_sharing/wrappers.cpp b/test_extensions/media_sharing/wrappers.cpp deleted file mode 100644 index e7eb5b2b..00000000 --- a/test_extensions/media_sharing/wrappers.cpp +++ /dev/null @@ -1,562 +0,0 @@ -// -// 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 "wrappers.h" -#include "harness/errorHelpers.h" - -LPCTSTR CDeviceWrapper::WINDOW_TITLE = _T( "cl_khr_dx9_media_sharing" ); -const int CDeviceWrapper::WINDOW_WIDTH = 256; -const int CDeviceWrapper::WINDOW_HEIGHT = 256; -CDeviceWrapper::TAccelerationType CDeviceWrapper::accelerationType = CDeviceWrapper::ACCELERATION_HW; - -#if defined(_WIN32) -const D3DFORMAT CDXVAWrapper::RENDER_TARGET_FORMAT = D3DFMT_X8R8G8B8; -const D3DFORMAT CDXVAWrapper::VIDEO_FORMAT = D3DFMT_X8R8G8B8; -const unsigned int CDXVAWrapper::VIDEO_FPS = 60; -#endif - -#if defined(_WIN32) -static LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) -{ - switch(msg) - { - case WM_DESTROY: - PostQuitMessage(0); - return 0; - case WM_PAINT: - ValidateRect(hWnd, 0); - return 0; - default: - break; - } - - return DefWindowProc(hWnd, msg, wParam, lParam); -} -#endif - -CDeviceWrapper::CDeviceWrapper() -#if defined(_WIN32) -:_hInstance(NULL),_hWnd(NULL) -#endif -{ - -} - -void CDeviceWrapper::WindowInit() -{ -#if defined(_WIN32) - _hInstance = GetModuleHandle(NULL); - static WNDCLASSEX wc = - { - sizeof(WNDCLASSEX), - CS_CLASSDC, - WndProc, - 0L, - 0L, - _hInstance, - NULL, - NULL, - NULL, - NULL, - WINDOW_TITLE, - NULL - }; - - RegisterClassEx(&wc); - - _hWnd = CreateWindow( - WINDOW_TITLE, - WINDOW_TITLE, - WS_OVERLAPPEDWINDOW, - 0, 0, - WINDOW_WIDTH, WINDOW_HEIGHT, - NULL, - NULL, - wc.hInstance, - NULL); - - if (!_hWnd) - { - log_error("Failed to create window"); - return; - } - - ShowWindow(_hWnd,SW_SHOWDEFAULT); - UpdateWindow(_hWnd); -#endif -} - -void CDeviceWrapper::WindowDestroy() -{ -#if defined(_WIN32) - if (_hWnd) - DestroyWindow(_hWnd); - _hWnd = NULL; -#endif -} - -#if defined(_WIN32) -HWND CDeviceWrapper::WindowHandle() const -{ - return _hWnd; -} -#endif - -int CDeviceWrapper::WindowWidth() const -{ - return WINDOW_WIDTH; -} - -int CDeviceWrapper::WindowHeight() const -{ - return WINDOW_HEIGHT; -} - -CDeviceWrapper::TAccelerationType CDeviceWrapper::AccelerationType() -{ - return accelerationType; -} - -void CDeviceWrapper::AccelerationType( TAccelerationType accelerationTypeNew ) -{ - accelerationType = accelerationTypeNew; -} - -CDeviceWrapper::~CDeviceWrapper() -{ - WindowDestroy(); -} - -#if defined(_WIN32) -CD3D9Wrapper::CD3D9Wrapper(): -_d3d9(NULL), _d3dDevice(NULL), _status(DEVICE_PASS), _adapterIdx(0), _adapterFound(false) -{ - WindowInit(); - - _d3d9 = Direct3DCreate9(D3D_SDK_VERSION); - if (!_d3d9) - { - log_error("Direct3DCreate9 failed\n"); - _status = DEVICE_FAIL; - } -} - -CD3D9Wrapper::~CD3D9Wrapper() -{ - Destroy(); - - if(_d3d9) - _d3d9->Release(); - _d3d9 = 0; -} - -void CD3D9Wrapper::Destroy() -{ - if (_d3dDevice) - _d3dDevice->Release(); - _d3dDevice = 0; -} - -cl_int CD3D9Wrapper::Init() -{ - if (!WindowHandle()) - { - log_error("D3D9: Window is not created\n"); - _status = DEVICE_FAIL; - return DEVICE_FAIL; - } - - if(!_d3d9 || DEVICE_PASS != _status || !_adapterFound) - return false; - - _d3d9->GetAdapterDisplayMode(_adapterIdx - 1, &_d3ddm); - - D3DPRESENT_PARAMETERS d3dParams; - ZeroMemory(&d3dParams, sizeof(d3dParams)); - - d3dParams.Windowed = TRUE; - d3dParams.BackBufferCount = 1; - d3dParams.SwapEffect = D3DSWAPEFFECT_DISCARD; - d3dParams.hDeviceWindow = WindowHandle(); - d3dParams.BackBufferWidth = WindowWidth(); - d3dParams.BackBufferHeight = WindowHeight(); - d3dParams.BackBufferFormat = _d3ddm.Format; - - DWORD processingType = (AccelerationType() == ACCELERATION_HW)? D3DCREATE_HARDWARE_VERTEXPROCESSING: - D3DCREATE_SOFTWARE_VERTEXPROCESSING; - - if ( FAILED( _d3d9->CreateDevice( _adapterIdx - 1, D3DDEVTYPE_HAL, WindowHandle(), - processingType, &d3dParams, &_d3dDevice) ) ) - { - log_error("CreateDevice failed\n"); - _status = DEVICE_FAIL; - return DEVICE_FAIL; - } - - _d3dDevice->BeginScene(); - _d3dDevice->Clear(0, NULL, D3DCLEAR_TARGET, 0, 1.0f, 0); - _d3dDevice->EndScene(); - - return true; -} - -void * CD3D9Wrapper::D3D() const -{ - return _d3d9; -} - -void *CD3D9Wrapper::Device() const -{ - return _d3dDevice; -} - -D3DFORMAT CD3D9Wrapper::Format() -{ - return _d3ddm.Format; -} - -D3DADAPTER_IDENTIFIER9 CD3D9Wrapper::Adapter() -{ - return _adapter; -} - -TDeviceStatus CD3D9Wrapper::Status() const -{ - return _status; -} - -bool CD3D9Wrapper::AdapterNext() -{ - if (DEVICE_PASS != _status) - return false; - - _adapterFound = false; - for(; _adapterIdx < _d3d9->GetAdapterCount();) - { - ++_adapterIdx; - D3DCAPS9 caps; - if (FAILED(_d3d9->GetDeviceCaps(_adapterIdx - 1, D3DDEVTYPE_HAL, &caps))) - continue; - - if(FAILED(_d3d9->GetAdapterIdentifier(_adapterIdx - 1, 0, &_adapter))) - { - log_error("D3D9: GetAdapterIdentifier failed\n"); - _status = DEVICE_FAIL; - return false; - } - - _adapterFound = true; - - Destroy(); - if(!Init()) - { - _status = DEVICE_FAIL; - _adapterFound = false; - } - break; - } - - return _adapterFound; -} - -unsigned int CD3D9Wrapper::AdapterIdx() const -{ - return _adapterIdx - 1; -} - - -CD3D9ExWrapper::CD3D9ExWrapper(): -_d3d9Ex(NULL), _d3dDeviceEx(NULL), _status(DEVICE_PASS), _adapterIdx(0), _adapterFound(false) -{ - WindowInit(); - - HRESULT result = Direct3DCreate9Ex(D3D_SDK_VERSION, &_d3d9Ex); - if (FAILED(result) || !_d3d9Ex) - { - log_error("Direct3DCreate9Ex failed\n"); - _status = DEVICE_FAIL; - } -} - -CD3D9ExWrapper::~CD3D9ExWrapper() -{ - Destroy(); - - if(_d3d9Ex) - _d3d9Ex->Release(); - _d3d9Ex = 0; -} - -void * CD3D9ExWrapper::D3D() const -{ - return _d3d9Ex; -} - -void *CD3D9ExWrapper::Device() const -{ - return _d3dDeviceEx; -} - -D3DFORMAT CD3D9ExWrapper::Format() -{ - return _d3ddmEx.Format; -} - -D3DADAPTER_IDENTIFIER9 CD3D9ExWrapper::Adapter() -{ - return _adapter; -} - -cl_int CD3D9ExWrapper::Init() -{ - if (!WindowHandle()) - { - log_error("D3D9EX: Window is not created\n"); - _status = DEVICE_FAIL; - return DEVICE_FAIL; - } - - if(!_d3d9Ex || DEVICE_FAIL == _status || !_adapterFound) - return DEVICE_FAIL; - - RECT rect; - GetClientRect(WindowHandle(),&rect); - - D3DPRESENT_PARAMETERS d3dParams; - ZeroMemory(&d3dParams, sizeof(d3dParams)); - - d3dParams.Windowed = TRUE; - d3dParams.SwapEffect = D3DSWAPEFFECT_FLIP; - d3dParams.BackBufferFormat = D3DFMT_X8R8G8B8; - d3dParams.BackBufferWidth = WindowWidth(); - d3dParams.BackBufferHeight = WindowHeight(); - - d3dParams.BackBufferCount = 1; - d3dParams.hDeviceWindow = WindowHandle(); - - DWORD processingType = (AccelerationType() == ACCELERATION_HW)? D3DCREATE_HARDWARE_VERTEXPROCESSING: - D3DCREATE_SOFTWARE_VERTEXPROCESSING; - - if ( FAILED( _d3d9Ex->CreateDeviceEx( _adapterIdx - 1, D3DDEVTYPE_HAL, WindowHandle(), - processingType, &d3dParams, NULL, &_d3dDeviceEx) ) ) - { - log_error("CreateDeviceEx failed\n"); - _status = DEVICE_FAIL; - return DEVICE_FAIL; - } - - _d3dDeviceEx->BeginScene(); - _d3dDeviceEx->Clear(0, NULL, D3DCLEAR_TARGET, 0, 1.0f, 0); - _d3dDeviceEx->EndScene(); - - return DEVICE_PASS; -} - -void CD3D9ExWrapper::Destroy() -{ - if (_d3dDeviceEx) - _d3dDeviceEx->Release(); - _d3dDeviceEx = 0; -} - -TDeviceStatus CD3D9ExWrapper::Status() const -{ - return _status; -} - -bool CD3D9ExWrapper::AdapterNext() -{ - if (DEVICE_FAIL == _status) - return false; - - _adapterFound = false; - for(; _adapterIdx < _d3d9Ex->GetAdapterCount();) - { - ++_adapterIdx; - D3DCAPS9 caps; - if (FAILED(_d3d9Ex->GetDeviceCaps(_adapterIdx - 1, D3DDEVTYPE_HAL, &caps))) - continue; - - if(FAILED(_d3d9Ex->GetAdapterIdentifier(_adapterIdx - 1, 0, &_adapter))) - { - log_error("D3D9EX: GetAdapterIdentifier failed\n"); - _status = DEVICE_FAIL; - return false; - } - - _adapterFound = true; - Destroy(); - if(!Init()) - { - _status = DEVICE_FAIL; - _adapterFound = _status; - } - - break; - } - - return _adapterFound; -} - -unsigned int CD3D9ExWrapper::AdapterIdx() const -{ - return _adapterIdx - 1; -} - -CDXVAWrapper::CDXVAWrapper(): -_dxvaDevice(NULL), _status(DEVICE_PASS), _adapterFound(false) -{ - _status = _d3d9.Status(); -} - -CDXVAWrapper::~CDXVAWrapper() -{ - DXVAHDDestroy(); -} - -void * CDXVAWrapper::Device() const -{ - return _dxvaDevice; -} - -TDeviceStatus CDXVAWrapper::Status() const -{ - if(_status == DEVICE_FAIL || _d3d9.Status() == DEVICE_FAIL) - return DEVICE_FAIL; - else if(_status == DEVICE_NOTSUPPORTED || _d3d9.Status() == DEVICE_NOTSUPPORTED) - return DEVICE_NOTSUPPORTED; - else - return DEVICE_PASS; -} - -bool CDXVAWrapper::AdapterNext() -{ - if (DEVICE_PASS != _status) - return false; - - _adapterFound = _d3d9.AdapterNext(); - _status = _d3d9.Status(); - if (DEVICE_PASS != _status) - { - _adapterFound = false; - return false; - } - - if (!_adapterFound) - return false; - - DXVAHDDestroy(); - _status = DXVAHDInit(); - if (DEVICE_PASS != _status) - { - _adapterFound = false; - return false; - } - - return true; -} - -TDeviceStatus CDXVAWrapper::DXVAHDInit() -{ - if ((_status == DEVICE_FAIL) || (_d3d9.Status() == DEVICE_FAIL) || !_adapterFound) - return DEVICE_FAIL; - - DXVAHD_RATIONAL fps = { VIDEO_FPS, 1 }; - - DXVAHD_CONTENT_DESC desc; - desc.InputFrameFormat= DXVAHD_FRAME_FORMAT_PROGRESSIVE; - desc.InputFrameRate = fps; - desc.InputWidth = WindowWidth(); - desc.InputHeight = WindowHeight(); - desc.OutputFrameRate = fps; - desc.OutputWidth = WindowWidth(); - desc.OutputHeight = WindowHeight(); - -#ifdef USE_SOFTWARE_PLUGIN - _status = DEVICE_FAIL; - return DEVICE_FAIL; -#endif - - HRESULT hr = DXVAHD_CreateDevice(static_cast(_d3d9.Device()), - &desc, DXVAHD_DEVICE_USAGE_PLAYBACK_NORMAL, NULL, &_dxvaDevice); - if(FAILED(hr)) - { - if (hr == E_NOINTERFACE) - { - log_error("DXVAHD_CreateDevice skipped due to no supported devices!\n"); - _status = DEVICE_NOTSUPPORTED; - } - else - { - log_error("DXVAHD_CreateDevice failed\n"); - _status = DEVICE_FAIL; - } - } - - return _status; -} - -void CDXVAWrapper::DXVAHDDestroy() -{ - if (_dxvaDevice) - _dxvaDevice->Release(); - _dxvaDevice = 0; -} - -void * CDXVAWrapper::D3D() const -{ - return _d3d9.D3D(); -} - -unsigned int CDXVAWrapper::AdapterIdx() const -{ - return _d3d9.AdapterIdx(); -} - -const CD3D9ExWrapper & CDXVAWrapper::D3D9() const -{ - return _d3d9; -} - -CD3D9SurfaceWrapper::CD3D9SurfaceWrapper(): -mMem(NULL) -{ - -} - -CD3D9SurfaceWrapper::CD3D9SurfaceWrapper( IDirect3DSurface9* mem ): -mMem(mem) -{ - -} - -CD3D9SurfaceWrapper::~CD3D9SurfaceWrapper() -{ - if(mMem != NULL) - mMem->Release(); - mMem = NULL; -} - -#endif - -CSurfaceWrapper::CSurfaceWrapper() -{ - -} - -CSurfaceWrapper::~CSurfaceWrapper() -{ - -} diff --git a/test_extensions/media_sharing/wrappers.h b/test_extensions/media_sharing/wrappers.h deleted file mode 100644 index 45b70326..00000000 --- a/test_extensions/media_sharing/wrappers.h +++ /dev/null @@ -1,197 +0,0 @@ -// -// 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. -// -#ifndef __WRAPPERS_H -#define __WRAPPERS_H - -#if defined(_WIN32) -#include -#if defined (__MINGW32__) -#include -typedef unsigned char UINT8; -#define __out -#define __in -#define __inout -#define __out_bcount(size) -#define __out_bcount_opt(size) -#define __in_opt -#define __in_ecount(size) -#define __in_ecount_opt(size) -#define __out_opt -#define __out_ecount(size) -#define __out_ecount_opt(size) -#define __in_bcount_opt(size) -#define __inout_opt -#define __inout_bcount(size) -#define __in_bcount(size) -#define __deref_out -#endif -#include -#include -#endif - -enum TDeviceStatus -{ - DEVICE_NOTSUPPORTED, - DEVICE_PASS, - DEVICE_FAIL, -}; - -class CDeviceWrapper { -public: - enum TAccelerationType - { - ACCELERATION_HW, - ACCELERATION_SW, - }; - - CDeviceWrapper(); - virtual ~CDeviceWrapper(); - - virtual bool AdapterNext() = 0; - virtual unsigned int AdapterIdx() const = 0; - virtual void *Device() const = 0; - virtual TDeviceStatus Status() const = 0; - virtual void *D3D() const = 0; - -#if defined(_WIN32) - HWND WindowHandle() const; -#endif - int WindowWidth() const; - int WindowHeight() const; - void WindowInit(); - - - static TAccelerationType AccelerationType(); - static void AccelerationType(TAccelerationType accelerationTypeNew); - -private: - static LPCTSTR WINDOW_TITLE; - static const int WINDOW_WIDTH; - static const int WINDOW_HEIGHT; - static TAccelerationType accelerationType; - -#if defined(_WIN32) - HMODULE _hInstance; - HWND _hWnd; -#endif - - void WindowDestroy(); -}; - -class CSurfaceWrapper -{ -public: - CSurfaceWrapper(); - virtual ~CSurfaceWrapper(); -}; - -#if defined(_WIN32) -//windows specific wrappers -class CD3D9Wrapper: public CDeviceWrapper { -public: - CD3D9Wrapper(); - ~CD3D9Wrapper(); - - virtual bool AdapterNext(); - virtual unsigned int AdapterIdx() const; - virtual void *Device() const; - virtual TDeviceStatus Status() const; - virtual void *D3D() const; - -private: - LPDIRECT3D9 _d3d9; - LPDIRECT3DDEVICE9 _d3dDevice; - D3DDISPLAYMODE _d3ddm; - D3DADAPTER_IDENTIFIER9 _adapter; - TDeviceStatus _status; - unsigned int _adapterIdx; - bool _adapterFound; - - D3DFORMAT Format(); - D3DADAPTER_IDENTIFIER9 Adapter(); - int Init(); - void Destroy(); -}; - -class CD3D9ExWrapper: public CDeviceWrapper { -public: - CD3D9ExWrapper(); - ~CD3D9ExWrapper(); - - virtual bool AdapterNext(); - virtual unsigned int AdapterIdx() const; - virtual void *Device() const; - virtual TDeviceStatus Status() const; - virtual void *D3D() const; - -private: - LPDIRECT3D9EX _d3d9Ex; - LPDIRECT3DDEVICE9EX _d3dDeviceEx; - D3DDISPLAYMODEEX _d3ddmEx; - D3DADAPTER_IDENTIFIER9 _adapter; - TDeviceStatus _status; - unsigned int _adapterIdx; - bool _adapterFound; - - D3DFORMAT Format(); - D3DADAPTER_IDENTIFIER9 Adapter(); - int Init(); - void Destroy(); -}; - -class CDXVAWrapper: public CDeviceWrapper { -public: - CDXVAWrapper(); - ~CDXVAWrapper(); - - virtual bool AdapterNext(); - virtual unsigned int AdapterIdx() const; - virtual void *Device() const; - virtual TDeviceStatus Status() const; - virtual void *D3D() const; - const CD3D9ExWrapper &D3D9() const; - -private: - CD3D9ExWrapper _d3d9; - IDXVAHD_Device *_dxvaDevice; - TDeviceStatus _status; - bool _adapterFound; - - static const D3DFORMAT RENDER_TARGET_FORMAT; - static const D3DFORMAT VIDEO_FORMAT; - static const unsigned int VIDEO_FPS; - - TDeviceStatus DXVAHDInit(); - void DXVAHDDestroy(); -}; - -class CD3D9SurfaceWrapper: public CSurfaceWrapper -{ -public: - CD3D9SurfaceWrapper(); - CD3D9SurfaceWrapper( IDirect3DSurface9* mem ); - ~CD3D9SurfaceWrapper(); - - operator IDirect3DSurface9*() { return mMem; } - IDirect3DSurface9* * operator&() { return &mMem; } - IDirect3DSurface9* operator->() const { return mMem; } - -private: - IDirect3DSurface9* mMem; -}; -#endif - -#endif // __D3D_WRAPPERS