-
Notifications
You must be signed in to change notification settings - Fork 35
/
BaseDevice.h
131 lines (101 loc) · 3.98 KB
/
BaseDevice.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
// Copyright 2022-2024 The Khronos Group
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include "BaseGlobalDeviceState.h"
#include "LockableObject.h"
#include "utility/IntrusivePtr.h"
#include "utility/ParameterizedObject.h"
// anari
#include "anari/backend/DeviceImpl.h"
namespace helium {
struct BaseDevice : public anari::DeviceImpl,
ParameterizedObject,
LockableObject
{
// Data Arrays //////////////////////////////////////////////////////////////
void *mapArray(ANARIArray) override;
void unmapArray(ANARIArray) override;
// Object + Parameter Lifetime Management ///////////////////////////////////
int getProperty(ANARIObject o,
const char *name,
ANARIDataType type,
void *mem,
uint64_t size,
uint32_t mask) override;
void setParameter(ANARIObject o,
const char *name,
ANARIDataType type,
const void *mem) override;
void unsetParameter(ANARIObject o, const char *name) override;
void unsetAllParameters(ANARIObject o) override;
void *mapParameterArray1D(ANARIObject o,
const char *name,
ANARIDataType dataType,
uint64_t numElements1,
uint64_t *elementStride) override;
void *mapParameterArray2D(ANARIObject o,
const char *name,
ANARIDataType dataType,
uint64_t numElements1,
uint64_t numElements2,
uint64_t *elementStride) override;
void *mapParameterArray3D(ANARIObject o,
const char *name,
ANARIDataType dataType,
uint64_t numElements1,
uint64_t numElements2,
uint64_t numElements3,
uint64_t *elementStride) override;
void unmapParameterArray(ANARIObject o, const char *name) override;
void commitParameters(ANARIObject o) override;
void release(ANARIObject o) override;
void retain(ANARIObject o) override;
// FrameBuffer Manipulation /////////////////////////////////////////////////
const void *frameBufferMap(ANARIFrame f,
const char *channel,
uint32_t *width,
uint32_t *height,
ANARIDataType *pixelType) override;
void frameBufferUnmap(ANARIFrame f, const char *channel) override;
// Frame Rendering //////////////////////////////////////////////////////////
void renderFrame(ANARIFrame f) override;
int frameReady(ANARIFrame f, ANARIWaitMask m) override;
void discardFrame(ANARIFrame f) override;
/////////////////////////////////////////////////////////////////////////////
// Helper/other functions and data members
/////////////////////////////////////////////////////////////////////////////
BaseDevice(ANARIStatusCallback defaultCallback, const void *userPtr);
BaseDevice(ANARILibrary l);
virtual ~BaseDevice() override;
protected:
template <typename... Args>
void reportMessage(
ANARIStatusSeverity, const char *fmt, Args &&...args) const;
virtual void deviceCommitParameters();
virtual int deviceGetProperty(
const char *name, ANARIDataType type, void *mem, uint64_t size);
std::unique_ptr<BaseGlobalDeviceState> m_state;
private:
std::scoped_lock<std::mutex> getObjectLock(ANARIObject object);
void deviceGetProperty(const char *id, ANARIDataType type, const void *mem);
void deviceSetParameter(const char *id, ANARIDataType type, const void *mem);
void deviceUnsetParameter(const char *id);
void deviceUnsetAllParameters();
uint32_t m_refCount{1};
};
std::string string_printf(const char *fmt, ...);
// Inlined definitions ////////////////////////////////////////////////////////
template <typename... Args>
inline void BaseDevice::reportMessage(
ANARIStatusSeverity severity, const char *fmt, Args &&...args) const
{
auto msg = string_printf(fmt, std::forward<Args>(args)...);
m_state->messageFunction(severity, msg, ANARI_DEVICE, this);
}
// Helper functions ///////////////////////////////////////////////////////////
template <typename OBJECT_T = BaseObject, typename HANDLE_T = ANARIObject>
inline OBJECT_T &referenceFromHandle(HANDLE_T handle)
{
return *((OBJECT_T *)handle);
}
} // namespace helium