mirror of
https://github.com/KhronosGroup/OpenCL-CTS.git
synced 2026-03-22 23:29:02 +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,310 +1,310 @@
|
||||
//
|
||||
// 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( 0x100, D3D10_BIND_CONSTANT_BUFFER, D3D10_USAGE_DYNAMIC, D3D10_CPU_ACCESS_WRITE),
|
||||
ADD_BUFFER_PROPERTIES( 0x1000, D3D10_BIND_CONSTANT_BUFFER, D3D10_USAGE_DYNAMIC, D3D10_CPU_ACCESS_WRITE),
|
||||
ADD_BUFFER_PROPERTIES( 0x8000, D3D10_BIND_CONSTANT_BUFFER, D3D10_USAGE_DYNAMIC, D3D10_CPU_ACCESS_WRITE),
|
||||
|
||||
ADD_BUFFER_PROPERTIES( 0x7FFFF, D3D10_BIND_SHADER_RESOURCE, D3D10_USAGE_DEFAULT, 0),
|
||||
ADD_BUFFER_PROPERTIES( 0x100000, D3D10_BIND_SHADER_RESOURCE, D3D10_USAGE_DEFAULT, 0),
|
||||
ADD_BUFFER_PROPERTIES( 0x100000, D3D10_BIND_STREAM_OUTPUT, D3D10_USAGE_DEFAULT, 0),
|
||||
ADD_BUFFER_PROPERTIES( 0x100001, D3D10_BIND_STREAM_OUTPUT, D3D10_USAGE_DEFAULT, 0),
|
||||
|
||||
ADD_BUFFER_PROPERTIES( 0x10, D3D10_BIND_VERTEX_BUFFER, D3D10_USAGE_DEFAULT, 0),
|
||||
ADD_BUFFER_PROPERTIES( 0x11, D3D10_BIND_INDEX_BUFFER, D3D10_USAGE_DYNAMIC, D3D10_CPU_ACCESS_WRITE),
|
||||
ADD_BUFFER_PROPERTIES( 0x121, D3D10_BIND_VERTEX_BUFFER, D3D10_USAGE_DEFAULT, 0),
|
||||
ADD_BUFFER_PROPERTIES( 0x1234, D3D10_BIND_INDEX_BUFFER, D3D10_USAGE_DEFAULT, 0),
|
||||
ADD_BUFFER_PROPERTIES( 0x12345, D3D10_BIND_VERTEX_BUFFER, D3D10_USAGE_DYNAMIC, D3D10_CPU_ACCESS_WRITE),
|
||||
ADD_BUFFER_PROPERTIES( 0x123456, D3D10_BIND_INDEX_BUFFER, D3D10_USAGE_DEFAULT, 0),
|
||||
#if 0 // avoid large sizes on automation
|
||||
ADD_BUFFER_PROPERTIES( 0x1234567, D3D10_BIND_INDEX_BUFFER, D3D10_USAGE_DYNAMIC, D3D10_CPU_ACCESS_WRITE),
|
||||
|
||||
ADD_BUFFER_PROPERTIES( 0x4000000, D3D10_BIND_VERTEX_BUFFER, D3D10_USAGE_DEFAULT, 0),
|
||||
ADD_BUFFER_PROPERTIES( 0x4000004, D3D10_BIND_VERTEX_BUFFER, D3D10_USAGE_DEFAULT, 0),
|
||||
ADD_BUFFER_PROPERTIES( 0x4000008, D3D10_BIND_VERTEX_BUFFER, D3D10_USAGE_DEFAULT, 0),
|
||||
ADD_BUFFER_PROPERTIES( 0x4000010, D3D10_BIND_VERTEX_BUFFER, D3D10_USAGE_DEFAULT, 0),
|
||||
ADD_BUFFER_PROPERTIES( 0x4000014, D3D10_BIND_VERTEX_BUFFER, D3D10_USAGE_DEFAULT, 0),
|
||||
#endif
|
||||
};
|
||||
UINT bufferPropertyCount = sizeof(bufferProperties)/sizeof(bufferProperties[0]);
|
||||
|
||||
void SubTestBuffer(
|
||||
cl_context context,
|
||||
cl_command_queue command_queue,
|
||||
ID3D10Device* pDevice,
|
||||
const BufferProperties* props)
|
||||
{
|
||||
ID3D10Buffer* pBuffer = NULL;
|
||||
HRESULT hr = S_OK;
|
||||
cl_mem mem = NULL;
|
||||
cl_int result = CL_SUCCESS;
|
||||
|
||||
HarnessD3D10_TestBegin("Buffer: Size=%d, BindFlags=%s, Usage=%s, CPUAccess=%s",
|
||||
props->ByteWidth,
|
||||
props->name_BindFlags,
|
||||
props->name_Usage,
|
||||
props->name_CPUAccess);
|
||||
|
||||
// create the D3D10 resource
|
||||
{
|
||||
D3D10_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 D3D10 resource with data
|
||||
{
|
||||
ID3D10Buffer* pStagingBuffer = NULL;
|
||||
char *pStagingData = NULL;
|
||||
|
||||
// create a staging buffer to use to copy data to the D3D buffer
|
||||
D3D10_BUFFER_DESC desc = {0};
|
||||
desc.ByteWidth = 16;
|
||||
desc.Usage = D3D10_USAGE_STAGING;
|
||||
desc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE|D3D10_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 = pStagingBuffer->Map(
|
||||
D3D10_MAP_READ_WRITE,
|
||||
0,
|
||||
(void **)&pStagingData);
|
||||
TestRequire(SUCCEEDED(hr), "Map failed!");
|
||||
memcpy(pStagingData, "abcdXXXXxxxx1234", 16);
|
||||
pStagingBuffer->Unmap();
|
||||
TestRequire(SUCCEEDED(hr), "Unmap failed!");
|
||||
|
||||
// copy 'abcdXXXX' to the front of the buffer and 'xxxx1234' to the back
|
||||
D3D10_BOX box = {0};
|
||||
box.front = 0;
|
||||
box.back = 1;
|
||||
box.top = 0;
|
||||
box.bottom = 1;
|
||||
|
||||
box.left = 0;
|
||||
box.right = 8;
|
||||
pDevice->CopySubresourceRegion(
|
||||
pBuffer,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
pStagingBuffer,
|
||||
0,
|
||||
&box);
|
||||
box.left = 8;
|
||||
box.right = 16;
|
||||
pDevice->CopySubresourceRegion(
|
||||
pBuffer,
|
||||
0,
|
||||
props->ByteWidth-8,
|
||||
0,
|
||||
0,
|
||||
pStagingBuffer,
|
||||
0,
|
||||
&box);
|
||||
pStagingBuffer->Release();
|
||||
}
|
||||
|
||||
// share the resource with OpenCL
|
||||
{
|
||||
mem = clCreateFromD3D10BufferKHR(
|
||||
context,
|
||||
0,
|
||||
pBuffer,
|
||||
&result);
|
||||
TestRequire(CL_SUCCESS == result, "clCreateFromD3D10BufferKHR failed");
|
||||
}
|
||||
|
||||
// validate the OpenCL mem obj's properties
|
||||
{
|
||||
ID3D10Resource* clResource = NULL;
|
||||
result = clGetMemObjectInfo(
|
||||
mem,
|
||||
CL_MEM_D3D10_RESOURCE_KHR,
|
||||
sizeof(clResource),
|
||||
&clResource,
|
||||
NULL);
|
||||
TestRequire(result == CL_SUCCESS, "clGetMemObjectInfo for CL_MEM_D3D10_RESOURCE_KHR failed.");
|
||||
TestRequire(clResource == pBuffer, "clGetMemObjectInfo for CL_MEM_D3D10_RESOURCE_KHR returned incorrect value.");
|
||||
}
|
||||
|
||||
// acquire the resource from OpenCL
|
||||
{
|
||||
result = clEnqueueAcquireD3D10ObjectsKHR(
|
||||
command_queue,
|
||||
1,
|
||||
&mem,
|
||||
0,
|
||||
NULL,
|
||||
NULL);
|
||||
TestRequire(result == CL_SUCCESS, "clEnqueueAcquireD3D10ObjectsKHR 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 = clEnqueueReleaseD3D10ObjectsKHR(
|
||||
command_queue,
|
||||
1,
|
||||
&mem,
|
||||
0,
|
||||
NULL,
|
||||
NULL);
|
||||
TestRequire(result == CL_SUCCESS, "clEnqueueReleaseD3D10ObjectsKHR failed.");
|
||||
}
|
||||
|
||||
// read data in D3D
|
||||
{
|
||||
ID3D10Buffer* pStagingBuffer = NULL;
|
||||
char *pStagingData = NULL;
|
||||
|
||||
// create a staging buffer to read the data back
|
||||
D3D10_BUFFER_DESC desc = {0};
|
||||
desc.ByteWidth = 16;
|
||||
desc.Usage = D3D10_USAGE_STAGING;
|
||||
desc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE|D3D10_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 = pStagingBuffer->Map(
|
||||
D3D10_MAP_READ_WRITE,
|
||||
0,
|
||||
(void **)&pStagingData);
|
||||
TestRequire(SUCCEEDED(hr), "Map failed!");
|
||||
memset(pStagingData, 0, 16);
|
||||
pStagingBuffer->Unmap();
|
||||
|
||||
|
||||
// copy the 'abcd1234' from the front and back of the buffer to the staging buffer
|
||||
D3D10_BOX box = {0};
|
||||
box.front = 0;
|
||||
box.back = 1;
|
||||
box.top = 0;
|
||||
box.bottom = 1;
|
||||
|
||||
box.left = 0;
|
||||
box.right = 8;
|
||||
pDevice->CopySubresourceRegion(
|
||||
pStagingBuffer,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
pBuffer,
|
||||
0,
|
||||
&box);
|
||||
box.left = props->ByteWidth-8;
|
||||
box.right = props->ByteWidth;
|
||||
pDevice->CopySubresourceRegion(
|
||||
pStagingBuffer,
|
||||
0,
|
||||
8,
|
||||
0,
|
||||
0,
|
||||
pBuffer,
|
||||
0,
|
||||
&box);
|
||||
TestRequire(SUCCEEDED(hr), "CopySubresourceRegion failed!");
|
||||
|
||||
// verify that we got the 'abcd1234'
|
||||
hr = pStagingBuffer->Map(
|
||||
D3D10_MAP_READ_WRITE,
|
||||
0,
|
||||
(void **)&pStagingData);
|
||||
TestRequire(SUCCEEDED(hr), "Map failed!");
|
||||
TestRequire(!memcmp(pStagingData, "abcd1234abcd1234", 16), "Data was not accurately");
|
||||
pStagingBuffer->Unmap();
|
||||
TestRequire(SUCCEEDED(hr), "Unmap failed!");
|
||||
|
||||
pStagingBuffer->Release();
|
||||
}
|
||||
|
||||
Cleanup:
|
||||
|
||||
if (pBuffer)
|
||||
{
|
||||
pBuffer->Release();
|
||||
}
|
||||
if (mem)
|
||||
{
|
||||
clReleaseMemObject(mem);
|
||||
}
|
||||
|
||||
HarnessD3D10_TestEnd();
|
||||
}
|
||||
|
||||
|
||||
void TestDeviceBuffer(
|
||||
cl_context context,
|
||||
cl_command_queue command_queue,
|
||||
ID3D10Device* pDevice)
|
||||
{
|
||||
for (UINT i = 0; i < bufferPropertyCount; ++i)
|
||||
{
|
||||
SubTestBuffer(
|
||||
context,
|
||||
command_queue,
|
||||
pDevice,
|
||||
&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( 0x100, D3D10_BIND_CONSTANT_BUFFER, D3D10_USAGE_DYNAMIC, D3D10_CPU_ACCESS_WRITE),
|
||||
ADD_BUFFER_PROPERTIES( 0x1000, D3D10_BIND_CONSTANT_BUFFER, D3D10_USAGE_DYNAMIC, D3D10_CPU_ACCESS_WRITE),
|
||||
ADD_BUFFER_PROPERTIES( 0x8000, D3D10_BIND_CONSTANT_BUFFER, D3D10_USAGE_DYNAMIC, D3D10_CPU_ACCESS_WRITE),
|
||||
|
||||
ADD_BUFFER_PROPERTIES( 0x7FFFF, D3D10_BIND_SHADER_RESOURCE, D3D10_USAGE_DEFAULT, 0),
|
||||
ADD_BUFFER_PROPERTIES( 0x100000, D3D10_BIND_SHADER_RESOURCE, D3D10_USAGE_DEFAULT, 0),
|
||||
ADD_BUFFER_PROPERTIES( 0x100000, D3D10_BIND_STREAM_OUTPUT, D3D10_USAGE_DEFAULT, 0),
|
||||
ADD_BUFFER_PROPERTIES( 0x100001, D3D10_BIND_STREAM_OUTPUT, D3D10_USAGE_DEFAULT, 0),
|
||||
|
||||
ADD_BUFFER_PROPERTIES( 0x10, D3D10_BIND_VERTEX_BUFFER, D3D10_USAGE_DEFAULT, 0),
|
||||
ADD_BUFFER_PROPERTIES( 0x11, D3D10_BIND_INDEX_BUFFER, D3D10_USAGE_DYNAMIC, D3D10_CPU_ACCESS_WRITE),
|
||||
ADD_BUFFER_PROPERTIES( 0x121, D3D10_BIND_VERTEX_BUFFER, D3D10_USAGE_DEFAULT, 0),
|
||||
ADD_BUFFER_PROPERTIES( 0x1234, D3D10_BIND_INDEX_BUFFER, D3D10_USAGE_DEFAULT, 0),
|
||||
ADD_BUFFER_PROPERTIES( 0x12345, D3D10_BIND_VERTEX_BUFFER, D3D10_USAGE_DYNAMIC, D3D10_CPU_ACCESS_WRITE),
|
||||
ADD_BUFFER_PROPERTIES( 0x123456, D3D10_BIND_INDEX_BUFFER, D3D10_USAGE_DEFAULT, 0),
|
||||
#if 0 // avoid large sizes on automation
|
||||
ADD_BUFFER_PROPERTIES( 0x1234567, D3D10_BIND_INDEX_BUFFER, D3D10_USAGE_DYNAMIC, D3D10_CPU_ACCESS_WRITE),
|
||||
|
||||
ADD_BUFFER_PROPERTIES( 0x4000000, D3D10_BIND_VERTEX_BUFFER, D3D10_USAGE_DEFAULT, 0),
|
||||
ADD_BUFFER_PROPERTIES( 0x4000004, D3D10_BIND_VERTEX_BUFFER, D3D10_USAGE_DEFAULT, 0),
|
||||
ADD_BUFFER_PROPERTIES( 0x4000008, D3D10_BIND_VERTEX_BUFFER, D3D10_USAGE_DEFAULT, 0),
|
||||
ADD_BUFFER_PROPERTIES( 0x4000010, D3D10_BIND_VERTEX_BUFFER, D3D10_USAGE_DEFAULT, 0),
|
||||
ADD_BUFFER_PROPERTIES( 0x4000014, D3D10_BIND_VERTEX_BUFFER, D3D10_USAGE_DEFAULT, 0),
|
||||
#endif
|
||||
};
|
||||
UINT bufferPropertyCount = sizeof(bufferProperties)/sizeof(bufferProperties[0]);
|
||||
|
||||
void SubTestBuffer(
|
||||
cl_context context,
|
||||
cl_command_queue command_queue,
|
||||
ID3D10Device* pDevice,
|
||||
const BufferProperties* props)
|
||||
{
|
||||
ID3D10Buffer* pBuffer = NULL;
|
||||
HRESULT hr = S_OK;
|
||||
cl_mem mem = NULL;
|
||||
cl_int result = CL_SUCCESS;
|
||||
|
||||
HarnessD3D10_TestBegin("Buffer: Size=%d, BindFlags=%s, Usage=%s, CPUAccess=%s",
|
||||
props->ByteWidth,
|
||||
props->name_BindFlags,
|
||||
props->name_Usage,
|
||||
props->name_CPUAccess);
|
||||
|
||||
// create the D3D10 resource
|
||||
{
|
||||
D3D10_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 D3D10 resource with data
|
||||
{
|
||||
ID3D10Buffer* pStagingBuffer = NULL;
|
||||
char *pStagingData = NULL;
|
||||
|
||||
// create a staging buffer to use to copy data to the D3D buffer
|
||||
D3D10_BUFFER_DESC desc = {0};
|
||||
desc.ByteWidth = 16;
|
||||
desc.Usage = D3D10_USAGE_STAGING;
|
||||
desc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE|D3D10_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 = pStagingBuffer->Map(
|
||||
D3D10_MAP_READ_WRITE,
|
||||
0,
|
||||
(void **)&pStagingData);
|
||||
TestRequire(SUCCEEDED(hr), "Map failed!");
|
||||
memcpy(pStagingData, "abcdXXXXxxxx1234", 16);
|
||||
pStagingBuffer->Unmap();
|
||||
TestRequire(SUCCEEDED(hr), "Unmap failed!");
|
||||
|
||||
// copy 'abcdXXXX' to the front of the buffer and 'xxxx1234' to the back
|
||||
D3D10_BOX box = {0};
|
||||
box.front = 0;
|
||||
box.back = 1;
|
||||
box.top = 0;
|
||||
box.bottom = 1;
|
||||
|
||||
box.left = 0;
|
||||
box.right = 8;
|
||||
pDevice->CopySubresourceRegion(
|
||||
pBuffer,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
pStagingBuffer,
|
||||
0,
|
||||
&box);
|
||||
box.left = 8;
|
||||
box.right = 16;
|
||||
pDevice->CopySubresourceRegion(
|
||||
pBuffer,
|
||||
0,
|
||||
props->ByteWidth-8,
|
||||
0,
|
||||
0,
|
||||
pStagingBuffer,
|
||||
0,
|
||||
&box);
|
||||
pStagingBuffer->Release();
|
||||
}
|
||||
|
||||
// share the resource with OpenCL
|
||||
{
|
||||
mem = clCreateFromD3D10BufferKHR(
|
||||
context,
|
||||
0,
|
||||
pBuffer,
|
||||
&result);
|
||||
TestRequire(CL_SUCCESS == result, "clCreateFromD3D10BufferKHR failed");
|
||||
}
|
||||
|
||||
// validate the OpenCL mem obj's properties
|
||||
{
|
||||
ID3D10Resource* clResource = NULL;
|
||||
result = clGetMemObjectInfo(
|
||||
mem,
|
||||
CL_MEM_D3D10_RESOURCE_KHR,
|
||||
sizeof(clResource),
|
||||
&clResource,
|
||||
NULL);
|
||||
TestRequire(result == CL_SUCCESS, "clGetMemObjectInfo for CL_MEM_D3D10_RESOURCE_KHR failed.");
|
||||
TestRequire(clResource == pBuffer, "clGetMemObjectInfo for CL_MEM_D3D10_RESOURCE_KHR returned incorrect value.");
|
||||
}
|
||||
|
||||
// acquire the resource from OpenCL
|
||||
{
|
||||
result = clEnqueueAcquireD3D10ObjectsKHR(
|
||||
command_queue,
|
||||
1,
|
||||
&mem,
|
||||
0,
|
||||
NULL,
|
||||
NULL);
|
||||
TestRequire(result == CL_SUCCESS, "clEnqueueAcquireD3D10ObjectsKHR 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 = clEnqueueReleaseD3D10ObjectsKHR(
|
||||
command_queue,
|
||||
1,
|
||||
&mem,
|
||||
0,
|
||||
NULL,
|
||||
NULL);
|
||||
TestRequire(result == CL_SUCCESS, "clEnqueueReleaseD3D10ObjectsKHR failed.");
|
||||
}
|
||||
|
||||
// read data in D3D
|
||||
{
|
||||
ID3D10Buffer* pStagingBuffer = NULL;
|
||||
char *pStagingData = NULL;
|
||||
|
||||
// create a staging buffer to read the data back
|
||||
D3D10_BUFFER_DESC desc = {0};
|
||||
desc.ByteWidth = 16;
|
||||
desc.Usage = D3D10_USAGE_STAGING;
|
||||
desc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE|D3D10_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 = pStagingBuffer->Map(
|
||||
D3D10_MAP_READ_WRITE,
|
||||
0,
|
||||
(void **)&pStagingData);
|
||||
TestRequire(SUCCEEDED(hr), "Map failed!");
|
||||
memset(pStagingData, 0, 16);
|
||||
pStagingBuffer->Unmap();
|
||||
|
||||
|
||||
// copy the 'abcd1234' from the front and back of the buffer to the staging buffer
|
||||
D3D10_BOX box = {0};
|
||||
box.front = 0;
|
||||
box.back = 1;
|
||||
box.top = 0;
|
||||
box.bottom = 1;
|
||||
|
||||
box.left = 0;
|
||||
box.right = 8;
|
||||
pDevice->CopySubresourceRegion(
|
||||
pStagingBuffer,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
pBuffer,
|
||||
0,
|
||||
&box);
|
||||
box.left = props->ByteWidth-8;
|
||||
box.right = props->ByteWidth;
|
||||
pDevice->CopySubresourceRegion(
|
||||
pStagingBuffer,
|
||||
0,
|
||||
8,
|
||||
0,
|
||||
0,
|
||||
pBuffer,
|
||||
0,
|
||||
&box);
|
||||
TestRequire(SUCCEEDED(hr), "CopySubresourceRegion failed!");
|
||||
|
||||
// verify that we got the 'abcd1234'
|
||||
hr = pStagingBuffer->Map(
|
||||
D3D10_MAP_READ_WRITE,
|
||||
0,
|
||||
(void **)&pStagingData);
|
||||
TestRequire(SUCCEEDED(hr), "Map failed!");
|
||||
TestRequire(!memcmp(pStagingData, "abcd1234abcd1234", 16), "Data was not accurately");
|
||||
pStagingBuffer->Unmap();
|
||||
TestRequire(SUCCEEDED(hr), "Unmap failed!");
|
||||
|
||||
pStagingBuffer->Release();
|
||||
}
|
||||
|
||||
Cleanup:
|
||||
|
||||
if (pBuffer)
|
||||
{
|
||||
pBuffer->Release();
|
||||
}
|
||||
if (mem)
|
||||
{
|
||||
clReleaseMemObject(mem);
|
||||
}
|
||||
|
||||
HarnessD3D10_TestEnd();
|
||||
}
|
||||
|
||||
|
||||
void TestDeviceBuffer(
|
||||
cl_context context,
|
||||
cl_command_queue command_queue,
|
||||
ID3D10Device* pDevice)
|
||||
{
|
||||
for (UINT i = 0; i < bufferPropertyCount; ++i)
|
||||
{
|
||||
SubTestBuffer(
|
||||
context,
|
||||
command_queue,
|
||||
pDevice,
|
||||
&bufferProperties[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,397 +1,397 @@
|
||||
//
|
||||
// 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
|
||||
*/
|
||||
|
||||
clGetDeviceIDsFromD3D10KHR_fn clGetDeviceIDsFromD3D10KHR = NULL;
|
||||
clCreateFromD3D10BufferKHR_fn clCreateFromD3D10BufferKHR = NULL;
|
||||
clCreateFromD3D10Texture2DKHR_fn clCreateFromD3D10Texture2DKHR = NULL;
|
||||
clCreateFromD3D10Texture3DKHR_fn clCreateFromD3D10Texture3DKHR = NULL;
|
||||
clEnqueueAcquireD3D10ObjectsKHR_fn clEnqueueAcquireD3D10ObjectsKHR = NULL;
|
||||
clEnqueueReleaseD3D10ObjectsKHR_fn clEnqueueReleaseD3D10ObjectsKHR = NULL;
|
||||
|
||||
#define INITPFN(x) \
|
||||
x = (x ## _fn)clGetExtensionFunctionAddressForPlatform(platform, #x); NonTestRequire(x, "Failed to get function pointer for %s", #x);
|
||||
|
||||
void
|
||||
HarnessD3D10_ExtensionCheck()
|
||||
{
|
||||
bool extensionPresent = false;
|
||||
cl_int result = CL_SUCCESS;
|
||||
cl_platform_id platform = NULL;
|
||||
char extensions[1024];
|
||||
|
||||
HarnessD3D10_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_d3d10_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:
|
||||
HarnessD3D10_TestEnd();
|
||||
|
||||
// early-out of the extension is not present
|
||||
if (!extensionPresent)
|
||||
{
|
||||
HarnessD3D10_TestStats();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
HarnessD3D10_Initialize(cl_platform_id platform)
|
||||
{
|
||||
HarnessD3D10_ExtensionCheck();
|
||||
|
||||
// extract function pointers for exported functions
|
||||
INITPFN(clGetDeviceIDsFromD3D10KHR);
|
||||
INITPFN(clCreateFromD3D10BufferKHR);
|
||||
INITPFN(clCreateFromD3D10Texture2DKHR);
|
||||
INITPFN(clCreateFromD3D10Texture3DKHR);
|
||||
INITPFN(clEnqueueAcquireD3D10ObjectsKHR);
|
||||
INITPFN(clEnqueueReleaseD3D10ObjectsKHR);
|
||||
}
|
||||
|
||||
/*
|
||||
* Window management
|
||||
*/
|
||||
|
||||
static IDXGISwapChain* HarnessD3D10_pSwapChain = NULL;
|
||||
static ID3D10Device* HarnessD3D10_pDevice = NULL;
|
||||
static HWND HarnessD3D10_hWnd = NULL;
|
||||
|
||||
static LRESULT WINAPI HarnessD3D10_Proc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
switch(msg)
|
||||
{
|
||||
case WM_KEYDOWN:
|
||||
return 0;
|
||||
break;
|
||||
case WM_DESTROY:
|
||||
HarnessD3D10_hWnd = NULL;
|
||||
PostQuitMessage(0);
|
||||
return 0;
|
||||
case WM_PAINT:
|
||||
ValidateRect(hWnd, NULL);
|
||||
return 0;
|
||||
}
|
||||
return DefWindowProc(hWnd, msg, wParam, lParam);
|
||||
}
|
||||
|
||||
static void HarnessD3D10_InteractiveLoop()
|
||||
{
|
||||
MSG msg;
|
||||
while(PeekMessage(&msg,HarnessD3D10_hWnd,0,0,PM_REMOVE))
|
||||
{
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
}
|
||||
|
||||
cl_int HarnessD3D10_CreateDevice(IDXGIAdapter* pAdapter, ID3D10Device **ppDevice)
|
||||
{
|
||||
HRESULT hr = S_OK;
|
||||
unsigned int cuStatus = 1;
|
||||
|
||||
*ppDevice = NULL;
|
||||
|
||||
// create window
|
||||
static WNDCLASSEX wc =
|
||||
{
|
||||
sizeof(WNDCLASSEX),
|
||||
CS_CLASSDC,
|
||||
HarnessD3D10_Proc,
|
||||
0L,
|
||||
0L,
|
||||
GetModuleHandle(NULL),
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
"cl_khr_d3d10_sharing_conformance",
|
||||
NULL
|
||||
};
|
||||
RegisterClassEx(&wc);
|
||||
HarnessD3D10_hWnd = CreateWindow(
|
||||
"cl_khr_d3d10_sharing_conformance",
|
||||
"cl_khr_d3d10_sharing_conformance",
|
||||
WS_OVERLAPPEDWINDOW,
|
||||
0, 0, 256, 256,
|
||||
NULL,
|
||||
NULL,
|
||||
wc.hInstance,
|
||||
NULL);
|
||||
NonTestRequire(0 != HarnessD3D10_hWnd, "Failed to create window");
|
||||
|
||||
ShowWindow(HarnessD3D10_hWnd,SW_SHOWDEFAULT);
|
||||
UpdateWindow(HarnessD3D10_hWnd);
|
||||
|
||||
RECT rc;
|
||||
GetClientRect(HarnessD3D10_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 = HarnessD3D10_hWnd;
|
||||
sd.SampleDesc.Count = 1;
|
||||
sd.SampleDesc.Quality = 0;
|
||||
sd.Windowed = TRUE;
|
||||
hr = D3D10CreateDeviceAndSwapChain(
|
||||
pAdapter,
|
||||
D3D10_DRIVER_TYPE_HARDWARE,
|
||||
NULL,
|
||||
D3D10_CREATE_DEVICE_DEBUG,
|
||||
D3D10_SDK_VERSION,
|
||||
&sd,
|
||||
&HarnessD3D10_pSwapChain,
|
||||
&HarnessD3D10_pDevice);
|
||||
|
||||
if (FAILED(hr) ) {
|
||||
return CL_DEVICE_NOT_FOUND;
|
||||
}
|
||||
|
||||
*ppDevice = HarnessD3D10_pDevice;
|
||||
return CL_SUCCESS;
|
||||
}
|
||||
|
||||
void HarnessD3D10_DestroyDevice()
|
||||
{
|
||||
HarnessD3D10_pSwapChain->Release();
|
||||
HarnessD3D10_pDevice->Release();
|
||||
|
||||
if (HarnessD3D10_hWnd) DestroyWindow(HarnessD3D10_hWnd);
|
||||
HarnessD3D10_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];
|
||||
} HarnessD3D10_testStats = {0};
|
||||
|
||||
void HarnessD3D10_TestBegin(const char* fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
vsprintf(HarnessD3D10_testStats.currentTestName, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
TestPrint("[%s] ... ", HarnessD3D10_testStats.currentTestName);
|
||||
|
||||
HarnessD3D10_testStats.inTest = 1;
|
||||
HarnessD3D10_testStats.currentTestPass = 1;
|
||||
}
|
||||
|
||||
void HarnessD3D10_TestFail()
|
||||
{
|
||||
if (HarnessD3D10_testStats.inTest)
|
||||
{
|
||||
HarnessD3D10_testStats.currentTestPass = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
++HarnessD3D10_testStats.nonTestFailures;
|
||||
}
|
||||
}
|
||||
|
||||
void HarnessD3D10_TestEnd()
|
||||
{
|
||||
HarnessD3D10_testStats.inTest = 0;
|
||||
|
||||
HarnessD3D10_testStats.testCount += 1;
|
||||
HarnessD3D10_testStats.passCount += HarnessD3D10_testStats.currentTestPass;
|
||||
|
||||
TestPrint("%s\n",
|
||||
HarnessD3D10_testStats.currentTestPass ? "PASSED" : "FAILED");
|
||||
}
|
||||
|
||||
void HarnessD3D10_TestStats()
|
||||
{
|
||||
TestPrint("PASSED %d of %d tests.\n", HarnessD3D10_testStats.passCount, HarnessD3D10_testStats.testCount);
|
||||
if (HarnessD3D10_testStats.testCount > HarnessD3D10_testStats.passCount)
|
||||
{
|
||||
TestPrint("***FAILED***\n");
|
||||
exit(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
TestPrint("&&&& cl_khr_d3d10_sharing test PASSED\n");
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
* Helper function
|
||||
*
|
||||
*/
|
||||
|
||||
cl_int HarnessD3D10_CreateKernelFromSource(
|
||||
cl_kernel *outKernel,
|
||||
cl_device_id device,
|
||||
cl_context context,
|
||||
const char *source,
|
||||
const char *entrypoint)
|
||||
{
|
||||
cl_int status;
|
||||
cl_program program = NULL;
|
||||
cl_kernel kernel = NULL;
|
||||
|
||||
// compile program
|
||||
{
|
||||
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
|
||||
*/
|
||||
|
||||
clGetDeviceIDsFromD3D10KHR_fn clGetDeviceIDsFromD3D10KHR = NULL;
|
||||
clCreateFromD3D10BufferKHR_fn clCreateFromD3D10BufferKHR = NULL;
|
||||
clCreateFromD3D10Texture2DKHR_fn clCreateFromD3D10Texture2DKHR = NULL;
|
||||
clCreateFromD3D10Texture3DKHR_fn clCreateFromD3D10Texture3DKHR = NULL;
|
||||
clEnqueueAcquireD3D10ObjectsKHR_fn clEnqueueAcquireD3D10ObjectsKHR = NULL;
|
||||
clEnqueueReleaseD3D10ObjectsKHR_fn clEnqueueReleaseD3D10ObjectsKHR = NULL;
|
||||
|
||||
#define INITPFN(x) \
|
||||
x = (x ## _fn)clGetExtensionFunctionAddressForPlatform(platform, #x); NonTestRequire(x, "Failed to get function pointer for %s", #x);
|
||||
|
||||
void
|
||||
HarnessD3D10_ExtensionCheck()
|
||||
{
|
||||
bool extensionPresent = false;
|
||||
cl_int result = CL_SUCCESS;
|
||||
cl_platform_id platform = NULL;
|
||||
char extensions[1024];
|
||||
|
||||
HarnessD3D10_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_d3d10_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:
|
||||
HarnessD3D10_TestEnd();
|
||||
|
||||
// early-out of the extension is not present
|
||||
if (!extensionPresent)
|
||||
{
|
||||
HarnessD3D10_TestStats();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
HarnessD3D10_Initialize(cl_platform_id platform)
|
||||
{
|
||||
HarnessD3D10_ExtensionCheck();
|
||||
|
||||
// extract function pointers for exported functions
|
||||
INITPFN(clGetDeviceIDsFromD3D10KHR);
|
||||
INITPFN(clCreateFromD3D10BufferKHR);
|
||||
INITPFN(clCreateFromD3D10Texture2DKHR);
|
||||
INITPFN(clCreateFromD3D10Texture3DKHR);
|
||||
INITPFN(clEnqueueAcquireD3D10ObjectsKHR);
|
||||
INITPFN(clEnqueueReleaseD3D10ObjectsKHR);
|
||||
}
|
||||
|
||||
/*
|
||||
* Window management
|
||||
*/
|
||||
|
||||
static IDXGISwapChain* HarnessD3D10_pSwapChain = NULL;
|
||||
static ID3D10Device* HarnessD3D10_pDevice = NULL;
|
||||
static HWND HarnessD3D10_hWnd = NULL;
|
||||
|
||||
static LRESULT WINAPI HarnessD3D10_Proc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
switch(msg)
|
||||
{
|
||||
case WM_KEYDOWN:
|
||||
return 0;
|
||||
break;
|
||||
case WM_DESTROY:
|
||||
HarnessD3D10_hWnd = NULL;
|
||||
PostQuitMessage(0);
|
||||
return 0;
|
||||
case WM_PAINT:
|
||||
ValidateRect(hWnd, NULL);
|
||||
return 0;
|
||||
}
|
||||
return DefWindowProc(hWnd, msg, wParam, lParam);
|
||||
}
|
||||
|
||||
static void HarnessD3D10_InteractiveLoop()
|
||||
{
|
||||
MSG msg;
|
||||
while(PeekMessage(&msg,HarnessD3D10_hWnd,0,0,PM_REMOVE))
|
||||
{
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
}
|
||||
|
||||
cl_int HarnessD3D10_CreateDevice(IDXGIAdapter* pAdapter, ID3D10Device **ppDevice)
|
||||
{
|
||||
HRESULT hr = S_OK;
|
||||
unsigned int cuStatus = 1;
|
||||
|
||||
*ppDevice = NULL;
|
||||
|
||||
// create window
|
||||
static WNDCLASSEX wc =
|
||||
{
|
||||
sizeof(WNDCLASSEX),
|
||||
CS_CLASSDC,
|
||||
HarnessD3D10_Proc,
|
||||
0L,
|
||||
0L,
|
||||
GetModuleHandle(NULL),
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
"cl_khr_d3d10_sharing_conformance",
|
||||
NULL
|
||||
};
|
||||
RegisterClassEx(&wc);
|
||||
HarnessD3D10_hWnd = CreateWindow(
|
||||
"cl_khr_d3d10_sharing_conformance",
|
||||
"cl_khr_d3d10_sharing_conformance",
|
||||
WS_OVERLAPPEDWINDOW,
|
||||
0, 0, 256, 256,
|
||||
NULL,
|
||||
NULL,
|
||||
wc.hInstance,
|
||||
NULL);
|
||||
NonTestRequire(0 != HarnessD3D10_hWnd, "Failed to create window");
|
||||
|
||||
ShowWindow(HarnessD3D10_hWnd,SW_SHOWDEFAULT);
|
||||
UpdateWindow(HarnessD3D10_hWnd);
|
||||
|
||||
RECT rc;
|
||||
GetClientRect(HarnessD3D10_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 = HarnessD3D10_hWnd;
|
||||
sd.SampleDesc.Count = 1;
|
||||
sd.SampleDesc.Quality = 0;
|
||||
sd.Windowed = TRUE;
|
||||
hr = D3D10CreateDeviceAndSwapChain(
|
||||
pAdapter,
|
||||
D3D10_DRIVER_TYPE_HARDWARE,
|
||||
NULL,
|
||||
D3D10_CREATE_DEVICE_DEBUG,
|
||||
D3D10_SDK_VERSION,
|
||||
&sd,
|
||||
&HarnessD3D10_pSwapChain,
|
||||
&HarnessD3D10_pDevice);
|
||||
|
||||
if (FAILED(hr) ) {
|
||||
return CL_DEVICE_NOT_FOUND;
|
||||
}
|
||||
|
||||
*ppDevice = HarnessD3D10_pDevice;
|
||||
return CL_SUCCESS;
|
||||
}
|
||||
|
||||
void HarnessD3D10_DestroyDevice()
|
||||
{
|
||||
HarnessD3D10_pSwapChain->Release();
|
||||
HarnessD3D10_pDevice->Release();
|
||||
|
||||
if (HarnessD3D10_hWnd) DestroyWindow(HarnessD3D10_hWnd);
|
||||
HarnessD3D10_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];
|
||||
} HarnessD3D10_testStats = {0};
|
||||
|
||||
void HarnessD3D10_TestBegin(const char* fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
vsprintf(HarnessD3D10_testStats.currentTestName, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
TestPrint("[%s] ... ", HarnessD3D10_testStats.currentTestName);
|
||||
|
||||
HarnessD3D10_testStats.inTest = 1;
|
||||
HarnessD3D10_testStats.currentTestPass = 1;
|
||||
}
|
||||
|
||||
void HarnessD3D10_TestFail()
|
||||
{
|
||||
if (HarnessD3D10_testStats.inTest)
|
||||
{
|
||||
HarnessD3D10_testStats.currentTestPass = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
++HarnessD3D10_testStats.nonTestFailures;
|
||||
}
|
||||
}
|
||||
|
||||
void HarnessD3D10_TestEnd()
|
||||
{
|
||||
HarnessD3D10_testStats.inTest = 0;
|
||||
|
||||
HarnessD3D10_testStats.testCount += 1;
|
||||
HarnessD3D10_testStats.passCount += HarnessD3D10_testStats.currentTestPass;
|
||||
|
||||
TestPrint("%s\n",
|
||||
HarnessD3D10_testStats.currentTestPass ? "PASSED" : "FAILED");
|
||||
}
|
||||
|
||||
void HarnessD3D10_TestStats()
|
||||
{
|
||||
TestPrint("PASSED %d of %d tests.\n", HarnessD3D10_testStats.passCount, HarnessD3D10_testStats.testCount);
|
||||
if (HarnessD3D10_testStats.testCount > HarnessD3D10_testStats.passCount)
|
||||
{
|
||||
TestPrint("***FAILED***\n");
|
||||
exit(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
TestPrint("&&&& cl_khr_d3d10_sharing test PASSED\n");
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
* Helper function
|
||||
*
|
||||
*/
|
||||
|
||||
cl_int HarnessD3D10_CreateKernelFromSource(
|
||||
cl_kernel *outKernel,
|
||||
cl_device_id device,
|
||||
cl_context context,
|
||||
const char *source,
|
||||
const char *entrypoint)
|
||||
{
|
||||
cl_int status;
|
||||
cl_program program = NULL;
|
||||
cl_kernel kernel = NULL;
|
||||
|
||||
// compile program
|
||||
{
|
||||
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,212 +1,212 @@
|
||||
//
|
||||
// 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_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_d3d10.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"); \
|
||||
HarnessD3D10_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;
|
||||
D3D10_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 HarnessD3D10_Initialize(cl_platform_id platform);
|
||||
cl_int HarnessD3D10_CreateDevice(IDXGIAdapter* pAdapter, ID3D10Device **ppDevice);
|
||||
void HarnessD3D10_DestroyDevice();
|
||||
|
||||
void HarnessD3D10_TestBegin(const char* fmt, ...);
|
||||
void HarnessD3D10_TestFail();
|
||||
void HarnessD3D10_TestEnd();
|
||||
void HarnessD3D10_TestStats();
|
||||
|
||||
|
||||
void TestAdapterEnumeration(
|
||||
cl_platform_id platform,
|
||||
IDXGIAdapter* pAdapter,
|
||||
ID3D10Device* pDevice,
|
||||
cl_uint* num_devices);
|
||||
|
||||
void TestAdapterDevices(
|
||||
cl_platform_id platform,
|
||||
IDXGIAdapter* pAdapter,
|
||||
ID3D10Device* pDevice,
|
||||
cl_uint num_devices);
|
||||
|
||||
void TestDevice(
|
||||
cl_device_id device,
|
||||
ID3D10Device* pDevice);
|
||||
|
||||
bool TestDeviceContextCreate(
|
||||
cl_device_id device,
|
||||
ID3D10Device* pDevice,
|
||||
cl_context* out_context,
|
||||
cl_command_queue* out_command_queue);
|
||||
|
||||
void TestDeviceBuffer(
|
||||
cl_context context,
|
||||
cl_command_queue command_queue,
|
||||
ID3D10Device* pDevice);
|
||||
|
||||
void TestDeviceTexture2D(
|
||||
cl_device_id device,
|
||||
cl_context context,
|
||||
cl_command_queue command_queue,
|
||||
ID3D10Device* pDevice);
|
||||
|
||||
void TestDeviceTexture3D(
|
||||
cl_device_id device,
|
||||
cl_context context,
|
||||
cl_command_queue command_queue,
|
||||
ID3D10Device* pDevice);
|
||||
|
||||
void TestDeviceMisc(
|
||||
cl_device_id device,
|
||||
cl_context context,
|
||||
cl_command_queue command_queue,
|
||||
ID3D10Device* pDevice);
|
||||
|
||||
cl_int HarnessD3D10_CreateKernelFromSource(
|
||||
cl_kernel *outKernel,
|
||||
cl_device_id device,
|
||||
cl_context context,
|
||||
const char *source,
|
||||
const char *entrypoint);
|
||||
|
||||
extern clGetDeviceIDsFromD3D10KHR_fn clGetDeviceIDsFromD3D10KHR;
|
||||
extern clCreateFromD3D10BufferKHR_fn clCreateFromD3D10BufferKHR;
|
||||
extern clCreateFromD3D10Texture2DKHR_fn clCreateFromD3D10Texture2DKHR;
|
||||
extern clCreateFromD3D10Texture3DKHR_fn clCreateFromD3D10Texture3DKHR;
|
||||
extern clEnqueueAcquireD3D10ObjectsKHR_fn clEnqueueAcquireD3D10ObjectsKHR;
|
||||
extern clEnqueueReleaseD3D10ObjectsKHR_fn clEnqueueReleaseD3D10ObjectsKHR;
|
||||
|
||||
#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_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_d3d10.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"); \
|
||||
HarnessD3D10_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;
|
||||
D3D10_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 HarnessD3D10_Initialize(cl_platform_id platform);
|
||||
cl_int HarnessD3D10_CreateDevice(IDXGIAdapter* pAdapter, ID3D10Device **ppDevice);
|
||||
void HarnessD3D10_DestroyDevice();
|
||||
|
||||
void HarnessD3D10_TestBegin(const char* fmt, ...);
|
||||
void HarnessD3D10_TestFail();
|
||||
void HarnessD3D10_TestEnd();
|
||||
void HarnessD3D10_TestStats();
|
||||
|
||||
|
||||
void TestAdapterEnumeration(
|
||||
cl_platform_id platform,
|
||||
IDXGIAdapter* pAdapter,
|
||||
ID3D10Device* pDevice,
|
||||
cl_uint* num_devices);
|
||||
|
||||
void TestAdapterDevices(
|
||||
cl_platform_id platform,
|
||||
IDXGIAdapter* pAdapter,
|
||||
ID3D10Device* pDevice,
|
||||
cl_uint num_devices);
|
||||
|
||||
void TestDevice(
|
||||
cl_device_id device,
|
||||
ID3D10Device* pDevice);
|
||||
|
||||
bool TestDeviceContextCreate(
|
||||
cl_device_id device,
|
||||
ID3D10Device* pDevice,
|
||||
cl_context* out_context,
|
||||
cl_command_queue* out_command_queue);
|
||||
|
||||
void TestDeviceBuffer(
|
||||
cl_context context,
|
||||
cl_command_queue command_queue,
|
||||
ID3D10Device* pDevice);
|
||||
|
||||
void TestDeviceTexture2D(
|
||||
cl_device_id device,
|
||||
cl_context context,
|
||||
cl_command_queue command_queue,
|
||||
ID3D10Device* pDevice);
|
||||
|
||||
void TestDeviceTexture3D(
|
||||
cl_device_id device,
|
||||
cl_context context,
|
||||
cl_command_queue command_queue,
|
||||
ID3D10Device* pDevice);
|
||||
|
||||
void TestDeviceMisc(
|
||||
cl_device_id device,
|
||||
cl_context context,
|
||||
cl_command_queue command_queue,
|
||||
ID3D10Device* pDevice);
|
||||
|
||||
cl_int HarnessD3D10_CreateKernelFromSource(
|
||||
cl_kernel *outKernel,
|
||||
cl_device_id device,
|
||||
cl_context context,
|
||||
const char *source,
|
||||
const char *entrypoint);
|
||||
|
||||
extern clGetDeviceIDsFromD3D10KHR_fn clGetDeviceIDsFromD3D10KHR;
|
||||
extern clCreateFromD3D10BufferKHR_fn clCreateFromD3D10BufferKHR;
|
||||
extern clCreateFromD3D10Texture2DKHR_fn clCreateFromD3D10Texture2DKHR;
|
||||
extern clCreateFromD3D10Texture3DKHR_fn clCreateFromD3D10Texture3DKHR;
|
||||
extern clEnqueueAcquireD3D10ObjectsKHR_fn clEnqueueAcquireD3D10ObjectsKHR;
|
||||
extern clEnqueueReleaseD3D10ObjectsKHR_fn clEnqueueReleaseD3D10ObjectsKHR;
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,413 +1,413 @@
|
||||
//
|
||||
// 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;
|
||||
char extensions[8192];
|
||||
|
||||
// get the platform to test
|
||||
result = clGetPlatformIDs(1, &platform, NULL); NonTestRequire(result == CL_SUCCESS, "Failed to get any platforms.");
|
||||
|
||||
// make sure the platform supports the extension
|
||||
result = clGetPlatformInfo(platform, CL_PLATFORM_EXTENSIONS, sizeof(extensions), extensions, NULL); NonTestRequire(result == CL_SUCCESS, "Failed to get extensions.");
|
||||
NonTestRequire(strstr(extensions, "cl_khr_d3d10_sharing"), "cl_khr_d3d10_sharing not supported.");
|
||||
|
||||
HarnessD3D10_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;
|
||||
ID3D10Device* pDevice = 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 D3D10 Device\n");
|
||||
TestPrint("Description=%ls, VendorID=%x, DeviceID=%x\n", desc.Description, desc.VendorId, desc.DeviceId);
|
||||
TestPrint("=====================================\n");
|
||||
|
||||
// run the test on the adapter
|
||||
HarnessD3D10_CreateDevice(pAdapter, &pDevice);
|
||||
|
||||
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, num_devices);
|
||||
}
|
||||
num_devices_tested += num_devices;
|
||||
|
||||
// destroy the D3D10 device
|
||||
if (pDevice)
|
||||
{
|
||||
HarnessD3D10_DestroyDevice();
|
||||
}
|
||||
|
||||
pAdapter->Release();
|
||||
}
|
||||
pFactory->Release();
|
||||
|
||||
NonTestRequire(num_devices_tested, "No D3D10 compatible cl_device_ids were found.");
|
||||
|
||||
HarnessD3D10_TestStats();
|
||||
}
|
||||
|
||||
void TestAdapterEnumeration(cl_platform_id platform, IDXGIAdapter* pAdapter, ID3D10Device* 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;
|
||||
|
||||
HarnessD3D10_TestBegin("cl_device_id Enumeration");
|
||||
|
||||
// get the cl_device_ids for the adapter
|
||||
{
|
||||
result = clGetDeviceIDsFromD3D10KHR(
|
||||
platform,
|
||||
CL_D3D10_DXGI_ADAPTER_KHR,
|
||||
pAdapter,
|
||||
CL_ALL_DEVICES_FOR_D3D10_KHR,
|
||||
0,
|
||||
NULL,
|
||||
&num_adapter_devices);
|
||||
TestRequire(
|
||||
(result == CL_SUCCESS || result == CL_DEVICE_NOT_FOUND),
|
||||
"clGetDeviceIDsFromD3D10KHR 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 = clGetDeviceIDsFromD3D10KHR(
|
||||
platform,
|
||||
CL_D3D10_DXGI_ADAPTER_KHR,
|
||||
pAdapter,
|
||||
CL_ALL_DEVICES_FOR_D3D10_KHR,
|
||||
num_adapter_devices,
|
||||
adapter_devices,
|
||||
NULL);
|
||||
TestRequire(
|
||||
(result == CL_SUCCESS),
|
||||
"clGetDeviceIDsFromD3D10KHR failed.");
|
||||
}
|
||||
}
|
||||
|
||||
// get the cl_device_ids for the device (if it was successfully created)
|
||||
if (pDevice)
|
||||
{
|
||||
result = clGetDeviceIDsFromD3D10KHR(
|
||||
platform,
|
||||
CL_D3D10_DEVICE_KHR,
|
||||
pDevice,
|
||||
CL_ALL_DEVICES_FOR_D3D10_KHR,
|
||||
0,
|
||||
NULL,
|
||||
&num_device_devices);
|
||||
TestRequire(
|
||||
(result == CL_SUCCESS || result == CL_DEVICE_NOT_FOUND),
|
||||
"clGetDeviceIDsFromD3D10KHR 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 = clGetDeviceIDsFromD3D10KHR(
|
||||
platform,
|
||||
CL_D3D10_DEVICE_KHR,
|
||||
pDevice,
|
||||
CL_ALL_DEVICES_FOR_D3D10_KHR,
|
||||
num_device_devices,
|
||||
device_devices,
|
||||
NULL);
|
||||
TestRequire(
|
||||
(result == CL_SUCCESS),
|
||||
"clGetDeviceIDsFromD3D10KHR failed.");
|
||||
}
|
||||
|
||||
// require that each cl_device_id returned for the ID3D10Device was among the devices listed for the adapter
|
||||
for (cl_uint device_device = 0; device_device < num_device_devices; ++device_device)
|
||||
{
|
||||
cl_uint adapter_device;
|
||||
for (adapter_device = 0; adapter_device < num_adapter_devices; ++adapter_device)
|
||||
{
|
||||
if (device_devices[device_device] == adapter_devices[adapter_device])
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
TestRequire(
|
||||
(adapter_device != num_adapter_devices),
|
||||
"CL_D3D10_DEVICE_KHR devices not a subset of CL_D3D10_DXGI_ADAPTER_KHR devices");
|
||||
}
|
||||
}
|
||||
|
||||
Cleanup:
|
||||
|
||||
if (adapter_devices)
|
||||
{
|
||||
delete[] adapter_devices;
|
||||
}
|
||||
if (device_devices)
|
||||
{
|
||||
delete[] device_devices;
|
||||
}
|
||||
|
||||
*num_devices = num_device_devices;
|
||||
|
||||
HarnessD3D10_TestEnd();
|
||||
}
|
||||
|
||||
void TestAdapterDevices(cl_platform_id platform, IDXGIAdapter* pAdapter, ID3D10Device* pDevice, 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 = clGetDeviceIDsFromD3D10KHR(
|
||||
platform,
|
||||
CL_D3D10_DEVICE_KHR,
|
||||
pDevice,
|
||||
CL_ALL_DEVICES_FOR_D3D10_KHR,
|
||||
num_devices_expected,
|
||||
devices,
|
||||
&num_devices);
|
||||
NonTestRequire(
|
||||
(result == CL_SUCCESS),
|
||||
"clGetDeviceIDsFromD3D10KHR failed.");
|
||||
NonTestRequire(
|
||||
(num_devices == num_devices_expected),
|
||||
"clGetDeviceIDsFromD3D10KHR returned an unexpected number of devices.");
|
||||
|
||||
for (cl_uint i = 0; i < num_devices; ++i)
|
||||
{
|
||||
TestDevice(devices[i], pDevice);
|
||||
}
|
||||
}
|
||||
|
||||
void TestDevice(cl_device_id device, ID3D10Device* pDevice)
|
||||
{
|
||||
char device_name[1024];
|
||||
cl_int result = CL_SUCCESS;
|
||||
cl_context context = NULL;
|
||||
cl_command_queue command_queue = NULL;
|
||||
cl_bool prefer_shared_resources = CL_FALSE;
|
||||
ID3D10Device* clDevice = NULL;
|
||||
|
||||
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_D3D10_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);
|
||||
|
||||
// run 2D texture tests
|
||||
TestDeviceTexture2D(
|
||||
device,
|
||||
context,
|
||||
command_queue,
|
||||
pDevice);
|
||||
|
||||
// run 3D texture tests
|
||||
TestDeviceTexture3D(
|
||||
device,
|
||||
context,
|
||||
command_queue,
|
||||
pDevice);
|
||||
|
||||
// run misc tests
|
||||
TestDeviceMisc(
|
||||
device,
|
||||
context,
|
||||
command_queue,
|
||||
pDevice);
|
||||
|
||||
clReleaseContext(context);
|
||||
clReleaseCommandQueue(command_queue);
|
||||
}
|
||||
|
||||
bool TestDeviceContextCreate(
|
||||
cl_device_id device,
|
||||
ID3D10Device* 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;
|
||||
|
||||
ID3D10Device* clDevice = NULL;
|
||||
|
||||
bool succeeded = false;
|
||||
|
||||
HarnessD3D10_TestBegin("Context creation");
|
||||
|
||||
cl_context_properties properties[5];
|
||||
|
||||
// create the context
|
||||
properties[0] = (cl_context_properties)CL_CONTEXT_D3D10_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_D3D10_DEVICE_KHR failed");
|
||||
result = clReleaseContext(context);
|
||||
TestRequire(
|
||||
(result == CL_SUCCESS),
|
||||
"clReleaseContext with CL_CONTEXT_D3D10_DEVICE_KHR failed");
|
||||
|
||||
// create the context
|
||||
properties[0] = (cl_context_properties)CL_CONTEXT_D3D10_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_D3D10_DEVICE_KHR failed");
|
||||
result = clReleaseContext(context);
|
||||
TestRequire(
|
||||
(result == CL_SUCCESS),
|
||||
"clReleaseContext with CL_CONTEXT_D3D10_DEVICE_KHR failed");
|
||||
|
||||
// create the context
|
||||
properties[0] = (cl_context_properties)CL_CONTEXT_D3D10_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_D3D10_DEVICE_KHR failed");
|
||||
|
||||
// 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_D3D10_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);
|
||||
}
|
||||
}
|
||||
HarnessD3D10_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;
|
||||
char extensions[8192];
|
||||
|
||||
// get the platform to test
|
||||
result = clGetPlatformIDs(1, &platform, NULL); NonTestRequire(result == CL_SUCCESS, "Failed to get any platforms.");
|
||||
|
||||
// make sure the platform supports the extension
|
||||
result = clGetPlatformInfo(platform, CL_PLATFORM_EXTENSIONS, sizeof(extensions), extensions, NULL); NonTestRequire(result == CL_SUCCESS, "Failed to get extensions.");
|
||||
NonTestRequire(strstr(extensions, "cl_khr_d3d10_sharing"), "cl_khr_d3d10_sharing not supported.");
|
||||
|
||||
HarnessD3D10_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;
|
||||
ID3D10Device* pDevice = 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 D3D10 Device\n");
|
||||
TestPrint("Description=%ls, VendorID=%x, DeviceID=%x\n", desc.Description, desc.VendorId, desc.DeviceId);
|
||||
TestPrint("=====================================\n");
|
||||
|
||||
// run the test on the adapter
|
||||
HarnessD3D10_CreateDevice(pAdapter, &pDevice);
|
||||
|
||||
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, num_devices);
|
||||
}
|
||||
num_devices_tested += num_devices;
|
||||
|
||||
// destroy the D3D10 device
|
||||
if (pDevice)
|
||||
{
|
||||
HarnessD3D10_DestroyDevice();
|
||||
}
|
||||
|
||||
pAdapter->Release();
|
||||
}
|
||||
pFactory->Release();
|
||||
|
||||
NonTestRequire(num_devices_tested, "No D3D10 compatible cl_device_ids were found.");
|
||||
|
||||
HarnessD3D10_TestStats();
|
||||
}
|
||||
|
||||
void TestAdapterEnumeration(cl_platform_id platform, IDXGIAdapter* pAdapter, ID3D10Device* 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;
|
||||
|
||||
HarnessD3D10_TestBegin("cl_device_id Enumeration");
|
||||
|
||||
// get the cl_device_ids for the adapter
|
||||
{
|
||||
result = clGetDeviceIDsFromD3D10KHR(
|
||||
platform,
|
||||
CL_D3D10_DXGI_ADAPTER_KHR,
|
||||
pAdapter,
|
||||
CL_ALL_DEVICES_FOR_D3D10_KHR,
|
||||
0,
|
||||
NULL,
|
||||
&num_adapter_devices);
|
||||
TestRequire(
|
||||
(result == CL_SUCCESS || result == CL_DEVICE_NOT_FOUND),
|
||||
"clGetDeviceIDsFromD3D10KHR 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 = clGetDeviceIDsFromD3D10KHR(
|
||||
platform,
|
||||
CL_D3D10_DXGI_ADAPTER_KHR,
|
||||
pAdapter,
|
||||
CL_ALL_DEVICES_FOR_D3D10_KHR,
|
||||
num_adapter_devices,
|
||||
adapter_devices,
|
||||
NULL);
|
||||
TestRequire(
|
||||
(result == CL_SUCCESS),
|
||||
"clGetDeviceIDsFromD3D10KHR failed.");
|
||||
}
|
||||
}
|
||||
|
||||
// get the cl_device_ids for the device (if it was successfully created)
|
||||
if (pDevice)
|
||||
{
|
||||
result = clGetDeviceIDsFromD3D10KHR(
|
||||
platform,
|
||||
CL_D3D10_DEVICE_KHR,
|
||||
pDevice,
|
||||
CL_ALL_DEVICES_FOR_D3D10_KHR,
|
||||
0,
|
||||
NULL,
|
||||
&num_device_devices);
|
||||
TestRequire(
|
||||
(result == CL_SUCCESS || result == CL_DEVICE_NOT_FOUND),
|
||||
"clGetDeviceIDsFromD3D10KHR 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 = clGetDeviceIDsFromD3D10KHR(
|
||||
platform,
|
||||
CL_D3D10_DEVICE_KHR,
|
||||
pDevice,
|
||||
CL_ALL_DEVICES_FOR_D3D10_KHR,
|
||||
num_device_devices,
|
||||
device_devices,
|
||||
NULL);
|
||||
TestRequire(
|
||||
(result == CL_SUCCESS),
|
||||
"clGetDeviceIDsFromD3D10KHR failed.");
|
||||
}
|
||||
|
||||
// require that each cl_device_id returned for the ID3D10Device was among the devices listed for the adapter
|
||||
for (cl_uint device_device = 0; device_device < num_device_devices; ++device_device)
|
||||
{
|
||||
cl_uint adapter_device;
|
||||
for (adapter_device = 0; adapter_device < num_adapter_devices; ++adapter_device)
|
||||
{
|
||||
if (device_devices[device_device] == adapter_devices[adapter_device])
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
TestRequire(
|
||||
(adapter_device != num_adapter_devices),
|
||||
"CL_D3D10_DEVICE_KHR devices not a subset of CL_D3D10_DXGI_ADAPTER_KHR devices");
|
||||
}
|
||||
}
|
||||
|
||||
Cleanup:
|
||||
|
||||
if (adapter_devices)
|
||||
{
|
||||
delete[] adapter_devices;
|
||||
}
|
||||
if (device_devices)
|
||||
{
|
||||
delete[] device_devices;
|
||||
}
|
||||
|
||||
*num_devices = num_device_devices;
|
||||
|
||||
HarnessD3D10_TestEnd();
|
||||
}
|
||||
|
||||
void TestAdapterDevices(cl_platform_id platform, IDXGIAdapter* pAdapter, ID3D10Device* pDevice, 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 = clGetDeviceIDsFromD3D10KHR(
|
||||
platform,
|
||||
CL_D3D10_DEVICE_KHR,
|
||||
pDevice,
|
||||
CL_ALL_DEVICES_FOR_D3D10_KHR,
|
||||
num_devices_expected,
|
||||
devices,
|
||||
&num_devices);
|
||||
NonTestRequire(
|
||||
(result == CL_SUCCESS),
|
||||
"clGetDeviceIDsFromD3D10KHR failed.");
|
||||
NonTestRequire(
|
||||
(num_devices == num_devices_expected),
|
||||
"clGetDeviceIDsFromD3D10KHR returned an unexpected number of devices.");
|
||||
|
||||
for (cl_uint i = 0; i < num_devices; ++i)
|
||||
{
|
||||
TestDevice(devices[i], pDevice);
|
||||
}
|
||||
}
|
||||
|
||||
void TestDevice(cl_device_id device, ID3D10Device* pDevice)
|
||||
{
|
||||
char device_name[1024];
|
||||
cl_int result = CL_SUCCESS;
|
||||
cl_context context = NULL;
|
||||
cl_command_queue command_queue = NULL;
|
||||
cl_bool prefer_shared_resources = CL_FALSE;
|
||||
ID3D10Device* clDevice = NULL;
|
||||
|
||||
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_D3D10_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);
|
||||
|
||||
// run 2D texture tests
|
||||
TestDeviceTexture2D(
|
||||
device,
|
||||
context,
|
||||
command_queue,
|
||||
pDevice);
|
||||
|
||||
// run 3D texture tests
|
||||
TestDeviceTexture3D(
|
||||
device,
|
||||
context,
|
||||
command_queue,
|
||||
pDevice);
|
||||
|
||||
// run misc tests
|
||||
TestDeviceMisc(
|
||||
device,
|
||||
context,
|
||||
command_queue,
|
||||
pDevice);
|
||||
|
||||
clReleaseContext(context);
|
||||
clReleaseCommandQueue(command_queue);
|
||||
}
|
||||
|
||||
bool TestDeviceContextCreate(
|
||||
cl_device_id device,
|
||||
ID3D10Device* 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;
|
||||
|
||||
ID3D10Device* clDevice = NULL;
|
||||
|
||||
bool succeeded = false;
|
||||
|
||||
HarnessD3D10_TestBegin("Context creation");
|
||||
|
||||
cl_context_properties properties[5];
|
||||
|
||||
// create the context
|
||||
properties[0] = (cl_context_properties)CL_CONTEXT_D3D10_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_D3D10_DEVICE_KHR failed");
|
||||
result = clReleaseContext(context);
|
||||
TestRequire(
|
||||
(result == CL_SUCCESS),
|
||||
"clReleaseContext with CL_CONTEXT_D3D10_DEVICE_KHR failed");
|
||||
|
||||
// create the context
|
||||
properties[0] = (cl_context_properties)CL_CONTEXT_D3D10_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_D3D10_DEVICE_KHR failed");
|
||||
result = clReleaseContext(context);
|
||||
TestRequire(
|
||||
(result == CL_SUCCESS),
|
||||
"clReleaseContext with CL_CONTEXT_D3D10_DEVICE_KHR failed");
|
||||
|
||||
// create the context
|
||||
properties[0] = (cl_context_properties)CL_CONTEXT_D3D10_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_D3D10_DEVICE_KHR failed");
|
||||
|
||||
// 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_D3D10_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);
|
||||
}
|
||||
}
|
||||
HarnessD3D10_TestEnd();
|
||||
return succeeded;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,259 +1,259 @@
|
||||
//
|
||||
// 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"
|
||||
|
||||
void SubTestMiscMultipleCreates(
|
||||
cl_context context,
|
||||
cl_command_queue command_queue,
|
||||
ID3D10Device* pDevice)
|
||||
{
|
||||
ID3D10Buffer* pBuffer = NULL;
|
||||
ID3D10Texture2D* pTexture = NULL;
|
||||
HRESULT hr = S_OK;
|
||||
cl_mem mem[5] = {NULL, NULL, NULL, NULL, NULL};
|
||||
cl_int result = CL_SUCCESS;
|
||||
|
||||
HarnessD3D10_TestBegin("Misc: Multiple Creates");
|
||||
|
||||
// create the D3D10 resources
|
||||
{
|
||||
D3D10_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 = D3D10_USAGE_DEFAULT;
|
||||
desc.BindFlags = D3D10_BIND_SHADER_RESOURCE | D3D10_BIND_RENDER_TARGET;
|
||||
desc.CPUAccessFlags = 0;
|
||||
desc.MiscFlags = 0;
|
||||
|
||||
hr = pDevice->CreateTexture2D(&desc, NULL, &pTexture);
|
||||
TestRequire(SUCCEEDED(hr), "Failed to create texture.");
|
||||
}
|
||||
|
||||
// create the D3D10 buffer
|
||||
{
|
||||
D3D10_BUFFER_DESC desc = {0};
|
||||
desc.ByteWidth = 1024;
|
||||
desc.Usage = D3D10_USAGE_DEFAULT;
|
||||
desc.CPUAccessFlags = 0;
|
||||
desc.BindFlags = D3D10_BIND_VERTEX_BUFFER;
|
||||
desc.MiscFlags = 0;
|
||||
hr = pDevice->CreateBuffer(&desc, NULL, &pBuffer);
|
||||
TestRequire(SUCCEEDED(hr), "Creating vertex buffer failed!");
|
||||
}
|
||||
|
||||
mem[0] = clCreateFromD3D10BufferKHR(
|
||||
context,
|
||||
0,
|
||||
pBuffer,
|
||||
&result);
|
||||
TestRequire(result == CL_SUCCESS, "clCreateFromD3D10BufferKHR");
|
||||
|
||||
mem[1] = clCreateFromD3D10BufferKHR(
|
||||
context,
|
||||
0,
|
||||
pBuffer,
|
||||
&result);
|
||||
TestRequire(result == CL_INVALID_D3D10_RESOURCE_KHR, "clCreateFromD3D10BufferKHR succeeded when it shouldn't");
|
||||
|
||||
mem[2] = clCreateFromD3D10Texture2DKHR(
|
||||
context,
|
||||
0,
|
||||
pTexture,
|
||||
1,
|
||||
&result);
|
||||
TestRequire(result == CL_SUCCESS, "clCreateFromD3D10Texture2DKHR failed");
|
||||
|
||||
mem[3] = clCreateFromD3D10Texture2DKHR(
|
||||
context,
|
||||
0,
|
||||
pTexture,
|
||||
1,
|
||||
&result);
|
||||
TestRequire(result == CL_INVALID_D3D10_RESOURCE_KHR, "clCreateFromD3D10Texture2DKHR succeeded when it shouldn't");
|
||||
|
||||
mem[4] = clCreateFromD3D10Texture2DKHR(
|
||||
context,
|
||||
0,
|
||||
pTexture,
|
||||
16,
|
||||
&result);
|
||||
TestRequire(result == CL_INVALID_VALUE, "clCreateFromD3D10Texture2DKHR 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();
|
||||
}
|
||||
|
||||
HarnessD3D10_TestEnd();
|
||||
}
|
||||
|
||||
void SubTestMiscAcquireRelease(
|
||||
cl_context context,
|
||||
cl_command_queue command_queue,
|
||||
ID3D10Device* pDevice)
|
||||
{
|
||||
ID3D10Buffer* pBuffer = NULL;
|
||||
ID3D10Texture2D* pTexture = NULL;
|
||||
HRESULT hr = S_OK;
|
||||
|
||||
cl_int result = CL_SUCCESS;
|
||||
cl_mem mem[2] = {NULL, NULL};
|
||||
|
||||
HarnessD3D10_TestBegin("Misc: Acquire Release");
|
||||
|
||||
// create the D3D10 resources
|
||||
{
|
||||
D3D10_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 = D3D10_USAGE_DEFAULT;
|
||||
desc.BindFlags = D3D10_BIND_SHADER_RESOURCE | D3D10_BIND_RENDER_TARGET;
|
||||
desc.CPUAccessFlags = 0;
|
||||
desc.MiscFlags = 0;
|
||||
|
||||
hr = pDevice->CreateTexture2D(&desc, NULL, &pTexture);
|
||||
TestRequire(SUCCEEDED(hr), "Failed to create texture.");
|
||||
}
|
||||
|
||||
// create the D3D10 buffer
|
||||
{
|
||||
D3D10_BUFFER_DESC desc = {0};
|
||||
desc.ByteWidth = 1024;
|
||||
desc.Usage = D3D10_USAGE_DEFAULT;
|
||||
desc.CPUAccessFlags = 0;
|
||||
desc.BindFlags = D3D10_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] = clCreateFromD3D10BufferKHR(
|
||||
context,
|
||||
0,
|
||||
pBuffer,
|
||||
&result);
|
||||
TestRequire(result == CL_SUCCESS, "clCreateFromD3D10BufferKHR");
|
||||
mem[1] = clCreateFromD3D10Texture2DKHR(
|
||||
context,
|
||||
0,
|
||||
pTexture,
|
||||
1,
|
||||
&result);
|
||||
TestRequire(result == CL_SUCCESS, "clCreateFromD3D10Texture2DKHR failed");
|
||||
|
||||
// test some acquire/release patterns
|
||||
result = clEnqueueAcquireD3D10ObjectsKHR(
|
||||
command_queue,
|
||||
1,
|
||||
&mem[1],
|
||||
0,
|
||||
NULL,
|
||||
NULL);
|
||||
TestRequire(result == CL_SUCCESS, "clEnqueueAcquireD3D10ObjectsKHR failed.");
|
||||
|
||||
result = clEnqueueAcquireD3D10ObjectsKHR(
|
||||
command_queue,
|
||||
1,
|
||||
&mem[0],
|
||||
0,
|
||||
NULL,
|
||||
NULL);
|
||||
TestRequire(result == CL_SUCCESS, "clEnqueueAcquireD3D10ObjectsKHR failed.");
|
||||
|
||||
result = clEnqueueReleaseD3D10ObjectsKHR(
|
||||
command_queue,
|
||||
1,
|
||||
&mem[1],
|
||||
0,
|
||||
NULL,
|
||||
NULL);
|
||||
TestRequire(result == CL_SUCCESS, "clEnqueueReleaseD3D10ObjectsKHR failed.");
|
||||
|
||||
|
||||
result = clEnqueueReleaseD3D10ObjectsKHR(
|
||||
command_queue,
|
||||
1,
|
||||
&mem[0],
|
||||
0,
|
||||
NULL,
|
||||
NULL);
|
||||
TestRequire(result == CL_SUCCESS, "clEnqueueReleaseD3D10ObjectsKHR failed.");
|
||||
|
||||
Cleanup:
|
||||
|
||||
for (UINT i = 0; i < 2; ++i)
|
||||
{
|
||||
if (mem[i])
|
||||
{
|
||||
clReleaseMemObject(mem[i]);
|
||||
}
|
||||
}
|
||||
if (pBuffer)
|
||||
{
|
||||
pBuffer->Release();
|
||||
}
|
||||
if (pTexture)
|
||||
{
|
||||
pTexture->Release();
|
||||
}
|
||||
|
||||
HarnessD3D10_TestEnd();
|
||||
}
|
||||
|
||||
void TestDeviceMisc(
|
||||
cl_device_id device,
|
||||
cl_context context,
|
||||
cl_command_queue command_queue,
|
||||
ID3D10Device* pDevice)
|
||||
{
|
||||
SubTestMiscMultipleCreates(
|
||||
context,
|
||||
command_queue,
|
||||
pDevice);
|
||||
|
||||
SubTestMiscAcquireRelease(
|
||||
context,
|
||||
command_queue,
|
||||
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.
|
||||
//
|
||||
#include "harness.h"
|
||||
|
||||
void SubTestMiscMultipleCreates(
|
||||
cl_context context,
|
||||
cl_command_queue command_queue,
|
||||
ID3D10Device* pDevice)
|
||||
{
|
||||
ID3D10Buffer* pBuffer = NULL;
|
||||
ID3D10Texture2D* pTexture = NULL;
|
||||
HRESULT hr = S_OK;
|
||||
cl_mem mem[5] = {NULL, NULL, NULL, NULL, NULL};
|
||||
cl_int result = CL_SUCCESS;
|
||||
|
||||
HarnessD3D10_TestBegin("Misc: Multiple Creates");
|
||||
|
||||
// create the D3D10 resources
|
||||
{
|
||||
D3D10_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 = D3D10_USAGE_DEFAULT;
|
||||
desc.BindFlags = D3D10_BIND_SHADER_RESOURCE | D3D10_BIND_RENDER_TARGET;
|
||||
desc.CPUAccessFlags = 0;
|
||||
desc.MiscFlags = 0;
|
||||
|
||||
hr = pDevice->CreateTexture2D(&desc, NULL, &pTexture);
|
||||
TestRequire(SUCCEEDED(hr), "Failed to create texture.");
|
||||
}
|
||||
|
||||
// create the D3D10 buffer
|
||||
{
|
||||
D3D10_BUFFER_DESC desc = {0};
|
||||
desc.ByteWidth = 1024;
|
||||
desc.Usage = D3D10_USAGE_DEFAULT;
|
||||
desc.CPUAccessFlags = 0;
|
||||
desc.BindFlags = D3D10_BIND_VERTEX_BUFFER;
|
||||
desc.MiscFlags = 0;
|
||||
hr = pDevice->CreateBuffer(&desc, NULL, &pBuffer);
|
||||
TestRequire(SUCCEEDED(hr), "Creating vertex buffer failed!");
|
||||
}
|
||||
|
||||
mem[0] = clCreateFromD3D10BufferKHR(
|
||||
context,
|
||||
0,
|
||||
pBuffer,
|
||||
&result);
|
||||
TestRequire(result == CL_SUCCESS, "clCreateFromD3D10BufferKHR");
|
||||
|
||||
mem[1] = clCreateFromD3D10BufferKHR(
|
||||
context,
|
||||
0,
|
||||
pBuffer,
|
||||
&result);
|
||||
TestRequire(result == CL_INVALID_D3D10_RESOURCE_KHR, "clCreateFromD3D10BufferKHR succeeded when it shouldn't");
|
||||
|
||||
mem[2] = clCreateFromD3D10Texture2DKHR(
|
||||
context,
|
||||
0,
|
||||
pTexture,
|
||||
1,
|
||||
&result);
|
||||
TestRequire(result == CL_SUCCESS, "clCreateFromD3D10Texture2DKHR failed");
|
||||
|
||||
mem[3] = clCreateFromD3D10Texture2DKHR(
|
||||
context,
|
||||
0,
|
||||
pTexture,
|
||||
1,
|
||||
&result);
|
||||
TestRequire(result == CL_INVALID_D3D10_RESOURCE_KHR, "clCreateFromD3D10Texture2DKHR succeeded when it shouldn't");
|
||||
|
||||
mem[4] = clCreateFromD3D10Texture2DKHR(
|
||||
context,
|
||||
0,
|
||||
pTexture,
|
||||
16,
|
||||
&result);
|
||||
TestRequire(result == CL_INVALID_VALUE, "clCreateFromD3D10Texture2DKHR 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();
|
||||
}
|
||||
|
||||
HarnessD3D10_TestEnd();
|
||||
}
|
||||
|
||||
void SubTestMiscAcquireRelease(
|
||||
cl_context context,
|
||||
cl_command_queue command_queue,
|
||||
ID3D10Device* pDevice)
|
||||
{
|
||||
ID3D10Buffer* pBuffer = NULL;
|
||||
ID3D10Texture2D* pTexture = NULL;
|
||||
HRESULT hr = S_OK;
|
||||
|
||||
cl_int result = CL_SUCCESS;
|
||||
cl_mem mem[2] = {NULL, NULL};
|
||||
|
||||
HarnessD3D10_TestBegin("Misc: Acquire Release");
|
||||
|
||||
// create the D3D10 resources
|
||||
{
|
||||
D3D10_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 = D3D10_USAGE_DEFAULT;
|
||||
desc.BindFlags = D3D10_BIND_SHADER_RESOURCE | D3D10_BIND_RENDER_TARGET;
|
||||
desc.CPUAccessFlags = 0;
|
||||
desc.MiscFlags = 0;
|
||||
|
||||
hr = pDevice->CreateTexture2D(&desc, NULL, &pTexture);
|
||||
TestRequire(SUCCEEDED(hr), "Failed to create texture.");
|
||||
}
|
||||
|
||||
// create the D3D10 buffer
|
||||
{
|
||||
D3D10_BUFFER_DESC desc = {0};
|
||||
desc.ByteWidth = 1024;
|
||||
desc.Usage = D3D10_USAGE_DEFAULT;
|
||||
desc.CPUAccessFlags = 0;
|
||||
desc.BindFlags = D3D10_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] = clCreateFromD3D10BufferKHR(
|
||||
context,
|
||||
0,
|
||||
pBuffer,
|
||||
&result);
|
||||
TestRequire(result == CL_SUCCESS, "clCreateFromD3D10BufferKHR");
|
||||
mem[1] = clCreateFromD3D10Texture2DKHR(
|
||||
context,
|
||||
0,
|
||||
pTexture,
|
||||
1,
|
||||
&result);
|
||||
TestRequire(result == CL_SUCCESS, "clCreateFromD3D10Texture2DKHR failed");
|
||||
|
||||
// test some acquire/release patterns
|
||||
result = clEnqueueAcquireD3D10ObjectsKHR(
|
||||
command_queue,
|
||||
1,
|
||||
&mem[1],
|
||||
0,
|
||||
NULL,
|
||||
NULL);
|
||||
TestRequire(result == CL_SUCCESS, "clEnqueueAcquireD3D10ObjectsKHR failed.");
|
||||
|
||||
result = clEnqueueAcquireD3D10ObjectsKHR(
|
||||
command_queue,
|
||||
1,
|
||||
&mem[0],
|
||||
0,
|
||||
NULL,
|
||||
NULL);
|
||||
TestRequire(result == CL_SUCCESS, "clEnqueueAcquireD3D10ObjectsKHR failed.");
|
||||
|
||||
result = clEnqueueReleaseD3D10ObjectsKHR(
|
||||
command_queue,
|
||||
1,
|
||||
&mem[1],
|
||||
0,
|
||||
NULL,
|
||||
NULL);
|
||||
TestRequire(result == CL_SUCCESS, "clEnqueueReleaseD3D10ObjectsKHR failed.");
|
||||
|
||||
|
||||
result = clEnqueueReleaseD3D10ObjectsKHR(
|
||||
command_queue,
|
||||
1,
|
||||
&mem[0],
|
||||
0,
|
||||
NULL,
|
||||
NULL);
|
||||
TestRequire(result == CL_SUCCESS, "clEnqueueReleaseD3D10ObjectsKHR failed.");
|
||||
|
||||
Cleanup:
|
||||
|
||||
for (UINT i = 0; i < 2; ++i)
|
||||
{
|
||||
if (mem[i])
|
||||
{
|
||||
clReleaseMemObject(mem[i]);
|
||||
}
|
||||
}
|
||||
if (pBuffer)
|
||||
{
|
||||
pBuffer->Release();
|
||||
}
|
||||
if (pTexture)
|
||||
{
|
||||
pTexture->Release();
|
||||
}
|
||||
|
||||
HarnessD3D10_TestEnd();
|
||||
}
|
||||
|
||||
void TestDeviceMisc(
|
||||
cl_device_id device,
|
||||
cl_context context,
|
||||
cl_command_queue command_queue,
|
||||
ID3D10Device* pDevice)
|
||||
{
|
||||
SubTestMiscMultipleCreates(
|
||||
context,
|
||||
command_queue,
|
||||
pDevice);
|
||||
|
||||
SubTestMiscAcquireRelease(
|
||||
context,
|
||||
command_queue,
|
||||
pDevice);
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,491 +1,491 @@
|
||||
//
|
||||
// Copyright (c) 2017 The Khronos Group Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#include "harness.h"
|
||||
|
||||
Texture3DSize texture3DSizes[] =
|
||||
{
|
||||
{
|
||||
4, // Width
|
||||
4, // Height
|
||||
4, // Depth
|
||||
1, // MipLevels
|
||||
1, // SubResourceCount
|
||||
{ // SubResources
|
||||
{ 0 }, // MipLevel
|
||||
{ 0 }, // MipLevel
|
||||
{ 0 }, // MipLevel
|
||||
{ 0 }, // MipLevel
|
||||
},
|
||||
0, // MiscFlags
|
||||
},
|
||||
{
|
||||
127, // Width
|
||||
25, // Height
|
||||
33, // Depth
|
||||
1, // MipLevels
|
||||
1, // SubResourceCount
|
||||
{ // SubResources
|
||||
{ 0 }, // MipLevel
|
||||
{ 0 }, // MipLevel
|
||||
{ 0 }, // MipLevel
|
||||
{ 0 }, // MipLevel
|
||||
},
|
||||
0, // MiscFlags
|
||||
},
|
||||
{
|
||||
128, // Width
|
||||
256, // Height
|
||||
64, // Depth
|
||||
4, // MipLevels
|
||||
3, // SubResourceCount
|
||||
{ // SubResources
|
||||
{ 2 }, // MipLevel
|
||||
{ 1 }, // MipLevel
|
||||
{ 0 }, // MipLevel
|
||||
{ 0 }, // MipLevel
|
||||
},
|
||||
0, // MiscFlags
|
||||
},
|
||||
{
|
||||
512, // Width
|
||||
64, // Height
|
||||
32, // Depth
|
||||
3, // MipLevels
|
||||
1, // SubResourceCount
|
||||
{ // SubResources
|
||||
{ 2 }, // MipLevel
|
||||
{ 0 }, // MipLevel
|
||||
{ 0 }, // MipLevel
|
||||
{ 0 }, // MipLevel
|
||||
},
|
||||
0, // MiscFlags
|
||||
},
|
||||
};
|
||||
UINT texture3DSizeCount = sizeof(texture3DSizes)/sizeof(texture3DSizes[0]);
|
||||
|
||||
const char *
|
||||
texture3DPatterns[2][2][2] =
|
||||
{
|
||||
{
|
||||
{"PlaceTheCasseroleDis", "hInAColdOvenPlaceACh"},
|
||||
{"airFacingTheOvenAndS", "itInItForeverThinkAb"},
|
||||
},
|
||||
{
|
||||
{"outHowHungryYouAreWh", "enNightFallsDoNotTur"},
|
||||
{"nOnTheLightMyEyeBeca", "meInflamedIHateCamus"},
|
||||
},
|
||||
};
|
||||
|
||||
void SubTestTexture3D(
|
||||
cl_context context,
|
||||
cl_command_queue command_queue,
|
||||
ID3D10Device* pDevice,
|
||||
const TextureFormat* format,
|
||||
const Texture3DSize* size)
|
||||
{
|
||||
ID3D10Texture3D* pTexture = NULL;
|
||||
HRESULT hr = S_OK;
|
||||
|
||||
cl_int result = CL_SUCCESS;
|
||||
|
||||
HarnessD3D10_TestBegin("3D Texture: Format=%s, Width=%d, Height=%d, Depth=%d, MipLevels=%d",
|
||||
format->name_format,
|
||||
size->Width,
|
||||
size->Height,
|
||||
size->Depth,
|
||||
size->MipLevels);
|
||||
|
||||
struct
|
||||
{
|
||||
cl_mem mem;
|
||||
UINT subResource;
|
||||
UINT width;
|
||||
UINT height;
|
||||
UINT depth;
|
||||
}
|
||||
subResourceInfo[4];
|
||||
|
||||
// create the D3D10 resources
|
||||
{
|
||||
D3D10_TEXTURE3D_DESC desc;
|
||||
memset(&desc, 0, sizeof(desc) );
|
||||
desc.Width = size->Width;
|
||||
desc.Height = size->Height;
|
||||
desc.Depth = size->Depth;
|
||||
desc.MipLevels = size->MipLevels;
|
||||
desc.Format = format->format;
|
||||
desc.Usage = D3D10_USAGE_DEFAULT;
|
||||
desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
|
||||
desc.CPUAccessFlags = 0;
|
||||
desc.MiscFlags = 0;
|
||||
|
||||
hr = pDevice->CreateTexture3D(&desc, NULL, &pTexture);
|
||||
TestRequire(SUCCEEDED(hr), "CreateTexture3D failed.");
|
||||
}
|
||||
|
||||
// initialize some useful variables
|
||||
for (UINT i = 0; i < size->SubResourceCount; ++i)
|
||||
{
|
||||
// compute the expected values for the subresource
|
||||
subResourceInfo[i].subResource = size->subResources[i].MipLevel;
|
||||
subResourceInfo[i].width = size->Width;
|
||||
subResourceInfo[i].height = size->Height;
|
||||
subResourceInfo[i].depth = size->Depth;
|
||||
for (UINT j = 0; j < size->subResources[i].MipLevel; ++j) {
|
||||
subResourceInfo[i].width /= 2;
|
||||
subResourceInfo[i].height /= 2;
|
||||
subResourceInfo[i].depth /= 2;
|
||||
}
|
||||
}
|
||||
|
||||
// copy a pattern into the corners of the image, coordinates
|
||||
for (UINT i = 0; i < size->SubResourceCount; ++i)
|
||||
for (UINT x = 0; x < 2; ++x)
|
||||
for (UINT y = 0; y < 2; ++y)
|
||||
for (UINT z = 0; z < 2; ++z)
|
||||
{
|
||||
// create the staging buffer
|
||||
ID3D10Texture3D* pStagingBuffer = NULL;
|
||||
{
|
||||
D3D10_TEXTURE3D_DESC desc = {0};
|
||||
desc.Width = 1;
|
||||
desc.Height = 1;
|
||||
desc.Depth = 1;
|
||||
desc.MipLevels = 1;
|
||||
desc.Format = format->format;
|
||||
desc.Usage = D3D10_USAGE_STAGING;
|
||||
desc.BindFlags = 0;
|
||||
desc.CPUAccessFlags = D3D10_CPU_ACCESS_READ | D3D10_CPU_ACCESS_WRITE;
|
||||
desc.MiscFlags = 0;
|
||||
hr = pDevice->CreateTexture3D(&desc, NULL, &pStagingBuffer);
|
||||
TestRequire(SUCCEEDED(hr), "CreateTexture3D failed.");
|
||||
}
|
||||
|
||||
// write the data to the staging buffer
|
||||
{
|
||||
D3D10_MAPPED_TEXTURE3D mappedTexture;
|
||||
hr = pStagingBuffer->Map(
|
||||
0,
|
||||
D3D10_MAP_READ_WRITE,
|
||||
0,
|
||||
&mappedTexture);
|
||||
memcpy(mappedTexture.pData, texture3DPatterns[x][y][z], format->bytesPerPixel);
|
||||
pStagingBuffer->Unmap(0);
|
||||
}
|
||||
|
||||
// copy the data to to the texture
|
||||
{
|
||||
D3D10_BOX box = {0};
|
||||
box.front = 0; box.back = 1;
|
||||
box.top = 0; box.bottom = 1;
|
||||
box.left = 0; box.right = 1;
|
||||
pDevice->CopySubresourceRegion(
|
||||
pTexture,
|
||||
subResourceInfo[i].subResource,
|
||||
x ? subResourceInfo[i].width - 1 : 0,
|
||||
y ? subResourceInfo[i].height - 1 : 0,
|
||||
z ? subResourceInfo[i].depth - 1 : 0,
|
||||
pStagingBuffer,
|
||||
0,
|
||||
&box);
|
||||
}
|
||||
|
||||
pStagingBuffer->Release();
|
||||
}
|
||||
|
||||
// create the cl_mem objects for the resources and verify its sanity
|
||||
for (UINT i = 0; i < size->SubResourceCount; ++i)
|
||||
{
|
||||
// create a cl_mem for the resource
|
||||
subResourceInfo[i].mem = clCreateFromD3D10Texture3DKHR(
|
||||
context,
|
||||
0,
|
||||
pTexture,
|
||||
subResourceInfo[i].subResource,
|
||||
&result);
|
||||
TestRequire(result == CL_SUCCESS, "clCreateFromD3D10Texture3DKHR failed");
|
||||
|
||||
// query resource pointer and verify
|
||||
ID3D10Resource* clResource = NULL;
|
||||
result = clGetMemObjectInfo(
|
||||
subResourceInfo[i].mem,
|
||||
CL_MEM_D3D10_RESOURCE_KHR,
|
||||
sizeof(clResource),
|
||||
&clResource,
|
||||
NULL);
|
||||
TestRequire(result == CL_SUCCESS, "clGetMemObjectInfo for CL_MEM_D3D10_RESOURCE_KHR failed.");
|
||||
TestRequire(clResource == pTexture, "clGetMemObjectInfo for CL_MEM_D3D10_RESOURCE_KHR returned incorrect value.");
|
||||
|
||||
// query subresource and verify
|
||||
UINT clSubResource;
|
||||
result = clGetImageInfo(
|
||||
subResourceInfo[i].mem,
|
||||
CL_IMAGE_D3D10_SUBRESOURCE_KHR,
|
||||
sizeof(clSubResource),
|
||||
&clSubResource,
|
||||
NULL);
|
||||
TestRequire(result == CL_SUCCESS, "clGetImageInfo for CL_IMAGE_D3D10_SUBRESOURCE_KHR failed");
|
||||
TestRequire(clResource == pTexture, "clGetImageInfo for CL_IMAGE_D3D10_SUBRESOURCE_KHR returned incorrect value.");
|
||||
|
||||
// query format and verify
|
||||
cl_image_format clFormat;
|
||||
result = clGetImageInfo(
|
||||
subResourceInfo[i].mem,
|
||||
CL_IMAGE_FORMAT,
|
||||
sizeof(clFormat),
|
||||
&clFormat,
|
||||
NULL);
|
||||
TestRequire(result == CL_SUCCESS, "clGetImageInfo for CL_IMAGE_FORMAT failed");
|
||||
TestRequire(clFormat.image_channel_order == format->channel_order, "clGetImageInfo for CL_IMAGE_FORMAT returned incorrect channel order.");
|
||||
TestRequire(clFormat.image_channel_data_type == format->channel_type, "clGetImageInfo for CL_IMAGE_FORMAT returned incorrect channel data type.");
|
||||
|
||||
// query width
|
||||
size_t width;
|
||||
result = clGetImageInfo(
|
||||
subResourceInfo[i].mem,
|
||||
CL_IMAGE_WIDTH,
|
||||
sizeof(width),
|
||||
&width,
|
||||
NULL);
|
||||
TestRequire(result == CL_SUCCESS, "clGetImageInfo for CL_IMAGE_WIDTH failed");
|
||||
TestRequire(width == subResourceInfo[i].width, "clGetImageInfo for CL_IMAGE_HEIGHT returned incorrect value.");
|
||||
|
||||
// query height
|
||||
size_t height;
|
||||
result = clGetImageInfo(
|
||||
subResourceInfo[i].mem,
|
||||
CL_IMAGE_HEIGHT,
|
||||
sizeof(height),
|
||||
&height,
|
||||
NULL);
|
||||
TestRequire(result == CL_SUCCESS, "clGetImageInfo for CL_IMAGE_HEIGHT failed");
|
||||
TestRequire(height == subResourceInfo[i].height, "clGetImageInfo for CL_IMAGE_HEIGHT returned incorrect value.");
|
||||
|
||||
// query depth
|
||||
size_t depth;
|
||||
result = clGetImageInfo(
|
||||
subResourceInfo[i].mem,
|
||||
CL_IMAGE_DEPTH,
|
||||
sizeof(depth),
|
||||
&depth,
|
||||
NULL);
|
||||
TestRequire(result == CL_SUCCESS, "clGetImageInfo for CL_IMAGE_DEPTH failed");
|
||||
TestRequire(depth == subResourceInfo[i].depth, "clGetImageInfo for CL_IMAGE_DEPTH returned incorrect value.");
|
||||
|
||||
}
|
||||
|
||||
// acquire the resources for OpenCL
|
||||
{
|
||||
cl_mem memToAcquire[MAX_REGISTERED_SUBRESOURCES];
|
||||
|
||||
// cut the registered sub-resources into two sets and send the acquire calls for them separately
|
||||
for(UINT i = 0; i < size->SubResourceCount; ++i)
|
||||
{
|
||||
memToAcquire[i] = subResourceInfo[i].mem;
|
||||
}
|
||||
|
||||
// do the acquire
|
||||
result = clEnqueueAcquireD3D10ObjectsKHR(
|
||||
command_queue,
|
||||
size->SubResourceCount,
|
||||
memToAcquire,
|
||||
0,
|
||||
NULL,
|
||||
NULL);
|
||||
TestRequire(result == CL_SUCCESS, "clEnqueueAcquireD3D10ObjectsKHR failed.");
|
||||
}
|
||||
|
||||
// download the data using OpenCL & compare with the expected results
|
||||
// copy the corners of the image into the image
|
||||
for (UINT i = 0; i < size->SubResourceCount; ++i)
|
||||
for (UINT x = 0; x < 2; ++x)
|
||||
for (UINT y = 0; y < 2; ++y)
|
||||
for (UINT z = 0; z < 2; ++z)
|
||||
{
|
||||
if (x == y && y == z && 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
size_t src[3] =
|
||||
{
|
||||
x ? subResourceInfo[i].width - 1 : 0,
|
||||
y ? subResourceInfo[i].height - 1 : 0,
|
||||
z ? subResourceInfo[i].depth - 1 : 0,
|
||||
};
|
||||
size_t dst[3] =
|
||||
{
|
||||
x ? subResourceInfo[i].width - 2 : 1,
|
||||
y ? subResourceInfo[i].height - 2 : 1,
|
||||
z ? subResourceInfo[i].depth - 2 : 1,
|
||||
};
|
||||
size_t region[3] =
|
||||
{
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
};
|
||||
result = clEnqueueCopyImage(
|
||||
command_queue,
|
||||
subResourceInfo[i].mem,
|
||||
subResourceInfo[i].mem,
|
||||
src,
|
||||
dst,
|
||||
region,
|
||||
0,
|
||||
NULL,
|
||||
NULL);
|
||||
TestRequire(result == CL_SUCCESS, "clEnqueueCopyImage failed.");
|
||||
}
|
||||
|
||||
// release the resource from OpenCL
|
||||
{
|
||||
cl_mem memToAcquire[MAX_REGISTERED_SUBRESOURCES];
|
||||
for(UINT i = 0; i < size->SubResourceCount; ++i)
|
||||
{
|
||||
memToAcquire[i] = subResourceInfo[i].mem;
|
||||
}
|
||||
|
||||
// do the release
|
||||
result = clEnqueueReleaseD3D10ObjectsKHR(
|
||||
command_queue,
|
||||
size->SubResourceCount,
|
||||
memToAcquire,
|
||||
0,
|
||||
NULL,
|
||||
NULL);
|
||||
TestRequire(result == CL_SUCCESS, "clEnqueueReleaseD3D10ObjectsKHR failed.");
|
||||
}
|
||||
|
||||
for (UINT i = 0; i < size->SubResourceCount; ++i)
|
||||
for (UINT x = 0; x < 2; ++x)
|
||||
for (UINT y = 0; y < 2; ++y)
|
||||
for (UINT z = 0; z < 2; ++z)
|
||||
{
|
||||
// create the staging buffer
|
||||
ID3D10Texture3D* pStagingBuffer = NULL;
|
||||
{
|
||||
D3D10_TEXTURE3D_DESC desc = {0};
|
||||
desc.Width = 1;
|
||||
desc.Height = 1;
|
||||
desc.Depth = 1;
|
||||
desc.MipLevels = 1;
|
||||
desc.Format = format->format;
|
||||
desc.Usage = D3D10_USAGE_STAGING;
|
||||
desc.BindFlags = 0;
|
||||
desc.CPUAccessFlags = D3D10_CPU_ACCESS_READ | D3D10_CPU_ACCESS_WRITE;
|
||||
desc.MiscFlags = 0;
|
||||
hr = pDevice->CreateTexture3D(&desc, NULL, &pStagingBuffer);
|
||||
TestRequire(SUCCEEDED(hr), "Failed to create staging buffer.");
|
||||
}
|
||||
|
||||
// wipe out the staging buffer to make sure we don't get stale values
|
||||
{
|
||||
D3D10_MAPPED_TEXTURE3D mappedTexture;
|
||||
hr = pStagingBuffer->Map(
|
||||
0,
|
||||
D3D10_MAP_READ_WRITE,
|
||||
0,
|
||||
&mappedTexture);
|
||||
TestRequire(SUCCEEDED(hr), "Failed to map staging buffer");
|
||||
memset(mappedTexture.pData, 0, format->bytesPerPixel);
|
||||
pStagingBuffer->Unmap(0);
|
||||
}
|
||||
|
||||
// copy the pixel to the staging buffer
|
||||
{
|
||||
D3D10_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;
|
||||
pDevice->CopySubresourceRegion(
|
||||
pStagingBuffer,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
pTexture,
|
||||
subResourceInfo[i].subResource,
|
||||
&box);
|
||||
}
|
||||
|
||||
// make sure we read back what was written next door
|
||||
{
|
||||
D3D10_MAPPED_TEXTURE3D mappedTexture;
|
||||
hr = pStagingBuffer->Map(
|
||||
0,
|
||||
D3D10_MAP_READ_WRITE,
|
||||
0,
|
||||
&mappedTexture);
|
||||
TestRequire(SUCCEEDED(hr), "Failed to map staging buffer");
|
||||
|
||||
/*
|
||||
// This can be helpful in debugging...
|
||||
printf("\n");
|
||||
for (UINT k = 0; k < format->bytesPerPixel; ++k)
|
||||
{
|
||||
printf("[%c %c]\n",
|
||||
texture2DPatterns[x][y][k],
|
||||
( (char *)mappedTexture.pData )[k]);
|
||||
}
|
||||
*/
|
||||
|
||||
TestRequire(
|
||||
!memcmp(mappedTexture.pData, texture3DPatterns[x][y][z], format->bytesPerPixel),
|
||||
"Failed to map staging buffer");
|
||||
|
||||
pStagingBuffer->Unmap(0);
|
||||
}
|
||||
|
||||
pStagingBuffer->Release();
|
||||
}
|
||||
|
||||
|
||||
Cleanup:
|
||||
|
||||
if (pTexture)
|
||||
{
|
||||
pTexture->Release();
|
||||
}
|
||||
for (UINT i = 0; i < size->SubResourceCount; ++i)
|
||||
{
|
||||
clReleaseMemObject(subResourceInfo[i].mem);
|
||||
}
|
||||
|
||||
HarnessD3D10_TestEnd();
|
||||
}
|
||||
|
||||
|
||||
void TestDeviceTexture3D(
|
||||
cl_device_id device,
|
||||
cl_context context,
|
||||
cl_command_queue command_queue,
|
||||
ID3D10Device* pDevice)
|
||||
{
|
||||
cl_int result = CL_SUCCESS;
|
||||
|
||||
|
||||
for (UINT format = 0, size = 0; format < formatCount; ++size, ++format)
|
||||
{
|
||||
SubTestTexture3D(
|
||||
context,
|
||||
command_queue,
|
||||
pDevice,
|
||||
&formats[format],
|
||||
&texture3DSizes[size % texture3DSizeCount]);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Copyright (c) 2017 The Khronos Group Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#include "harness.h"
|
||||
|
||||
Texture3DSize texture3DSizes[] =
|
||||
{
|
||||
{
|
||||
4, // Width
|
||||
4, // Height
|
||||
4, // Depth
|
||||
1, // MipLevels
|
||||
1, // SubResourceCount
|
||||
{ // SubResources
|
||||
{ 0 }, // MipLevel
|
||||
{ 0 }, // MipLevel
|
||||
{ 0 }, // MipLevel
|
||||
{ 0 }, // MipLevel
|
||||
},
|
||||
0, // MiscFlags
|
||||
},
|
||||
{
|
||||
127, // Width
|
||||
25, // Height
|
||||
33, // Depth
|
||||
1, // MipLevels
|
||||
1, // SubResourceCount
|
||||
{ // SubResources
|
||||
{ 0 }, // MipLevel
|
||||
{ 0 }, // MipLevel
|
||||
{ 0 }, // MipLevel
|
||||
{ 0 }, // MipLevel
|
||||
},
|
||||
0, // MiscFlags
|
||||
},
|
||||
{
|
||||
128, // Width
|
||||
256, // Height
|
||||
64, // Depth
|
||||
4, // MipLevels
|
||||
3, // SubResourceCount
|
||||
{ // SubResources
|
||||
{ 2 }, // MipLevel
|
||||
{ 1 }, // MipLevel
|
||||
{ 0 }, // MipLevel
|
||||
{ 0 }, // MipLevel
|
||||
},
|
||||
0, // MiscFlags
|
||||
},
|
||||
{
|
||||
512, // Width
|
||||
64, // Height
|
||||
32, // Depth
|
||||
3, // MipLevels
|
||||
1, // SubResourceCount
|
||||
{ // SubResources
|
||||
{ 2 }, // MipLevel
|
||||
{ 0 }, // MipLevel
|
||||
{ 0 }, // MipLevel
|
||||
{ 0 }, // MipLevel
|
||||
},
|
||||
0, // MiscFlags
|
||||
},
|
||||
};
|
||||
UINT texture3DSizeCount = sizeof(texture3DSizes)/sizeof(texture3DSizes[0]);
|
||||
|
||||
const char *
|
||||
texture3DPatterns[2][2][2] =
|
||||
{
|
||||
{
|
||||
{"PlaceTheCasseroleDis", "hInAColdOvenPlaceACh"},
|
||||
{"airFacingTheOvenAndS", "itInItForeverThinkAb"},
|
||||
},
|
||||
{
|
||||
{"outHowHungryYouAreWh", "enNightFallsDoNotTur"},
|
||||
{"nOnTheLightMyEyeBeca", "meInflamedIHateCamus"},
|
||||
},
|
||||
};
|
||||
|
||||
void SubTestTexture3D(
|
||||
cl_context context,
|
||||
cl_command_queue command_queue,
|
||||
ID3D10Device* pDevice,
|
||||
const TextureFormat* format,
|
||||
const Texture3DSize* size)
|
||||
{
|
||||
ID3D10Texture3D* pTexture = NULL;
|
||||
HRESULT hr = S_OK;
|
||||
|
||||
cl_int result = CL_SUCCESS;
|
||||
|
||||
HarnessD3D10_TestBegin("3D Texture: Format=%s, Width=%d, Height=%d, Depth=%d, MipLevels=%d",
|
||||
format->name_format,
|
||||
size->Width,
|
||||
size->Height,
|
||||
size->Depth,
|
||||
size->MipLevels);
|
||||
|
||||
struct
|
||||
{
|
||||
cl_mem mem;
|
||||
UINT subResource;
|
||||
UINT width;
|
||||
UINT height;
|
||||
UINT depth;
|
||||
}
|
||||
subResourceInfo[4];
|
||||
|
||||
// create the D3D10 resources
|
||||
{
|
||||
D3D10_TEXTURE3D_DESC desc;
|
||||
memset(&desc, 0, sizeof(desc) );
|
||||
desc.Width = size->Width;
|
||||
desc.Height = size->Height;
|
||||
desc.Depth = size->Depth;
|
||||
desc.MipLevels = size->MipLevels;
|
||||
desc.Format = format->format;
|
||||
desc.Usage = D3D10_USAGE_DEFAULT;
|
||||
desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
|
||||
desc.CPUAccessFlags = 0;
|
||||
desc.MiscFlags = 0;
|
||||
|
||||
hr = pDevice->CreateTexture3D(&desc, NULL, &pTexture);
|
||||
TestRequire(SUCCEEDED(hr), "CreateTexture3D failed.");
|
||||
}
|
||||
|
||||
// initialize some useful variables
|
||||
for (UINT i = 0; i < size->SubResourceCount; ++i)
|
||||
{
|
||||
// compute the expected values for the subresource
|
||||
subResourceInfo[i].subResource = size->subResources[i].MipLevel;
|
||||
subResourceInfo[i].width = size->Width;
|
||||
subResourceInfo[i].height = size->Height;
|
||||
subResourceInfo[i].depth = size->Depth;
|
||||
for (UINT j = 0; j < size->subResources[i].MipLevel; ++j) {
|
||||
subResourceInfo[i].width /= 2;
|
||||
subResourceInfo[i].height /= 2;
|
||||
subResourceInfo[i].depth /= 2;
|
||||
}
|
||||
}
|
||||
|
||||
// copy a pattern into the corners of the image, coordinates
|
||||
for (UINT i = 0; i < size->SubResourceCount; ++i)
|
||||
for (UINT x = 0; x < 2; ++x)
|
||||
for (UINT y = 0; y < 2; ++y)
|
||||
for (UINT z = 0; z < 2; ++z)
|
||||
{
|
||||
// create the staging buffer
|
||||
ID3D10Texture3D* pStagingBuffer = NULL;
|
||||
{
|
||||
D3D10_TEXTURE3D_DESC desc = {0};
|
||||
desc.Width = 1;
|
||||
desc.Height = 1;
|
||||
desc.Depth = 1;
|
||||
desc.MipLevels = 1;
|
||||
desc.Format = format->format;
|
||||
desc.Usage = D3D10_USAGE_STAGING;
|
||||
desc.BindFlags = 0;
|
||||
desc.CPUAccessFlags = D3D10_CPU_ACCESS_READ | D3D10_CPU_ACCESS_WRITE;
|
||||
desc.MiscFlags = 0;
|
||||
hr = pDevice->CreateTexture3D(&desc, NULL, &pStagingBuffer);
|
||||
TestRequire(SUCCEEDED(hr), "CreateTexture3D failed.");
|
||||
}
|
||||
|
||||
// write the data to the staging buffer
|
||||
{
|
||||
D3D10_MAPPED_TEXTURE3D mappedTexture;
|
||||
hr = pStagingBuffer->Map(
|
||||
0,
|
||||
D3D10_MAP_READ_WRITE,
|
||||
0,
|
||||
&mappedTexture);
|
||||
memcpy(mappedTexture.pData, texture3DPatterns[x][y][z], format->bytesPerPixel);
|
||||
pStagingBuffer->Unmap(0);
|
||||
}
|
||||
|
||||
// copy the data to to the texture
|
||||
{
|
||||
D3D10_BOX box = {0};
|
||||
box.front = 0; box.back = 1;
|
||||
box.top = 0; box.bottom = 1;
|
||||
box.left = 0; box.right = 1;
|
||||
pDevice->CopySubresourceRegion(
|
||||
pTexture,
|
||||
subResourceInfo[i].subResource,
|
||||
x ? subResourceInfo[i].width - 1 : 0,
|
||||
y ? subResourceInfo[i].height - 1 : 0,
|
||||
z ? subResourceInfo[i].depth - 1 : 0,
|
||||
pStagingBuffer,
|
||||
0,
|
||||
&box);
|
||||
}
|
||||
|
||||
pStagingBuffer->Release();
|
||||
}
|
||||
|
||||
// create the cl_mem objects for the resources and verify its sanity
|
||||
for (UINT i = 0; i < size->SubResourceCount; ++i)
|
||||
{
|
||||
// create a cl_mem for the resource
|
||||
subResourceInfo[i].mem = clCreateFromD3D10Texture3DKHR(
|
||||
context,
|
||||
0,
|
||||
pTexture,
|
||||
subResourceInfo[i].subResource,
|
||||
&result);
|
||||
TestRequire(result == CL_SUCCESS, "clCreateFromD3D10Texture3DKHR failed");
|
||||
|
||||
// query resource pointer and verify
|
||||
ID3D10Resource* clResource = NULL;
|
||||
result = clGetMemObjectInfo(
|
||||
subResourceInfo[i].mem,
|
||||
CL_MEM_D3D10_RESOURCE_KHR,
|
||||
sizeof(clResource),
|
||||
&clResource,
|
||||
NULL);
|
||||
TestRequire(result == CL_SUCCESS, "clGetMemObjectInfo for CL_MEM_D3D10_RESOURCE_KHR failed.");
|
||||
TestRequire(clResource == pTexture, "clGetMemObjectInfo for CL_MEM_D3D10_RESOURCE_KHR returned incorrect value.");
|
||||
|
||||
// query subresource and verify
|
||||
UINT clSubResource;
|
||||
result = clGetImageInfo(
|
||||
subResourceInfo[i].mem,
|
||||
CL_IMAGE_D3D10_SUBRESOURCE_KHR,
|
||||
sizeof(clSubResource),
|
||||
&clSubResource,
|
||||
NULL);
|
||||
TestRequire(result == CL_SUCCESS, "clGetImageInfo for CL_IMAGE_D3D10_SUBRESOURCE_KHR failed");
|
||||
TestRequire(clResource == pTexture, "clGetImageInfo for CL_IMAGE_D3D10_SUBRESOURCE_KHR returned incorrect value.");
|
||||
|
||||
// query format and verify
|
||||
cl_image_format clFormat;
|
||||
result = clGetImageInfo(
|
||||
subResourceInfo[i].mem,
|
||||
CL_IMAGE_FORMAT,
|
||||
sizeof(clFormat),
|
||||
&clFormat,
|
||||
NULL);
|
||||
TestRequire(result == CL_SUCCESS, "clGetImageInfo for CL_IMAGE_FORMAT failed");
|
||||
TestRequire(clFormat.image_channel_order == format->channel_order, "clGetImageInfo for CL_IMAGE_FORMAT returned incorrect channel order.");
|
||||
TestRequire(clFormat.image_channel_data_type == format->channel_type, "clGetImageInfo for CL_IMAGE_FORMAT returned incorrect channel data type.");
|
||||
|
||||
// query width
|
||||
size_t width;
|
||||
result = clGetImageInfo(
|
||||
subResourceInfo[i].mem,
|
||||
CL_IMAGE_WIDTH,
|
||||
sizeof(width),
|
||||
&width,
|
||||
NULL);
|
||||
TestRequire(result == CL_SUCCESS, "clGetImageInfo for CL_IMAGE_WIDTH failed");
|
||||
TestRequire(width == subResourceInfo[i].width, "clGetImageInfo for CL_IMAGE_HEIGHT returned incorrect value.");
|
||||
|
||||
// query height
|
||||
size_t height;
|
||||
result = clGetImageInfo(
|
||||
subResourceInfo[i].mem,
|
||||
CL_IMAGE_HEIGHT,
|
||||
sizeof(height),
|
||||
&height,
|
||||
NULL);
|
||||
TestRequire(result == CL_SUCCESS, "clGetImageInfo for CL_IMAGE_HEIGHT failed");
|
||||
TestRequire(height == subResourceInfo[i].height, "clGetImageInfo for CL_IMAGE_HEIGHT returned incorrect value.");
|
||||
|
||||
// query depth
|
||||
size_t depth;
|
||||
result = clGetImageInfo(
|
||||
subResourceInfo[i].mem,
|
||||
CL_IMAGE_DEPTH,
|
||||
sizeof(depth),
|
||||
&depth,
|
||||
NULL);
|
||||
TestRequire(result == CL_SUCCESS, "clGetImageInfo for CL_IMAGE_DEPTH failed");
|
||||
TestRequire(depth == subResourceInfo[i].depth, "clGetImageInfo for CL_IMAGE_DEPTH returned incorrect value.");
|
||||
|
||||
}
|
||||
|
||||
// acquire the resources for OpenCL
|
||||
{
|
||||
cl_mem memToAcquire[MAX_REGISTERED_SUBRESOURCES];
|
||||
|
||||
// cut the registered sub-resources into two sets and send the acquire calls for them separately
|
||||
for(UINT i = 0; i < size->SubResourceCount; ++i)
|
||||
{
|
||||
memToAcquire[i] = subResourceInfo[i].mem;
|
||||
}
|
||||
|
||||
// do the acquire
|
||||
result = clEnqueueAcquireD3D10ObjectsKHR(
|
||||
command_queue,
|
||||
size->SubResourceCount,
|
||||
memToAcquire,
|
||||
0,
|
||||
NULL,
|
||||
NULL);
|
||||
TestRequire(result == CL_SUCCESS, "clEnqueueAcquireD3D10ObjectsKHR failed.");
|
||||
}
|
||||
|
||||
// download the data using OpenCL & compare with the expected results
|
||||
// copy the corners of the image into the image
|
||||
for (UINT i = 0; i < size->SubResourceCount; ++i)
|
||||
for (UINT x = 0; x < 2; ++x)
|
||||
for (UINT y = 0; y < 2; ++y)
|
||||
for (UINT z = 0; z < 2; ++z)
|
||||
{
|
||||
if (x == y && y == z && 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
size_t src[3] =
|
||||
{
|
||||
x ? subResourceInfo[i].width - 1 : 0,
|
||||
y ? subResourceInfo[i].height - 1 : 0,
|
||||
z ? subResourceInfo[i].depth - 1 : 0,
|
||||
};
|
||||
size_t dst[3] =
|
||||
{
|
||||
x ? subResourceInfo[i].width - 2 : 1,
|
||||
y ? subResourceInfo[i].height - 2 : 1,
|
||||
z ? subResourceInfo[i].depth - 2 : 1,
|
||||
};
|
||||
size_t region[3] =
|
||||
{
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
};
|
||||
result = clEnqueueCopyImage(
|
||||
command_queue,
|
||||
subResourceInfo[i].mem,
|
||||
subResourceInfo[i].mem,
|
||||
src,
|
||||
dst,
|
||||
region,
|
||||
0,
|
||||
NULL,
|
||||
NULL);
|
||||
TestRequire(result == CL_SUCCESS, "clEnqueueCopyImage failed.");
|
||||
}
|
||||
|
||||
// release the resource from OpenCL
|
||||
{
|
||||
cl_mem memToAcquire[MAX_REGISTERED_SUBRESOURCES];
|
||||
for(UINT i = 0; i < size->SubResourceCount; ++i)
|
||||
{
|
||||
memToAcquire[i] = subResourceInfo[i].mem;
|
||||
}
|
||||
|
||||
// do the release
|
||||
result = clEnqueueReleaseD3D10ObjectsKHR(
|
||||
command_queue,
|
||||
size->SubResourceCount,
|
||||
memToAcquire,
|
||||
0,
|
||||
NULL,
|
||||
NULL);
|
||||
TestRequire(result == CL_SUCCESS, "clEnqueueReleaseD3D10ObjectsKHR failed.");
|
||||
}
|
||||
|
||||
for (UINT i = 0; i < size->SubResourceCount; ++i)
|
||||
for (UINT x = 0; x < 2; ++x)
|
||||
for (UINT y = 0; y < 2; ++y)
|
||||
for (UINT z = 0; z < 2; ++z)
|
||||
{
|
||||
// create the staging buffer
|
||||
ID3D10Texture3D* pStagingBuffer = NULL;
|
||||
{
|
||||
D3D10_TEXTURE3D_DESC desc = {0};
|
||||
desc.Width = 1;
|
||||
desc.Height = 1;
|
||||
desc.Depth = 1;
|
||||
desc.MipLevels = 1;
|
||||
desc.Format = format->format;
|
||||
desc.Usage = D3D10_USAGE_STAGING;
|
||||
desc.BindFlags = 0;
|
||||
desc.CPUAccessFlags = D3D10_CPU_ACCESS_READ | D3D10_CPU_ACCESS_WRITE;
|
||||
desc.MiscFlags = 0;
|
||||
hr = pDevice->CreateTexture3D(&desc, NULL, &pStagingBuffer);
|
||||
TestRequire(SUCCEEDED(hr), "Failed to create staging buffer.");
|
||||
}
|
||||
|
||||
// wipe out the staging buffer to make sure we don't get stale values
|
||||
{
|
||||
D3D10_MAPPED_TEXTURE3D mappedTexture;
|
||||
hr = pStagingBuffer->Map(
|
||||
0,
|
||||
D3D10_MAP_READ_WRITE,
|
||||
0,
|
||||
&mappedTexture);
|
||||
TestRequire(SUCCEEDED(hr), "Failed to map staging buffer");
|
||||
memset(mappedTexture.pData, 0, format->bytesPerPixel);
|
||||
pStagingBuffer->Unmap(0);
|
||||
}
|
||||
|
||||
// copy the pixel to the staging buffer
|
||||
{
|
||||
D3D10_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;
|
||||
pDevice->CopySubresourceRegion(
|
||||
pStagingBuffer,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
pTexture,
|
||||
subResourceInfo[i].subResource,
|
||||
&box);
|
||||
}
|
||||
|
||||
// make sure we read back what was written next door
|
||||
{
|
||||
D3D10_MAPPED_TEXTURE3D mappedTexture;
|
||||
hr = pStagingBuffer->Map(
|
||||
0,
|
||||
D3D10_MAP_READ_WRITE,
|
||||
0,
|
||||
&mappedTexture);
|
||||
TestRequire(SUCCEEDED(hr), "Failed to map staging buffer");
|
||||
|
||||
/*
|
||||
// This can be helpful in debugging...
|
||||
printf("\n");
|
||||
for (UINT k = 0; k < format->bytesPerPixel; ++k)
|
||||
{
|
||||
printf("[%c %c]\n",
|
||||
texture2DPatterns[x][y][k],
|
||||
( (char *)mappedTexture.pData )[k]);
|
||||
}
|
||||
*/
|
||||
|
||||
TestRequire(
|
||||
!memcmp(mappedTexture.pData, texture3DPatterns[x][y][z], format->bytesPerPixel),
|
||||
"Failed to map staging buffer");
|
||||
|
||||
pStagingBuffer->Unmap(0);
|
||||
}
|
||||
|
||||
pStagingBuffer->Release();
|
||||
}
|
||||
|
||||
|
||||
Cleanup:
|
||||
|
||||
if (pTexture)
|
||||
{
|
||||
pTexture->Release();
|
||||
}
|
||||
for (UINT i = 0; i < size->SubResourceCount; ++i)
|
||||
{
|
||||
clReleaseMemObject(subResourceInfo[i].mem);
|
||||
}
|
||||
|
||||
HarnessD3D10_TestEnd();
|
||||
}
|
||||
|
||||
|
||||
void TestDeviceTexture3D(
|
||||
cl_device_id device,
|
||||
cl_context context,
|
||||
cl_command_queue command_queue,
|
||||
ID3D10Device* pDevice)
|
||||
{
|
||||
cl_int result = CL_SUCCESS;
|
||||
|
||||
|
||||
for (UINT format = 0, size = 0; format < formatCount; ++size, ++format)
|
||||
{
|
||||
SubTestTexture3D(
|
||||
context,
|
||||
command_queue,
|
||||
pDevice,
|
||||
&formats[format],
|
||||
&texture3DSizes[size % texture3DSizeCount]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user