mirror of
https://github.com/KhronosGroup/OpenCL-CTS.git
synced 2026-03-23 07:39:01 +00:00
Synchronise with Khronos-private Gitlab branch
The maintenance of the conformance tests is moving to Github. This commit contains all the changes that have been done in Gitlab since the first public release of the conformance tests. Signed-off-by: Kevin Petit <kevin.petit@arm.com>
This commit is contained in:
@@ -1,321 +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]);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// 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]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,408 +1,408 @@
|
||||
//
|
||||
// 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"
|
||||
|
||||
/*
|
||||
* 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()
|
||||
{
|
||||
bool extensionPresent = false;
|
||||
cl_int result = CL_SUCCESS;
|
||||
cl_platform_id platform = NULL;
|
||||
char extensions[1024];
|
||||
|
||||
HarnessD3D11_TestBegin("Extension query");
|
||||
|
||||
result = clGetPlatformIDs(1, &platform, NULL);
|
||||
NonTestRequire(result == CL_SUCCESS, "Failed to get any platforms.");
|
||||
result = clGetPlatformInfo(platform, CL_PLATFORM_EXTENSIONS, sizeof(extensions), extensions, NULL);
|
||||
NonTestRequire(result == CL_SUCCESS, "Failed to list extensions.");
|
||||
extensionPresent = strstr(extensions, "cl_khr_d3d11_sharing") ? true : false;
|
||||
|
||||
OSVERSIONINFO osvi;
|
||||
osvi.dwOSVersionInfoSize = sizeof(osvi);
|
||||
GetVersionEx(&osvi);
|
||||
if (osvi.dwMajorVersion <= 5)
|
||||
{
|
||||
TestRequire(!extensionPresent, "Extension should not be exported on Windows < 6");
|
||||
}
|
||||
else
|
||||
{
|
||||
TestRequire(extensionPresent, "Extension should be exported on Windows >= 6");
|
||||
}
|
||||
|
||||
Cleanup:
|
||||
HarnessD3D11_TestEnd();
|
||||
|
||||
// early-out of the extension is not present
|
||||
if (!extensionPresent)
|
||||
{
|
||||
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,
|
||||
"cl_khr_d3d11_sharing_conformance",
|
||||
NULL
|
||||
};
|
||||
RegisterClassEx(&wc);
|
||||
HarnessD3D11_hWnd = CreateWindow(
|
||||
"cl_khr_d3d11_sharing_conformance",
|
||||
"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) };
|
||||
|
||||
program = clCreateProgramWithSource(
|
||||
context,
|
||||
1,
|
||||
sourceTexts,
|
||||
sourceLengths,
|
||||
&status);
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// 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"
|
||||
|
||||
/*
|
||||
* 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()
|
||||
{
|
||||
bool extensionPresent = false;
|
||||
cl_int result = CL_SUCCESS;
|
||||
cl_platform_id platform = NULL;
|
||||
char extensions[1024];
|
||||
|
||||
HarnessD3D11_TestBegin("Extension query");
|
||||
|
||||
result = clGetPlatformIDs(1, &platform, NULL);
|
||||
NonTestRequire(result == CL_SUCCESS, "Failed to get any platforms.");
|
||||
result = clGetPlatformInfo(platform, CL_PLATFORM_EXTENSIONS, sizeof(extensions), extensions, NULL);
|
||||
NonTestRequire(result == CL_SUCCESS, "Failed to list extensions.");
|
||||
extensionPresent = strstr(extensions, "cl_khr_d3d11_sharing") ? true : false;
|
||||
|
||||
OSVERSIONINFO osvi;
|
||||
osvi.dwOSVersionInfoSize = sizeof(osvi);
|
||||
GetVersionEx(&osvi);
|
||||
if (osvi.dwMajorVersion <= 5)
|
||||
{
|
||||
TestRequire(!extensionPresent, "Extension should not be exported on Windows < 6");
|
||||
}
|
||||
else
|
||||
{
|
||||
TestRequire(extensionPresent, "Extension should be exported on Windows >= 6");
|
||||
}
|
||||
|
||||
Cleanup:
|
||||
HarnessD3D11_TestEnd();
|
||||
|
||||
// early-out of the extension is not present
|
||||
if (!extensionPresent)
|
||||
{
|
||||
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,
|
||||
"cl_khr_d3d11_sharing_conformance",
|
||||
NULL
|
||||
};
|
||||
RegisterClassEx(&wc);
|
||||
HarnessD3D11_hWnd = CreateWindow(
|
||||
"cl_khr_d3d11_sharing_conformance",
|
||||
"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) };
|
||||
|
||||
program = clCreateProgramWithSource(
|
||||
context,
|
||||
1,
|
||||
sourceTexts,
|
||||
sourceLengths,
|
||||
&status);
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,220 +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.
|
||||
//
|
||||
#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"
|
||||
|
||||
// #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
|
||||
//
|
||||
// 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"
|
||||
|
||||
// #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
|
||||
|
||||
@@ -1,424 +1,424 @@
|
||||
//
|
||||
// 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"
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
cl_int result;
|
||||
cl_platform_id platform = NULL;
|
||||
cl_uint num_devices_tested = 0;
|
||||
|
||||
// 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
|
||||
result = clGetContextInfo(
|
||||
context,
|
||||
CL_CONTEXT_D3D11_DEVICE_KHR,
|
||||
sizeof(clDevice),
|
||||
&clDevice,
|
||||
NULL);
|
||||
TestRequire(
|
||||
(result == CL_SUCCESS),
|
||||
"clGetContextInfo with CL_CONTEXT_D3D11_DEVICE_KHR failed");
|
||||
TestRequire(
|
||||
(pDevice == clDevice),
|
||||
"clGetContextInfo with CL_CONTEXT_D3D11_DEVICE_KHR returned invalid value");
|
||||
|
||||
// create the command queue
|
||||
TestPrint("Creating a command queue.\n");
|
||||
command_queue = clCreateCommandQueue(
|
||||
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;
|
||||
}
|
||||
|
||||
//
|
||||
// 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"
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
cl_int result;
|
||||
cl_platform_id platform = NULL;
|
||||
cl_uint num_devices_tested = 0;
|
||||
|
||||
// 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
|
||||
result = clGetContextInfo(
|
||||
context,
|
||||
CL_CONTEXT_D3D11_DEVICE_KHR,
|
||||
sizeof(clDevice),
|
||||
&clDevice,
|
||||
NULL);
|
||||
TestRequire(
|
||||
(result == CL_SUCCESS),
|
||||
"clGetContextInfo with CL_CONTEXT_D3D11_DEVICE_KHR failed");
|
||||
TestRequire(
|
||||
(pDevice == clDevice),
|
||||
"clGetContextInfo with CL_CONTEXT_D3D11_DEVICE_KHR returned invalid value");
|
||||
|
||||
// create the command queue
|
||||
TestPrint("Creating a command queue.\n");
|
||||
command_queue = clCreateCommandQueue(
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,224 +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);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
||||
//
|
||||
// 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
|
||||
@@ -16,7 +16,7 @@
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#include "harness.h"
|
||||
|
||||
Texture3DSize texture3DSizes[] =
|
||||
Texture3DSize texture3DSizes[] =
|
||||
{
|
||||
{
|
||||
4, // Width
|
||||
@@ -80,11 +80,11 @@ UINT texture3DSizeCount = sizeof(texture3DSizes)/sizeof(texture3DSizes[0]);
|
||||
const char *
|
||||
texture3DPatterns[2][2][2] =
|
||||
{
|
||||
{
|
||||
{
|
||||
{"PlaceTheCasseroleDis", "hInAColdOvenPlaceACh"},
|
||||
{"airFacingTheOvenAndS", "itInItForeverThinkAb"},
|
||||
},
|
||||
{
|
||||
{
|
||||
{"outHowHungryYouAreWh", "enNightFallsDoNotTur"},
|
||||
{"nOnTheLightMyEyeBeca", "meInflamedIHateCamus"},
|
||||
},
|
||||
@@ -94,7 +94,7 @@ void SubTestTexture3D(
|
||||
cl_context context,
|
||||
cl_command_queue command_queue,
|
||||
ID3D11Device* pDevice,
|
||||
ID3D11DeviceContext* pDC,
|
||||
ID3D11DeviceContext* pDC,
|
||||
const TextureFormat* format,
|
||||
const Texture3DSize* size)
|
||||
{
|
||||
@@ -103,11 +103,11 @@ void SubTestTexture3D(
|
||||
|
||||
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,
|
||||
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
|
||||
@@ -133,7 +133,7 @@ void SubTestTexture3D(
|
||||
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
|
||||
desc.CPUAccessFlags = 0;
|
||||
desc.MiscFlags = 0;
|
||||
|
||||
|
||||
hr = pDevice->CreateTexture3D(&desc, NULL, &pTexture);
|
||||
TestRequire(SUCCEEDED(hr), "CreateTexture3D failed.");
|
||||
}
|
||||
@@ -191,8 +191,8 @@ void SubTestTexture3D(
|
||||
|
||||
// copy the data to to the texture
|
||||
{
|
||||
D3D11_BOX box = {0};
|
||||
box.front = 0; box.back = 1;
|
||||
D3D11_BOX box = {0};
|
||||
box.front = 0; box.back = 1;
|
||||
box.top = 0; box.bottom = 1;
|
||||
box.left = 0; box.right = 1;
|
||||
pDC->CopySubresourceRegion(
|
||||
@@ -206,13 +206,13 @@ void SubTestTexture3D(
|
||||
&box);
|
||||
}
|
||||
|
||||
pStagingBuffer->Release();
|
||||
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
|
||||
// create a cl_mem for the resource
|
||||
subResourceInfo[i].mem = clCreateFromD3D11Texture3DKHR(
|
||||
context,
|
||||
0,
|
||||
@@ -262,7 +262,7 @@ void SubTestTexture3D(
|
||||
CL_IMAGE_WIDTH,
|
||||
sizeof(width),
|
||||
&width,
|
||||
NULL);
|
||||
NULL);
|
||||
TestRequire(result == CL_SUCCESS, "clGetImageInfo for CL_IMAGE_WIDTH failed");
|
||||
TestRequire(width == subResourceInfo[i].width, "clGetImageInfo for CL_IMAGE_HEIGHT returned incorrect value.");
|
||||
|
||||
@@ -273,7 +273,7 @@ void SubTestTexture3D(
|
||||
CL_IMAGE_HEIGHT,
|
||||
sizeof(height),
|
||||
&height,
|
||||
NULL);
|
||||
NULL);
|
||||
TestRequire(result == CL_SUCCESS, "clGetImageInfo for CL_IMAGE_HEIGHT failed");
|
||||
TestRequire(height == subResourceInfo[i].height, "clGetImageInfo for CL_IMAGE_HEIGHT returned incorrect value.");
|
||||
|
||||
@@ -284,12 +284,12 @@ void SubTestTexture3D(
|
||||
CL_IMAGE_DEPTH,
|
||||
sizeof(depth),
|
||||
&depth,
|
||||
NULL);
|
||||
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];
|
||||
@@ -322,22 +322,22 @@ void SubTestTexture3D(
|
||||
{
|
||||
continue;
|
||||
}
|
||||
size_t src[3] =
|
||||
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] =
|
||||
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] =
|
||||
size_t region[3] =
|
||||
{
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
};
|
||||
result = clEnqueueCopyImage(
|
||||
@@ -348,7 +348,7 @@ void SubTestTexture3D(
|
||||
dst,
|
||||
region,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL);
|
||||
TestRequire(result == CL_SUCCESS, "clEnqueueCopyImage failed.");
|
||||
}
|
||||
@@ -393,7 +393,7 @@ void SubTestTexture3D(
|
||||
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;
|
||||
@@ -403,14 +403,14 @@ void SubTestTexture3D(
|
||||
D3D11_MAP_READ_WRITE,
|
||||
0,
|
||||
&mappedTexture);
|
||||
TestRequire(SUCCEEDED(hr), "Failed to map staging buffer");
|
||||
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};
|
||||
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;
|
||||
@@ -436,12 +436,12 @@ void SubTestTexture3D(
|
||||
&mappedTexture);
|
||||
TestRequire(SUCCEEDED(hr), "Failed to map staging buffer");
|
||||
TestRequire(
|
||||
!memcmp(mappedTexture.pData, texture3DPatterns[x][y][z], format->bytesPerPixel),
|
||||
!memcmp(mappedTexture.pData, texture3DPatterns[x][y][z], format->bytesPerPixel),
|
||||
"Failed to map staging buffer");
|
||||
pDC->Unmap(pStagingBuffer, 0);
|
||||
}
|
||||
|
||||
pStagingBuffer->Release();
|
||||
|
||||
pStagingBuffer->Release();
|
||||
}
|
||||
|
||||
|
||||
@@ -450,7 +450,7 @@ Cleanup:
|
||||
if (pTexture)
|
||||
{
|
||||
pTexture->Release();
|
||||
}
|
||||
}
|
||||
for (UINT i = 0; i < size->SubResourceCount; ++i)
|
||||
{
|
||||
clReleaseMemObject(subResourceInfo[i].mem);
|
||||
@@ -462,8 +462,8 @@ Cleanup:
|
||||
|
||||
void TestDeviceTexture3D(
|
||||
cl_device_id device,
|
||||
cl_context context,
|
||||
cl_command_queue command_queue,
|
||||
cl_context context,
|
||||
cl_command_queue command_queue,
|
||||
ID3D11Device* pDevice,
|
||||
ID3D11DeviceContext* pDC)
|
||||
{
|
||||
@@ -480,5 +480,5 @@ void TestDeviceTexture3D(
|
||||
&formats[format],
|
||||
&texture3DSizes[size % texture3DSizeCount]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user