Commit: aee7ae7cbb59008f38f0849de8b71a90d11d6339
Author: Thomas Dinges
Date:   Thu May 19 02:13:35 2016 +0200
Branches: soc-2016-cycles_images
https://developer.blender.org/rBaee7ae7cbb59008f38f0849de8b71a90d11d6339

Free the CUtexObjects properly.

===================================================================

M       intern/cycles/device/device.h
M       intern/cycles/device/device_cpu.cpp
M       intern/cycles/device/device_cuda.cpp
M       intern/cycles/device/device_multi.cpp
M       intern/cycles/device/device_network.cpp
M       intern/cycles/device/device_opencl.cpp
M       intern/cycles/render/image.cpp

===================================================================

diff --git a/intern/cycles/device/device.h b/intern/cycles/device/device.h
index 2bfcf67..1383a17 100644
--- a/intern/cycles/device/device.h
+++ b/intern/cycles/device/device.h
@@ -233,7 +233,11 @@ public:
                (void)flat_slot; /* Ignored. */
        };
 
-       virtual void tex_free(device_memory& /*mem*/) {};
+       virtual void tex_free(device_memory& /*mem*/,
+                             int flat_slot = -1)
+       {
+               (void)flat_slot; /* Ignored. */
+       };
 
        /* pixel memory */
        virtual void pixels_alloc(device_memory& mem);
diff --git a/intern/cycles/device/device_cpu.cpp 
b/intern/cycles/device/device_cpu.cpp
index 6b6be7c..3071c52 100644
--- a/intern/cycles/device/device_cpu.cpp
+++ b/intern/cycles/device/device_cpu.cpp
@@ -170,7 +170,7 @@ public:
                stats.mem_alloc(mem.device_size);
        }
 
-       void tex_free(device_memory& mem)
+       void tex_free(device_memory& mem, int /*flat_slot*/)
        {
                if(mem.device_pointer) {
                        mem.device_pointer = 0;
diff --git a/intern/cycles/device/device_cuda.cpp 
b/intern/cycles/device/device_cuda.cpp
index 0e629ec..79a70e0 100644
--- a/intern/cycles/device/device_cuda.cpp
+++ b/intern/cycles/device/device_cuda.cpp
@@ -222,7 +222,7 @@ public:
        {
                task_pool.stop();
 
-               tex_free(bindless_mapping);
+               tex_free(bindless_mapping, -1);
 
                cuda_assert(cuCtxDestroy(cuContext));
        }
@@ -714,7 +714,7 @@ public:
                tex_interp_map[mem.device_pointer] = (interpolation != 
INTERPOLATION_NONE);
        }
 
-       void tex_free(device_memory& mem)
+       void tex_free(device_memory& mem, int flat_slot)
        {
                if(mem.device_pointer) {
                        if(tex_interp_map[mem.device_pointer]) {
@@ -733,6 +733,11 @@ public:
                                mem_free(mem);
                        }
                }
+
+               /* Free CUtexObject (Bindless Textures) */
+               if(flat_slot != -1) {
+                       
cuTexObjectDestroy(bindless_mapping.get_data()[flat_slot]);
+               }
        }
 
        void path_trace(RenderTile& rtile, int sample, bool branched)
diff --git a/intern/cycles/device/device_multi.cpp 
b/intern/cycles/device/device_multi.cpp
index 34a97db..472d7fa 100644
--- a/intern/cycles/device/device_multi.cpp
+++ b/intern/cycles/device/device_multi.cpp
@@ -187,13 +187,13 @@ public:
                mem.device_pointer = unique_ptr++;
        }
 
-       void tex_free(device_memory& mem)
+       void tex_free(device_memory& mem, int flat_slot)
        {
                device_ptr tmp = mem.device_pointer;
 
                foreach(SubDevice& sub, devices) {
                        mem.device_pointer = sub.ptr_map[tmp];
-                       sub.device->tex_free(mem);
+                       sub.device->tex_free(mem, flat_slot);
                        sub.ptr_map.erase(sub.ptr_map.find(tmp));
                }
 
diff --git a/intern/cycles/device/device_network.cpp 
b/intern/cycles/device/device_network.cpp
index 449f543..8b7ee7c 100644
--- a/intern/cycles/device/device_network.cpp
+++ b/intern/cycles/device/device_network.cpp
@@ -188,7 +188,7 @@ public:
                snd.write_buffer((void*)mem.data_pointer, mem.memory_size());
        }
 
-       void tex_free(device_memory& mem)
+       void tex_free(device_memory& mem, int flat_slot)
        {
                if(mem.device_pointer) {
                        thread_scoped_lock lock(rpc_lock);
@@ -196,6 +196,7 @@ public:
                        RPCSend snd(socket, &error_func, "tex_free");
 
                        snd.add(mem);
+                       snd.add(flat_slot);
                        snd.write();
 
                        mem.device_pointer = 0;
diff --git a/intern/cycles/device/device_opencl.cpp 
b/intern/cycles/device/device_opencl.cpp
index 61f83f2..6a0399b 100644
--- a/intern/cycles/device/device_opencl.cpp
+++ b/intern/cycles/device/device_opencl.cpp
@@ -1195,7 +1195,7 @@ public:
                mem_map.insert(MemMap::value_type(name, mem.device_pointer));
        }
 
-       void tex_free(device_memory& mem)
+       void tex_free(device_memory& mem, int /*flat_slot*/)
        {
                if(mem.device_pointer) {
                        foreach(const MemMap::value_type& value, mem_map) {
diff --git a/intern/cycles/render/image.cpp b/intern/cycles/render/image.cpp
index 6bbfc88..0c60d96 100644
--- a/intern/cycles/render/image.cpp
+++ b/intern/cycles/render/image.cpp
@@ -771,7 +771,7 @@ void ImageManager::device_load_image(Device *device, 
DeviceScene *dscene, ImageD
 
                if(tex_img.device_pointer) {
                        thread_scoped_lock device_lock(device_mutex);
-                       device->tex_free(tex_img);
+                       device->tex_free(tex_img, flat_slot);
                }
 
                if(!file_load_float4_image(img, tex_img)) {
@@ -798,7 +798,7 @@ void ImageManager::device_load_image(Device *device, 
DeviceScene *dscene, ImageD
 
                if(tex_img.device_pointer) {
                        thread_scoped_lock device_lock(device_mutex);
-                       device->tex_free(tex_img);
+                       device->tex_free(tex_img, flat_slot);
                }
 
                if(!file_load_float_image(img, tex_img)) {
@@ -822,7 +822,7 @@ void ImageManager::device_load_image(Device *device, 
DeviceScene *dscene, ImageD
 
                if(tex_img.device_pointer) {
                        thread_scoped_lock device_lock(device_mutex);
-                       device->tex_free(tex_img);
+                       device->tex_free(tex_img, flat_slot);
                }
 
                if(!file_load_byte4_image(img, tex_img)) {
@@ -849,7 +849,7 @@ void ImageManager::device_load_image(Device *device, 
DeviceScene *dscene, ImageD
 
                if(tex_img.device_pointer) {
                        thread_scoped_lock device_lock(device_mutex);
-                       device->tex_free(tex_img);
+                       device->tex_free(tex_img, flat_slot);
                }
 
                if(!file_load_byte_image(img, tex_img)) {
@@ -876,6 +876,8 @@ void ImageManager::device_free_image(Device *device, 
DeviceScene *dscene, ImageD
 {
        Image *img = images[type][slot];
 
+       int flat_slot = type_index_to_flattened_slot(slot, type);
+
        if(img) {
                if(osl_texture_system && !img->builtin_data) {
 #ifdef WITH_OSL
@@ -888,7 +890,7 @@ void ImageManager::device_free_image(Device *device, 
DeviceScene *dscene, ImageD
 
                        if(tex_img.device_pointer) {
                                thread_scoped_lock device_lock(device_mutex);
-                               device->tex_free(tex_img);
+                               device->tex_free(tex_img, flat_slot);
                        }
 
                        tex_img.clear();
@@ -898,7 +900,7 @@ void ImageManager::device_free_image(Device *device, 
DeviceScene *dscene, ImageD
 
                        if(tex_img.device_pointer) {
                                thread_scoped_lock device_lock(device_mutex);
-                               device->tex_free(tex_img);
+                               device->tex_free(tex_img, flat_slot);
                        }
 
                        tex_img.clear();
@@ -908,7 +910,7 @@ void ImageManager::device_free_image(Device *device, 
DeviceScene *dscene, ImageD
 
                        if(tex_img.device_pointer) {
                                thread_scoped_lock device_lock(device_mutex);
-                               device->tex_free(tex_img);
+                               device->tex_free(tex_img, flat_slot);
                        }
 
                        tex_img.clear();
@@ -918,7 +920,7 @@ void ImageManager::device_free_image(Device *device, 
DeviceScene *dscene, ImageD
 
                        if(tex_img.device_pointer) {
                                thread_scoped_lock device_lock(device_mutex);
-                               device->tex_free(tex_img);
+                               device->tex_free(tex_img, flat_slot);
                        }
 
                        tex_img.clear();

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to