Blender  V2.93
kernel_split_data_types.h
Go to the documentation of this file.
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 #ifndef __KERNEL_SPLIT_DATA_TYPES_H__
18 #define __KERNEL_SPLIT_DATA_TYPES_H__
19 
21 
22 /* parameters used by the split kernels, we use a single struct to avoid passing these to each
23  * kernel */
24 
25 typedef struct SplitParams {
28 
29  ccl_global unsigned int *work_pools;
30 
34 
35  /* Place for storing sd->flag. AMD GPU OpenCL compiler workaround */
38 
39 /* Global memory variables [porting]; These memory is used for
40  * co-operation between different kernels; Data written by one
41  * kernel will be available to another kernel via this global
42  * memory.
43  */
44 
45 /* SPLIT_DATA_ENTRY(type, name, num) */
46 
47 #ifdef __BRANCHED_PATH__
48 
49 typedef ccl_global struct SplitBranchedState {
50  /* various state that must be kept and restored after an indirect loop */
51  PathState path_state;
52  float3 throughput;
53  Ray ray;
54 
55  Intersection isect;
56 
57  char ray_state;
58 
59  /* indirect loop state */
60  int next_closure;
61  int next_sample;
62 
63 # ifdef __SUBSURFACE__
64  int ss_next_closure;
65  int ss_next_sample;
66  int next_hit;
67  int num_hits;
68 
69  uint lcg_state;
70  LocalIntersection ss_isect;
71 # endif /*__SUBSURFACE__ */
72 
73  int shared_sample_count; /* number of branched samples shared with other threads */
74  int original_ray; /* index of original ray when sharing branched samples */
75  bool waiting_on_shared_samples;
76 } SplitBranchedState;
77 
78 # define SPLIT_DATA_BRANCHED_ENTRIES \
79  SPLIT_DATA_ENTRY(SplitBranchedState, branched_state, 1) \
80  SPLIT_DATA_ENTRY(ShaderData, _branched_state_sd, 0)
81 #else
82 # define SPLIT_DATA_BRANCHED_ENTRIES
83 #endif /* __BRANCHED_PATH__ */
84 
85 #ifdef __SUBSURFACE__
86 # define SPLIT_DATA_SUBSURFACE_ENTRIES \
87  SPLIT_DATA_ENTRY(ccl_global SubsurfaceIndirectRays, ss_rays, 1)
88 #else
89 # define SPLIT_DATA_SUBSURFACE_ENTRIES
90 #endif /* __SUBSURFACE__ */
91 
92 #ifdef __VOLUME__
93 # define SPLIT_DATA_VOLUME_ENTRIES SPLIT_DATA_ENTRY(ccl_global PathState, state_shadow, 1)
94 #else
95 # define SPLIT_DATA_VOLUME_ENTRIES
96 #endif /* __VOLUME__ */
97 
98 #define SPLIT_DATA_ENTRIES \
99  SPLIT_DATA_ENTRY(ccl_global float3, throughput, 1) \
100  SPLIT_DATA_ENTRY(PathRadiance, path_radiance, 1) \
101  SPLIT_DATA_ENTRY(ccl_global Ray, ray, 1) \
102  SPLIT_DATA_ENTRY(ccl_global PathState, path_state, 1) \
103  SPLIT_DATA_ENTRY(ccl_global Intersection, isect, 1) \
104  SPLIT_DATA_ENTRY(ccl_global BsdfEval, bsdf_eval, 1) \
105  SPLIT_DATA_ENTRY(ccl_global int, is_lamp, 1) \
106  SPLIT_DATA_ENTRY(ccl_global Ray, light_ray, 1) \
107  SPLIT_DATA_ENTRY( \
108  ccl_global int, queue_data, (NUM_QUEUES * 2)) /* TODO(mai): this is too large? */ \
109  SPLIT_DATA_ENTRY(ccl_global uint, buffer_offset, 1) \
110  SPLIT_DATA_ENTRY(ShaderDataTinyStorage, sd_DL_shadow, 1) \
111  SPLIT_DATA_SUBSURFACE_ENTRIES \
112  SPLIT_DATA_VOLUME_ENTRIES \
113  SPLIT_DATA_BRANCHED_ENTRIES \
114  SPLIT_DATA_ENTRY(ShaderData, _sd, 0)
115 
116 /* Entries to be copied to inactive rays when sharing branched samples
117  * (TODO: which are actually needed?) */
118 #define SPLIT_DATA_ENTRIES_BRANCHED_SHARED \
119  SPLIT_DATA_ENTRY(ccl_global float3, throughput, 1) \
120  SPLIT_DATA_ENTRY(PathRadiance, path_radiance, 1) \
121  SPLIT_DATA_ENTRY(ccl_global Ray, ray, 1) \
122  SPLIT_DATA_ENTRY(ccl_global PathState, path_state, 1) \
123  SPLIT_DATA_ENTRY(ccl_global Intersection, isect, 1) \
124  SPLIT_DATA_ENTRY(ccl_global BsdfEval, bsdf_eval, 1) \
125  SPLIT_DATA_ENTRY(ccl_global int, is_lamp, 1) \
126  SPLIT_DATA_ENTRY(ccl_global Ray, light_ray, 1) \
127  SPLIT_DATA_ENTRY(ShaderDataTinyStorage, sd_DL_shadow, 1) \
128  SPLIT_DATA_SUBSURFACE_ENTRIES \
129  SPLIT_DATA_VOLUME_ENTRIES \
130  SPLIT_DATA_BRANCHED_ENTRIES \
131  SPLIT_DATA_ENTRY(ShaderData, _sd, 0)
132 
133 /* struct that holds pointers to data in the shared state buffer */
134 typedef struct SplitData {
135 #define SPLIT_DATA_ENTRY(type, name, num) type *name;
137 #undef SPLIT_DATA_ENTRY
138 
139  /* this is actually in a separate buffer from the rest of the split state data (so it can be read
140  * back from the host easily) but is still used the same as the other data so we have it here in
141  * this struct as well
142  */
145 
146 #ifndef __KERNEL_CUDA__
147 # define kernel_split_state (kg->split_data)
148 # define kernel_split_params (kg->split_param_data)
149 #else
150 __device__ SplitData __split_data;
151 # define kernel_split_state (__split_data)
152 __device__ SplitParams __split_param_data;
153 # define kernel_split_params (__split_param_data)
154 #endif /* __KERNEL_CUDA__ */
155 
156 #define kernel_split_sd(sd, ray_index) \
157  ((ShaderData *)(((ccl_global char *)kernel_split_state._##sd) + \
158  (sizeof(ShaderData) + \
159  sizeof(ShaderClosure) * (kernel_data.integrator.max_closures - 1)) * \
160  (ray_index)))
161 
162 /* Local storage for queue_enqueue kernel. */
163 typedef struct QueueEnqueueLocals {
166 
167 /* Local storage for holdout_emission_blurring_pathtermination_ao kernel. */
168 typedef struct BackgroundAOLocals {
172 
173 typedef struct ShaderSortLocals {
177 
179 
180 #endif /* __KERNEL_SPLIT_DATA_TYPES_H__ */
unsigned int uint
Definition: BLI_sys_types.h:83
unsigned short ushort
Definition: BLI_sys_types.h:84
#define ccl_global
#define CCL_NAMESPACE_END
struct QueueEnqueueLocals QueueEnqueueLocals
struct ShaderSortLocals ShaderSortLocals
struct BackgroundAOLocals BackgroundAOLocals
struct SplitData SplitData
#define SPLIT_DATA_ENTRIES
CCL_NAMESPACE_BEGIN struct SplitParams SplitParams
__kernel void ccl_constant KernelData ccl_global void ccl_global char * ray_state
#define SHADER_SORT_BLOCK_SIZE
Definition: kernel_types.h:75
ushort local_index[SHADER_SORT_BLOCK_SIZE]
uint local_value[SHADER_SORT_BLOCK_SIZE]
SPLIT_DATA_ENTRIES ccl_global char * ray_state
ccl_global unsigned int * work_pools
ccl_global char * use_queues_flag
ccl_global int * queue_index