[Bf-blender-cvs] [a280697e77b] master: Cycles: Support "precompiled" headers in include expansion algorithm

Sergey Sharybin noreply at git.blender.org
Wed Aug 2 21:13:40 CEST 2017


Commit: a280697e77be984021cdf3181a396f34529f933d
Author: Sergey Sharybin
Date:   Wed Aug 2 20:10:36 2017 +0200
Branches: master
https://developer.blender.org/rBa280697e77be984021cdf3181a396f34529f933d

Cycles: Support "precompiled" headers in include expansion algorithm

The idea here is that it is possible to mark certain include statements
as "precompiled" which means all subsequent includes of that file will
be replaced with an empty string.

This is a way to deal with tricky include pattern happening in single
program OpenCL split kernel which was including bunch of headers about
10 times.

This brings preprocessing time from ~1sec to ~0.1sec on my laptop.

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

M	intern/cycles/kernel/kernels/opencl/kernel_split.cl
M	intern/cycles/util/util_path.cpp

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

diff --git a/intern/cycles/kernel/kernels/opencl/kernel_split.cl b/intern/cycles/kernel/kernels/opencl/kernel_split.cl
index 651addb02f4..4cbda1bc2e7 100644
--- a/intern/cycles/kernel/kernels/opencl/kernel_split.cl
+++ b/intern/cycles/kernel/kernels/opencl/kernel_split.cl
@@ -14,6 +14,9 @@
  * limitations under the License.
  */
 
+#include "kernel/kernel_compat_opencl.h"  // PRECOMPILED
+#include "kernel/split/kernel_split_common.h"  // PRECOMPILED
+
 #include "kernel/kernels/opencl/kernel_state_buffer_size.cl"
 #include "kernel/kernels/opencl/kernel_data_init.cl"
 #include "kernel/kernels/opencl/kernel_path_init.cl"
diff --git a/intern/cycles/util/util_path.cpp b/intern/cycles/util/util_path.cpp
index 921a9a8915c..22b407ce926 100644
--- a/intern/cycles/util/util_path.cpp
+++ b/intern/cycles/util/util_path.cpp
@@ -771,8 +771,10 @@ bool path_remove(const string& path)
 
 struct SourceReplaceState {
 	typedef map<string, string> ProcessedMapping;
+
 	string base;
 	ProcessedMapping processed_files;
+	set<string> precompiled_headers;
 };
 
 static string line_directive(const SourceReplaceState& state,
@@ -811,6 +813,10 @@ static string path_source_replace_includes_recursive(
 	SourceReplaceState::ProcessedMapping::iterator replaced_file =
 	        state->processed_files.find(source_filepath);
 	if(replaced_file != state->processed_files.end()) {
+		if(state->precompiled_headers.find(source_filepath) !=
+		        state->precompiled_headers.end()) {
+			return "";
+		}
 		return replaced_file->second;
 	}
 	/* Perform full file processing.  */
@@ -827,11 +833,15 @@ static string path_source_replace_includes_recursive(
 					const size_t n_start = 1;
 					const size_t n_end = token.find("\"", n_start);
 					const string filename = token.substr(n_start, n_end - n_start);
+					const bool is_precompiled = string_endswith(token, "// PRECOMPILED");
 					string filepath = path_join(state->base, filename);
 					if(!path_exists(filepath)) {
 						filepath = path_join(path_dirname(source_filepath),
 						                     filename);
 					}
+					if(is_precompiled) {
+						state->precompiled_headers.insert(filepath);
+					}
 					string text;
 					if(path_read_text(filepath, text)) {
 						text = path_source_replace_includes_recursive(




More information about the Bf-blender-cvs mailing list