kernel_queue_enqueue.h 3.4 KB

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