Cycles: Fix wrong order in object flags calculations
[blender.git] / intern / cycles / render / scene.cpp
index 52e355df3825641e6fe87377fdc8e027b8972230..19d715d834b45cc9ce2ddd164815412571f12849 100644 (file)
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
- * limitations under the License
+ * limitations under the License.
  */
 
 #include <stdlib.h>
 
 #include "background.h"
+#include "bake.h"
 #include "camera.h"
 #include "curves.h"
 #include "device.h"
 #include "util_foreach.h"
 #include "util_progress.h"
 
+#ifdef WITH_CYCLES_DEBUG
+#  include "util_guarded_allocator.h"
+#  include "util_logging.h"
+#endif
+
 CCL_NAMESPACE_BEGIN
 
 Scene::Scene(const SceneParams& params_, const DeviceInfo& device_info_)
@@ -54,15 +60,16 @@ Scene::Scene(const SceneParams& params_, const DeviceInfo& device_info_)
        image_manager = new ImageManager();
        particle_system_manager = new ParticleSystemManager();
        curve_system_manager = new CurveSystemManager();
+       bake_manager = new BakeManager();
 
        /* OSL only works on the CPU */
        if(device_info_.type == DEVICE_CPU)
                shader_manager = ShaderManager::create(this, params.shadingsystem);
        else
-               shader_manager = ShaderManager::create(this, SceneParams::SVM);
+               shader_manager = ShaderManager::create(this, SHADINGSYSTEM_SVM);
 
-       if (device_info_.type == DEVICE_CPU)
-               image_manager->set_extended_image_limits();
+       /* Extended image limits for CPU and GPUs */
+       image_manager->set_extended_image_limits(device_info_);
 }
 
 Scene::~Scene()
@@ -103,8 +110,12 @@ void Scene::free_memory(bool final)
                particle_system_manager->device_free(device, &dscene);
                curve_system_manager->device_free(device, &dscene);
 
+               bake_manager->device_free(device, &dscene);
+
                if(!params.persistent_data || final)
                        image_manager->device_free(device, &dscene);
+               else
+                       image_manager->device_free_builtin(device, &dscene);
 
                lookup_tables->device_free(device, &dscene);
        }
@@ -122,6 +133,7 @@ void Scene::free_memory(bool final)
                delete particle_system_manager;
                delete curve_system_manager;
                delete image_manager;
+               delete bake_manager;
        }
 }
 
@@ -133,77 +145,111 @@ void Scene::device_update(Device *device_, Progress& progress)
        /* The order of updates is important, because there's dependencies between
         * the different managers, using data computed by previous managers.
         *
-        * - Background generates shader graph compiled by shader manager.
         * - Image manager uploads images used by shaders.
-        * - Camera may be used for adapative subdivison.
+        * - Camera may be used for adaptive subdivision.
         * - Displacement shader must have all shader data available.
-        * - Light manager needs final mesh data to compute emission CDF.
+        * - Light manager needs lookup tables and final mesh data to compute emission CDF.
+        * - Film needs light manager to run for use_light_visibility
+        * - Lookup tables are done a second time to handle film tables
         */
        
        image_manager->set_pack_images(device->info.pack_images);
 
-       progress.set_status("Updating Background");
-       background->device_update(device, &dscene, this);
-
-       if(progress.get_cancel()) return;
-
        progress.set_status("Updating Shaders");
        shader_manager->device_update(device, &dscene, this, progress);
 
-       if(progress.get_cancel()) return;
+       if(progress.get_cancel() || device->have_error()) return;
 
-       progress.set_status("Updating Images");
-       image_manager->device_update(device, &dscene, progress);
+       progress.set_status("Updating Background");
+       background->device_update(device, &dscene, this);
 
-       if(progress.get_cancel()) return;
+       if(progress.get_cancel() || device->have_error()) return;
 
        progress.set_status("Updating Camera");
        camera->device_update(device, &dscene, this);
 
-       if(progress.get_cancel()) return;
+       if(progress.get_cancel() || device->have_error()) return;
 
        progress.set_status("Updating Objects");
        object_manager->device_update(device, &dscene, this, progress);
 
-       if(progress.get_cancel()) return;
+       if(progress.get_cancel() || device->have_error()) return;
 
-       progress.set_status("Updating Hair Systems");
-       curve_system_manager->device_update(device, &dscene, this, progress);
+       progress.set_status("Updating Meshes Flags");
+       mesh_manager->device_update_flags(device, &dscene, this, progress);
 
-       if(progress.get_cancel()) return;
+       if(progress.get_cancel() || device->have_error()) return;
 
        progress.set_status("Updating Meshes");
        mesh_manager->device_update(device, &dscene, this, progress);
 
-       if(progress.get_cancel()) return;
+       if(progress.get_cancel() || device->have_error()) return;
+
+       progress.set_status("Updating Objects Flags");
+       object_manager->device_update_flags(device, &dscene, this, progress);
+
+       if(progress.get_cancel() || device->have_error()) return;
+
+       progress.set_status("Updating Images");
+       image_manager->device_update(device, &dscene, progress);
+
+       if(progress.get_cancel() || device->have_error()) return;
+
+       progress.set_status("Updating Camera Volume");
+       camera->device_update_volume(device, &dscene, this);
+
+       if(progress.get_cancel() || device->have_error()) return;
+
+       progress.set_status("Updating Hair Systems");
+       curve_system_manager->device_update(device, &dscene, this, progress);
+
+       if(progress.get_cancel() || device->have_error()) return;
+
+       progress.set_status("Updating Lookup Tables");
+       lookup_tables->device_update(device, &dscene);
+
+       if(progress.get_cancel() || device->have_error()) return;
 
        progress.set_status("Updating Lights");
        light_manager->device_update(device, &dscene, this, progress);
 
-       if(progress.get_cancel()) return;
+       if(progress.get_cancel() || device->have_error()) return;
 
        progress.set_status("Updating Particle Systems");
        particle_system_manager->device_update(device, &dscene, this, progress);
 
-       if(progress.get_cancel()) return;
+       if(progress.get_cancel() || device->have_error()) return;
 
        progress.set_status("Updating Film");
        film->device_update(device, &dscene, this);
 
-       if(progress.get_cancel()) return;
+       if(progress.get_cancel() || device->have_error()) return;
 
        progress.set_status("Updating Integrator");
        integrator->device_update(device, &dscene, this);
 
-       if(progress.get_cancel()) return;
+       if(progress.get_cancel() || device->have_error()) return;
 
        progress.set_status("Updating Lookup Tables");
        lookup_tables->device_update(device, &dscene);
 
-       if(progress.get_cancel()) return;
+       if(progress.get_cancel() || device->have_error()) return;
+
+       progress.set_status("Updating Baking");
+       bake_manager->device_update(device, &dscene, this, progress);
+
+       if(progress.get_cancel() || device->have_error()) return;
+
+       if(device->have_error() == false) {
+               progress.set_status("Updating Device", "Writing constant memory");
+               device->const_copy_to("__data", &dscene.data, sizeof(dscene.data));
+       }
 
-       progress.set_status("Updating Device", "Writing constant memory");
-       device->const_copy_to("__data", &dscene.data, sizeof(dscene.data));
+#ifdef WITH_CYCLES_DEBUG
+       VLOG(1) << "System memory statistics after full device sync:\n"
+               << "  Usage: " << util_guarded_get_mem_used() << "\n"
+               << "  Peak: " << util_guarded_get_mem_peak();
+#endif
 }
 
 Scene::MotionType Scene::need_motion(bool advanced_shading)
@@ -220,8 +266,10 @@ bool Scene::need_global_attribute(AttributeStandard std)
 {
        if(std == ATTR_STD_UV)
                return Pass::contains(film->passes, PASS_UV);
-       if(std == ATTR_STD_MOTION_PRE || std == ATTR_STD_MOTION_POST)
-               return need_motion() == MOTION_PASS;
+       else if(std == ATTR_STD_MOTION_VERTEX_POSITION)
+               return need_motion() != MOTION_NONE;
+       else if(std == ATTR_STD_MOTION_VERTEX_NORMAL)
+               return need_motion() == MOTION_BLUR;
        
        return false;
 }
@@ -250,7 +298,9 @@ bool Scene::need_reset()
                || integrator->need_update
                || shader_manager->need_update
                || particle_system_manager->need_update
-               || curve_system_manager->need_update);
+               || curve_system_manager->need_update
+               || bake_manager->need_update
+               || film->need_update);
 }
 
 void Scene::reset()
@@ -263,6 +313,11 @@ void Scene::reset()
        film->tag_update(this);
        background->tag_update(this);
        integrator->tag_update(this);
+       object_manager->tag_update(this);
+       mesh_manager->tag_update(this);
+       light_manager->tag_update(this);
+       particle_system_manager->tag_update(this);
+       curve_system_manager->tag_update(this);
 }
 
 void Scene::device_free()