Cycles: Calculate size of split state buffer kernel side
[blender.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
39 #include "../../kernel_film.h"
40
41 /* kernels */
42 extern "C" __global__ void
43 CUDA_LAUNCH_BOUNDS(CUDA_THREADS_BLOCK_WIDTH, CUDA_KERNEL_MAX_REGISTERS)
44 kernel_cuda_state_buffer_size(uint num_threads, uint *size)
45 {
46         *size = split_data_buffer_size(NULL, num_threads);
47 }
48
49 extern "C" __global__ void
50 CUDA_LAUNCH_BOUNDS(CUDA_THREADS_BLOCK_WIDTH, CUDA_KERNEL_MAX_REGISTERS)
51 kernel_cuda_path_trace_data_init(
52         ccl_global void *split_data_buffer,
53         int num_elements,
54         ccl_global char *ray_state,
55         ccl_global uint *rng_state,
56         int start_sample,
57         int end_sample,
58         int sx, int sy, int sw, int sh, int offset, int stride,
59         ccl_global int *Queue_index,
60         int queuesize,
61         ccl_global char *use_queues_flag,
62         ccl_global unsigned int *work_pool_wgs,
63         unsigned int num_samples,
64         ccl_global float *buffer)
65 {
66         kernel_data_init(NULL,
67                          NULL,
68                          split_data_buffer,
69                          num_elements,
70                          ray_state,
71                          rng_state,
72                          start_sample,
73                          end_sample,
74                          sx, sy, sw, sh, offset, stride,
75                          Queue_index,
76                          queuesize,
77                          use_queues_flag,
78                          work_pool_wgs,
79                          num_samples,
80                          buffer);
81 }
82
83 #define DEFINE_SPLIT_KERNEL_FUNCTION(name) \
84         extern "C" __global__ void \
85         CUDA_LAUNCH_BOUNDS(CUDA_THREADS_BLOCK_WIDTH, CUDA_KERNEL_MAX_REGISTERS) \
86         kernel_cuda_##name() \
87         { \
88                 kernel_##name(NULL); \
89         }
90
91 DEFINE_SPLIT_KERNEL_FUNCTION(path_init)
92 DEFINE_SPLIT_KERNEL_FUNCTION(scene_intersect)
93 DEFINE_SPLIT_KERNEL_FUNCTION(lamp_emission)
94 DEFINE_SPLIT_KERNEL_FUNCTION(queue_enqueue)
95 DEFINE_SPLIT_KERNEL_FUNCTION(background_buffer_update)
96 DEFINE_SPLIT_KERNEL_FUNCTION(shader_eval)
97 DEFINE_SPLIT_KERNEL_FUNCTION(holdout_emission_blurring_pathtermination_ao)
98 DEFINE_SPLIT_KERNEL_FUNCTION(direct_lighting)
99 DEFINE_SPLIT_KERNEL_FUNCTION(shadow_blocked)
100 DEFINE_SPLIT_KERNEL_FUNCTION(next_iteration_setup)
101
102 extern "C" __global__ void
103 CUDA_LAUNCH_BOUNDS(CUDA_THREADS_BLOCK_WIDTH, CUDA_KERNEL_MAX_REGISTERS)
104 kernel_cuda_convert_to_byte(uchar4 *rgba, float *buffer, float sample_scale, int sx, int sy, int sw, int sh, int offset, int stride)
105 {
106         int x = sx + blockDim.x*blockIdx.x + threadIdx.x;
107         int y = sy + blockDim.y*blockIdx.y + threadIdx.y;
108
109         if(x < sx + sw && y < sy + sh)
110                 kernel_film_convert_to_byte(NULL, rgba, buffer, sample_scale, x, y, offset, stride);
111 }
112
113 extern "C" __global__ void
114 CUDA_LAUNCH_BOUNDS(CUDA_THREADS_BLOCK_WIDTH, CUDA_KERNEL_MAX_REGISTERS)
115 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)
116 {
117         int x = sx + blockDim.x*blockIdx.x + threadIdx.x;
118         int y = sy + blockDim.y*blockIdx.y + threadIdx.y;
119
120         if(x < sx + sw && y < sy + sh)
121                 kernel_film_convert_to_half_float(NULL, rgba, buffer, sample_scale, x, y, offset, stride);
122 }
123
124 #endif
125