diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2017-08-02 21:10:36 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2017-08-02 21:59:19 +0300 |
commit | a280697e77be984021cdf3181a396f34529f933d (patch) | |
tree | 3c1bd48ffb3380230a3ca03868335f9e924f53c1 | |
parent | 4ad39964fd2f7e27ecc42946b421c22794e8f75f (diff) |
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.
-rw-r--r-- | intern/cycles/kernel/kernels/opencl/kernel_split.cl | 3 | ||||
-rw-r--r-- | intern/cycles/util/util_path.cpp | 10 |
2 files changed, 13 insertions, 0 deletions
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( |