Cycles: Rework BVH functions calls a little bit

Basic idea is to allow multiple implementation per feature-set, meaning this
commit tries to make it easier to hook new algorithms for BVH traversal.
This commit is contained in:
Sergey Sharybin 2014-12-25 00:06:49 +05:00
parent ab8d9c4b88
commit 0476e2c87a
5 changed files with 90 additions and 15 deletions

@ -42,6 +42,10 @@ CCL_NAMESPACE_BEGIN
#define BVH_HAIR 4
#define BVH_HAIR_MINIMUM_WIDTH 8
#define BVH_NAME_JOIN(x,y) x ## _ ## y
#define BVH_NAME_EVAL(x,y) BVH_NAME_JOIN(x,y)
#define BVH_FUNCTION_FULL_NAME(prefix) BVH_NAME_EVAL(prefix, BVH_FUNCTION_NAME)
/* Regular BVH traversal */
#define BVH_FUNCTION_NAME bvh_intersect
@ -168,6 +172,10 @@ CCL_NAMESPACE_BEGIN
#include "geom_bvh_volume.h"
#endif
#undef BVH_NAME_JOIN
#undef BVH_NAME_EVAL
#undef BVH_FUNCTION_FULL_NAME
ccl_device_intersect bool scene_intersect(KernelGlobals *kg, const Ray *ray, const uint visibility, Intersection *isect,
uint *lcg_state, float difl, float extmax)
{

@ -29,8 +29,11 @@
#define FEATURE(f) (((BVH_FUNCTION_FEATURES) & (f)) != 0)
ccl_device bool BVH_FUNCTION_NAME
(KernelGlobals *kg, const Ray *ray, Intersection *isect_array, const uint max_hits, uint *num_hits)
ccl_device bool BVH_FUNCTION_FULL_NAME(BVH)(KernelGlobals *kg,
const Ray *ray,
Intersection *isect_array,
const uint max_hits,
uint *num_hits)
{
/* todo:
* - likely and unlikely for if() statements
@ -373,7 +376,19 @@ ccl_device bool BVH_FUNCTION_NAME
return false;
}
ccl_device_inline bool BVH_FUNCTION_NAME(KernelGlobals *kg,
const Ray *ray,
Intersection *isect_array,
const uint max_hits,
uint *num_hits)
{
return BVH_FUNCTION_FULL_NAME(BVH)(kg,
ray,
isect_array,
max_hits,
num_hits);
}
#undef FEATURE
#undef BVH_FUNCTION_NAME
#undef BVH_FUNCTION_FEATURES

@ -28,8 +28,12 @@
#define FEATURE(f) (((BVH_FUNCTION_FEATURES) & (f)) != 0)
ccl_device uint BVH_FUNCTION_NAME(KernelGlobals *kg, const Ray *ray, Intersection *isect_array,
int subsurface_object, uint *lcg_state, int max_hits)
ccl_device uint BVH_FUNCTION_FULL_NAME(BVH)(KernelGlobals *kg,
const Ray *ray,
Intersection *isect_array,
int subsurface_object,
uint *lcg_state,
int max_hits)
{
/* todo:
* - test if pushing distance on the stack helps (for non shadow rays)
@ -291,7 +295,21 @@ ccl_device uint BVH_FUNCTION_NAME(KernelGlobals *kg, const Ray *ray, Intersectio
return num_hits;
}
ccl_device_inline uint BVH_FUNCTION_NAME(KernelGlobals *kg,
const Ray *ray,
Intersection *isect_array,
int subsurface_object,
uint *lcg_state,
int max_hits)
{
return BVH_FUNCTION_FULL_NAME(BVH)(kg,
ray,
isect_array,
subsurface_object,
lcg_state,
max_hits);
}
#undef FEATURE
#undef BVH_FUNCTION_NAME
#undef BVH_FUNCTION_FEATURES

@ -30,10 +30,14 @@
#define FEATURE(f) (((BVH_FUNCTION_FEATURES) & (f)) != 0)
ccl_device bool BVH_FUNCTION_NAME
(KernelGlobals *kg, const Ray *ray, Intersection *isect, const uint visibility
ccl_device bool BVH_FUNCTION_FULL_NAME(BVH)(KernelGlobals *kg,
const Ray *ray,
Intersection *isect,
const uint visibility
#if FEATURE(BVH_HAIR_MINIMUM_WIDTH)
, uint *lcg_state, float difl, float extmax
, uint *lcg_state,
float difl,
float extmax
#endif
)
{
@ -368,7 +372,29 @@ ccl_device bool BVH_FUNCTION_NAME
return (isect->prim != PRIM_NONE);
}
ccl_device_inline bool BVH_FUNCTION_NAME(KernelGlobals *kg,
const Ray *ray,
Intersection *isect,
const uint visibility
#if FEATURE(BVH_HAIR_MINIMUM_WIDTH)
, uint *lcg_state,
float difl,
float extmax
#endif
)
{
return BVH_FUNCTION_FULL_NAME(BVH)(kg,
ray,
isect,
visibility
#if FEATURE(BVH_HAIR_MINIMUM_WIDTH)
, lcg_state,
difl,
extmax
#endif
);
}
#undef FEATURE
#undef BVH_FUNCTION_NAME
#undef BVH_FUNCTION_FEATURES

@ -29,7 +29,7 @@
#define FEATURE(f) (((BVH_FUNCTION_FEATURES) & (f)) != 0)
ccl_device bool BVH_FUNCTION_NAME(KernelGlobals *kg,
ccl_device bool BVH_FUNCTION_FULL_NAME(BVH)(KernelGlobals *kg,
const Ray *ray,
Intersection *isect)
{
@ -312,7 +312,15 @@ ccl_device bool BVH_FUNCTION_NAME(KernelGlobals *kg,
return (isect->prim != PRIM_NONE);
}
ccl_device_inline bool BVH_FUNCTION_NAME(KernelGlobals *kg,
const Ray *ray,
Intersection *isect)
{
return BVH_FUNCTION_FULL_NAME(BVH)(kg,
ray,
isect);
}
#undef FEATURE
#undef BVH_FUNCTION_NAME
#undef BVH_FUNCTION_FEATURES