[Bf-blender-cvs] [0a9c1e51f56] soc-2018-cycles-volumes: Create SparseTextureInfo.

Geraldine Chua noreply at git.blender.org
Thu Aug 2 18:10:10 CEST 2018


Commit: 0a9c1e51f56dfdf75c7f88972ff609ea0a5b71ca
Author: Geraldine Chua
Date:   Thu Aug 2 23:32:32 2018 +0800
Branches: soc-2018-cycles-volumes
https://developer.blender.org/rB0a9c1e51f56dfdf75c7f88972ff609ea0a5b71ca

Create SparseTextureInfo.

Will be used for better organization of info used to convert dense to
sparse coordinates in volumes. Also added back tricubic interpolation
of sparse grids.

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

M	intern/cycles/device/device_cpu.cpp
M	intern/cycles/kernel/kernels/cpu/kernel_cpu_image.h
M	intern/cycles/util/util_texture.h

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

diff --git a/intern/cycles/device/device_cpu.cpp b/intern/cycles/device/device_cpu.cpp
index f2c643f5202..47ef95cb59f 100644
--- a/intern/cycles/device/device_cpu.cpp
+++ b/intern/cycles/device/device_cpu.cpp
@@ -417,27 +417,25 @@ public:
 			info.cl_buffer = 0;
 			info.interpolation = mem.interpolation;
 			info.extension = mem.extension;
-			info.grid_type = mem.grid_type;
 			info.width = mem.real_width;
 			info.height = mem.real_height;
 			info.depth = mem.real_depth;
 
-			switch(mem.grid_type) {
-				case IMAGE_GRID_TYPE_SPARSE:
-					info.util = (uint64_t)sparse_mem->host_pointer;
-					info.tiled_width = get_tile_res(info.width);
-					info.tiled_height = get_tile_res(info.height);
-					info.even_width = info.width - (info.width % TILE_SIZE);
-					info.even_height = info.height - (info.height % TILE_SIZE);
-					info.last_tile_dim = 0;
-					info.last_tile_dim |= ((info.width % TILE_SIZE) << LAST_TILE_WIDTH_MASK);
-					info.last_tile_dim |= ((info.height % TILE_SIZE) << LAST_TILE_HEIGHT_MASK);
-					break;
-				case IMAGE_GRID_TYPE_OPENVDB:
-				case IMAGE_GRID_TYPE_DEFAULT:
-				default:
-					info.util = 0;
+			SparseTextureInfo sparse_info;
+			if(mem.grid_type == IMAGE_GRID_TYPE_SPARSE) {
+				sparse_info.offsets = (uint64_t)sparse_mem->host_pointer;
+				sparse_info.tiled_w = get_tile_res(info.width);
+				sparse_info.tiled_h = get_tile_res(info.height);
+				sparse_info.remain_w = info.width % TILE_SIZE;
+				sparse_info.remain_h = info.height % TILE_SIZE;
+				sparse_info.div_w = info.width - sparse_info.remain_w;
+				sparse_info.div_h = info.height - sparse_info.remain_h;
+			}
+			else {
+				sparse_info.offsets = 0;
 			}
+			info.sparse_info = sparse_info;
+
 			need_texture_info = true;
 		}
 
diff --git a/intern/cycles/kernel/kernels/cpu/kernel_cpu_image.h b/intern/cycles/kernel/kernels/cpu/kernel_cpu_image.h
index 08f79278cf1..02ca18f97bb 100644
--- a/intern/cycles/kernel/kernels/cpu/kernel_cpu_image.h
+++ b/intern/cycles/kernel/kernels/cpu/kernel_cpu_image.h
@@ -74,40 +74,38 @@ struct TextureInterpolator {
 		return read(data[y * width + x]);
 	}
 
-	/* Default grid voxel access. */
-	static ccl_always_inline float4 read_data(const T *data,
-	                                          const void */*util*/,
-	                                          int x, int y, int z,
-	                                          int width, int height,
-	                                          int /*tiw*/, int /*tih*/,
-	                                          int /*evw*/, int /*evh*/,
-	                                          int /*ltw*/, int /*lth*/)
-	{
-		return read(data[x + width * (y + z * height)]);
-	}
-
 	/* Sparse grid voxel access. */
 	static ccl_always_inline float4 read_data(const T *data,
-	                                          const int *sparse_indexes,
-	                                          int x, int y, int z,
-	                                          int /*width*/, int /*height*/,
-	                                          int tiw, int tih,
-	                                          int evw, int evh,
-	                                          int ltw, int lth)
+	                                          const SparseTextureInfo s_info,
+	                                          const int *offsets,
+	                                          int x, int y, int z)
 	{
 		int tix = x / TILE_SIZE, itix = x % TILE_SIZE,
 		    tiy = y / TILE_SIZE, itiy = y % TILE_SIZE,
 		    tiz = z / TILE_SIZE, itiz = z % TILE_SIZE;
-		int sparse_index = sparse_indexes[(tix + tiw * (tiy + tiz * tih))];
+		int tile_index = tix + s_info.tiled_w * (tiy + tiz * s_info.tiled_h);
+		int sparse_index = offsets[tile_index];
 		if(sparse_index < 0) {
 			return make_float4(0.0f);
 		}
-		int itiw = (x > evw) ? ltw : TILE_SIZE;
-		int itih = (y > evh) ? lth : TILE_SIZE;
+		int itiw = (x > s_info.div_w) ? s_info.remain_w : TILE_SIZE;
+		int itih = (y > s_info.div_h) ? s_info.remain_h : TILE_SIZE;
 		int in_tile_index = itix + itiw * (itiy + itiz * itih);
 		return read(data[sparse_index + in_tile_index]);
 	}
 
+	static ccl_always_inline float4 read_data(const T *data,
+	                                          const SparseTextureInfo s_info,
+	                                          const int *offsets,
+	                                          int index,
+	                                          int width, int height, int /*depth*/)
+	{
+		int x = index % width;
+		int y = (index / width) % height;
+		int z = index / (width * height);
+		return read_data(data, s_info, offsets, x, y, z);
+	}
+
 	static ccl_always_inline int wrap_periodic(int x, int width)
 	{
 		x %= width;
@@ -315,13 +313,13 @@ struct TextureInterpolator {
 		}
 
 		const T *data = (const T*)info.data;
-		const int *util = (const int*)info.util;
-		int ltw = info.last_tile_dim & LAST_TILE_WIDTH_MASK;
-		int lth = info.last_tile_dim & LAST_TILE_HEIGHT_MASK;
+		const SparseTextureInfo s_info = info.sparse_info;
 
-		return read_data(data, util, ix, iy, iz, width, height,
-		                 info.tiled_width, info.tiled_height,
-		                 info.even_width, info.even_height, ltw, lth);
+		if(UNLIKELY(s_info.offsets)) {
+			const int *offsets = (const int*)s_info.offsets;
+			return read_data(data, s_info, offsets, ix, iy, iz);
+		}
+		return read(data[ix + width * (iy + iz * height)]);
 	}
 
 	static ccl_always_inline float4 interp_3d_linear(const TextureInfo& info,
@@ -370,22 +368,29 @@ struct TextureInterpolator {
 
 		float4 r;
 		const T *data = (const T*)info.data;
-		const int *util = (const int*)info.util;
-		int tiw = info.tiled_width;
-		int tih = info.tiled_height;
-		int evw = info.even_width;
-		int evh = info.even_height;
-		int ltw = info.last_tile_dim & LAST_TILE_WIDTH_MASK;
-		int lth = info.last_tile_dim & LAST_TILE_HEIGHT_MASK;
-
-		r  = (1.0f - tz)*(1.0f - ty)*(1.0f - tx) * read_data(data, util, ix,  iy,  iz,  width, height, tiw, tih, evw, evh, ltw, lth);
-		r += (1.0f - tz)*(1.0f - ty)*tx          * read_data(data, util, nix, iy,  iz,  width, height, tiw, tih, evw, evh, ltw, lth);
-		r += (1.0f - tz)*ty*(1.0f - tx)          * read_data(data, util, ix,  niy, iz,  width, height, tiw, tih, evw, evh, ltw, lth);
-		r += (1.0f - tz)*ty*tx                   * read_data(data, util, nix, niy, iz,  width, height, tiw, tih, evw, evh, ltw, lth);
-		r += tz*(1.0f - ty)*(1.0f - tx)          * read_data(data, util, ix,  iy,  niz, width, height, tiw, tih, evw, evh, ltw, lth);
-		r += tz*(1.0f - ty)*tx                   * read_data(data, util, nix, iy,  niz, width, height, tiw, tih, evw, evh, ltw, lth);
-		r += tz*ty*(1.0f - tx)                   * read_data(data, util, ix,  niy, niz, width, height, tiw, tih, evw, evh, ltw, lth);
-		r += tz*ty*tx                            * read_data(data, util, nix, niy, niz, width, height, tiw, tih, evw, evh, ltw, lth);
+		const SparseTextureInfo s_info = info.sparse_info;
+
+		if(UNLIKELY(s_info.offsets)) {
+			const int *offsets = (const int*)s_info.offsets;
+			r  = (1.0f - tz)*(1.0f - ty)*(1.0f - tx) * read_data(data, s_info, offsets, ix,  iy,  iz);
+			r += (1.0f - tz)*(1.0f - ty)*tx          * read_data(data, s_info, offsets, nix, iy,  iz);
+			r += (1.0f - tz)*ty*(1.0f - tx)          * read_data(data, s_info, offsets, ix,  niy, iz);
+			r += (1.0f - tz)*ty*tx                   * read_data(data, s_info, offsets, nix, niy, iz);
+			r += tz*(1.0f - ty)*(1.0f - tx)          * read_data(data, s_info, offsets, ix,  iy,  niz);
+			r += tz*(1.0f - ty)*tx                   * read_data(data, s_info, offsets, nix, iy,  niz);
+			r += tz*ty*(1.0f - tx)                   * read_data(data, s_info, offsets, ix,  niy, niz);
+			r += tz*ty*tx                            * read_data(data, s_info, offsets, nix, niy, niz);
+		}
+		else {
+			r  = (1.0f - tz)*(1.0f - ty)*(1.0f - tx) * read(data[ix  + width * (iy  + iz  * height)]);
+			r += (1.0f - tz)*(1.0f - ty)*tx          * read(data[nix + width * (iy  + iz  * height)]);
+			r += (1.0f - tz)*ty*(1.0f - tx)          * read(data[ix  + width * (niy + iz  * height)]);
+			r += (1.0f - tz)*ty*tx                   * read(data[nix + width * (niy + iz  * height)]);
+			r += tz*(1.0f - ty)*(1.0f - tx)          * read(data[ix  + width * (iy  + niz * height)]);
+			r += tz*(1.0f - ty)*tx                   * read(data[nix + width * (iy  + niz * height)]);
+			r += tz*ty*(1.0f - tx)                   * read(data[ix  + width * (niy + niz * height)]);
+			r += tz*ty*tx                            * read(data[nix + width * (niy + niz * height)]);
+		}
 
 		return r;
 	}
@@ -475,8 +480,9 @@ struct TextureInterpolator {
 		/* Some helper macro to keep code reasonable size,
 		 * let compiler to inline all the matrix multiplications.
 		 */
-		/* To-do (gschua): fix voxel access for non-default grid types. */
-#define DATA(x, y, z) (read(data[xc[x] + yc[y] + zc[z]]))
+#define DATA(x, y, z) (UNLIKELY(s_info.offsets) ? \
+		read_data(data, s_info, offsets, xc[x] + yc[y] + zc[z], width, height, depth) : \
+		read(data[xc[x] + yc[y] + zc[z]]))
 #define COL_TERM(col, row) \
 		(v[col] * (u[0] * DATA(0, col, row) + \
 		           u[1] * DATA(1, col, row) + \
@@ -494,6 +500,8 @@ struct TextureInterpolator {
 
 		/* Actual interpolation. */
 		const T *data = (const T*)info.data;
+		const SparseTextureInfo s_info = info.sparse_info;
+		const int *offsets = (const int*)s_info.offsets;
 		return ROW_TERM(0) + ROW_TERM(1) + ROW_TERM(2) + ROW_TERM(3);
 
 #undef COL_TERM
diff --git a/intern/cycles/util/util_texture.h b/intern/cycles/util/util_texture.h
index bceea1b26b6..ddc29cb774a 100644
--- a/intern/cycles/util/util_texture.h
+++ b/intern/cycles/util/util_texture.h
@@ -81,30 +81,31 @@ typedef enum ExtensionType {
 	EXTENSION_NUM_TYPES,
 } ExtensionType;
 
+typedef struct SparseTextureInfo {
+	/* Tile offsets for sparse volumes. */
+	uint64_t offsets;
+	/* Dim / TILE_SIZE */
+	uint tiled_w, tiled_h;
+	/* Dim % TILE_SIZE */
+	uint remain_w, remain_h;
+	/* Dim - (Dim % TILE_SIZE) */
+	uint div_w, div_h;
+} SparseTextureInfo;
+
 typedef struct TextureInfo {
 	/* Pointer, offset or texture depending on device. */
 	uint64_t data;
-	/* References the offsets for tiles in sparse volumes. */
-	uint64_t u

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list