• 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 #ifndef _HARNESS_H_
17 #define _HARNESS_H_
18 
19 #define _CRT_SECURE_NO_WARNINGS
20 
21 #if defined (__MINGW32__)
22 #include <rpcsal.h>
23 typedef unsigned char UINT8;
24 #define __out
25 #define __in
26 #define __inout
27 #define __out_bcount(size)
28 #define __out_bcount_opt(size)
29 #define __in_opt
30 #define __in_ecount(size)
31 #define __in_ecount_opt(size)
32 #define __out_opt
33 #define __out_ecount(size)
34 #define __out_ecount_opt(size)
35 #define __in_bcount_opt(size)
36 #define __inout_opt
37 #endif
38 
39 #include <CL/cl.h>
40 #include <CL/cl_platform.h>
41 #include <CL/cl_d3d11.h>
42 #include <stdio.h>
43 #include "errorHelpers.h"
44 #include "kernelHelpers.h"
45 
46 // #define log_info(...) printf(__VA_ARGS__)
47 // #define log_error(...) printf(__VA_ARGS__)
48 
49 #define NonTestRequire(x, ...) \
50 do \
51 { \
52     if (!(x) ) \
53     { \
54         log_info("\n[assertion failed: %s at %s:%d]\n", #x, __FILE__, __LINE__); \
55         log_info("CATASTROPHIC NON-TEST ERROR: "); \
56         log_error(__VA_ARGS__); \
57         log_info("\n"); \
58         log_info("***FAILED***\n"); \
59         exit(1); \
60     } \
61 } while (0)
62 
63 #define TestRequire(x, ...) \
64     do \
65     { \
66         if (!(x) ) \
67         { \
68             log_info("\n[assertion failed: %s at %s:%d]\n", #x, __FILE__, __LINE__); \
69             log_info("ERROR: "); \
70             log_error(__VA_ARGS__); \
71             log_info("\n"); \
72             HarnessD3D11_TestFail(); \
73             goto Cleanup; \
74         } \
75     } while (0)
76 
77 #define TestPrint(...) \
78     do \
79     { \
80         log_error(__VA_ARGS__); \
81     } while (0)
82 
83 struct TextureFormat
84 {
85     DXGI_FORMAT format;
86     cl_channel_order channel_order;
87     cl_channel_type  channel_type;
88     UINT bytesPerPixel;
89     enum
90     {
91         GENERIC_FLOAT = 0,
92         GENERIC_UINT  = 1,
93         GENERIC_SINT  = 2,
94     } generic;
95 
96     const char *name_format;
97     const char *name_channel_order;
98     const char *name_channel_type;
99 };
100 extern TextureFormat formats[];
101 extern UINT formatCount;
102 
103 
104 #define MAX_REGISTERED_SUBRESOURCES 4 // limit to just make life easier
105 
106 struct BufferProperties
107 {
108     UINT ByteWidth;
109     UINT BindFlags;
110     D3D11_USAGE Usage;
111     UINT CPUAccess;
112     const char* name_BindFlags;
113     const char* name_Usage;
114     const char* name_CPUAccess;
115 };
116 
117 struct Texture2DSize
118 {
119     UINT Width;
120     UINT Height;
121     UINT MipLevels;
122     UINT ArraySize;
123     UINT SubResourceCount;
124     struct
125     {
126         UINT MipLevel;
127         UINT ArraySlice;
128     } subResources[MAX_REGISTERED_SUBRESOURCES];
129     UINT MiscFlags;
130 };
131 struct Texture3DSize
132 {
133     UINT Width;
134     UINT Height;
135     UINT Depth;
136     UINT MipLevels;
137     UINT SubResourceCount;
138     struct
139     {
140         UINT MipLevel;
141     } subResources[MAX_REGISTERED_SUBRESOURCES];
142     UINT MiscFlags;
143 };
144 
145 void HarnessD3D11_Initialize(cl_platform_id platform);
146 cl_int HarnessD3D11_CreateDevice(
147     IDXGIAdapter* pAdapter,
148     ID3D11Device **ppDevice,
149     ID3D11DeviceContext** ppDC);
150 void HarnessD3D11_DestroyDevice();
151 
152 void HarnessD3D11_TestBegin(const char* fmt, ...);
153 void HarnessD3D11_TestFail();
154 void HarnessD3D11_TestEnd();
155 void HarnessD3D11_TestStats();
156 
157 void TestAdapterEnumeration(
158     cl_platform_id platform,
159     IDXGIAdapter* pAdapter,
160     ID3D11Device* pDevice,
161     cl_uint* num_devices);
162 
163 void TestAdapterDevices(
164     cl_platform_id platform,
165     IDXGIAdapter* pAdapter,
166     ID3D11Device* pDevice,
167     ID3D11DeviceContext* pDC,
168     cl_uint num_devices);
169 
170 void TestDevice(
171     cl_device_id device,
172     ID3D11Device* pDevice,
173     ID3D11DeviceContext* pDC);
174 
175 bool TestDeviceContextCreate(
176     cl_device_id device,
177     ID3D11Device* pDevice,
178     cl_context* out_context,
179     cl_command_queue* out_command_queue);
180 
181 void TestDeviceBuffer(
182     cl_context context,
183     cl_command_queue command_queue,
184     ID3D11Device* pDevice,
185     ID3D11DeviceContext* pDC);
186 
187 void TestDeviceTexture2D(
188     cl_device_id device,
189     cl_context context,
190     cl_command_queue command_queue,
191     ID3D11Device* pDevice,
192     ID3D11DeviceContext* pDC);
193 
194 void TestDeviceTexture3D(
195     cl_device_id device,
196     cl_context context,
197     cl_command_queue command_queue,
198     ID3D11Device* pDevice,
199     ID3D11DeviceContext* pDC);
200 
201 void TestDeviceMisc(
202     cl_device_id device,
203     cl_context context,
204     cl_command_queue command_queue,
205     ID3D11Device* pDevice);
206 
207 cl_int HarnessD3D11_CreateKernelFromSource(
208     cl_kernel *outKernel,
209     cl_device_id device,
210     cl_context context,
211     const char *source,
212     const char *entrypoint);
213 
214 extern clGetDeviceIDsFromD3D11KHR_fn      clGetDeviceIDsFromD3D11KHR;
215 extern clCreateFromD3D11BufferKHR_fn      clCreateFromD3D11BufferKHR;
216 extern clCreateFromD3D11Texture2DKHR_fn   clCreateFromD3D11Texture2DKHR;
217 extern clCreateFromD3D11Texture3DKHR_fn   clCreateFromD3D11Texture3DKHR;
218 extern clEnqueueAcquireD3D11ObjectsKHR_fn clEnqueueAcquireD3D11ObjectsKHR;
219 extern clEnqueueReleaseD3D11ObjectsKHR_fn clEnqueueReleaseD3D11ObjectsKHR;
220 
221 #endif
222