Path Tracing
Loading...
Searching...
No Matches
oidn.hpp
Go to the documentation of this file.
1// Copyright 2018 Intel Corporation
2// SPDX-License-Identifier: Apache-2.0
3
4#pragma once
5
6#include "oidn.h"
7#include <cstdint>
8#include <cassert>
9#include <cstring>
10#include <algorithm>
11#include <type_traits>
12#include <vector>
13#include <array>
14#include <string>
15
17
18 // -----------------------------------------------------------------------------------------------
19 // Flags helper type
20 // -----------------------------------------------------------------------------------------------
21
22 template<typename FlagT>
23 struct IsFlag
24 {
25 static constexpr bool value = false;
26 };
27
28 template<typename FlagT>
29 class Flags
30 {
31 public:
32 static_assert(IsFlag<FlagT>::value, "not a flag type");
33
34 constexpr Flags() noexcept : mask(0) {}
35 constexpr Flags(FlagT flag) noexcept : mask(static_cast<OIDNFlags>(flag)) {}
36 constexpr Flags(const Flags& b) noexcept = default;
37 constexpr explicit Flags(OIDNFlags mask) noexcept : mask(mask) {}
38
39 constexpr bool operator !() const noexcept { return !mask; }
40
41 constexpr Flags operator &(const Flags& b) const noexcept { return Flags(mask & b.mask); }
42 constexpr Flags operator |(const Flags& b) const noexcept { return Flags(mask | b.mask); }
43 constexpr Flags operator ^(const Flags& b) const noexcept { return Flags(mask ^ b.mask); }
44
45 Flags& operator =(const Flags& b) noexcept = default;
46
47 Flags& operator &=(const Flags& b) noexcept
48 {
49 mask &= b.mask;
50 return *this;
51 }
52
53 Flags& operator |=(const Flags& b) noexcept
54 {
55 mask |= b.mask;
56 return *this;
57 }
58
59 Flags& operator ^=(const Flags& b) noexcept
60 {
61 mask ^= b.mask;
62 return *this;
63 }
64
65 constexpr bool operator ==(const Flags& b) const noexcept { return mask == b.mask; }
66 constexpr bool operator !=(const Flags& b) const noexcept { return mask != b.mask; }
67
68 constexpr explicit operator bool() const noexcept { return mask; }
69 constexpr explicit operator OIDNFlags() const noexcept { return mask; }
70
71 private:
72 OIDNFlags mask;
73 };
74
75 template<typename FlagT>
76 inline constexpr Flags<FlagT> operator &(FlagT a, const Flags<FlagT>& b) noexcept
77 {
78 return Flags<FlagT>(a) & b;
79 }
80
81 template<typename FlagT>
82 inline constexpr Flags<FlagT> operator |(FlagT a, const Flags<FlagT>& b) noexcept
83 {
84 return Flags<FlagT>(a) | b;
85 }
86
87 template<typename FlagT>
88 inline constexpr Flags<FlagT> operator ^(FlagT a, const Flags<FlagT>& b) noexcept
89 {
90 return Flags<FlagT>(a) ^ b;
91 }
92
93 template<typename FlagT, typename std::enable_if<IsFlag<FlagT>::value, bool>::type = true>
94 inline constexpr Flags<FlagT> operator &(FlagT a, FlagT b) noexcept
95 {
96 return Flags<FlagT>(a) & b;
97 }
98
99 template<typename FlagT, typename std::enable_if<IsFlag<FlagT>::value, bool>::type = true>
100 inline constexpr Flags<FlagT> operator |(FlagT a, FlagT b) noexcept
101 {
102 return Flags<FlagT>(a) | b;
103 }
104
105 template<typename FlagT, typename std::enable_if<IsFlag<FlagT>::value, bool>::type = true>
106 inline constexpr Flags<FlagT> operator ^(FlagT a, FlagT b) noexcept
107 {
108 return Flags<FlagT>(a) ^ b;
109 }
110
111 // -----------------------------------------------------------------------------------------------
112 // Buffer
113 // -----------------------------------------------------------------------------------------------
114
115 // Formats for images and other data stored in buffers
116 enum class Format
117 {
119
120 // 32-bit single-precision floating-point scalar and vector formats
125
126 // 16-bit half-precision floating-point scalar and vector formats
131 };
132
133 // Storage modes for buffers
134 enum class Storage
135 {
137
138 // stored on the host, accessible by both host and device
140
141 // stored on the device, *not* accessible by the host
143
144 // automatically migrated between host and device, accessible by both
145 // *not* supported by all devices, "managedMemorySupported" device parameter should be checked
147 };
148
149 // External memory type flags
151 {
153
154 // opaque POSIX file descriptor handle
156
157 // file descriptor handle for a Linux dma_buf
159
160 // opaque NT handle
162
163 // opaque global share (KMT) handle
165
166 // NT handle returned by IDXGIResource1::CreateSharedHandle referring to a Direct3D 11
167 // texture resource
169
170 // global share (KMT) handle returned by IDXGIResource::GetSharedHandle referring to a
171 // Direct3D 11 texture resource
173
174 // NT handle returned by IDXGIResource1::CreateSharedHandle referring to a Direct3D 11
175 // resource
177
178 // global share (KMT) handle returned by IDXGIResource::GetSharedHandle referring to a
179 // Direct3D 11 resource
181
182 // NT handle returned by ID3D12Device::CreateSharedHandle referring to a Direct3D 12
183 // heap resource
185
186 // NT handle returned by ID3D12Device::CreateSharedHandle referring to a Direct3D 12
187 // committed resource
189
190 // modifier flag indicating that the external memory has dedicated allocation
191 // used only in combination with one of the handle type flags above
193 };
194
195 template<> struct IsFlag<ExternalMemoryTypeFlag> { static constexpr bool value = true; };
197
198 // Buffer object with automatic reference counting
200 {
201 public:
202 BufferRef() : handle(nullptr) {}
203 BufferRef(OIDNBuffer handle) : handle(handle) {}
204
205 BufferRef(const BufferRef& other) : handle(other.handle)
206 {
207 if (handle)
208 oidnRetainBuffer(handle);
209 }
210
211 BufferRef(BufferRef&& other) noexcept : handle(other.handle)
212 {
213 other.handle = nullptr;
214 }
215
217 {
218 if (&other != this)
219 {
220 if (other.handle)
221 oidnRetainBuffer(other.handle);
222 if (handle)
223 oidnReleaseBuffer(handle);
224 handle = other.handle;
225 }
226 return *this;
227 }
228
229 BufferRef& operator =(BufferRef&& other) noexcept
230 {
231 std::swap(handle, other.handle);
232 return *this;
233 }
234
236 {
237 if (other)
238 oidnRetainBuffer(other);
239 if (handle)
240 oidnReleaseBuffer(handle);
241 handle = other;
242 return *this;
243 }
244
246 {
247 if (handle)
248 oidnReleaseBuffer(handle);
249 }
250
251 const OIDNBuffer& getHandle() const
252 {
253 return handle;
254 }
255
256 operator bool() const
257 {
258 return handle != nullptr;
259 }
260
261 // Releases the buffer (decrements the reference count).
262 void release()
263 {
264 if (handle)
265 {
266 oidnReleaseBuffer(handle);
267 handle = nullptr;
268 }
269 }
270
271 // Gets the size of the buffer in bytes.
272 size_t getSize() const
273 {
274 return oidnGetBufferSize(handle);
275 }
276
277 // Gets the storage mode of the buffer.
279 {
280 return static_cast<Storage>(oidnGetBufferStorage(handle));
281 }
282
283 // Gets a pointer to the buffer data, which is accessible to the device but not necessarily to
284 // the host as well, depending on the storage mode. Null pointer may be returned if the buffer
285 // is empty or getting a pointer to data with device storage is not supported by the device.
286 void* getData() const
287 {
288 return oidnGetBufferData(handle);
289 }
290
291 // Copies data from a region of the buffer to host memory.
292 void read(size_t byteOffset, size_t byteSize, void* dstHostPtr) const
293 {
294 oidnReadBuffer(handle, byteOffset, byteSize, dstHostPtr);
295 }
296
297 // Copies data from a region of the buffer to host memory asynchronously.
298 void readAsync(size_t byteOffset, size_t byteSize, void* dstHostPtr) const
299 {
300 oidnReadBufferAsync(handle, byteOffset, byteSize, dstHostPtr);
301 }
302
303 // Copies data to a region of the buffer from host memory.
304 void write(size_t byteOffset, size_t byteSize, const void* srcHostPtr)
305 {
306 oidnWriteBuffer(handle, byteOffset, byteSize, srcHostPtr);
307 }
308
309 // Copies data to a region of the buffer from host memory asynchronously.
310 void writeAsync(size_t byteOffset, size_t byteSize, const void* srcHostPtr)
311 {
312 oidnWriteBufferAsync(handle, byteOffset, byteSize, srcHostPtr);
313 }
314
315 private:
316 OIDNBuffer handle;
317 };
318
319 // -----------------------------------------------------------------------------------------------
320 // Semaphore
321 // -----------------------------------------------------------------------------------------------
322
323 // External semaphore type flags
325 {
327
328 // opaque POSIX file descriptor handle
330
331 // opaque NT handle
333
334 // opaque global share (KMT) handle
336
337 // NT handle referencing a Direct3D 11 fence object
339
340 // NT handle referencing a Direct3D 12 fence object
342
343 // NT handle referencing a Direct3D 11 keyed mutex object
345
346 // global share (KMT) handle referencing a Direct3D 11 keyed mutex object
348
349 // POSIX file descriptor referencing a timeline semaphore
351
352 // NT handle referencing a timeline semaphore
354 };
355
356 template<> struct IsFlag<ExternalSemaphoreTypeFlag> { static constexpr bool value = true; };
358
359 // Semaphore object with automatic reference counting
361 {
362 public:
363 SemaphoreRef() : handle(nullptr) {}
364 SemaphoreRef(OIDNSemaphore handle) : handle(handle) {}
365
366 SemaphoreRef(const SemaphoreRef& other) : handle(other.handle)
367 {
368 if (handle)
369 oidnRetainSemaphore(handle);
370 }
371
372 SemaphoreRef(SemaphoreRef&& other) noexcept : handle(other.handle)
373 {
374 other.handle = nullptr;
375 }
376
378 {
379 if (&other != this)
380 {
381 if (other.handle)
382 oidnRetainSemaphore(other.handle);
383 if (handle)
384 oidnReleaseSemaphore(handle);
385 handle = other.handle;
386 }
387 return *this;
388 }
389
391 {
392 std::swap(handle, other.handle);
393 return *this;
394 }
395
397 {
398 if (other)
399 oidnRetainSemaphore(other);
400 if (handle)
401 oidnReleaseSemaphore(handle);
402 handle = other;
403 return *this;
404 }
405
407 {
408 if (handle)
409 oidnReleaseSemaphore(handle);
410 }
411
413 {
414 return handle;
415 }
416
417 operator bool() const
418 {
419 return handle != nullptr;
420 }
421
422 // Releases the semaphore (decrements the reference count).
423 void release()
424 {
425 if (handle)
426 {
427 oidnReleaseSemaphore(handle);
428 handle = nullptr;
429 }
430 }
431
432 private:
433 OIDNSemaphore handle;
434 };
435
436 // -----------------------------------------------------------------------------------------------
437 // Filter
438 // -----------------------------------------------------------------------------------------------
439
440 // Filter quality/performance modes
441 enum class Quality
442 {
443 Default = OIDN_QUALITY_DEFAULT, // default quality
444
445 Fast = OIDN_QUALITY_FAST, // high performance (for interactive/real-time preview rendering)
446 Balanced = OIDN_QUALITY_BALANCED, // balanced quality/performance (for interactive/real-time rendering)
447 High = OIDN_QUALITY_HIGH, // high quality (for final-frame rendering)
448 };
449
450 // Progress monitor callback function
452
453 // Filter object with automatic reference counting
455 {
456 public:
457 FilterRef() : handle(nullptr) {}
458 FilterRef(OIDNFilter handle) : handle(handle) {}
459
460 FilterRef(const FilterRef& other) : handle(other.handle)
461 {
462 if (handle)
463 oidnRetainFilter(handle);
464 }
465
466 FilterRef(FilterRef&& other) noexcept : handle(other.handle)
467 {
468 other.handle = nullptr;
469 }
470
472 {
473 if (&other != this)
474 {
475 if (other.handle)
476 oidnRetainFilter(other.handle);
477 if (handle)
478 oidnReleaseFilter(handle);
479 handle = other.handle;
480 }
481 return *this;
482 }
483
484 FilterRef& operator =(FilterRef&& other) noexcept
485 {
486 std::swap(handle, other.handle);
487 return *this;
488 }
489
491 {
492 if (other)
493 oidnRetainFilter(other);
494 if (handle)
495 oidnReleaseFilter(handle);
496 handle = other;
497 return *this;
498 }
499
501 {
502 if (handle)
503 oidnReleaseFilter(handle);
504 }
505
506 const OIDNFilter& getHandle() const
507 {
508 return handle;
509 }
510
511 operator bool() const
512 {
513 return handle != nullptr;
514 }
515
516 // Releases the filter (decrements the reference count).
517 void release()
518 {
519 if (handle)
520 {
521 oidnReleaseFilter(handle);
522 handle = nullptr;
523 }
524 }
525
526 // Sets an image parameter of the filter with data stored in a buffer.
527 void setImage(const char* name,
529 size_t width, size_t height,
530 size_t byteOffset = 0,
531 size_t pixelByteStride = 0, size_t rowByteStride = 0)
532 {
533 oidnSetFilterImage(handle, name,
534 buffer.getHandle(), static_cast<OIDNFormat>(format),
535 width, height,
536 byteOffset,
537 pixelByteStride, rowByteStride);
538 }
539
540 // Sets an image parameter of the filter with data owned by the user and accessible to the device.
541 void setImage(const char* name,
542 void* devPtr, Format format,
543 size_t width, size_t height,
544 size_t byteOffset = 0,
545 size_t pixelByteStride = 0, size_t rowByteStride = 0)
546 {
548 devPtr, static_cast<OIDNFormat>(format),
549 width, height,
550 byteOffset,
551 pixelByteStride, rowByteStride);
552 }
553
554 // Unsets an image parameter of the filter that was previously set.
555 void unsetImage(const char* name)
556 {
557 oidnUnsetFilterImage(handle, name);
558 }
559
560 OIDN_DEPRECATED("removeImage is deprecated. Use unsetImage instead.")
561 void removeImage(const char* name)
562 {
563 oidnUnsetFilterImage(handle, name);
564 }
565
566 // Sets an opaque data parameter of the filter owned by the user and accessible to the host.
567 void setData(const char* name, void* hostPtr, size_t byteSize)
568 {
569 oidnSetSharedFilterData(handle, name, hostPtr, byteSize);
570 }
571
572 // Notifies the filter that the contents of an opaque data parameter has been changed.
573 void updateData(const char* name)
574 {
575 oidnUpdateFilterData(handle, name);
576 }
577
578 // Unsets an opaque data parameter of the filter that was previously set.
579 void unsetData(const char* name)
580 {
581 oidnUnsetFilterData(handle, name);
582 }
583
584 OIDN_DEPRECATED("removeData is deprecated. Use unsetData instead.")
585 void removeData(const char* name)
586 {
587 oidnUnsetFilterData(handle, name);
588 }
589
590 // Sets a boolean parameter of the filter.
591 void set(const char* name, bool value)
592 {
593 oidnSetFilterBool(handle, name, value);
594 }
595
596 // Sets an integer parameter of the filter.
597 void set(const char* name, int value)
598 {
599 oidnSetFilterInt(handle, name, value);
600 }
601
602 void set(const char* name, Quality value)
603 {
604 oidnSetFilterInt(handle, name, static_cast<int>(value));
605 }
606
607 // Sets a float parameter of the filter.
608 void set(const char* name, float value)
609 {
610 oidnSetFilterFloat(handle, name, value);
611 }
612
613 // Gets a parameter of the filter.
614 template<typename T>
615 T get(const char* name) const;
616
617 // Sets the progress monitor callback function of the filter.
618 void setProgressMonitorFunction(ProgressMonitorFunction func, void* userPtr = nullptr)
619 {
620 oidnSetFilterProgressMonitorFunction(handle, func, userPtr);
621 }
622
623 // Commits all previous changes to the filter.
624 void commit()
625 {
626 oidnCommitFilter(handle);
627 }
628
629 // Executes the filter.
630 void execute()
631 {
632 oidnExecuteFilter(handle);
633 }
634
635 // Executes the filter asynchronously.
637 {
639 }
640
641 #if defined(OIDN_SYCL_HPP)
642 // Executes the filter of a SYCL device using the specified dependent events asynchronously, and
643 // optionally returns an event for completion.
644 sycl::event executeAsync(const std::vector<sycl::event>& depEvents)
645 {
646 sycl::event doneEvent;
647 oidnExecuteSYCLFilterAsync(handle, depEvents.data(), static_cast<int>(depEvents.size()), &doneEvent);
648 return doneEvent;
649 }
650 #endif
651
652 private:
653 OIDNFilter handle;
654 };
655
656 template<>
657 inline bool FilterRef::get(const char* name) const
658 {
659 return oidnGetFilterBool(handle, name);
660 }
661
662 template<>
663 inline int FilterRef::get(const char* name) const
664 {
665 return oidnGetFilterInt(handle, name);
666 }
667
668 template<>
669 inline Quality FilterRef::get(const char* name) const
670 {
671 return static_cast<Quality>(oidnGetFilterInt(handle, name));
672 }
673
674 template<>
675 inline float FilterRef::get(const char* name) const
676 {
677 return oidnGetFilterFloat(handle, name);
678 }
679
680 // -----------------------------------------------------------------------------------------------
681 // Device
682 // -----------------------------------------------------------------------------------------------
683
684 // Device types
685 enum class DeviceType
686 {
687 Default = OIDN_DEVICE_TYPE_DEFAULT, // select device automatically
688
689 CPU = OIDN_DEVICE_TYPE_CPU, // CPU device
690 SYCL = OIDN_DEVICE_TYPE_SYCL, // SYCL device
691 CUDA = OIDN_DEVICE_TYPE_CUDA, // CUDA device
692 HIP = OIDN_DEVICE_TYPE_HIP, // HIP device
693 Metal = OIDN_DEVICE_TYPE_METAL, // Metal device
694 };
695
696 // Error codes
697 enum class Error
698 {
699 None = OIDN_ERROR_NONE, // no error occurred
700 Unknown = OIDN_ERROR_UNKNOWN, // an unknown error occurred
701 InvalidArgument = OIDN_ERROR_INVALID_ARGUMENT, // an invalid argument was specified
702 InvalidOperation = OIDN_ERROR_INVALID_OPERATION, // the operation is not allowed
703 OutOfMemory = OIDN_ERROR_OUT_OF_MEMORY, // not enough memory to execute the operation
704 UnsupportedHardware = OIDN_ERROR_UNSUPPORTED_HARDWARE, // the hardware (e.g. CPU) is not supported
705 Cancelled = OIDN_ERROR_CANCELLED, // the operation was cancelled by the user
706 };
707
708 // Error callback function
709 typedef void (*ErrorFunction)(void* userPtr, Error code, const char* message);
710
711 // Opaque universally unique identifier (UUID) of a physical device
712 struct UUID
713 {
715 };
716
717 // Opaque locally unique identifier (LUID) of a physical device
718 struct LUID
719 {
720 union
721 {
722 struct
723 {
724 uint32_t low;
725 int32_t high;
726 };
728 };
729 };
730
731 // Device object with automatic reference counting
733 {
734 public:
735 DeviceRef() : handle(nullptr) {}
736 DeviceRef(OIDNDevice handle) : handle(handle) {}
737
738 DeviceRef(const DeviceRef& other) : handle(other.handle)
739 {
740 if (handle)
741 oidnRetainDevice(handle);
742 }
743
744 DeviceRef(DeviceRef&& other) noexcept : handle(other.handle)
745 {
746 other.handle = nullptr;
747 }
748
750 {
751 if (&other != this)
752 {
753 if (other.handle)
754 oidnRetainDevice(other.handle);
755 if (handle)
756 oidnReleaseDevice(handle);
757 handle = other.handle;
758 }
759 return *this;
760 }
761
762 DeviceRef& operator =(DeviceRef&& other) noexcept
763 {
764 std::swap(handle, other.handle);
765 return *this;
766 }
767
769 {
770 if (other)
771 oidnRetainDevice(other);
772 if (handle)
773 oidnReleaseDevice(handle);
774 handle = other;
775 return *this;
776 }
777
779 {
780 if (handle)
781 oidnReleaseDevice(handle);
782 }
783
784 const OIDNDevice& getHandle() const
785 {
786 return handle;
787 }
788
789 operator bool() const
790 {
791 return handle != nullptr;
792 }
793
794 // Releases the device (decrements the reference count).
795 void release()
796 {
797 if (handle)
798 {
799 oidnReleaseDevice(handle);
800 handle = nullptr;
801 }
802 }
803
804 // Sets a boolean parameter of the device.
805 void set(const char* name, bool value)
806 {
807 oidnSetDeviceBool(handle, name, value);
808 }
809
810 // Sets an integer parameter of the device.
811 void set(const char* name, int value)
812 {
813 oidnSetDeviceInt(handle, name, value);
814 }
815
816 // Sets an unsigned integer parameter of the device.
817 void set(const char* name, unsigned int value)
818 {
819 oidnSetDeviceUInt(handle, name, value);
820 }
821
822 // Gets a parameter of the device.
823 template<typename T>
824 T get(const char* name) const;
825
826 // Sets the error callback function of the device.
827 void setErrorFunction(ErrorFunction func, void* userPtr = nullptr)
828 {
829 oidnSetDeviceErrorFunction(handle, reinterpret_cast<OIDNErrorFunction>(func), userPtr);
830 }
831
832 // Returns the first unqueried error code and clears the stored error.
833 // Can be called for a null device as well to check for global errors (e.g. why a device
834 // creation or physical device query has failed.
836 {
837 return static_cast<Error>(oidnGetDeviceError(handle, nullptr));
838 }
839
840 // Returns the first unqueried error code and string message, and clears the stored error.
841 // Can be called for a null device as well to check why a device creation failed.
842 Error getError(const char*& outMessage)
843 {
844 return static_cast<Error>(oidnGetDeviceError(handle, &outMessage));
845 }
846
847 // Commits all previous changes to the device.
848 // Must be called before first using the device (e.g. creating filters).
849 void commit()
850 {
851 oidnCommitDevice(handle);
852 }
853
854 // Waits for all asynchronous operations running on the device to complete.
855 void sync()
856 {
857 oidnSyncDevice(handle);
858 }
859
860 // Creates a buffer accessible to both the host and device.
861 BufferRef newBuffer(size_t byteSize) const
862 {
863 return oidnNewBuffer(handle, byteSize);
864 }
865
866 // Creates a buffer with the specified storage mode.
867 BufferRef newBuffer(size_t byteSize, Storage storage) const
868 {
869 return oidnNewBufferWithStorage(handle, byteSize, static_cast<OIDNStorage>(storage));
870 }
871
872 // Creates a shared buffer from memory allocated and owned by the user and accessible to the
873 // device.
874 BufferRef newBuffer(void* ptr, size_t byteSize) const
875 {
876 return oidnNewSharedBuffer(handle, ptr, byteSize);
877 }
878
879 // Creates a shared buffer by importing external memory from a POSIX file descriptor.
880 BufferRef newBuffer(ExternalMemoryTypeFlags fdType, int fd, size_t byteSize) const
881 {
883 handle, static_cast<OIDNExternalMemoryTypeFlags>(fdType), fd, byteSize);
884 }
885
886 // Creates a shared buffer by importing external memory from a Win32 handle.
887 BufferRef newBuffer(ExternalMemoryTypeFlags handleType, void* handle, const void* name, size_t byteSize) const
888 {
890 this->handle, static_cast<OIDNExternalMemoryTypeFlags>(handleType), handle, name, byteSize);
891 }
892
893 // Creates a shared buffer from a Metal buffer.
894 // Only buffers with shared or private storage and hazard tracking are supported.
895 #if defined(__OBJC__)
896 BufferRef newBuffer(id<MTLBuffer> buffer) const
897 {
898 return oidnNewSharedBufferFromMetal(handle, buffer);
899 }
900 #endif
901
903 {
905 handle, static_cast<OIDNExternalSemaphoreTypeFlags>(fdType), fd);
906 }
907
908 SemaphoreRef newSemaphore(ExternalSemaphoreTypeFlags handleType, void* handle, const void* name) const
909 {
911 this->handle, static_cast<OIDNExternalSemaphoreTypeFlags>(handleType), handle, name);
912 }
913
914 void signalSemaphoreAsync(const SemaphoreRef& semaphore) const
915 {
916 oidnSignalSemaphoresAsync(handle, &semaphore.getHandle(), nullptr, 1);
917 }
918
919 void signalSemaphoreAsync(const SemaphoreRef& semaphore, uint64_t value) const
920 {
921 oidnSignalSemaphoresAsync(handle, &semaphore.getHandle(), &value, 1);
922 }
923
924 void signalSemaphoresAsync(const std::vector<SemaphoreRef>& semaphores) const
925 {
927 reinterpret_cast<const OIDNSemaphore*>(semaphores.data()),
928 nullptr,
929 static_cast<int>(semaphores.size()));
930 }
931
932 void signalSemaphoresAsync(const std::vector<SemaphoreRef>& semaphores,
933 const std::vector<uint64_t>& values) const
934 {
936 reinterpret_cast<const OIDNSemaphore*>(semaphores.data()),
937 values.data(),
938 static_cast<int>(semaphores.size()));
939 }
940
941 void waitSemaphoreAsync(const SemaphoreRef& semaphore) const
942 {
943 oidnWaitSemaphoresAsync(handle, &semaphore.getHandle(), nullptr, nullptr, 1);
944 }
945
946 void waitSemaphoreAsync(const SemaphoreRef& semaphore, uint64_t value) const
947 {
948 oidnWaitSemaphoresAsync(handle, &semaphore.getHandle(), &value, nullptr, 1);
949 }
950
951 void waitSemaphoreAsync(const SemaphoreRef& semaphore, uint64_t value, uint32_t timeoutMs) const
952 {
953 oidnWaitSemaphoresAsync(handle, &semaphore.getHandle(), &value, &timeoutMs, 1);
954 }
955
956 void waitSemaphoresAsync(const std::vector<SemaphoreRef>& semaphores) const
957 {
959 reinterpret_cast<const OIDNSemaphore*>(semaphores.data()),
960 nullptr,
961 nullptr,
962 static_cast<int>(semaphores.size()));
963 }
964
965 void waitSemaphoresAsync(const std::vector<SemaphoreRef>& semaphores,
966 const std::vector<uint64_t>& values) const
967 {
969 reinterpret_cast<const OIDNSemaphore*>(semaphores.data()),
970 values.data(),
971 nullptr,
972 static_cast<int>(semaphores.size()));
973 }
974
975 void waitSemaphoresAsync(const std::vector<SemaphoreRef>& semaphores,
976 const std::vector<uint64_t>& values,
977 const std::vector<uint32_t>& timeoutsMs) const
978 {
980 reinterpret_cast<const OIDNSemaphore*>(semaphores.data()),
981 values.data(),
982 timeoutsMs.data(),
983 static_cast<int>(semaphores.size()));
984 }
985
986 // Creates a filter of the specified type (e.g. "RT").
987 FilterRef newFilter(const char* type) const
988 {
989 return oidnNewFilter(handle, type);
990 }
991
992 private:
993 OIDNDevice handle;
994 };
995
996 template<>
997 inline bool DeviceRef::get(const char* name) const
998 {
999 return oidnGetDeviceBool(handle, name);
1000 }
1001
1002 template<>
1003 inline int DeviceRef::get(const char* name) const
1004 {
1005 return oidnGetDeviceInt(handle, name);
1006 }
1007
1008 template<>
1009 inline unsigned int DeviceRef::get(const char* name) const
1010 {
1011 return oidnGetDeviceUInt(handle, name);
1012 }
1013
1014 template<>
1015 inline DeviceType DeviceRef::get(const char* name) const
1016 {
1017 return static_cast<DeviceType>(oidnGetDeviceInt(handle, name));
1018 }
1019
1020 template<>
1022 {
1024 }
1025
1026 // Returns the first unqueried per-thread global error code and clears the stored error.
1028 {
1029 return static_cast<Error>(oidnGetDeviceError(nullptr, nullptr));
1030 }
1031
1032 // Returns the first unqueried per-thread global error code and string message, and clears the
1033 // stored error.
1034 inline Error getError(const char*& outMessage)
1035 {
1036 return static_cast<Error>(oidnGetDeviceError(nullptr, &outMessage));
1037 }
1038
1039 // Returns whether the CPU device is supported.
1041 {
1042 return oidnIsCPUDeviceSupported();
1043 }
1044
1045 // Returns whether the specified SYCL device is supported.
1046#if defined(OIDN_SYCL_HPP)
1047 inline bool isSYCLDeviceSupported(const sycl::device& device)
1048 {
1049 return oidnIsSYCLDeviceSupported(&device);
1050 }
1051#endif
1052
1053 // Returns whether the specified CUDA device is supported.
1054 inline bool isCUDADeviceSupported(int deviceID)
1055 {
1056 return oidnIsCUDADeviceSupported(deviceID);
1057 }
1058
1059 // Returns whether the specified HIP device is supported.
1060 inline bool isHIPDeviceSupported(int deviceID)
1061 {
1062 return oidnIsHIPDeviceSupported(deviceID);
1063 }
1064
1065 // Returns whether the specified Metal device is supported.
1067 {
1068 return oidnIsMetalDeviceSupported(device);
1069 }
1070
1071 // Creates a device of the specified type.
1076
1077 // Creates a device from a physical device specified by its ID (0 to getNumPhysicalDevices()-1).
1078 inline DeviceRef newDevice(int physicalDeviceID)
1079 {
1080 return DeviceRef(oidnNewDeviceByID(physicalDeviceID));
1081 }
1082
1083 // Creates a device from a physical device specified by its UUID.
1084 inline DeviceRef newDevice(const UUID& uuid)
1085 {
1086 return DeviceRef(oidnNewDeviceByUUID(uuid.bytes));
1087 }
1088
1089 // Creates a device from a physical device specified by its LUID.
1090 inline DeviceRef newDevice(const LUID& luid)
1091 {
1092 return DeviceRef(oidnNewDeviceByLUID(luid.bytes));
1093 }
1094
1095 // Creates a device from a physical device specified by its PCI address.
1096 inline DeviceRef newDevice(int pciDomain, int pciBus, int pciDevice, int pciFunction)
1097 {
1098 return DeviceRef(oidnNewDeviceByPCIAddress(pciDomain, pciBus, pciDevice, pciFunction));
1099 }
1100
1101#if defined(OIDN_SYCL_HPP)
1102 // Creates a device from the specified SYCL queue.
1103 inline DeviceRef newSYCLDevice(const sycl::queue& queue)
1104 {
1105 return DeviceRef(oidnNewSYCLDevice(&queue, 1));
1106 }
1107
1108 // Creates a device from the specified list of SYCL queues.
1109 // The queues should belong to different SYCL sub-devices (Xe Stack/Tile) of the same SYCL
1110 // root-device (GPU).
1111 inline DeviceRef newSYCLDevice(const std::vector<sycl::queue>& queues)
1112 {
1113 return DeviceRef(oidnNewSYCLDevice(queues.data(), static_cast<int>(queues.size())));
1114 }
1115#endif
1116
1117 // Creates a device from the specified CUDA device ID and stream (null stream corresponds to the
1118 // default stream).
1119 inline DeviceRef newCUDADevice(int deviceID, cudaStream_t stream)
1120 {
1121 return DeviceRef(oidnNewCUDADevice(&deviceID, &stream, 1));
1122 }
1123
1124 // Creates a device from the specified pairs of CUDA device IDs and streams (null stream
1125 // corresponds to the default stream). Currently only one device ID/stream is supported.
1126 inline DeviceRef newCUDADevice(const std::vector<int>& deviceIDs,
1127 const std::vector<cudaStream_t>& streams)
1128 {
1129 assert(deviceIDs.size() == streams.size());
1130 return DeviceRef(oidnNewCUDADevice(deviceIDs.data(), streams.data(),
1131 static_cast<int>(streams.size())));
1132 }
1133
1134 // Creates a device from the specified HIP device ID and stream (null stream corresponds to the
1135 // default stream).
1136 inline DeviceRef newHIPDevice(int deviceID, hipStream_t stream)
1137 {
1138 return DeviceRef(oidnNewHIPDevice(&deviceID, &stream, 1));
1139 }
1140
1141 // Creates a device from the specified pairs of HIP device IDs and streams (null stream
1142 // corresponds to the default stream). Currently only one device ID/stream is supported.
1143 inline DeviceRef newHIPDevice(const std::vector<int>& deviceIDs,
1144 const std::vector<hipStream_t>& streams)
1145 {
1146 assert(deviceIDs.size() == streams.size());
1147 return DeviceRef(oidnNewHIPDevice(deviceIDs.data(), streams.data(),
1148 static_cast<int>(streams.size())));
1149 }
1150
1151 // Creates a device from the specified Metal command queue.
1153 {
1154 return DeviceRef(oidnNewMetalDevice(&commandQueue, 1));
1155 }
1156
1157 // Creates a device from the specified list of Metal command queues.
1158 // Currently only one queue is supported.
1159 inline DeviceRef newMetalDevice(const std::vector<MTLCommandQueue_id>& commandQueues)
1160 {
1161 return DeviceRef(oidnNewMetalDevice(commandQueues.data(), static_cast<int>(commandQueues.size())));
1162 }
1163
1164 // -----------------------------------------------------------------------------------------------
1165 // Physical Device
1166 // -----------------------------------------------------------------------------------------------
1167
1169 {
1170 public:
1171 PhysicalDeviceRef() : id(-1) {}
1172 PhysicalDeviceRef(int id) : id(id) {}
1173
1175 {
1176 id = other;
1177 return *this;
1178 }
1179
1180 int getID() const
1181 {
1182 return id;
1183 }
1184
1185 operator bool() const
1186 {
1187 return id >= 0;
1188 }
1189
1190 // Gets a paramter of the physical device.
1191 template<typename T>
1192 T get(const char* name) const;
1193
1194 // Gets an opaque data parameter of the physical device.
1195 std::pair<const void*, size_t> getData(const char* name) const
1196 {
1197 size_t byteSize = 0;
1198 const void* ptr = oidnGetPhysicalDeviceData(id, name, &byteSize);
1199 return {ptr, byteSize};
1200 }
1201
1202 // Creates a device from the physical device.
1204 {
1205 return DeviceRef(oidnNewDeviceByID(id));
1206 }
1207
1208 private:
1209 int id;
1210 };
1211
1212 // Returns the number of supported physical devices.
1214 {
1216 }
1217
1218 template<>
1219 inline bool PhysicalDeviceRef::get(const char* name) const
1220 {
1221 return oidnGetPhysicalDeviceBool(id, name);
1222 }
1223
1224 template<>
1225 inline int PhysicalDeviceRef::get(const char* name) const
1226 {
1227 return oidnGetPhysicalDeviceInt(id, name);
1228 }
1229
1230 template<>
1231 inline unsigned int PhysicalDeviceRef::get(const char* name) const
1232 {
1233 return oidnGetPhysicalDeviceUInt(id, name);
1234 }
1235
1236 template<>
1237 inline DeviceType PhysicalDeviceRef::get(const char* name) const
1238 {
1239 return static_cast<DeviceType>(oidnGetPhysicalDeviceInt(id, name));
1240 }
1241
1242 template<>
1243 inline const char* PhysicalDeviceRef::get(const char* name) const
1244 {
1246 }
1247
1248 template<>
1249 inline std::string PhysicalDeviceRef::get(const char* name) const
1250 {
1251 const char* str = oidnGetPhysicalDeviceString(id, name);
1252 return str ? str : "";
1253 }
1254
1255 template<>
1256 inline UUID PhysicalDeviceRef::get(const char* name) const
1257 {
1258 UUID uuid{};
1259 auto data = getData(name);
1260 if (data.first != nullptr)
1261 {
1262 if (data.second == sizeof(uuid.bytes))
1263 std::memcpy(uuid.bytes, data.first, sizeof(uuid.bytes));
1264 else
1265 getData(""); // invoke an error
1266 }
1267 return uuid;
1268 }
1269
1270 template<>
1271 inline LUID PhysicalDeviceRef::get(const char* name) const
1272 {
1273 LUID luid{};
1274 auto data = getData(name);
1275 if (data.first != nullptr)
1276 {
1277 if (data.second == sizeof(luid.bytes))
1278 std::memcpy(luid.bytes, data.first, sizeof(luid.bytes));
1279 else
1280 getData(""); // invoke an error
1281 }
1282 return luid;
1283 }
1284
Definition oidn.hpp:200
void readAsync(size_t byteOffset, size_t byteSize, void *dstHostPtr) const
Definition oidn.hpp:298
BufferRef(BufferRef &&other) noexcept
Definition oidn.hpp:211
BufferRef()
Definition oidn.hpp:202
~BufferRef()
Definition oidn.hpp:245
void writeAsync(size_t byteOffset, size_t byteSize, const void *srcHostPtr)
Definition oidn.hpp:310
BufferRef(OIDNBuffer handle)
Definition oidn.hpp:203
void release()
Definition oidn.hpp:262
size_t getSize() const
Definition oidn.hpp:272
void read(size_t byteOffset, size_t byteSize, void *dstHostPtr) const
Definition oidn.hpp:292
void * getData() const
Definition oidn.hpp:286
BufferRef(const BufferRef &other)
Definition oidn.hpp:205
const OIDNBuffer & getHandle() const
Definition oidn.hpp:251
void write(size_t byteOffset, size_t byteSize, const void *srcHostPtr)
Definition oidn.hpp:304
BufferRef & operator=(const BufferRef &other)
Definition oidn.hpp:216
Storage getStorage() const
Definition oidn.hpp:278
Definition oidn.hpp:733
~DeviceRef()
Definition oidn.hpp:778
void commit()
Definition oidn.hpp:849
void waitSemaphoreAsync(const SemaphoreRef &semaphore, uint64_t value) const
Definition oidn.hpp:946
void waitSemaphoreAsync(const SemaphoreRef &semaphore, uint64_t value, uint32_t timeoutMs) const
Definition oidn.hpp:951
void waitSemaphoresAsync(const std::vector< SemaphoreRef > &semaphores, const std::vector< uint64_t > &values, const std::vector< uint32_t > &timeoutsMs) const
Definition oidn.hpp:975
void set(const char *name, int value)
Definition oidn.hpp:811
DeviceRef(DeviceRef &&other) noexcept
Definition oidn.hpp:744
Error getError(const char *&outMessage)
Definition oidn.hpp:842
Error getError()
Definition oidn.hpp:835
void waitSemaphoreAsync(const SemaphoreRef &semaphore) const
Definition oidn.hpp:941
void signalSemaphoreAsync(const SemaphoreRef &semaphore, uint64_t value) const
Definition oidn.hpp:919
void signalSemaphoreAsync(const SemaphoreRef &semaphore) const
Definition oidn.hpp:914
DeviceRef & operator=(const DeviceRef &other)
Definition oidn.hpp:749
BufferRef newBuffer(ExternalMemoryTypeFlags handleType, void *handle, const void *name, size_t byteSize) const
Definition oidn.hpp:887
FilterRef newFilter(const char *type) const
Definition oidn.hpp:987
DeviceRef(OIDNDevice handle)
Definition oidn.hpp:736
BufferRef newBuffer(void *ptr, size_t byteSize) const
Definition oidn.hpp:874
const OIDNDevice & getHandle() const
Definition oidn.hpp:784
void waitSemaphoresAsync(const std::vector< SemaphoreRef > &semaphores, const std::vector< uint64_t > &values) const
Definition oidn.hpp:965
SemaphoreRef newSemaphore(ExternalSemaphoreTypeFlags handleType, void *handle, const void *name) const
Definition oidn.hpp:908
void sync()
Definition oidn.hpp:855
BufferRef newBuffer(ExternalMemoryTypeFlags fdType, int fd, size_t byteSize) const
Definition oidn.hpp:880
BufferRef newBuffer(size_t byteSize, Storage storage) const
Definition oidn.hpp:867
void set(const char *name, unsigned int value)
Definition oidn.hpp:817
void waitSemaphoresAsync(const std::vector< SemaphoreRef > &semaphores) const
Definition oidn.hpp:956
DeviceRef(const DeviceRef &other)
Definition oidn.hpp:738
void release()
Definition oidn.hpp:795
void set(const char *name, bool value)
Definition oidn.hpp:805
void setErrorFunction(ErrorFunction func, void *userPtr=nullptr)
Definition oidn.hpp:827
SemaphoreRef newSemaphore(ExternalSemaphoreTypeFlags fdType, int fd) const
Definition oidn.hpp:902
void signalSemaphoresAsync(const std::vector< SemaphoreRef > &semaphores) const
Definition oidn.hpp:924
T get(const char *name) const
DeviceRef()
Definition oidn.hpp:735
BufferRef newBuffer(size_t byteSize) const
Definition oidn.hpp:861
void signalSemaphoresAsync(const std::vector< SemaphoreRef > &semaphores, const std::vector< uint64_t > &values) const
Definition oidn.hpp:932
Definition oidn.hpp:455
const OIDNFilter & getHandle() const
Definition oidn.hpp:506
void removeData(const char *name)
Definition oidn.hpp:585
void setImage(const char *name, const BufferRef &buffer, Format format, size_t width, size_t height, size_t byteOffset=0, size_t pixelByteStride=0, size_t rowByteStride=0)
Definition oidn.hpp:527
void updateData(const char *name)
Definition oidn.hpp:573
void set(const char *name, bool value)
Definition oidn.hpp:591
void set(const char *name, int value)
Definition oidn.hpp:597
void setProgressMonitorFunction(ProgressMonitorFunction func, void *userPtr=nullptr)
Definition oidn.hpp:618
FilterRef(const FilterRef &other)
Definition oidn.hpp:460
FilterRef(OIDNFilter handle)
Definition oidn.hpp:458
FilterRef(FilterRef &&other) noexcept
Definition oidn.hpp:466
void executeAsync()
Definition oidn.hpp:636
void setData(const char *name, void *hostPtr, size_t byteSize)
Definition oidn.hpp:567
void release()
Definition oidn.hpp:517
void setImage(const char *name, void *devPtr, Format format, size_t width, size_t height, size_t byteOffset=0, size_t pixelByteStride=0, size_t rowByteStride=0)
Definition oidn.hpp:541
FilterRef & operator=(const FilterRef &other)
Definition oidn.hpp:471
void set(const char *name, Quality value)
Definition oidn.hpp:602
~FilterRef()
Definition oidn.hpp:500
FilterRef()
Definition oidn.hpp:457
void removeImage(const char *name)
Definition oidn.hpp:561
void commit()
Definition oidn.hpp:624
void execute()
Definition oidn.hpp:630
void set(const char *name, float value)
Definition oidn.hpp:608
void unsetImage(const char *name)
Definition oidn.hpp:555
T get(const char *name) const
void unsetData(const char *name)
Definition oidn.hpp:579
Definition oidn.hpp:30
constexpr Flags operator|(const Flags &b) const noexcept
Definition oidn.hpp:42
constexpr bool operator!() const noexcept
Definition oidn.hpp:39
constexpr Flags operator&(const Flags &b) const noexcept
Definition oidn.hpp:41
constexpr Flags(OIDNFlags mask) noexcept
Definition oidn.hpp:37
constexpr bool operator!=(const Flags &b) const noexcept
Definition oidn.hpp:66
constexpr bool operator==(const Flags &b) const noexcept
Definition oidn.hpp:65
Flags & operator^=(const Flags &b) noexcept
Definition oidn.hpp:59
constexpr Flags(const Flags &b) noexcept=default
constexpr Flags operator^(const Flags &b) const noexcept
Definition oidn.hpp:43
constexpr Flags(FlagT flag) noexcept
Definition oidn.hpp:35
Flags & operator&=(const Flags &b) noexcept
Definition oidn.hpp:47
Flags & operator=(const Flags &b) noexcept=default
Flags & operator|=(const Flags &b) noexcept
Definition oidn.hpp:53
constexpr Flags() noexcept
Definition oidn.hpp:34
PhysicalDeviceRef()
Definition oidn.hpp:1171
PhysicalDeviceRef & operator=(int other)
Definition oidn.hpp:1174
std::pair< const void *, size_t > getData(const char *name) const
Definition oidn.hpp:1195
T get(const char *name) const
PhysicalDeviceRef(int id)
Definition oidn.hpp:1172
DeviceRef newDevice()
Definition oidn.hpp:1203
int getID() const
Definition oidn.hpp:1180
Definition oidn.hpp:361
SemaphoreRef & operator=(const SemaphoreRef &other)
Definition oidn.hpp:377
const OIDNSemaphore & getHandle() const
Definition oidn.hpp:412
SemaphoreRef(const SemaphoreRef &other)
Definition oidn.hpp:366
SemaphoreRef(SemaphoreRef &&other) noexcept
Definition oidn.hpp:372
void release()
Definition oidn.hpp:423
SemaphoreRef(OIDNSemaphore handle)
Definition oidn.hpp:364
SemaphoreRef()
Definition oidn.hpp:363
~SemaphoreRef()
Definition oidn.hpp:406
#define OIDN_NAMESPACE_BEGIN
Definition config.h:36
#define OIDN_DEPRECATED(msg)
Definition config.h:62
#define OIDN_NAMESPACE_END
Definition config.h:37
GLint GLsizei width
Definition imgui_impl_opengl3_loader.h:191
GLsizei GLboolean const GLfloat * value
Definition imgui_impl_opengl3_loader.h:330
GLuint buffer
Definition imgui_impl_opengl3_loader.h:274
const GLchar * name
Definition imgui_impl_opengl3_loader.h:317
GLint GLint GLsizei GLsizei GLint GLenum GLenum type
Definition imgui_impl_opengl3_loader.h:193
GLint GLsizei GLsizei height
Definition imgui_impl_opengl3_loader.h:191
GLint GLint GLsizei GLsizei GLint GLenum format
Definition imgui_impl_opengl3_loader.h:193
GLint * data
Definition imgui_impl_opengl3_loader.h:202
typedef void(APIENTRYP PFNGLPOLYGONMODEPROC)(GLenum face
OIDN_API void oidnReleaseFilter(OIDNFilter filter)
OIDN_API void oidnRetainDevice(OIDNDevice device)
OIDN_API OIDNError oidnGetDeviceError(OIDNDevice device, const char **outMessage)
OIDN_API const char * oidnGetPhysicalDeviceString(int physicalDeviceID, const char *name)
OIDN_API OIDNDevice oidnNewDeviceByLUID(const void *luid)
OIDN_API OIDNDevice oidnNewMetalDevice(const MTLCommandQueue_id *commandQueues, int numQueues)
OIDN_API void oidnReadBufferAsync(OIDNBuffer buffer, size_t byteOffset, size_t byteSize, void *dstHostPtr)
unsigned int oidnGetDeviceUInt(OIDNDevice device, const char *name)
Definition oidn.h:209
struct ihipStream_t * hipStream_t
Definition oidn.h:29
OIDN_API OIDNFilter oidnNewFilter(OIDNDevice device, const char *type)
OIDN_API OIDNBuffer oidnNewSharedBufferFromWin32Handle(OIDNDevice device, OIDNExternalMemoryTypeFlags handleType, void *handle, const void *name, size_t byteSize)
@ OIDN_QUALITY_HIGH
Definition oidn.h:463
@ OIDN_QUALITY_DEFAULT
Definition oidn.h:459
@ OIDN_QUALITY_FAST
Definition oidn.h:461
@ OIDN_QUALITY_BALANCED
Definition oidn.h:462
struct OIDNBufferImpl * OIDNBuffer
Definition oidn.h:322
@ OIDN_EXTERNAL_SEMAPHORE_TYPE_FLAG_OPAQUE_FD
Definition oidn.h:389
@ OIDN_EXTERNAL_SEMAPHORE_TYPE_FLAG_KEYED_MUTEX_KMT
Definition oidn.h:407
@ OIDN_EXTERNAL_SEMAPHORE_TYPE_FLAG_NONE
Definition oidn.h:386
@ OIDN_EXTERNAL_SEMAPHORE_TYPE_FLAG_TIMELINE_SEMAPHORE_FD
Definition oidn.h:410
@ OIDN_EXTERNAL_SEMAPHORE_TYPE_FLAG_TIMELINE_SEMAPHORE_WIN32
Definition oidn.h:413
@ OIDN_EXTERNAL_SEMAPHORE_TYPE_FLAG_D3D12_FENCE
Definition oidn.h:401
@ OIDN_EXTERNAL_SEMAPHORE_TYPE_FLAG_D3D11_FENCE
Definition oidn.h:398
@ OIDN_EXTERNAL_SEMAPHORE_TYPE_FLAG_OPAQUE_WIN32
Definition oidn.h:392
@ OIDN_EXTERNAL_SEMAPHORE_TYPE_FLAG_KEYED_MUTEX
Definition oidn.h:404
@ OIDN_EXTERNAL_SEMAPHORE_TYPE_FLAG_OPAQUE_WIN32_KMT
Definition oidn.h:395
OIDN_API OIDNDevice oidnNewCUDADevice(const int *deviceIDs, const cudaStream_t *streams, int numPairs)
OIDN_API OIDNDevice oidnNewHIPDevice(const int *deviceIDs, const hipStream_t *streams, int numPairs)
OIDN_API void oidnExecuteFilterAsync(OIDNFilter filter)
OIDN_API bool oidnIsCPUDeviceSupported()
OIDN_API void oidnSetDeviceInt(OIDNDevice device, const char *name, int value)
OIDN_API bool oidnGetDeviceBool(OIDNDevice device, const char *name)
struct OIDNDeviceImpl * OIDNDevice
Definition oidn.h:110
OIDNFlags OIDNExternalSemaphoreTypeFlags
Definition oidn.h:416
OIDN_API int oidnGetPhysicalDeviceInt(int physicalDeviceID, const char *name)
OIDN_API_NAMESPACE_BEGIN typedef unsigned int OIDNFlags
Definition oidn.h:47
@ OIDN_ERROR_UNKNOWN
Definition oidn.h:98
@ OIDN_ERROR_UNSUPPORTED_HARDWARE
Definition oidn.h:102
@ OIDN_ERROR_INVALID_OPERATION
Definition oidn.h:100
@ OIDN_ERROR_CANCELLED
Definition oidn.h:103
@ OIDN_ERROR_NONE
Definition oidn.h:97
@ OIDN_ERROR_OUT_OF_MEMORY
Definition oidn.h:101
@ OIDN_ERROR_INVALID_ARGUMENT
Definition oidn.h:99
OIDN_API OIDNSemaphore oidnNewSharedSemaphoreFromFD(OIDNDevice device, OIDNExternalSemaphoreTypeFlags fdType, int fd)
OIDN_API void oidnSyncDevice(OIDNDevice device)
OIDN_API void oidnSetFilterBool(OIDNFilter filter, const char *name, bool value)
OIDN_API void oidnReadBuffer(OIDNBuffer buffer, size_t byteOffset, size_t byteSize, void *dstHostPtr)
OIDN_API void oidnSetFilterProgressMonitorFunction(OIDNFilter filter, OIDNProgressMonitorFunction func, void *userPtr)
OIDN_API void oidnSignalSemaphoresAsync(OIDNDevice device, const OIDNSemaphore *semaphores, const uint64_t *values, int numSemaphores)
void * MTLDevice_id
Definition oidn.h:40
OIDN_API int oidnGetFilterInt(OIDNFilter filter, const char *name)
OIDN_API void oidnSetDeviceBool(OIDNDevice device, const char *name, bool value)
OIDN_API void oidnRetainSemaphore(OIDNSemaphore semaphore)
OIDN_API OIDNDevice oidnNewDeviceByID(int physicalDeviceID)
OIDN_API void oidnUnsetFilterData(OIDNFilter filter, const char *name)
bool(* OIDNProgressMonitorFunction)(void *userPtr, double n)
Definition oidn.h:467
OIDNFlags OIDNExternalMemoryTypeFlags
Definition oidn.h:319
OIDNStorage
Definition oidn.h:260
@ OIDN_STORAGE_HOST
Definition oidn.h:264
@ OIDN_STORAGE_MANAGED
Definition oidn.h:271
@ OIDN_STORAGE_DEVICE
Definition oidn.h:267
@ OIDN_STORAGE_UNDEFINED
Definition oidn.h:261
OIDN_API bool oidnIsMetalDeviceSupported(MTLDevice_id device)
OIDN_API void oidnWaitSemaphoresAsync(OIDNDevice device, const OIDNSemaphore *semaphores, const uint64_t *values, const uint32_t *timeoutsMs, int numSemaphores)
OIDN_API int oidnGetNumPhysicalDevices()
OIDN_API void oidnUnsetFilterImage(OIDNFilter filter, const char *name)
OIDN_API size_t oidnGetBufferSize(OIDNBuffer buffer)
#define OIDN_LUID_SIZE
Definition oidn.h:54
struct OIDNSemaphoreImpl * OIDNSemaphore
Definition oidn.h:419
OIDN_API OIDNBuffer oidnNewSharedBufferFromFD(OIDNDevice device, OIDNExternalMemoryTypeFlags fdType, int fd, size_t byteSize)
OIDN_API float oidnGetFilterFloat(OIDNFilter filter, const char *name)
OIDN_API void oidnSetFilterInt(OIDNFilter filter, const char *name, int value)
OIDN_API void oidnSetSharedFilterImage(OIDNFilter filter, const char *name, void *devPtr, OIDNFormat format, size_t width, size_t height, size_t byteOffset, size_t pixelByteStride, size_t rowByteStride)
OIDN_API OIDNDevice oidnNewDeviceByPCIAddress(int pciDomain, int pciBus, int pciDevice, int pciFunction)
OIDN_API OIDNBuffer oidnNewSharedBuffer(OIDNDevice device, void *devPtr, size_t byteSize)
OIDN_API OIDNBuffer oidnNewSharedBufferFromMetal(OIDNDevice device, MTLBuffer_id buffer)
OIDN_API void oidnCommitFilter(OIDNFilter filter)
OIDN_API OIDNDevice oidnNewDevice(OIDNDeviceType type)
OIDN_API bool oidnIsHIPDeviceSupported(int deviceID)
unsigned int oidnGetPhysicalDeviceUInt(int physicalDeviceID, const char *name)
Definition oidn.h:66
OIDNDeviceType
Definition oidn.h:84
@ OIDN_DEVICE_TYPE_CPU
Definition oidn.h:87
@ OIDN_DEVICE_TYPE_SYCL
Definition oidn.h:88
@ OIDN_DEVICE_TYPE_CUDA
Definition oidn.h:89
@ OIDN_DEVICE_TYPE_METAL
Definition oidn.h:91
@ OIDN_DEVICE_TYPE_HIP
Definition oidn.h:90
@ OIDN_DEVICE_TYPE_DEFAULT
Definition oidn.h:85
OIDN_API void oidnCommitDevice(OIDNDevice device)
struct OIDNFilterImpl * OIDNFilter
Definition oidn.h:470
OIDN_API void oidnWriteBufferAsync(OIDNBuffer buffer, size_t byteOffset, size_t byteSize, const void *srcHostPtr)
OIDN_API OIDNBuffer oidnNewBuffer(OIDNDevice device, size_t byteSize)
OIDN_API OIDNBuffer oidnNewBufferWithStorage(OIDNDevice device, size_t byteSize, OIDNStorage storage)
OIDN_API void oidnSetFilterFloat(OIDNFilter filter, const char *name, float value)
#define OIDN_UUID_SIZE
Definition oidn.h:53
OIDN_API OIDNStorage oidnGetBufferStorage(OIDNBuffer buffer)
OIDNFormat
Definition oidn.h:242
@ OIDN_FORMAT_FLOAT
Definition oidn.h:246
@ OIDN_FORMAT_FLOAT4
Definition oidn.h:249
@ OIDN_FORMAT_HALF
Definition oidn.h:252
@ OIDN_FORMAT_HALF4
Definition oidn.h:255
@ OIDN_FORMAT_UNDEFINED
Definition oidn.h:243
@ OIDN_FORMAT_FLOAT3
Definition oidn.h:248
@ OIDN_FORMAT_HALF2
Definition oidn.h:253
@ OIDN_FORMAT_FLOAT2
Definition oidn.h:247
@ OIDN_FORMAT_HALF3
Definition oidn.h:254
OIDN_API void oidnReleaseBuffer(OIDNBuffer buffer)
OIDN_API void oidnSetFilterImage(OIDNFilter filter, const char *name, OIDNBuffer buffer, OIDNFormat format, size_t width, size_t height, size_t byteOffset, size_t pixelByteStride, size_t rowByteStride)
OIDN_API OIDNDevice oidnNewDeviceByUUID(const void *uuid)
OIDN_API bool oidnGetPhysicalDeviceBool(int physicalDeviceID, const char *name)
OIDN_API void oidnExecuteFilter(OIDNFilter filter)
OIDN_API const void * oidnGetPhysicalDeviceData(int physicalDeviceID, const char *name, size_t *byteSize)
OIDN_API void oidnSetSharedFilterData(OIDNFilter filter, const char *name, void *hostPtr, size_t byteSize)
OIDN_API void oidnWriteBuffer(OIDNBuffer buffer, size_t byteOffset, size_t byteSize, const void *srcHostPtr)
OIDN_API void oidnRetainFilter(OIDNFilter filter)
OIDN_API void oidnUpdateFilterData(OIDNFilter filter, const char *name)
struct CUstream_st * cudaStream_t
Definition oidn.h:28
OIDN_API bool oidnGetFilterBool(OIDNFilter filter, const char *name)
OIDN_API bool oidnIsCUDADeviceSupported(int deviceID)
OIDN_API void * oidnGetBufferData(OIDNBuffer buffer)
void * MTLCommandQueue_id
Definition oidn.h:41
void(* OIDNErrorFunction)(void *userPtr, OIDNError code, const char *message)
Definition oidn.h:107
OIDN_API OIDNSemaphore oidnNewSharedSemaphoreFromWin32Handle(OIDNDevice device, OIDNExternalSemaphoreTypeFlags handleType, void *handle, const void *name)
OIDN_API void oidnReleaseDevice(OIDNDevice device)
OIDN_API void oidnRetainBuffer(OIDNBuffer buffer)
OIDN_API void oidnReleaseSemaphore(OIDNSemaphore semaphore)
OIDN_API void oidnSetDeviceErrorFunction(OIDNDevice device, OIDNErrorFunction func, void *userPtr)
@ OIDN_EXTERNAL_MEMORY_TYPE_FLAG_NONE
Definition oidn.h:277
@ OIDN_EXTERNAL_MEMORY_TYPE_FLAG_D3D12_HEAP
Definition oidn.h:308
@ OIDN_EXTERNAL_MEMORY_TYPE_FLAG_OPAQUE_WIN32_KMT
Definition oidn.h:289
@ OIDN_EXTERNAL_MEMORY_TYPE_FLAG_D3D12_RESOURCE
Definition oidn.h:312
@ OIDN_EXTERNAL_MEMORY_TYPE_FLAG_D3D11_RESOURCE_KMT
Definition oidn.h:304
@ OIDN_EXTERNAL_MEMORY_TYPE_FLAG_DMA_BUF
Definition oidn.h:283
@ OIDN_EXTERNAL_MEMORY_TYPE_FLAG_OPAQUE_FD
Definition oidn.h:280
@ OIDN_EXTERNAL_MEMORY_TYPE_FLAG_DEDICATED
Definition oidn.h:316
@ OIDN_EXTERNAL_MEMORY_TYPE_FLAG_OPAQUE_WIN32
Definition oidn.h:286
@ OIDN_EXTERNAL_MEMORY_TYPE_FLAG_D3D11_TEXTURE
Definition oidn.h:293
@ OIDN_EXTERNAL_MEMORY_TYPE_FLAG_D3D11_TEXTURE_KMT
Definition oidn.h:297
@ OIDN_EXTERNAL_MEMORY_TYPE_FLAG_D3D11_RESOURCE
Definition oidn.h:300
void oidnSetDeviceUInt(OIDNDevice device, const char *name, unsigned int value)
Definition oidn.h:191
OIDN_API int oidnGetDeviceInt(OIDNDevice device, const char *name)
bool isCUDADeviceSupported(int deviceID)
Definition oidn.hpp:1054
constexpr Flags< FlagT > operator^(FlagT a, const Flags< FlagT > &b) noexcept
Definition oidn.hpp:88
ExternalMemoryTypeFlag
Definition oidn.hpp:151
@ D3D11Resource
Definition oidn.hpp:176
@ OpaqueWin32KMT
Definition oidn.hpp:164
@ DMABuf
Definition oidn.hpp:158
@ D3D12Heap
Definition oidn.hpp:184
@ OpaqueWin32
Definition oidn.hpp:161
@ None
Definition oidn.hpp:152
@ OpaqueFD
Definition oidn.hpp:155
@ D3D11TextureKMT
Definition oidn.hpp:172
@ D3D11ResourceKMT
Definition oidn.hpp:180
@ D3D11Texture
Definition oidn.hpp:168
@ D3D12Resource
Definition oidn.hpp:188
@ Dedicated
Definition oidn.hpp:192
void(* ErrorFunction)(void *userPtr, Error code, const char *message)
Definition oidn.hpp:709
Error
Definition oidn.hpp:698
@ InvalidOperation
Definition oidn.hpp:702
@ InvalidArgument
Definition oidn.hpp:701
@ UnsupportedHardware
Definition oidn.hpp:704
@ Unknown
Definition oidn.hpp:700
@ Cancelled
Definition oidn.hpp:705
@ OutOfMemory
Definition oidn.hpp:703
Error getError()
Definition oidn.hpp:1027
Flags< ExternalSemaphoreTypeFlag > ExternalSemaphoreTypeFlags
Definition oidn.hpp:357
OIDNProgressMonitorFunction ProgressMonitorFunction
Definition oidn.hpp:451
DeviceRef newDevice(DeviceType type=DeviceType::Default)
Definition oidn.hpp:1072
Storage
Definition oidn.hpp:135
@ Managed
Definition oidn.hpp:146
@ Host
Definition oidn.hpp:139
@ Device
Definition oidn.hpp:142
int getNumPhysicalDevices()
Definition oidn.hpp:1213
Quality
Definition oidn.hpp:442
@ High
Definition oidn.hpp:447
@ Default
Definition oidn.hpp:443
@ Balanced
Definition oidn.hpp:446
@ Fast
Definition oidn.hpp:445
Flags< ExternalMemoryTypeFlag > ExternalMemoryTypeFlags
Definition oidn.hpp:196
Format
Definition oidn.hpp:117
@ Float
Definition oidn.hpp:121
@ Float4
Definition oidn.hpp:124
@ Float2
Definition oidn.hpp:122
@ Half4
Definition oidn.hpp:130
@ Float3
Definition oidn.hpp:123
@ Half3
Definition oidn.hpp:129
@ Half2
Definition oidn.hpp:128
@ Half
Definition oidn.hpp:127
@ Undefined
Definition oidn.hpp:118
DeviceRef newCUDADevice(int deviceID, cudaStream_t stream)
Definition oidn.hpp:1119
bool isHIPDeviceSupported(int deviceID)
Definition oidn.hpp:1060
constexpr Flags< FlagT > operator&(FlagT a, const Flags< FlagT > &b) noexcept
Definition oidn.hpp:76
DeviceType
Definition oidn.hpp:686
@ CPU
Definition oidn.hpp:689
@ SYCL
Definition oidn.hpp:690
@ HIP
Definition oidn.hpp:692
@ Default
Definition oidn.hpp:687
@ CUDA
Definition oidn.hpp:691
@ Metal
Definition oidn.hpp:693
DeviceRef newHIPDevice(int deviceID, hipStream_t stream)
Definition oidn.hpp:1136
constexpr Flags< FlagT > operator|(FlagT a, const Flags< FlagT > &b) noexcept
Definition oidn.hpp:82
bool isMetalDeviceSupported(MTLDevice_id device)
Definition oidn.hpp:1066
bool isCPUDeviceSupported()
Definition oidn.hpp:1040
DeviceRef newMetalDevice(MTLCommandQueue_id commandQueue)
Definition oidn.hpp:1152
ExternalSemaphoreTypeFlag
Definition oidn.hpp:325
@ TimelineSemaphoreFD
Definition oidn.hpp:350
@ KeyedMutexKMT
Definition oidn.hpp:347
@ TimelineSemaphoreWin32
Definition oidn.hpp:353
@ D3D12Fence
Definition oidn.hpp:341
@ KeyedMutex
Definition oidn.hpp:344
@ D3D11Fence
Definition oidn.hpp:338
static constexpr bool value
Definition oidn.hpp:195
static constexpr bool value
Definition oidn.hpp:356
Definition oidn.hpp:24
static constexpr bool value
Definition oidn.hpp:25
Definition oidn.hpp:719
uint8_t bytes[OIDN_LUID_SIZE]
Definition oidn.hpp:727
int32_t high
Definition oidn.hpp:725
uint32_t low
Definition oidn.hpp:724
Definition oidn.hpp:713
uint8_t bytes[OIDN_UUID_SIZE]
Definition oidn.hpp:714