Cycles: Cleanup, indent nested preprocessor directives
Quite straightforward, main trick is happening in path_source_replace_includes(). Reviewers: brecht, dingto, lukasstockner97, juicyfruit Differential Revision: https://developer.blender.org/D1794
This commit is contained in:
@@ -294,7 +294,7 @@ ccl_device_intersect bool scene_intersect_shadow_all(KernelGlobals *kg, const Ra
|
||||
|
||||
return bvh_intersect_shadow_all(kg, ray, isect, max_hits, num_hits);
|
||||
}
|
||||
#endif
|
||||
#endif /* __SHADOW_RECORD_ALL__ */
|
||||
|
||||
#ifdef __VOLUME__
|
||||
ccl_device_intersect bool scene_intersect_volume(KernelGlobals *kg,
|
||||
@@ -335,7 +335,7 @@ ccl_device_intersect bool scene_intersect_volume(KernelGlobals *kg,
|
||||
|
||||
# endif /* __KERNEL_CPU__ */
|
||||
}
|
||||
#endif
|
||||
#endif /* __VOLUME__ */
|
||||
|
||||
#ifdef __VOLUME_RECORD_ALL__
|
||||
ccl_device_intersect uint scene_intersect_volume_all(KernelGlobals *kg,
|
||||
@@ -366,7 +366,7 @@ ccl_device_intersect uint scene_intersect_volume_all(KernelGlobals *kg,
|
||||
|
||||
return bvh_intersect_volume_all(kg, ray, isect, max_hits);
|
||||
}
|
||||
#endif
|
||||
#endif /* __VOLUME_RECORD_ALL__ */
|
||||
|
||||
|
||||
/* Ray offset to avoid self intersection.
|
||||
|
@@ -84,7 +84,7 @@ ccl_device bool BVH_FUNCTION_FULL_NAME(BVH)(KernelGlobals *kg,
|
||||
ssef tsplat(0.0f, 0.0f, -isect_t, -isect_t);
|
||||
|
||||
gen_idirsplat_swap(pn, shuf_identity, shuf_swap, idir, idirsplat, shufflexyz);
|
||||
#endif
|
||||
#endif /* __KERNEL_SSE2__ */
|
||||
|
||||
IsectPrecalc isect_precalc;
|
||||
triangle_intersect_precalc(dir, &isect_precalc);
|
||||
|
@@ -283,7 +283,7 @@ ccl_device uint BVH_FUNCTION_FULL_NAME(BVH)(KernelGlobals *kg,
|
||||
}
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#endif /* BVH_MOTION */
|
||||
#if BVH_FEATURE(BVH_HAIR)
|
||||
case PRIMITIVE_CURVE:
|
||||
case PRIMITIVE_MOTION_CURVE: {
|
||||
@@ -326,7 +326,7 @@ ccl_device uint BVH_FUNCTION_FULL_NAME(BVH)(KernelGlobals *kg,
|
||||
}
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#endif /* BVH_HAIR */
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
|
@@ -147,7 +147,7 @@ ccl_device bool BVH_FUNCTION_FULL_NAME(QBVH)(KernelGlobals *kg,
|
||||
&dist);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
#endif /* BVH_HAIR_MINIMUM_WIDTH */
|
||||
{
|
||||
traverseChild = qbvh_node_intersect(kg,
|
||||
tnear,
|
||||
|
@@ -343,7 +343,7 @@ ccl_device uint BVH_FUNCTION_FULL_NAME(QBVH)(KernelGlobals *kg,
|
||||
}
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#endif /* BVH_HAIR */
|
||||
}
|
||||
}
|
||||
#if BVH_FEATURE(BVH_INSTANCING)
|
||||
|
@@ -54,7 +54,7 @@ typedef struct KernelGlobals {
|
||||
|
||||
} KernelGlobals;
|
||||
|
||||
#endif
|
||||
#endif /* __KERNEL_CPU__ */
|
||||
|
||||
/* For CUDA, constant memory textures must be globals, so we can't put them
|
||||
* into a struct. As a result we don't actually use this struct and use actual
|
||||
@@ -74,7 +74,7 @@ typedef struct KernelGlobals {} KernelGlobals;
|
||||
# define KERNEL_IMAGE_TEX(type, ttype, name) ttype name;
|
||||
# include "kernel_textures.h"
|
||||
|
||||
#endif
|
||||
#endif /* __KERNEL_CUDA__ */
|
||||
|
||||
/* OpenCL */
|
||||
|
||||
@@ -93,7 +93,7 @@ typedef ccl_addr_space struct KernelGlobals {
|
||||
# endif
|
||||
} KernelGlobals;
|
||||
|
||||
#endif
|
||||
#endif /* __KERNEL_OPENCL__ */
|
||||
|
||||
/* Interpolated lookup table access */
|
||||
|
||||
|
@@ -75,7 +75,7 @@ CCL_NAMESPACE_BEGIN
|
||||
# define __VOLUME_SCATTER__
|
||||
# define __SHADOW_RECORD_ALL__
|
||||
# define __VOLUME_RECORD_ALL__
|
||||
#endif
|
||||
#endif /* __KERNEL_CPU__ */
|
||||
|
||||
#ifdef __KERNEL_CUDA__
|
||||
# define __KERNEL_SHADING__
|
||||
@@ -85,7 +85,7 @@ CCL_NAMESPACE_BEGIN
|
||||
# define __VOLUME_SCATTER__
|
||||
# define __SUBSURFACE__
|
||||
# define __CMJ__
|
||||
#endif
|
||||
#endif /* __KERNEL_CUDA__ */
|
||||
|
||||
#ifdef __KERNEL_OPENCL__
|
||||
|
||||
@@ -97,7 +97,7 @@ CCL_NAMESPACE_BEGIN
|
||||
# ifdef __KERNEL_EXPERIMENTAL__
|
||||
# define __CMJ__
|
||||
# endif
|
||||
#endif
|
||||
# endif /* __KERNEL_OPENCL_NVIDIA__ */
|
||||
|
||||
# ifdef __KERNEL_OPENCL_APPLE__
|
||||
# define __KERNEL_SHADING__
|
||||
@@ -109,7 +109,7 @@ CCL_NAMESPACE_BEGIN
|
||||
# ifdef __KERNEL_EXPERIMENTAL__
|
||||
# define __CMJ__
|
||||
# endif
|
||||
#endif
|
||||
# endif /* __KERNEL_OPENCL_NVIDIA__ */
|
||||
|
||||
# ifdef __KERNEL_OPENCL_AMD__
|
||||
# define __CL_USE_NATIVE__
|
||||
@@ -125,7 +125,7 @@ CCL_NAMESPACE_BEGIN
|
||||
# ifdef __KERNEL_EXPERIMENTAL__
|
||||
# define __TRANSPARENT_SHADOWS__
|
||||
# endif
|
||||
#endif
|
||||
# endif /* __KERNEL_OPENCL_AMD__ */
|
||||
|
||||
# ifdef __KERNEL_OPENCL_INTEL_CPU__
|
||||
# define __CL_USE_NATIVE__
|
||||
@@ -134,9 +134,9 @@ CCL_NAMESPACE_BEGIN
|
||||
# ifdef __KERNEL_EXPERIMENTAL__
|
||||
# define __CMJ__
|
||||
# endif
|
||||
#endif
|
||||
# endif /* __KERNEL_OPENCL_INTEL_CPU__ */
|
||||
|
||||
#endif // __KERNEL_OPENCL__
|
||||
#endif /* __KERNEL_OPENCL__ */
|
||||
|
||||
/* kernel features */
|
||||
#define __SOBOL__
|
||||
|
@@ -33,5 +33,4 @@
|
||||
# include "kernel.h"
|
||||
# define KERNEL_ARCH cpu_avx
|
||||
# include "kernel_cpu_impl.h"
|
||||
|
||||
#endif /* WITH_CYCLES_OPTIMIZED_KERNEL_AVX */
|
||||
|
@@ -34,5 +34,4 @@
|
||||
# include "kernel.h"
|
||||
# define KERNEL_ARCH cpu_avx2
|
||||
# include "kernel_cpu_impl.h"
|
||||
|
||||
#endif /* WITH_CYCLES_OPTIMIZED_KERNEL_AVX2 */
|
||||
|
@@ -29,5 +29,4 @@
|
||||
# include "kernel.h"
|
||||
# define KERNEL_ARCH cpu_sse2
|
||||
# include "kernel_cpu_impl.h"
|
||||
|
||||
#endif /* WITH_CYCLES_OPTIMIZED_KERNEL_SSE2 */
|
||||
|
@@ -31,5 +31,4 @@
|
||||
# include "kernel.h"
|
||||
# define KERNEL_ARCH cpu_sse3
|
||||
# include "kernel_cpu_impl.h"
|
||||
|
||||
#endif /* WITH_CYCLES_OPTIMIZED_KERNEL_SSE3 */
|
||||
|
@@ -32,5 +32,4 @@
|
||||
# include "kernel.h"
|
||||
# define KERNEL_ARCH cpu_sse41
|
||||
# include "kernel_cpu_impl.h"
|
||||
|
||||
#endif /* WITH_CYCLES_OPTIMIZED_KERNEL_SSE41 */
|
||||
|
@@ -720,31 +720,46 @@ bool path_remove(const string& path)
|
||||
return remove(path.c_str()) == 0;
|
||||
}
|
||||
|
||||
string path_source_replace_includes(const string& source_, const string& path)
|
||||
string path_source_replace_includes(const string& source, const string& path)
|
||||
{
|
||||
/* our own little c preprocessor that replaces #includes with the file
|
||||
/* Our own little c preprocessor that replaces #includes with the file
|
||||
* contents, to work around issue of opencl drivers not supporting
|
||||
* include paths with spaces in them */
|
||||
string source = source_;
|
||||
const string include = "#include \"";
|
||||
size_t n, pos = 0;
|
||||
* include paths with spaces in them.
|
||||
*/
|
||||
|
||||
while((n = source.find(include, pos)) != string::npos) {
|
||||
size_t n_start = n + include.size();
|
||||
size_t n_end = source.find("\"", n_start);
|
||||
string filename = source.substr(n_start, n_end - n_start);
|
||||
string result = "";
|
||||
vector<string> lines;
|
||||
string_split(lines, source, "\n");
|
||||
|
||||
for(size_t i = 0; i < lines.size(); ++i) {
|
||||
string line = lines[i];
|
||||
if(line[0] == '#') {
|
||||
string token = string_strip(line.substr(1, line.size() - 1));
|
||||
if(string_startswith(token, "include")) {
|
||||
token = string_strip(token.substr(7, token.size() - 7));
|
||||
if(token[0] == '"') {
|
||||
size_t n_start = 1;
|
||||
size_t n_end = token.find("\"", n_start);
|
||||
string filename = token.substr(n_start, n_end - n_start);
|
||||
string text, filepath = path_join(path, filename);
|
||||
|
||||
if(path_read_text(filepath, text)) {
|
||||
text = path_source_replace_includes(text, path_dirname(filepath));
|
||||
source.replace(n, n_end + 1 - n, "\n" + text + "\n");
|
||||
/* Replace include directories with both current path
|
||||
* and path extracted from the include file.
|
||||
* Not totally robust, but works fine for Cycles kernel
|
||||
* and avoids having list of include directories.x
|
||||
*/
|
||||
text = path_source_replace_includes(
|
||||
text, path_dirname(filepath));
|
||||
text = path_source_replace_includes(text, path);
|
||||
line = token.replace(0, n_end + 1, "\n" + text + "\n");
|
||||
}
|
||||
else
|
||||
pos = n_end;
|
||||
}
|
||||
}
|
||||
}
|
||||
result += line + "\n";
|
||||
}
|
||||
|
||||
return source;
|
||||
return result;
|
||||
}
|
||||
|
||||
FILE *path_fopen(const string& path, const string& mode)
|
||||
|
Reference in New Issue
Block a user