Cycles/OpenCL: Reduce How Often Kernel Recompilations Are Needed
authorJeroen Bakker <j.bakker@atmind.nl>
Tue, 12 Mar 2019 12:58:39 +0000 (13:58 +0100)
committerJeroen Bakker <j.bakker@atmind.nl>
Tue, 12 Mar 2019 13:06:45 +0000 (14:06 +0100)
This patch will reduce the number of times that we need to
recompile kernels. It does this by (en/dis)abling features
by default. So when the user needs them that the kernels are
already available.

Other features are enabled by default for background and foreground
rendering. When in background rendering the user wants the best
render performance. When in foreground rendering the user wants
the least amount of recompilations.

Enabling volumetrics or subdivision evaluation will still trigger
a recompilation during foreground rendering.

Reviewed By: #cycles, brecht

Differential Revision: https://developer.blender.org/D4485

intern/cycles/device/opencl/opencl.h
intern/cycles/device/opencl/opencl_split.cpp
intern/cycles/render/session.cpp

index 4ecf71e116eb6c9cb0bde95979e4470dfe56e6ea..2a4e07419ac5abee324275226512a173fa5c9f74 100644 (file)
@@ -374,6 +374,8 @@ public:
        /* Get the program file name to compile (*.cl) for the given kernel */
        const string get_opencl_program_filename(const string& kernel_name);
        string get_build_options(const DeviceRequestedFeatures& requested_features, const string& opencl_program_name);
+       /* Enable the default features to reduce recompilation events */
+       void enable_default_features(DeviceRequestedFeatures& features);
 
        void mem_alloc(device_memory& mem);
        void mem_copy_to(device_memory& mem);
index b575b008fe05d4782a4754333b194068188c4cb9..422813c2e0744dbec29bed44370664ad4e889944 100644 (file)
@@ -73,6 +73,25 @@ const string OpenCLDevice::get_opencl_program_filename(const string& kernel_name
        }
 }
 
+/* Enable features that we always want to compile to reduce recompilation events */
+void OpenCLDevice::enable_default_features(DeviceRequestedFeatures& features)
+{
+       features.use_transparent = true;
+       features.use_shadow_tricks = true;
+       features.use_principled = true;
+       features.use_denoising = true;
+
+       if (!background)
+       {
+               features.max_nodes_group = NODE_GROUP_LEVEL_MAX;
+               features.nodes_features = NODE_FEATURE_ALL;
+               features.use_hair = true;
+               features.use_subsurface = true;
+               features.use_camera_motion = false;
+               features.use_object_motion = false;
+       }
+}
+
 string OpenCLDevice::get_build_options(const DeviceRequestedFeatures& requested_features, const string& opencl_program_name)
 {
        /* first check for non-split kernel programs */
@@ -84,15 +103,22 @@ string OpenCLDevice::get_build_options(const DeviceRequestedFeatures& requested_
                 * displace and background are always requested.
                 * `__SPLIT_KERNEL__` must not be present in the compile directives for bake */
                DeviceRequestedFeatures features(requested_features);
+               enable_default_features(features);
                features.use_denoising = false;
                features.use_object_motion = false;
                features.use_camera_motion = false;
+               features.use_hair = true;
+               features.use_subsurface = true;
+               features.max_nodes_group = NODE_GROUP_LEVEL_MAX;
+               features.nodes_features = NODE_FEATURE_ALL;
+               features.use_integrator_branched = false;
                return features.get_build_options();
        }
        else if (opencl_program_name == "displace") {
                /* As displacement does not use any nodes from the Shading group (eg BSDF).
                 * We disable all features that are related to shading. */
                DeviceRequestedFeatures features(requested_features);
+               enable_default_features(features);
                features.use_denoising = false;
                features.use_object_motion = false;
                features.use_camera_motion = false;
@@ -104,13 +130,17 @@ string OpenCLDevice::get_build_options(const DeviceRequestedFeatures& requested_
                features.nodes_features &= ~NODE_FEATURE_VOLUME;
                features.use_denoising = false;
                features.use_principled = false;
+               features.use_integrator_branched = false;
                return features.get_build_options();
        }
        else if (opencl_program_name == "background") {
                /* Background uses Background shading
                 * It is save to disable shadow features, subsurface and volumetric. */
                DeviceRequestedFeatures features(requested_features);
+               enable_default_features(features);
                features.use_baking = false;
+               features.use_object_motion = false;
+               features.use_camera_motion = false;
                features.use_transparent = false;
                features.use_shadow_tricks = false;
                features.use_denoising = false;
@@ -120,11 +150,13 @@ string OpenCLDevice::get_build_options(const DeviceRequestedFeatures& requested_
                features.nodes_features &= ~NODE_FEATURE_VOLUME;
                features.use_subsurface = false;
                features.use_volume = false;
+               features.use_shader_raytrace = false;
+               features.use_patch_evaluation = false;
+               features.use_integrator_branched = false;
                return features.get_build_options();
        }
 
        string build_options = "-D__SPLIT_KERNEL__ ";
-       DeviceRequestedFeatures nofeatures;
        /* Set compute device build option. */
        cl_device_type device_type;
        OpenCLInfo::get_device_type(this->cdDevice, &device_type, &this->ciErr);
@@ -133,17 +165,16 @@ string OpenCLDevice::get_build_options(const DeviceRequestedFeatures& requested_
                build_options += "-D__COMPUTE_DEVICE_GPU__ ";
        }
 
+       DeviceRequestedFeatures nofeatures;
+       enable_default_features(nofeatures);
+
        /* Add program specific optimized compile directives */
        if (opencl_program_name == "split_do_volume" && !requested_features.use_volume) {
                build_options += nofeatures.get_build_options();
        }
-       else if (opencl_program_name == "split_subsurface_scatter" && !requested_features.use_subsurface) {
-               /* When subsurface is off, the kernel updates indexes and does not need any
-                * Compile directives */
-               build_options += nofeatures.get_build_options();
-       }
        else {
                DeviceRequestedFeatures features(requested_features);
+               enable_default_features(features);
 
                /* Always turn off baking at this point. Baking is only usefull when building the bake kernel.
                 * this also makes sure that the kernels that are build during baking can be reused
@@ -155,6 +186,7 @@ string OpenCLDevice::get_build_options(const DeviceRequestedFeatures& requested_
                if (opencl_program_name == "split_bundle") {
                        features.max_nodes_group = 0;
                        features.nodes_features = 0;
+                       features.use_shader_raytrace = false;
                }
 
                /* No specific settings, just add the regular ones */
index 87c46ec44c8ae061c3667a58a005fe941b4c7e8a..dea50d52cfaa94bcf012b9444f4400bf138fdf28 100644 (file)
@@ -658,11 +658,6 @@ DeviceRequestedFeatures Session::get_requested_device_features()
        scene->shader_manager->get_requested_features(
                scene,
                &requested_features);
-       if(!params.background) {
-               /* Avoid too much re-compilations for viewport render. */
-               requested_features.max_nodes_group = NODE_GROUP_LEVEL_MAX;
-               requested_features.nodes_features = NODE_FEATURE_ALL;
-       }
 
        /* This features are not being tweaked as often as shaders,
         * so could be done selective magic for the viewport as well.