[Bf-blender-cvs] [e1db45c41a9] soc-2018-cycles-volumes: Updates to tiling function.

Geraldine Chua noreply at git.blender.org
Thu Jun 7 17:18:55 CEST 2018


Commit: e1db45c41a9acb9dadbb40183e1037d441a15035
Author: Geraldine Chua
Date:   Tue Jun 5 21:35:24 2018 +0800
Branches: soc-2018-cycles-volumes
https://developer.blender.org/rBe1db45c41a9acb9dadbb40183e1037d441a15035

Updates to tiling function.

1. Supports all data types (or at least the ones enumerated in
ImageDataType).

2. Will tile all volume attributes.

3. Changed method of activating tiling to a bool member of Image.

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

M	intern/cycles/blender/blender_mesh.cpp
M	intern/cycles/blender/blender_session.cpp
M	intern/cycles/kernel/kernels/cpu/kernel_cpu_image.h
M	intern/cycles/render/image.cpp
M	intern/cycles/render/image.h
M	intern/cycles/render/nodes.cpp
M	intern/cycles/util/CMakeLists.txt
M	intern/cycles/util/util_image_impl.h
D	intern/cycles/util/util_sparse_grid.cpp
M	intern/cycles/util/util_sparse_grid.h
M	intern/cycles/util/util_texture.h

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

diff --git a/intern/cycles/blender/blender_mesh.cpp b/intern/cycles/blender/blender_mesh.cpp
index 7d6ca18b074..8bf3f66dff6 100644
--- a/intern/cycles/blender/blender_mesh.cpp
+++ b/intern/cycles/blender/blender_mesh.cpp
@@ -342,6 +342,7 @@ static void create_mesh_volume_attribute(BL::Object& b_ob,
 	ImageMetaData metadata;
 	bool animated = false;
 	bool use_alpha = true;
+	bool make_sparse = true;
 
 	volume_data->manager = image_manager;
 	volume_data->slot = image_manager->add_image(
@@ -352,6 +353,7 @@ static void create_mesh_volume_attribute(BL::Object& b_ob,
 	        INTERPOLATION_LINEAR,
 	        EXTENSION_CLIP,
 	        use_alpha,
+	        make_sparse,
 	        metadata);
 }
 
diff --git a/intern/cycles/blender/blender_session.cpp b/intern/cycles/blender/blender_session.cpp
index 649d6edc679..00d23b9095e 100644
--- a/intern/cycles/blender/blender_session.cpp
+++ b/intern/cycles/blender/blender_session.cpp
@@ -1051,7 +1051,6 @@ void BlenderSession::builtin_image_info(const string &builtin_name,
 		BL::SmokeDomainSettings b_domain = object_smoke_domain_find(b_ob);
 
 		metadata.is_float = true;
-		metadata.is_volume = false;
 		metadata.depth = 1;
 		metadata.channels = 1;
 
@@ -1061,19 +1060,14 @@ void BlenderSession::builtin_image_info(const string &builtin_name,
 		if(builtin_name == Attribute::standard_name(ATTR_STD_VOLUME_DENSITY) ||
 		   builtin_name == Attribute::standard_name(ATTR_STD_VOLUME_FLAME) ||
 		   builtin_name == Attribute::standard_name(ATTR_STD_VOLUME_HEAT) ||
-		   builtin_name == Attribute::standard_name(ATTR_STD_VOLUME_TEMPERATURE)) {
+		   builtin_name == Attribute::standard_name(ATTR_STD_VOLUME_TEMPERATURE))
 			metadata.channels = 1;
-		}
-		else if(builtin_name == Attribute::standard_name(ATTR_STD_VOLUME_COLOR)) {
+		else if(builtin_name == Attribute::standard_name(ATTR_STD_VOLUME_COLOR))
 			metadata.channels = 4;
-			metadata.is_volume = true;
-		}
-		else if(builtin_name == Attribute::standard_name(ATTR_STD_VOLUME_VELOCITY)) {
+		else if(builtin_name == Attribute::standard_name(ATTR_STD_VOLUME_VELOCITY))
 			metadata.channels = 3;
-		}
-		else {
+		else
 			return;
-		}
 
 		int3 resolution = get_int3(b_domain.domain_resolution());
 		int amplify = (b_domain.use_high_resolution())? b_domain.amplify() + 1: 1;
diff --git a/intern/cycles/kernel/kernels/cpu/kernel_cpu_image.h b/intern/cycles/kernel/kernels/cpu/kernel_cpu_image.h
index 3c18b08d5b8..3435bcab70a 100644
--- a/intern/cycles/kernel/kernels/cpu/kernel_cpu_image.h
+++ b/intern/cycles/kernel/kernels/cpu/kernel_cpu_image.h
@@ -21,8 +21,7 @@
 
 CCL_NAMESPACE_BEGIN
 
-template<typename T, bool is_tile = false>
-struct TextureInterpolator  {
+template<typename T> struct TextureInterpolator  {
 #define SET_CUBIC_SPLINE_WEIGHTS(u, t) \
 	{ \
 		u[0] = (((-1.0f/6.0f)* t + 0.5f) * t - 0.5f) * t + (1.0f/6.0f); \
@@ -282,10 +281,13 @@ struct TextureInterpolator  {
 				return make_float4(0.0f);
 		}
 
-		if(is_tile) {
-			const SparseTile *data = (const SparseTile*)info.data;
-			const int *ofs = (const int*)info.offsets;
-			return read(get_value(data, ofs, ix, iy, iz, width, height, depth));
+		const int *ofs = (const int*)info.offsets;
+		if(ofs) {
+			const SparseTile<T> *data = (const SparseTile<T>*)info.data;
+			return read(get_value<T>(data, ofs, ix, iy, iz,
+			                         compute_tile_resolution(width),
+			                         compute_tile_resolution(height),
+			                         compute_tile_resolution(depth)));
 		}
 		else {
 			const T *data = (const T*)info.data;
@@ -338,23 +340,26 @@ struct TextureInterpolator  {
 		}
 
 		float4 r;
+		const int *ofs = (const int*)info.offsets;
 
-		if(is_tile) {
-			const SparseTile *data = (const SparseTile*)info.data;
-			const int *ofs = (const int*)info.offsets;
+		if(ofs) {
+			const SparseTile<T> *data = (const SparseTile<T>*)info.data;
+			int tiw = compute_tile_resolution(width);
+			int tih = compute_tile_resolution(height);
+			int tid = compute_tile_resolution(depth);
 			/* Initial check if either voxel is in an active tile. */
-			if(!is_active(ofs, ix, iy, iz, width, height, depth) &&
-			   !is_active(ofs, nix, niy, niz, width, height, depth)) {
+			if(!tile_is_active(ofs, ix, iy, iz, tiw, tih, tid) &&
+			   !tile_is_active(ofs, nix, niy, niz, tiw, tih, tid)) {
 				return make_float4(0.0f);
 			}
-			r  = (1.0f - tz)*(1.0f - ty)*(1.0f - tx) * read(get_value(data, ofs, ix,  iy,  iz,  width, height, depth));
-			r += (1.0f - tz)*(1.0f - ty)*tx			 * read(get_value(data, ofs, nix, iy,  iz,  width, height, depth));
-			r += (1.0f - tz)*ty*(1.0f - tx)			 * read(get_value(data, ofs, ix,  niy, iz,  width, height, depth));
-			r += (1.0f - tz)*ty*tx					 * read(get_value(data, ofs, nix, niy, iz,  width, height, depth));
-			r += tz*(1.0f - ty)*(1.0f - tx)			 * read(get_value(data, ofs, ix,  iy,  niz, width, height, depth));
-			r += tz*(1.0f - ty)*tx					 * read(get_value(data, ofs, nix, iy,  niz, width, height, depth));
-			r += tz*ty*(1.0f - tx)					 * read(get_value(data, ofs, ix,  niy, niz, width, height, depth));
-			r += tz*ty*tx							 * read(get_value(data, ofs, nix, niy, niz, width, height, depth));
+			r  = (1.0f - tz)*(1.0f - ty)*(1.0f - tx) * read(get_value<T>(data, ofs, ix,  iy,  iz,  tiw, tih, tid));
+			r += (1.0f - tz)*(1.0f - ty)*tx			 * read(get_value<T>(data, ofs, nix, iy,  iz,  tiw, tih, tid));
+			r += (1.0f - tz)*ty*(1.0f - tx)			 * read(get_value<T>(data, ofs, ix,  niy, iz,  tiw, tih, tid));
+			r += (1.0f - tz)*ty*tx					 * read(get_value<T>(data, ofs, nix, niy, iz,  tiw, tih, tid));
+			r += tz*(1.0f - ty)*(1.0f - tx)			 * read(get_value<T>(data, ofs, ix,  iy,  niz, tiw, tih, tid));
+			r += tz*(1.0f - ty)*tx					 * read(get_value<T>(data, ofs, nix, iy,  niz, tiw, tih, tid));
+			r += tz*ty*(1.0f - tx)					 * read(get_value<T>(data, ofs, ix,  niy, niz, tiw, tih, tid));
+			r += tz*ty*tx							 * read(get_value<T>(data, ofs, nix, niy, niz, tiw, tih, tid));
 		}
 		else {
 			const T *data = (const T*)info.data;
@@ -384,8 +389,6 @@ struct TextureInterpolator  {
 #endif
 	float4 interp_3d_tricubic(const TextureInfo& info, float x, float y, float z)
 	{
-		/* todo (gchua): add tile support for this */
-		kernel_assert(!is_tile);
 		int width = info.width;
 		int height = info.height;
 		int depth = info.depth;
@@ -538,8 +541,6 @@ ccl_device float4 kernel_tex_image_interp_3d(KernelGlobals *kg, int id, float x,
 			return TextureInterpolator<half4>::interp_3d(info, x, y, z, interp);
 		case IMAGE_DATA_TYPE_BYTE4:
 			return TextureInterpolator<uchar4>::interp_3d(info, x, y, z, interp);
-		case IMAGE_DATA_TYPE_VOLUME:
-			return TextureInterpolator<float4, true>::interp_3d(info, x, y, z, interp);
 		case IMAGE_DATA_TYPE_FLOAT4:
 		default:
 			return TextureInterpolator<float4>::interp_3d(info, x, y, z, interp);
diff --git a/intern/cycles/render/image.cpp b/intern/cycles/render/image.cpp
index f7e2f6488a1..c1caea34619 100644
--- a/intern/cycles/render/image.cpp
+++ b/intern/cycles/render/image.cpp
@@ -22,6 +22,7 @@
 #include "util/util_logging.h"
 #include "util/util_path.h"
 #include "util/util_progress.h"
+#include "util/util_sparse_grid.h"
 #include "util/util_texture.h"
 
 #ifdef WITH_OSL
@@ -108,10 +109,7 @@ bool ImageManager::get_image_metadata(const string& filename,
 			return false;
 		}
 
-		if(metadata.is_volume) {
-			metadata.type = IMAGE_DATA_TYPE_VOLUME;
-		}
-		else if(metadata.is_float) {
+		if(metadata.is_float) {
 			metadata.is_linear = true;
 			metadata.type = (metadata.channels > 1) ? IMAGE_DATA_TYPE_FLOAT4 : IMAGE_DATA_TYPE_FLOAT;
 		}
@@ -186,10 +184,7 @@ bool ImageManager::get_image_metadata(const string& filename,
 	/* set type and channels */
 	metadata.channels = spec.nchannels;
 
-	if(metadata.is_volume) {
-		metadata.type = IMAGE_DATA_TYPE_VOLUME;
-	}
-	else if(metadata.is_half) {
+	if(metadata.is_half) {
 		metadata.type = (metadata.channels > 1) ? IMAGE_DATA_TYPE_HALF4 : IMAGE_DATA_TYPE_HALF;
 	}
 	else if(metadata.is_float) {
@@ -241,8 +236,6 @@ string ImageManager::name_from_type(int type)
 		return "half4";
 	else if(type == IMAGE_DATA_TYPE_HALF)
 		return "half";
-	else if(type == IMAGE_DATA_TYPE_VOLUME)
-		return "volume";
 	else
 		return "byte4";
 }
@@ -268,6 +261,7 @@ int ImageManager::add_image(const string& filename,
                             InterpolationType interpolation,
                             ExtensionType extension,
                             bool use_alpha,
+                            bool make_sparse,
                             ImageMetaData& metadata)
 {
 	Image *img;
@@ -345,6 +339,7 @@ int ImageManager::add_image(const string& filename,
 	img->extension = extension;
 	img->users = 1;
 	img->use_alpha = use_alpha;
+	img->make_sparse = make_sparse;
 	img->mem = NULL;
 
 	images[type][slot] = img;
@@ -582,7 +577,6 @@ bool ImageManager::file_load_image(Image *img,
 	 * but device doesn't support single channel textures.
 	 */
 	bool is_rgba = (type == IMAGE_DATA_TYPE_FLOAT4 ||
-	                type == IMAGE_DATA_TYPE_VOLUME ||
 	                type == IMAGE_DATA_TYPE_HALF4 ||
 	                type == IMAGE_DATA_TYPE_BYTE4);
 	if(is_rgba) {
@@ -691,87 +685,160 @@ bool ImageManager::file_load_image(Image *img,
 	return true;
 }
 
-
-/* If volume, call this to convert to sparse grid. */
-template<TypeDesc::BASETYPE FileFormat,
-         typename StorageType,
+template<typename StorageType,
          typename DeviceType>
-bool ImageManager::file_load_image(Image *img,
-                                   ImageDataType type,
-                                   int texture_limit,
-                                   device_vector<SparseTile>& tex_img,
-                                   device_vector<int>& tex_offsets)
+void ImageManager::file_load_failed(device_vector<DeviceType> *tex_img,
+                                    ImageDataType type)
 {
+	/* On failure to load, we set a 1x1 pixels pink image. */
+	thread_scoped_lock device_lock(device_mutex);
+	StorageType *pixels = (StorageType*)tex_img->alloc(1, 1);
 
-	device_vector<DeviceType> *tex_img_dense
-		= new device_vector<DeviceType>(NULL, img->mem_name.c_str(), MEM_TEXTURE);
-
-	if(!file_load_image<FileFormat, StorageType, DeviceType>(img,

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list