• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright (c) 2017 The Khronos Group Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //    http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 #define _CRT_SECURE_NO_WARNINGS
17 #include "harness.h"
18 
SubTestMiscMultipleCreates(cl_context context,cl_command_queue command_queue,ID3D11Device * pDevice)19 void SubTestMiscMultipleCreates(
20     cl_context context,
21     cl_command_queue command_queue,
22     ID3D11Device* pDevice)
23 {
24     cl_mem mem[5] = {NULL, NULL, NULL, NULL, NULL};
25     ID3D11Buffer* pBuffer = NULL;
26     ID3D11Texture2D* pTexture = NULL;
27     HRESULT hr = S_OK;
28 
29     cl_int result = CL_SUCCESS;
30 
31     HarnessD3D11_TestBegin("Misc: Multiple Creates");
32 
33     // create the D3D11 resources
34     {
35         D3D11_TEXTURE2D_DESC desc;
36         memset(&desc, 0, sizeof(desc) );
37         desc.Width      = 256;
38         desc.Height     = 256;
39         desc.MipLevels  = 4;
40         desc.ArraySize  = 4;
41         desc.Format     = DXGI_FORMAT_R32G32B32A32_FLOAT;
42         desc.SampleDesc.Count = 1;
43         desc.SampleDesc.Quality = 0;
44         desc.Usage = D3D11_USAGE_DEFAULT;
45         desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
46         desc.CPUAccessFlags = 0;
47         desc.MiscFlags = 0;
48 
49         hr = pDevice->CreateTexture2D(&desc, NULL, &pTexture);
50         TestRequire(SUCCEEDED(hr), "Failed to create texture.");
51     }
52 
53     // create the D3D11 buffer
54     {
55         D3D11_BUFFER_DESC desc = {0};
56         desc.ByteWidth = 1124;
57         desc.Usage = D3D11_USAGE_DEFAULT;
58         desc.CPUAccessFlags = 0;
59         desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
60         desc.MiscFlags = 0;
61         hr = pDevice->CreateBuffer(&desc, NULL, &pBuffer);
62         TestRequire(SUCCEEDED(hr), "Creating vertex buffer failed!");
63     }
64 
65     mem[0] = clCreateFromD3D11BufferKHR(
66         context,
67         0,
68         pBuffer,
69         &result);
70     TestRequire(result == CL_SUCCESS, "clCreateFromD3D11BufferKHR");
71 
72     mem[1] = clCreateFromD3D11BufferKHR(
73         context,
74         0,
75         pBuffer,
76         &result);
77     TestRequire(result == CL_INVALID_D3D11_RESOURCE_KHR, "clCreateFromD3D11BufferKHR succeeded when it shouldn't");
78 
79     mem[2] = clCreateFromD3D11Texture2DKHR(
80         context,
81         0,
82         pTexture,
83         1,
84         &result);
85     TestRequire(result == CL_SUCCESS, "clCreateFromD3D11Texture2DKHR failed");
86 
87     mem[3] = clCreateFromD3D11Texture2DKHR(
88         context,
89         0,
90         pTexture,
91         1,
92         &result);
93     TestRequire(result == CL_INVALID_D3D11_RESOURCE_KHR, "clCreateFromD3D11Texture2DKHR succeeded when it shouldn't");
94 
95     mem[4] = clCreateFromD3D11Texture2DKHR(
96         context,
97         0,
98         pTexture,
99         16,
100         &result);
101     TestRequire(result == CL_INVALID_VALUE, "clCreateFromD3D11Texture2DKHR succeeded when it shouldn't");
102 
103 
104 Cleanup:
105 
106     for (UINT i = 0; i < 4; ++i)
107     {
108         if (mem[i])
109         {
110             clReleaseMemObject(mem[i]);
111         }
112     }
113     if (pBuffer)
114     {
115         pBuffer->Release();
116     }
117     if (pTexture)
118     {
119         pTexture->Release();
120     }
121 
122     HarnessD3D11_TestEnd();
123 }
124 
SubTestMiscAcquireRelease(cl_device_id device,cl_context context,ID3D11Device * pDevice)125 void SubTestMiscAcquireRelease(
126     cl_device_id  device,
127     cl_context context,
128     ID3D11Device* pDevice)
129 {
130     ID3D11Buffer* pBuffer = NULL;
131     ID3D11Texture2D* pTexture = NULL;
132     HRESULT hr = S_OK;
133 
134     cl_int result = CL_SUCCESS;
135     cl_mem mem[2] = {NULL, NULL};
136 
137     HarnessD3D11_TestBegin("Misc: Acquire Release");
138 
139 
140     // create the D3D11 resources
141     {
142         D3D11_TEXTURE2D_DESC desc;
143         memset(&desc, 0, sizeof(desc) );
144         desc.Width      = 256;
145         desc.Height     = 256;
146         desc.MipLevels  = 4;
147         desc.ArraySize  = 4;
148         desc.Format     = DXGI_FORMAT_R32G32B32A32_FLOAT;
149         desc.SampleDesc.Count = 1;
150         desc.SampleDesc.Quality = 0;
151         desc.Usage = D3D11_USAGE_DEFAULT;
152         desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
153         desc.CPUAccessFlags = 0;
154         desc.MiscFlags = 0;
155 
156         hr = pDevice->CreateTexture2D(&desc, NULL, &pTexture);
157         TestRequire(SUCCEEDED(hr), "Failed to create texture.");
158     }
159 
160     // create the D3D11 buffer
161     {
162         D3D11_BUFFER_DESC desc = {0};
163         desc.ByteWidth = 1124;
164         desc.Usage = D3D11_USAGE_DEFAULT;
165         desc.CPUAccessFlags = 0;
166         desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
167         desc.MiscFlags = 0;
168         hr = pDevice->CreateBuffer(&desc, NULL, &pBuffer);
169         TestRequire(SUCCEEDED(hr), "Creating vertex buffer failed!");
170     }
171 
172     // create cl_mem objects for the resources
173     mem[0] = clCreateFromD3D11BufferKHR(
174         context,
175         0,
176         pBuffer,
177         &result);
178     TestRequire(result == CL_SUCCESS, "clCreateFromD3D11BufferKHR");
179     mem[1] = clCreateFromD3D11Texture2DKHR(
180         context,
181         0,
182         pTexture,
183         1,
184         &result);
185     TestRequire(result == CL_SUCCESS, "clCreateFromD3D11Texture2DKHR failed");
186 
187 Cleanup:
188     for (UINT i = 0; i < 2; ++i)
189     {
190         if (mem[i])
191         {
192             clReleaseMemObject(mem[i]);
193         }
194     }
195     if (pBuffer)
196     {
197         pBuffer->Release();
198     }
199     if (pTexture)
200     {
201         pTexture->Release();
202     }
203 
204     HarnessD3D11_TestEnd();
205 }
206 
TestDeviceMisc(cl_device_id device,cl_context context,cl_command_queue command_queue,ID3D11Device * pDevice)207 void TestDeviceMisc(
208     cl_device_id device,
209     cl_context context,
210     cl_command_queue command_queue,
211     ID3D11Device* pDevice)
212 {
213     SubTestMiscMultipleCreates(
214         context,
215         command_queue,
216         pDevice);
217 
218     SubTestMiscAcquireRelease(
219         device,
220         context,
221         pDevice);
222 }
223 
224 
225