aboutsummaryrefslogtreecommitdiff
path: root/test_conformance/d3d10/harness.h
blob: 184e52cb5b2e9adbbe2074e913293f2111873f3f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
//
// 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"
#include "kernelHelpers.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