[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [39889] branches/cycles/intern/cycles: Cycles:

Brecht Van Lommel brechtvanlommel at pandora.be
Sat Sep 3 12:49:55 CEST 2011


Revision: 39889
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=39889
Author:   blendix
Date:     2011-09-03 10:49:54 +0000 (Sat, 03 Sep 2011)
Log Message:
-----------
Cycles:
* Compute MD5 hash to deal with nvidia opencl compiler cache not recognizing
  changes in #included files, makes it possible to do kernel compile only
  once and remember it for the next time blender is started.
* Kernel tweak to compile with ATI/linux. Enabling any more functionality than
  simple clay render still chokes the compiler though, without a specific error
  message ..

Modified Paths:
--------------
    branches/cycles/intern/cycles/blender/addon/enums.py
    branches/cycles/intern/cycles/device/device_opencl.cpp
    branches/cycles/intern/cycles/kernel/kernel_path.h
    branches/cycles/intern/cycles/kernel/kernel_types.h
    branches/cycles/intern/cycles/kernel/svm/svm_bsdf.h
    branches/cycles/intern/cycles/render/session.cpp
    branches/cycles/intern/cycles/util/util_md5.cpp
    branches/cycles/intern/cycles/util/util_md5.h
    branches/cycles/intern/cycles/util/util_path.cpp
    branches/cycles/intern/cycles/util/util_path.h

Modified: branches/cycles/intern/cycles/blender/addon/enums.py
===================================================================
--- branches/cycles/intern/cycles/blender/addon/enums.py	2011-09-03 09:43:20 UTC (rev 39888)
+++ branches/cycles/intern/cycles/blender/addon/enums.py	2011-09-03 10:49:54 UTC (rev 39889)
@@ -25,9 +25,9 @@
     if cuda and opencl:
         gpu_string = "GPU"
     elif cuda and not opencl:
-        gpu_string = "GPU (CUDA)"
+        gpu_string = "CUDA GPU"
     else:
-        gpu_string = "GPU (OpenCL)"
+        gpu_string = "OpenCL GPU"
     
     return gpu_string
 

Modified: branches/cycles/intern/cycles/device/device_opencl.cpp
===================================================================
--- branches/cycles/intern/cycles/device/device_opencl.cpp	2011-09-03 09:43:20 UTC (rev 39888)
+++ branches/cycles/intern/cycles/device/device_opencl.cpp	2011-09-03 10:49:54 UTC (rev 39889)
@@ -217,19 +217,19 @@
 		if(!opencl_version_check())
 			return false;
 
-		/* nvidia opencl cache doesn't not work correct with includes, so force recompile */
-		static double recompile_trick = 0.0;
-		if(recompile_trick == 0.0)
-			recompile_trick = time_dt();
+		/* we compile kernels consisting of many files. unfortunately opencl
+		   kernel caches do not seem to recognize changes in included files.
+		   so we force recompile on changes by adding the md5 hash of all files */
+		string kernel_path = path_get("kernel");
+		string kernel_md5 = path_files_md5_hash(kernel_path);
 
-		/* compile source */
-		string source = string_printf("#include \"kernel.cl\" // %lf\n", recompile_trick);
+		string source = "#include \"kernel.cl\" // " + kernel_md5 + "\n";
 		size_t source_len = source.size();
 		const char *source_str = source.c_str();
 
 		string build_options = "";
 
-		build_options += "-I " + path_get("kernel") + " -I " + path_get("util"); /* todo: escape path */
+		build_options += "-I " + kernel_path + ""; /* todo: escape path */
 		build_options += " -Werror -cl-fast-relaxed-math -cl-strict-aliasing";
 
 		cpProgram = clCreateProgramWithSource(cxContext, 1, &source_str, &source_len, &ciErr);

Modified: branches/cycles/intern/cycles/kernel/kernel_path.h
===================================================================
--- branches/cycles/intern/cycles/kernel/kernel_path.h	2011-09-03 09:43:20 UTC (rev 39888)
+++ branches/cycles/intern/cycles/kernel/kernel_path.h	2011-09-03 10:49:54 UTC (rev 39889)
@@ -194,7 +194,7 @@
 				L += throughput*shader_eval_background(kg, &sd, state.flag);
 				shader_release(kg, &sd);
 #else
-				L += make_float3(0.8f, 0.8f, 0.8f);
+				L += throughput*make_float3(0.8f, 0.8f, 0.8f);
 #endif
 			}
 

Modified: branches/cycles/intern/cycles/kernel/kernel_types.h
===================================================================
--- branches/cycles/intern/cycles/kernel/kernel_types.h	2011-09-03 09:43:20 UTC (rev 39888)
+++ branches/cycles/intern/cycles/kernel/kernel_types.h	2011-09-03 10:49:54 UTC (rev 39889)
@@ -32,12 +32,12 @@
 #define __DPDU__
 #define __UV__
 #define __BACKGROUND__
-#define __EMISSION__
 #define __CAUSTICS_TRICKS__
 #define __VISIBILITY_FLAG__
 
 #ifndef __KERNEL_OPENCL__
 #define __SVM__
+#define __EMISSION__
 #define __TEXTURES__
 #define __HOLDOUT__
 #endif

Modified: branches/cycles/intern/cycles/kernel/svm/svm_bsdf.h
===================================================================
--- branches/cycles/intern/cycles/kernel/svm/svm_bsdf.h	2011-09-03 09:43:20 UTC (rev 39888)
+++ branches/cycles/intern/cycles/kernel/svm/svm_bsdf.h	2011-09-03 10:49:54 UTC (rev 39889)
@@ -37,6 +37,7 @@
 		case CLOSURE_BSDF_DIFFUSE_ID:
 			label = bsdf_diffuse_sample(sd, randu, randv, eval, omega_in, &domega_in->dx, &domega_in->dy, pdf);
 			break;
+#ifdef __SVM__
 		case CLOSURE_BSDF_TRANSLUCENT_ID:
 			label = bsdf_translucent_sample(sd, randu, randv, eval, omega_in, &domega_in->dx, &domega_in->dy, pdf);
 			break;
@@ -71,6 +72,7 @@
 		case CLOSURE_BSDF_WESTIN_SHEEN_ID:
 			label = bsdf_westin_sheen_sample(sd, randu, randv, eval, omega_in, &domega_in->dx, &domega_in->dy, pdf);
 			break;
+#endif
 		default:
 			label = LABEL_NONE;
 			break;

Modified: branches/cycles/intern/cycles/render/session.cpp
===================================================================
--- branches/cycles/intern/cycles/render/session.cpp	2011-09-03 09:43:20 UTC (rev 39888)
+++ branches/cycles/intern/cycles/render/session.cpp	2011-09-03 10:49:54 UTC (rev 39889)
@@ -35,7 +35,7 @@
 : params(params_),
   tile_manager(params.progressive, params.passes, params.tile_size, params.min_size)
 {
-	device_use_gl = (params.device_type == DEVICE_CUDA && !params.background);
+	device_use_gl = ((params.device_type == DEVICE_CUDA || params.device_type == DEVICE_OPENCL) && !params.background);
 
 	device = Device::create(params.device_type, params.background, params.threads);
 	buffers = new RenderBuffers(device);
@@ -381,7 +381,7 @@
 void Session::run()
 {
 	/* load kernels */
-	progress.set_status("Loading render kernels");
+	progress.set_status("Loading render kernels (may take a few minutes)");
 
 	if(!device->load_kernels()) {
 		progress.set_status("Failed loading render kernel, see console for errors");

Modified: branches/cycles/intern/cycles/util/util_md5.cpp
===================================================================
--- branches/cycles/intern/cycles/util/util_md5.cpp	2011-09-03 09:43:20 UTC (rev 39888)
+++ branches/cycles/intern/cycles/util/util_md5.cpp	2011-09-03 10:49:54 UTC (rev 39889)
@@ -309,6 +309,29 @@
 		memcpy(buf, p, left);
 }
 
+bool MD5Hash::append_file(const string& filepath)
+{
+	FILE *f = fopen(filepath.c_str(), "rb");
+
+	if(!f)
+		return false;
+
+	const size_t buffer_size = 1024;
+	uint8_t buffer[buffer_size];
+	size_t n;
+
+	do {
+		n = fread(buffer, 1, buffer_size, f);
+		append(buffer, n);
+	} while(n == buffer_size);
+
+	bool success = (ferror(f) == 0);
+
+	fclose(f);
+	
+	return success;
+}
+
 void MD5Hash::finish(uint8_t digest[16])
 {
 	static const uint8_t pad[64] = {

Modified: branches/cycles/intern/cycles/util/util_md5.h
===================================================================
--- branches/cycles/intern/cycles/util/util_md5.h	2011-09-03 09:43:20 UTC (rev 39888)
+++ branches/cycles/intern/cycles/util/util_md5.h	2011-09-03 10:49:54 UTC (rev 39889)
@@ -41,6 +41,7 @@
 	~MD5Hash();
 
 	void append(const uint8_t *data, int size);
+	bool append_file(const string& filepath);
 	string get_hex();
 
 protected:

Modified: branches/cycles/intern/cycles/util/util_path.cpp
===================================================================
--- branches/cycles/intern/cycles/util/util_path.cpp	2011-09-03 09:43:20 UTC (rev 39888)
+++ branches/cycles/intern/cycles/util/util_path.cpp	2011-09-03 10:49:54 UTC (rev 39889)
@@ -17,6 +17,7 @@
  */
 
 #include "util_debug.h"
+#include "util_md5.h"
 #include "util_path.h"
 #include "util_string.h"
 
@@ -59,5 +60,29 @@
 	return (boost::filesystem::path(dir) / boost::filesystem::path(file)).string();
 }
 
+string path_files_md5_hash(const string& dir)
+{
+	/* computes md5 hash of all files in the directory */
+	MD5Hash hash;
+
+	if(boost::filesystem::exists(dir)) {
+		boost::filesystem::directory_iterator it(dir), it_end;
+
+		for(; it != it_end; it++) {
+			if(boost::filesystem::is_directory(it->status())) {
+				path_files_md5_hash(it->path().string());
+			}
+			else {
+				string filepath = it->path().string();
+
+				hash.append((const uint8_t*)filepath.c_str(), filepath.size());
+				hash.append_file(filepath);
+			}
+		}
+	}
+
+	return hash.get_hex();
+}
+
 CCL_NAMESPACE_END
 

Modified: branches/cycles/intern/cycles/util/util_path.h
===================================================================
--- branches/cycles/intern/cycles/util/util_path.h	2011-09-03 09:43:20 UTC (rev 39888)
+++ branches/cycles/intern/cycles/util/util_path.h	2011-09-03 10:49:54 UTC (rev 39889)
@@ -35,6 +35,8 @@
 string path_dirname(const string& path);
 string path_join(const string& dir, const string& file);
 
+string path_files_md5_hash(const string& dir);
+
 CCL_NAMESPACE_END
 
 #endif




More information about the Bf-blender-cvs mailing list