Blender  V3.3
optix/queue.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: Apache-2.0
2  * Copyright 2011-2022 Blender Foundation */
3 
4 #ifdef WITH_OPTIX
5 
6 # include "device/optix/queue.h"
8 
9 # include "util/time.h"
10 
11 # define __KERNEL_OPTIX__
13 
15 
16 /* CUDADeviceQueue */
17 
18 OptiXDeviceQueue::OptiXDeviceQueue(OptiXDevice *device) : CUDADeviceQueue(device)
19 {
20 }
21 
23 {
25 }
26 
27 static bool is_optix_specific_kernel(DeviceKernel kernel)
28 {
35 }
36 
37 bool OptiXDeviceQueue::enqueue(DeviceKernel kernel,
38  const int work_size,
39  DeviceKernelArguments const &args)
40 {
41  if (!is_optix_specific_kernel(kernel)) {
42  return CUDADeviceQueue::enqueue(kernel, work_size, args);
43  }
44 
45  if (cuda_device_->have_error()) {
46  return false;
47  }
48 
49  debug_enqueue(kernel, work_size);
50 
51  const CUDAContextScope scope(cuda_device_);
52 
53  OptiXDevice *const optix_device = static_cast<OptiXDevice *>(cuda_device_);
54 
55  const device_ptr sbt_data_ptr = optix_device->sbt_data.device_pointer;
56  const device_ptr launch_params_ptr = optix_device->launch_params.device_pointer;
57 
58  cuda_device_assert(
59  cuda_device_,
60  cuMemcpyHtoDAsync(launch_params_ptr + offsetof(KernelParamsOptiX, path_index_array),
61  args.values[0], // &d_path_index
62  sizeof(device_ptr),
63  cuda_stream_));
64 
68  cuda_device_assert(
69  cuda_device_,
70  cuMemcpyHtoDAsync(launch_params_ptr + offsetof(KernelParamsOptiX, render_buffer),
71  args.values[1], // &d_render_buffer
72  sizeof(device_ptr),
73  cuda_stream_));
74  }
75 
76  cuda_device_assert(cuda_device_, cuStreamSynchronize(cuda_stream_));
77 
78  OptixPipeline pipeline = nullptr;
79  OptixShaderBindingTable sbt_params = {};
80 
81  switch (kernel) {
83  pipeline = optix_device->pipelines[PIP_SHADE_RAYTRACE];
84  sbt_params.raygenRecord = sbt_data_ptr + PG_RGEN_SHADE_SURFACE_RAYTRACE * sizeof(SbtRecord);
85  break;
87  pipeline = optix_device->pipelines[PIP_SHADE_MNEE];
88  sbt_params.raygenRecord = sbt_data_ptr + PG_RGEN_SHADE_SURFACE_MNEE * sizeof(SbtRecord);
89  break;
91  pipeline = optix_device->pipelines[PIP_INTERSECT];
92  sbt_params.raygenRecord = sbt_data_ptr + PG_RGEN_INTERSECT_CLOSEST * sizeof(SbtRecord);
93  break;
95  pipeline = optix_device->pipelines[PIP_INTERSECT];
96  sbt_params.raygenRecord = sbt_data_ptr + PG_RGEN_INTERSECT_SHADOW * sizeof(SbtRecord);
97  break;
99  pipeline = optix_device->pipelines[PIP_INTERSECT];
100  sbt_params.raygenRecord = sbt_data_ptr + PG_RGEN_INTERSECT_SUBSURFACE * sizeof(SbtRecord);
101  break;
103  pipeline = optix_device->pipelines[PIP_INTERSECT];
104  sbt_params.raygenRecord = sbt_data_ptr + PG_RGEN_INTERSECT_VOLUME_STACK * sizeof(SbtRecord);
105  break;
106 
107  default:
108  LOG(ERROR) << "Invalid kernel " << device_kernel_as_string(kernel)
109  << " is attempted to be enqueued.";
110  return false;
111  }
112 
113  sbt_params.missRecordBase = sbt_data_ptr + MISS_PROGRAM_GROUP_OFFSET * sizeof(SbtRecord);
114  sbt_params.missRecordStrideInBytes = sizeof(SbtRecord);
115  sbt_params.missRecordCount = NUM_MIS_PROGRAM_GROUPS;
116  sbt_params.hitgroupRecordBase = sbt_data_ptr + HIT_PROGAM_GROUP_OFFSET * sizeof(SbtRecord);
117  sbt_params.hitgroupRecordStrideInBytes = sizeof(SbtRecord);
118  sbt_params.hitgroupRecordCount = NUM_HIT_PROGRAM_GROUPS;
119  sbt_params.callablesRecordBase = sbt_data_ptr + CALLABLE_PROGRAM_GROUPS_BASE * sizeof(SbtRecord);
120  sbt_params.callablesRecordCount = NUM_CALLABLE_PROGRAM_GROUPS;
121  sbt_params.callablesRecordStrideInBytes = sizeof(SbtRecord);
122 
123  /* Launch the ray generation program. */
124  optix_device_assert(optix_device,
125  optixLaunch(pipeline,
126  cuda_stream_,
127  launch_params_ptr,
128  optix_device->launch_params.data_elements,
129  &sbt_params,
130  work_size,
131  1,
132  1));
133 
134  return !(optix_device->have_error());
135 }
136 
138 
139 #endif /* WITH_OPTIX */
#define CCL_NAMESPACE_END
Definition: cuda/compat.h:9
CCL_NAMESPACE_BEGIN const char * device_kernel_as_string(DeviceKernel kernel)
SyclQueue void void size_t num_bytes SyclQueue void const char void *memory_device_pointer KernelContext int kernel
static struct ImBuf * init_execution(const SeqRenderData *context, ImBuf *ibuf1, ImBuf *ibuf2, ImBuf *ibuf3)
Definition: effects.c:3519
ccl_gpu_kernel_postfix ccl_global const int ccl_global float const int work_size
ccl_gpu_kernel_postfix ccl_global const int * path_index_array
ccl_gpu_kernel_postfix ccl_global KernelWorkTile const int ccl_global float * render_buffer
DeviceKernel
@ DEVICE_KERNEL_INTEGRATOR_INTERSECT_SUBSURFACE
@ DEVICE_KERNEL_INTEGRATOR_INTERSECT_VOLUME_STACK
@ DEVICE_KERNEL_INTEGRATOR_SHADE_SURFACE_RAYTRACE
@ DEVICE_KERNEL_INTEGRATOR_SHADE_SURFACE_MNEE
@ DEVICE_KERNEL_INTEGRATOR_INTERSECT_SHADOW
@ DEVICE_KERNEL_INTEGRATOR_INTERSECT_CLOSEST
#define LOG(severity)
Definition: log.h:36
void * values[MAX_ARGS]
Definition: device/queue.h:35
uint64_t device_ptr
Definition: util/types.h:43