Merge branch 'master' into blender2.8
authorBastien Montagne <montagne29@wanadoo.fr>
Tue, 8 Aug 2017 17:16:25 +0000 (19:16 +0200)
committerBastien Montagne <montagne29@wanadoo.fr>
Tue, 8 Aug 2017 17:16:25 +0000 (19:16 +0200)
Conflicts:
source/blender/modifiers/intern/MOD_meshsequencecache.c

intern/cycles/device/opencl/opencl_base.cpp
intern/cycles/render/image.cpp
intern/cycles/render/image.h
source/blender/editors/interface/interface_layout.c
source/blender/modifiers/intern/MOD_meshsequencecache.c

index 63b5e004b7d5ab49665680c8e9db81b6d9fdc0d2..d3f0172a7b650fb798244dbeb3ed2798dcbe4311 100644 (file)
 
 CCL_NAMESPACE_BEGIN
 
+struct texture_slot_t {
+       string name;
+       int slot;
+};
+
 bool OpenCLDeviceBase::opencl_error(cl_int err)
 {
        if(err != CL_SUCCESS) {
@@ -511,7 +516,9 @@ void OpenCLDeviceBase::tex_alloc(const char *name,
 
        memory_manager.alloc(name, mem);
 
-       textures[name] = {&mem, interpolation, extension};
+       textures[name] = (Texture){.mem = &mem,
+                                  .interpolation = interpolation,
+                                  .extension = extension};
 
        textures_need_update = true;
 }
@@ -609,16 +616,12 @@ void OpenCLDeviceBase::flush_texture_buffers()
        /* Setup slots for textures. */
        int num_slots = 0;
 
-       struct texture_slot_t {
-               string name;
-               int slot;
-       };
-
        vector<texture_slot_t> texture_slots;
 
-#define KERNEL_TEX(type, ttype, name) \
-       if(textures.find(#name) != textures.end()) { \
-               texture_slots.push_back({#name, num_slots}); \
+#define KERNEL_TEX(type, ttype, slot_name) \
+       if(textures.find(#slot_name) != textures.end()) { \
+               texture_slots.push_back((texture_slot_t){.name = #slot_name, \
+                                                        .slot = num_slots}); \
        } \
        num_slots++;
 #include "kernel/kernel_textures.h"
@@ -632,7 +635,9 @@ void OpenCLDeviceBase::flush_texture_buffers()
                        int pos = name.rfind("_");
                        int id = atoi(name.data() + pos + 1);
 
-                       texture_slots.push_back({name, num_data_slots + id});
+                       texture_slots.push_back((texture_slot_t){
+                                   .name = name,
+                                   .slot = num_data_slots + id});
 
                        num_slots = max(num_slots, num_data_slots + id + 1);
                }
index 80ec77f8b4ab3640e00e7394c0e7ff8c84712e9f..cfdf26c67873878c089c8b0e3150b8ec57156c3c 100644 (file)
@@ -716,12 +716,7 @@ void ImageManager::device_load_image(Device *device,
                if(dscene->tex_float4_image[slot] == NULL)
                        dscene->tex_float4_image[slot] = new device_vector<float4>();
                device_vector<float4>& tex_img = *dscene->tex_float4_image[slot];
-
-               if(tex_img.device_pointer) {
-                       thread_scoped_lock device_lock(device_mutex);
-                       device->tex_free(tex_img);
-               }
-
+               device_tex_free_safe(device, tex_img);
                if(!file_load_image<TypeDesc::FLOAT, float>(img,
                                                            type,
                                                            texture_limit,
@@ -748,12 +743,7 @@ void ImageManager::device_load_image(Device *device,
                if(dscene->tex_float_image[slot] == NULL)
                        dscene->tex_float_image[slot] = new device_vector<float>();
                device_vector<float>& tex_img = *dscene->tex_float_image[slot];
-
-               if(tex_img.device_pointer) {
-                       thread_scoped_lock device_lock(device_mutex);
-                       device->tex_free(tex_img);
-               }
-
+               device_tex_free_safe(device, tex_img);
                if(!file_load_image<TypeDesc::FLOAT, float>(img,
                                                            type,
                                                            texture_limit,
@@ -777,12 +767,7 @@ void ImageManager::device_load_image(Device *device,
                if(dscene->tex_byte4_image[slot] == NULL)
                        dscene->tex_byte4_image[slot] = new device_vector<uchar4>();
                device_vector<uchar4>& tex_img = *dscene->tex_byte4_image[slot];
-
-               if(tex_img.device_pointer) {
-                       thread_scoped_lock device_lock(device_mutex);
-                       device->tex_free(tex_img);
-               }
-
+               device_tex_free_safe(device, tex_img);
                if(!file_load_image<TypeDesc::UINT8, uchar>(img,
                                                            type,
                                                            texture_limit,
@@ -809,12 +794,7 @@ void ImageManager::device_load_image(Device *device,
                if(dscene->tex_byte_image[slot] == NULL)
                        dscene->tex_byte_image[slot] = new device_vector<uchar>();
                device_vector<uchar>& tex_img = *dscene->tex_byte_image[slot];
-
-               if(tex_img.device_pointer) {
-                       thread_scoped_lock device_lock(device_mutex);
-                       device->tex_free(tex_img);
-               }
-
+               device_tex_free_safe(device, tex_img);
                if(!file_load_image<TypeDesc::UINT8, uchar>(img,
                                                            type,
                                                            texture_limit,
@@ -837,12 +817,7 @@ void ImageManager::device_load_image(Device *device,
                if(dscene->tex_half4_image[slot] == NULL)
                        dscene->tex_half4_image[slot] = new device_vector<half4>();
                device_vector<half4>& tex_img = *dscene->tex_half4_image[slot];
-
-               if(tex_img.device_pointer) {
-                       thread_scoped_lock device_lock(device_mutex);
-                       device->tex_free(tex_img);
-               }
-
+               device_tex_free_safe(device, tex_img);
                if(!file_load_image<TypeDesc::HALF, half>(img,
                                                          type,
                                                          texture_limit,
@@ -868,12 +843,7 @@ void ImageManager::device_load_image(Device *device,
                if(dscene->tex_half_image[slot] == NULL)
                        dscene->tex_half_image[slot] = new device_vector<half>();
                device_vector<half>& tex_img = *dscene->tex_half_image[slot];
-
-               if(tex_img.device_pointer) {
-                       thread_scoped_lock device_lock(device_mutex);
-                       device->tex_free(tex_img);
-               }
-
+               device_tex_free_safe(device, tex_img);
                if(!file_load_image<TypeDesc::HALF, half>(img,
                                                          type,
                                                          texture_limit,
@@ -957,11 +927,7 @@ void ImageManager::device_free_image(Device *device, DeviceScene *dscene, ImageD
                                        tex_img = NULL;
                        }
                        if(tex_img) {
-                               if(tex_img->device_pointer) {
-                                       thread_scoped_lock device_lock(device_mutex);
-                                       device->tex_free(*tex_img);
-                               }
-
+                               device_tex_free_safe(device, *tex_img);
                                delete tex_img;
                        }
                }
@@ -1097,5 +1063,16 @@ void ImageManager::device_free(Device *device, DeviceScene *dscene)
        dscene->tex_half_image.clear();
 }
 
+void ImageManager::device_tex_free_safe(Device *device, device_memory& mem)
+{
+       if(mem.device_pointer) {
+               thread_scoped_lock device_lock(device_mutex);
+               device->tex_free(mem);
+       }
+       else {
+               device->tex_free(mem);
+       }
+}
+
 CCL_NAMESPACE_END
 
index c86d1cbedbf50f2065b5d83d7fece843eae414d2..abd1abbd729374a9f047b211742fddcdef04fce3 100644 (file)
@@ -160,6 +160,11 @@ private:
                               DeviceScene *dscene,
                               ImageDataType type,
                               int slot);
+
+       /* Will do locking when needed and make sure possible memory manager from
+        * the device implementation is aware of freed texture.
+        */
+       void device_tex_free_safe(Device *device, device_memory& mem);
 };
 
 CCL_NAMESPACE_END
index f2bdbe3865bdac100aa4e39203be90c4fbafc9b1..d2ab88c9c070bb734519d53bfadef600c5a0f44f 100644 (file)
@@ -2387,7 +2387,6 @@ static void ui_litem_estimate_box(uiLayout *litem)
        uiStyle *style = litem->root->style;
 
        ui_litem_estimate_column(litem, true);
-       litem->item.flag &= ~UI_ITEM_MIN;
        litem->w += 2 * style->boxspace;
        litem->h += 2 * style->boxspace;
 }
index 5d623295edf843e1b3417dcd8be666294494f369..5c2f1aba8e16e9fcdeb1e5c1265fa96e90759925 100644 (file)
  */
 
 #include "DNA_cachefile_types.h"
+#include "DNA_mesh_types.h"
 #include "DNA_modifier_types.h"
 #include "DNA_object_types.h"
 #include "DNA_scene_types.h"
 
 #include "BKE_cachefile.h"
 #include "BKE_DerivedMesh.h"
+#include "BKE_cdderivedmesh.h"
 #include "BKE_global.h"
 #include "BKE_library.h"
 #include "BKE_library_query.h"
@@ -94,11 +96,15 @@ static bool isDisabled(ModifierData *md, int UNUSED(useRenderParams))
 
 static DerivedMesh *applyModifier(ModifierData *md, struct EvaluationContext *UNUSED(eval_ctx),
                                   Object *ob, DerivedMesh *dm,
-                                  ModifierApplyFlag flag)
+                                  ModifierApplyFlag UNUSED(flag))
 {
 #ifdef WITH_ALEMBIC
        MeshSeqCacheModifierData *mcmd = (MeshSeqCacheModifierData *) md;
 
+       /* Only used to check wehther we are operating on org data or not... */
+       Mesh *me = (ob->type == OB_MESH) ? ob->data : NULL;
+       DerivedMesh *org_dm = dm;
+
        Scene *scene = md->scene;
        const float frame = BKE_scene_frame_get(scene);
        const float time = BKE_cachefile_time_offset(mcmd->cache_file, frame, FPS);
@@ -120,6 +126,16 @@ static DerivedMesh *applyModifier(ModifierData *md, struct EvaluationContext *UN
                }
        }
 
+       if (me != NULL) {
+               MVert *mvert = dm->getVertArray(dm);
+               MEdge *medge = dm->getEdgeArray(dm);
+               MPoly *mpoly = dm->getPolyArray(dm);
+               if ((me->mvert == mvert) || (me->medge == medge) || (me->mpoly == mpoly)) {
+                       /* We need to duplicate data here, otherwise we'll modify org mesh, see T51701. */
+                       dm = CDDM_copy(dm);
+               }
+       }
+
        DerivedMesh *result = ABC_read_mesh(mcmd->reader,
                                            ob,
                                            dm,
@@ -131,11 +147,15 @@ static DerivedMesh *applyModifier(ModifierData *md, struct EvaluationContext *UN
                modifier_setError(md, "%s", err_str);
        }
 
+       if (!ELEM(result, NULL, dm) && (dm != org_dm)) {
+               dm->release(dm);
+               dm = org_dm;
+       }
+
        return result ? result : dm;
-       UNUSED_VARS(flag);
 #else
        return dm;
-       UNUSED_VARS(md, ob, flag);
+       UNUSED_VARS(md, ob);
 #endif
 }