[Bf-blender-cvs] [d86092c] soc-2016-cycles_images: Don't pass flat_slot to tex_free(), handle this inside the device.

Thomas Dinges noreply at git.blender.org
Thu May 19 11:42:14 CEST 2016


Commit: d86092cecd893d6c6a84bf686b71b67cea508969
Author: Thomas Dinges
Date:   Thu May 19 11:41:45 2016 +0200
Branches: soc-2016-cycles_images
https://developer.blender.org/rBd86092cecd893d6c6a84bf686b71b67cea508969

Don't pass flat_slot to tex_free(), handle this inside the device.

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

M	intern/cycles/device/device.h
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 1383a17..2bfcf67 100644
--- a/intern/cycles/device/device.h
+++ b/intern/cycles/device/device.h
@@ -233,11 +233,7 @@ public:
 		(void)flat_slot; /* Ignored. */
 	};
 
-	virtual void tex_free(device_memory& /*mem*/,
-	                      int flat_slot = -1)
-	{
-		(void)flat_slot; /* Ignored. */
-	};
+	virtual void tex_free(device_memory& /*mem*/) {};
 
 	/* pixel memory */
 	virtual void pixels_alloc(device_memory& mem);
diff --git a/intern/cycles/device/device_cuda.cpp b/intern/cycles/device/device_cuda.cpp
index 145ab97..741dcd5 100644
--- a/intern/cycles/device/device_cuda.cpp
+++ b/intern/cycles/device/device_cuda.cpp
@@ -85,6 +85,7 @@ public:
 	CUcontext cuContext;
 	CUmodule cuModule;
 	map<device_ptr, bool> tex_interp_map;
+	map<device_ptr, uint> tex_bindless_map;
 	int cuDevId;
 	int cuDevArchitecture;
 	bool first_error;
@@ -223,7 +224,7 @@ public:
 		task_pool.stop();
 
 		if(info.has_bindless_textures)
-			tex_free(bindless_mapping, -1);
+			tex_free(bindless_mapping);
 
 		cuda_assert(cuCtxDestroy(cuContext));
 	}
@@ -405,7 +406,7 @@ public:
 	void load_bindless_mapping()
 	{
 		if(info.has_bindless_textures && sync_bindless_mapping) {
-			tex_free(bindless_mapping, -1);
+			tex_free(bindless_mapping);
 			tex_alloc("__bindless_mapping", bindless_mapping, INTERPOLATION_NONE, EXTENSION_REPEAT, 0);
 			sync_bindless_mapping = false;
 		}
@@ -661,6 +662,12 @@ public:
 			else
 				cuda_assert(cuMemcpyHtoA(handle, 0, (void*)mem.data_pointer, size));
 
+			/* Fermi and Kepler */
+			mem.device_pointer = (device_ptr)handle;
+			mem.device_size = size;
+
+			stats.mem_alloc(size);
+
 			/* Bindless Textures - Kepler */
 			if(has_bindless_textures) {
 				CUDA_RESOURCE_DESC resDesc;
@@ -684,6 +691,7 @@ public:
 				bindless_mapping.get_data()[flat_slot] = (uint)tex;
 
 				sync_bindless_mapping = true;
+				tex_bindless_map[mem.device_pointer] = (uint)tex;
 			}
 			/* Regular Textures - Fermi */
 			else {
@@ -693,12 +701,6 @@ public:
 			}
 
 			cuda_pop_context();
-
-			/* Fermi and Kepler */
-			mem.device_pointer = (device_ptr)handle;
-			mem.device_size = size;
-
-			stats.mem_alloc(size);
 		}
 
 		/* Fermi, Data and Image Textures */
@@ -720,7 +722,7 @@ public:
 		tex_interp_map[mem.device_pointer] = (interpolation != INTERPOLATION_NONE);
 	}
 
-	void tex_free(device_memory& mem, int flat_slot)
+	void tex_free(device_memory& mem)
 	{
 		if(mem.device_pointer) {
 			if(tex_interp_map[mem.device_pointer]) {
@@ -728,6 +730,12 @@ public:
 				cuArrayDestroy((CUarray)mem.device_pointer);
 				cuda_pop_context();
 
+				/* Free CUtexObject (Bindless Textures) */
+				if(info.has_bindless_textures && tex_bindless_map[mem.device_pointer]) {
+					uint flat_slot = tex_bindless_map[mem.device_pointer];
+					cuTexObjectDestroy(flat_slot);
+				}
+
 				tex_interp_map.erase(tex_interp_map.find(mem.device_pointer));
 				mem.device_pointer = 0;
 
@@ -739,11 +747,6 @@ public:
 				mem_free(mem);
 			}
 		}
-
-		/* Free CUtexObject (Bindless Textures) */
-		if(info.has_bindless_textures && 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 472d7fa..34a97db 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, int flat_slot)
+	void tex_free(device_memory& mem)
 	{
 		device_ptr tmp = mem.device_pointer;
 
 		foreach(SubDevice& sub, devices) {
 			mem.device_pointer = sub.ptr_map[tmp];
-			sub.device->tex_free(mem, flat_slot);
+			sub.device->tex_free(mem);
 			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 8b7ee7c..449f543 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, int flat_slot)
+	void tex_free(device_memory& mem)
 	{
 		if(mem.device_pointer) {
 			thread_scoped_lock lock(rpc_lock);
@@ -196,7 +196,6 @@ 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 6a0399b..61f83f2 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, int /*flat_slot*/)
+	void tex_free(device_memory& mem)
 	{
 		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 0c60d96..d8fb5ba 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, flat_slot);
+			device->tex_free(tex_img);
 		}
 
 		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, flat_slot);
+			device->tex_free(tex_img);
 		}
 
 		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, flat_slot);
+			device->tex_free(tex_img);
 		}
 
 		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, flat_slot);
+			device->tex_free(tex_img);
 		}
 
 		if(!file_load_byte_image(img, tex_img)) {
@@ -890,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, flat_slot);
+				device->tex_free(tex_img);
 			}
 
 			tex_img.clear();
@@ -900,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, flat_slot);
+				device->tex_free(tex_img);
 			}
 
 			tex_img.clear();
@@ -910,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, flat_slot);
+				device->tex_free(tex_img);
 			}
 
 			tex_img.clear();
@@ -920,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, flat_slot);
+				device->tex_free(tex_img);
 			}
 
 			tex_img.clear();




More information about the Bf-blender-cvs mailing list