Blender V5.3
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
31bool device_optix_init(bool *r_meets_driver_requirement)
32{
33 if (r_meets_driver_requirement) {
34 *r_meets_driver_requirement = true;
35 }
36#ifdef WITH_OPTIX
37 if (OPTIX_FUNCTION_TABLE_SYMBOL.optixDeviceContextCreate != nullptr) {
38 /* Already initialized function table. */
39 return true;
40 }
41
42 /* Need to initialize CUDA as well. */
43 if (!device_cuda_init()) {
44 return false;
45 }
46
47 const OptixResult result = optixInit();
48
49 if (result == OPTIX_ERROR_UNSUPPORTED_ABI_VERSION) {
50 LOG_WARNING << "OptiX initialization failed because the installed NVIDIA driver is too old. "
51 "Please update to the latest driver first!";
52 if (r_meets_driver_requirement) {
53 *r_meets_driver_requirement = false;
54 }
55 return false;
56 }
57 if (result != OPTIX_SUCCESS) {
58 LOG_WARNING << "OptiX initialization failed with error code " << (unsigned int)result;
59 return false;
60 }
61
62 /* Loaded OptiX successfully! */
63 return true;
64#else
65 return false;
66#endif
67}
68
69void device_optix_info(const vector<DeviceInfo> &cuda_devices, vector<DeviceInfo> &devices)
70{
71#ifdef WITH_OPTIX
72 devices.reserve(cuda_devices.size());
73
74 /* Simply add all supported CUDA devices as OptiX devices again. */
75 for (DeviceInfo info : cuda_devices) {
76 assert(info.type == DEVICE_CUDA);
77
78 int major;
79 cuDeviceGetAttribute(&major, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR, info.num);
80 if (major < 5) {
81 /* Only Maxwell and up are supported by OptiX. */
82 continue;
83 }
84
85 info.type = DEVICE_OPTIX;
86 info.id += "_OptiX";
87
88 info.use_hardware_raytracing = true;
89
90# if defined(WITH_OSL) && defined(OSL_USE_OPTIX) && \
91 (OSL_VERSION_MINOR >= 13 || OSL_VERSION_MAJOR > 1)
92 info.has_osl = true;
93# endif
94 info.denoisers |= DENOISER_OPTIX;
95# if defined(WITH_OPENIMAGEDENOISE)
96# if OIDN_VERSION >= 20300
97 if (oidnIsCUDADeviceSupported(info.num)) {
98# else
99 if (OIDNDenoiserGPU::is_device_supported(info)) {
100# endif
101 info.denoisers |= DENOISER_OPENIMAGEDENOISE;
102 }
103# endif
104
105 devices.push_back(info);
106 }
107#else
108 (void)cuda_devices;
109 (void)devices;
110#endif
111}
112
114 Stats &stats,
115 Profiler &profiler,
116 bool headless)
117{
118#ifdef WITH_OPTIX
119 return make_unique<OptiXDevice>(info, stats, profiler, headless);
120#else
121 (void)info;
122 (void)stats;
123 (void)profiler;
124 (void)headless;
125
126 LOG_FATAL << "Request to create OptiX device without compiled-in support. Should never happen.";
127
128 return nullptr;
129#endif
130}
131
@ 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(bool *r_meets_driver_requirement)
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