[Bf-blender-cvs] [a2e4ebd] master: Cycles code internals: add CPU kernel support for 3D image textures.

Brecht Van Lommel noreply at git.blender.org
Sat Mar 29 15:33:09 CET 2014


Commit: a2e4ebd36a319dc18f362b1f75863b8ee93eed7d
Author: Brecht Van Lommel
Date:   Sat Mar 29 13:03:48 2014 +0100
https://developer.blender.org/rBa2e4ebd36a319dc18f362b1f75863b8ee93eed7d

Cycles code internals: add CPU kernel support for 3D image textures.

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

M	intern/cycles/blender/blender_session.cpp
M	intern/cycles/blender/blender_session.h
M	intern/cycles/device/device_cpu.cpp
M	intern/cycles/device/device_cuda.cpp
M	intern/cycles/device/device_memory.h
M	intern/cycles/device/device_network.h
M	intern/cycles/kernel/kernel.cpp
M	intern/cycles/kernel/kernel.h
M	intern/cycles/kernel/kernel_compat_cpu.h
M	intern/cycles/render/image.cpp
M	intern/cycles/render/image.h

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

diff --git a/intern/cycles/blender/blender_session.cpp b/intern/cycles/blender/blender_session.cpp
index 09e7472..8243471 100644
--- a/intern/cycles/blender/blender_session.cpp
+++ b/intern/cycles/blender/blender_session.cpp
@@ -93,6 +93,11 @@ void BlenderSession::create_session()
 	/* create scene */
 	scene = new Scene(scene_params, session_params.device);
 
+	/* setup callbacks for builtin image support */
+	scene->image_manager->builtin_image_info_cb = function_bind(&BlenderSession::builtin_image_info, this, _1, _2, _3, _4, _5, _6, _7);
+	scene->image_manager->builtin_image_pixels_cb = function_bind(&BlenderSession::builtin_image_pixels, this, _1, _2, _3);
+	scene->image_manager->builtin_image_float_pixels_cb = function_bind(&BlenderSession::builtin_image_float_pixels, this, _1, _2, _3);
+
 	/* create session */
 	session = new Session(session_params);
 	session->scene = scene;
@@ -121,11 +126,6 @@ void BlenderSession::create_session()
 	session->reset(buffer_params, session_params.samples);
 
 	b_engine.use_highlight_tiles(session_params.progressive_refine == false);
-
-	/* setup callbacks for builtin image support */
-	scene->image_manager->builtin_image_info_cb = function_bind(&BlenderSession::builtin_image_info, this, _1, _2, _3, _4, _5, _6);
-	scene->image_manager->builtin_image_pixels_cb = function_bind(&BlenderSession::builtin_image_pixels, this, _1, _2, _3);
-	scene->image_manager->builtin_image_float_pixels_cb = function_bind(&BlenderSession::builtin_image_float_pixels, this, _1, _2, _3);
 }
 
 void BlenderSession::reset_session(BL::BlendData b_data_, BL::Scene b_scene_)
@@ -724,7 +724,7 @@ int BlenderSession::builtin_image_frame(const string &builtin_name)
 	return atoi(builtin_name.substr(last + 1, builtin_name.size() - last - 1).c_str());
 }
 
-void BlenderSession::builtin_image_info(const string &builtin_name, void *builtin_data, bool &is_float, int &width, int &height, int &channels)
+void BlenderSession::builtin_image_info(const string &builtin_name, void *builtin_data, bool &is_float, int &width, int &height, int &depth, int &channels)
 {
 	PointerRNA ptr;
 	RNA_id_pointer_create((ID*)builtin_data, &ptr);
@@ -734,12 +734,14 @@ void BlenderSession::builtin_image_info(const string &builtin_name, void *builti
 		is_float = b_image.is_float();
 		width = b_image.size()[0];
 		height = b_image.size()[1];
+		depth = 1;
 		channels = b_image.channels();
 	}
 	else {
 		is_float = false;
 		width = 0;
 		height = 0;
+		depth = 0;
 		channels = 0;
 	}
 }
diff --git a/intern/cycles/blender/blender_session.h b/intern/cycles/blender/blender_session.h
index 0568fb2..d30e3ed 100644
--- a/intern/cycles/blender/blender_session.h
+++ b/intern/cycles/blender/blender_session.h
@@ -99,7 +99,7 @@ protected:
 	void do_write_update_render_tile(RenderTile& rtile, bool do_update_only);
 
 	int builtin_image_frame(const string &builtin_name);
-	void builtin_image_info(const string &builtin_name, void *builtin_data, bool &is_float, int &width, int &height, int &channels);
+	void builtin_image_info(const string &builtin_name, void *builtin_data, bool &is_float, int &width, int &height, int &depth, int &channels);
 	bool builtin_image_pixels(const string &builtin_name, void *builtin_data, unsigned char *pixels);
 	bool builtin_image_float_pixels(const string &builtin_name, void *builtin_data, float *pixels);
 };
diff --git a/intern/cycles/device/device_cpu.cpp b/intern/cycles/device/device_cpu.cpp
index de44feb..e14e403 100644
--- a/intern/cycles/device/device_cpu.cpp
+++ b/intern/cycles/device/device_cpu.cpp
@@ -105,7 +105,7 @@ public:
 
 	void tex_alloc(const char *name, device_memory& mem, InterpolationType interpolation, bool periodic)
 	{
-		kernel_tex_copy(&kernel_globals, name, mem.data_pointer, mem.data_width, mem.data_height, interpolation);
+		kernel_tex_copy(&kernel_globals, name, mem.data_pointer, mem.data_width, mem.data_height, mem.data_depth, interpolation);
 		mem.device_pointer = mem.data_pointer;
 
 		stats.mem_alloc(mem.memory_size());
diff --git a/intern/cycles/device/device_cuda.cpp b/intern/cycles/device/device_cuda.cpp
index a8a3134..26d356a 100644
--- a/intern/cycles/device/device_cuda.cpp
+++ b/intern/cycles/device/device_cuda.cpp
@@ -461,6 +461,8 @@ public:
 
 	void tex_alloc(const char *name, device_memory& mem, InterpolationType interpolation, bool periodic)
 	{
+		/* todo: support 3D textures, only CPU for now */
+
 		/* determine format */
 		CUarray_format_enum format;
 		size_t dsize = datatype_size(mem.data_type);
diff --git a/intern/cycles/device/device_memory.h b/intern/cycles/device/device_memory.h
index 1427d12..8d6f4a4 100644
--- a/intern/cycles/device/device_memory.h
+++ b/intern/cycles/device/device_memory.h
@@ -169,6 +169,7 @@ public:
 	size_t data_size;
 	size_t data_width;
 	size_t data_height;
+	size_t data_depth;
 
 	/* device pointer */
 	device_ptr device_pointer;
@@ -195,6 +196,7 @@ public:
 		data_size = 0;
 		data_width = 0;
 		data_height = 0;
+		data_depth = 0;
 
 		assert(data_elements > 0);
 
@@ -204,20 +206,21 @@ public:
 	virtual ~device_vector() {}
 
 	/* vector functions */
-	T *resize(size_t width, size_t height = 0)
+	T *resize(size_t width, size_t height = 0, size_t depth = 0)
 	{
-		data_size = (height == 0)? width: width*height;
+		data_size = width * ((height == 0)? 1: height) * ((depth == 0)? 1: depth);
 		data.resize(data_size);
 		data_pointer = (device_ptr)&data[0];
 		data_width = width;
 		data_height = height;
+		data_depth = depth;
 
 		return &data[0];
 	}
 
-	T *copy(T *ptr, size_t width, size_t height = 0)
+	T *copy(T *ptr, size_t width, size_t height = 0, size_t depth = 0)
 	{
-		T *mem = resize(width, height);
+		T *mem = resize(width, height, depth);
 		memcpy(mem, ptr, memory_size());
 		return mem;
 	}
@@ -230,13 +233,14 @@ public:
 		}
 	}
 
-	void reference(T *ptr, size_t width, size_t height = 0)
+	void reference(T *ptr, size_t width, size_t height = 0, size_t depth = 0)
 	{
 		data.clear();
-		data_size = (height == 0)? width: width*height;
+		data_size = width * ((height == 0)? 1: height) * ((depth == 0)? 1: depth);
 		data_pointer = (device_ptr)ptr;
 		data_width = width;
 		data_height = height;
+		data_depth = depth;
 	}
 
 	void clear()
@@ -245,6 +249,7 @@ public:
 		data_pointer = 0;
 		data_width = 0;
 		data_height = 0;
+		data_depth = 0;
 		data_size = 0;
 	}
 
diff --git a/intern/cycles/device/device_network.h b/intern/cycles/device/device_network.h
index bf8f3c7..8596b61 100644
--- a/intern/cycles/device/device_network.h
+++ b/intern/cycles/device/device_network.h
@@ -118,7 +118,7 @@ public:
 	void add(const device_memory& mem)
 	{
 		archive & mem.data_type & mem.data_elements & mem.data_size;
-		archive & mem.data_width & mem.data_height & mem.device_pointer;
+		archive & mem.data_width & mem.data_height & mem.data_depth & mem.device_pointer;
 	}
 
 	template<typename T> void add(const T& data)
@@ -261,7 +261,7 @@ public:
 	void read(network_device_memory& mem)
 	{
 		*archive & mem.data_type & mem.data_elements & mem.data_size;
-		*archive & mem.data_width & mem.data_height & mem.device_pointer;
+		*archive & mem.data_width & mem.data_height & mem.data_depth & mem.device_pointer;
 
 		mem.data_pointer = 0;
 	}
diff --git a/intern/cycles/kernel/kernel.cpp b/intern/cycles/kernel/kernel.cpp
index 5d74fee..41cf7a6 100644
--- a/intern/cycles/kernel/kernel.cpp
+++ b/intern/cycles/kernel/kernel.cpp
@@ -37,7 +37,7 @@ void kernel_const_copy(KernelGlobals *kg, const char *name, void *host, size_t s
 		assert(0);
 }
 
-void kernel_tex_copy(KernelGlobals *kg, const char *name, device_ptr mem, size_t width, size_t height, InterpolationType interpolation)
+void kernel_tex_copy(KernelGlobals *kg, const char *name, device_ptr mem, size_t width, size_t height, size_t depth, InterpolationType interpolation)
 {
 	if(0) {
 	}
@@ -63,6 +63,7 @@ void kernel_tex_copy(KernelGlobals *kg, const char *name, device_ptr mem, size_t
 			tex->data = (float4*)mem;
 			tex->width = width;
 			tex->height = height;
+			tex->depth = depth;
 			tex->interpolation = interpolation;
 		}
 	}
@@ -79,6 +80,7 @@ void kernel_tex_copy(KernelGlobals *kg, const char *name, device_ptr mem, size_t
 			tex->data = (uchar4*)mem;
 			tex->width = width;
 			tex->height = height;
+			tex->depth = depth;
 			tex->interpolation = interpolation;
 		}
 	}
diff --git a/intern/cycles/kernel/kernel.h b/intern/cycles/kernel/kernel.h
index a4f13e7..c4a0864 100644
--- a/intern/cycles/kernel/kernel.h
+++ b/intern/cycles/kernel/kernel.h
@@ -32,7 +32,7 @@ void *kernel_osl_memory(KernelGlobals *kg);
 bool kernel_osl_use(KernelGlobals *kg);
 
 void kernel_const_copy(KernelGlobals *kg, const char *name, void *host, size_t size);
-void kernel_tex_copy(KernelGlobals *kg, const char *name, device_ptr mem, size_t width, size_t height, InterpolationType interpolation=INTERPOLATION_LINEAR);
+void kernel_tex_copy(KernelGlobals *kg, const char *name, device_ptr mem, size_t width, size_t height, size_t depth, InterpolationType interpolation=INTERPOLATION_LINEAR);
 
 void kernel_cpu_path_trace(KernelGlobals *kg, float *buffer, unsigned int *rng_state,
 	int sample, int x, int y, int offset, int stride);
diff --git a/intern/cycles/kernel/kernel_compat_cpu.h b/intern/cycles/kernel/kernel_compat_cpu.h
index 850ef0a..feaff50 100644
--- a/intern/cycles/kernel/kernel_compat_cpu.h
+++ b/intern/cycles/kernel/kernel_compat_cpu.h
@@ -99,6 +99,7 @@ template<typename T> struct texture_image  {
 			return make_float4(0.0f, 0.0f, 0.0f, 0.0f);
 
 		int ix, iy, nix, niy;
+
 		if(interpolation == INTERPOLATION_CLOSEST) {
 			frac(x*width, &ix);
 			frac(y*height, &iy);
@@ -131,17 +132,84 @@ template<typename T> struct texture_image  {
 				nix = wrap_clamp(ix+1, width);
 				niy = wrap_clamp(iy+1, height);
 			}
+
 			float4 r = (1.0f - ty)*(1.0f - tx)*read(data[ix + iy*width]);
 			r += (1.0f - ty)*tx*read(data[nix + iy*width]);
 			r += ty*(1.0f - tx)*read(data[ix + niy*width]);
 			r += ty*tx*read(data[nix + niy*width]);
+
+			return r;
+		}
+	}
+
+	ccl_always_inline float4 interp_3d(float x, float y, float z, bool periodic = false)
+	{
+		if(!data)
+			return make_float4(0.0f, 0.0f, 0.0f, 0.0f);
+
+		int ix, iy, iz, nix, niy, niz;
+
+		if(interpo

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list