forked from KhronosGroup/ANARI-SDK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDebugDevice.h
260 lines (198 loc) · 7.46 KB
/
DebugDevice.h
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
// Copyright 2021-2024 The Khronos Group
// SPDX-License-Identifier: Apache-2.0
#pragma once
// helium
#include "helium/utility/IntrusivePtr.h"
// anari
#include "anari/backend/DeviceImpl.h"
#include "anari/anari_cpp.hpp"
// std
#include <cstring>
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>
#include "DebugInterface.h"
#include "DebugSerializerInterface.h"
#include "anari/ext/debug/DebugObject.h"
#include <cstdarg>
#include "ExtendedQueries.h"
namespace anari {
namespace debug_device {
struct DEBUG_DEVICE_INTERFACE DebugDevice : public DeviceImpl, public helium::RefCounted
{
void reportStatus(ANARIObject source,
ANARIDataType sourceType,
ANARIStatusSeverity severity,
ANARIStatusCode code,
const char *format,
...);
void vreportStatus(ANARIObject source,
ANARIDataType sourceType,
ANARIStatusSeverity severity,
ANARIStatusCode code,
const char *format,
va_list);
/////////////////////////////////////////////////////////////////////////////
// Main interface to accepting API calls
/////////////////////////////////////////////////////////////////////////////
// Data Arrays //////////////////////////////////////////////////////////////
ANARIArray1D newArray1D(const void *appMemory,
ANARIMemoryDeleter deleter,
const void *userdata,
ANARIDataType,
uint64_t numItems1) override;
ANARIArray2D newArray2D(const void *appMemory,
ANARIMemoryDeleter deleter,
const void *userdata,
ANARIDataType,
uint64_t numItems1,
uint64_t numItems2) override;
ANARIArray3D newArray3D(const void *appMemory,
ANARIMemoryDeleter deleter,
const void *userdata,
ANARIDataType,
uint64_t numItems1,
uint64_t numItems2,
uint64_t numItems3) override;
void *mapArray(ANARIArray) override;
void unmapArray(ANARIArray) override;
// Renderable Objects ///////////////////////////////////////////////////////
ANARILight newLight(const char *type) override;
ANARICamera newCamera(const char *type) override;
ANARIGeometry newGeometry(const char *type) override;
ANARISpatialField newSpatialField(const char *type) override;
ANARISurface newSurface() override;
ANARIVolume newVolume(const char *type) override;
// Surface Meta-Data ////////////////////////////////////////////////////////
ANARIMaterial newMaterial(const char *material_type) override;
ANARISampler newSampler(const char *type) override;
// Instancing ///////////////////////////////////////////////////////////////
ANARIGroup newGroup() override;
ANARIInstance newInstance(const char *type) override;
// Top-level Worlds /////////////////////////////////////////////////////////
ANARIWorld newWorld() override;
// Query functions //////////////////////////////////////////////////////////
const char ** getObjectSubtypes(ANARIDataType objectType) override;
const void* getObjectInfo(ANARIDataType objectType,
const char* objectSubtype,
const char* infoName,
ANARIDataType infoType) override;
const void* getParameterInfo(ANARIDataType objectType,
const char* objectSubtype,
const char* parameterName,
ANARIDataType parameterType,
const char* infoName,
ANARIDataType infoType) override;
// Object + Parameter Lifetime Management ///////////////////////////////////
int getProperty(ANARIObject object,
const char *name,
ANARIDataType type,
void *mem,
uint64_t size,
ANARIWaitMask mask) override;
void setParameter(ANARIObject object,
const char *name,
ANARIDataType type,
const void *mem) override;
void unsetParameter(ANARIObject object, const char *name) override;
void unsetAllParameters(ANARIObject object) override;
void* mapParameterArray1D(ANARIObject object,
const char* name,
ANARIDataType dataType,
uint64_t numElements1,
uint64_t* elementStride) override;
void* mapParameterArray2D(ANARIObject object,
const char* name,
ANARIDataType dataType,
uint64_t numElements1,
uint64_t numElements2,
uint64_t* elementStride) override;
void* mapParameterArray3D(ANARIObject object,
const char* name,
ANARIDataType dataType,
uint64_t numElements1,
uint64_t numElements2,
uint64_t numElements3,
uint64_t* elementStride) override;
void unmapParameterArray(ANARIObject object,
const char* name) override;
void commitParameters(ANARIObject object) override;
void release(ANARIObject _obj) override;
void retain(ANARIObject _obj) override;
// FrameBuffer Manipulation /////////////////////////////////////////////////
ANARIFrame newFrame() override;
const void *frameBufferMap(ANARIFrame fb,
const char *channel,
uint32_t *width,
uint32_t *height,
ANARIDataType *pixelType) override;
void frameBufferUnmap(ANARIFrame fb, const char *channel) override;
// Frame Rendering //////////////////////////////////////////////////////////
ANARIRenderer newRenderer(const char *type) override;
void renderFrame(ANARIFrame) override;
int frameReady(ANARIFrame, ANARIWaitMask) override;
void discardFrame(ANARIFrame) override;
/////////////////////////////////////////////////////////////////////////////
// Helper/other functions and data members
/////////////////////////////////////////////////////////////////////////////
void deviceSetParameter(const char *id, ANARIDataType type, const void *mem);
void deviceUnsetParameter(const char *id);
void deviceCommit();
DebugDevice(ANARILibrary);
~DebugDevice();
ANARIObject newObjectHandle(ANARIObject, ANARIDataType);
ANARIObject newObjectHandle(ANARIObject, ANARIDataType, const char *);
ANARIObject wrapObjectHandle(ANARIObject, ANARIDataType = ANARI_OBJECT);
ANARIObject unwrapObjectHandle(ANARIObject, ANARIDataType = ANARI_OBJECT);
DebugObjectBase *getObjectInfo(ANARIObject);
template <typename T>
T newHandle(T o)
{
return static_cast<T>(newObjectHandle(o, ANARITypeFor<T>::value));
}
template <typename T>
T newHandle(T o, const char *name)
{
return static_cast<T>(newObjectHandle(o, ANARITypeFor<T>::value, name));
}
template <typename T>
T wrapHandle(T o)
{
return static_cast<T>(wrapObjectHandle(o, ANARITypeFor<T>::value));
}
template <typename T>
T unwrapHandle(T o)
{
return static_cast<T>(unwrapObjectHandle(o, ANARITypeFor<T>::value));
}
template <typename T>
T *getDynamicObjectInfo(ANARIObject o)
{
return dynamic_cast<T *>(getObjectInfo(o));
}
int used_features[anari::debug_queries::extension_count] = {};
int unknown_feature_uses = 0;
void reportParameterUse(ANARIDataType objtype,
const char *objSubtype,
const char *paramname,
ANARIDataType paramtype);
void reportObjectUse(ANARIDataType objtype, const char *objSubtype);
std::vector<std::unique_ptr<DebugObjectBase>> objects;
ANARIDevice getWrapped() const { return wrapped; }
private:
std::string wrappedLibraryFromEnv;
ANARIDevice wrapped{nullptr};
ANARIDevice staged{nullptr};
DebugObject<ANARI_DEVICE> deviceInfo;
std::unordered_map<ANARIObject, ANARIObject> objectMap;
std::vector<char> last_status_message;
std::unique_ptr<DebugInterface> debug;
ObjectFactory *debugObjectFactory{nullptr};
std::unique_ptr<SerializerInterface> serializer;
SerializerInterface *(*createSerializer)(DebugDevice *) = nullptr;
public:
std::string traceDir;
};
} // namespace debug_device
} // namespace anari