From cd47d1b2ed0834e52c1e71027c5b5032f1a24afd Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Tue, 26 Jul 2022 20:58:16 +0200 Subject: Fix broken BVH2 on CPU after recent changes Runtime switching between Embree and BVH2 got lost. --- intern/cycles/kernel/bvh/bvh.h | 26 +++++++++++ intern/cycles/kernel/device/cpu/bvh.h | 81 ++++++++++------------------------- 2 files changed, 48 insertions(+), 59 deletions(-) (limited to 'intern/cycles/kernel') diff --git a/intern/cycles/kernel/bvh/bvh.h b/intern/cycles/kernel/bvh/bvh.h index 11e732ec480..5e3f8d839e9 100644 --- a/intern/cycles/kernel/bvh/bvh.h +++ b/intern/cycles/kernel/bvh/bvh.h @@ -12,6 +12,7 @@ #if defined(__EMBREE__) # include "kernel/device/cpu/bvh.h" +# define __BVH2__ #elif defined(__METALRT__) # include "kernel/device/metal/bvh.h" #elif defined(__KERNEL_OPTIX__) @@ -72,6 +73,12 @@ ccl_device_intersect bool scene_intersect(KernelGlobals kg, return false; } +# ifdef __EMBREE__ + if (kernel_data.device_bvh) { + return kernel_embree_intersect(kg, ray, visibility, isect); + } +# endif + # ifdef __OBJECT_MOTION__ if (kernel_data.bvh.have_motion) { # ifdef __HAIR__ @@ -121,6 +128,12 @@ ccl_device_intersect bool scene_intersect_local(KernelGlobals kg, return false; } +# ifdef __EMBREE__ + if (kernel_data.device_bvh) { + return kernel_embree_intersect_local(kg, ray, local_isect, local_object, lcg_state, max_hits); + } +# endif + # ifdef __OBJECT_MOTION__ if (kernel_data.bvh.have_motion) { return bvh_intersect_local_motion(kg, ray, local_isect, local_object, lcg_state, max_hits); @@ -170,6 +183,13 @@ ccl_device_intersect bool scene_intersect_shadow_all(KernelGlobals kg, return false; } +# ifdef __EMBREE__ + if (kernel_data.device_bvh) { + return kernel_embree_intersect_shadow_all( + kg, state, ray, visibility, max_hits, num_recorded_hits, throughput); + } +# endif + # ifdef __OBJECT_MOTION__ if (kernel_data.bvh.have_motion) { # ifdef __HAIR__ @@ -254,6 +274,12 @@ ccl_device_intersect uint scene_intersect_volume(KernelGlobals kg, return false; } +# ifdef __EMBREE__ + if (kernel_data.device_bvh) { + return kernel_embree_intersect_volume(kg, ray, isect, max_hits, visibility); + } +# endif + # ifdef __OBJECT_MOTION__ if (kernel_data.bvh.have_motion) { return bvh_intersect_volume_all_motion(kg, ray, isect, max_hits, visibility); diff --git a/intern/cycles/kernel/device/cpu/bvh.h b/intern/cycles/kernel/device/cpu/bvh.h index b5ea3d831f4..8ebeee99c47 100644 --- a/intern/cycles/kernel/device/cpu/bvh.h +++ b/intern/cycles/kernel/device/cpu/bvh.h @@ -446,19 +446,11 @@ ccl_device void kernel_embree_filter_occluded_func_backface_cull( /* Scene intersection. */ -ccl_device_intersect bool scene_intersect(KernelGlobals kg, - ccl_private const Ray *ray, - const uint visibility, - ccl_private Intersection *isect) +ccl_device_intersect bool kernel_embree_intersect(KernelGlobals kg, + ccl_private const Ray *ray, + const uint visibility, + ccl_private Intersection *isect) { - if (!intersection_ray_valid(ray)) { - return false; - } - - if (!kernel_data.device_bvh) { - return false; - } - isect->t = ray->tmax; CCLIntersectContext ctx(kg, CCLIntersectContext::RAY_REGULAR); IntersectContext rtc_ctx(&ctx); @@ -476,24 +468,13 @@ ccl_device_intersect bool scene_intersect(KernelGlobals kg, } #ifdef __BVH_LOCAL__ -ccl_device_intersect bool scene_intersect_local(KernelGlobals kg, - ccl_private const Ray *ray, - ccl_private LocalIntersection *local_isect, - int local_object, - ccl_private uint *lcg_state, - int max_hits) +ccl_device_intersect bool kernel_embree_intersect_local(KernelGlobals kg, + ccl_private const Ray *ray, + ccl_private LocalIntersection *local_isect, + int local_object, + ccl_private uint *lcg_state, + int max_hits) { - if (!intersection_ray_valid(ray)) { - if (local_isect) { - local_isect->num_hits = 0; - } - return false; - } - - if (!kernel_data.device_bvh) { - return false; - } - const bool has_bvh = !(kernel_data_fetch(object_flag, local_object) & SD_OBJECT_TRANSFORM_APPLIED); CCLIntersectContext ctx(kg, @@ -544,24 +525,14 @@ ccl_device_intersect bool scene_intersect_local(KernelGlobals kg, #endif #ifdef __SHADOW_RECORD_ALL__ -ccl_device_intersect bool scene_intersect_shadow_all(KernelGlobals kg, - IntegratorShadowStateCPU *state, - ccl_private const Ray *ray, - uint visibility, - uint max_hits, - ccl_private uint *num_recorded_hits, - ccl_private float *throughput) +ccl_device_intersect bool kernel_embree_intersect_shadow_all(KernelGlobals kg, + IntegratorShadowStateCPU *state, + ccl_private const Ray *ray, + uint visibility, + uint max_hits, + ccl_private uint *num_recorded_hits, + ccl_private float *throughput) { - if (!intersection_ray_valid(ray)) { - *num_recorded_hits = 0; - *throughput = 1.0f; - return false; - } - - if (!kernel_data.device_bvh) { - return false; - } - CCLIntersectContext ctx(kg, CCLIntersectContext::RAY_SHADOW_ALL); Intersection *isect_array = (Intersection *)state->shadow_isect; ctx.isect_s = isect_array; @@ -579,20 +550,12 @@ ccl_device_intersect bool scene_intersect_shadow_all(KernelGlobals kg, #endif #ifdef __VOLUME__ -ccl_device_intersect uint scene_intersect_volume(KernelGlobals kg, - ccl_private const Ray *ray, - ccl_private Intersection *isect, - const uint max_hits, - const uint visibility) +ccl_device_intersect uint kernel_embree_intersect_volume(KernelGlobals kg, + ccl_private const Ray *ray, + ccl_private Intersection *isect, + const uint max_hits, + const uint visibility) { - if (!intersection_ray_valid(ray)) { - return false; - } - - if (!kernel_data.device_bvh) { - return false; - } - CCLIntersectContext ctx(kg, CCLIntersectContext::RAY_VOLUME_ALL); ctx.isect_s = isect; ctx.max_hits = max_hits; -- cgit v1.2.3