mirror of
https://github.com/KhronosGroup/OpenCL-CTS.git
synced 2026-03-19 06:09:01 +00:00
Move media_sharing tests to test_conformance/extensions/ (#1164)
* Move media_sharing tests to test_conformance/extensions/ And rename to cl_khr_dx9_media_sharing. Signed-off-by: Kevin Petit <kevin.petit@arm.com> * format code * more format changes
This commit is contained in:
@@ -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")
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
add_subdirectory( cl_ext_cxx_for_opencl )
|
||||
add_subdirectory( cl_khr_dx9_media_sharing )
|
||||
|
||||
@@ -21,5 +21,5 @@ set_source_files_properties(
|
||||
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
include(../../test_conformance/CMakeCommon.txt)
|
||||
include(../../CMakeCommon.txt)
|
||||
endif(WIN32)
|
||||
231
test_conformance/extensions/cl_khr_dx9_media_sharing/main.cpp
Normal file
231
test_conformance/extensions/cl_khr_dx9_media_sharing/main.cpp
Normal file
@@ -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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#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<cl_platform_id> 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<cl_device_id> 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);
|
||||
}
|
||||
@@ -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__
|
||||
#endif // #ifndef __MEDIA_SHARING_PROCS_H__
|
||||
@@ -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<CDeviceWrapper> deviceWrapper;
|
||||
if (!DeviceCreate(adapterType, deviceWrapper))
|
||||
{
|
||||
result.ResultSub(CResult::TEST_ERROR);
|
||||
return result.Result();
|
||||
}
|
||||
|
||||
// generate input data
|
||||
std::vector<cl_uchar> 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<CSurfaceWrapper> 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<CD3D9SurfaceWrapper *>(surface.get()));
|
||||
surfaceInfo.shared_handle = objectSharedHandle;
|
||||
#else
|
||||
void *surfaceInfo = 0;
|
||||
return TEST_NOT_IMPLEMENTED;
|
||||
#endif
|
||||
|
||||
std::vector<cl_mem> memObjList;
|
||||
unsigned int planesNum = PlanesNum(surfaceFormat);
|
||||
std::vector<clMemWrapper> 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<cl_uint>(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<cl_uchar> 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<cl_uint>(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<cl_uchar> 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<cl_dx9_media_adapter_type_khr> 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<TContextFuncType> contextFuncs;
|
||||
contextFuncs.push_back(CONTEXT_CREATE_DEFAULT);
|
||||
contextFuncs.push_back(CONTEXT_CREATE_FROM_TYPE);
|
||||
|
||||
std::vector<TSurfaceFormat> formats;
|
||||
formats.push_back(SURFACE_FORMAT_NV12);
|
||||
formats.push_back(SURFACE_FORMAT_YV12);
|
||||
|
||||
std::vector<TSharedHandleType> 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();
|
||||
}
|
||||
@@ -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<CDeviceWrapper> deviceWrapper;
|
||||
if (!DeviceCreate(adapterType, deviceWrapper))
|
||||
{
|
||||
result.ResultSub(CResult::TEST_ERROR);
|
||||
return result.Result();
|
||||
}
|
||||
|
||||
// generate input and expected data
|
||||
std::vector<std::vector<cl_uchar>> bufferRef1(FRAME_NUM);
|
||||
std::vector<std::vector<cl_uchar>> bufferRef2(FRAME_NUM);
|
||||
std::vector<std::vector<cl_uchar>> 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<cl_uchar>(step * i),
|
||||
static_cast<cl_uchar>(step * (i + 1)))
|
||||
|| !YUVGenerate(surfaceFormat, bufferRef2[i], width, height,
|
||||
static_cast<cl_uchar>(step * i),
|
||||
static_cast<cl_uchar>(step * (i + 1)), 0.2)
|
||||
|| !YUVGenerate(surfaceFormat, bufferRef3[i], width, height,
|
||||
static_cast<cl_uchar>(step * i),
|
||||
static_cast<cl_uchar>(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<CSurfaceWrapper> 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<CD3D9SurfaceWrapper *>(surface.get()));
|
||||
surfaceInfo.shared_handle = objectSharedHandle;
|
||||
#else
|
||||
void *surfaceInfo = 0;
|
||||
return TEST_NOT_IMPLEMENTED;
|
||||
#endif
|
||||
|
||||
std::vector<cl_mem> memObjList;
|
||||
unsigned int planesNum = PlanesNum(surfaceFormat);
|
||||
std::vector<clMemWrapper> 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<cl_uint>(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<cl_uchar> 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<cl_uchar> 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<cl_uchar> 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<cl_uchar> 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<cl_uchar> 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<cl_uchar> 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<cl_uchar> 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<cl_uchar *>(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<cl_uchar *>(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<cl_uint>(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<cl_uchar> 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();
|
||||
}
|
||||
@@ -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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#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<CDeviceWrapper> deviceWrapper;
|
||||
if (!DeviceCreate(adapterType, deviceWrapper))
|
||||
{
|
||||
result.ResultSub(CResult::TEST_ERROR);
|
||||
return result.Result();
|
||||
}
|
||||
|
||||
std::vector<std::vector<cl_uchar>> bufferIn(FRAME_NUM);
|
||||
std::vector<std::vector<cl_uchar>> 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<cl_uchar>(step * i),
|
||||
static_cast<cl_uchar>(step * (i + 1)))
|
||||
|| !YUVGenerate(surfaceFormat, bufferExp[i], width, height,
|
||||
static_cast<cl_uchar>(step * i),
|
||||
static_cast<cl_uchar>(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<CSurfaceWrapper> 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<CSurfaceWrapper> 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<CD3D9SurfaceWrapper *>(surfaceSrc.get()));
|
||||
surfaceInfoSrc.shared_handle = objectSrcHandle;
|
||||
|
||||
cl_dx9_surface_info_khr surfaceInfoDst;
|
||||
surfaceInfoDst.resource =
|
||||
*(static_cast<CD3D9SurfaceWrapper *>(surfaceDst.get()));
|
||||
surfaceInfoDst.shared_handle = objectDstHandle;
|
||||
#else
|
||||
void *surfaceInfoSrc = 0;
|
||||
void *surfaceInfoDst = 0;
|
||||
return TEST_NOT_IMPLEMENTED;
|
||||
#endif
|
||||
|
||||
std::vector<cl_mem> memObjSrcList;
|
||||
std::vector<cl_mem> memObjDstList;
|
||||
unsigned int planesNum = PlanesNum(surfaceFormat);
|
||||
std::vector<clMemWrapper> planeSrcList(planesNum);
|
||||
std::vector<clMemWrapper> 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<cl_uint>(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<cl_uint>(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<cl_uchar> 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<cl_uint> 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<cl_uint>(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<cl_uint>(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<cl_uchar> 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();
|
||||
}
|
||||
@@ -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<CDeviceWrapper> 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<cl_device_id> 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<cl_dx9_media_adapter_type_khr> mediaAdapterTypes;
|
||||
mediaAdapterTypes.push_back(adapterType);
|
||||
|
||||
std::vector<void *> 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<cl_device_id> 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<cl_device_id> 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();
|
||||
}
|
||||
@@ -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<CDeviceWrapper> deviceWrapper;
|
||||
if (!DeviceCreate(adapterType, deviceWrapper))
|
||||
{
|
||||
result.ResultSub(CResult::TEST_ERROR);
|
||||
return result.Result();
|
||||
}
|
||||
|
||||
// generate input data
|
||||
std::vector<cl_uchar> 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<CSurfaceWrapper> 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<CD3D9SurfaceWrapper *>(surface.get()));
|
||||
surfaceInfo.shared_handle = objectSharedHandle;
|
||||
#else
|
||||
void *surfaceInfo = 0;
|
||||
return TEST_NOT_IMPLEMENTED;
|
||||
#endif
|
||||
|
||||
std::vector<cl_mem> memObjList;
|
||||
unsigned int planesNum = PlanesNum(surfaceFormat);
|
||||
std::vector<clMemWrapper> 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<CDXVAWrapper *>(&(*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<cl_uint>(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<cl_uchar> 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<cl_uint>(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<cl_uchar> 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<cl_dx9_media_adapter_type_khr> 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<TContextFuncType> contextFuncs;
|
||||
contextFuncs.push_back(CONTEXT_CREATE_DEFAULT);
|
||||
contextFuncs.push_back(CONTEXT_CREATE_FROM_TYPE);
|
||||
|
||||
std::vector<TSurfaceFormat> formats;
|
||||
formats.push_back(SURFACE_FORMAT_NV12);
|
||||
formats.push_back(SURFACE_FORMAT_YV12);
|
||||
|
||||
std::vector<TSharedHandleType> sharedHandleTypes;
|
||||
sharedHandleTypes.push_back(SHARED_HANDLE_DISABLED);
|
||||
sharedHandleTypes.push_back(SHARED_HANDLE_ENABLED);
|
||||
|
||||
std::vector<cl_bool> 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();
|
||||
}
|
||||
@@ -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<CDeviceWrapper> 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<cl_uchar> bufferRef0(frameSize, 0);
|
||||
std::vector<cl_uchar> bufferRef1(frameSize, 0);
|
||||
std::vector<cl_uchar> 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<CSurfaceWrapper> 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<CD3D9SurfaceWrapper *>(surface.get()));
|
||||
surfaceInfo.shared_handle = objectSharedHandle;
|
||||
#else
|
||||
void *surfaceInfo = 0;
|
||||
return TEST_NOT_IMPLEMENTED;
|
||||
#endif
|
||||
|
||||
std::vector<cl_mem> memObjList;
|
||||
unsigned int planesNum = PlanesNum(surfaceFormat);
|
||||
std::vector<clMemWrapper> 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<cl_uint>(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<cl_uint>(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<cl_uchar> 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<CD3D9SurfaceWrapper *>(surface.get()));
|
||||
surfaceInfo.shared_handle = objectSharedHandle;
|
||||
#else
|
||||
void *surfaceInfo = 0;
|
||||
return TEST_NOT_IMPLEMENTED;
|
||||
#endif
|
||||
|
||||
std::vector<cl_mem> memObjList;
|
||||
unsigned int planesNum = PlanesNum(surfaceFormat);
|
||||
std::vector<clMemWrapper> 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<cl_uint>(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<cl_uchar> 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<cl_uint>(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<cl_uchar> 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<CD3D9SurfaceWrapper *>(surface.get()));
|
||||
surfaceInfo.shared_handle = objectSharedHandle;
|
||||
#else
|
||||
void *surfaceInfo = 0;
|
||||
return TEST_NOT_IMPLEMENTED;
|
||||
#endif
|
||||
|
||||
std::vector<cl_mem> memObjList;
|
||||
unsigned int planesNum = PlanesNum(surfaceFormat);
|
||||
std::vector<clMemWrapper> 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<cl_uint>(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<cl_uchar> 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<cl_uint>(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<cl_uchar> 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();
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
1664
test_conformance/extensions/cl_khr_dx9_media_sharing/utils.cpp
Normal file
1664
test_conformance/extensions/cl_khr_dx9_media_sharing/utils.cpp
Normal file
File diff suppressed because it is too large
Load Diff
215
test_conformance/extensions/cl_khr_dx9_media_sharing/utils.h
Normal file
215
test_conformance/extensions/cl_khr_dx9_media_sharing/utils.h
Normal file
@@ -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 <string>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#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<cl_uchar> &yuv, unsigned int width,
|
||||
unsigned int height, cl_uchar valueMin, cl_uchar valueMax,
|
||||
double valueAdd = 0.0);
|
||||
void YUVGenerateYV12(std::vector<cl_uchar> &yuv, unsigned int width,
|
||||
unsigned int height, cl_uchar valueMin, cl_uchar valueMax,
|
||||
double valueAdd = 0.0);
|
||||
bool YUVGenerate(TSurfaceFormat surfaceFormat, std::vector<cl_uchar> &yuv,
|
||||
unsigned int width, unsigned int height, cl_uchar valueMin,
|
||||
cl_uchar valueMax, double valueAdd = 0.0);
|
||||
bool YUVSurfaceSetNV12(std::auto_ptr<CSurfaceWrapper> &surface,
|
||||
const std::vector<cl_uchar> &yuv, unsigned int width,
|
||||
unsigned int height);
|
||||
bool YUVSurfaceSetYV12(std::auto_ptr<CSurfaceWrapper> &surface,
|
||||
const std::vector<cl_uchar> &yuv, unsigned int width,
|
||||
unsigned int height);
|
||||
bool YUVSurfaceSet(TSurfaceFormat surfaceFormat,
|
||||
std::auto_ptr<CSurfaceWrapper> &surface,
|
||||
const std::vector<cl_uchar> &yuv, unsigned int width,
|
||||
unsigned int height);
|
||||
bool YUVSurfaceGetNV12(std::auto_ptr<CSurfaceWrapper> &surface,
|
||||
std::vector<cl_uchar> &yuv, unsigned int width,
|
||||
unsigned int height);
|
||||
bool YUVSurfaceGetYV12(std::auto_ptr<CSurfaceWrapper> &surface,
|
||||
std::vector<cl_uchar> &yuv, unsigned int width,
|
||||
unsigned int height);
|
||||
bool YUVSurfaceGet(TSurfaceFormat surfaceFormat,
|
||||
std::auto_ptr<CSurfaceWrapper> &surface,
|
||||
std::vector<cl_uchar> &yuv, unsigned int width,
|
||||
unsigned int height);
|
||||
bool YUVCompareNV12(const std::vector<cl_uchar> &yuvTest,
|
||||
const std::vector<cl_uchar> &yuvRef, unsigned int width,
|
||||
unsigned int height);
|
||||
bool YUVCompareYV12(const std::vector<cl_uchar> &yuvTest,
|
||||
const std::vector<cl_uchar> &yuvRef, unsigned int width,
|
||||
unsigned int height);
|
||||
bool YUVCompare(TSurfaceFormat surfaceFormat,
|
||||
const std::vector<cl_uchar> &yuvTest,
|
||||
const std::vector<cl_uchar> &yuvRef, unsigned int width,
|
||||
unsigned int height);
|
||||
|
||||
// other types utils
|
||||
void DataGenerate(TSurfaceFormat surfaceFormat, cl_channel_type type,
|
||||
std::vector<float> &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<cl_half> &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<cl_uchar> &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<cl_float> &dataTest,
|
||||
const std::vector<cl_float> &dataExp, unsigned int width,
|
||||
unsigned int height, unsigned int channelNum);
|
||||
bool DataCompare(TSurfaceFormat surfaceFormat, cl_channel_type type,
|
||||
const std::vector<cl_half> &dataTest,
|
||||
const std::vector<cl_half> &dataExp, unsigned int width,
|
||||
unsigned int height, unsigned int channelNum);
|
||||
bool DataCompare(TSurfaceFormat surfaceFormat, cl_channel_type type,
|
||||
const std::vector<cl_uchar> &dataTest,
|
||||
const std::vector<cl_uchar> &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<CSurfaceWrapper> &surface,
|
||||
void *shareHandleExp);
|
||||
bool ImageInfoVerify(cl_dx9_media_adapter_type_khr adapterType,
|
||||
const std::vector<cl_mem> &memObjList, unsigned int width,
|
||||
unsigned int height,
|
||||
std::auto_ptr<CSurfaceWrapper> &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<CDeviceWrapper> &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<CSurfaceWrapper> &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
|
||||
@@ -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<IDirect3DDevice9Ex *>(_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() {}
|
||||
195
test_conformance/extensions/cl_khr_dx9_media_sharing/wrappers.h
Normal file
195
test_conformance/extensions/cl_khr_dx9_media_sharing/wrappers.h
Normal file
@@ -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 <d3d9.h>
|
||||
#if defined(__MINGW32__)
|
||||
#include <rpcsal.h>
|
||||
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 <dxvahd.h>
|
||||
#include <tchar.h>
|
||||
#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
|
||||
@@ -1,2 +0,0 @@
|
||||
set(HARNESS_LIB harness)
|
||||
add_subdirectory( media_sharing )
|
||||
@@ -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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#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<cl_platform_id> 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<cl_device_id> 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);
|
||||
}
|
||||
@@ -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<CDeviceWrapper> deviceWrapper;
|
||||
if (!DeviceCreate(adapterType, deviceWrapper))
|
||||
{
|
||||
result.ResultSub(CResult::TEST_ERROR);
|
||||
return result.Result();
|
||||
}
|
||||
|
||||
//generate input data
|
||||
std::vector<cl_uchar> 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<CSurfaceWrapper> 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<CD3D9SurfaceWrapper *>(surface.get()));
|
||||
surfaceInfo.shared_handle = objectSharedHandle;
|
||||
#else
|
||||
void *surfaceInfo = 0;
|
||||
return TEST_NOT_IMPLEMENTED;
|
||||
#endif
|
||||
|
||||
std::vector<cl_mem> memObjList;
|
||||
unsigned int planesNum = PlanesNum(surfaceFormat);
|
||||
std::vector<clMemWrapper> 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<cl_uint>(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<cl_uchar> 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<cl_uint>(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<cl_uchar> 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<cl_dx9_media_adapter_type_khr> 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<TContextFuncType> contextFuncs;
|
||||
contextFuncs.push_back(CONTEXT_CREATE_DEFAULT);
|
||||
contextFuncs.push_back(CONTEXT_CREATE_FROM_TYPE);
|
||||
|
||||
std::vector<TSurfaceFormat> formats;
|
||||
formats.push_back(SURFACE_FORMAT_NV12);
|
||||
formats.push_back(SURFACE_FORMAT_YV12);
|
||||
|
||||
std::vector<TSharedHandleType> 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();
|
||||
}
|
||||
@@ -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<CDeviceWrapper> deviceWrapper;
|
||||
if (!DeviceCreate(adapterType, deviceWrapper))
|
||||
{
|
||||
result.ResultSub(CResult::TEST_ERROR);
|
||||
return result.Result();
|
||||
}
|
||||
|
||||
//generate input and expected data
|
||||
std::vector<std::vector<cl_uchar> > bufferRef1(FRAME_NUM);
|
||||
std::vector<std::vector<cl_uchar> > bufferRef2(FRAME_NUM);
|
||||
std::vector<std::vector<cl_uchar> > 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<cl_uchar>(step * i), static_cast<cl_uchar>(step * (i + 1))) ||
|
||||
!YUVGenerate(surfaceFormat, bufferRef2[i], width, height, static_cast<cl_uchar>(step * i), static_cast<cl_uchar>(step * (i + 1)), 0.2) ||
|
||||
!YUVGenerate(surfaceFormat, bufferRef3[i], width, height, static_cast<cl_uchar>(step * i), static_cast<cl_uchar>(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<CSurfaceWrapper> 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<CD3D9SurfaceWrapper *>(surface.get()));
|
||||
surfaceInfo.shared_handle = objectSharedHandle;
|
||||
#else
|
||||
void *surfaceInfo = 0;
|
||||
return TEST_NOT_IMPLEMENTED;
|
||||
#endif
|
||||
|
||||
std::vector<cl_mem> memObjList;
|
||||
unsigned int planesNum = PlanesNum(surfaceFormat);
|
||||
std::vector<clMemWrapper> 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<cl_uint>(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<cl_uchar> 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<cl_uchar> 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<cl_uchar> 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<cl_uchar> 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<cl_uchar> 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<cl_uchar> 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<cl_uchar> 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<cl_uchar *>(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<cl_uchar *>(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<cl_uint>(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<cl_uchar> 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();
|
||||
}
|
||||
@@ -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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#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<CDeviceWrapper> deviceWrapper;
|
||||
if (!DeviceCreate(adapterType, deviceWrapper))
|
||||
{
|
||||
result.ResultSub(CResult::TEST_ERROR);
|
||||
return result.Result();
|
||||
}
|
||||
|
||||
std::vector<std::vector<cl_uchar> > bufferIn(FRAME_NUM);
|
||||
std::vector<std::vector<cl_uchar> > 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<cl_uchar>(step * i), static_cast<cl_uchar>(step * (i + 1))) ||
|
||||
!YUVGenerate(surfaceFormat, bufferExp[i], width, height, static_cast<cl_uchar>(step * i), static_cast<cl_uchar>(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<CSurfaceWrapper> 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<CSurfaceWrapper> 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<CD3D9SurfaceWrapper *>(surfaceSrc.get()));
|
||||
surfaceInfoSrc.shared_handle = objectSrcHandle;
|
||||
|
||||
cl_dx9_surface_info_khr surfaceInfoDst;
|
||||
surfaceInfoDst.resource = *(static_cast<CD3D9SurfaceWrapper *>(surfaceDst.get()));
|
||||
surfaceInfoDst.shared_handle = objectDstHandle;
|
||||
#else
|
||||
void *surfaceInfoSrc = 0;
|
||||
void *surfaceInfoDst = 0;
|
||||
return TEST_NOT_IMPLEMENTED;
|
||||
#endif
|
||||
|
||||
std::vector<cl_mem> memObjSrcList;
|
||||
std::vector<cl_mem> memObjDstList;
|
||||
unsigned int planesNum = PlanesNum(surfaceFormat);
|
||||
std::vector<clMemWrapper> planeSrcList(planesNum);
|
||||
std::vector<clMemWrapper> 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<cl_uint>(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<cl_uint>(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<cl_uchar> 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<cl_uint> 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<cl_uint>(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<cl_uint>(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<cl_uchar> 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();
|
||||
}
|
||||
@@ -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<CDeviceWrapper> 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<cl_device_id> 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<cl_dx9_media_adapter_type_khr> mediaAdapterTypes;
|
||||
mediaAdapterTypes.push_back(adapterType);
|
||||
|
||||
std::vector<void *> 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<cl_device_id> 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<cl_device_id> 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();
|
||||
}
|
||||
@@ -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<CDeviceWrapper> deviceWrapper;
|
||||
if (!DeviceCreate(adapterType, deviceWrapper))
|
||||
{
|
||||
result.ResultSub(CResult::TEST_ERROR);
|
||||
return result.Result();
|
||||
}
|
||||
|
||||
//generate input data
|
||||
std::vector<cl_uchar> 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<CSurfaceWrapper> 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<CD3D9SurfaceWrapper *>(surface.get()));
|
||||
surfaceInfo.shared_handle = objectSharedHandle;
|
||||
#else
|
||||
void *surfaceInfo = 0;
|
||||
return TEST_NOT_IMPLEMENTED;
|
||||
#endif
|
||||
|
||||
std::vector<cl_mem> memObjList;
|
||||
unsigned int planesNum = PlanesNum(surfaceFormat);
|
||||
std::vector<clMemWrapper> 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<CDXVAWrapper *>(&(*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<cl_uint>(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<cl_uchar> 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<cl_uint>(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<cl_uchar> 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<cl_dx9_media_adapter_type_khr> 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<TContextFuncType> contextFuncs;
|
||||
contextFuncs.push_back(CONTEXT_CREATE_DEFAULT);
|
||||
contextFuncs.push_back(CONTEXT_CREATE_FROM_TYPE);
|
||||
|
||||
std::vector<TSurfaceFormat> formats;
|
||||
formats.push_back(SURFACE_FORMAT_NV12);
|
||||
formats.push_back(SURFACE_FORMAT_YV12);
|
||||
|
||||
std::vector<TSharedHandleType> sharedHandleTypes;
|
||||
sharedHandleTypes.push_back(SHARED_HANDLE_DISABLED);
|
||||
sharedHandleTypes.push_back(SHARED_HANDLE_ENABLED);
|
||||
|
||||
std::vector<cl_bool> 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();
|
||||
}
|
||||
@@ -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<CDeviceWrapper> 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<cl_uchar> bufferRef0(frameSize, 0);
|
||||
std::vector<cl_uchar> bufferRef1(frameSize, 0);
|
||||
std::vector<cl_uchar> 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<CSurfaceWrapper> 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<CD3D9SurfaceWrapper *>(surface.get()));
|
||||
surfaceInfo.shared_handle = objectSharedHandle;
|
||||
#else
|
||||
void *surfaceInfo = 0;
|
||||
return TEST_NOT_IMPLEMENTED;
|
||||
#endif
|
||||
|
||||
std::vector<cl_mem> memObjList;
|
||||
unsigned int planesNum = PlanesNum(surfaceFormat);
|
||||
std::vector<clMemWrapper> 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<cl_uint>(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<cl_uint>(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<cl_uchar> 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<CD3D9SurfaceWrapper *>(surface.get()));
|
||||
surfaceInfo.shared_handle = objectSharedHandle;
|
||||
#else
|
||||
void *surfaceInfo = 0;
|
||||
return TEST_NOT_IMPLEMENTED;
|
||||
#endif
|
||||
|
||||
std::vector<cl_mem> memObjList;
|
||||
unsigned int planesNum = PlanesNum(surfaceFormat);
|
||||
std::vector<clMemWrapper> 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<cl_uint>(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<cl_uchar> 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<cl_uint>(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<cl_uchar> 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<CD3D9SurfaceWrapper *>(surface.get()));
|
||||
surfaceInfo.shared_handle = objectSharedHandle;
|
||||
#else
|
||||
void *surfaceInfo = 0;
|
||||
return TEST_NOT_IMPLEMENTED;
|
||||
#endif
|
||||
|
||||
std::vector<cl_mem> memObjList;
|
||||
unsigned int planesNum = PlanesNum(surfaceFormat);
|
||||
std::vector<clMemWrapper> 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<cl_uint>(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<cl_uchar> 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<cl_uint>(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<cl_uchar> 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();
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -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 <string>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#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<cl_uchar> &yuv, unsigned int width, unsigned int height,
|
||||
cl_uchar valueMin, cl_uchar valueMax, double valueAdd = 0.0);
|
||||
void YUVGenerateYV12(std::vector<cl_uchar> &yuv, unsigned int width, unsigned int height,
|
||||
cl_uchar valueMin, cl_uchar valueMax, double valueAdd = 0.0);
|
||||
bool YUVGenerate(TSurfaceFormat surfaceFormat, std::vector<cl_uchar> &yuv, unsigned int width, unsigned int height,
|
||||
cl_uchar valueMin, cl_uchar valueMax, double valueAdd = 0.0);
|
||||
bool YUVSurfaceSetNV12(std::auto_ptr<CSurfaceWrapper> &surface, const std::vector<cl_uchar> &yuv,
|
||||
unsigned int width, unsigned int height);
|
||||
bool YUVSurfaceSetYV12(std::auto_ptr<CSurfaceWrapper> &surface, const std::vector<cl_uchar> &yuv,
|
||||
unsigned int width, unsigned int height);
|
||||
bool YUVSurfaceSet(TSurfaceFormat surfaceFormat, std::auto_ptr<CSurfaceWrapper> &surface, const std::vector<cl_uchar> &yuv,
|
||||
unsigned int width, unsigned int height);
|
||||
bool YUVSurfaceGetNV12(std::auto_ptr<CSurfaceWrapper> &surface, std::vector<cl_uchar> &yuv,
|
||||
unsigned int width, unsigned int height);
|
||||
bool YUVSurfaceGetYV12(std::auto_ptr<CSurfaceWrapper> &surface, std::vector<cl_uchar> &yuv,
|
||||
unsigned int width, unsigned int height);
|
||||
bool YUVSurfaceGet(TSurfaceFormat surfaceFormat, std::auto_ptr<CSurfaceWrapper> &surface, std::vector<cl_uchar> &yuv,
|
||||
unsigned int width, unsigned int height);
|
||||
bool YUVCompareNV12(const std::vector<cl_uchar> &yuvTest, const std::vector<cl_uchar> &yuvRef,
|
||||
unsigned int width, unsigned int height);
|
||||
bool YUVCompareYV12(const std::vector<cl_uchar> &yuvTest, const std::vector<cl_uchar> &yuvRef,
|
||||
unsigned int width, unsigned int height);
|
||||
bool YUVCompare(TSurfaceFormat surfaceFormat, const std::vector<cl_uchar> &yuvTest, const std::vector<cl_uchar> &yuvRef,
|
||||
unsigned int width, unsigned int height);
|
||||
|
||||
//other types utils
|
||||
void DataGenerate(TSurfaceFormat surfaceFormat, cl_channel_type type, std::vector<float> &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<cl_half> &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<cl_uchar> &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<cl_float> &dataTest, const std::vector<cl_float> &dataExp,
|
||||
unsigned int width, unsigned int height, unsigned int channelNum);
|
||||
bool DataCompare(TSurfaceFormat surfaceFormat, cl_channel_type type, const std::vector<cl_half> &dataTest, const std::vector<cl_half> &dataExp,
|
||||
unsigned int width, unsigned int height, unsigned int channelNum);
|
||||
bool DataCompare(TSurfaceFormat surfaceFormat, cl_channel_type type, const std::vector<cl_uchar> &dataTest, const std::vector<cl_uchar> &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<CSurfaceWrapper> &surface, void *shareHandleExp);
|
||||
bool ImageInfoVerify(cl_dx9_media_adapter_type_khr adapterType, const std::vector<cl_mem> &memObjList, unsigned int width, unsigned int height,
|
||||
std::auto_ptr<CSurfaceWrapper> &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<CDeviceWrapper> &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<CSurfaceWrapper> &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
|
||||
@@ -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<IDirect3DDevice9Ex *>(_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()
|
||||
{
|
||||
|
||||
}
|
||||
@@ -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 <d3d9.h>
|
||||
#if defined (__MINGW32__)
|
||||
#include <rpcsal.h>
|
||||
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 <dxvahd.h>
|
||||
#include <tchar.h>
|
||||
#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
|
||||
Reference in New Issue
Block a user