diff options
-rw-r--r-- | intern/cycles/device/device_cuda.cpp | 2 | ||||
-rw-r--r-- | intern/cycles/device/device_opencl.cpp | 12 | ||||
-rw-r--r-- | intern/cycles/util/util_path.cpp | 37 | ||||
-rw-r--r-- | intern/cycles/util/util_path.h | 1 |
4 files changed, 45 insertions, 7 deletions
diff --git a/intern/cycles/device/device_cuda.cpp b/intern/cycles/device/device_cuda.cpp index 76e52498b42..147e21d798a 100644 --- a/intern/cycles/device/device_cuda.cpp +++ b/intern/cycles/device/device_cuda.cpp @@ -343,7 +343,7 @@ public: const string cubin_file = string_printf("cycles_kernel_sm%d%d_%s.cubin", major, minor, cubin_md5.c_str()); - const string cubin = path_user_get(path_join("cache", cubin_file)); + const string cubin = path_cache_get(path_join("kernels", cubin_file)); VLOG(1) << "Testing for locally compiled kernel " << cubin << "."; if(path_exists(cubin)) { VLOG(1) << "Using locally compiled kernel."; diff --git a/intern/cycles/device/device_opencl.cpp b/intern/cycles/device/device_opencl.cpp index 5c05aeb5569..c43a3878009 100644 --- a/intern/cycles/device/device_opencl.cpp +++ b/intern/cycles/device/device_opencl.cpp @@ -987,7 +987,7 @@ public: string clbin = string_printf("cycles_kernel_%s_%s.clbin", device_md5.c_str(), kernel_md5.c_str()); - clbin = path_user_get(path_join("cache", clbin)); + clbin = path_cache_get(path_join("kernels", clbin)); /* path to preprocessed source for debugging */ string clsrc, *debug_src = NULL; @@ -996,7 +996,7 @@ public: clsrc = string_printf("cycles_kernel_%s_%s.cl", device_md5.c_str(), kernel_md5.c_str()); - clsrc = path_user_get(path_join("cache", clsrc)); + clsrc = path_cache_get(path_join("kernels", clsrc)); debug_src = &clsrc; } @@ -1680,7 +1680,7 @@ public: string clbin = string_printf("cycles_kernel_%s_%s.clbin", device_md5.c_str(), kernel_md5.c_str()); - clbin = path_user_get(path_join("cache", clbin)); + clbin = path_cache_get(path_join("kernels", clbin)); /* Path to preprocessed source for debugging. */ string clsrc, *debug_src = NULL; @@ -1688,7 +1688,7 @@ public: clsrc = string_printf("cycles_kernel_%s_%s.cl", device_md5.c_str(), kernel_md5.c_str()); - clsrc = path_user_get(path_join("cache", clsrc)); + clsrc = path_cache_get(path_join("kernels", clsrc)); debug_src = &clsrc; } @@ -2102,7 +2102,7 @@ public: return false; } - string cache_clbin = path_user_get(path_join("cache", clbin)); + string cache_clbin = path_cache_get(path_join("kernels", clbin)); /* If exists already, try use it. */ if(path_exists(cache_clbin) && load_binary(kernel_path, @@ -2220,7 +2220,7 @@ public: if(opencl_kernel_use_debug()) { \ clsrc = string_printf("cycles_kernel_%s_%s_" #name ".cl", \ device_md5.c_str(), kernel_md5.c_str()); \ - clsrc = path_user_get(path_join("cache", clsrc)); \ + clsrc = path_cache_get(path_join("kernels", clsrc)); \ debug_src = &clsrc; \ } \ if(!load_split_kernel(#name, \ diff --git a/intern/cycles/util/util_path.cpp b/intern/cycles/util/util_path.cpp index f23f2cb0168..d515b62d49f 100644 --- a/intern/cycles/util/util_path.cpp +++ b/intern/cycles/util/util_path.cpp @@ -36,6 +36,7 @@ OIIO_NAMESPACE_USING #else # define DIR_SEP '/' # include <dirent.h> +# include <pwd.h> #endif #ifdef HAVE_SHLWAPI_H @@ -63,6 +64,7 @@ typedef struct stat path_stat_t; static string cached_path = ""; static string cached_user_path = ""; +static string cached_xdg_cache_path = ""; namespace { @@ -331,6 +333,23 @@ static char *path_specials(const string& sub) return NULL; } +#if defined(__linux__) || defined(__APPLE__) +static string path_xdg_cache_get() +{ + const char *home = getenv("XDG_CACHE_HOME"); + if(home) { + return string(home); + } + else { + home = getenv("HOME"); + if(home == NULL) { + home = getpwuid(getuid())->pw_dir; + } + return path_join(string(home), ".cache"); + } +} +#endif + void path_init(const string& path, const string& user_path) { cached_path = path; @@ -364,6 +383,24 @@ string path_user_get(const string& sub) return path_join(cached_user_path, sub); } +string path_cache_get(const string& sub) +{ +#if defined(__linux__) || defined(__APPLE__) + if(cached_xdg_cache_path == "") { + cached_xdg_cache_path = path_xdg_cache_get(); + } + string result = path_join(cached_xdg_cache_path, "cycles"); + return path_join(result, sub); +#else + /* TODO(sergey): What that should be on Windows? */ + return path_user_get(path_join("cache", sub)); +#endif +} + +#if defined(__linux__) || defined(__APPLE__) +string path_xdg_home_get(const string& sub = ""); +#endif + string path_filename(const string& path) { size_t index = find_last_slash(path); diff --git a/intern/cycles/util/util_path.h b/intern/cycles/util/util_path.h index c80247f3837..4a89d87cbc6 100644 --- a/intern/cycles/util/util_path.h +++ b/intern/cycles/util/util_path.h @@ -35,6 +35,7 @@ CCL_NAMESPACE_BEGIN void path_init(const string& path = "", const string& user_path = ""); string path_get(const string& sub = ""); string path_user_get(const string& sub = ""); +string path_cache_get(const string& sub = ""); /* path string manipulation */ string path_filename(const string& path); |