Blender V4.3
optix/device_impl.h
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
6#pragma once
7
8#ifdef WITH_OPTIX
9
11# include "device/optix/util.h"
12# include "kernel/osl/globals.h"
13
15
16class BVHOptiX;
18
19/* List of OptiX program groups. */
20enum {
21 PG_RGEN_INTERSECT_CLOSEST,
22 PG_RGEN_INTERSECT_SHADOW,
23 PG_RGEN_INTERSECT_SUBSURFACE,
24 PG_RGEN_INTERSECT_VOLUME_STACK,
25 PG_RGEN_INTERSECT_DEDICATED_LIGHT,
26 PG_RGEN_SHADE_BACKGROUND,
27 PG_RGEN_SHADE_LIGHT,
28 PG_RGEN_SHADE_SURFACE,
29 PG_RGEN_SHADE_SURFACE_RAYTRACE,
30 PG_RGEN_SHADE_SURFACE_MNEE,
31 PG_RGEN_SHADE_VOLUME,
32 PG_RGEN_SHADE_SHADOW,
33 PG_RGEN_SHADE_DEDICATED_LIGHT,
34 PG_RGEN_EVAL_DISPLACE,
35 PG_RGEN_EVAL_BACKGROUND,
36 PG_RGEN_EVAL_CURVE_SHADOW_TRANSPARENCY,
37 PG_MISS,
38 PG_HITD, /* Default hit group. */
39 PG_HITS, /* __SHADOW_RECORD_ALL__ hit group. */
40 PG_HITL, /* __BVH_LOCAL__ hit group (only used for triangles). */
41 PG_HITV, /* __VOLUME__ hit group. */
42 PG_HITD_MOTION,
43 PG_HITS_MOTION,
44 PG_HITD_POINTCLOUD,
45 PG_HITS_POINTCLOUD,
46 PG_CALL_SVM_AO,
47 PG_CALL_SVM_BEVEL,
48 NUM_PROGRAM_GROUPS
49};
50
51static const int MISS_PROGRAM_GROUP_OFFSET = PG_MISS;
52static const int NUM_MISS_PROGRAM_GROUPS = 1;
53static const int HIT_PROGAM_GROUP_OFFSET = PG_HITD;
54static const int NUM_HIT_PROGRAM_GROUPS = 8;
55static const int CALLABLE_PROGRAM_GROUPS_BASE = PG_CALL_SVM_AO;
56static const int NUM_CALLABLE_PROGRAM_GROUPS = 2;
57
58/* List of OptiX pipelines. */
59enum { PIP_SHADE, PIP_INTERSECT, NUM_PIPELINES };
60
61/* A single shader binding table entry. */
62struct SbtRecord {
63 char header[OPTIX_SBT_RECORD_HEADER_SIZE];
64};
65
66class OptiXDevice : public CUDADevice {
67 public:
68 OptixDeviceContext context = NULL;
69
70 OptixModule optix_module = NULL; /* All necessary OptiX kernels are in one module. */
71 OptixModule builtin_modules[2] = {};
72 OptixPipeline pipelines[NUM_PIPELINES] = {};
73 OptixProgramGroup groups[NUM_PROGRAM_GROUPS] = {};
74 OptixPipelineCompileOptions pipeline_options = {};
75
78
79# ifdef WITH_OSL
80 OSLGlobals osl_globals;
81 vector<OptixModule> osl_modules;
83# endif
84
85 private:
86 OptixTraversableHandle tlas_handle = 0;
87 vector<unique_ptr<device_only_memory<char>>> delayed_free_bvh_memory;
88 thread_mutex delayed_free_bvh_mutex;
89
90 public:
91 OptiXDevice(const DeviceInfo &info, Stats &stats, Profiler &profiler, bool headless);
92 ~OptiXDevice();
93
94 BVHLayoutMask get_bvh_layout_mask(uint /*kernel_features*/) const override;
95
96 string compile_kernel_get_common_cflags(const uint kernel_features);
97
98 bool load_kernels(const uint kernel_features) override;
99
100 bool load_osl_kernels() override;
101
102 bool build_optix_bvh(BVHOptiX *bvh,
103 OptixBuildOperation operation,
104 const OptixBuildInput &build_input,
105 uint16_t num_motion_steps);
106
107 void build_bvh(BVH *bvh, Progress &progress, bool refit) override;
108
109 void release_bvh(BVH *bvh) override;
110 void free_bvh_memory_delayed();
111
112 void const_copy_to(const char *name, void *host, size_t size) override;
113
114 void update_launch_params(size_t offset, void *data, size_t data_size);
115
116 virtual unique_ptr<DeviceQueue> gpu_queue_create() override;
117
118 void *get_cpu_osl_memory() override;
119};
120
122
123#endif /* WITH_OPTIX */
unsigned int uint
void refit(btStridingMeshInterface *triangles, const btVector3 &aabbMin, const btVector3 &aabbMax)
Definition bvh/bvh.h:66
#define CCL_NAMESPACE_END
#define NULL
int BVHLayoutMask
Definition params.h:51
unsigned short uint16_t
Definition stdint.h:79
CCL_NAMESPACE_BEGIN typedef std::mutex thread_mutex
Definition thread.h:29