Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/intern
diff options
context:
space:
mode:
authorBrecht Van Lommel <brecht@blender.org>2020-10-26 21:25:00 +0300
committerBrecht Van Lommel <brecht@blender.org>2020-10-28 14:43:42 +0300
commit0767683496f5c846edb5a068d8ad9b59a351d2e9 (patch)
tree6b258e57a24cf67cc32fb1e444ee8ee1bed422d9 /intern
parentd58b55b55a0197c397810766446f18d64a8d4a6b (diff)
Cycles: refactor to make attribute lookup slightly more efficient
Ref D2057
Diffstat (limited to 'intern')
-rw-r--r--intern/cycles/kernel/geom/geom_curve.h144
-rw-r--r--intern/cycles/kernel/geom/geom_triangle.h252
-rw-r--r--intern/cycles/kernel/kernel_types.h24
3 files changed, 147 insertions, 273 deletions
diff --git a/intern/cycles/kernel/geom/geom_curve.h b/intern/cycles/kernel/geom/geom_curve.h
index 6ff0c7f2044..b5a62a31ca9 100644
--- a/intern/cycles/kernel/geom/geom_curve.h
+++ b/intern/cycles/kernel/geom/geom_curve.h
@@ -28,18 +28,7 @@ CCL_NAMESPACE_BEGIN
ccl_device float curve_attribute_float(
KernelGlobals *kg, const ShaderData *sd, const AttributeDescriptor desc, float *dx, float *dy)
{
- if (desc.element == ATTR_ELEMENT_CURVE) {
-# ifdef __RAY_DIFFERENTIALS__
- if (dx)
- *dx = 0.0f;
- if (dy)
- *dy = 0.0f;
-# endif
-
- return kernel_tex_fetch(__attributes_float, desc.offset + sd->prim);
- }
- else if (desc.element == ATTR_ELEMENT_CURVE_KEY ||
- desc.element == ATTR_ELEMENT_CURVE_KEY_MOTION) {
+ if (desc.element & (ATTR_ELEMENT_CURVE_KEY | ATTR_ELEMENT_CURVE_KEY_MOTION)) {
float4 curvedata = kernel_tex_fetch(__curves, sd->prim);
int k0 = __float_as_int(curvedata.x) + PRIMITIVE_UNPACK_SEGMENT(sd->type);
int k1 = k0 + 1;
@@ -56,16 +45,6 @@ ccl_device float curve_attribute_float(
return (1.0f - sd->u) * f0 + sd->u * f1;
}
- else if (desc.element == ATTR_ELEMENT_OBJECT || desc.element == ATTR_ELEMENT_MESH) {
-# ifdef __RAY_DIFFERENTIALS__
- if (dx)
- *dx = 0.0f;
- if (dy)
- *dy = 0.0f;
-# endif
-
- return kernel_tex_fetch(__attributes_float, desc.offset);
- }
else {
# ifdef __RAY_DIFFERENTIALS__
if (dx)
@@ -74,7 +53,14 @@ ccl_device float curve_attribute_float(
*dy = 0.0f;
# endif
- return 0.0f;
+ if (desc.element & (ATTR_ELEMENT_CURVE | ATTR_ELEMENT_OBJECT | ATTR_ELEMENT_MESH)) {
+ const int offset = (desc.element == ATTR_ELEMENT_CURVE) ? desc.offset + sd->prim :
+ desc.offset;
+ return kernel_tex_fetch(__attributes_float, offset);
+ }
+ else {
+ return 0.0f;
+ }
}
}
@@ -84,22 +70,7 @@ ccl_device float2 curve_attribute_float2(KernelGlobals *kg,
float2 *dx,
float2 *dy)
{
- if (desc.element == ATTR_ELEMENT_CURVE) {
- /* idea: we can't derive any useful differentials here, but for tiled
- * mipmap image caching it would be useful to avoid reading the highest
- * detail level always. maybe a derivative based on the hair density
- * could be computed somehow? */
-# ifdef __RAY_DIFFERENTIALS__
- if (dx)
- *dx = make_float2(0.0f, 0.0f);
- if (dy)
- *dy = make_float2(0.0f, 0.0f);
-# endif
-
- return kernel_tex_fetch(__attributes_float2, desc.offset + sd->prim);
- }
- else if (desc.element == ATTR_ELEMENT_CURVE_KEY ||
- desc.element == ATTR_ELEMENT_CURVE_KEY_MOTION) {
+ if (desc.element & (ATTR_ELEMENT_CURVE_KEY | ATTR_ELEMENT_CURVE_KEY_MOTION)) {
float4 curvedata = kernel_tex_fetch(__curves, sd->prim);
int k0 = __float_as_int(curvedata.x) + PRIMITIVE_UNPACK_SEGMENT(sd->type);
int k1 = k0 + 1;
@@ -116,17 +87,11 @@ ccl_device float2 curve_attribute_float2(KernelGlobals *kg,
return (1.0f - sd->u) * f0 + sd->u * f1;
}
- else if (desc.element == ATTR_ELEMENT_OBJECT || desc.element == ATTR_ELEMENT_MESH) {
-# ifdef __RAY_DIFFERENTIALS__
- if (dx)
- *dx = make_float2(0.0f, 0.0f);
- if (dy)
- *dy = make_float2(0.0f, 0.0f);
-# endif
-
- return kernel_tex_fetch(__attributes_float2, desc.offset);
- }
else {
+ /* idea: we can't derive any useful differentials here, but for tiled
+ * mipmap image caching it would be useful to avoid reading the highest
+ * detail level always. maybe a derivative based on the hair density
+ * could be computed somehow? */
# ifdef __RAY_DIFFERENTIALS__
if (dx)
*dx = make_float2(0.0f, 0.0f);
@@ -134,7 +99,14 @@ ccl_device float2 curve_attribute_float2(KernelGlobals *kg,
*dy = make_float2(0.0f, 0.0f);
# endif
- return make_float2(0.0f, 0.0f);
+ if (desc.element & (ATTR_ELEMENT_CURVE | ATTR_ELEMENT_OBJECT | ATTR_ELEMENT_MESH)) {
+ const int offset = (desc.element == ATTR_ELEMENT_CURVE) ? desc.offset + sd->prim :
+ desc.offset;
+ return kernel_tex_fetch(__attributes_float2, offset);
+ }
+ else {
+ return make_float2(0.0f, 0.0f);
+ }
}
}
@@ -144,22 +116,7 @@ ccl_device float3 curve_attribute_float3(KernelGlobals *kg,
float3 *dx,
float3 *dy)
{
- if (desc.element == ATTR_ELEMENT_CURVE) {
- /* idea: we can't derive any useful differentials here, but for tiled
- * mipmap image caching it would be useful to avoid reading the highest
- * detail level always. maybe a derivative based on the hair density
- * could be computed somehow? */
-# ifdef __RAY_DIFFERENTIALS__
- if (dx)
- *dx = make_float3(0.0f, 0.0f, 0.0f);
- if (dy)
- *dy = make_float3(0.0f, 0.0f, 0.0f);
-# endif
-
- return float4_to_float3(kernel_tex_fetch(__attributes_float3, desc.offset + sd->prim));
- }
- else if (desc.element == ATTR_ELEMENT_CURVE_KEY ||
- desc.element == ATTR_ELEMENT_CURVE_KEY_MOTION) {
+ if (desc.element & (ATTR_ELEMENT_CURVE_KEY | ATTR_ELEMENT_CURVE_KEY_MOTION)) {
float4 curvedata = kernel_tex_fetch(__curves, sd->prim);
int k0 = __float_as_int(curvedata.x) + PRIMITIVE_UNPACK_SEGMENT(sd->type);
int k1 = k0 + 1;
@@ -176,16 +133,6 @@ ccl_device float3 curve_attribute_float3(KernelGlobals *kg,
return (1.0f - sd->u) * f0 + sd->u * f1;
}
- else if (desc.element == ATTR_ELEMENT_OBJECT || desc.element == ATTR_ELEMENT_MESH) {
-# ifdef __RAY_DIFFERENTIALS__
- if (dx)
- *dx = make_float3(0.0f, 0.0f, 0.0f);
- if (dy)
- *dy = make_float3(0.0f, 0.0f, 0.0f);
-# endif
-
- return float4_to_float3(kernel_tex_fetch(__attributes_float3, desc.offset));
- }
else {
# ifdef __RAY_DIFFERENTIALS__
if (dx)
@@ -194,7 +141,14 @@ ccl_device float3 curve_attribute_float3(KernelGlobals *kg,
*dy = make_float3(0.0f, 0.0f, 0.0f);
# endif
- return make_float3(0.0f, 0.0f, 0.0f);
+ if (desc.element & (ATTR_ELEMENT_CURVE | ATTR_ELEMENT_OBJECT | ATTR_ELEMENT_MESH)) {
+ const int offset = (desc.element == ATTR_ELEMENT_CURVE) ? desc.offset + sd->prim :
+ desc.offset;
+ return float4_to_float3(kernel_tex_fetch(__attributes_float3, offset));
+ }
+ else {
+ return make_float3(0.0f, 0.0f, 0.0f);
+ }
}
}
@@ -204,22 +158,7 @@ ccl_device float4 curve_attribute_float4(KernelGlobals *kg,
float4 *dx,
float4 *dy)
{
- if (desc.element == ATTR_ELEMENT_CURVE) {
- /* idea: we can't derive any useful differentials here, but for tiled
- * mipmap image caching it would be useful to avoid reading the highest
- * detail level always. maybe a derivative based on the hair density
- * could be computed somehow? */
-# ifdef __RAY_DIFFERENTIALS__
- if (dx)
- *dx = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
- if (dy)
- *dy = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
-# endif
-
- return kernel_tex_fetch(__attributes_float3, desc.offset + sd->prim);
- }
- else if (desc.element == ATTR_ELEMENT_CURVE_KEY ||
- desc.element == ATTR_ELEMENT_CURVE_KEY_MOTION) {
+ if (desc.element & (ATTR_ELEMENT_CURVE_KEY | ATTR_ELEMENT_CURVE_KEY_MOTION)) {
float4 curvedata = kernel_tex_fetch(__curves, sd->prim);
int k0 = __float_as_int(curvedata.x) + PRIMITIVE_UNPACK_SEGMENT(sd->type);
int k1 = k0 + 1;
@@ -236,16 +175,6 @@ ccl_device float4 curve_attribute_float4(KernelGlobals *kg,
return (1.0f - sd->u) * f0 + sd->u * f1;
}
- else if (desc.element == ATTR_ELEMENT_OBJECT || desc.element == ATTR_ELEMENT_MESH) {
-# ifdef __RAY_DIFFERENTIALS__
- if (dx)
- *dx = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
- if (dy)
- *dy = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
-# endif
-
- return kernel_tex_fetch(__attributes_float3, desc.offset);
- }
else {
# ifdef __RAY_DIFFERENTIALS__
if (dx)
@@ -254,7 +183,14 @@ ccl_device float4 curve_attribute_float4(KernelGlobals *kg,
*dy = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
# endif
- return make_float4(0.0f, 0.0f, 0.0f, 0.0f);
+ if (desc.element & (ATTR_ELEMENT_CURVE | ATTR_ELEMENT_OBJECT | ATTR_ELEMENT_MESH)) {
+ const int offset = (desc.element == ATTR_ELEMENT_CURVE) ? desc.offset + sd->prim :
+ desc.offset;
+ return kernel_tex_fetch(__attributes_float3, offset);
+ }
+ else {
+ return make_float4(0.0f, 0.0f, 0.0f, 0.0f);
+ }
}
}
diff --git a/intern/cycles/kernel/geom/geom_triangle.h b/intern/cycles/kernel/geom/geom_triangle.h
index 45fd761b13f..2d9da23371e 100644
--- a/intern/cycles/kernel/geom/geom_triangle.h
+++ b/intern/cycles/kernel/geom/geom_triangle.h
@@ -114,35 +114,21 @@ ccl_device_inline void triangle_dPdudv(KernelGlobals *kg,
ccl_device float triangle_attribute_float(
KernelGlobals *kg, const ShaderData *sd, const AttributeDescriptor desc, float *dx, float *dy)
{
- if (desc.element == ATTR_ELEMENT_FACE) {
- if (dx)
- *dx = 0.0f;
- if (dy)
- *dy = 0.0f;
-
- return kernel_tex_fetch(__attributes_float, desc.offset + sd->prim);
- }
- else if (desc.element == ATTR_ELEMENT_VERTEX || desc.element == ATTR_ELEMENT_VERTEX_MOTION) {
- uint4 tri_vindex = kernel_tex_fetch(__tri_vindex, sd->prim);
-
- float f0 = kernel_tex_fetch(__attributes_float, desc.offset + tri_vindex.x);
- float f1 = kernel_tex_fetch(__attributes_float, desc.offset + tri_vindex.y);
- float f2 = kernel_tex_fetch(__attributes_float, desc.offset + tri_vindex.z);
-
-#ifdef __RAY_DIFFERENTIALS__
- if (dx)
- *dx = sd->du.dx * f0 + sd->dv.dx * f1 - (sd->du.dx + sd->dv.dx) * f2;
- if (dy)
- *dy = sd->du.dy * f0 + sd->dv.dy * f1 - (sd->du.dy + sd->dv.dy) * f2;
-#endif
-
- return sd->u * f0 + sd->v * f1 + (1.0f - sd->u - sd->v) * f2;
- }
- else if (desc.element == ATTR_ELEMENT_CORNER) {
- int tri = desc.offset + sd->prim * 3;
- float f0 = kernel_tex_fetch(__attributes_float, tri + 0);
- float f1 = kernel_tex_fetch(__attributes_float, tri + 1);
- float f2 = kernel_tex_fetch(__attributes_float, tri + 2);
+ if (desc.element & (ATTR_ELEMENT_VERTEX | ATTR_ELEMENT_VERTEX_MOTION | ATTR_ELEMENT_CORNER)) {
+ float f0, f1, f2;
+
+ if (desc.element & (ATTR_ELEMENT_VERTEX | ATTR_ELEMENT_VERTEX_MOTION)) {
+ const uint4 tri_vindex = kernel_tex_fetch(__tri_vindex, sd->prim);
+ f0 = kernel_tex_fetch(__attributes_float, desc.offset + tri_vindex.x);
+ f1 = kernel_tex_fetch(__attributes_float, desc.offset + tri_vindex.y);
+ f2 = kernel_tex_fetch(__attributes_float, desc.offset + tri_vindex.z);
+ }
+ else {
+ const int tri = desc.offset + sd->prim * 3;
+ f0 = kernel_tex_fetch(__attributes_float, tri + 0);
+ f1 = kernel_tex_fetch(__attributes_float, tri + 1);
+ f2 = kernel_tex_fetch(__attributes_float, tri + 2);
+ }
#ifdef __RAY_DIFFERENTIALS__
if (dx)
@@ -153,21 +139,22 @@ ccl_device float triangle_attribute_float(
return sd->u * f0 + sd->v * f1 + (1.0f - sd->u - sd->v) * f2;
}
- else if (desc.element == ATTR_ELEMENT_OBJECT || desc.element == ATTR_ELEMENT_MESH) {
- if (dx)
- *dx = 0.0f;
- if (dy)
- *dy = 0.0f;
-
- return kernel_tex_fetch(__attributes_float, desc.offset);
- }
else {
+#ifdef __RAY_DIFFERENTIALS__
if (dx)
*dx = 0.0f;
if (dy)
*dy = 0.0f;
+#endif
- return 0.0f;
+ if (desc.element & (ATTR_ELEMENT_FACE | ATTR_ELEMENT_OBJECT | ATTR_ELEMENT_MESH)) {
+ const int offset = (desc.element == ATTR_ELEMENT_FACE) ? desc.offset + sd->prim :
+ desc.offset;
+ return kernel_tex_fetch(__attributes_float, offset);
+ }
+ else {
+ return 0.0f;
+ }
}
}
@@ -177,35 +164,17 @@ ccl_device float2 triangle_attribute_float2(KernelGlobals *kg,
float2 *dx,
float2 *dy)
{
- if (desc.element == ATTR_ELEMENT_FACE) {
- if (dx)
- *dx = make_float2(0.0f, 0.0f);
- if (dy)
- *dy = make_float2(0.0f, 0.0f);
-
- return kernel_tex_fetch(__attributes_float2, desc.offset + sd->prim);
- }
- else if (desc.element == ATTR_ELEMENT_VERTEX || desc.element == ATTR_ELEMENT_VERTEX_MOTION) {
- uint4 tri_vindex = kernel_tex_fetch(__tri_vindex, sd->prim);
-
- float2 f0 = kernel_tex_fetch(__attributes_float2, desc.offset + tri_vindex.x);
- float2 f1 = kernel_tex_fetch(__attributes_float2, desc.offset + tri_vindex.y);
- float2 f2 = kernel_tex_fetch(__attributes_float2, desc.offset + tri_vindex.z);
-
-#ifdef __RAY_DIFFERENTIALS__
- if (dx)
- *dx = sd->du.dx * f0 + sd->dv.dx * f1 - (sd->du.dx + sd->dv.dx) * f2;
- if (dy)
- *dy = sd->du.dy * f0 + sd->dv.dy * f1 - (sd->du.dy + sd->dv.dy) * f2;
-#endif
-
- return sd->u * f0 + sd->v * f1 + (1.0f - sd->u - sd->v) * f2;
- }
- else if (desc.element == ATTR_ELEMENT_CORNER) {
- int tri = desc.offset + sd->prim * 3;
+ if (desc.element & (ATTR_ELEMENT_VERTEX | ATTR_ELEMENT_VERTEX_MOTION | ATTR_ELEMENT_CORNER)) {
float2 f0, f1, f2;
- if (desc.element == ATTR_ELEMENT_CORNER) {
+ if (desc.element & (ATTR_ELEMENT_VERTEX | ATTR_ELEMENT_VERTEX_MOTION)) {
+ const uint4 tri_vindex = kernel_tex_fetch(__tri_vindex, sd->prim);
+ f0 = kernel_tex_fetch(__attributes_float2, desc.offset + tri_vindex.x);
+ f1 = kernel_tex_fetch(__attributes_float2, desc.offset + tri_vindex.y);
+ f2 = kernel_tex_fetch(__attributes_float2, desc.offset + tri_vindex.z);
+ }
+ else {
+ const int tri = desc.offset + sd->prim * 3;
f0 = kernel_tex_fetch(__attributes_float2, tri + 0);
f1 = kernel_tex_fetch(__attributes_float2, tri + 1);
f2 = kernel_tex_fetch(__attributes_float2, tri + 2);
@@ -220,21 +189,22 @@ ccl_device float2 triangle_attribute_float2(KernelGlobals *kg,
return sd->u * f0 + sd->v * f1 + (1.0f - sd->u - sd->v) * f2;
}
- else if (desc.element == ATTR_ELEMENT_OBJECT || desc.element == ATTR_ELEMENT_MESH) {
- if (dx)
- *dx = make_float2(0.0f, 0.0f);
- if (dy)
- *dy = make_float2(0.0f, 0.0f);
-
- return kernel_tex_fetch(__attributes_float2, desc.offset);
- }
else {
+#ifdef __RAY_DIFFERENTIALS__
if (dx)
*dx = make_float2(0.0f, 0.0f);
if (dy)
*dy = make_float2(0.0f, 0.0f);
+#endif
- return make_float2(0.0f, 0.0f);
+ if (desc.element & (ATTR_ELEMENT_FACE | ATTR_ELEMENT_OBJECT | ATTR_ELEMENT_MESH)) {
+ const int offset = (desc.element == ATTR_ELEMENT_FACE) ? desc.offset + sd->prim :
+ desc.offset;
+ return kernel_tex_fetch(__attributes_float2, offset);
+ }
+ else {
+ return make_float2(0.0f, 0.0f);
+ }
}
}
@@ -244,40 +214,21 @@ ccl_device float3 triangle_attribute_float3(KernelGlobals *kg,
float3 *dx,
float3 *dy)
{
- if (desc.element == ATTR_ELEMENT_FACE) {
- if (dx)
- *dx = make_float3(0.0f, 0.0f, 0.0f);
- if (dy)
- *dy = make_float3(0.0f, 0.0f, 0.0f);
-
- return float4_to_float3(kernel_tex_fetch(__attributes_float3, desc.offset + sd->prim));
- }
- else if (desc.element == ATTR_ELEMENT_VERTEX || desc.element == ATTR_ELEMENT_VERTEX_MOTION) {
- uint4 tri_vindex = kernel_tex_fetch(__tri_vindex, sd->prim);
-
- float3 f0 = float4_to_float3(
- kernel_tex_fetch(__attributes_float3, desc.offset + tri_vindex.x));
- float3 f1 = float4_to_float3(
- kernel_tex_fetch(__attributes_float3, desc.offset + tri_vindex.y));
- float3 f2 = float4_to_float3(
- kernel_tex_fetch(__attributes_float3, desc.offset + tri_vindex.z));
-
-#ifdef __RAY_DIFFERENTIALS__
- if (dx)
- *dx = sd->du.dx * f0 + sd->dv.dx * f1 - (sd->du.dx + sd->dv.dx) * f2;
- if (dy)
- *dy = sd->du.dy * f0 + sd->dv.dy * f1 - (sd->du.dy + sd->dv.dy) * f2;
-#endif
-
- return sd->u * f0 + sd->v * f1 + (1.0f - sd->u - sd->v) * f2;
- }
- else if (desc.element == ATTR_ELEMENT_CORNER) {
- int tri = desc.offset + sd->prim * 3;
+ if (desc.element & (ATTR_ELEMENT_VERTEX | ATTR_ELEMENT_VERTEX_MOTION | ATTR_ELEMENT_CORNER)) {
float3 f0, f1, f2;
- f0 = float4_to_float3(kernel_tex_fetch(__attributes_float3, tri + 0));
- f1 = float4_to_float3(kernel_tex_fetch(__attributes_float3, tri + 1));
- f2 = float4_to_float3(kernel_tex_fetch(__attributes_float3, tri + 2));
+ if (desc.element & (ATTR_ELEMENT_VERTEX | ATTR_ELEMENT_VERTEX_MOTION)) {
+ const uint4 tri_vindex = kernel_tex_fetch(__tri_vindex, sd->prim);
+ f0 = float4_to_float3(kernel_tex_fetch(__attributes_float3, desc.offset + tri_vindex.x));
+ f1 = float4_to_float3(kernel_tex_fetch(__attributes_float3, desc.offset + tri_vindex.y));
+ f2 = float4_to_float3(kernel_tex_fetch(__attributes_float3, desc.offset + tri_vindex.z));
+ }
+ else {
+ const int tri = desc.offset + sd->prim * 3;
+ f0 = float4_to_float3(kernel_tex_fetch(__attributes_float3, tri + 0));
+ f1 = float4_to_float3(kernel_tex_fetch(__attributes_float3, tri + 1));
+ f2 = float4_to_float3(kernel_tex_fetch(__attributes_float3, tri + 2));
+ }
#ifdef __RAY_DIFFERENTIALS__
if (dx)
@@ -288,21 +239,22 @@ ccl_device float3 triangle_attribute_float3(KernelGlobals *kg,
return sd->u * f0 + sd->v * f1 + (1.0f - sd->u - sd->v) * f2;
}
- else if (desc.element == ATTR_ELEMENT_OBJECT || desc.element == ATTR_ELEMENT_MESH) {
- if (dx)
- *dx = make_float3(0.0f, 0.0f, 0.0f);
- if (dy)
- *dy = make_float3(0.0f, 0.0f, 0.0f);
-
- return float4_to_float3(kernel_tex_fetch(__attributes_float3, desc.offset));
- }
else {
+#ifdef __RAY_DIFFERENTIALS__
if (dx)
*dx = make_float3(0.0f, 0.0f, 0.0f);
if (dy)
*dy = make_float3(0.0f, 0.0f, 0.0f);
+#endif
- return make_float3(0.0f, 0.0f, 0.0f);
+ if (desc.element & (ATTR_ELEMENT_FACE | ATTR_ELEMENT_OBJECT | ATTR_ELEMENT_MESH)) {
+ const int offset = (desc.element == ATTR_ELEMENT_FACE) ? desc.offset + sd->prim :
+ desc.offset;
+ return float4_to_float3(kernel_tex_fetch(__attributes_float3, offset));
+ }
+ else {
+ return make_float3(0.0f, 0.0f, 0.0f);
+ }
}
}
@@ -312,43 +264,28 @@ ccl_device float4 triangle_attribute_float4(KernelGlobals *kg,
float4 *dx,
float4 *dy)
{
- if (desc.element == ATTR_ELEMENT_FACE) {
- if (dx)
- *dx = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
- if (dy)
- *dy = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
-
- return kernel_tex_fetch(__attributes_float3, desc.offset + sd->prim);
- }
- else if (desc.element == ATTR_ELEMENT_VERTEX || desc.element == ATTR_ELEMENT_VERTEX_MOTION) {
- uint4 tri_vindex = kernel_tex_fetch(__tri_vindex, sd->prim);
-
- float4 f0 = kernel_tex_fetch(__attributes_float3, desc.offset + tri_vindex.x);
- float4 f1 = kernel_tex_fetch(__attributes_float3, desc.offset + tri_vindex.y);
- float4 f2 = kernel_tex_fetch(__attributes_float3, desc.offset + tri_vindex.z);
-
-#ifdef __RAY_DIFFERENTIALS__
- if (dx)
- *dx = sd->du.dx * f0 + sd->dv.dx * f1 - (sd->du.dx + sd->dv.dx) * f2;
- if (dy)
- *dy = sd->du.dy * f0 + sd->dv.dy * f1 - (sd->du.dy + sd->dv.dy) * f2;
-#endif
-
- return sd->u * f0 + sd->v * f1 + (1.0f - sd->u - sd->v) * f2;
- }
- else if (desc.element == ATTR_ELEMENT_CORNER || desc.element == ATTR_ELEMENT_CORNER_BYTE) {
- int tri = desc.offset + sd->prim * 3;
+ if (desc.element & (ATTR_ELEMENT_VERTEX | ATTR_ELEMENT_VERTEX_MOTION | ATTR_ELEMENT_CORNER |
+ ATTR_ELEMENT_CORNER_BYTE)) {
float4 f0, f1, f2;
- if (desc.element == ATTR_ELEMENT_CORNER_BYTE) {
- f0 = color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, tri + 0));
- f1 = color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, tri + 1));
- f2 = color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, tri + 2));
+ if (desc.element & (ATTR_ELEMENT_VERTEX | ATTR_ELEMENT_VERTEX_MOTION)) {
+ const uint4 tri_vindex = kernel_tex_fetch(__tri_vindex, sd->prim);
+ f0 = kernel_tex_fetch(__attributes_float3, desc.offset + tri_vindex.x);
+ f1 = kernel_tex_fetch(__attributes_float3, desc.offset + tri_vindex.y);
+ f2 = kernel_tex_fetch(__attributes_float3, desc.offset + tri_vindex.z);
}
else {
- f0 = kernel_tex_fetch(__attributes_float3, tri + 0);
- f1 = kernel_tex_fetch(__attributes_float3, tri + 1);
- f2 = kernel_tex_fetch(__attributes_float3, tri + 2);
+ const int tri = desc.offset + sd->prim * 3;
+ if (desc.element == ATTR_ELEMENT_CORNER) {
+ f0 = kernel_tex_fetch(__attributes_float3, tri + 0);
+ f1 = kernel_tex_fetch(__attributes_float3, tri + 1);
+ f2 = kernel_tex_fetch(__attributes_float3, tri + 2);
+ }
+ else {
+ f0 = color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, tri + 0));
+ f1 = color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, tri + 1));
+ f2 = color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, tri + 2));
+ }
}
#ifdef __RAY_DIFFERENTIALS__
@@ -360,21 +297,22 @@ ccl_device float4 triangle_attribute_float4(KernelGlobals *kg,
return sd->u * f0 + sd->v * f1 + (1.0f - sd->u - sd->v) * f2;
}
- else if (desc.element == ATTR_ELEMENT_OBJECT || desc.element == ATTR_ELEMENT_MESH) {
- if (dx)
- *dx = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
- if (dy)
- *dy = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
-
- return kernel_tex_fetch(__attributes_float3, desc.offset);
- }
else {
+#ifdef __RAY_DIFFERENTIALS__
if (dx)
*dx = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
if (dy)
*dy = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
+#endif
- return make_float4(0.0f, 0.0f, 0.0f, 0.0f);
+ if (desc.element & (ATTR_ELEMENT_FACE | ATTR_ELEMENT_OBJECT | ATTR_ELEMENT_MESH)) {
+ const int offset = (desc.element == ATTR_ELEMENT_FACE) ? desc.offset + sd->prim :
+ desc.offset;
+ return kernel_tex_fetch(__attributes_float3, offset);
+ }
+ else {
+ return make_float4(0.0f, 0.0f, 0.0f, 0.0f);
+ }
}
}
diff --git a/intern/cycles/kernel/kernel_types.h b/intern/cycles/kernel/kernel_types.h
index 77e134da4b0..8e2b0e46a66 100644
--- a/intern/cycles/kernel/kernel_types.h
+++ b/intern/cycles/kernel/kernel_types.h
@@ -733,18 +733,18 @@ typedef enum AttributePrimitive {
} AttributePrimitive;
typedef enum AttributeElement {
- ATTR_ELEMENT_NONE,
- ATTR_ELEMENT_OBJECT,
- ATTR_ELEMENT_MESH,
- ATTR_ELEMENT_FACE,
- ATTR_ELEMENT_VERTEX,
- ATTR_ELEMENT_VERTEX_MOTION,
- ATTR_ELEMENT_CORNER,
- ATTR_ELEMENT_CORNER_BYTE,
- ATTR_ELEMENT_CURVE,
- ATTR_ELEMENT_CURVE_KEY,
- ATTR_ELEMENT_CURVE_KEY_MOTION,
- ATTR_ELEMENT_VOXEL
+ ATTR_ELEMENT_NONE = 0,
+ ATTR_ELEMENT_OBJECT = (1 << 0),
+ ATTR_ELEMENT_MESH = (1 << 1),
+ ATTR_ELEMENT_FACE = (1 << 2),
+ ATTR_ELEMENT_VERTEX = (1 << 3),
+ ATTR_ELEMENT_VERTEX_MOTION = (1 << 4),
+ ATTR_ELEMENT_CORNER = (1 << 5),
+ ATTR_ELEMENT_CORNER_BYTE = (1 << 6),
+ ATTR_ELEMENT_CURVE = (1 << 7),
+ ATTR_ELEMENT_CURVE_KEY = (1 << 8),
+ ATTR_ELEMENT_CURVE_KEY_MOTION = (1 << 9),
+ ATTR_ELEMENT_VOXEL = (1 << 10)
} AttributeElement;
typedef enum AttributeStandard {