Blender V4.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
7
10
12
13#include "util/log.h"
14
15#ifdef WITH_OSL
16# include <OSL/oslconfig.h>
17# include <OSL/oslversion.h>
18#endif
19
20#ifdef WITH_OPTIX
21# include <optix_function_table_definition.h>
22#endif
23
25
27{
28#ifdef WITH_OPTIX
29 if (g_optixFunctionTable.optixDeviceContextCreate != NULL) {
30 /* Already initialized function table. */
31 return true;
32 }
33
34 /* Need to initialize CUDA as well. */
35 if (!device_cuda_init()) {
36 return false;
37 }
38
39 const OptixResult result = optixInit();
40
41 if (result == OPTIX_ERROR_UNSUPPORTED_ABI_VERSION) {
42 VLOG_WARNING << "OptiX initialization failed because the installed NVIDIA driver is too old. "
43 "Please update to the latest driver first!";
44 return false;
45 }
46 else if (result != OPTIX_SUCCESS) {
47 VLOG_WARNING << "OptiX initialization failed with error code " << (unsigned int)result;
48 return false;
49 }
50
51 /* Loaded OptiX successfully! */
52 return true;
53#else
54 return false;
55#endif
56}
57
58void device_optix_info(const vector<DeviceInfo> &cuda_devices, vector<DeviceInfo> &devices)
59{
60#ifdef WITH_OPTIX
61 devices.reserve(cuda_devices.size());
62
63 /* Simply add all supported CUDA devices as OptiX devices again. */
64 for (DeviceInfo info : cuda_devices) {
65 assert(info.type == DEVICE_CUDA);
66
67 int major;
68 cuDeviceGetAttribute(&major, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR, info.num);
69 if (major < 5) {
70 /* Only Maxwell and up are supported by OptiX. */
71 continue;
72 }
73
74 info.type = DEVICE_OPTIX;
75 info.id += "_OptiX";
76# if defined(WITH_OSL) && defined(OSL_USE_OPTIX) && \
77 (OSL_VERSION_MINOR >= 13 || OSL_VERSION_MAJOR > 1)
78 info.has_osl = true;
79# endif
80 info.denoisers |= DENOISER_OPTIX;
81# if defined(WITH_OPENIMAGEDENOISE)
82# if OIDN_VERSION >= 20300
83 if (oidnIsCUDADeviceSupported(info.num)) {
84# else
85 if (OIDNDenoiserGPU::is_device_supported(info)) {
86# endif
87 info.denoisers |= DENOISER_OPENIMAGEDENOISE;
88 }
89# endif
90
91 devices.push_back(info);
92 }
93#else
94 (void)cuda_devices;
95 (void)devices;
96#endif
97}
98
100 Stats &stats,
101 Profiler &profiler,
102 bool headless)
103{
104#ifdef WITH_OPTIX
105 return new OptiXDevice(info, stats, profiler, headless);
106#else
107 (void)info;
108 (void)stats;
109 (void)profiler;
110 (void)headless;
111
112 LOG(FATAL) << "Request to create OptiX device without compiled-in support. Should never happen.";
113
114 return nullptr;
115#endif
116}
117
@ DENOISER_OPTIX
Definition denoise.h:14
@ DENOISER_OPENIMAGEDENOISE
Definition denoise.h:15
#define CCL_NAMESPACE_END
CCL_NAMESPACE_BEGIN bool device_cuda_init()
@ DEVICE_CUDA
@ DEVICE_OPTIX
#define NULL
CCL_NAMESPACE_BEGIN bool device_optix_init()
void device_optix_info(const vector< DeviceInfo > &cuda_devices, vector< DeviceInfo > &devices)
Device * device_optix_create(const DeviceInfo &info, Stats &stats, Profiler &profiler, bool headless)
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
#define VLOG_WARNING
Definition log.h:70
#define LOG(severity)
Definition log.h:33