Cycles: remove __UV__ and __INSTANCING__ as kernel options

The kernel did not work correctly when these were disabled anyway. The
optimized BVH traversal for the no instances case was also only used on
the CPU, so no longer makes sense to keep.

Ref T73778

Depends on D8010

Maniphest Tasks: T73778

Differential Revision: https://developer.blender.org/D8011
This commit is contained in:
Brecht Van Lommel 2020-02-23 10:15:35 +01:00
parent fed101a7be
commit 1de0e13af6
12 changed files with 58 additions and 211 deletions

@ -51,27 +51,21 @@ CCL_NAMESPACE_BEGIN
# define BVH_FUNCTION_FEATURES 0
# include "kernel/bvh/bvh_traversal.h"
# if defined(__INSTANCING__)
# define BVH_FUNCTION_NAME bvh_intersect_instancing
# define BVH_FUNCTION_FEATURES BVH_INSTANCING
# include "kernel/bvh/bvh_traversal.h"
# endif
# if defined(__HAIR__)
# define BVH_FUNCTION_NAME bvh_intersect_hair
# define BVH_FUNCTION_FEATURES BVH_INSTANCING | BVH_HAIR
# define BVH_FUNCTION_FEATURES BVH_HAIR
# include "kernel/bvh/bvh_traversal.h"
# endif
# if defined(__OBJECT_MOTION__)
# define BVH_FUNCTION_NAME bvh_intersect_motion
# define BVH_FUNCTION_FEATURES BVH_INSTANCING | BVH_MOTION
# define BVH_FUNCTION_FEATURES BVH_MOTION
# include "kernel/bvh/bvh_traversal.h"
# endif
# if defined(__HAIR__) && defined(__OBJECT_MOTION__)
# define BVH_FUNCTION_NAME bvh_intersect_hair_motion
# define BVH_FUNCTION_FEATURES BVH_INSTANCING | BVH_HAIR | BVH_MOTION
# define BVH_FUNCTION_FEATURES BVH_HAIR | BVH_MOTION
# include "kernel/bvh/bvh_traversal.h"
# endif
@ -96,15 +90,9 @@ CCL_NAMESPACE_BEGIN
# define BVH_FUNCTION_FEATURES BVH_HAIR
# include "kernel/bvh/bvh_volume.h"
# if defined(__INSTANCING__)
# define BVH_FUNCTION_NAME bvh_intersect_volume_instancing
# define BVH_FUNCTION_FEATURES BVH_INSTANCING | BVH_HAIR
# include "kernel/bvh/bvh_volume.h"
# endif
# if defined(__OBJECT_MOTION__)
# define BVH_FUNCTION_NAME bvh_intersect_volume_motion
# define BVH_FUNCTION_FEATURES BVH_INSTANCING | BVH_MOTION | BVH_HAIR
# define BVH_FUNCTION_FEATURES BVH_MOTION | BVH_HAIR
# include "kernel/bvh/bvh_volume.h"
# endif
# endif /* __VOLUME__ */
@ -116,27 +104,21 @@ CCL_NAMESPACE_BEGIN
# define BVH_FUNCTION_FEATURES 0
# include "kernel/bvh/bvh_shadow_all.h"
# if defined(__INSTANCING__)
# define BVH_FUNCTION_NAME bvh_intersect_shadow_all_instancing
# define BVH_FUNCTION_FEATURES BVH_INSTANCING
# include "kernel/bvh/bvh_shadow_all.h"
# endif
# if defined(__HAIR__)
# define BVH_FUNCTION_NAME bvh_intersect_shadow_all_hair
# define BVH_FUNCTION_FEATURES BVH_INSTANCING | BVH_HAIR
# define BVH_FUNCTION_FEATURES BVH_HAIR
# include "kernel/bvh/bvh_shadow_all.h"
# endif
# if defined(__OBJECT_MOTION__)
# define BVH_FUNCTION_NAME bvh_intersect_shadow_all_motion
# define BVH_FUNCTION_FEATURES BVH_INSTANCING | BVH_MOTION
# define BVH_FUNCTION_FEATURES BVH_MOTION
# include "kernel/bvh/bvh_shadow_all.h"
# endif
# if defined(__HAIR__) && defined(__OBJECT_MOTION__)
# define BVH_FUNCTION_NAME bvh_intersect_shadow_all_hair_motion
# define BVH_FUNCTION_FEATURES BVH_INSTANCING | BVH_HAIR | BVH_MOTION
# define BVH_FUNCTION_FEATURES BVH_HAIR | BVH_MOTION
# include "kernel/bvh/bvh_shadow_all.h"
# endif
# endif /* __SHADOW_RECORD_ALL__ */
@ -148,15 +130,9 @@ CCL_NAMESPACE_BEGIN
# define BVH_FUNCTION_FEATURES BVH_HAIR
# include "kernel/bvh/bvh_volume_all.h"
# if defined(__INSTANCING__)
# define BVH_FUNCTION_NAME bvh_intersect_volume_all_instancing
# define BVH_FUNCTION_FEATURES BVH_INSTANCING | BVH_HAIR
# include "kernel/bvh/bvh_volume_all.h"
# endif
# if defined(__OBJECT_MOTION__)
# define BVH_FUNCTION_NAME bvh_intersect_volume_all_motion
# define BVH_FUNCTION_FEATURES BVH_INSTANCING | BVH_MOTION | BVH_HAIR
# define BVH_FUNCTION_FEATURES BVH_MOTION | BVH_HAIR
# include "kernel/bvh/bvh_volume_all.h"
# endif
# endif /* __VOLUME_RECORD_ALL__ */
@ -264,21 +240,8 @@ ccl_device_intersect bool scene_intersect(KernelGlobals *kg,
}
# endif /* __HAIR__ */
# ifdef __KERNEL_CPU__
# ifdef __INSTANCING__
if (kernel_data.bvh.have_instancing) {
return bvh_intersect_instancing(kg, ray, isect, visibility);
}
# endif /* __INSTANCING__ */
return bvh_intersect(kg, ray, isect, visibility);
# else /* __KERNEL_CPU__ */
# ifdef __INSTANCING__
return bvh_intersect_instancing(kg, ray, isect, visibility);
# else
return bvh_intersect(kg, ray, isect, visibility);
# endif /* __INSTANCING__ */
# endif /* __KERNEL_CPU__ */
#endif /* __KERNEL_OPTIX__ */
#endif /* __KERNEL_OPTIX__ */
}
#ifdef __BVH_LOCAL__
@ -476,21 +439,8 @@ ccl_device_intersect bool scene_intersect_shadow_all(KernelGlobals *kg,
}
# endif /* __HAIR__ */
# ifdef __KERNEL_CPU__
# ifdef __INSTANCING__
if (kernel_data.bvh.have_instancing) {
return bvh_intersect_shadow_all_instancing(kg, ray, isect, visibility, max_hits, num_hits);
}
# endif /* __INSTANCING__ */
return bvh_intersect_shadow_all(kg, ray, isect, visibility, max_hits, num_hits);
# else
# ifdef __INSTANCING__
return bvh_intersect_shadow_all_instancing(kg, ray, isect, visibility, max_hits, num_hits);
# else
return bvh_intersect_shadow_all(kg, ray, isect, visibility, max_hits, num_hits);
# endif /* __INSTANCING__ */
# endif /* __KERNEL_CPU__ */
# endif /* __KERNEL_OPTIX__ */
# endif /* __KERNEL_OPTIX__ */
}
#endif /* __SHADOW_RECORD_ALL__ */
@ -548,21 +498,8 @@ ccl_device_intersect bool scene_intersect_volume(KernelGlobals *kg,
}
# endif /* __OBJECT_MOTION__ */
# ifdef __KERNEL_CPU__
# ifdef __INSTANCING__
if (kernel_data.bvh.have_instancing) {
return bvh_intersect_volume_instancing(kg, ray, isect, visibility);
}
# endif /* __INSTANCING__ */
return bvh_intersect_volume(kg, ray, isect, visibility);
# else /* __KERNEL_CPU__ */
# ifdef __INSTANCING__
return bvh_intersect_volume_instancing(kg, ray, isect, visibility);
# else
return bvh_intersect_volume(kg, ray, isect, visibility);
# endif /* __INSTANCING__ */
# endif /* __KERNEL_CPU__ */
# endif /* __KERNEL_OPTIX__ */
# endif /* __KERNEL_OPTIX__ */
}
#endif /* __VOLUME__ */
@ -599,11 +536,6 @@ ccl_device_intersect uint scene_intersect_volume_all(KernelGlobals *kg,
}
# endif /* __OBJECT_MOTION__ */
# ifdef __INSTANCING__
if (kernel_data.bvh.have_instancing) {
return bvh_intersect_volume_all_instancing(kg, ray, isect, max_hits, visibility);
}
# endif /* __INSTANCING__ */
return bvh_intersect_volume_all(kg, ray, isect, max_hits, visibility);
}
#endif /* __VOLUME_RECORD_ALL__ */

@ -34,7 +34,6 @@
* enabled/disabled. This way we can compile optimized versions for each case
* without new features slowing things down.
*
* BVH_INSTANCING: object instancing
* BVH_HAIR: hair curve rendering
* BVH_MOTION: motion blur rendering
*/
@ -76,9 +75,7 @@ ccl_device_inline
Transform ob_itfm;
#endif
#if BVH_FEATURE(BVH_INSTANCING)
int num_hits_in_instance = 0;
#endif
*num_hits = 0;
isect_array->t = tmax;
@ -174,9 +171,7 @@ ccl_device_inline
float4 leaf = kernel_tex_fetch(__bvh_leaf_nodes, (-node_addr - 1));
int prim_addr = __float_as_int(leaf.x);
#if BVH_FEATURE(BVH_INSTANCING)
if (prim_addr >= 0) {
#endif
const int prim_addr2 = __float_as_int(leaf.y);
const uint type = __float_as_int(leaf.w);
const uint p_type = type & PRIMITIVE_ALL;
@ -256,9 +251,7 @@ ccl_device_inline
/* move on to next entry in intersections array */
isect_array++;
(*num_hits)++;
#if BVH_FEATURE(BVH_INSTANCING)
num_hits_in_instance++;
#endif
isect_array->t = isect_t;
}
@ -266,16 +259,15 @@ ccl_device_inline
prim_addr++;
}
}
#if BVH_FEATURE(BVH_INSTANCING)
else {
/* instance push */
object = kernel_tex_fetch(__prim_object, -prim_addr - 1);
# if BVH_FEATURE(BVH_MOTION)
#if BVH_FEATURE(BVH_MOTION)
isect_t = bvh_instance_motion_push(kg, object, ray, &P, &dir, &idir, isect_t, &ob_itfm);
# else
#else
isect_t = bvh_instance_push(kg, object, ray, &P, &dir, &idir, isect_t);
# endif
#endif
num_hits_in_instance = 0;
isect_array->t = isect_t;
@ -299,10 +291,8 @@ ccl_device_inline
node_addr = kernel_tex_fetch(__object_node, object);
}
}
#endif /* FEATURE(BVH_INSTANCING) */
} while (node_addr != ENTRYPOINT_SENTINEL);
#if BVH_FEATURE(BVH_INSTANCING)
if (stack_ptr >= 0) {
kernel_assert(object != OBJECT_NONE);
@ -310,11 +300,11 @@ ccl_device_inline
if (num_hits_in_instance) {
float t_fac;
# if BVH_FEATURE(BVH_MOTION)
#if BVH_FEATURE(BVH_MOTION)
bvh_instance_motion_pop_factor(kg, object, ray, &P, &dir, &idir, &t_fac, &ob_itfm);
# else
#else
bvh_instance_pop_factor(kg, object, ray, &P, &dir, &idir, &t_fac);
# endif
#endif
/* scale isect->t to adjust for instancing */
for (int i = 0; i < num_hits_in_instance; i++) {
@ -322,11 +312,11 @@ ccl_device_inline
}
}
else {
# if BVH_FEATURE(BVH_MOTION)
#if BVH_FEATURE(BVH_MOTION)
bvh_instance_motion_pop(kg, object, ray, &P, &dir, &idir, FLT_MAX, &ob_itfm);
# else
#else
bvh_instance_pop(kg, object, ray, &P, &dir, &idir, FLT_MAX);
# endif
#endif
}
isect_t = tmax;
@ -348,7 +338,6 @@ ccl_device_inline
node_addr = traversal_stack[stack_ptr];
--stack_ptr;
}
#endif /* FEATURE(BVH_INSTANCING) */
} while (node_addr != ENTRYPOINT_SENTINEL);
return false;

@ -34,7 +34,6 @@
* enabled/disabled. This way we can compile optimized versions for each case
* without new features slowing things down.
*
* BVH_INSTANCING: object instancing
* BVH_HAIR: hair curve rendering
* BVH_MOTION: motion blur rendering
*/
@ -173,9 +172,7 @@ ccl_device_noinline bool BVH_FUNCTION_FULL_NAME(BVH)(KernelGlobals *kg,
float4 leaf = kernel_tex_fetch(__bvh_leaf_nodes, (-node_addr - 1));
int prim_addr = __float_as_int(leaf.x);
#if BVH_FEATURE(BVH_INSTANCING)
if (prim_addr >= 0) {
#endif
const int prim_addr2 = __float_as_int(leaf.y);
const uint type = __float_as_int(leaf.w);
@ -259,17 +256,16 @@ ccl_device_noinline bool BVH_FUNCTION_FULL_NAME(BVH)(KernelGlobals *kg,
#endif /* BVH_FEATURE(BVH_HAIR) */
}
}
#if BVH_FEATURE(BVH_INSTANCING)
else {
/* instance push */
object = kernel_tex_fetch(__prim_object, -prim_addr - 1);
# if BVH_FEATURE(BVH_MOTION)
#if BVH_FEATURE(BVH_MOTION)
isect->t = bvh_instance_motion_push(
kg, object, ray, &P, &dir, &idir, isect->t, &ob_itfm);
# else
#else
isect->t = bvh_instance_push(kg, object, ray, &P, &dir, &idir, isect->t);
# endif
#endif
# if defined(__KERNEL_SSE2__)
Psplat[0] = ssef(P.x);
@ -293,19 +289,17 @@ ccl_device_noinline bool BVH_FUNCTION_FULL_NAME(BVH)(KernelGlobals *kg,
BVH_DEBUG_NEXT_INSTANCE();
}
}
#endif /* FEATURE(BVH_INSTANCING) */
} while (node_addr != ENTRYPOINT_SENTINEL);
#if BVH_FEATURE(BVH_INSTANCING)
if (stack_ptr >= 0) {
kernel_assert(object != OBJECT_NONE);
/* instance pop */
# if BVH_FEATURE(BVH_MOTION)
#if BVH_FEATURE(BVH_MOTION)
isect->t = bvh_instance_motion_pop(kg, object, ray, &P, &dir, &idir, isect->t, &ob_itfm);
# else
#else
isect->t = bvh_instance_pop(kg, object, ray, &P, &dir, &idir, isect->t);
# endif
#endif
# if defined(__KERNEL_SSE2__)
Psplat[0] = ssef(P.x);
@ -324,7 +318,6 @@ ccl_device_noinline bool BVH_FUNCTION_FULL_NAME(BVH)(KernelGlobals *kg,
node_addr = traversal_stack[stack_ptr];
--stack_ptr;
}
#endif /* FEATURE(BVH_INSTANCING) */
} while (node_addr != ENTRYPOINT_SENTINEL);
return (isect->prim != PRIM_NONE);

@ -35,9 +35,8 @@ CCL_NAMESPACE_BEGIN
#define BVH_OSTACK_SIZE 768
/* BVH intersection function variations */
#define BVH_INSTANCING 1
#define BVH_MOTION 2
#define BVH_HAIR 4
#define BVH_MOTION 1
#define BVH_HAIR 2
#define BVH_NAME_JOIN(x, y) x##_##y
#define BVH_NAME_EVAL(x, y) BVH_NAME_JOIN(x, y)

@ -34,7 +34,6 @@
* various features can be enabled/disabled. This way we can compile optimized
* versions for each case without new features slowing things down.
*
* BVH_INSTANCING: object instancing
* BVH_MOTION: motion blur rendering
*/
@ -170,9 +169,7 @@ ccl_device_inline
float4 leaf = kernel_tex_fetch(__bvh_leaf_nodes, (-node_addr - 1));
int prim_addr = __float_as_int(leaf.x);
#if BVH_FEATURE(BVH_INSTANCING)
if (prim_addr >= 0) {
#endif
const int prim_addr2 = __float_as_int(leaf.y);
const uint type = __float_as_int(leaf.w);
@ -222,18 +219,17 @@ ccl_device_inline
}
}
}
#if BVH_FEATURE(BVH_INSTANCING)
else {
/* instance push */
object = kernel_tex_fetch(__prim_object, -prim_addr - 1);
int object_flag = kernel_tex_fetch(__object_flag, object);
if (object_flag & SD_OBJECT_HAS_VOLUME) {
# if BVH_FEATURE(BVH_MOTION)
#if BVH_FEATURE(BVH_MOTION)
isect->t = bvh_instance_motion_push(
kg, object, ray, &P, &dir, &idir, isect->t, &ob_itfm);
# else
#else
isect->t = bvh_instance_push(kg, object, ray, &P, &dir, &idir, isect->t);
# endif
#endif
# if defined(__KERNEL_SSE2__)
Psplat[0] = ssef(P.x);
@ -262,19 +258,17 @@ ccl_device_inline
}
}
}
#endif /* FEATURE(BVH_INSTANCING) */
} while (node_addr != ENTRYPOINT_SENTINEL);
#if BVH_FEATURE(BVH_INSTANCING)
if (stack_ptr >= 0) {
kernel_assert(object != OBJECT_NONE);
/* instance pop */
# if BVH_FEATURE(BVH_MOTION)
#if BVH_FEATURE(BVH_MOTION)
isect->t = bvh_instance_motion_pop(kg, object, ray, &P, &dir, &idir, isect->t, &ob_itfm);
# else
#else
isect->t = bvh_instance_pop(kg, object, ray, &P, &dir, &idir, isect->t);
# endif
#endif
# if defined(__KERNEL_SSE2__)
Psplat[0] = ssef(P.x);
@ -293,7 +287,6 @@ ccl_device_inline
node_addr = traversal_stack[stack_ptr];
--stack_ptr;
}
#endif /* FEATURE(BVH_MOTION) */
} while (node_addr != ENTRYPOINT_SENTINEL);
return (isect->prim != PRIM_NONE);

@ -34,7 +34,6 @@
* various features can be enabled/disabled. This way we can compile optimized
* versions for each case without new features slowing things down.
*
* BVH_INSTANCING: object instancing
* BVH_MOTION: motion blur rendering
*/
@ -76,9 +75,7 @@ ccl_device_inline
Transform ob_itfm;
#endif
#if BVH_FEATURE(BVH_INSTANCING)
int num_hits_in_instance = 0;
#endif
uint num_hits = 0;
isect_array->t = tmax;
@ -174,9 +171,7 @@ ccl_device_inline
float4 leaf = kernel_tex_fetch(__bvh_leaf_nodes, (-node_addr - 1));
int prim_addr = __float_as_int(leaf.x);
#if BVH_FEATURE(BVH_INSTANCING)
if (prim_addr >= 0) {
#endif
const int prim_addr2 = __float_as_int(leaf.y);
const uint type = __float_as_int(leaf.w);
bool hit;
@ -204,25 +199,21 @@ ccl_device_inline
/* Move on to next entry in intersections array. */
isect_array++;
num_hits++;
#if BVH_FEATURE(BVH_INSTANCING)
num_hits_in_instance++;
#endif
isect_array->t = isect_t;
if (num_hits == max_hits) {
#if BVH_FEATURE(BVH_INSTANCING)
if (object != OBJECT_NONE) {
# if BVH_FEATURE(BVH_MOTION)
#if BVH_FEATURE(BVH_MOTION)
float t_fac = 1.0f / len(transform_direction(&ob_itfm, dir));
# else
#else
Transform itfm = object_fetch_transform(
kg, object, OBJECT_INVERSE_TRANSFORM);
float t_fac = 1.0f / len(transform_direction(&itfm, dir));
# endif
#endif
for (int i = 0; i < num_hits_in_instance; i++) {
(isect_array - i - 1)->t *= t_fac;
}
}
#endif /* BVH_FEATURE(BVH_INSTANCING) */
return num_hits;
}
}
@ -248,25 +239,21 @@ ccl_device_inline
/* Move on to next entry in intersections array. */
isect_array++;
num_hits++;
# if BVH_FEATURE(BVH_INSTANCING)
num_hits_in_instance++;
# endif
isect_array->t = isect_t;
if (num_hits == max_hits) {
# if BVH_FEATURE(BVH_INSTANCING)
if (object != OBJECT_NONE) {
# if BVH_FEATURE(BVH_MOTION)
# if BVH_FEATURE(BVH_MOTION)
float t_fac = 1.0f / len(transform_direction(&ob_itfm, dir));
# else
# else
Transform itfm = object_fetch_transform(
kg, object, OBJECT_INVERSE_TRANSFORM);
float t_fac = 1.0f / len(transform_direction(&itfm, dir));
# endif
# endif
for (int i = 0; i < num_hits_in_instance; i++) {
(isect_array - i - 1)->t *= t_fac;
}
}
# endif /* BVH_FEATURE(BVH_INSTANCING) */
return num_hits;
}
}
@ -279,18 +266,17 @@ ccl_device_inline
}
}
}
#if BVH_FEATURE(BVH_INSTANCING)
else {
/* instance push */
object = kernel_tex_fetch(__prim_object, -prim_addr - 1);
int object_flag = kernel_tex_fetch(__object_flag, object);
if (object_flag & SD_OBJECT_HAS_VOLUME) {
# if BVH_FEATURE(BVH_MOTION)
#if BVH_FEATURE(BVH_MOTION)
isect_t = bvh_instance_motion_push(
kg, object, ray, &P, &dir, &idir, isect_t, &ob_itfm);
# else
#else
isect_t = bvh_instance_push(kg, object, ray, &P, &dir, &idir, isect_t);
# endif
#endif
num_hits_in_instance = 0;
isect_array->t = isect_t;
@ -322,32 +308,30 @@ ccl_device_inline
}
}
}
#endif /* FEATURE(BVH_INSTANCING) */
} while (node_addr != ENTRYPOINT_SENTINEL);
#if BVH_FEATURE(BVH_INSTANCING)
if (stack_ptr >= 0) {
kernel_assert(object != OBJECT_NONE);
/* Instance pop. */
if (num_hits_in_instance) {
float t_fac;
# if BVH_FEATURE(BVH_MOTION)
#if BVH_FEATURE(BVH_MOTION)
bvh_instance_motion_pop_factor(kg, object, ray, &P, &dir, &idir, &t_fac, &ob_itfm);
# else
#else
bvh_instance_pop_factor(kg, object, ray, &P, &dir, &idir, &t_fac);
# endif
#endif
/* Scale isect->t to adjust for instancing. */
for (int i = 0; i < num_hits_in_instance; i++) {
(isect_array - i - 1)->t *= t_fac;
}
}
else {
# if BVH_FEATURE(BVH_MOTION)
#if BVH_FEATURE(BVH_MOTION)
bvh_instance_motion_pop(kg, object, ray, &P, &dir, &idir, FLT_MAX, &ob_itfm);
# else
#else
bvh_instance_pop(kg, object, ray, &P, &dir, &idir, FLT_MAX);
# endif
#endif
}
isect_t = tmax;
@ -370,7 +354,6 @@ ccl_device_inline
node_addr = traversal_stack[stack_ptr];
--stack_ptr;
}
#endif /* FEATURE(BVH_INSTANCING) */
} while (node_addr != ENTRYPOINT_SENTINEL);
return num_hits;

@ -529,10 +529,8 @@ ccl_device_inline float3 curve_refine(KernelGlobals *kg,
P = P + D * t;
# ifdef __UV__
sd->u = isect->u;
sd->v = 0.0f;
# endif
float3 tg = normalize(curvetangent(isect->u, p[0], p[1], p[2], p[3]));

@ -313,20 +313,18 @@ ccl_device_inline bool triangle_world_space_vertices(
triangle_vertices(kg, prim, V);
}
#ifdef __INSTANCING__
if (!(object_flag & SD_OBJECT_TRANSFORM_APPLIED)) {
# ifdef __OBJECT_MOTION__
#ifdef __OBJECT_MOTION__
float object_time = (time >= 0.0f) ? time : 0.5f;
Transform tfm = object_fetch_transform_motion_test(kg, object, object_time, NULL);
# else
#else
Transform tfm = object_fetch_transform(kg, object, OBJECT_TRANSFORM);
# endif
#endif
V[0] = transform_point(&tfm, V[0]);
V[1] = transform_point(&tfm, V[1]);
V[2] = transform_point(&tfm, V[2]);
has_motion = true;
}
#endif
return has_motion;
}

@ -63,10 +63,8 @@ ccl_device_noinline
{
PROFILING_INIT(kg, PROFILING_SHADER_SETUP);
#ifdef __INSTANCING__
sd->object = (isect->object == OBJECT_NONE) ? kernel_tex_fetch(__prim_object, isect->prim) :
isect->object;
#endif
sd->lamp = LAMP_NONE;
sd->type = isect->type;
@ -82,10 +80,8 @@ ccl_device_noinline
sd->prim = kernel_tex_fetch(__prim_index, isect->prim);
sd->ray_length = isect->t;
#ifdef __UV__
sd->u = isect->u;
sd->v = isect->v;
#endif
#ifdef __HAIR__
if (sd->type & PRIMITIVE_ALL_CURVE) {
@ -125,17 +121,15 @@ ccl_device_noinline
sd->flag |= kernel_tex_fetch(__shaders, (sd->shader & SHADER_MASK)).flags;
#ifdef __INSTANCING__
if (isect->object != OBJECT_NONE) {
/* instance transform */
object_normal_transform_auto(kg, sd, &sd->N);
object_normal_transform_auto(kg, sd, &sd->Ng);
# ifdef __DPDU__
#ifdef __DPDU__
object_dir_transform_auto(kg, sd, &sd->dPdu);
object_dir_transform_auto(kg, sd, &sd->dPdv);
# endif
}
#endif
}
/* backfacing test */
bool backfacing = (dot(sd->Ng, sd->I) < 0.0f);
@ -185,10 +179,8 @@ ccl_device_inline
sd->prim = kernel_tex_fetch(__prim_index, isect->prim);
sd->type = isect->type;
# ifdef __UV__
sd->u = isect->u;
sd->v = isect->v;
# endif
/* fetch triangle data */
if (sd->type == PRIMITIVE_TRIANGLE) {
@ -215,17 +207,15 @@ ccl_device_inline
sd->flag |= kernel_tex_fetch(__shaders, (sd->shader & SHADER_MASK)).flags;
# ifdef __INSTANCING__
if (isect->object != OBJECT_NONE) {
/* instance transform */
object_normal_transform_auto(kg, sd, &sd->N);
object_normal_transform_auto(kg, sd, &sd->Ng);
# ifdef __DPDU__
# ifdef __DPDU__
object_dir_transform_auto(kg, sd, &sd->dPdu);
object_dir_transform_auto(kg, sd, &sd->dPdv);
# endif
}
# endif
}
/* backfacing test */
if (backfacing) {
@ -284,17 +274,13 @@ ccl_device_inline void shader_setup_from_sample(KernelGlobals *kg,
else
sd->type = PRIMITIVE_NONE;
/* primitive */
#ifdef __INSTANCING__
/* primitive */
sd->object = object;
#endif
sd->lamp = LAMP_NONE;
/* currently no access to bvh prim index for strand sd->prim*/
sd->prim = prim;
#ifdef __UV__
sd->u = u;
sd->v = v;
#endif
sd->time = time;
sd->ray_length = t;
@ -330,23 +316,19 @@ ccl_device_inline void shader_setup_from_sample(KernelGlobals *kg,
if (sd->shader & SHADER_SMOOTH_NORMAL) {
sd->N = triangle_smooth_normal(kg, Ng, sd->prim, sd->u, sd->v);
#ifdef __INSTANCING__
if (!(sd->object_flag & SD_OBJECT_TRANSFORM_APPLIED)) {
object_normal_transform_auto(kg, sd, &sd->N);
}
#endif
}
/* dPdu/dPdv */
#ifdef __DPDU__
triangle_dPdudv(kg, sd->prim, &sd->dPdu, &sd->dPdv);
# ifdef __INSTANCING__
if (!(sd->object_flag & SD_OBJECT_TRANSFORM_APPLIED)) {
object_dir_transform_auto(kg, sd, &sd->dPdu);
object_dir_transform_auto(kg, sd, &sd->dPdv);
}
# endif
#endif
}
else {
@ -432,15 +414,11 @@ ccl_device_inline void shader_setup_from_background(KernelGlobals *kg,
sd->time = ray->time;
sd->ray_length = 0.0f;
#ifdef __INSTANCING__
sd->object = OBJECT_NONE;
#endif
sd->lamp = LAMP_NONE;
sd->prim = PRIM_NONE;
#ifdef __UV__
sd->u = 0.0f;
sd->v = 0.0f;
#endif
#ifdef __DPDU__
/* dPdu/dPdv */
@ -481,17 +459,13 @@ ccl_device_inline void shader_setup_from_volume(KernelGlobals *kg, ShaderData *s
sd->time = ray->time;
sd->ray_length = 0.0f; /* todo: can we set this to some useful value? */
# ifdef __INSTANCING__
sd->object = OBJECT_NONE; /* todo: fill this for texture coordinates */
# endif
sd->lamp = LAMP_NONE;
sd->prim = PRIM_NONE;
sd->type = PRIMITIVE_NONE;
# ifdef __UV__
sd->u = 0.0f;
sd->v = 0.0f;
# endif
# ifdef __DPDU__
/* dPdu/dPdv */

@ -84,9 +84,7 @@ CCL_NAMESPACE_BEGIN
/* Kernel features */
#define __SOBOL__
#define __INSTANCING__
#define __DPDU__
#define __UV__
#define __BACKGROUND__
#define __CAUSTICS_TRICKS__
#define __VISIBILITY_FLAG__
@ -1406,9 +1404,9 @@ typedef struct KernelBVH {
int root;
int have_motion;
int have_curves;
int have_instancing;
int bvh_layout;
int use_bvh_steps;
int pad;
/* Custom BVH */
#ifdef __KERNEL_OPTIX__

@ -41,11 +41,9 @@ ccl_device_inline void svm_node_geometry(
case NODE_GEOM_Ng:
data = sd->Ng;
break;
#ifdef __UV__
case NODE_GEOM_uv:
data = make_float3(sd->u, sd->v, 0.0f);
break;
#endif
default:
data = make_float3(0.0f, 0.0f, 0.0f);
}

@ -616,7 +616,6 @@ void ObjectManager::device_update_transforms(DeviceScene *dscene, Scene *scene,
dscene->data.bvh.have_motion = state.have_motion;
dscene->data.bvh.have_curves = state.have_curves;
dscene->data.bvh.have_instancing = true;
}
void ObjectManager::device_update(Device *device,
@ -791,7 +790,6 @@ void ObjectManager::apply_static_transforms(DeviceScene *dscene, Scene *scene, P
bool motion_blur = need_motion == Scene::MOTION_BLUR;
bool apply_to_motion = need_motion != Scene::MOTION_PASS;
int i = 0;
bool have_instancing = false;
foreach (Object *object, scene->objects) {
map<Geometry *, int>::iterator it = geometry_users.find(object->geometry);
@ -837,16 +835,10 @@ void ObjectManager::apply_static_transforms(DeviceScene *dscene, Scene *scene, P
if (geom->transform_negative_scaled)
object_flag[i] |= SD_OBJECT_NEGATIVE_SCALE_APPLIED;
}
else
have_instancing = true;
}
else
have_instancing = true;
i++;
}
dscene->data.bvh.have_instancing = have_instancing;
}
void ObjectManager::tag_update(Scene *scene)