Initial open source release of OpenCL 2.2 CTS.

This commit is contained in:
Kedar Patil
2017-05-16 18:25:37 +05:30
parent 6911ba5116
commit 2821bf1323
1035 changed files with 343518 additions and 0 deletions

View File

@@ -0,0 +1,47 @@
if(WIN32)
set(D3D11_INCLUDE_DIR $ENV{NV_TOOLS}/sdk/DirectX_Aug2009/Include)
if(${ARCH} STREQUAL "i686")
set(D3D11_LIB_DIR $ENV{NV_TOOLS}/sdk/DirectX_Aug2009/Lib/x86)
endif(${ARCH} STREQUAL "i686")
if(${ARCH} STREQUAL "x86_64")
set(D3D11_LIB_DIR $ENV{NV_TOOLS}/sdk/DirectX_Aug2009/Lib/x64)
endif(${ARCH} STREQUAL "x86_64")
list(APPEND CLConform_INCLUDE_DIR ${D3D11_INCLUDE_DIR})
include_directories (${CLConform_SOURCE_DIR}/test_common/harness
${CLConform_INCLUDE_DIR} )
link_directories(${CL_LIB_DIR}, ${D3D11_LIB_DIR})
list(APPEND CLConform_LIBRARIES d3d11 dxgi)
set(D3D11_SOURCES
buffer.cpp
texture2d.cpp
texture3d.cpp
misc.cpp
main.cpp
harness.cpp
../../test_common/harness/errorHelpers.c
../../test_common/harness/threadTesting.c
../../test_common/harness/testHarness.c
../../test_common/harness/kernelHelpers.c
../../test_common/harness/mt19937.c
../../test_common/harness/conversions.c
../../test_common/harness/msvc9.c
../../test_common/harness/parseParameters.cpp)
add_executable(conformance_test_d3d11
${D3D11_SOURCES})
set_source_files_properties(
${D3D11_SOURCES}
PROPERTIES LANGUAGE CXX)
TARGET_LINK_LIBRARIES(conformance_test_d3d11
${CLConform_LIBRARIES})
endif(WIN32)

View File

@@ -0,0 +1,321 @@
//
// 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 "harness.h"
#define ADD_BUFFER_PROPERTIES(w, x, y, z) \
{ w, x, y, z, #x, #y, #z, }
BufferProperties bufferProperties[] =
{
ADD_BUFFER_PROPERTIES( 0x110, D3D11_BIND_CONSTANT_BUFFER, D3D11_USAGE_DYNAMIC, D3D11_CPU_ACCESS_WRITE),
ADD_BUFFER_PROPERTIES( 0x1100, D3D11_BIND_CONSTANT_BUFFER, D3D11_USAGE_DYNAMIC, D3D11_CPU_ACCESS_WRITE),
ADD_BUFFER_PROPERTIES( 0x8000, D3D11_BIND_CONSTANT_BUFFER, D3D11_USAGE_DYNAMIC, D3D11_CPU_ACCESS_WRITE),
ADD_BUFFER_PROPERTIES( 0x7FFFF, D3D11_BIND_SHADER_RESOURCE, D3D11_USAGE_DEFAULT, 0),
ADD_BUFFER_PROPERTIES( 0x110000, D3D11_BIND_SHADER_RESOURCE, D3D11_USAGE_DEFAULT, 0),
ADD_BUFFER_PROPERTIES( 0x110000, D3D11_BIND_STREAM_OUTPUT, D3D11_USAGE_DEFAULT, 0),
ADD_BUFFER_PROPERTIES( 0x110001, D3D11_BIND_STREAM_OUTPUT, D3D11_USAGE_DEFAULT, 0),
ADD_BUFFER_PROPERTIES( 0x11, D3D11_BIND_VERTEX_BUFFER, D3D11_USAGE_DEFAULT, 0),
ADD_BUFFER_PROPERTIES( 0x11, D3D11_BIND_INDEX_BUFFER, D3D11_USAGE_DYNAMIC, D3D11_CPU_ACCESS_WRITE),
ADD_BUFFER_PROPERTIES( 0x121, D3D11_BIND_VERTEX_BUFFER, D3D11_USAGE_DEFAULT, 0),
ADD_BUFFER_PROPERTIES( 0x1234, D3D11_BIND_INDEX_BUFFER, D3D11_USAGE_DEFAULT, 0),
ADD_BUFFER_PROPERTIES( 0x12345, D3D11_BIND_VERTEX_BUFFER, D3D11_USAGE_DYNAMIC, D3D11_CPU_ACCESS_WRITE),
ADD_BUFFER_PROPERTIES( 0x123456, D3D11_BIND_INDEX_BUFFER, D3D11_USAGE_DEFAULT, 0),
#if 0 // avoid large sizes on automation
ADD_BUFFER_PROPERTIES( 0x1234567, D3D11_BIND_INDEX_BUFFER, D3D11_USAGE_DYNAMIC, D3D11_CPU_ACCESS_WRITE),
ADD_BUFFER_PROPERTIES( 0x4000000, D3D11_BIND_VERTEX_BUFFER, D3D11_USAGE_DEFAULT, 0),
ADD_BUFFER_PROPERTIES( 0x4000004, D3D11_BIND_VERTEX_BUFFER, D3D11_USAGE_DEFAULT, 0),
ADD_BUFFER_PROPERTIES( 0x4000008, D3D11_BIND_VERTEX_BUFFER, D3D11_USAGE_DEFAULT, 0),
ADD_BUFFER_PROPERTIES( 0x4000011, D3D11_BIND_VERTEX_BUFFER, D3D11_USAGE_DEFAULT, 0),
ADD_BUFFER_PROPERTIES( 0x4000014, D3D11_BIND_VERTEX_BUFFER, D3D11_USAGE_DEFAULT, 0),
#endif
};
UINT bufferPropertyCount = sizeof(bufferProperties)/sizeof(bufferProperties[0]);
void SubTestBuffer(
cl_context context,
cl_command_queue command_queue,
ID3D11Device* pDevice,
ID3D11DeviceContext* pDC,
const BufferProperties* props)
{
ID3D11Buffer* pBuffer = NULL;
HRESULT hr = S_OK;
cl_mem mem = NULL;
cl_int result = CL_SUCCESS;
HarnessD3D11_TestBegin("Buffer: Size=%d, BindFlags=%s, Usage=%s, CPUAccess=%s",
props->ByteWidth,
props->name_BindFlags,
props->name_Usage,
props->name_CPUAccess);
// create the D3D11 resource
{
D3D11_BUFFER_DESC desc = {0};
desc.ByteWidth = props->ByteWidth;
desc.Usage = props->Usage;
desc.CPUAccessFlags = props->CPUAccess;
desc.BindFlags = props->BindFlags;
desc.MiscFlags = 0;
hr = pDevice->CreateBuffer(&desc, NULL, &pBuffer);
TestRequire(SUCCEEDED(hr), "Creating vertex buffer failed!");
}
// populate the D3D11 resource with data
{
ID3D11Buffer* pStagingBuffer = NULL;
char *pStagingData = NULL;
D3D11_MAPPED_SUBRESOURCE map = {0};
// create a staging buffer to use to copy data to the D3D buffer
D3D11_BUFFER_DESC desc = {0};
desc.ByteWidth = 16;
desc.Usage = D3D11_USAGE_STAGING;
desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE|D3D11_CPU_ACCESS_READ;
desc.BindFlags = 0;
desc.MiscFlags = 0;
hr = pDevice->CreateBuffer(&desc, NULL, &pStagingBuffer);
TestRequire(SUCCEEDED(hr), "Creating staging vertex buffer failed!");
// populate the staging buffer
hr = pDC->Map(
pStagingBuffer,
0,
D3D11_MAP_READ_WRITE,
0,
&map);
TestRequire(SUCCEEDED(hr), "Map failed!");
memcpy(map.pData, "abcdXXXXxxxx1234", 16);
pDC->Unmap(pStagingBuffer, 0);
TestRequire(SUCCEEDED(hr), "Unmap failed!");
// copy 'abcdXXXX' to the front of the buffer and 'xxxx1234' to the back
D3D11_BOX box = {0};
box.front = 0;
box.back = 1;
box.top = 0;
box.bottom = 1;
box.left = 0;
box.right = 8;
pDC->CopySubresourceRegion(
pBuffer,
0,
0,
0,
0,
pStagingBuffer,
0,
&box);
box.left = 8;
box.right = 16;
pDC->CopySubresourceRegion(
pBuffer,
0,
props->ByteWidth-8,
0,
0,
pStagingBuffer,
0,
&box);
pStagingBuffer->Release();
}
// share the resource with OpenCL
{
mem = clCreateFromD3D11BufferKHR(
context,
0,
pBuffer,
&result);
TestRequire(CL_SUCCESS == result, "clCreateFromD3D11BufferKHR failed");
}
// validate the OpenCL mem obj's properties
{
ID3D11Resource* clResource = NULL;
result = clGetMemObjectInfo(
mem,
CL_MEM_D3D11_RESOURCE_KHR,
sizeof(clResource),
&clResource,
NULL);
TestRequire(result == CL_SUCCESS, "clGetMemObjectInfo for CL_MEM_D3D11_RESOURCE_KHR failed.");
TestRequire(clResource == pBuffer, "clGetMemObjectInfo for CL_MEM_D3D11_RESOURCE_KHR returned incorrect value.");
}
// acquire the resource from OpenCL
{
result = clEnqueueAcquireD3D11ObjectsKHR(
command_queue,
1,
&mem,
0,
NULL,
NULL);
TestRequire(result == CL_SUCCESS, "clEnqueueAcquireD3D11ObjectsKHR failed.");
}
// read+write data from the buffer in OpenCL
{
// overwrite the 'XXXX' with '1234' and the 'xxxx' with 'abcd' so we now have
// 'abcd1234' at the beginning and end of the buffer
result = clEnqueueCopyBuffer(
command_queue,
mem,
mem,
0,
props->ByteWidth-8,
4,
0,
NULL,
NULL);
TestRequire(result == CL_SUCCESS, "clEnqueueCopyBuffer failed.");
result = clEnqueueCopyBuffer(
command_queue,
mem,
mem,
props->ByteWidth-4,
4,
4,
0,
NULL,
NULL);
TestRequire(result == CL_SUCCESS, "clEnqueueCopyBuffer failed.");
}
// release the resource from OpenCL
{
result = clEnqueueReleaseD3D11ObjectsKHR(
command_queue,
1,
&mem,
0,
NULL,
NULL);
TestRequire(result == CL_SUCCESS, "clEnqueueReleaseD3D11ObjectsKHR failed.");
}
// read data in D3D
{
ID3D11Buffer* pStagingBuffer = NULL;
char *pStagingData = NULL;
D3D11_MAPPED_SUBRESOURCE map = {0};
// create a staging buffer to read the data back
D3D11_BUFFER_DESC desc = {0};
desc.ByteWidth = 16;
desc.Usage = D3D11_USAGE_STAGING;
desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE|D3D11_CPU_ACCESS_READ;
desc.BindFlags = 0;
desc.MiscFlags = 0;
hr = pDevice->CreateBuffer(&desc, NULL, &pStagingBuffer);
TestRequire(SUCCEEDED(hr), "Creating staging vertex buffer failed!");
// make sure the staging buffer doesn't get stale data
hr = pDC->Map(
pStagingBuffer,
0,
D3D11_MAP_READ_WRITE,
0,
&map);
TestRequire(SUCCEEDED(hr), "Map failed!");
memset(map.pData, 0, 16);
pDC->Unmap(pStagingBuffer, 0);
TestRequire(SUCCEEDED(hr), "Unmap failed!");
// copy the 'abcd1234' from the front and back of the buffer to the staging buffer
D3D11_BOX box = {0};
box.front = 0;
box.back = 1;
box.top = 0;
box.bottom = 1;
box.left = 0;
box.right = 8;
pDC->CopySubresourceRegion(
pStagingBuffer,
0,
0,
0,
0,
pBuffer,
0,
&box);
box.left = props->ByteWidth-8;
box.right = props->ByteWidth;
pDC->CopySubresourceRegion(
pStagingBuffer,
0,
8,
0,
0,
pBuffer,
0,
&box);
TestRequire(SUCCEEDED(hr), "CopySubresourceRegion failed!");
// verify that we got the 'abcd1234'
hr = pDC->Map(
pStagingBuffer,
0,
D3D11_MAP_READ_WRITE,
0,
&map);
TestRequire(SUCCEEDED(hr), "Map failed!");
TestRequire(!memcmp(map.pData, "abcd1234abcd1234", 16), "Data was not accurately");
pDC->Unmap(pStagingBuffer, 0);
TestRequire(SUCCEEDED(hr), "Unmap failed!");
pStagingBuffer->Release();
}
Cleanup:
if (pBuffer)
{
pBuffer->Release();
}
if (mem)
{
clReleaseMemObject(mem);
}
HarnessD3D11_TestEnd();
}
void TestDeviceBuffer(
cl_context context,
cl_command_queue command_queue,
ID3D11Device* pDevice,
ID3D11DeviceContext* pDC)
{
for (UINT i = 0; i < bufferPropertyCount; ++i)
{
SubTestBuffer(
context,
command_queue,
pDevice,
pDC,
&bufferProperties[i]);
}
}

View File

@@ -0,0 +1,456 @@
//
// 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.
//
#define INITGUID
#include "harness.h"
#include <tchar.h>
#include <string>
#include <vector>
/*
* OpenCL state
*/
clGetDeviceIDsFromD3D11KHR_fn clGetDeviceIDsFromD3D11KHR = NULL;
clCreateFromD3D11BufferKHR_fn clCreateFromD3D11BufferKHR = NULL;
clCreateFromD3D11Texture2DKHR_fn clCreateFromD3D11Texture2DKHR = NULL;
clCreateFromD3D11Texture3DKHR_fn clCreateFromD3D11Texture3DKHR = NULL;
clEnqueueAcquireD3D11ObjectsKHR_fn clEnqueueAcquireD3D11ObjectsKHR = NULL;
clEnqueueReleaseD3D11ObjectsKHR_fn clEnqueueReleaseD3D11ObjectsKHR = NULL;
#define INITPFN(x) \
x = (x ## _fn)clGetExtensionFunctionAddressForPlatform(platform, #x); NonTestRequire(x, "Failed to get function pointer for %s", #x);
void
HarnessD3D11_ExtensionCheck()
{
cl_int result = CL_SUCCESS;
cl_platform_id platform = NULL;
HarnessD3D11_TestBegin("Extension query");
bool platform_d3d11 = false; // Does platform support the extension?
{
std::vector< char > buffer;
size_t size = 0;
result = clGetPlatformIDs( 1, &platform, NULL );
NonTestRequire( result == CL_SUCCESS, "Failed to get any platforms." );
result = clGetPlatformInfo( platform, CL_PLATFORM_EXTENSIONS, 0, NULL, & size );
NonTestRequire( result == CL_SUCCESS, "Failed to get size of extension string." );
buffer.resize( size );
result = clGetPlatformInfo( platform, CL_PLATFORM_EXTENSIONS, buffer.size(), & buffer.front(), & size );
NonTestRequire( result == CL_SUCCESS, "Failed to get extension string." );
std::string extensions = std::string( " " ) + & buffer.front() + " ";
platform_d3d11 = ( extensions.find( " cl_khr_d3d11_sharing " ) != std::string::npos );
}
// Platform is required to report the extension only if all devices support it,
// so let us iterate through all the devices and count devices supporting the extension.
// Get list of all devices.
std::vector< cl_device_id > devices;
cl_uint num_devices = 0;
result = clGetDeviceIDs( platform, CL_DEVICE_TYPE_ALL, 0, NULL, & num_devices );
NonTestRequire( result == CL_SUCCESS, "Failed to get number of devices." );
devices.resize( num_devices );
result = clGetDeviceIDs( platform, CL_DEVICE_TYPE_ALL, devices.size(), & devices.front(), & num_devices );
NonTestRequire( result == CL_SUCCESS, "Failed to get list of device ids." );
NonTestRequire( num_devices == devices.size(), "Failed to get list of device ids." );
// Iterate through the devices and count devices supporting the extension.
cl_uint num_devices_d3d11 = 0; // Number of devices supporting cl_khr_d3d11_sharing.
for ( cl_uint i = 0; i < devices.size(); ++ i )
{
std::vector< char > buffer;
size_t size = 0;
result = clGetDeviceInfo( devices[ i ], CL_DEVICE_EXTENSIONS, 0, NULL, & size );
NonTestRequire( result == CL_SUCCESS, "Failed to get size of extension string." );
buffer.resize( size );
result = clGetDeviceInfo( devices[ i ], CL_DEVICE_EXTENSIONS, buffer.size(), & buffer.front(), & size );
NonTestRequire( result == CL_SUCCESS, "Failed to get extension string." );
std::string extensions = std::string( " " ) + & buffer.front() + " ";
if ( extensions.find( " cl_khr_d3d11_sharing " ) != std::string::npos )
{
++ num_devices_d3d11;
}
}
OSVERSIONINFO osvi;
osvi.dwOSVersionInfoSize = sizeof(osvi);
GetVersionEx(&osvi);
if (osvi.dwMajorVersion <= 5)
{
// Neither platform nor devices should declare support.
TestRequire( ! platform_d3d11, "Platform should not declare extension on Windows < 6" );
TestRequire( num_devices_d3d11 == 0, "Devices should not declare extension on Windows < 6" );
}
else
{
if ( num_devices_d3d11 == num_devices )
{
// All the devices declare support, so platform must declare support as well.
TestRequire( platform_d3d11, "Extension should be exported on Windows >= 6" );
}
else
{
// Not all the devices support th eextension => platform should not declare it.
TestRequire( ! platform_d3d11, "Extension should not be exported on Windows >= 6" );
}
}
Cleanup:
HarnessD3D11_TestEnd();
// early-out of the extension is not present
if ( num_devices_d3d11 == 0 )
{
HarnessD3D11_TestStats();
}
}
void
HarnessD3D11_Initialize(cl_platform_id platform)
{
HarnessD3D11_ExtensionCheck();
// extract function pointers for exported functions
INITPFN(clGetDeviceIDsFromD3D11KHR);
INITPFN(clCreateFromD3D11BufferKHR);
INITPFN(clCreateFromD3D11Texture2DKHR);
INITPFN(clCreateFromD3D11Texture3DKHR);
INITPFN(clEnqueueAcquireD3D11ObjectsKHR);
INITPFN(clEnqueueReleaseD3D11ObjectsKHR);
}
/*
* Window management
*/
static IDXGISwapChain* HarnessD3D11_pSwapChain = NULL;
static ID3D11Device* HarnessD3D11_pDevice = NULL;
static ID3D11DeviceContext* HarnessD3D11_pDC = NULL;
static HWND HarnessD3D11_hWnd = NULL;
static LRESULT WINAPI HarnessD3D11_Proc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_KEYDOWN:
return 0;
break;
case WM_DESTROY:
HarnessD3D11_hWnd = NULL;
PostQuitMessage(0);
return 0;
case WM_PAINT:
ValidateRect(hWnd, NULL);
return 0;
}
return DefWindowProc(hWnd, msg, wParam, lParam);
}
static void HarnessD3D11_InteractiveLoop()
{
MSG msg;
while(PeekMessage(&msg,HarnessD3D11_hWnd,0,0,PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
cl_int HarnessD3D11_CreateDevice(
IDXGIAdapter* pAdapter,
ID3D11Device **ppDevice,
ID3D11DeviceContext** ppDC)
{
HRESULT hr = S_OK;
unsigned int cuStatus = 1;
*ppDevice = NULL;
// create window
static WNDCLASSEX wc =
{
sizeof(WNDCLASSEX),
CS_CLASSDC,
HarnessD3D11_Proc,
0L,
0L,
GetModuleHandle(NULL),
NULL,
NULL,
NULL,
NULL,
_T( "cl_khr_d3d11_sharing_conformance" ),
NULL
};
RegisterClassEx(&wc);
HarnessD3D11_hWnd = CreateWindow(
_T( "cl_khr_d3d11_sharing_conformance" ),
_T( "cl_khr_d3d11_sharing_conformance" ),
WS_OVERLAPPEDWINDOW,
0, 0, 256, 256,
NULL,
NULL,
wc.hInstance,
NULL);
NonTestRequire(0 != HarnessD3D11_hWnd, "Failed to create window");
ShowWindow(HarnessD3D11_hWnd,SW_SHOWDEFAULT);
UpdateWindow(HarnessD3D11_hWnd);
RECT rc;
GetClientRect(HarnessD3D11_hWnd, &rc);
UINT width = rc.right - rc.left;
UINT height = rc.bottom - rc.top;
// Create device and swapchain
DXGI_SWAP_CHAIN_DESC sd;
ZeroMemory( &sd, sizeof(sd) );
sd.BufferCount = 1;
sd.BufferDesc.Width = width;
sd.BufferDesc.Height = height;
sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
sd.BufferDesc.RefreshRate.Numerator = 60;
sd.BufferDesc.RefreshRate.Denominator = 1;
sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
sd.OutputWindow = HarnessD3D11_hWnd;
sd.SampleDesc.Count = 1;
sd.SampleDesc.Quality = 0;
sd.Windowed = TRUE;
D3D_FEATURE_LEVEL requestedFeatureLevels[] = {D3D_FEATURE_LEVEL_10_0};
D3D_FEATURE_LEVEL featureLevel = D3D_FEATURE_LEVEL_11_0;
hr = D3D11CreateDeviceAndSwapChain(
NULL, // pAdapter,
D3D_DRIVER_TYPE_HARDWARE,
NULL,
0,
requestedFeatureLevels,
1,
D3D11_SDK_VERSION,
&sd,
&HarnessD3D11_pSwapChain,
&HarnessD3D11_pDevice,
&featureLevel,
&HarnessD3D11_pDC);
if (FAILED(hr) ) {
return CL_DEVICE_NOT_FOUND;
}
*ppDevice = HarnessD3D11_pDevice;
*ppDC = HarnessD3D11_pDC;
return CL_SUCCESS;
}
void HarnessD3D11_DestroyDevice()
{
HarnessD3D11_pSwapChain->Release();
HarnessD3D11_pDevice->Release();
HarnessD3D11_pDC->Release();
if (HarnessD3D11_hWnd) DestroyWindow(HarnessD3D11_hWnd);
HarnessD3D11_hWnd = 0;
}
/*
*
* texture formats
*
*/
#define ADD_TEXTURE_FORMAT(x,y,z,a,b,g) { x, y, z, a*b/8, g, #x, #y, #z, }
TextureFormat formats[] =
{
ADD_TEXTURE_FORMAT( DXGI_FORMAT_R32G32B32A32_FLOAT , CL_RGBA , CL_FLOAT , 32, 4, TextureFormat::GENERIC_FLOAT ),
ADD_TEXTURE_FORMAT( DXGI_FORMAT_R32G32B32A32_UINT , CL_RGBA , CL_UNSIGNED_INT32 , 32, 4, TextureFormat::GENERIC_UINT ),
ADD_TEXTURE_FORMAT( DXGI_FORMAT_R32G32B32A32_SINT , CL_RGBA , CL_SIGNED_INT32 , 32, 4, TextureFormat::GENERIC_SINT ),
ADD_TEXTURE_FORMAT( DXGI_FORMAT_R16G16B16A16_FLOAT , CL_RGBA , CL_HALF_FLOAT , 16, 4, TextureFormat::GENERIC_FLOAT ),
ADD_TEXTURE_FORMAT( DXGI_FORMAT_R16G16B16A16_UNORM , CL_RGBA , CL_UNORM_INT16 , 16, 4, TextureFormat::GENERIC_FLOAT ),
ADD_TEXTURE_FORMAT( DXGI_FORMAT_R16G16B16A16_UINT , CL_RGBA , CL_UNSIGNED_INT16 , 16, 4, TextureFormat::GENERIC_UINT ),
ADD_TEXTURE_FORMAT( DXGI_FORMAT_R16G16B16A16_SNORM , CL_RGBA , CL_SNORM_INT16 , 16, 4, TextureFormat::GENERIC_FLOAT ),
ADD_TEXTURE_FORMAT( DXGI_FORMAT_R16G16B16A16_SINT , CL_RGBA , CL_SIGNED_INT16 , 16, 4, TextureFormat::GENERIC_SINT ),
ADD_TEXTURE_FORMAT( DXGI_FORMAT_R8G8B8A8_UNORM , CL_RGBA , CL_UNORM_INT8 , 8, 4, TextureFormat::GENERIC_FLOAT ),
ADD_TEXTURE_FORMAT( DXGI_FORMAT_R8G8B8A8_UINT , CL_RGBA , CL_UNSIGNED_INT8 , 8, 4, TextureFormat::GENERIC_UINT ),
ADD_TEXTURE_FORMAT( DXGI_FORMAT_R8G8B8A8_SNORM , CL_RGBA , CL_SNORM_INT8 , 8, 4, TextureFormat::GENERIC_FLOAT ),
ADD_TEXTURE_FORMAT( DXGI_FORMAT_R8G8B8A8_SINT , CL_RGBA , CL_SIGNED_INT8 , 8, 4, TextureFormat::GENERIC_SINT ),
ADD_TEXTURE_FORMAT( DXGI_FORMAT_R32G32_FLOAT , CL_RG , CL_FLOAT , 32, 2, TextureFormat::GENERIC_FLOAT ),
ADD_TEXTURE_FORMAT( DXGI_FORMAT_R32G32_UINT , CL_RG , CL_UNSIGNED_INT32 , 32, 2, TextureFormat::GENERIC_UINT ),
ADD_TEXTURE_FORMAT( DXGI_FORMAT_R32G32_SINT , CL_RG , CL_SIGNED_INT32 , 32, 2, TextureFormat::GENERIC_SINT ),
ADD_TEXTURE_FORMAT( DXGI_FORMAT_R16G16_FLOAT , CL_RG , CL_HALF_FLOAT , 16, 2, TextureFormat::GENERIC_FLOAT ),
ADD_TEXTURE_FORMAT( DXGI_FORMAT_R16G16_UNORM , CL_RG , CL_UNORM_INT16 , 16, 2, TextureFormat::GENERIC_FLOAT ),
ADD_TEXTURE_FORMAT( DXGI_FORMAT_R16G16_UINT , CL_RG , CL_UNSIGNED_INT16 , 16, 2, TextureFormat::GENERIC_UINT ),
ADD_TEXTURE_FORMAT( DXGI_FORMAT_R16G16_SNORM , CL_RG , CL_SNORM_INT16 , 16, 2, TextureFormat::GENERIC_FLOAT ),
ADD_TEXTURE_FORMAT( DXGI_FORMAT_R16G16_SINT , CL_RG , CL_SIGNED_INT16 , 16, 2, TextureFormat::GENERIC_SINT ),
ADD_TEXTURE_FORMAT( DXGI_FORMAT_R8G8_UNORM , CL_RG , CL_UNORM_INT8 , 8, 2, TextureFormat::GENERIC_FLOAT ),
ADD_TEXTURE_FORMAT( DXGI_FORMAT_R8G8_UINT , CL_RG , CL_UNSIGNED_INT8 , 8, 2, TextureFormat::GENERIC_UINT ),
ADD_TEXTURE_FORMAT( DXGI_FORMAT_R8G8_SNORM , CL_RG , CL_SNORM_INT8 , 8, 2, TextureFormat::GENERIC_FLOAT ),
ADD_TEXTURE_FORMAT( DXGI_FORMAT_R8G8_SINT , CL_RG , CL_SIGNED_INT8 , 8, 2, TextureFormat::GENERIC_SINT ),
ADD_TEXTURE_FORMAT( DXGI_FORMAT_R32_FLOAT , CL_R , CL_FLOAT , 32, 1, TextureFormat::GENERIC_FLOAT ),
ADD_TEXTURE_FORMAT( DXGI_FORMAT_R32_UINT , CL_R , CL_UNSIGNED_INT32 , 32, 1, TextureFormat::GENERIC_UINT ),
ADD_TEXTURE_FORMAT( DXGI_FORMAT_R32_SINT , CL_R , CL_SIGNED_INT32 , 32, 1, TextureFormat::GENERIC_SINT ),
ADD_TEXTURE_FORMAT( DXGI_FORMAT_R16_FLOAT , CL_R , CL_HALF_FLOAT , 16, 1, TextureFormat::GENERIC_FLOAT ),
ADD_TEXTURE_FORMAT( DXGI_FORMAT_R16_UNORM , CL_R , CL_UNORM_INT16 , 16, 1, TextureFormat::GENERIC_FLOAT ),
ADD_TEXTURE_FORMAT( DXGI_FORMAT_R16_UINT , CL_R , CL_UNSIGNED_INT16 , 16, 1, TextureFormat::GENERIC_UINT ),
ADD_TEXTURE_FORMAT( DXGI_FORMAT_R16_SNORM , CL_R , CL_SNORM_INT16 , 16, 1, TextureFormat::GENERIC_FLOAT ),
ADD_TEXTURE_FORMAT( DXGI_FORMAT_R16_SINT , CL_R , CL_SIGNED_INT16 , 16, 1, TextureFormat::GENERIC_SINT ),
ADD_TEXTURE_FORMAT( DXGI_FORMAT_R8_UNORM , CL_R , CL_UNORM_INT8 , 8, 1, TextureFormat::GENERIC_FLOAT ),
ADD_TEXTURE_FORMAT( DXGI_FORMAT_R8_UINT , CL_R , CL_UNSIGNED_INT8 , 8, 1, TextureFormat::GENERIC_UINT ),
ADD_TEXTURE_FORMAT( DXGI_FORMAT_R8_SNORM , CL_R , CL_SNORM_INT8 , 8, 1, TextureFormat::GENERIC_FLOAT ),
ADD_TEXTURE_FORMAT( DXGI_FORMAT_R8_SINT , CL_R , CL_SIGNED_INT8 , 8, 1, TextureFormat::GENERIC_SINT ),
};
UINT formatCount = sizeof(formats)/sizeof(formats[0]);
/*
*
* Logging and error reporting
*
*/
static struct
{
cl_int testCount;
cl_int passCount;
cl_int nonTestFailures;
cl_int inTest;
cl_int currentTestPass;
char currentTestName[1024];
} HarnessD3D11_testStats = {0};
void HarnessD3D11_TestBegin(const char* fmt, ...)
{
va_list ap;
va_start(ap, fmt);
vsprintf(HarnessD3D11_testStats.currentTestName, fmt, ap);
va_end(ap);
printf("[%s] ... ", HarnessD3D11_testStats.currentTestName);
HarnessD3D11_testStats.inTest = 1;
HarnessD3D11_testStats.currentTestPass = 1;
}
void HarnessD3D11_TestFail()
{
if (HarnessD3D11_testStats.inTest)
{
HarnessD3D11_testStats.currentTestPass = 0;
}
else
{
++HarnessD3D11_testStats.nonTestFailures;
}
}
void HarnessD3D11_TestEnd()
{
HarnessD3D11_testStats.inTest = 0;
HarnessD3D11_testStats.testCount += 1;
HarnessD3D11_testStats.passCount += HarnessD3D11_testStats.currentTestPass;
TestPrint("%s\n",
HarnessD3D11_testStats.currentTestPass ? "PASSED" : "FAILED");
}
void HarnessD3D11_TestStats()
{
TestPrint("PASSED %d of %d tests.\n", HarnessD3D11_testStats.passCount, HarnessD3D11_testStats.testCount);
if (HarnessD3D11_testStats.testCount > HarnessD3D11_testStats.passCount)
{
TestPrint("***FAILED***\n");
exit(1);
}
else
{
TestPrint("&&&& cl_khr_d3d11_sharing test PASSED\n");
}
exit(0);
}
/*
*
* Helper function
*
*/
cl_int HarnessD3D11_CreateKernelFromSource(
cl_kernel *outKernel,
cl_device_id device,
cl_context context,
const char *source,
const char *entrypoint)
{
cl_int status;
cl_kernel kernel = NULL;
// compile program
cl_program program = NULL;
{
const char *sourceTexts[] = {source};
size_t sourceLengths[] = {strlen(source) };
status = create_single_kernel_helper_create_program(context, &program, 1, &sourceTexts[0]);
TestRequire(
CL_SUCCESS == status,
"clCreateProgramWithSource failed");
}
status = clBuildProgram(
program,
0,
NULL,
NULL,
NULL,
NULL);
if (CL_SUCCESS != status)
{
char log[2048] = {0};
status = clGetProgramBuildInfo(
program,
device,
CL_PROGRAM_BUILD_LOG,
sizeof(log),
log,
NULL);
TestPrint("error: %s\n", log);
TestRequire(
CL_SUCCESS == status,
"Compilation error log:\n%s\n", log);
}
kernel = clCreateKernel(
program,
entrypoint,
&status);
TestRequire(
CL_SUCCESS == status,
"clCreateKernel failed");
clReleaseProgram(program);
*outKernel = kernel;
Cleanup:
return CL_SUCCESS;
}

View File

@@ -0,0 +1,221 @@
//
// 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 _HARNESS_H_
#define _HARNESS_H_
#define _CRT_SECURE_NO_WARNINGS
#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
#endif
#include <CL/cl.h>
#include <CL/cl_platform.h>
#include <CL/cl_d3d11.h>
#include <stdio.h>
#include "errorHelpers.h"
#include "../test_common/harness/kernelHelpers.h"
// #define log_info(...) printf(__VA_ARGS__)
// #define log_error(...) printf(__VA_ARGS__)
#define NonTestRequire(x, ...) \
do \
{ \
if (!(x) ) \
{ \
log_info("\n[assertion failed: %s at %s:%d]\n", #x, __FILE__, __LINE__); \
log_info("CATASTROPHIC NON-TEST ERROR: "); \
log_error(__VA_ARGS__); \
log_info("\n"); \
log_info("***FAILED***\n"); \
exit(1); \
} \
} while (0)
#define TestRequire(x, ...) \
do \
{ \
if (!(x) ) \
{ \
log_info("\n[assertion failed: %s at %s:%d]\n", #x, __FILE__, __LINE__); \
log_info("ERROR: "); \
log_error(__VA_ARGS__); \
log_info("\n"); \
HarnessD3D11_TestFail(); \
goto Cleanup; \
} \
} while (0)
#define TestPrint(...) \
do \
{ \
log_error(__VA_ARGS__); \
} while (0)
struct TextureFormat
{
DXGI_FORMAT format;
cl_channel_order channel_order;
cl_channel_type channel_type;
UINT bytesPerPixel;
enum
{
GENERIC_FLOAT = 0,
GENERIC_UINT = 1,
GENERIC_SINT = 2,
} generic;
const char *name_format;
const char *name_channel_order;
const char *name_channel_type;
};
extern TextureFormat formats[];
extern UINT formatCount;
#define MAX_REGISTERED_SUBRESOURCES 4 // limit to just make life easier
struct BufferProperties
{
UINT ByteWidth;
UINT BindFlags;
D3D11_USAGE Usage;
UINT CPUAccess;
const char* name_BindFlags;
const char* name_Usage;
const char* name_CPUAccess;
};
struct Texture2DSize
{
UINT Width;
UINT Height;
UINT MipLevels;
UINT ArraySize;
UINT SubResourceCount;
struct
{
UINT MipLevel;
UINT ArraySlice;
} subResources[MAX_REGISTERED_SUBRESOURCES];
UINT MiscFlags;
};
struct Texture3DSize
{
UINT Width;
UINT Height;
UINT Depth;
UINT MipLevels;
UINT SubResourceCount;
struct
{
UINT MipLevel;
} subResources[MAX_REGISTERED_SUBRESOURCES];
UINT MiscFlags;
};
void HarnessD3D11_Initialize(cl_platform_id platform);
cl_int HarnessD3D11_CreateDevice(
IDXGIAdapter* pAdapter,
ID3D11Device **ppDevice,
ID3D11DeviceContext** ppDC);
void HarnessD3D11_DestroyDevice();
void HarnessD3D11_TestBegin(const char* fmt, ...);
void HarnessD3D11_TestFail();
void HarnessD3D11_TestEnd();
void HarnessD3D11_TestStats();
void TestAdapterEnumeration(
cl_platform_id platform,
IDXGIAdapter* pAdapter,
ID3D11Device* pDevice,
cl_uint* num_devices);
void TestAdapterDevices(
cl_platform_id platform,
IDXGIAdapter* pAdapter,
ID3D11Device* pDevice,
ID3D11DeviceContext* pDC,
cl_uint num_devices);
void TestDevice(
cl_device_id device,
ID3D11Device* pDevice,
ID3D11DeviceContext* pDC);
bool TestDeviceContextCreate(
cl_device_id device,
ID3D11Device* pDevice,
cl_context* out_context,
cl_command_queue* out_command_queue);
void TestDeviceBuffer(
cl_context context,
cl_command_queue command_queue,
ID3D11Device* pDevice,
ID3D11DeviceContext* pDC);
void TestDeviceTexture2D(
cl_device_id device,
cl_context context,
cl_command_queue command_queue,
ID3D11Device* pDevice,
ID3D11DeviceContext* pDC);
void TestDeviceTexture3D(
cl_device_id device,
cl_context context,
cl_command_queue command_queue,
ID3D11Device* pDevice,
ID3D11DeviceContext* pDC);
void TestDeviceMisc(
cl_device_id device,
cl_context context,
cl_command_queue command_queue,
ID3D11Device* pDevice);
cl_int HarnessD3D11_CreateKernelFromSource(
cl_kernel *outKernel,
cl_device_id device,
cl_context context,
const char *source,
const char *entrypoint);
extern clGetDeviceIDsFromD3D11KHR_fn clGetDeviceIDsFromD3D11KHR;
extern clCreateFromD3D11BufferKHR_fn clCreateFromD3D11BufferKHR;
extern clCreateFromD3D11Texture2DKHR_fn clCreateFromD3D11Texture2DKHR;
extern clCreateFromD3D11Texture3DKHR_fn clCreateFromD3D11Texture3DKHR;
extern clEnqueueAcquireD3D11ObjectsKHR_fn clEnqueueAcquireD3D11ObjectsKHR;
extern clEnqueueReleaseD3D11ObjectsKHR_fn clEnqueueReleaseD3D11ObjectsKHR;
#endif

View File

@@ -0,0 +1,464 @@
//
// 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.
//
#if defined( _WIN32 )
#define _CRT_SECURE_NO_WARNINGS
#include <vector>
#include <algorithm>
#include "harness.h"
#include "../../test_common/harness/testHarness.h"
#include "../../test_common/harness/parseParameters.h"
int main(int argc, const char* argv[])
{
cl_int result;
cl_platform_id platform = NULL;
cl_uint num_devices_tested = 0;
argc = parseCustomParam(argc, argv);
// get the platforms to test
result = clGetPlatformIDs(1, &platform, NULL); NonTestRequire(result == CL_SUCCESS, "Failed to get any platforms.");
HarnessD3D11_Initialize(platform);
// for each adapter...
IDXGIFactory* pFactory = NULL;
HRESULT hr = CreateDXGIFactory(IID_IDXGIFactory, (void**)(&pFactory) );
NonTestRequire(SUCCEEDED(hr), "Failed to create DXGI factory.");
for (UINT adapter = 0;; ++adapter)
{
IDXGIAdapter* pAdapter = NULL;
ID3D11Device* pDevice = NULL;
ID3D11DeviceContext* pDC = NULL;
HRESULT hr = pFactory->EnumAdapters(adapter, &pAdapter);
if (FAILED(hr))
{
break;
}
// print data about the adapter
DXGI_ADAPTER_DESC desc;
hr = pAdapter->GetDesc(&desc);
NonTestRequire(SUCCEEDED(hr), "IDXGIAdapter::GetDesc failed.");
TestPrint("=====================================\n");
TestPrint("Testing DXGI Adapter and D3D11 Device\n");
TestPrint("Description=%ls, VendorID=%x, DeviceID=%x\n", desc.Description, desc.VendorId, desc.DeviceId);
TestPrint("=====================================\n");
// run the test on the adapter
HarnessD3D11_CreateDevice(pAdapter, &pDevice, &pDC);
cl_uint num_devices = 0;
// test adapter and device enumeration
TestAdapterEnumeration(platform, pAdapter, pDevice, &num_devices);
// if there were any devices found in enumeration, run the tests on them
if (num_devices)
{
TestAdapterDevices(platform, pAdapter, pDevice, pDC, num_devices);
}
num_devices_tested += num_devices;
// destroy the D3D11 device
if (pDevice)
{
HarnessD3D11_DestroyDevice();
}
pAdapter->Release();
}
pFactory->Release();
// allow the test to be waived in automation
// NonTestRequire(num_devices_tested, "No D3D11 compatible cl_device_ids were found.");
HarnessD3D11_TestStats();
}
void TestAdapterEnumeration(
cl_platform_id platform,
IDXGIAdapter* pAdapter,
ID3D11Device* pDevice,
cl_uint* num_devices)
{
cl_uint num_adapter_devices = 0;
cl_device_id* adapter_devices = NULL;
cl_uint num_device_devices = 0;
cl_device_id* device_devices = NULL;
cl_int result;
HarnessD3D11_TestBegin("cl_device_id Enumeration");
// get the cl_device_ids for the adapter
{
result = clGetDeviceIDsFromD3D11KHR(
platform,
CL_D3D11_DXGI_ADAPTER_KHR,
pAdapter,
CL_ALL_DEVICES_FOR_D3D11_KHR,
0,
NULL,
&num_adapter_devices);
TestRequire(
(result == CL_SUCCESS || result == CL_DEVICE_NOT_FOUND),
"clGetDeviceIDsFromD3D11KHR failed.");
if (result == CL_DEVICE_NOT_FOUND)
{
TestPrint("No devices found for adapter.\n");
}
else
{
// if there were devices, query them
adapter_devices = new cl_device_id[num_adapter_devices];
result = clGetDeviceIDsFromD3D11KHR(
platform,
CL_D3D11_DXGI_ADAPTER_KHR,
pAdapter,
CL_ALL_DEVICES_FOR_D3D11_KHR,
num_adapter_devices,
adapter_devices,
NULL);
TestRequire(
(result == CL_SUCCESS),
"clGetDeviceIDsFromD3D11KHR failed.");
}
}
// get the cl_device_ids for the device (if it was successfully created)
if (pDevice)
{
result = clGetDeviceIDsFromD3D11KHR(
platform,
CL_D3D11_DEVICE_KHR,
pDevice,
CL_ALL_DEVICES_FOR_D3D11_KHR,
0,
NULL,
&num_device_devices);
TestRequire(
(result == CL_SUCCESS || result == CL_DEVICE_NOT_FOUND),
"clGetDeviceIDsFromD3D11KHR failed.");
if (result == CL_DEVICE_NOT_FOUND)
{
TestPrint("No devices found for D3D device.\n");
}
else
{
// if there were devices, query them
device_devices = new cl_device_id[num_device_devices];
result = clGetDeviceIDsFromD3D11KHR(
platform,
CL_D3D11_DEVICE_KHR,
pDevice,
CL_ALL_DEVICES_FOR_D3D11_KHR,
num_device_devices,
device_devices,
NULL);
TestRequire(
(result == CL_SUCCESS),
"clGetDeviceIDsFromD3D11KHR failed.");
}
}
Cleanup:
if (adapter_devices)
{
delete[] adapter_devices;
}
if (device_devices)
{
delete[] device_devices;
}
*num_devices = num_device_devices;
HarnessD3D11_TestEnd();
}
void TestAdapterDevices(
cl_platform_id platform,
IDXGIAdapter* pAdapter,
ID3D11Device* pDevice,
ID3D11DeviceContext* pDC,
cl_uint num_devices_expected)
{
cl_int result;
cl_uint num_devices = 0;
cl_device_id* devices = NULL;
devices = new cl_device_id[num_devices_expected];
NonTestRequire(
devices,
"Memory allocation failure.");
result = clGetDeviceIDsFromD3D11KHR(
platform,
CL_D3D11_DEVICE_KHR,
pDevice,
CL_ALL_DEVICES_FOR_D3D11_KHR,
num_devices_expected,
devices,
&num_devices);
NonTestRequire(
(result == CL_SUCCESS),
"clGetDeviceIDsFromD3D11KHR failed.");
NonTestRequire(
(num_devices == num_devices_expected),
"clGetDeviceIDsFromD3D11KHR returned an unexpected number of devices.");
for (cl_uint i = 0; i < num_devices; ++i)
{
TestDevice(devices[i], pDevice, pDC);
}
}
void TestDevice(
cl_device_id device,
ID3D11Device* pDevice,
ID3D11DeviceContext* pDC)
{
char device_name[1024];
cl_int result = CL_SUCCESS;
cl_context context = NULL;
cl_command_queue command_queue = NULL;
ID3D11Device* clDevice = NULL;
cl_uint prefer_shared_resources;
result = clGetDeviceInfo(
device,
CL_DEVICE_NAME,
sizeof(device_name),
device_name,
NULL);
NonTestRequire(CL_SUCCESS == result, "clGetDeviceInfo with CL_DEVICE_NAME failed");
TestPrint("--------------------\n");
TestPrint("Testing cl_device_id\n");
TestPrint("Name=%s\n", device_name);
TestPrint("--------------------\n");
if (!TestDeviceContextCreate(device, pDevice, &context, &command_queue) )
{
return;
}
// make sure that we can query the shared resource preference
result = clGetContextInfo(
context,
CL_CONTEXT_D3D11_PREFER_SHARED_RESOURCES_KHR,
sizeof(prefer_shared_resources),
&prefer_shared_resources,
NULL);
NonTestRequire(CL_SUCCESS == result, "clGetContextInfo with CL_CONTEXT_D3D10_PREFER_SHARED_RESOURCES_KHR failed");
// run buffer tests
TestDeviceBuffer(
context,
command_queue,
pDevice,
pDC);
// run 2D texture tests
TestDeviceTexture2D(
device,
context,
command_queue,
pDevice,
pDC);
// run 3D texture tests
TestDeviceTexture3D(
device,
context,
command_queue,
pDevice,
pDC);
// run misc tests
TestDeviceMisc(
device,
context,
command_queue,
pDevice);
clReleaseContext(context);
clReleaseCommandQueue(command_queue);
}
bool TestDeviceContextCreate(
cl_device_id device,
ID3D11Device* pDevice,
cl_context* out_context,
cl_command_queue* out_command_queue)
{
cl_int result = CL_SUCCESS;
cl_context context = NULL;
cl_command_queue command_queue = NULL;
ID3D11Device* clDevice = NULL;
bool succeeded = false;
HarnessD3D11_TestBegin("Context creation");
cl_context_properties properties[5];
// create the context
properties[0] = (cl_context_properties)CL_CONTEXT_D3D11_DEVICE_KHR;
properties[1] = (cl_context_properties)pDevice;
properties[2] = (cl_context_properties)CL_CONTEXT_INTEROP_USER_SYNC;
properties[3] = (cl_context_properties)CL_TRUE;
properties[4] = (cl_context_properties)0;
context = clCreateContext(
properties,
1,
&device,
NULL,
NULL,
&result);
TestRequire(
(result == CL_SUCCESS),
"clCreateContext with CL_CONTEXT_D3D11_DEVICE_KHR failed");
result = clReleaseContext(context);
TestRequire(
(result == CL_SUCCESS),
"clReleaseContext with CL_CONTEXT_D3D11_DEVICE_KHR failed");
// create the context
properties[0] = (cl_context_properties)CL_CONTEXT_D3D11_DEVICE_KHR;
properties[1] = (cl_context_properties)pDevice;
properties[2] = (cl_context_properties)CL_CONTEXT_INTEROP_USER_SYNC;
properties[3] = (cl_context_properties)CL_FALSE;
properties[4] = (cl_context_properties)0;
context = clCreateContext(
properties,
1,
&device,
NULL,
NULL,
&result);
TestRequire(
(result == CL_SUCCESS),
"clCreateContext with CL_CONTEXT_D3D11_DEVICE_KHR failed");
result = clReleaseContext(context);
TestRequire(
(result == CL_SUCCESS),
"clReleaseContext with CL_CONTEXT_D3D11_DEVICE_KHR failed");
// create the context
properties[0] = (cl_context_properties)CL_CONTEXT_D3D11_DEVICE_KHR;
properties[1] = (cl_context_properties)pDevice;
properties[2] = (cl_context_properties)0;
context = clCreateContext(
properties,
1,
&device,
NULL,
NULL,
&result);
TestRequire(
(result == CL_SUCCESS),
"clCreateContext with CL_CONTEXT_D3D11_DEVICE_KHR failed");
// check CL_CONTEXT_D3D11_DEVICE_KHR
{
size_t param_value_size_ret;
result = clGetContextInfo(context, CL_CONTEXT_PROPERTIES, 0, NULL, &param_value_size_ret);
TestRequire(
(result == CL_SUCCESS),
"clGetContextInfo with CL_CONTEXT_PROPERTIES failed");
TestRequire(
((param_value_size_ret % sizeof(cl_context_properties)) == 0),
"param_value_size_ret is not a multiple of sizeof(cl_context_properties)");
std::vector<cl_context_properties> contextProperties(param_value_size_ret / sizeof(cl_context_properties));
result = clGetContextInfo(context, CL_CONTEXT_PROPERTIES, param_value_size_ret, &contextProperties[0], NULL);
TestRequire(
(result == CL_SUCCESS),
"clGetContextInfo with CL_CONTEXT_PROPERTIES failed");
TestRequire(contextProperties.size() % 2 == 1, "Property list size is not odd.");
TestRequire(contextProperties[contextProperties.size() - 1] == 0, "last property is not zero");
std::vector<cl_context_properties>::const_iterator iter;
for (iter = contextProperties.begin(); *iter != 0; iter+=2)
{
if (CL_CONTEXT_D3D11_DEVICE_KHR == *iter)
{
TestRequire((ID3D11Device*)*(iter+1) == pDevice, "CL_CONTEXT_D3D11_DEVICE_KHR returned invalid value");
break;
}
}
TestRequire((iter != contextProperties.end()), "CL_CONTEXT_PROPERTIES doesn't include CL_CONTEXT_D3D11_DEVICE_KHR");
}
// create the command queue
TestPrint("Creating a command queue.\n");
command_queue = clCreateCommandQueueWithProperties(
context,
device,
NULL,
&result);
TestRequire(
(result == CL_SUCCESS),
"clCreateContext with CL_CONTEXT_D3D11_DEVICE_KHR failed");
succeeded = true;
Cleanup:
if (succeeded)
{
*out_context = context;
*out_command_queue = command_queue;
}
else
{
if (context)
{
clReleaseContext(context);
}
if (command_queue)
{
clReleaseCommandQueue(command_queue);
}
}
HarnessD3D11_TestEnd();
return succeeded;
}
#else
#include "errorHelpers.h"
int main(int argc, char* argv[])
{
log_info( "Windows-specific test skipped.\n" );
return 0;
}
#endif

View File

@@ -0,0 +1,224 @@
//
// 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.
//
#define _CRT_SECURE_NO_WARNINGS
#include "harness.h"
void SubTestMiscMultipleCreates(
cl_context context,
cl_command_queue command_queue,
ID3D11Device* pDevice)
{
cl_mem mem[5] = {NULL, NULL, NULL, NULL, NULL};
ID3D11Buffer* pBuffer = NULL;
ID3D11Texture2D* pTexture = NULL;
HRESULT hr = S_OK;
cl_int result = CL_SUCCESS;
HarnessD3D11_TestBegin("Misc: Multiple Creates");
// create the D3D11 resources
{
D3D11_TEXTURE2D_DESC desc;
memset(&desc, 0, sizeof(desc) );
desc.Width = 256;
desc.Height = 256;
desc.MipLevels = 4;
desc.ArraySize = 4;
desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
desc.SampleDesc.Count = 1;
desc.SampleDesc.Quality = 0;
desc.Usage = D3D11_USAGE_DEFAULT;
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
desc.CPUAccessFlags = 0;
desc.MiscFlags = 0;
hr = pDevice->CreateTexture2D(&desc, NULL, &pTexture);
TestRequire(SUCCEEDED(hr), "Failed to create texture.");
}
// create the D3D11 buffer
{
D3D11_BUFFER_DESC desc = {0};
desc.ByteWidth = 1124;
desc.Usage = D3D11_USAGE_DEFAULT;
desc.CPUAccessFlags = 0;
desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
desc.MiscFlags = 0;
hr = pDevice->CreateBuffer(&desc, NULL, &pBuffer);
TestRequire(SUCCEEDED(hr), "Creating vertex buffer failed!");
}
mem[0] = clCreateFromD3D11BufferKHR(
context,
0,
pBuffer,
&result);
TestRequire(result == CL_SUCCESS, "clCreateFromD3D11BufferKHR");
mem[1] = clCreateFromD3D11BufferKHR(
context,
0,
pBuffer,
&result);
TestRequire(result == CL_INVALID_D3D11_RESOURCE_KHR, "clCreateFromD3D11BufferKHR succeeded when it shouldn't");
mem[2] = clCreateFromD3D11Texture2DKHR(
context,
0,
pTexture,
1,
&result);
TestRequire(result == CL_SUCCESS, "clCreateFromD3D11Texture2DKHR failed");
mem[3] = clCreateFromD3D11Texture2DKHR(
context,
0,
pTexture,
1,
&result);
TestRequire(result == CL_INVALID_D3D11_RESOURCE_KHR, "clCreateFromD3D11Texture2DKHR succeeded when it shouldn't");
mem[4] = clCreateFromD3D11Texture2DKHR(
context,
0,
pTexture,
16,
&result);
TestRequire(result == CL_INVALID_VALUE, "clCreateFromD3D11Texture2DKHR succeeded when it shouldn't");
Cleanup:
for (UINT i = 0; i < 4; ++i)
{
if (mem[i])
{
clReleaseMemObject(mem[i]);
}
}
if (pBuffer)
{
pBuffer->Release();
}
if (pTexture)
{
pTexture->Release();
}
HarnessD3D11_TestEnd();
}
void SubTestMiscAcquireRelease(
cl_device_id device,
cl_context context,
ID3D11Device* pDevice)
{
ID3D11Buffer* pBuffer = NULL;
ID3D11Texture2D* pTexture = NULL;
HRESULT hr = S_OK;
cl_int result = CL_SUCCESS;
cl_mem mem[2] = {NULL, NULL};
HarnessD3D11_TestBegin("Misc: Acquire Release");
// create the D3D11 resources
{
D3D11_TEXTURE2D_DESC desc;
memset(&desc, 0, sizeof(desc) );
desc.Width = 256;
desc.Height = 256;
desc.MipLevels = 4;
desc.ArraySize = 4;
desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
desc.SampleDesc.Count = 1;
desc.SampleDesc.Quality = 0;
desc.Usage = D3D11_USAGE_DEFAULT;
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
desc.CPUAccessFlags = 0;
desc.MiscFlags = 0;
hr = pDevice->CreateTexture2D(&desc, NULL, &pTexture);
TestRequire(SUCCEEDED(hr), "Failed to create texture.");
}
// create the D3D11 buffer
{
D3D11_BUFFER_DESC desc = {0};
desc.ByteWidth = 1124;
desc.Usage = D3D11_USAGE_DEFAULT;
desc.CPUAccessFlags = 0;
desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
desc.MiscFlags = 0;
hr = pDevice->CreateBuffer(&desc, NULL, &pBuffer);
TestRequire(SUCCEEDED(hr), "Creating vertex buffer failed!");
}
// create cl_mem objects for the resources
mem[0] = clCreateFromD3D11BufferKHR(
context,
0,
pBuffer,
&result);
TestRequire(result == CL_SUCCESS, "clCreateFromD3D11BufferKHR");
mem[1] = clCreateFromD3D11Texture2DKHR(
context,
0,
pTexture,
1,
&result);
TestRequire(result == CL_SUCCESS, "clCreateFromD3D11Texture2DKHR failed");
Cleanup:
for (UINT i = 0; i < 2; ++i)
{
if (mem[i])
{
clReleaseMemObject(mem[i]);
}
}
if (pBuffer)
{
pBuffer->Release();
}
if (pTexture)
{
pTexture->Release();
}
HarnessD3D11_TestEnd();
}
void TestDeviceMisc(
cl_device_id device,
cl_context context,
cl_command_queue command_queue,
ID3D11Device* pDevice)
{
SubTestMiscMultipleCreates(
context,
command_queue,
pDevice);
SubTestMiscAcquireRelease(
device,
context,
pDevice);
}

View File

@@ -0,0 +1,749 @@
//
// 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.
//
#define _CRT_SECURE_NO_WARNINGS
#include "harness.h"
#include <vector>
Texture2DSize texture2DSizes[] =
{
{
4, // Width
4, // Height
1, // MipLevels
1, // ArraySize
1, // SubResourceCount
{ // SubResources
{0, 0}, // MipLevel, ArraySlice
{0, 0}, // MipLevel, ArraySlice
{0, 0}, // MipLevel, ArraySlice
{0, 0}, // MipLevel, ArraySlice
},
0, // MiscFlags
},
{
15, // Width
37, // Height
2, // MipLevels
1, // ArraySize
2, // SubResourceCount
{ // SubResources
{0, 0}, // MipLevel, ArraySlice
{1, 0}, // MipLevel, ArraySlice
{0, 0}, // MipLevel, ArraySlice
{0, 0}, // MipLevel, ArraySlice
},
0, // MiscFlags
},
{
65, // Width
17, // Height
1, // MipLevels
1, // ArraySize
1, // SubResourceCount
{ // SubResources
{0, 0}, // MipLevel, ArraySlice
{0, 0}, // MipLevel, ArraySlice
{0, 0}, // MipLevel, ArraySlice
{0, 0}, // MipLevel, ArraySlice
},
D3D11_RESOURCE_MISC_SHARED, // MiscFlags
},
{
127, // Width
125, // Height
4, // MipLevels
1, // ArraySize
4, // SubResourceCount
{ // SubResources
{3, 0}, // MipLevel, ArraySlice
{2, 0}, // MipLevel, ArraySlice
{1, 0}, // MipLevel, ArraySlice
{0, 0}, // MipLevel, ArraySlice
},
0, // MiscFlags
},
{
128, // Width
128, // Height
4, // MipLevels
6, // ArraySize
4, // SubResourceCount
{ // SubResources
{0, 1}, // MipLevel, ArraySlice
{1, 0}, // MipLevel, ArraySlice
{0, 2}, // MipLevel, ArraySlice
{3, 5}, // MipLevel, ArraySlice
},
0, // MiscFlags
},
{
256, // Width
256, // Height
0, // MipLevels
256, // ArraySize
4, // SubResourceCount
{ // SubResources
{0, 0}, // MipLevel, ArraySlice
{1, 255}, // MipLevel, ArraySlice
{2, 127}, // MipLevel, ArraySlice
{3, 128}, // MipLevel, ArraySlice
},
0, // MiscFlags
},
{
258, // Width
511, // Height
1, // MipLevels
1, // ArraySize
1, // SubResourceCount
{ // SubResources
{0, 0}, // MipLevel, ArraySlice
{0, 0}, // MipLevel, ArraySlice
{0, 0}, // MipLevel, ArraySlice
{0, 0}, // MipLevel, ArraySlice
},
0, // MiscFlags
},
{
767, // Width
1025, // Height
4, // MipLevels
1, // ArraySize
1, // SubResourceCount
{ // SubResources
{0, 0}, // MipLevel, ArraySlice
{0, 0}, // MipLevel, ArraySlice
{0, 0}, // MipLevel, ArraySlice
{0, 0}, // MipLevel, ArraySlice
},
0, // MiscFlags
},
{
2048, // Width
2048, // Height
1, // MipLevels
1, // ArraySize
1, // SubResourceCount
{ // SubResources
{0, 0}, // MipLevel, ArraySlice
{0, 0}, // MipLevel, ArraySlice
{0, 0}, // MipLevel, ArraySlice
{0, 0}, // MipLevel, ArraySlice
},
0, // MiscFlags
},
};
UINT texture2DSizeCount = sizeof(texture2DSizes)/sizeof(texture2DSizes[0]);
const char *
texture2DPatterns[2][2] =
{
{"aAbBcCdDeEfFgGhHiIjJ", "AaBbCcDdEeFfGgHhIiJj"},
{"zZyYxXwWvVuUtTsSrRqQ", "ZzYyXxWwVvUuTtSsRrQq"},
};
void SubTestTexture2D(
cl_context context,
cl_command_queue command_queue,
cl_kernel kernel,
ID3D11Device* pDevice,
ID3D11DeviceContext* pDC,
const TextureFormat* format,
const Texture2DSize* size)
{
ID3D11Texture2D* pTexture = NULL;
HRESULT hr = S_OK;
cl_image_format clFormat;
cl_int result = CL_SUCCESS;
HarnessD3D11_TestBegin("2D Texture: Format=%s, Width=%d, Height=%d, MipLevels=%d, ArraySize=%d",
format->name_format,
size->Width,
size->Height,
size->MipLevels,
size->ArraySize);
struct
{
cl_mem mem;
UINT subResource;
UINT width;
UINT height;
}
subResourceInfo[4];
cl_event events[4] = {NULL, NULL, NULL, NULL};
// create the D3D11 resources
{
D3D11_TEXTURE2D_DESC desc;
memset(&desc, 0, sizeof(desc) );
desc.Width = size->Width;
desc.Height = size->Height;
desc.MipLevels = size->MipLevels;
desc.ArraySize = size->ArraySize;
desc.Format = format->format;
desc.SampleDesc.Count = 1;
desc.SampleDesc.Quality = 0;
desc.Usage = D3D11_USAGE_DEFAULT;
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
desc.CPUAccessFlags = 0;
desc.MiscFlags = 0;
hr = pDevice->CreateTexture2D(&desc, NULL, &pTexture);
TestRequire(SUCCEEDED(hr), "ID3D11Device::CreateTexture2D failed (non-OpenCL D3D error, but test is invalid).");
}
// initialize some useful variables
for (UINT i = 0; i < size->SubResourceCount; ++i)
{
// compute the expected values for the subresource
subResourceInfo[i].subResource = D3D11CalcSubresource(
size->subResources[i].MipLevel,
size->subResources[i].ArraySlice,
size->MipLevels);
subResourceInfo[i].width = size->Width;
subResourceInfo[i].height = size->Height;
for (UINT j = 0; j < size->subResources[i].MipLevel; ++j) {
subResourceInfo[i].width /= 2;
subResourceInfo[i].height /= 2;
}
subResourceInfo[i].mem = NULL;
}
// copy a pattern into the corners of the image, coordinates
// (0,0), (w,0-1), (0,h-1), (w-1,h-1)
for (UINT i = 0; i < size->SubResourceCount; ++i)
for (UINT x = 0; x < 2; ++x)
for (UINT y = 0; y < 2; ++y)
{
// create the staging buffer
ID3D11Texture2D* pStagingBuffer = NULL;
{
D3D11_TEXTURE2D_DESC desc = {0};
desc.Width = 1;
desc.Height = 1;
desc.MipLevels = 1;
desc.ArraySize = 1;
desc.Format = format->format;
desc.SampleDesc.Count = 1;
desc.SampleDesc.Quality = 0;
desc.Usage = D3D11_USAGE_STAGING;
desc.BindFlags = 0;
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
desc.MiscFlags = 0;
hr = pDevice->CreateTexture2D(&desc, NULL, &pStagingBuffer);
TestRequire(SUCCEEDED(hr), "ID3D11Device::CreateTexture2D failed (non-OpenCL D3D error, but test is invalid).");
}
// write the data to the staging buffer
{
D3D11_MAPPED_SUBRESOURCE mappedTexture;
hr = pDC->Map(
pStagingBuffer,
0,
D3D11_MAP_READ_WRITE,
0,
&mappedTexture);
memcpy(mappedTexture.pData, texture2DPatterns[x][y], format->bytesPerPixel);
pDC->Unmap(pStagingBuffer, 0);
}
// copy the data to to the texture
{
D3D11_BOX box = {0};
box.front = 0; box.back = 1;
box.top = 0; box.bottom = 1;
box.left = 0; box.right = 1;
pDC->CopySubresourceRegion(
pTexture,
subResourceInfo[i].subResource,
x ? subResourceInfo[i].width - 1 : 0,
y ? subResourceInfo[i].height - 1 : 0,
0,
pStagingBuffer,
0,
&box);
}
pStagingBuffer->Release();
}
// create the cl_mem objects for the resources and verify its sanity
for (UINT i = 0; i < size->SubResourceCount; ++i)
{
// create a cl_mem for the resource
subResourceInfo[i].mem = clCreateFromD3D11Texture2DKHR(
context,
0,
pTexture,
subResourceInfo[i].subResource,
&result);
if (CL_IMAGE_FORMAT_NOT_SUPPORTED == result)
{
goto Cleanup;
}
TestRequire(result == CL_SUCCESS, "clCreateFromD3D11Texture2DKHR failed");
// query resource pointer and verify
ID3D11Resource* clResource = NULL;
result = clGetMemObjectInfo(
subResourceInfo[i].mem,
CL_MEM_D3D11_RESOURCE_KHR,
sizeof(clResource),
&clResource,
NULL);
TestRequire(result == CL_SUCCESS, "clGetMemObjectInfo for CL_MEM_D3D11_RESOURCE_KHR failed.");
TestRequire(clResource == pTexture, "clGetMemObjectInfo for CL_MEM_D3D11_RESOURCE_KHR returned incorrect value.");
// query subresource and verify
UINT clSubResource;
result = clGetImageInfo(
subResourceInfo[i].mem,
CL_IMAGE_D3D11_SUBRESOURCE_KHR,
sizeof(clSubResource),
&clSubResource,
NULL);
TestRequire(result == CL_SUCCESS, "clGetImageInfo for CL_IMAGE_D3D11_SUBRESOURCE_KHR failed");
TestRequire(clSubResource == subResourceInfo[i].subResource, "clGetImageInfo for CL_IMAGE_D3D11_SUBRESOURCE_KHR returned incorrect value.");
// query format and verify
result = clGetImageInfo(
subResourceInfo[i].mem,
CL_IMAGE_FORMAT,
sizeof(clFormat),
&clFormat,
NULL);
TestRequire(result == CL_SUCCESS, "clGetImageInfo for CL_IMAGE_FORMAT failed");
TestRequire(clFormat.image_channel_order == format->channel_order, "clGetImageInfo for CL_IMAGE_FORMAT returned incorrect channel order.");
TestRequire(clFormat.image_channel_data_type == format->channel_type, "clGetImageInfo for CL_IMAGE_FORMAT returned incorrect channel data type.");
// query width
size_t width;
result = clGetImageInfo(
subResourceInfo[i].mem,
CL_IMAGE_WIDTH,
sizeof(width),
&width,
NULL);
TestRequire(result == CL_SUCCESS, "clGetImageInfo for CL_IMAGE_WIDTH failed");
TestRequire(width == subResourceInfo[i].width, "clGetImageInfo for CL_IMAGE_HEIGHT returned incorrect value.");
// query height
size_t height;
result = clGetImageInfo(
subResourceInfo[i].mem,
CL_IMAGE_HEIGHT,
sizeof(height),
&height,
NULL);
TestRequire(result == CL_SUCCESS, "clGetImageInfo for CL_IMAGE_HEIGHT failed");
TestRequire(height == subResourceInfo[i].height, "clGetImageInfo for CL_IMAGE_HEIGHT returned incorrect value.");
}
// acquire the resources for OpenCL
for (UINT i = 0; i < 2; ++i)
{
cl_uint memCount = 0;
cl_mem memToAcquire[MAX_REGISTERED_SUBRESOURCES];
// cut the registered sub-resources into two sets and send the acquire calls for them separately
if (i == 0)
{
for(UINT j = 0; j < size->SubResourceCount/2; ++j)
{
memToAcquire[memCount++] = subResourceInfo[j].mem;
}
}
else
{
for(UINT j = size->SubResourceCount/2; j < size->SubResourceCount; ++j)
{
memToAcquire[memCount++] = subResourceInfo[j].mem;
}
}
if (!memCount) continue;
// do the acquire
result = clEnqueueAcquireD3D11ObjectsKHR(
command_queue,
memCount,
memToAcquire,
0,
NULL,
&events[0+i]);
TestRequire(result == CL_SUCCESS, "clEnqueueAcquireD3D11ObjectsKHR failed.");
TestRequire(events[0+i], "clEnqueueAcquireD3D11ObjectsKHR did not return an event.");
// make sure the event type is correct
cl_uint eventType = 0;
result = clGetEventInfo(
events[0+i],
CL_EVENT_COMMAND_TYPE,
sizeof(eventType),
&eventType,
NULL);
TestRequire(result == CL_SUCCESS, "clGetEventInfo for event created by clEnqueueAcquireD3D11ObjectsKHR failed.");
TestRequire(eventType == CL_COMMAND_ACQUIRE_D3D11_OBJECTS_KHR, "clGetEventInfo for CL_EVENT_COMMAND_TYPE was not CL_COMMAND_ACQUIRE_D3D11_OBJECTS_KHR.");
}
// download the data using OpenCL & compare with the expected results
for (UINT i = 0; i < size->SubResourceCount; ++i)
{
size_t origin[3] = {0,0,0};
size_t region[3] = {subResourceInfo[i].width, subResourceInfo[i].height, 1};
cl_mem tempImage;
cl_image_desc image_desc = { 0 };
image_desc.image_depth = 1;
image_desc.image_height = subResourceInfo[i].height;
image_desc.image_width = subResourceInfo[i].width;
image_desc.image_type = CL_MEM_OBJECT_IMAGE2D;
tempImage = clCreateImage(context, 0, &clFormat, &image_desc, NULL, &result);
TestRequire(result == CL_SUCCESS, "clCreateImage failed");
result = clEnqueueCopyImage(command_queue, subResourceInfo[i].mem, tempImage,
origin, origin, region, 0, NULL, NULL);
TestRequire(result == CL_SUCCESS, "clEnqueueCopyImage failed");
// copy (0,0) to (1,1) and (w-1,h-1) to (w-2,h-2) using a kernel
{
result = clSetKernelArg(
kernel,
0,
sizeof(cl_mem),
(void *)&tempImage);
result = clSetKernelArg(
kernel,
1,
sizeof(cl_mem),
(void *)&subResourceInfo[i].mem);
TestRequire(CL_SUCCESS == result, "clSetKernelArg failed");
size_t localWorkSize[] = {1};
size_t globalWorkSize[] = {1};
result = clEnqueueNDRangeKernel(
command_queue,
kernel,
1,
NULL,
globalWorkSize,
localWorkSize,
0,
NULL,
NULL);
TestRequire(CL_SUCCESS == result, "clEnqueueNDRangeKernel failed");
}
// copy (w-1,0) to (w-2,1) and (0,h) to (1,h-2) using a memcpy
for (UINT x = 0; x < 2; ++x)
for (UINT y = 0; y < 2; ++y)
{
if (x == y)
{
continue;
}
size_t src[3] =
{
x ? subResourceInfo[i].width - 1 : 0,
y ? subResourceInfo[i].height - 1 : 0,
0,
};
size_t dst[3] =
{
x ? subResourceInfo[i].width - 2 : 1,
y ? subResourceInfo[i].height - 2 : 1,
0,
};
size_t region[3] =
{
1,
1,
1,
};
result = clEnqueueCopyImage(
command_queue,
subResourceInfo[i].mem,
subResourceInfo[i].mem,
src,
dst,
region,
0,
NULL,
NULL);
TestRequire(result == CL_SUCCESS, "clEnqueueCopyImage failed.");
}
clReleaseMemObject(tempImage);
}
// release the resource from OpenCL
for (UINT i = 0; i < 2; ++i)
{
cl_uint memCount = 0;
cl_mem memToAcquire[MAX_REGISTERED_SUBRESOURCES];
// cut the registered sub-resources into two sets and send the release calls for them separately
if (i == 0)
{
for(UINT j = size->SubResourceCount/4; j < size->SubResourceCount; ++j)
{
memToAcquire[memCount++] = subResourceInfo[j].mem;
}
}
else
{
for(UINT j = 0; j < size->SubResourceCount/4; ++j)
{
memToAcquire[memCount++] = subResourceInfo[j].mem;
}
}
if (!memCount) continue;
// do the release
result = clEnqueueReleaseD3D11ObjectsKHR(
command_queue,
memCount,
memToAcquire,
0,
NULL,
&events[2+i]);
TestRequire(result == CL_SUCCESS, "clEnqueueReleaseD3D11ObjectsKHR failed.");
TestRequire(events[2+i], "clEnqueueReleaseD3D11ObjectsKHR did not return an event.");
// make sure the event type is correct
cl_uint eventType = 0;
result = clGetEventInfo(
events[2+i],
CL_EVENT_COMMAND_TYPE,
sizeof(eventType),
&eventType,
NULL);
TestRequire(result == CL_SUCCESS, "clGetEventInfo for event created by clEnqueueReleaseD3D11ObjectsKHR failed.");
TestRequire(eventType == CL_COMMAND_RELEASE_D3D11_OBJECTS_KHR, "clGetEventInfo for CL_EVENT_COMMAND_TYPE was not CL_COMMAND_RELEASE_D3D11_OBJECTS_KHR.");
}
for (UINT i = 0; i < size->SubResourceCount; ++i)
for (UINT x = 0; x < 2; ++x)
for (UINT y = 0; y < 2; ++y)
{
// create the staging buffer
ID3D11Texture2D* pStagingBuffer = NULL;
{
D3D11_TEXTURE2D_DESC desc = {0};
desc.Width = 1;
desc.Height = 1;
desc.MipLevels = 1;
desc.ArraySize = 1;
desc.Format = format->format;
desc.SampleDesc.Count = 1;
desc.SampleDesc.Quality = 0;
desc.Usage = D3D11_USAGE_STAGING;
desc.BindFlags = 0;
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
desc.MiscFlags = 0;
hr = pDevice->CreateTexture2D(&desc, NULL, &pStagingBuffer);
TestRequire(SUCCEEDED(hr), "Failed to create staging buffer.");
}
// wipe out the staging buffer to make sure we don't get stale values
{
D3D11_MAPPED_SUBRESOURCE mappedTexture;
hr = pDC->Map(
pStagingBuffer,
0,
D3D11_MAP_READ_WRITE,
0,
&mappedTexture);
TestRequire(SUCCEEDED(hr), "Failed to map staging buffer");
memset(mappedTexture.pData, 0, format->bytesPerPixel);
pDC->Unmap(pStagingBuffer, 0);
}
// copy the pixel to the staging buffer
{
D3D11_BOX box = {0};
box.left = x ? subResourceInfo[i].width - 2 : 1; box.right = box.left + 1;
box.top = y ? subResourceInfo[i].height - 2 : 1; box.bottom = box.top + 1;
box.front = 0; box.back = 1;
pDC->CopySubresourceRegion(
pStagingBuffer,
0,
0,
0,
0,
pTexture,
subResourceInfo[i].subResource,
&box);
}
// make sure we read back what was written next door
{
D3D11_MAPPED_SUBRESOURCE mappedTexture;
hr = pDC->Map(
pStagingBuffer,
0,
D3D11_MAP_READ_WRITE,
0,
&mappedTexture);
TestRequire(SUCCEEDED(hr), "Failed to map staging buffer");
TestRequire(
!memcmp(mappedTexture.pData, texture2DPatterns[x][y], format->bytesPerPixel),
"Failed to map staging buffer");
pDC->Unmap(pStagingBuffer, 0);
}
pStagingBuffer->Release();
}
Cleanup:
if (pTexture)
{
pTexture->Release();
}
for (UINT i = 0; i < size->SubResourceCount; ++i)
{
clReleaseMemObject(subResourceInfo[i].mem);
}
for (UINT i = 0; i < 4; ++i)
{
if (events[i])
{
result = clReleaseEvent(events[i]);
TestRequire(result == CL_SUCCESS, "clReleaseEvent for event failed.");
}
}
HarnessD3D11_TestEnd();
}
bool is_format_supported(
cl_channel_order channel_order,
cl_channel_type channel_type,
const std::vector<cl_image_format> &supported_image_formats)
{
for (std::vector<cl_image_format>::const_iterator it = supported_image_formats.begin(); it != supported_image_formats.end(); ++it)
if (it->image_channel_data_type == channel_type && it->image_channel_order == channel_order)
return true;
return false;
}
void TestDeviceTexture2D(
cl_device_id device,
cl_context context,
cl_command_queue command_queue,
ID3D11Device* pDevice,
ID3D11DeviceContext* pDC)
{
cl_int result = CL_SUCCESS;
cl_kernel kernels[3] = {NULL, NULL, NULL};
const char *sourceRaw =
" \
__kernel void texture2D\n\
( \n\
__read_only image2d_t texIn, \n\
__write_only image2d_t texOut \n\
) \n\
{ \n\
const sampler_t smp = CLK_FILTER_NEAREST; \n\
CLK_NORMALIZED_COORDS_FALSE |\n\
CLK_ADDRESS_CLAMP_TO_EDGE; \n\
%s value; \n\
int2 coordIn; \n\
int2 coordOut; \n\
int w = get_image_width(texIn); \n\
int h = get_image_height(texIn); \n\
\n\
coordIn = (int2)(0, 0); \n\
coordOut = (int2)(1, 1); \n\
value = read_image%s(texIn, smp, coordIn); \n\
write_image%s(texOut, coordOut, value); \n\
\n\
coordIn = (int2)(w-1, h-1); \n\
coordOut = (int2)(w-2, h-2); \n\
value = read_image%s(texIn, smp, coordIn); \n\
write_image%s(texOut, coordOut, value); \n\
} \n\
";
cl_uint supported_formats_count;
std::vector<cl_image_format> supported_image_formats;
result = clGetSupportedImageFormats(context, CL_MEM_READ_ONLY, CL_MEM_OBJECT_IMAGE2D, 0, NULL, &supported_formats_count);
TestRequire(CL_SUCCESS == result, "clGetSupportedImageFormats failed.");
supported_image_formats.resize(supported_formats_count);
result = clGetSupportedImageFormats(context, CL_MEM_READ_ONLY, CL_MEM_OBJECT_IMAGE2D, supported_formats_count, &supported_image_formats[0], NULL);
TestRequire(CL_SUCCESS == result, "clGetSupportedImageFormats failed.");
char source[2048];
sprintf(source, sourceRaw, "float4", "f", "f", "f", "f");
result = HarnessD3D11_CreateKernelFromSource(&kernels[0], device, context, source, "texture2D");
TestRequire(CL_SUCCESS == result, "HarnessD3D11_CreateKernelFromSource failed.");
sprintf(source, sourceRaw, "uint4", "ui", "ui", "ui", "ui");
result = HarnessD3D11_CreateKernelFromSource(&kernels[1], device, context, source, "texture2D");
TestRequire(CL_SUCCESS == result, "HarnessD3D11_CreateKernelFromSource failed.");
sprintf(source, sourceRaw, "int4", "i", "i", "i", "i");
result = HarnessD3D11_CreateKernelFromSource(&kernels[2], device, context, source, "texture2D");
TestRequire(CL_SUCCESS == result, "HarnessD3D11_CreateKernelFromSource failed.");
for (UINT format = 0, size = 0; format < formatCount; ++size, ++format)
{
if (!is_format_supported(formats[format].channel_order, formats[format].channel_type, supported_image_formats))
{
HarnessD3D11_TestBegin("2D_texture: Format=%s, Width=%d, Height=%d, MipLevels=%d, ArraySize=%d\n",
formats[format].name_format,
texture2DSizes[size % texture2DSizeCount].Width,
texture2DSizes[size % texture2DSizeCount].Height,
texture2DSizes[size % texture2DSizeCount].MipLevels,
texture2DSizes[size % texture2DSizeCount].ArraySize);
log_info("\tFormat not supported, skipping test!\n");
HarnessD3D11_TestEnd();
continue;
}
SubTestTexture2D(
context,
command_queue,
kernels[formats[format].generic],
pDevice,
pDC,
&formats[format],
&texture2DSizes[size % texture2DSizeCount]);
}
Cleanup:
for (UINT i = 0; i < 3; ++i)
{
if (kernels[i])
{
clReleaseKernel(kernels[i]);
}
}
}

View File

@@ -0,0 +1,489 @@
//
// 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.
//
#define _CRT_SECURE_NO_WARNINGS
#include "harness.h"
Texture3DSize texture3DSizes[] =
{
{
4, // Width
4, // Height
4, // Depth
1, // MipLevels
1, // SubResourceCount
{ // SubResources
{ 0 }, // MipLevel
{ 0 }, // MipLevel
{ 0 }, // MipLevel
{ 0 }, // MipLevel
},
0, // MiscFlags
},
{
127, // Width
55, // Height
33, // Depth
1, // MipLevels
1, // SubResourceCount
{ // SubResources
{ 0 }, // MipLevel
{ 0 }, // MipLevel
{ 0 }, // MipLevel
{ 0 }, // MipLevel
},
0, // MiscFlags
},
{
128, // Width
256, // Height
64, // Depth
4, // MipLevels
3, // SubResourceCount
{ // SubResources
{ 2 }, // MipLevel
{ 1 }, // MipLevel
{ 0 }, // MipLevel
{ 0 }, // MipLevel
},
0, // MiscFlags
},
{
512, // Width
64, // Height
32, // Depth
3, // MipLevels
1, // SubResourceCount
{ // SubResources
{ 2 }, // MipLevel
{ 0 }, // MipLevel
{ 0 }, // MipLevel
{ 0 }, // MipLevel
},
0, // MiscFlags
},
};
UINT texture3DSizeCount = sizeof(texture3DSizes)/sizeof(texture3DSizes[0]);
const char *
texture3DPatterns[2][2][2] =
{
{
{"PlaceTheCasseroleDis", "hInAColdOvenPlaceACh"},
{"airFacingTheOvenAndS", "itInItForeverThinkAb"},
},
{
{"outHowHungryYouAreWh", "enNightFallsDoNotTur"},
{"nOnTheLightMyEyeBeca", "meInflamedIHateCamus"},
},
};
void SubTestTexture3D(
cl_context context,
cl_command_queue command_queue,
ID3D11Device* pDevice,
ID3D11DeviceContext* pDC,
const TextureFormat* format,
const Texture3DSize* size)
{
ID3D11Texture3D* pTexture = NULL;
HRESULT hr = S_OK;
cl_int result = CL_SUCCESS;
HarnessD3D11_TestBegin("3D Texture: Format=%s, Width=%d, Height=%d, Depth=%d, MipLevels=%d",
format->name_format,
size->Width,
size->Height,
size->Depth,
size->MipLevels);
struct
{
cl_mem mem;
UINT subResource;
UINT width;
UINT height;
UINT depth;
}
subResourceInfo[4];
// create the D3D11 resources
{
D3D11_TEXTURE3D_DESC desc;
memset(&desc, 0, sizeof(desc) );
desc.Width = size->Width;
desc.Height = size->Height;
desc.Depth = size->Depth;
desc.MipLevels = size->MipLevels;
desc.Format = format->format;
desc.Usage = D3D11_USAGE_DEFAULT;
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
desc.CPUAccessFlags = 0;
desc.MiscFlags = 0;
hr = pDevice->CreateTexture3D(&desc, NULL, &pTexture);
TestRequire(SUCCEEDED(hr), "CreateTexture3D failed.");
}
// initialize some useful variables
for (UINT i = 0; i < size->SubResourceCount; ++i)
{
// compute the expected values for the subresource
subResourceInfo[i].subResource = size->subResources[i].MipLevel;
subResourceInfo[i].width = size->Width;
subResourceInfo[i].height = size->Height;
subResourceInfo[i].depth = size->Depth;
for (UINT j = 0; j < size->subResources[i].MipLevel; ++j) {
subResourceInfo[i].width /= 2;
subResourceInfo[i].height /= 2;
subResourceInfo[i].depth /= 2;
}
subResourceInfo[i].mem = NULL;
}
// copy a pattern into the corners of the image, coordinates
for (UINT i = 0; i < size->SubResourceCount; ++i)
for (UINT x = 0; x < 2; ++x)
for (UINT y = 0; y < 2; ++y)
for (UINT z = 0; z < 2; ++z)
{
// create the staging buffer
ID3D11Texture3D* pStagingBuffer = NULL;
{
D3D11_TEXTURE3D_DESC desc = {0};
desc.Width = 1;
desc.Height = 1;
desc.Depth = 1;
desc.MipLevels = 1;
desc.Format = format->format;
desc.Usage = D3D11_USAGE_STAGING;
desc.BindFlags = 0;
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
desc.MiscFlags = 0;
hr = pDevice->CreateTexture3D(&desc, NULL, &pStagingBuffer);
TestRequire(SUCCEEDED(hr), "CreateTexture3D failed.");
}
// write the data to the staging buffer
{
D3D11_MAPPED_SUBRESOURCE mappedTexture;
hr = pDC->Map(
pStagingBuffer,
0,
D3D11_MAP_READ_WRITE,
0,
&mappedTexture);
memcpy(mappedTexture.pData, texture3DPatterns[x][y][z], format->bytesPerPixel);
pDC->Unmap(pStagingBuffer, 0);
}
// copy the data to to the texture
{
D3D11_BOX box = {0};
box.front = 0; box.back = 1;
box.top = 0; box.bottom = 1;
box.left = 0; box.right = 1;
pDC->CopySubresourceRegion(
pTexture,
subResourceInfo[i].subResource,
x ? subResourceInfo[i].width - 1 : 0,
y ? subResourceInfo[i].height - 1 : 0,
z ? subResourceInfo[i].depth - 1 : 0,
pStagingBuffer,
0,
&box);
}
pStagingBuffer->Release();
}
// create the cl_mem objects for the resources and verify its sanity
for (UINT i = 0; i < size->SubResourceCount; ++i)
{
// create a cl_mem for the resource
subResourceInfo[i].mem = clCreateFromD3D11Texture3DKHR(
context,
0,
pTexture,
subResourceInfo[i].subResource,
&result);
if (CL_IMAGE_FORMAT_NOT_SUPPORTED == result)
{
goto Cleanup;
}
TestRequire(result == CL_SUCCESS, "clCreateFromD3D11Texture3DKHR failed");
// query resource pointer and verify
ID3D11Resource* clResource = NULL;
result = clGetMemObjectInfo(
subResourceInfo[i].mem,
CL_MEM_D3D11_RESOURCE_KHR,
sizeof(clResource),
&clResource,
NULL);
TestRequire(result == CL_SUCCESS, "clGetMemObjectInfo for CL_MEM_D3D11_RESOURCE_KHR failed.");
TestRequire(clResource == pTexture, "clGetMemObjectInfo for CL_MEM_D3D11_RESOURCE_KHR returned incorrect value.");
// query subresource and verify
UINT clSubResource;
result = clGetImageInfo(
subResourceInfo[i].mem,
CL_IMAGE_D3D11_SUBRESOURCE_KHR,
sizeof(clSubResource),
&clSubResource,
NULL);
TestRequire(result == CL_SUCCESS, "clGetImageInfo for CL_IMAGE_D3D11_SUBRESOURCE_KHR failed");
TestRequire(clSubResource == subResourceInfo[i].subResource, "clGetImageInfo for CL_IMAGE_D3D11_SUBRESOURCE_KHR returned incorrect value.");
// query format and verify
cl_image_format clFormat;
result = clGetImageInfo(
subResourceInfo[i].mem,
CL_IMAGE_FORMAT,
sizeof(clFormat),
&clFormat,
NULL);
TestRequire(result == CL_SUCCESS, "clGetImageInfo for CL_IMAGE_FORMAT failed");
TestRequire(clFormat.image_channel_order == format->channel_order, "clGetImageInfo for CL_IMAGE_FORMAT returned incorrect channel order.");
TestRequire(clFormat.image_channel_data_type == format->channel_type, "clGetImageInfo for CL_IMAGE_FORMAT returned incorrect channel data type.");
// query width
size_t width;
result = clGetImageInfo(
subResourceInfo[i].mem,
CL_IMAGE_WIDTH,
sizeof(width),
&width,
NULL);
TestRequire(result == CL_SUCCESS, "clGetImageInfo for CL_IMAGE_WIDTH failed");
TestRequire(width == subResourceInfo[i].width, "clGetImageInfo for CL_IMAGE_HEIGHT returned incorrect value.");
// query height
size_t height;
result = clGetImageInfo(
subResourceInfo[i].mem,
CL_IMAGE_HEIGHT,
sizeof(height),
&height,
NULL);
TestRequire(result == CL_SUCCESS, "clGetImageInfo for CL_IMAGE_HEIGHT failed");
TestRequire(height == subResourceInfo[i].height, "clGetImageInfo for CL_IMAGE_HEIGHT returned incorrect value.");
// query depth
size_t depth;
result = clGetImageInfo(
subResourceInfo[i].mem,
CL_IMAGE_DEPTH,
sizeof(depth),
&depth,
NULL);
TestRequire(result == CL_SUCCESS, "clGetImageInfo for CL_IMAGE_DEPTH failed");
TestRequire(depth == subResourceInfo[i].depth, "clGetImageInfo for CL_IMAGE_DEPTH returned incorrect value.");
}
// acquire the resources for OpenCL
{
cl_mem memToAcquire[MAX_REGISTERED_SUBRESOURCES];
// cut the registered sub-resources into two sets and send the acquire calls for them separately
for(UINT i = 0; i < size->SubResourceCount; ++i)
{
memToAcquire[i] = subResourceInfo[i].mem;
}
// do the acquire
result = clEnqueueAcquireD3D11ObjectsKHR(
command_queue,
size->SubResourceCount,
memToAcquire,
0,
NULL,
NULL);
TestRequire(result == CL_SUCCESS, "clEnqueueAcquireD3D11ObjectsKHR failed.");
}
// download the data using OpenCL & compare with the expected results
// copy the corners of the image into the image
for (UINT i = 0; i < size->SubResourceCount; ++i)
for (UINT x = 0; x < 2; ++x)
for (UINT y = 0; y < 2; ++y)
for (UINT z = 0; z < 2; ++z)
{
if (x == y && y == z && 0)
{
continue;
}
size_t src[3] =
{
x ? subResourceInfo[i].width - 1 : 0,
y ? subResourceInfo[i].height - 1 : 0,
z ? subResourceInfo[i].depth - 1 : 0,
};
size_t dst[3] =
{
x ? subResourceInfo[i].width - 2 : 1,
y ? subResourceInfo[i].height - 2 : 1,
z ? subResourceInfo[i].depth - 2 : 1,
};
size_t region[3] =
{
1,
1,
1,
};
result = clEnqueueCopyImage(
command_queue,
subResourceInfo[i].mem,
subResourceInfo[i].mem,
src,
dst,
region,
0,
NULL,
NULL);
TestRequire(result == CL_SUCCESS, "clEnqueueCopyImage failed.");
}
// release the resource from OpenCL
{
cl_mem memToAcquire[MAX_REGISTERED_SUBRESOURCES];
for(UINT i = 0; i < size->SubResourceCount; ++i)
{
memToAcquire[i] = subResourceInfo[i].mem;
}
// do the release
result = clEnqueueReleaseD3D11ObjectsKHR(
command_queue,
size->SubResourceCount,
memToAcquire,
0,
NULL,
NULL);
TestRequire(result == CL_SUCCESS, "clEnqueueReleaseD3D11ObjectsKHR failed.");
}
for (UINT i = 0; i < size->SubResourceCount; ++i)
for (UINT x = 0; x < 2; ++x)
for (UINT y = 0; y < 2; ++y)
for (UINT z = 0; z < 2; ++z)
{
// create the staging buffer
ID3D11Texture3D* pStagingBuffer = NULL;
{
D3D11_TEXTURE3D_DESC desc = {0};
desc.Width = 1;
desc.Height = 1;
desc.Depth = 1;
desc.MipLevels = 1;
desc.Format = format->format;
desc.Usage = D3D11_USAGE_STAGING;
desc.BindFlags = 0;
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
desc.MiscFlags = 0;
hr = pDevice->CreateTexture3D(&desc, NULL, &pStagingBuffer);
TestRequire(SUCCEEDED(hr), "Failed to create staging buffer.");
}
// wipe out the staging buffer to make sure we don't get stale values
{
D3D11_MAPPED_SUBRESOURCE mappedTexture;
hr = pDC->Map(
pStagingBuffer,
0,
D3D11_MAP_READ_WRITE,
0,
&mappedTexture);
TestRequire(SUCCEEDED(hr), "Failed to map staging buffer");
memset(mappedTexture.pData, 0, format->bytesPerPixel);
pDC->Unmap(pStagingBuffer, 0);
}
// copy the pixel to the staging buffer
{
D3D11_BOX box = {0};
box.left = x ? subResourceInfo[i].width - 2 : 1; box.right = box.left + 1;
box.top = y ? subResourceInfo[i].height - 2 : 1; box.bottom = box.top + 1;
box.front = z ? subResourceInfo[i].depth - 2 : 1; box.back = box.front + 1;
pDC->CopySubresourceRegion(
pStagingBuffer,
0,
0,
0,
0,
pTexture,
subResourceInfo[i].subResource,
&box);
}
// make sure we read back what was written next door
{
D3D11_MAPPED_SUBRESOURCE mappedTexture;
hr = pDC->Map(
pStagingBuffer,
0,
D3D11_MAP_READ_WRITE,
0,
&mappedTexture);
TestRequire(SUCCEEDED(hr), "Failed to map staging buffer");
TestRequire(
!memcmp(mappedTexture.pData, texture3DPatterns[x][y][z], format->bytesPerPixel),
"Failed to map staging buffer");
pDC->Unmap(pStagingBuffer, 0);
}
pStagingBuffer->Release();
}
Cleanup:
if (pTexture)
{
pTexture->Release();
}
for (UINT i = 0; i < size->SubResourceCount; ++i)
{
clReleaseMemObject(subResourceInfo[i].mem);
}
HarnessD3D11_TestEnd();
}
void TestDeviceTexture3D(
cl_device_id device,
cl_context context,
cl_command_queue command_queue,
ID3D11Device* pDevice,
ID3D11DeviceContext* pDC)
{
cl_int result = CL_SUCCESS;
for (UINT format = 0, size = 0; format < formatCount; ++size, ++format)
{
SubTestTexture3D(
context,
command_queue,
pDevice,
pDC,
&formats[format],
&texture3DSizes[size % texture3DSizeCount]);
}
}