kernel_split_common.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. #ifndef __KERNEL_SPLIT_H__
  17. #define __KERNEL_SPLIT_H__
  18. #include "kernel/kernel_math.h"
  19. #include "kernel/kernel_types.h"
  20. #include "kernel/split/kernel_split_data.h"
  21. #include "kernel/kernel_globals.h"
  22. #include "kernel/kernel_color.h"
  23. #ifdef __OSL__
  24. # include "kernel/osl/osl_shader.h"
  25. #endif
  26. #ifdef __KERNEL_OPENCL__
  27. # include "kernel/kernels/opencl/kernel_opencl_image.h"
  28. #endif
  29. #ifdef __KERNEL_CUDA__
  30. # include "kernel/kernels/cuda/kernel_cuda_image.h"
  31. #endif
  32. #ifdef __KERNEL_CPU__
  33. # include "kernel/kernels/cpu/kernel_cpu_image.h"
  34. #endif
  35. #include "util/util_atomic.h"
  36. #include "kernel/kernel_path.h"
  37. #ifdef __BRANCHED_PATH__
  38. # include "kernel/kernel_path_branched.h"
  39. #endif
  40. #include "kernel/kernel_queues.h"
  41. #include "kernel/kernel_work_stealing.h"
  42. #ifdef __BRANCHED_PATH__
  43. # include "kernel/split/kernel_branched.h"
  44. #endif
  45. CCL_NAMESPACE_BEGIN
  46. ccl_device_inline void kernel_split_path_end(KernelGlobals *kg, int ray_index)
  47. {
  48. ccl_global char *ray_state = kernel_split_state.ray_state;
  49. #ifdef __BRANCHED_PATH__
  50. # ifdef __SUBSURFACE__
  51. ccl_addr_space SubsurfaceIndirectRays *ss_indirect = &kernel_split_state.ss_rays[ray_index];
  52. if (ss_indirect->num_rays) {
  53. ASSIGN_RAY_STATE(ray_state, ray_index, RAY_UPDATE_BUFFER);
  54. }
  55. else
  56. # endif /* __SUBSURFACE__ */
  57. if (IS_FLAG(ray_state, ray_index, RAY_BRANCHED_INDIRECT_SHARED)) {
  58. int orig_ray = kernel_split_state.branched_state[ray_index].original_ray;
  59. PathRadiance *L = &kernel_split_state.path_radiance[ray_index];
  60. PathRadiance *orig_ray_L = &kernel_split_state.path_radiance[orig_ray];
  61. path_radiance_sum_indirect(L);
  62. path_radiance_accum_sample(orig_ray_L, L);
  63. atomic_fetch_and_dec_uint32(
  64. (ccl_global uint *)&kernel_split_state.branched_state[orig_ray].shared_sample_count);
  65. ASSIGN_RAY_STATE(ray_state, ray_index, RAY_INACTIVE);
  66. }
  67. else if (IS_FLAG(ray_state, ray_index, RAY_BRANCHED_LIGHT_INDIRECT)) {
  68. ASSIGN_RAY_STATE(ray_state, ray_index, RAY_LIGHT_INDIRECT_NEXT_ITER);
  69. }
  70. else if (IS_FLAG(ray_state, ray_index, RAY_BRANCHED_VOLUME_INDIRECT)) {
  71. ASSIGN_RAY_STATE(ray_state, ray_index, RAY_VOLUME_INDIRECT_NEXT_ITER);
  72. }
  73. else if (IS_FLAG(ray_state, ray_index, RAY_BRANCHED_SUBSURFACE_INDIRECT)) {
  74. ASSIGN_RAY_STATE(ray_state, ray_index, RAY_SUBSURFACE_INDIRECT_NEXT_ITER);
  75. }
  76. else {
  77. ASSIGN_RAY_STATE(ray_state, ray_index, RAY_UPDATE_BUFFER);
  78. }
  79. #else
  80. ASSIGN_RAY_STATE(ray_state, ray_index, RAY_UPDATE_BUFFER);
  81. #endif
  82. }
  83. CCL_NAMESPACE_END
  84. #endif /* __KERNEL_SPLIT_H__ */