-
Notifications
You must be signed in to change notification settings - Fork 3
/
VisionarayDevice.cpp
347 lines (282 loc) · 9.05 KB
/
VisionarayDevice.cpp
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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
// Copyright 2022 The Khronos Group
// SPDX-License-Identifier: Apache-2.0
#include "VisionarayDevice.h"
#include "array/Array1D.h"
#include "array/Array2D.h"
#include "array/Array3D.h"
#include "array/ObjectArray.h"
#include "frame/Frame.h"
#include "scene/light/Light.h"
#include "scene/surface/geometry/Geometry.h"
#include "scene/surface/material/sampler/Sampler.h"
#include "scene/surface/Surface.h"
#include "scene/volume/spatial_field/SpatialField.h"
#include "scene/volume/Volume.h"
#include "scene/Group.h"
#include "scene/Instance.h"
namespace visionaray {
///////////////////////////////////////////////////////////////////////////////
// Generated function declarations ////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
const char **query_object_types(ANARIDataType type);
const void *query_object_info(ANARIDataType type,
const char *subtype,
const char *infoName,
ANARIDataType infoType);
const void *query_param_info(ANARIDataType type,
const char *subtype,
const char *paramName,
ANARIDataType paramType,
const char *infoName,
ANARIDataType infoType);
const char **query_extensions();
///////////////////////////////////////////////////////////////////////////////
// VisionarayDevice definitions ///////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Data Arrays ////////////////////////////////////////////////////////////////
void *VisionarayDevice::mapArray(ANARIArray a)
{
#ifdef WITH_CUDA
// TODO: set device
#elif defined(WITH_HIP)
// TODO: set device
#else
deviceState()->renderingSemaphore.arrayMapAcquire();
#endif
return helium::BaseDevice::mapArray(a);
}
void VisionarayDevice::unmapArray(ANARIArray a)
{
helium::BaseDevice::unmapArray(a);
#ifdef WITH_CUDA
// TODO: set device
#elif defined(WITH_HIP)
// TODO: set device
#else
deviceState()->renderingSemaphore.arrayMapRelease();
#endif
}
// API Objects ////////////////////////////////////////////////////////////////
ANARIArray1D VisionarayDevice::newArray1D(const void *appMemory,
ANARIMemoryDeleter deleter,
const void *userData,
ANARIDataType type,
uint64_t numItems)
{
initDevice();
Array1DMemoryDescriptor md;
md.appMemory = appMemory;
md.deleter = deleter;
md.deleterPtr = userData;
md.elementType = type;
md.numItems = numItems;
if (anari::isObject(type))
return (ANARIArray1D) new ObjectArray(deviceState(), md);
else
return (ANARIArray1D) new Array1D(deviceState(), md);
}
ANARIArray2D VisionarayDevice::newArray2D(const void *appMemory,
ANARIMemoryDeleter deleter,
const void *userData,
ANARIDataType type,
uint64_t numItems1,
uint64_t numItems2)
{
initDevice();
Array2DMemoryDescriptor md;
md.appMemory = appMemory;
md.deleter = deleter;
md.deleterPtr = userData;
md.elementType = type;
md.numItems1 = numItems1;
md.numItems2 = numItems2;
return (ANARIArray2D) new Array2D(deviceState(), md);
}
ANARIArray3D VisionarayDevice::newArray3D(const void *appMemory,
ANARIMemoryDeleter deleter,
const void *userData,
ANARIDataType type,
uint64_t numItems1,
uint64_t numItems2,
uint64_t numItems3)
{
initDevice();
Array3DMemoryDescriptor md;
md.appMemory = appMemory;
md.deleter = deleter;
md.deleterPtr = userData;
md.elementType = type;
md.numItems1 = numItems1;
md.numItems2 = numItems2;
md.numItems3 = numItems3;
return (ANARIArray3D) new Array3D(deviceState(), md);
}
// Renderable Objects /////////////////////////////////////////////////////////
ANARILight VisionarayDevice::newLight(const char *subtype)
{
initDevice();
return (ANARILight)Light::createInstance(subtype, deviceState());
}
ANARICamera VisionarayDevice::newCamera(const char *subtype)
{
initDevice();
return (ANARICamera)Camera::createInstance(subtype, deviceState());
}
ANARIGeometry VisionarayDevice::newGeometry(const char *subtype)
{
initDevice();
return (ANARIGeometry)Geometry::createInstance(subtype, deviceState());
}
ANARISpatialField VisionarayDevice::newSpatialField(const char *subtype)
{
initDevice();
return (ANARISpatialField)SpatialField::createInstance(subtype, deviceState());
}
ANARISurface VisionarayDevice::newSurface()
{
initDevice();
return (ANARISurface) new Surface(deviceState());
}
ANARIVolume VisionarayDevice::newVolume(const char *subtype)
{
initDevice();
return (ANARIVolume)Volume::createInstance(subtype, deviceState());
}
// Surface Meta-Data //////////////////////////////////////////////////////////
ANARIMaterial VisionarayDevice::newMaterial(const char *subtype)
{
initDevice();
return (ANARIMaterial)Material::createInstance(subtype, deviceState());
}
ANARISampler VisionarayDevice::newSampler(const char *subtype)
{
initDevice();
return (ANARISampler)Sampler::createInstance(subtype, deviceState());
}
// Instancing /////////////////////////////////////////////////////////////////
ANARIGroup VisionarayDevice::newGroup()
{
initDevice();
return (ANARIGroup) new Group(deviceState());
}
ANARIInstance VisionarayDevice::newInstance(const char *subtype)
{
initDevice();
return (ANARIInstance)Instance::createInstance(subtype, deviceState());
}
// Top-level Worlds ///////////////////////////////////////////////////////////
ANARIWorld VisionarayDevice::newWorld()
{
initDevice();
return (ANARIWorld) new World(deviceState());
}
// Query functions ////////////////////////////////////////////////////////////
const char **VisionarayDevice::getObjectSubtypes(ANARIDataType objectType)
{
return visionaray::query_object_types(objectType);
}
const void *VisionarayDevice::getObjectInfo(ANARIDataType objectType,
const char *objectSubtype,
const char *infoName,
ANARIDataType infoType)
{
return visionaray::query_object_info(
objectType, objectSubtype, infoName, infoType);
}
const void *VisionarayDevice::getParameterInfo(ANARIDataType objectType,
const char *objectSubtype,
const char *parameterName,
ANARIDataType parameterType,
const char *infoName,
ANARIDataType infoType)
{
return visionaray::query_param_info(objectType,
objectSubtype,
parameterName,
parameterType,
infoName,
infoType);
}
// Object + Parameter Lifetime Management /////////////////////////////////////
int VisionarayDevice::getProperty(ANARIObject object,
const char *name,
ANARIDataType type,
void *mem,
uint64_t size,
uint32_t mask)
{
if (mask == ANARI_WAIT) {
auto lock = scopeLockObject();
deviceState()->waitOnCurrentFrame();
}
return helium::BaseDevice::getProperty(object, name, type, mem, size, mask);
}
// Frame Manipulation /////////////////////////////////////////////////////////
ANARIFrame VisionarayDevice::newFrame()
{
initDevice();
return (ANARIFrame) new Frame(deviceState());
}
// Frame Rendering ////////////////////////////////////////////////////////////
ANARIRenderer VisionarayDevice::newRenderer(const char *subtype)
{
initDevice();
return (ANARIRenderer)Renderer::createInstance(subtype, deviceState());
}
// Other VisionarayDevice definitions /////////////////////////////////////////
VisionarayDevice::VisionarayDevice(ANARIStatusCallback cb, const void *ptr)
: helium::BaseDevice(cb, ptr)
{
m_state = std::make_unique<VisionarayGlobalState>(this_device());
deviceCommitParameters();
}
VisionarayDevice::VisionarayDevice(ANARILibrary l) : helium::BaseDevice(l)
{
m_state = std::make_unique<VisionarayGlobalState>(this_device());
deviceCommitParameters();
}
VisionarayDevice::~VisionarayDevice()
{
auto &state = *deviceState();
state.commitBufferClear();
reportMessage(ANARI_SEVERITY_DEBUG, "destroying visionaray device (%p)", this);
// TODO: clear context?!
}
void VisionarayDevice::initDevice()
{
if (m_initialized)
return;
reportMessage(ANARI_SEVERITY_DEBUG, "initializing visionaray device (%p)", this);
auto &state = *deviceState();
m_initialized = true;
}
void VisionarayDevice::deviceCommitParameters()
{
auto &state = *deviceState();
// bool allowInvalidSurfaceMaterials = state.allowInvalidSurfaceMaterials;
// state.allowInvalidSurfaceMaterials =
// getParam<bool>("allowInvalidMaterials", true);
// state.invalidMaterialColor =
// getParam<float4>("invalidMaterialColor", float4(1.f, 0.f, 1.f, 1.f));
// if (allowInvalidSurfaceMaterials != state.allowInvalidSurfaceMaterials)
// state.objectUpdates.lastBLSReconstructSceneRequest = helium::newTimeStamp();
helium::BaseDevice::deviceCommitParameters();
}
int VisionarayDevice::deviceGetProperty(
const char *name, ANARIDataType type, void *mem, uint64_t size)
{
std::string_view prop = name;
if (prop == "extension" && type == ANARI_STRING_LIST) {
helium::writeToVoidP(mem, query_extensions());
return 1;
} else if (prop == "visionaray" && type == ANARI_BOOL) {
helium::writeToVoidP(mem, true);
return 1;
}
return 0;
}
VisionarayGlobalState *VisionarayDevice::deviceState() const
{
return (VisionarayGlobalState *)helium::BaseDevice::m_state.get();
}
} // namespace visionaray