Cycles: Split path initialization into own kernel
[blender-staging.git] / intern / cycles / kernel / kernels / cuda / kernel_split.cu
1 /*
2  * Copyright 2011-2016 Blender Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 /* CUDA split kernel entry points */
18
19 #ifdef __CUDA_ARCH__
20
21 #define __SPLIT_KERNEL__
22
23 #include "../../kernel_compat_cuda.h"
24 #include "kernel_config.h"
25
26 #include "../../split/kernel_split_common.h"
27 #include "../../split/kernel_data_init.h"
28 #include "../../split/kernel_path_init.h"
29 #include "../../split/kernel_scene_intersect.h"
30 #include "../../split/kernel_lamp_emission.h"
31 #include "../../split/kernel_queue_enqueue.h"
32 #include "../../split/kernel_background_buffer_update.h"
33 #include "../../split/kernel_shader_eval.h"
34 #include "../../split/kernel_holdout_emission_blurring_pathtermination_ao.h"
35 #include "../../split/kernel_direct_lighting.h"
36 #include "../../split/kernel_shadow_blocked.h"
37 #include "../../split/kernel_next_iteration_setup.h"
38 #include "../../split/kernel_sum_all_radiance.h"
39
40 #include "../../kernel_film.h"
41
42 /* kernels */
43 extern "C" __global__ void
44 CUDA_LAUNCH_BOUNDS(CUDA_THREADS_BLOCK_WIDTH, CUDA_KERNEL_MAX_REGISTERS)
45 kernel_cuda_path_trace_data_init(
46         ccl_global void *split_data_buffer,
47         int num_elements,
48         ccl_global char *ray_state,
49         ccl_global uint *rng_state,
50         int start_sample,
51         int end_sample,
52         int sx, int sy, int sw, int sh, int offset, int stride,
53         ccl_global int *Queue_index,
54         int queuesize,
55         ccl_global char *use_queues_flag,
56         ccl_global unsigned int *work_pool_wgs,
57         unsigned int num_samples,
58         ccl_global float *buffer)
59 {
60         kernel_data_init(NULL,
61                          NULL,
62                          split_data_buffer,
63                          num_elements,
64                          ray_state,
65                          rng_state,
66                          start_sample,
67                          end_sample,
68                          sx, sy, sw, sh, offset, stride,
69                          Queue_index,
70                          queuesize,
71                          use_queues_flag,
72                          work_pool_wgs,
73                          num_samples,
74                          buffer);
75 }
76
77 #define DEFINE_SPLIT_KERNEL_FUNCTION(name) \
78         extern "C" __global__ void \
79         CUDA_LAUNCH_BOUNDS(CUDA_THREADS_BLOCK_WIDTH, CUDA_KERNEL_MAX_REGISTERS) \
80         kernel_cuda_##name() \
81         { \
82                 kernel_##name(NULL); \
83         }
84
85 DEFINE_SPLIT_KERNEL_FUNCTION(path_init)
86 DEFINE_SPLIT_KERNEL_FUNCTION(scene_intersect)
87 DEFINE_SPLIT_KERNEL_FUNCTION(lamp_emission)
88 DEFINE_SPLIT_KERNEL_FUNCTION(queue_enqueue)
89 DEFINE_SPLIT_KERNEL_FUNCTION(background_buffer_update)
90 DEFINE_SPLIT_KERNEL_FUNCTION(shader_eval)
91 DEFINE_SPLIT_KERNEL_FUNCTION(holdout_emission_blurring_pathtermination_ao)
92 DEFINE_SPLIT_KERNEL_FUNCTION(direct_lighting)
93 DEFINE_SPLIT_KERNEL_FUNCTION(shadow_blocked)
94 DEFINE_SPLIT_KERNEL_FUNCTION(next_iteration_setup)
95 DEFINE_SPLIT_KERNEL_FUNCTION(sum_all_radiance)
96
97 extern "C" __global__ void
98 CUDA_LAUNCH_BOUNDS(CUDA_THREADS_BLOCK_WIDTH, CUDA_KERNEL_MAX_REGISTERS)
99 kernel_cuda_convert_to_byte(uchar4 *rgba, float *buffer, float sample_scale, int sx, int sy, int sw, int sh, int offset, int stride)
100 {
101         int x = sx + blockDim.x*blockIdx.x + threadIdx.x;
102         int y = sy + blockDim.y*blockIdx.y + threadIdx.y;
103
104         if(x < sx + sw && y < sy + sh)
105                 kernel_film_convert_to_byte(NULL, rgba, buffer, sample_scale, x, y, offset, stride);
106 }
107
108 extern "C" __global__ void
109 CUDA_LAUNCH_BOUNDS(CUDA_THREADS_BLOCK_WIDTH, CUDA_KERNEL_MAX_REGISTERS)
110 kernel_cuda_convert_to_half_float(uchar4 *rgba, float *buffer, float sample_scale, int sx, int sy, int sw, int sh, int offset, int stride)
111 {
112         int x = sx + blockDim.x*blockIdx.x + threadIdx.x;
113         int y = sy + blockDim.y*blockIdx.y + threadIdx.y;
114
115         if(x < sx + sw && y < sy + sh)
116                 kernel_film_convert_to_half_float(NULL, rgba, buffer, sample_scale, x, y, offset, stride);
117 }
118
119 #endif
120