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:
Sergey Sharybin
2016-02-12 18:33:43 +01:00
parent 0e47e0cc9e
commit 700722f686
43 changed files with 649 additions and 639 deletions

View File

@@ -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); return bvh_intersect_shadow_all(kg, ray, isect, max_hits, num_hits);
} }
#endif #endif /* __SHADOW_RECORD_ALL__ */
#ifdef __VOLUME__ #ifdef __VOLUME__
ccl_device_intersect bool scene_intersect_volume(KernelGlobals *kg, 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 /* __KERNEL_CPU__ */
} }
#endif #endif /* __VOLUME__ */
#ifdef __VOLUME_RECORD_ALL__ #ifdef __VOLUME_RECORD_ALL__
ccl_device_intersect uint scene_intersect_volume_all(KernelGlobals *kg, 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); return bvh_intersect_volume_all(kg, ray, isect, max_hits);
} }
#endif #endif /* __VOLUME_RECORD_ALL__ */
/* Ray offset to avoid self intersection. /* Ray offset to avoid self intersection.

View File

@@ -84,7 +84,7 @@ ccl_device bool BVH_FUNCTION_FULL_NAME(BVH)(KernelGlobals *kg,
ssef tsplat(0.0f, 0.0f, -isect_t, -isect_t); ssef tsplat(0.0f, 0.0f, -isect_t, -isect_t);
gen_idirsplat_swap(pn, shuf_identity, shuf_swap, idir, idirsplat, shufflexyz); gen_idirsplat_swap(pn, shuf_identity, shuf_swap, idir, idirsplat, shufflexyz);
#endif #endif /* __KERNEL_SSE2__ */
IsectPrecalc isect_precalc; IsectPrecalc isect_precalc;
triangle_intersect_precalc(dir, &isect_precalc); triangle_intersect_precalc(dir, &isect_precalc);

View File

@@ -283,7 +283,7 @@ ccl_device uint BVH_FUNCTION_FULL_NAME(BVH)(KernelGlobals *kg,
} }
break; break;
} }
#endif #endif /* BVH_MOTION */
#if BVH_FEATURE(BVH_HAIR) #if BVH_FEATURE(BVH_HAIR)
case PRIMITIVE_CURVE: case PRIMITIVE_CURVE:
case PRIMITIVE_MOTION_CURVE: { case PRIMITIVE_MOTION_CURVE: {
@@ -326,7 +326,7 @@ ccl_device uint BVH_FUNCTION_FULL_NAME(BVH)(KernelGlobals *kg,
} }
break; break;
} }
#endif #endif /* BVH_HAIR */
default: { default: {
break; break;
} }

View File

@@ -147,7 +147,7 @@ ccl_device bool BVH_FUNCTION_FULL_NAME(QBVH)(KernelGlobals *kg,
&dist); &dist);
} }
else else
#endif #endif /* BVH_HAIR_MINIMUM_WIDTH */
{ {
traverseChild = qbvh_node_intersect(kg, traverseChild = qbvh_node_intersect(kg,
tnear, tnear,

View File

@@ -343,7 +343,7 @@ ccl_device uint BVH_FUNCTION_FULL_NAME(QBVH)(KernelGlobals *kg,
} }
break; break;
} }
#endif #endif /* BVH_HAIR */
} }
} }
#if BVH_FEATURE(BVH_INSTANCING) #if BVH_FEATURE(BVH_INSTANCING)

View File

@@ -54,7 +54,7 @@ typedef struct KernelGlobals {
} KernelGlobals; } KernelGlobals;
#endif #endif /* __KERNEL_CPU__ */
/* For CUDA, constant memory textures must be globals, so we can't put them /* 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 * 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; # define KERNEL_IMAGE_TEX(type, ttype, name) ttype name;
# include "kernel_textures.h" # include "kernel_textures.h"
#endif #endif /* __KERNEL_CUDA__ */
/* OpenCL */ /* OpenCL */
@@ -93,7 +93,7 @@ typedef ccl_addr_space struct KernelGlobals {
# endif # endif
} KernelGlobals; } KernelGlobals;
#endif #endif /* __KERNEL_OPENCL__ */
/* Interpolated lookup table access */ /* Interpolated lookup table access */

View File

@@ -75,7 +75,7 @@ CCL_NAMESPACE_BEGIN
# define __VOLUME_SCATTER__ # define __VOLUME_SCATTER__
# define __SHADOW_RECORD_ALL__ # define __SHADOW_RECORD_ALL__
# define __VOLUME_RECORD_ALL__ # define __VOLUME_RECORD_ALL__
#endif #endif /* __KERNEL_CPU__ */
#ifdef __KERNEL_CUDA__ #ifdef __KERNEL_CUDA__
# define __KERNEL_SHADING__ # define __KERNEL_SHADING__
@@ -85,7 +85,7 @@ CCL_NAMESPACE_BEGIN
# define __VOLUME_SCATTER__ # define __VOLUME_SCATTER__
# define __SUBSURFACE__ # define __SUBSURFACE__
# define __CMJ__ # define __CMJ__
#endif #endif /* __KERNEL_CUDA__ */
#ifdef __KERNEL_OPENCL__ #ifdef __KERNEL_OPENCL__
@@ -97,7 +97,7 @@ CCL_NAMESPACE_BEGIN
# ifdef __KERNEL_EXPERIMENTAL__ # ifdef __KERNEL_EXPERIMENTAL__
# define __CMJ__ # define __CMJ__
# endif # endif
#endif # endif /* __KERNEL_OPENCL_NVIDIA__ */
# ifdef __KERNEL_OPENCL_APPLE__ # ifdef __KERNEL_OPENCL_APPLE__
# define __KERNEL_SHADING__ # define __KERNEL_SHADING__
@@ -109,7 +109,7 @@ CCL_NAMESPACE_BEGIN
# ifdef __KERNEL_EXPERIMENTAL__ # ifdef __KERNEL_EXPERIMENTAL__
# define __CMJ__ # define __CMJ__
# endif # endif
#endif # endif /* __KERNEL_OPENCL_NVIDIA__ */
# ifdef __KERNEL_OPENCL_AMD__ # ifdef __KERNEL_OPENCL_AMD__
# define __CL_USE_NATIVE__ # define __CL_USE_NATIVE__
@@ -125,7 +125,7 @@ CCL_NAMESPACE_BEGIN
# ifdef __KERNEL_EXPERIMENTAL__ # ifdef __KERNEL_EXPERIMENTAL__
# define __TRANSPARENT_SHADOWS__ # define __TRANSPARENT_SHADOWS__
# endif # endif
#endif # endif /* __KERNEL_OPENCL_AMD__ */
# ifdef __KERNEL_OPENCL_INTEL_CPU__ # ifdef __KERNEL_OPENCL_INTEL_CPU__
# define __CL_USE_NATIVE__ # define __CL_USE_NATIVE__
@@ -134,9 +134,9 @@ CCL_NAMESPACE_BEGIN
# ifdef __KERNEL_EXPERIMENTAL__ # ifdef __KERNEL_EXPERIMENTAL__
# define __CMJ__ # define __CMJ__
# endif # endif
#endif # endif /* __KERNEL_OPENCL_INTEL_CPU__ */
#endif // __KERNEL_OPENCL__ #endif /* __KERNEL_OPENCL__ */
/* kernel features */ /* kernel features */
#define __SOBOL__ #define __SOBOL__

View File

@@ -33,5 +33,4 @@
# include "kernel.h" # include "kernel.h"
# define KERNEL_ARCH cpu_avx # define KERNEL_ARCH cpu_avx
# include "kernel_cpu_impl.h" # include "kernel_cpu_impl.h"
#endif /* WITH_CYCLES_OPTIMIZED_KERNEL_AVX */ #endif /* WITH_CYCLES_OPTIMIZED_KERNEL_AVX */

View File

@@ -34,5 +34,4 @@
# include "kernel.h" # include "kernel.h"
# define KERNEL_ARCH cpu_avx2 # define KERNEL_ARCH cpu_avx2
# include "kernel_cpu_impl.h" # include "kernel_cpu_impl.h"
#endif /* WITH_CYCLES_OPTIMIZED_KERNEL_AVX2 */ #endif /* WITH_CYCLES_OPTIMIZED_KERNEL_AVX2 */

View File

@@ -29,5 +29,4 @@
# include "kernel.h" # include "kernel.h"
# define KERNEL_ARCH cpu_sse2 # define KERNEL_ARCH cpu_sse2
# include "kernel_cpu_impl.h" # include "kernel_cpu_impl.h"
#endif /* WITH_CYCLES_OPTIMIZED_KERNEL_SSE2 */ #endif /* WITH_CYCLES_OPTIMIZED_KERNEL_SSE2 */

View File

@@ -31,5 +31,4 @@
# include "kernel.h" # include "kernel.h"
# define KERNEL_ARCH cpu_sse3 # define KERNEL_ARCH cpu_sse3
# include "kernel_cpu_impl.h" # include "kernel_cpu_impl.h"
#endif /* WITH_CYCLES_OPTIMIZED_KERNEL_SSE3 */ #endif /* WITH_CYCLES_OPTIMIZED_KERNEL_SSE3 */

View File

@@ -32,5 +32,4 @@
# include "kernel.h" # include "kernel.h"
# define KERNEL_ARCH cpu_sse41 # define KERNEL_ARCH cpu_sse41
# include "kernel_cpu_impl.h" # include "kernel_cpu_impl.h"
#endif /* WITH_CYCLES_OPTIMIZED_KERNEL_SSE41 */ #endif /* WITH_CYCLES_OPTIMIZED_KERNEL_SSE41 */

View File

@@ -720,31 +720,46 @@ bool path_remove(const string& path)
return remove(path.c_str()) == 0; 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 * contents, to work around issue of opencl drivers not supporting
* include paths with spaces in them */ * include paths with spaces in them.
string source = source_; */
const string include = "#include \"";
size_t n, pos = 0;
while((n = source.find(include, pos)) != string::npos) { string result = "";
size_t n_start = n + include.size(); vector<string> lines;
size_t n_end = source.find("\"", n_start); string_split(lines, source, "\n");
string filename = source.substr(n_start, n_end - n_start);
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); string text, filepath = path_join(path, filename);
if(path_read_text(filepath, text)) { if(path_read_text(filepath, text)) {
text = path_source_replace_includes(text, path_dirname(filepath)); /* Replace include directories with both current path
source.replace(n, n_end + 1 - n, "\n" + text + "\n"); * 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) FILE *path_fopen(const string& path, const string& mode)