kernel_indirect_subsurface.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Copyright 2011-2017 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. ccl_device void kernel_indirect_subsurface(KernelGlobals *kg)
  18. {
  19. int thread_index = ccl_global_id(1) * ccl_global_size(0) + ccl_global_id(0);
  20. if (thread_index == 0) {
  21. /* We will empty both queues in this kernel. */
  22. kernel_split_params.queue_index[QUEUE_ACTIVE_AND_REGENERATED_RAYS] = 0;
  23. kernel_split_params.queue_index[QUEUE_HITBG_BUFF_UPDATE_TOREGEN_RAYS] = 0;
  24. }
  25. int ray_index;
  26. get_ray_index(kg,
  27. thread_index,
  28. QUEUE_ACTIVE_AND_REGENERATED_RAYS,
  29. kernel_split_state.queue_data,
  30. kernel_split_params.queue_size,
  31. 1);
  32. ray_index = get_ray_index(kg,
  33. thread_index,
  34. QUEUE_HITBG_BUFF_UPDATE_TOREGEN_RAYS,
  35. kernel_split_state.queue_data,
  36. kernel_split_params.queue_size,
  37. 1);
  38. #ifdef __SUBSURFACE__
  39. if (ray_index == QUEUE_EMPTY_SLOT) {
  40. return;
  41. }
  42. ccl_global char *ray_state = kernel_split_state.ray_state;
  43. ccl_global PathState *state = &kernel_split_state.path_state[ray_index];
  44. PathRadiance *L = &kernel_split_state.path_radiance[ray_index];
  45. ccl_global Ray *ray = &kernel_split_state.ray[ray_index];
  46. ccl_global float3 *throughput = &kernel_split_state.throughput[ray_index];
  47. if (IS_STATE(ray_state, ray_index, RAY_UPDATE_BUFFER)) {
  48. ccl_addr_space SubsurfaceIndirectRays *ss_indirect = &kernel_split_state.ss_rays[ray_index];
  49. /* Trace indirect subsurface rays by restarting the loop. this uses less
  50. * stack memory than invoking kernel_path_indirect.
  51. */
  52. if (ss_indirect->num_rays) {
  53. kernel_path_subsurface_setup_indirect(kg, ss_indirect, state, ray, L, throughput);
  54. ASSIGN_RAY_STATE(ray_state, ray_index, RAY_REGENERATED);
  55. }
  56. }
  57. #endif /* __SUBSURFACE__ */
  58. }
  59. CCL_NAMESPACE_END