708 bool true_displacement_used =
false;
709 bool curve_shadow_transparency_used =
false;
710 size_t num_tessellation = 0;
715 scene->
update_stats->geometry.times.add_entry({
"device_update (normals)", time});
722 Mesh *mesh =
static_cast<Mesh *
>(geom);
729#ifdef WITH_OPENSUBDIV
742 true_displacement_used =
true;
746 Hair *hair =
static_cast<Hair *
>(geom);
748 curve_shadow_transparency_used =
true;
767 {(num_tessellation) ?
"device_update (tessellation and tangents)" :
768 "device_update (tangents)",
774 if (num_tessellation) {
775 dicing_camera->set_screen_size(dicing_camera->get_full_width(),
776 dicing_camera->get_full_height());
777 dicing_camera->update(scene);
783 if (progress.get_cancel()) {
791 Mesh *mesh =
static_cast<Mesh *
>(geom);
793 if (num_tessellation && mesh->need_tesselation()) {
795 const thread_scoped_lock status_lock(status_mutex);
796 string msg =
"Tessellating ";
797 if (mesh->name.empty()) {
798 msg += string_printf(
"%u/%u", (uint)(i + 1), (uint)num_tessellation);
801 msg += string_printf(
802 "%s %u/%u", mesh->name.c_str(), (uint)(i + 1), (uint)num_tessellation);
805 progress.set_status(
"Updating Mesh", msg);
810 subd_params.
dicing_rate = mesh->get_subd_dicing_rate();
811 subd_params.max_level = mesh->get_subd_max_level();
813 subd_params.objecttoworld = mesh->get_subd_objecttoworld();
814 subd_params.camera = dicing_camera;
817 mesh->tessellate(subd_params);
821 mesh->update_generated(scene);
823 mesh->update_tangents(scene,
true);
824 if (!mesh->has_true_displacement()) {
825 mesh->update_tangents(scene, false);
829 if (progress.get_cancel()) {
834 if (true_displacement_used || curve_shadow_transparency_used) {
836 if (scene->update_stats) {
837 scene->update_stats->geometry.times.add_entry(
838 {
"device_update (displacement: load images)", time});
841 device_update_displacement_images(device, scene, progress);
842 scene->object_manager->device_update_flags(device, dscene, scene, progress,
false);
846 device_free(device, dscene,
false);
849 scene->params.bvh_layout, device->get_bvh_layout_mask(dscene->data.kernel_features));
850 geom_calc_offset(scene, bvh_layout);
851 if (true_displacement_used || curve_shadow_transparency_used) {
853 if (scene->update_stats) {
854 scene->update_stats->geometry.times.add_entry(
855 {
"device_update (displacement: copy meshes to device)", time});
858 device_update_mesh(device, dscene, scene, progress);
861 if (progress.get_cancel()) {
868 if (scene->update_stats) {
869 scene->update_stats->object.times.add_entry(
870 {
"device_update (apply static transforms)", time});
874 progress.set_status(
"Updating Objects",
"Applying Static Transformations");
875 scene->object_manager->apply_static_transforms(dscene, scene, progress);
878 if (progress.get_cancel()) {
884 if (scene->update_stats) {
885 scene->update_stats->geometry.times.add_entry({
"device_update (attributes)", time});
888 device_update_attributes(device, dscene, scene, progress);
889 if (progress.get_cancel()) {
895 bool displacement_done =
false;
896 bool curve_shadow_transparency_done =
false;
900 device->const_copy_to(
"data", &dscene->data,
sizeof(dscene->data));
903 if (scene->update_stats) {
904 scene->update_stats->geometry.times.add_entry({
"device_update (displacement)", time});
908 for (
Geometry *geom : scene->geometry) {
911 Mesh *mesh =
static_cast<Mesh *
>(geom);
912 if (displace(device, scene, mesh, progress)) {
913 displacement_done =
true;
917 Hair *hair =
static_cast<Hair *
>(geom);
919 curve_shadow_transparency_done =
true;
924 if (progress.get_cancel()) {
930 if (progress.get_cancel()) {
935 if (displacement_done || curve_shadow_transparency_done) {
937 if (scene->update_stats) {
938 scene->update_stats->geometry.times.add_entry(
939 {
"device_update (displacement: attributes)", time});
942 device_free(device, dscene,
false);
944 device_update_attributes(device, dscene, scene, progress);
945 if (progress.get_cancel()) {
955 bool need_update_scene_bvh = (scene->bvh ==
nullptr ||
956 (update_flags & (TRANSFORM_MODIFIED | VISIBILITY_MODIFIED)) != 0);
959 if (scene->update_stats) {
960 scene->update_stats->geometry.times.add_entry({
"device_update (build object BVHs)", time});
966 for (
Geometry *geom : scene->geometry) {
968 need_update_scene_bvh =
true;
976 bvh_task_pool_.push([geom, device, dscene, scene, &progress,
i, &num_bvh] {
977 geom->
compute_bvh(device, dscene, &scene->params, &progress,
i, num_bvh);
983 bvh_task_pool_.wait_work(&summary);
987 for (
Shader *shader : scene->shaders) {
1000 if (scene->update_stats) {
1001 scene->update_stats->geometry.times.add_entry({
"device_update (compute bounds)", time});
1004 for (
Object *
object : scene->objects) {
1005 object->compute_bounds(motion_blur);
1009 if (progress.get_cancel()) {
1013 if (need_update_scene_bvh) {
1015 if (scene->update_stats) {
1016 scene->update_stats->geometry.times.add_entry({
"device_update (build scene BVH)", time});
1019 device_update_bvh(device, dscene, scene, progress);
1020 if (progress.get_cancel()) {
1028 scene->params.bvh_layout, device->get_bvh_layout_mask(dscene->data.kernel_features));
1032 if (scene->update_stats) {
1033 scene->update_stats->geometry.times.add_entry(
1034 {
"device_update (copy meshes to device)", time});
1037 device_update_mesh(device, dscene, scene, progress);
1038 if (progress.get_cancel()) {
1045 for (
Geometry *geom : scene->geometry) {
1050 Mesh *mesh =
static_cast<Mesh *
>(geom);
1055 update_flags = UPDATE_NONE;
1057 dscene->bvh_nodes.clear_modified();
1058 dscene->bvh_leaf_nodes.clear_modified();
1059 dscene->object_node.clear_modified();
1060 dscene->prim_type.clear_modified();
1061 dscene->prim_visibility.clear_modified();
1062 dscene->prim_index.clear_modified();
1063 dscene->prim_object.clear_modified();
1064 dscene->prim_time.clear_modified();
1065 dscene->tri_verts.clear_modified();
1066 dscene->tri_shader.clear_modified();
1067 dscene->tri_vindex.clear_modified();
1068 dscene->tri_vnormal.clear_modified();
1069 dscene->curves.clear_modified();
1070 dscene->curve_keys.clear_modified();
1071 dscene->curve_segments.clear_modified();
1072 dscene->points.clear_modified();
1073 dscene->points_shader.clear_modified();
1074 dscene->attributes_map.clear_modified();
1075 dscene->attributes_float.clear_modified();
1076 dscene->attributes_float2.clear_modified();
1077 dscene->attributes_float3.clear_modified();
1078 dscene->attributes_float4.clear_modified();
1079 dscene->attributes_uchar4.clear_modified();