kernel_split_data.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. #ifndef __KERNEL_SPLIT_DATA_H__
  17. #define __KERNEL_SPLIT_DATA_H__
  18. #include "kernel/split/kernel_split_data_types.h"
  19. #include "kernel/kernel_globals.h"
  20. CCL_NAMESPACE_BEGIN
  21. ccl_device_inline uint64_t split_data_buffer_size(KernelGlobals *kg, size_t num_elements)
  22. {
  23. (void)kg; /* Unused on CPU. */
  24. uint64_t size = 0;
  25. #define SPLIT_DATA_ENTRY(type, name, num) +align_up(num_elements *num * sizeof(type), 16)
  26. size = size SPLIT_DATA_ENTRIES;
  27. #undef SPLIT_DATA_ENTRY
  28. uint64_t closure_size = sizeof(ShaderClosure) * (kernel_data.integrator.max_closures - 1);
  29. #ifdef __BRANCHED_PATH__
  30. size += align_up(num_elements * (sizeof(ShaderData) + closure_size), 16);
  31. #endif
  32. size += align_up(num_elements * (sizeof(ShaderData) + closure_size), 16);
  33. return size;
  34. }
  35. ccl_device_inline void split_data_init(KernelGlobals *kg,
  36. ccl_global SplitData *split_data,
  37. size_t num_elements,
  38. ccl_global void *data,
  39. ccl_global char *ray_state)
  40. {
  41. (void)kg; /* Unused on CPU. */
  42. ccl_global char *p = (ccl_global char *)data;
  43. #define SPLIT_DATA_ENTRY(type, name, num) \
  44. split_data->name = (type *)p; \
  45. p += align_up(num_elements * num * sizeof(type), 16);
  46. SPLIT_DATA_ENTRIES;
  47. #undef SPLIT_DATA_ENTRY
  48. uint64_t closure_size = sizeof(ShaderClosure) * (kernel_data.integrator.max_closures - 1);
  49. #ifdef __BRANCHED_PATH__
  50. split_data->_branched_state_sd = (ShaderData *)p;
  51. p += align_up(num_elements * (sizeof(ShaderData) + closure_size), 16);
  52. #endif
  53. split_data->_sd = (ShaderData *)p;
  54. p += align_up(num_elements * (sizeof(ShaderData) + closure_size), 16);
  55. split_data->ray_state = ray_state;
  56. }
  57. CCL_NAMESPACE_END
  58. #endif /* __KERNEL_SPLIT_DATA_H__ */