Blender  V2.93
kernel_queue_enqueue.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 
18 
19 /* This kernel enqueues rays of different ray state into their
20  * appropriate queues:
21  *
22  * 1. Rays that have been determined to hit the background from the
23  * "kernel_scene_intersect" kernel are enqueued in
24  * QUEUE_HITBG_BUFF_UPDATE_TOREGEN_RAYS;
25  * 2. Rays that have been determined to be actively participating in pat
26  * -iteration will be enqueued into QUEUE_ACTIVE_AND_REGENERATED_RAYS.
27  *
28  * State of queue during other times this kernel is called:
29  * At entry,
30  * - QUEUE_ACTIVE_AND_REGENERATED_RAYS will be empty.
31  * - QUEUE_HITBG_BUFF_UPDATE_TOREGEN_RAYS will contain RAY_TO_REGENERATE
32  * and RAY_UPDATE_BUFFER rays.
33  * At exit,
34  * - QUEUE_ACTIVE_AND_REGENERATED_RAYS will be filled with RAY_ACTIVE rays.
35  * - QUEUE_HITBG_BUFF_UPDATE_TOREGEN_RAYS will be filled with
36  * RAY_TO_REGENERATE, RAY_UPDATE_BUFFER, RAY_HIT_BACKGROUND rays.
37  */
39 {
40  /* We have only 2 cases (Hit/Not-Hit) */
41  int lidx = ccl_local_id(1) * ccl_local_size(0) + ccl_local_id(0);
42  int ray_index = ccl_global_id(1) * ccl_global_size(0) + ccl_global_id(0);
43 
44  if (lidx == 0) {
45  locals->queue_atomics[0] = 0;
46  locals->queue_atomics[1] = 0;
47  }
49 
50  int queue_number = -1;
51 
52  if (IS_STATE(kernel_split_state.ray_state, ray_index, RAY_HIT_BACKGROUND) ||
53  IS_STATE(kernel_split_state.ray_state, ray_index, RAY_UPDATE_BUFFER) ||
54  IS_STATE(kernel_split_state.ray_state, ray_index, RAY_TO_REGENERATE)) {
56  }
57  else if (IS_STATE(kernel_split_state.ray_state, ray_index, RAY_ACTIVE) ||
58  IS_STATE(kernel_split_state.ray_state, ray_index, RAY_HAS_ONLY_VOLUME) ||
59  IS_STATE(kernel_split_state.ray_state, ray_index, RAY_REGENERATED)) {
60  queue_number = QUEUE_ACTIVE_AND_REGENERATED_RAYS;
61  }
62 
63  unsigned int my_lqidx;
64  if (queue_number != -1) {
65  my_lqidx = get_local_queue_index(queue_number, locals->queue_atomics);
66  }
68 
69  if (lidx == 0) {
71  QUEUE_ACTIVE_AND_REGENERATED_RAYS, locals->queue_atomics, kernel_split_params.queue_index);
74  locals->queue_atomics,
75  kernel_split_params.queue_index);
76  }
78 
79  unsigned int my_gqidx;
80  if (queue_number != -1) {
81  my_gqidx = get_global_queue_index(
82  queue_number, kernel_split_params.queue_size, my_lqidx, locals->queue_atomics);
83  kernel_split_state.queue_data[my_gqidx] = ray_index;
84  }
85 }
86 
#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)
ccl_device_inline uint ccl_local_size(uint d)
#define CCL_NAMESPACE_END
CCL_NAMESPACE_BEGIN ccl_device void kernel_queue_enqueue(KernelGlobals *kg, ccl_local_param QueueEnqueueLocals *locals)
ccl_device unsigned int get_global_queue_index(int queue_number, int queuesize, unsigned int lqidx, ccl_local_param unsigned int *global_per_queue_offset)
ccl_device unsigned int get_local_queue_index(int queue_number, ccl_local_param unsigned int *local_queue_atomics)
ccl_device unsigned int get_global_per_queue_offset(int queue_number, ccl_local_param unsigned int *local_queue_atomics, ccl_global int *global_queue_atomics)
#define kernel_split_params
#define kernel_split_state
#define IS_STATE(ray_state, ray_index, state)
@ RAY_UPDATE_BUFFER
@ RAY_HIT_BACKGROUND
@ RAY_ACTIVE
@ RAY_HAS_ONLY_VOLUME
@ RAY_TO_REGENERATE
@ RAY_REGENERATED
@ QUEUE_HITBG_BUFF_UPDATE_TOREGEN_RAYS
@ QUEUE_ACTIVE_AND_REGENERATED_RAYS
#define CCL_LOCAL_MEM_FENCE
Definition: util_atomic.h:32
#define ccl_barrier(flags)
Definition: util_atomic.h:33