HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
oidn.h
Go to the documentation of this file.
1 // ======================================================================== //
2 // Copyright 2009-2019 Intel Corporation //
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 
17 #pragma once
18 
19 #include <stddef.h>
20 #include <stdbool.h>
21 #include <stdint.h>
22 
23 #include "version.h"
24 
25 #if defined(__cplusplus)
26 extern "C" {
27 #endif
28 
29 #ifndef OIDN_API
30 #if defined(_WIN32) && !defined(OIDN_STATIC_LIB)
31 # define OIDN_API __declspec(dllimport)
32 #else
33 # define OIDN_API
34 #endif
35 #endif
36 
37 // ----------------------------------------------------------------------------
38 // Device
39 // ----------------------------------------------------------------------------
40 
41 // Device types
42 typedef enum
43 {
44  OIDN_DEVICE_TYPE_DEFAULT = 0, // select device automatically
45 
46  OIDN_DEVICE_TYPE_CPU = 1, // CPU device
48 
49 // Error codes
50 typedef enum
51 {
52  OIDN_ERROR_NONE = 0, // no error occurred
53  OIDN_ERROR_UNKNOWN = 1, // an unknown error occurred
54  OIDN_ERROR_INVALID_ARGUMENT = 2, // an invalid argument was specified
55  OIDN_ERROR_INVALID_OPERATION = 3, // the operation is not allowed
56  OIDN_ERROR_OUT_OF_MEMORY = 4, // not enough memory to execute the operation
57  OIDN_ERROR_UNSUPPORTED_HARDWARE = 5, // the hardware (e.g. CPU) is not supported
58  OIDN_ERROR_CANCELLED = 6, // the operation was cancelled by the user
59 } OIDNError;
60 
61 // Error callback function
62 typedef void (*OIDNErrorFunction)(void* userPtr, OIDNError code, const char* message);
63 
64 // Device handle
65 typedef struct OIDNDeviceImpl* OIDNDevice;
66 
67 // Creates a new device.
69 
70 // Retains the device (increments the reference count).
71 OIDN_API void oidnRetainDevice(OIDNDevice device);
72 
73 // Releases the device (decrements the reference count).
74 OIDN_API void oidnReleaseDevice(OIDNDevice device);
75 
76 // Sets a boolean parameter of the device.
77 OIDN_API void oidnSetDevice1b(OIDNDevice device, const char* name, bool value);
78 
79 // Sets an integer parameter of the device.
80 OIDN_API void oidnSetDevice1i(OIDNDevice device, const char* name, int value);
81 
82 // Gets a boolean parameter of the device.
83 OIDN_API bool oidnGetDevice1b(OIDNDevice device, const char* name);
84 
85 // Gets an integer parameter of the device (e.g. "version").
86 OIDN_API int oidnGetDevice1i(OIDNDevice device, const char* name);
87 
88 // Sets the error callback function of the device.
89 OIDN_API void oidnSetDeviceErrorFunction(OIDNDevice device, OIDNErrorFunction func, void* userPtr);
90 
91 // Returns the first unqueried error code stored in the device for the current
92 // thread, optionally also returning a string message (if not NULL), and clears
93 // the stored error. Can be called with a NULL device as well to check why a
94 // device creation failed.
95 OIDN_API OIDNError oidnGetDeviceError(OIDNDevice device, const char** outMessage);
96 
97 // Commits all previous changes to the device.
98 // Must be called before first using the device (e.g. creating filters).
99 OIDN_API void oidnCommitDevice(OIDNDevice device);
100 
101 // ----------------------------------------------------------------------------
102 // Buffer
103 // ----------------------------------------------------------------------------
104 
105 // Formats for images and other data stored in buffers
106 typedef enum
107 {
109 
110  // 32-bit single-precision floating point scalar and vector formats
115 } OIDNFormat;
116 
117 // Access modes for mapping buffers
118 typedef enum
119 {
120  OIDN_ACCESS_READ = 0, // read-only access
121  OIDN_ACCESS_WRITE = 1, // write-only access
122  OIDN_ACCESS_READ_WRITE = 2, // read and write access
123  OIDN_ACCESS_WRITE_DISCARD = 3, // write-only access, previous contents discarded
124 } OIDNAccess;
125 
126 // Buffer handle
127 typedef struct OIDNBufferImpl* OIDNBuffer;
128 
129 // Creates a new buffer (data allocated and owned by the device).
130 OIDN_API OIDNBuffer oidnNewBuffer(OIDNDevice device, size_t byteSize);
131 
132 // Creates a new shared buffer (data allocated and owned by the user).
133 OIDN_API OIDNBuffer oidnNewSharedBuffer(OIDNDevice device, void* ptr, size_t byteSize);
134 
135 // Maps a region of the buffer to host memory.
136 // If byteSize is 0, the maximum available amount of memory will be mapped.
137 OIDN_API void* oidnMapBuffer(OIDNBuffer buffer, OIDNAccess access, size_t byteOffset, size_t byteSize);
138 
139 // Unmaps a region of the buffer.
140 // mappedPtr must be a pointer returned by a previous call to oidnMapBuffer.
141 OIDN_API void oidnUnmapBuffer(OIDNBuffer buffer, void* mappedPtr);
142 
143 // Retains the buffer (increments the reference count).
144 OIDN_API void oidnRetainBuffer(OIDNBuffer buffer);
145 
146 // Releases the buffer (decrements the reference count).
147 OIDN_API void oidnReleaseBuffer(OIDNBuffer buffer);
148 
149 // ----------------------------------------------------------------------------
150 // Filter
151 // ----------------------------------------------------------------------------
152 
153 // Progress monitor callback function
154 typedef bool (*OIDNProgressMonitorFunction)(void* userPtr, double n);
155 
156 // Filter handle
157 typedef struct OIDNFilterImpl* OIDNFilter;
158 
159 // Creates a new filter of the specified type (e.g. "RT").
160 OIDN_API OIDNFilter oidnNewFilter(OIDNDevice device, const char* type);
161 
162 // Retains the filter (increments the reference count).
163 OIDN_API void oidnRetainFilter(OIDNFilter filter);
164 
165 // Releases the filter (decrements the reference count).
166 OIDN_API void oidnReleaseFilter(OIDNFilter filter);
167 
168 // Sets an image parameter of the filter (stored in a buffer).
169 // If bytePixelStride and/or byteRowStride are zero, these will be computed automatically.
170 OIDN_API void oidnSetFilterImage(OIDNFilter filter, const char* name,
171  OIDNBuffer buffer, OIDNFormat format,
172  size_t width, size_t height,
173  size_t byteOffset,
174  size_t bytePixelStride, size_t byteRowStride);
175 
176 // Sets an image parameter of the filter (owned by the user).
177 // If bytePixelStride and/or byteRowStride are zero, these will be computed automatically.
178 OIDN_API void oidnSetSharedFilterImage(OIDNFilter filter, const char* name,
179  void* ptr, OIDNFormat format,
180  size_t width, size_t height,
181  size_t byteOffset,
182  size_t bytePixelStride, size_t byteRowStride);
183 
184 // Sets a boolean parameter of the filter.
185 OIDN_API void oidnSetFilter1b(OIDNFilter filter, const char* name, bool value);
186 
187 // Gets a boolean parameter of the filter.
188 OIDN_API bool oidnGetFilter1b(OIDNFilter filter, const char* name);
189 
190 // Sets an integer parameter of the filter.
191 OIDN_API void oidnSetFilter1i(OIDNFilter filter, const char* name, int value);
192 
193 // Gets an integer parameter of the filter.
194 OIDN_API int oidnGetFilter1i(OIDNFilter filter, const char* name);
195 
196 // Sets a float parameter of the filter.
197 OIDN_API void oidnSetFilter1f(OIDNFilter filter, const char* name, float value);
198 
199 // Gets a float parameter of the filter.
200 OIDN_API float oidnGetFilter1f(OIDNFilter filter, const char* name);
201 
202 // Sets the progress monitor callback function of the filter.
204 
205 // Commits all previous changes to the filter.
206 // Must be called before first executing the filter.
207 OIDN_API void oidnCommitFilter(OIDNFilter filter);
208 
209 // Executes the filter.
210 OIDN_API void oidnExecuteFilter(OIDNFilter filter);
211 
212 #if defined(__cplusplus)
213 }
214 #endif
OIDN_API int oidnGetDevice1i(OIDNDevice device, const char *name)
OIDN_API bool oidnGetDevice1b(OIDNDevice device, const char *name)
GLuint const GLchar * name
Definition: glew.h:1814
OIDN_API void oidnUnmapBuffer(OIDNBuffer buffer, void *mappedPtr)
OIDN_API void oidnExecuteFilter(OIDNFilter filter)
OIDN_API int oidnGetFilter1i(OIDNFilter filter, const char *name)
OIDN_API void oidnReleaseDevice(OIDNDevice device)
OIDN_API void oidnReleaseFilter(OIDNFilter filter)
GLint GLint GLint GLint GLint GLint GLsizei width
Definition: glew.h:1252
OIDNFormat
Definition: oidn.h:106
GLint GLint GLint GLint GLint GLint GLsizei GLsizei height
Definition: glew.h:1252
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: glew.h:1254
struct OIDNFilterImpl * OIDNFilter
Definition: oidn.h:157
OIDN_API void oidnSetDevice1b(OIDNDevice device, const char *name, bool value)
OIDN_API void oidnRetainFilter(OIDNFilter filter)
OIDN_API void oidnRetainBuffer(OIDNBuffer buffer)
OIDNDeviceType
Definition: oidn.h:42
struct OIDNBufferImpl * OIDNBuffer
Definition: oidn.h:127
OIDN_API void oidnSetFilter1f(OIDNFilter filter, const char *name, float value)
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glew.h:2981
void(* OIDNErrorFunction)(void *userPtr, OIDNError code, const char *message)
Definition: oidn.h:62
OIDN_API OIDNBuffer oidnNewSharedBuffer(OIDNDevice device, void *ptr, size_t byteSize)
OIDN_API void * oidnMapBuffer(OIDNBuffer buffer, OIDNAccess access, size_t byteOffset, size_t byteSize)
OIDN_API void oidnReleaseBuffer(OIDNBuffer buffer)
GLuint buffer
Definition: glew.h:1680
OIDN_API void oidnRetainDevice(OIDNDevice device)
OIDN_API bool oidnGetFilter1b(OIDNFilter filter, const char *name)
OIDN_API void oidnCommitFilter(OIDNFilter filter)
OIDN_API void oidnSetFilterProgressMonitorFunction(OIDNFilter filter, OIDNProgressMonitorFunction func, void *userPtr)
OIDN_API void oidnSetFilter1b(OIDNFilter filter, const char *name, bool value)
GLsizei GLenum GLuint GLuint GLsizei GLchar * message
Definition: glew.h:2581
void
Definition: png.h:1083
GLsizei n
Definition: glew.h:4040
OIDN_API void oidnSetDevice1i(OIDNDevice device, const char *name, int value)
OIDN_API void oidnCommitDevice(OIDNDevice device)
OIDN_API OIDNBuffer oidnNewBuffer(OIDNDevice device, size_t byteSize)
OIDN_API OIDNDevice oidnNewDevice(OIDNDeviceType type)
OIDN_API void oidnSetDeviceErrorFunction(OIDNDevice device, OIDNErrorFunction func, void *userPtr)
OIDN_API float oidnGetFilter1f(OIDNFilter filter, const char *name)
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1253
GLenum func
Definition: glcorearb.h:782
bool(* OIDNProgressMonitorFunction)(void *userPtr, double n)
Definition: oidn.h:154
OIDNError
Definition: oidn.h:50
OIDN_API void oidnSetSharedFilterImage(OIDNFilter filter, const char *name, void *ptr, OIDNFormat format, size_t width, size_t height, size_t byteOffset, size_t bytePixelStride, size_t byteRowStride)
const void * ptr(const T *p)
Definition: format.h:3292
struct OIDNDeviceImpl * OIDNDevice
Definition: oidn.h:65
OIDN_API void oidnSetFilter1i(OIDNFilter filter, const char *name, int value)
OIDN_API void oidnSetFilterImage(OIDNFilter filter, const char *name, OIDNBuffer buffer, OIDNFormat format, size_t width, size_t height, size_t byteOffset, size_t bytePixelStride, size_t byteRowStride)
GLenum access
Definition: glew.h:3608
#define OIDN_API
Definition: oidn.h:33
OIDN_API OIDNFilter oidnNewFilter(OIDNDevice device, const char *type)
OIDNAccess
Definition: oidn.h:118
GLsizei const GLfloat * value
Definition: glew.h:1849
OIDN_API OIDNError oidnGetDeviceError(OIDNDevice device, const char **outMessage)