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