kernel_data_init.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. CCL_NAMESPACE_BEGIN
  17. /* This kernel Initializes structures needed in path-iteration kernels.
  18. *
  19. * Note on Queues:
  20. * All slots in queues are initialized to queue empty slot;
  21. * The number of elements in the queues is initialized to 0;
  22. */
  23. #ifndef __KERNEL_CPU__
  24. ccl_device void kernel_data_init(
  25. #else
  26. void KERNEL_FUNCTION_FULL_NAME(data_init)(
  27. #endif
  28. KernelGlobals *kg,
  29. ccl_constant KernelData *data,
  30. ccl_global void *split_data_buffer,
  31. int num_elements,
  32. ccl_global char *ray_state,
  33. #ifdef __KERNEL_OPENCL__
  34. KERNEL_BUFFER_PARAMS,
  35. #endif
  36. int start_sample,
  37. int end_sample,
  38. int sx,
  39. int sy,
  40. int sw,
  41. int sh,
  42. int offset,
  43. int stride,
  44. ccl_global int *Queue_index, /* Tracks the number of elements in queues */
  45. int queuesize, /* size (capacity) of the queue */
  46. ccl_global char *use_queues_flag, /* flag to decide if scene-intersect kernel should use queues
  47. to fetch ray index */
  48. ccl_global unsigned int *work_pools, /* Work pool for each work group */
  49. unsigned int num_samples,
  50. ccl_global float *buffer)
  51. {
  52. #ifdef KERNEL_STUB
  53. STUB_ASSERT(KERNEL_ARCH, data_init);
  54. #else
  55. # ifdef __KERNEL_OPENCL__
  56. kg->data = data;
  57. # endif
  58. kernel_split_params.tile.x = sx;
  59. kernel_split_params.tile.y = sy;
  60. kernel_split_params.tile.w = sw;
  61. kernel_split_params.tile.h = sh;
  62. kernel_split_params.tile.start_sample = start_sample;
  63. kernel_split_params.tile.num_samples = num_samples;
  64. kernel_split_params.tile.offset = offset;
  65. kernel_split_params.tile.stride = stride;
  66. kernel_split_params.tile.buffer = buffer;
  67. kernel_split_params.total_work_size = sw * sh * num_samples;
  68. kernel_split_params.work_pools = work_pools;
  69. kernel_split_params.queue_index = Queue_index;
  70. kernel_split_params.queue_size = queuesize;
  71. kernel_split_params.use_queues_flag = use_queues_flag;
  72. split_data_init(kg, &kernel_split_state, num_elements, split_data_buffer, ray_state);
  73. # ifdef __KERNEL_OPENCL__
  74. kernel_set_buffer_pointers(kg, KERNEL_BUFFER_ARGS);
  75. kernel_set_buffer_info(kg);
  76. # endif
  77. int thread_index = ccl_global_id(1) * ccl_global_size(0) + ccl_global_id(0);
  78. /* Initialize queue data and queue index. */
  79. if (thread_index < queuesize) {
  80. for (int i = 0; i < NUM_QUEUES; i++) {
  81. kernel_split_state.queue_data[i * queuesize + thread_index] = QUEUE_EMPTY_SLOT;
  82. }
  83. }
  84. if (thread_index == 0) {
  85. for (int i = 0; i < NUM_QUEUES; i++) {
  86. Queue_index[i] = 0;
  87. }
  88. /* The scene-intersect kernel should not use the queues very first time.
  89. * since the queue would be empty.
  90. */
  91. *use_queues_flag = 0;
  92. }
  93. #endif /* KERENL_STUB */
  94. }
  95. CCL_NAMESPACE_END