Blender V5.0
device/optix/device.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2019 NVIDIA Corporation
2 * SPDX-FileCopyrightText: 2019-2022 Blender Foundation
3 *
4 * SPDX-License-Identifier: Apache-2.0 */
5
8#include "device/device.h"
9
10#ifdef WITH_OSL
11# include <OSL/oslconfig.h>
12# include <OSL/oslversion.h>
13#endif
14
15#ifdef WITH_OPTIX
17
18# include "integrator/denoiser_oidn_gpu.h" // IWYU pragma: keep
19
20# include <optix_function_table_definition.h>
21#endif
22
23#include "util/log.h"
24
25#ifndef OPTIX_FUNCTION_TABLE_SYMBOL
26# define OPTIX_FUNCTION_TABLE_SYMBOL g_optixFunctionTable
27#endif
28
30
32{
33#ifdef WITH_OPTIX
34 if (OPTIX_FUNCTION_TABLE_SYMBOL.optixDeviceContextCreate != nullptr) {
35 /* Already initialized function table. */
36 return true;
37 }
38
39 /* Need to initialize CUDA as well. */
40 if (!device_cuda_init()) {
41 return false;
42 }
43
44 const OptixResult result = optixInit();
45
46 if (result == OPTIX_ERROR_UNSUPPORTED_ABI_VERSION) {
47 LOG_WARNING << "OptiX initialization failed because the installed NVIDIA driver is too old. "
48 "Please update to the latest driver first!";
49 return false;
50 }
51 if (result != OPTIX_SUCCESS) {
52 LOG_WARNING << "OptiX initialization failed with error code " << (unsigned int)result;
53 return false;
54 }
55
56 /* Loaded OptiX successfully! */
57 return true;
58#else
59 return false;
60#endif
61}
62
63void device_optix_info(const vector<DeviceInfo> &cuda_devices, vector<DeviceInfo> &devices)
64{
65#ifdef WITH_OPTIX
66 devices.reserve(cuda_devices.size());
67
68 /* Simply add all supported CUDA devices as OptiX devices again. */
69 for (DeviceInfo info : cuda_devices) {
70 assert(info.type == DEVICE_CUDA);
71
72 int major;
73 cuDeviceGetAttribute(&major, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR, info.num);
74 if (major < 5) {
75 /* Only Maxwell and up are supported by OptiX. */
76 continue;
77 }
78
79 info.type = DEVICE_OPTIX;
80 info.id += "_OptiX";
81# if defined(WITH_OSL) && defined(OSL_USE_OPTIX) && \
82 (OSL_VERSION_MINOR >= 13 || OSL_VERSION_MAJOR > 1)
83 info.has_osl = true;
84# endif
85 info.denoisers |= DENOISER_OPTIX;
86# if defined(WITH_OPENIMAGEDENOISE)
87# if OIDN_VERSION >= 20300
88 if (oidnIsCUDADeviceSupported(info.num)) {
89# else
90 if (OIDNDenoiserGPU::is_device_supported(info)) {
91# endif
92 info.denoisers |= DENOISER_OPENIMAGEDENOISE;
93 }
94# endif
95
96 devices.push_back(info);
97 }
98#else
99 (void)cuda_devices;
100 (void)devices;
101#endif
102}
103
105 Stats &stats,
106 Profiler &profiler,
107 bool headless)
108{
109#ifdef WITH_OPTIX
110 return make_unique<OptiXDevice>(info, stats, profiler, headless);
111#else
112 (void)info;
113 (void)stats;
114 (void)profiler;
115 (void)headless;
116
117 LOG_FATAL << "Request to create OptiX device without compiled-in support. Should never happen.";
118
119 return nullptr;
120#endif
121}
122
@ DENOISER_OPTIX
Definition denoise.h:12
@ DENOISER_OPENIMAGEDENOISE
Definition denoise.h:13
#define CCL_NAMESPACE_END
CCL_NAMESPACE_BEGIN bool device_cuda_init()
@ DEVICE_CUDA
@ DEVICE_OPTIX
CCL_NAMESPACE_BEGIN bool device_optix_init()
void device_optix_info(const vector< DeviceInfo > &cuda_devices, vector< DeviceInfo > &devices)
#define OPTIX_FUNCTION_TABLE_SYMBOL
unique_ptr< Device > device_optix_create(const DeviceInfo &info, Stats &stats, Profiler &profiler, bool headless)
#define assert(assertion)
#define LOG_FATAL
Definition log.h:99
#define LOG_WARNING
Definition log.h:103