kernel_split.cu 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. /* CUDA split kernel entry points */
  17. #ifdef __CUDA_ARCH__
  18. #define __SPLIT_KERNEL__
  19. #include "kernel/kernel_compat_cuda.h"
  20. #include "kernel_config.h"
  21. #include "kernel/split/kernel_split_common.h"
  22. #include "kernel/split/kernel_data_init.h"
  23. #include "kernel/split/kernel_path_init.h"
  24. #include "kernel/split/kernel_scene_intersect.h"
  25. #include "kernel/split/kernel_lamp_emission.h"
  26. #include "kernel/split/kernel_do_volume.h"
  27. #include "kernel/split/kernel_queue_enqueue.h"
  28. #include "kernel/split/kernel_indirect_background.h"
  29. #include "kernel/split/kernel_shader_setup.h"
  30. #include "kernel/split/kernel_shader_sort.h"
  31. #include "kernel/split/kernel_shader_eval.h"
  32. #include "kernel/split/kernel_holdout_emission_blurring_pathtermination_ao.h"
  33. #include "kernel/split/kernel_subsurface_scatter.h"
  34. #include "kernel/split/kernel_direct_lighting.h"
  35. #include "kernel/split/kernel_shadow_blocked_ao.h"
  36. #include "kernel/split/kernel_shadow_blocked_dl.h"
  37. #include "kernel/split/kernel_enqueue_inactive.h"
  38. #include "kernel/split/kernel_next_iteration_setup.h"
  39. #include "kernel/split/kernel_indirect_subsurface.h"
  40. #include "kernel/split/kernel_buffer_update.h"
  41. #include "kernel/kernel_film.h"
  42. /* kernels */
  43. extern "C" __global__ void
  44. CUDA_LAUNCH_BOUNDS(CUDA_THREADS_BLOCK_WIDTH, CUDA_KERNEL_MAX_REGISTERS)
  45. kernel_cuda_state_buffer_size(uint num_threads, uint64_t *size)
  46. {
  47. *size = split_data_buffer_size(NULL, num_threads);
  48. }
  49. extern "C" __global__ void
  50. CUDA_LAUNCH_BOUNDS(CUDA_THREADS_BLOCK_WIDTH, CUDA_KERNEL_MAX_REGISTERS)
  51. kernel_cuda_path_trace_data_init(
  52. ccl_global void *split_data_buffer,
  53. int num_elements,
  54. ccl_global char *ray_state,
  55. int start_sample,
  56. int end_sample,
  57. int sx, int sy, int sw, int sh, int offset, int stride,
  58. ccl_global int *Queue_index,
  59. int queuesize,
  60. ccl_global char *use_queues_flag,
  61. ccl_global unsigned int *work_pool_wgs,
  62. unsigned int num_samples,
  63. ccl_global float *buffer)
  64. {
  65. kernel_data_init(NULL,
  66. NULL,
  67. split_data_buffer,
  68. num_elements,
  69. ray_state,
  70. start_sample,
  71. end_sample,
  72. sx, sy, sw, sh, offset, stride,
  73. Queue_index,
  74. queuesize,
  75. use_queues_flag,
  76. work_pool_wgs,
  77. num_samples,
  78. buffer);
  79. }
  80. #define DEFINE_SPLIT_KERNEL_FUNCTION(name) \
  81. extern "C" __global__ void \
  82. CUDA_LAUNCH_BOUNDS(CUDA_THREADS_BLOCK_WIDTH, CUDA_KERNEL_SPLIT_MAX_REGISTERS) \
  83. kernel_cuda_##name() \
  84. { \
  85. kernel_##name(NULL); \
  86. }
  87. #define DEFINE_SPLIT_KERNEL_FUNCTION_LOCALS(name, type) \
  88. extern "C" __global__ void \
  89. CUDA_LAUNCH_BOUNDS(CUDA_THREADS_BLOCK_WIDTH, CUDA_KERNEL_SPLIT_MAX_REGISTERS) \
  90. kernel_cuda_##name() \
  91. { \
  92. ccl_local type locals; \
  93. kernel_##name(NULL, &locals); \
  94. }
  95. DEFINE_SPLIT_KERNEL_FUNCTION(path_init)
  96. DEFINE_SPLIT_KERNEL_FUNCTION(scene_intersect)
  97. DEFINE_SPLIT_KERNEL_FUNCTION(lamp_emission)
  98. DEFINE_SPLIT_KERNEL_FUNCTION(do_volume)
  99. DEFINE_SPLIT_KERNEL_FUNCTION_LOCALS(queue_enqueue, QueueEnqueueLocals)
  100. DEFINE_SPLIT_KERNEL_FUNCTION(indirect_background)
  101. DEFINE_SPLIT_KERNEL_FUNCTION_LOCALS(shader_setup, uint)
  102. DEFINE_SPLIT_KERNEL_FUNCTION_LOCALS(shader_sort, ShaderSortLocals)
  103. DEFINE_SPLIT_KERNEL_FUNCTION(shader_eval)
  104. DEFINE_SPLIT_KERNEL_FUNCTION_LOCALS(holdout_emission_blurring_pathtermination_ao, BackgroundAOLocals)
  105. DEFINE_SPLIT_KERNEL_FUNCTION(subsurface_scatter)
  106. DEFINE_SPLIT_KERNEL_FUNCTION_LOCALS(direct_lighting, uint)
  107. DEFINE_SPLIT_KERNEL_FUNCTION(shadow_blocked_ao)
  108. DEFINE_SPLIT_KERNEL_FUNCTION(shadow_blocked_dl)
  109. DEFINE_SPLIT_KERNEL_FUNCTION_LOCALS(enqueue_inactive, uint)
  110. DEFINE_SPLIT_KERNEL_FUNCTION_LOCALS(next_iteration_setup, uint)
  111. DEFINE_SPLIT_KERNEL_FUNCTION(indirect_subsurface)
  112. DEFINE_SPLIT_KERNEL_FUNCTION_LOCALS(buffer_update, uint)
  113. extern "C" __global__ void
  114. CUDA_LAUNCH_BOUNDS(CUDA_THREADS_BLOCK_WIDTH, CUDA_KERNEL_MAX_REGISTERS)
  115. kernel_cuda_convert_to_byte(uchar4 *rgba, float *buffer, float sample_scale, int sx, int sy, int sw, int sh, int offset, int stride)
  116. {
  117. int x = sx + blockDim.x*blockIdx.x + threadIdx.x;
  118. int y = sy + blockDim.y*blockIdx.y + threadIdx.y;
  119. if(x < sx + sw && y < sy + sh)
  120. kernel_film_convert_to_byte(NULL, rgba, buffer, sample_scale, x, y, offset, stride);
  121. }
  122. extern "C" __global__ void
  123. CUDA_LAUNCH_BOUNDS(CUDA_THREADS_BLOCK_WIDTH, CUDA_KERNEL_MAX_REGISTERS)
  124. kernel_cuda_convert_to_half_float(uchar4 *rgba, float *buffer, float sample_scale, int sx, int sy, int sw, int sh, int offset, int stride)
  125. {
  126. int x = sx + blockDim.x*blockIdx.x + threadIdx.x;
  127. int y = sy + blockDim.y*blockIdx.y + threadIdx.y;
  128. if(x < sx + sw && y < sy + sh)
  129. kernel_film_convert_to_half_float(NULL, rgba, buffer, sample_scale, x, y, offset, stride);
  130. }
  131. #endif