Blender  V2.93
kernel_buffer_update.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2015 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 
18 
19 /* This kernel takes care of rays that hit the background (sceneintersect
20  * kernel), and for the rays of state RAY_UPDATE_BUFFER it updates the ray's
21  * accumulated radiance in the output buffer. This kernel also takes care of
22  * rays that have been determined to-be-regenerated.
23  *
24  * We will empty QUEUE_HITBG_BUFF_UPDATE_TOREGEN_RAYS queue in this kernel.
25  *
26  * Typically all rays that are in state RAY_HIT_BACKGROUND, RAY_UPDATE_BUFFER
27  * will be eventually set to RAY_TO_REGENERATE state in this kernel.
28  * Finally all rays of ray_state RAY_TO_REGENERATE will be regenerated and put
29  * in queue QUEUE_ACTIVE_AND_REGENERATED_RAYS.
30  *
31  * State of queues when this kernel is called:
32  * At entry,
33  * - QUEUE_ACTIVE_AND_REGENERATED_RAYS will be filled with RAY_ACTIVE rays.
34  * - QUEUE_HITBG_BUFF_UPDATE_TOREGEN_RAYS will be filled with
35  * RAY_UPDATE_BUFFER, RAY_HIT_BACKGROUND, RAY_TO_REGENERATE rays.
36  * At exit,
37  * - QUEUE_ACTIVE_AND_REGENERATED_RAYS will be filled with RAY_ACTIVE and
38  * RAY_REGENERATED rays.
39  * - QUEUE_HITBG_BUFF_UPDATE_TOREGEN_RAYS will be empty.
40  */
41 ccl_device void kernel_buffer_update(KernelGlobals *kg,
42  ccl_local_param unsigned int *local_queue_atomics)
43 {
44  if (ccl_local_id(0) == 0 && ccl_local_id(1) == 0) {
45  *local_queue_atomics = 0;
46  }
48 
49  int ray_index = ccl_global_id(1) * ccl_global_size(0) + ccl_global_id(0);
50  if (ray_index == 0) {
51  /* We will empty this queue in this kernel. */
53  }
54  char enqueue_flag = 0;
55  ray_index = get_ray_index(kg,
56  ray_index,
58  kernel_split_state.queue_data,
59  kernel_split_params.queue_size,
60  1);
61 
62  if (ray_index != QUEUE_EMPTY_SLOT) {
63  ccl_global char *ray_state = kernel_split_state.ray_state;
64  ccl_global PathState *state = &kernel_split_state.path_state[ray_index];
65  PathRadiance *L = &kernel_split_state.path_radiance[ray_index];
66  ccl_global Ray *ray = &kernel_split_state.ray[ray_index];
67  ccl_global float3 *throughput = &kernel_split_state.throughput[ray_index];
68  bool ray_was_updated = false;
69 
70  if (IS_STATE(ray_state, ray_index, RAY_UPDATE_BUFFER)) {
71  ray_was_updated = true;
72  uint sample = state->sample;
73  uint buffer_offset = kernel_split_state.buffer_offset[ray_index];
74  ccl_global float *buffer = kernel_split_params.tile.buffer + buffer_offset;
75 
76  /* accumulate result in output buffer */
78 
80  }
81 
82  if (kernel_data.film.cryptomatte_passes) {
83  /* Make sure no thread is writing to the buffers. */
85  if (ray_was_updated && state->sample - 1 == kernel_data.integrator.aa_samples) {
86  uint buffer_offset = kernel_split_state.buffer_offset[ray_index];
87  ccl_global float *buffer = kernel_split_params.tile.buffer + buffer_offset;
88  ccl_global float *cryptomatte_buffer = buffer + kernel_data.film.pass_cryptomatte;
89  kernel_sort_id_slots(cryptomatte_buffer, 2 * kernel_data.film.cryptomatte_depth);
90  }
91  }
92 
93  if (IS_STATE(ray_state, ray_index, RAY_TO_REGENERATE)) {
94  /* We have completed current work; So get next work */
96  uint total_work_size = kernel_split_params.total_work_size;
97  uint work_index;
98 
99  if (!get_next_work(kg, work_pools, total_work_size, ray_index, &work_index)) {
100  /* If work is invalid, this means no more work is available and the thread may exit */
102  }
103 
104  if (IS_STATE(ray_state, ray_index, RAY_TO_REGENERATE)) {
106  uint x, y, sample;
107  get_work_pixel(tile, work_index, &x, &y, &sample);
108 
109  /* Store buffer offset for writing to passes. */
110  uint buffer_offset = (tile->offset + x + y * tile->stride) * kernel_data.film.pass_stride;
111  kernel_split_state.buffer_offset[ray_index] = buffer_offset;
112 
113  /* Initialize random numbers and ray. */
114  uint rng_hash;
115  kernel_path_trace_setup(kg, sample, x, y, &rng_hash, ray);
116 
117  if (ray->t != 0.0f) {
118  /* Initialize throughput, path radiance, Ray, PathState;
119  * These rays proceed with path-iteration.
120  */
121  *throughput = make_float3(1.0f, 1.0f, 1.0f);
124  AS_SHADER_DATA(&kernel_split_state.sd_DL_shadow[ray_index]),
125  state,
126  rng_hash,
127  sample,
128  ray);
129 #ifdef __SUBSURFACE__
130  kernel_path_subsurface_init_indirect(&kernel_split_state.ss_rays[ray_index]);
131 #endif
133  enqueue_flag = 1;
134  }
135  else {
137  }
138  }
139  }
140  }
141 
142  /* Enqueue RAY_REGENERATED rays into QUEUE_ACTIVE_AND_REGENERATED_RAYS;
143  * These rays will be made active during next SceneIntersectkernel.
144  */
145  enqueue_ray_index_local(ray_index,
147  enqueue_flag,
148  kernel_split_params.queue_size,
149  local_queue_atomics,
150  kernel_split_state.queue_data,
151  kernel_split_params.queue_index);
152 }
153 
unsigned int uint
Definition: BLI_sys_types.h:83
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
ccl_device_inline void path_radiance_init(KernelGlobals *kg, PathRadiance *L)
CCL_NAMESPACE_BEGIN ccl_device void kernel_buffer_update(KernelGlobals *kg, ccl_local_param unsigned int *local_queue_atomics)
#define kernel_data
#define ccl_global_id(d)
#define ccl_global_size(d)
#define ccl_local_param
#define ccl_device
ccl_device_inline uint ccl_local_id(uint d)
#define ccl_global
#define CCL_NAMESPACE_END
#define make_float3(x, y, z)
ccl_device_inline void kernel_sort_id_slots(ccl_global float *buffer, int num_slots)
ccl_device_inline void kernel_write_result(KernelGlobals *kg, ccl_global float *buffer, int sample, PathRadiance *L)
CCL_NAMESPACE_BEGIN ccl_device_inline void kernel_path_trace_setup(KernelGlobals *kg, int sample, int x, int y, uint *rng_hash, ccl_addr_space Ray *ray)
CCL_NAMESPACE_BEGIN ccl_device_inline void path_state_init(KernelGlobals *kg, ShaderData *stack_sd, ccl_addr_space PathState *state, uint rng_hash, int sample, ccl_addr_space Ray *ray)
ccl_device int get_ray_index(KernelGlobals *kg, int thread_index, int queue_number, ccl_global int *queues, int queuesize, int empty_queue)
Definition: kernel_queues.h:53
ccl_device void enqueue_ray_index_local(int ray_index, int queue_number, char enqueue_flag, int queuesize, ccl_local_param unsigned int *local_queue_atomics, ccl_global int *Queue_data, ccl_global int *Queue_index)
Definition: kernel_queues.h:71
#define kernel_split_params
#define kernel_split_state
__kernel void ccl_constant KernelData ccl_global void ccl_global char ccl_global int ccl_global char ccl_global unsigned int ccl_global float * buffer
__kernel void ccl_constant KernelData ccl_global void ccl_global char * ray_state
__kernel void ccl_constant KernelData ccl_global void ccl_global char ccl_global int ccl_global char ccl_global unsigned int * work_pools
#define AS_SHADER_DATA(shader_data_tiny_storage)
#define IS_STATE(ray_state, ray_index, state)
#define QUEUE_EMPTY_SLOT
#define ASSIGN_RAY_STATE(ray_state, ray_index, state)
@ RAY_UPDATE_BUFFER
@ RAY_TO_REGENERATE
@ RAY_REGENERATED
@ RAY_INACTIVE
@ QUEUE_HITBG_BUFF_UPDATE_TOREGEN_RAYS
@ QUEUE_ACTIVE_AND_REGENERATED_RAYS
CCL_NAMESPACE_BEGIN ccl_device_inline void get_work_pixel(ccl_global const WorkTile *tile, uint global_work_index, ccl_private uint *x, ccl_private uint *y, ccl_private uint *sample)
static ulong state[N]
#define L
static void sample(SocketReader *reader, int x, int y, float color[4])
#define CCL_LOCAL_MEM_FENCE
Definition: util_atomic.h:32
#define ccl_barrier(flags)
Definition: util_atomic.h:33