forked from bartvdbraak/blender
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.
This commit is contained in:
parent
4ad39964fd
commit
a280697e77
@ -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"
|
||||
|
@ -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(
|
||||
|
Loading…
Reference in New Issue
Block a user