Cycles microdisplacement: Allow kernels to be built without patch evaluation
authorMai Lavelle <mai.lavelle@gmail.com>
Mon, 15 Aug 2016 13:08:38 +0000 (09:08 -0400)
committerMai Lavelle <mai.lavelle@gmail.com>
Mon, 15 Aug 2016 15:13:18 +0000 (11:13 -0400)
Kernels can now be built without patch evaluation when not needed by the
scene (Catmull-Clark subdivision not in use), giving a performance boost
for some devices.

intern/cycles/device/device.cpp
intern/cycles/device/device.h
intern/cycles/kernel/geom/geom.h
intern/cycles/kernel/geom/geom_subd_triangle.h
intern/cycles/kernel/kernel_types.h
intern/cycles/render/session.cpp

index df01215c91a2dcfdf4310484c32f0f6d45aa64f1..85e736ad6354aa98c4f0fc66c6c7bfd3216a4de5 100644 (file)
@@ -56,8 +56,14 @@ std::ostream& operator <<(std::ostream &os,
           << string_from_bool(requested_features.use_camera_motion)  << std::endl;
        os << "Use Baking: "
           << string_from_bool(requested_features.use_baking)  << std::endl;
+       os << "Use Subsurface: "
+          << string_from_bool(requested_features.use_subsurface) << std::endl;
        os << "Use Volume: "
           << string_from_bool(requested_features.use_volume)  << std::endl;
+       os << "Use Branched Integrator: "
+          << string_from_bool(requested_features.use_integrator_branched) << std::endl;
+       os << "Use Patch Evaluation: "
+          << string_from_bool(requested_features.use_patch_evaluation) << std::endl;
        return os;
 }
 
index e11bb7f76af7c64a58fa17405f8dac199d615460..77dc1fa9713390fe9daa0b30523db4f3a65312b7 100644 (file)
@@ -109,6 +109,9 @@ public:
        /* Use branched integrator. */
        bool use_integrator_branched;
 
+       /* Use OpenSubdiv patch evaluation */
+       bool use_patch_evaluation;
+
        DeviceRequestedFeatures()
        {
                /* TODO(sergey): Find more meaningful defaults. */
@@ -123,6 +126,7 @@ public:
                use_subsurface = false;
                use_volume = false;
                use_integrator_branched = false;
+               use_patch_evaluation = false;
        }
 
        bool modified(const DeviceRequestedFeatures& requested_features)
@@ -137,7 +141,8 @@ public:
                         use_baking == requested_features.use_baking &&
                         use_subsurface == requested_features.use_subsurface &&
                         use_volume == requested_features.use_volume &&
-                        use_integrator_branched == requested_features.use_integrator_branched);
+                        use_integrator_branched == requested_features.use_integrator_branched &&
+                        use_patch_evaluation == requested_features.use_patch_evaluation);
        }
 
        /* Convert the requested features structure to a build options,
@@ -175,6 +180,9 @@ public:
                if(!use_integrator_branched) {
                        build_options += " -D__NO_BRANCHED_PATH__";
                }
+               if(!use_patch_evaluation) {
+                       build_options += " -D__NO_PATCH_EVAL__";
+               }
                return build_options;
        }
 };
index 11548324e18fe44be3398eb8182068890fd06f74..3605394f18217c1542742293b8f515f7d37adbe4 100644 (file)
@@ -17,7 +17,9 @@
 
 #include "geom_attribute.h"
 #include "geom_object.h"
-#include "geom_patch.h"
+#ifdef __PATCH_EVAL__
+#  include "geom_patch.h"
+#endif
 #include "geom_triangle.h"
 #include "geom_subd_triangle.h"
 #include "geom_triangle_intersect.h"
index fccacf435f9852e3a35ed5e4bfbc0709f3a9d5e0..647840dc696924bff0859266791a567fa39f84b0 100644 (file)
@@ -101,6 +101,7 @@ ccl_device_noinline float subd_triangle_attribute_float(KernelGlobals *kg, const
 {
        int patch = subd_triangle_patch(kg, sd);
 
+#ifdef __PATCH_EVAL__
        if(desc.flags & ATTR_SUBDIVIDED) {
                float2 uv[3];
                subd_triangle_patch_uv(kg, sd, uv);
@@ -144,7 +145,9 @@ ccl_device_noinline float subd_triangle_attribute_float(KernelGlobals *kg, const
 
                return a;
        }
-       else if(desc.element == ATTR_ELEMENT_FACE) {
+       else
+#endif /* __PATCH_EVAL__ */
+       if(desc.element == ATTR_ELEMENT_FACE) {
                if(dx) *dx = 0.0f;
                if(dy) *dy = 0.0f;
 
@@ -217,6 +220,7 @@ ccl_device_noinline float3 subd_triangle_attribute_float3(KernelGlobals *kg, con
 {
        int patch = subd_triangle_patch(kg, sd);
 
+#ifdef __PATCH_EVAL__
        if(desc.flags & ATTR_SUBDIVIDED) {
                float2 uv[3];
                subd_triangle_patch_uv(kg, sd, uv);
@@ -266,7 +270,9 @@ ccl_device_noinline float3 subd_triangle_attribute_float3(KernelGlobals *kg, con
 
                return a;
        }
-       else if(desc.element == ATTR_ELEMENT_FACE) {
+       else
+#endif /* __PATCH_EVAL__ */
+       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);
 
index bb26570455b191e5f1932714ad13d60dae55c519..e29940672cadec4de0a8932fd44e9e003da4ede8 100644 (file)
@@ -148,6 +148,7 @@ CCL_NAMESPACE_BEGIN
 #define __CAMERA_CLIPPING__
 #define __INTERSECTION_REFINE__
 #define __CLAMP_SAMPLE__
+#define __PATCH_EVAL__
 
 #ifdef __KERNEL_SHADING__
 #  define __SVM__
@@ -197,6 +198,9 @@ CCL_NAMESPACE_BEGIN
 #ifdef __NO_BRANCHED_PATH__
 #  undef __BRANCHED_PATH__
 #endif
+#ifdef __NO_PATCH_EVAL__
+#  undef __PATCH_EVAL__
+#endif
 
 /* Random Numbers */
 
index 1cd76ff2b397b8df78cc52cb0a51f99764598ce6..9d8c9fed7af4bac86b41eb027fc697160cc8622e 100644 (file)
@@ -635,6 +635,11 @@ DeviceRequestedFeatures Session::get_requested_device_features()
                }
                requested_features.use_object_motion |= object->use_motion | mesh->use_motion_blur;
                requested_features.use_camera_motion |= mesh->use_motion_blur;
+#ifdef WITH_OPENSUBDIV
+               if(mesh->subdivision_type != Mesh::SUBDIVISION_NONE) {
+                       requested_features.use_patch_evaluation = true;
+               }
+#endif
        }
 
        BakeManager *bake_manager = scene->bake_manager;