Merge branch 'master' into blender2.8
authorCampbell Barton <ideasman42@gmail.com>
Thu, 4 May 2017 22:23:59 +0000 (08:23 +1000)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 4 May 2017 22:23:59 +0000 (08:23 +1000)
intern/cycles/device/device_cpu.cpp
intern/cycles/render/image.cpp
intern/cycles/render/image.h
intern/cycles/render/mesh.cpp
intern/cycles/util/util_debug.cpp
source/blender/blenkernel/intern/library.c
source/blender/blenkernel/intern/library_remap.c
source/blender/blenkernel/intern/object.c
source/blender/blenkernel/intern/scene.c
source/blender/blenkernel/intern/texture.c
source/blender/editors/space_view3d/drawobject.c

index 3c481bb2b39db11b401b1cd225f7a92cedc8e023..84cce605182cbe420615bf07962a9da79d0156cd 100644 (file)
@@ -446,8 +446,7 @@ public:
                kgbuffer.resize(sizeof(KernelGlobals));
                mem_alloc("kernel_globals", kgbuffer, MEM_READ_WRITE);
 
-               KernelGlobals *kg = (KernelGlobals*)kgbuffer.device_pointer;
-               *kg = thread_kernel_globals_init();
+               KernelGlobals *kg = new ((void*) kgbuffer.device_pointer) KernelGlobals(thread_kernel_globals_init());
 
                requested_features.max_closure = MAX_CLOSURE;
                if(!split_kernel.load_kernels(requested_features)) {
index d26ea3e14e081a4a7a786e5dceb03a6c79c09e48..b66d694c82ad53731d6507284051d3673fb3c6e1 100644 (file)
@@ -949,16 +949,8 @@ void ImageManager::device_free_image(Device *device, DeviceScene *dscene, ImageD
        }
 }
 
-void ImageManager::device_update(Device *device,
-                                 DeviceScene *dscene,
-                                 Scene *scene,
-                                 Progress& progress)
+void ImageManager::device_prepare_update(DeviceScene *dscene)
 {
-       if(!need_update)
-               return;
-
-       TaskPool pool;
-
        for(int type = 0; type < IMAGE_DATA_NUM_TYPES; type++) {
                switch(type) {
                        case IMAGE_DATA_TYPE_FLOAT4:
@@ -986,6 +978,23 @@ void ImageManager::device_update(Device *device,
                                        dscene->tex_half_image.resize(tex_num_images[IMAGE_DATA_TYPE_HALF]);
                                break;
                }
+       }
+}
+
+void ImageManager::device_update(Device *device,
+                                 DeviceScene *dscene,
+                                 Scene *scene,
+                                 Progress& progress)
+{
+       if(!need_update) {
+               return;
+       }
+
+       /* Make sure arrays are proper size. */
+       device_prepare_update(dscene);
+
+       TaskPool pool;
+       for(int type = 0; type < IMAGE_DATA_NUM_TYPES; type++) {
                for(size_t slot = 0; slot < images[type].size(); slot++) {
                        if(!images[type][slot])
                                continue;
index 5550d019868629ba8c4b9c4389e1a62f99813ae0..77214bf25bc4876055ba7d54dcf12585f9a42016 100644 (file)
@@ -59,6 +59,7 @@ public:
                              bool use_alpha);
        ImageDataType get_image_metadata(const string& filename, void *builtin_data, bool& is_linear);
 
+       void device_prepare_update(DeviceScene *dscene);
        void device_update(Device *device,
                           DeviceScene *dscene,
                           Scene *scene,
index a4dc06c43454102da81256e46f9051e11daad11b..33d1936659b0cab01c4ebd03e70f5ca1829bcea2 100644 (file)
@@ -1944,6 +1944,7 @@ void MeshManager::device_update_displacement_images(Device *device,
                        }
                }
        }
+       image_manager->device_prepare_update(dscene);
        foreach(int slot, bump_images) {
                pool.push(function_bind(&ImageManager::device_update_slot,
                                        image_manager,
index c259685f050b01b9dab4a26f45cf3cccd50893f0..ab038d2b9fbb1a3835eff9effa90b97a6969f2fa 100644 (file)
@@ -184,7 +184,7 @@ std::ostream& operator <<(std::ostream &os,
           << "  Device type    : " << opencl_device_type << "\n"
           << "  Kernel type    : " << opencl_kernel_type << "\n"
           << "  Debug          : " << string_from_bool(debug_flags.opencl.debug) << "\n"
-          << "  Signle program : " << string_from_bool(debug_flags.opencl.single_program)
+          << "  Single program : " << string_from_bool(debug_flags.opencl.single_program)
           << "\n";
        return os;
 }
index 48a6693ad6d5174d9aeb8946e51d976a6601a7e4..64c888943f48eea9757f87e2af0279939c0d1886 100644 (file)
 
 #include "atomic_ops.h"
 
+//#define DEBUG_TIME
+
+#ifdef DEBUG_TIME
+#  include "PIL_time_utildefines.h"
+#endif
+
 /* GS reads the memory pointed at in a specific ordering. 
  * only use this definition, makes little and big endian systems
  * work fine, in conjunction with MAKE_ID */
@@ -1776,9 +1782,18 @@ void BKE_library_make_local(
        LinkNode *copied_ids = NULL;
        MemArena *linklist_mem = BLI_memarena_new(512 * sizeof(*todo_ids), __func__);
 
+       GSet *done_ids = BLI_gset_ptr_new(__func__);
+
+#ifdef DEBUG_TIME
+       TIMEIT_START(make_local);
+#endif
+
        BKE_main_relations_create(bmain);
 
-       GSet *done_ids = BLI_gset_ptr_new(__func__);
+#ifdef DEBUG_TIME
+       printf("Pre-compute current ID relations: Done.\n");
+       TIMEIT_VALUE_PRINT(make_local);
+#endif
 
        /* Step 1: Detect datablocks to make local. */
        for (a = set_listbasepointers(bmain, lbarray); a--; ) {
@@ -1829,6 +1844,11 @@ void BKE_library_make_local(
                }
        }
 
+#ifdef DEBUG_TIME
+       printf("Step 1: Detect datablocks to make local: Done.\n");
+       TIMEIT_VALUE_PRINT(make_local);
+#endif
+
        /* Step 2: Check which datablocks we can directly make local (because they are only used by already, or future,
         * local data), others will need to be duplicated. */
        GSet *loop_tags = BLI_gset_ptr_new(__func__);
@@ -1842,6 +1862,11 @@ void BKE_library_make_local(
        /* Next step will most likely add new IDs, better to get rid of this mapping now. */
        BKE_main_relations_free(bmain);
 
+#ifdef DEBUG_TIME
+       printf("Step 2: Check which datablocks we can directly make local: Done.\n");
+       TIMEIT_VALUE_PRINT(make_local);
+#endif
+
        /* Step 3: Make IDs local, either directly (quick and simple), or using generic process,
         * which involves more complex checks and might instead create a local copy of original linked ID. */
        for (LinkNode *it = todo_ids, *it_next; it; it = it_next) {
@@ -1882,11 +1907,16 @@ void BKE_library_make_local(
                }
        }
 
+#ifdef DEBUG_TIME
+       printf("Step 3: Make IDs local: Done.\n");
+       TIMEIT_VALUE_PRINT(make_local);
+#endif
+
        /* At this point, we are done with directly made local IDs. Now we have to handle duplicated ones, since their
         * remaining linked original counterpart may not be needed anymore... */
        todo_ids = NULL;
 
-       /* Step 4: We have to remap local usages of old (linked) ID to new (local) id in a separated loop,
+       /* Step 4: We have to remap local usages of old (linked) ID to new (local) ID in a separated loop,
         * as lbarray ordering is not enough to ensure us we did catch all dependencies
         * (e.g. if making local a parent object before its child...). See T48907. */
        /* TODO This is now the biggest step by far (in term of processing time). We may be able to gain here by
@@ -1910,6 +1940,11 @@ void BKE_library_make_local(
                }
        }
 
+#ifdef DEBUG_TIME
+       printf("Step 4: Remap local usages of old (linked) ID to new (local) ID: Done.\n");
+       TIMEIT_VALUE_PRINT(make_local);
+#endif
+
        /* Note: Keeping both version of the code (old one being safer, since it still has checks against unused IDs)
         * for now, we can remove old one once it has been tested for some time in master... */
 #if 1
@@ -1954,6 +1989,12 @@ void BKE_library_make_local(
                        }
                }
        }
+
+#ifdef DEBUG_TIME
+       printf("Step 5: Proxy 'remapping' hack: Done.\n");
+       TIMEIT_VALUE_PRINT(make_local);
+#endif
+
 #else
        LinkNode *linked_loop_candidates = NULL;
 
@@ -2032,6 +2073,11 @@ void BKE_library_make_local(
                }
        }
 
+#ifdef DEBUG_TIME
+       printf("Step 5: Remove linked datablocks that have been copied and ended fully localized: Done.\n");
+       TIMEIT_VALUE_PRINT(make_local);
+#endif
+
        /* Step 6: Try to find circle dependencies between indirectly-linked-only datablocks.
         * Those are fake 'usages' that prevent their deletion. See T49775 for nice ugly case. */
        BKE_library_unused_linked_data_set_tag(bmain, false);
@@ -2068,10 +2114,21 @@ void BKE_library_make_local(
                        it->link = NULL;
                }
        }
+
+#ifdef DEBUG_TIME
+       printf("Step 6: Try to find circle dependencies between indirectly-linked-only datablocks: Done.\n");
+       TIMEIT_END(make_local);
+#endif
+
 #endif
 
        BKE_main_id_clear_newpoins(bmain);
        BLI_memarena_free(linklist_mem);
+
+#ifdef DEBUG_TIME
+       printf("Cleanup and finish: Done.\n");
+       TIMEIT_END(make_local);
+#endif
 }
 
 /**
index 255904841b26b070255b0e898f84119a85083bf1..02128ae9c3a6912d093be24499a67a7a739a932b 100644 (file)
@@ -550,8 +550,12 @@ void BKE_libblock_remap_locked(
                id_us_clear_real(old_id);
        }
 
-       BLI_assert(old_id->us - skipped_refcounted >= 0);
-       UNUSED_VARS_NDEBUG(skipped_refcounted);
+       if (old_id->us - skipped_refcounted < 0) {
+               printf("Error in remapping process from '%s' (%p) to '%s' (%p): "
+                      "wrong user count in old ID after process (summing up to %d)\n",
+                      old_id->name, old_id, new_id ? new_id->name : "<NULL>", new_id, old_id->us - skipped_refcounted);
+               BLI_assert(0);
+       }
 
        if (skipped_direct == 0) {
                /* old_id is assumed to not be used directly anymore... */
index b70eb2b503a74e29fd84059c60bebd0e00393fb3..684b00c6e0ab0ea7a2c4b0f724019e7fdd6a153e 100644 (file)
@@ -1164,6 +1164,7 @@ Object *BKE_object_copy_ex(Main *bmain, Object *ob, bool copy_caches)
 
        /* increase user numbers */
        id_us_plus((ID *)obn->data);
+       id_us_plus((ID *)obn->poselib);
        id_us_plus((ID *)obn->gpd);
        id_us_plus((ID *)obn->dup_group);
 
index 44e29e5b9943cfcd6d7ff1facc9b1c13f2785373..420c1a3ebabfcff2609e5cf0371ef64aa29fc95c 100644 (file)
@@ -291,6 +291,9 @@ Scene *BKE_scene_copy(Main *bmain, Scene *sce, int type)
                /* copy Freestyle settings */
                new_srl = scen->r.layers.first;
                for (srl = sce->r.layers.first; srl; srl = srl->next) {
+                       if (new_srl->prop != NULL) {
+                               new_srl->prop = IDP_CopyProperty(new_srl->prop);
+                       }
                        BKE_freestyle_config_copy(&new_srl->freestyleConfig, &srl->freestyleConfig);
                        if (type == SCE_COPY_FULL) {
                                for (lineset = new_srl->freestyleConfig.linesets.first; lineset; lineset = lineset->next) {
@@ -513,11 +516,15 @@ void BKE_scene_free(Scene *sce)
                MEM_freeN(sce->r.ffcodecdata.properties);
                sce->r.ffcodecdata.properties = NULL;
        }
-       
+
        for (srl = sce->r.layers.first; srl; srl = srl->next) {
+               if (srl->prop != NULL) {
+                       IDP_FreeProperty(srl->prop);
+                       MEM_freeN(srl->prop);
+               }
                BKE_freestyle_config_free(&srl->freestyleConfig);
        }
-       
+
        BLI_freelistN(&sce->markers);
        BLI_freelistN(&sce->transform_spaces);
        BLI_freelistN(&sce->r.layers);
index 60990c03b0efcdff52909341923847c783d537e1..ba04dd9b8f49e5e875a43743e425755064fa67c9 100644 (file)
@@ -549,11 +549,11 @@ int colorband_element_remove(struct ColorBand *coba, int index)
        if (index < 0 || index >= coba->tot)
                return 0;
 
+       coba->tot--;
        for (a = index; a < coba->tot; a++) {
                coba->data[a] = coba->data[a + 1];
        }
        if (coba->cur) coba->cur--;
-       coba->tot--;
        return 1;
 }
 
index a1aa2beeb7f779039177a8d2d4befa6300e3d90f..b0593c917cd66d03946ddc3c4994aa7bc7bd0487 100644 (file)
@@ -9601,8 +9601,8 @@ void draw_object_backbufsel(Scene *scene, View3D *v3d, RegionView3D *rv3d, Objec
                                bbs_mesh_wire(em, dm, bm_solidoffs);
                                bm_wireoffs = bm_solidoffs + em->bm->totedge;
 
-                               /* we draw verts if vert select mode or if in transform (for snap). */
-                               if ((ts->selectmode & SCE_SELECT_VERTEX) || (G.moving & G_TRANSFORM_EDIT)) {
+                               /* we draw verts if vert select mode. */
+                               if (ts->selectmode & SCE_SELECT_VERTEX) {
                                        bbs_mesh_verts(em, dm, bm_wireoffs);
                                        bm_vertoffs = bm_wireoffs + em->bm->totvert;
                                }