Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGon Solo <gonsolo>2022-11-08 21:31:48 +0300
committerBrecht Van Lommel <brecht@blender.org>2022-11-08 21:40:57 +0300
commitc306ccb67fcf44d9bca3c4ed0f20d1af1df29f26 (patch)
tree26f6dbf70e7e919208c75f1a07770b51b5d939d8
parent5925b1821a5706d59d1504ab3b426ce5df6aff52 (diff)
Fix Cycles error with runtime compilation when there is no path to OptiX SDK
If no OPTIX_ROOT is set, nvcc fails to compile because there is a stray "-I" in the arguments. Detect if the include path is empty and act accordingly. Differential Revision: https://developer.blender.org/D16308
-rw-r--r--intern/cycles/device/cuda/device_impl.cpp6
-rw-r--r--intern/cycles/device/cuda/device_impl.h4
-rw-r--r--intern/cycles/device/hip/device_impl.h2
-rw-r--r--intern/cycles/device/optix/device_impl.cpp58
-rw-r--r--intern/cycles/device/optix/device_impl.h2
5 files changed, 43 insertions, 29 deletions
diff --git a/intern/cycles/device/cuda/device_impl.cpp b/intern/cycles/device/cuda/device_impl.cpp
index 01c021551f3..b56765208ee 100644
--- a/intern/cycles/device/cuda/device_impl.cpp
+++ b/intern/cycles/device/cuda/device_impl.cpp
@@ -232,7 +232,7 @@ string CUDADevice::compile_kernel_get_common_cflags(const uint kernel_features)
return cflags;
}
-string CUDADevice::compile_kernel(const uint kernel_features,
+string CUDADevice::compile_kernel(const string& common_cflags,
const char *name,
const char *base,
bool force_ptx)
@@ -281,7 +281,6 @@ string CUDADevice::compile_kernel(const uint kernel_features,
/* We include cflags into md5 so changing cuda toolkit or changing other
* compiler command line arguments makes sure cubin gets re-built.
*/
- string common_cflags = compile_kernel_get_common_cflags(kernel_features);
const string kernel_md5 = util_md5_string(source_md5 + common_cflags);
const char *const kernel_ext = force_ptx ? "ptx" : "cubin";
@@ -417,7 +416,8 @@ bool CUDADevice::load_kernels(const uint kernel_features)
/* get kernel */
const char *kernel_name = "kernel";
- string cubin = compile_kernel(kernel_features, kernel_name);
+ string cflags = compile_kernel_get_common_cflags(kernel_features);
+ string cubin = compile_kernel(cflags, kernel_name);
if (cubin.empty())
return false;
diff --git a/intern/cycles/device/cuda/device_impl.h b/intern/cycles/device/cuda/device_impl.h
index a754c33f79d..bd6d806561b 100644
--- a/intern/cycles/device/cuda/device_impl.h
+++ b/intern/cycles/device/cuda/device_impl.h
@@ -77,9 +77,9 @@ class CUDADevice : public Device {
bool use_adaptive_compilation();
- virtual string compile_kernel_get_common_cflags(const uint kernel_features);
+ string compile_kernel_get_common_cflags(const uint kernel_features);
- string compile_kernel(const uint kernel_features,
+ string compile_kernel(const string& cflags,
const char *name,
const char *base = "cuda",
bool force_ptx = false);
diff --git a/intern/cycles/device/hip/device_impl.h b/intern/cycles/device/hip/device_impl.h
index 9afef3789af..efdc15dca79 100644
--- a/intern/cycles/device/hip/device_impl.h
+++ b/intern/cycles/device/hip/device_impl.h
@@ -74,7 +74,7 @@ class HIPDevice : public Device {
bool use_adaptive_compilation();
- virtual string compile_kernel_get_common_cflags(const uint kernel_features);
+ string compile_kernel_get_common_cflags(const uint kernel_features);
string compile_kernel(const uint kernel_features, const char *name, const char *base = "hip");
diff --git a/intern/cycles/device/optix/device_impl.cpp b/intern/cycles/device/optix/device_impl.cpp
index 6c64e7106d5..fabf4d7b69d 100644
--- a/intern/cycles/device/optix/device_impl.cpp
+++ b/intern/cycles/device/optix/device_impl.cpp
@@ -381,13 +381,44 @@ bool OptiXDevice::load_kernels(const uint kernel_features)
return false;
}
+ /* Skip creating OptiX module if only doing denoising. */
+ const bool need_optix_kernels = (kernel_features &
+ (KERNEL_FEATURE_PATH_TRACING | KERNEL_FEATURE_BAKING));
+
+ /* Detect existence of OptiX kernel and SDK here early. So we can error out
+ * before compiling the CUDA kernels, to avoid failing right after when
+ * compiling the OptiX kernel. */
+ string ptx_filename;
+ if (need_optix_kernels) {
+ ptx_filename = path_get(
+ (kernel_features & (KERNEL_FEATURE_NODE_RAYTRACE | KERNEL_FEATURE_MNEE)) ?
+ "lib/kernel_optix_shader_raytrace.ptx" :
+ "lib/kernel_optix.ptx");
+ if (use_adaptive_compilation() || path_file_size(ptx_filename) == -1) {
+ std::string optix_include_dir = get_optix_include_dir();
+ if (optix_include_dir.empty()) {
+ set_error(
+ "Unable to compile OptiX kernels at runtime. Set OPTIX_ROOT_DIR environment variable "
+ "to a directory containing the OptiX SDK.");
+ return false;
+ }
+ else if (!path_is_directory(optix_include_dir)) {
+ set_error(string_printf(
+ "OptiX headers not found at %s, unable to compile OptiX kernels at runtime. Install "
+ "OptiX SDK in the specified location, or set OPTIX_ROOT_DIR environment variable to a "
+ "directory containing the OptiX SDK.",
+ optix_include_dir.c_str()));
+ return false;
+ }
+ }
+ }
+
/* Load CUDA modules because we need some of the utility kernels. */
if (!CUDADevice::load_kernels(kernel_features)) {
return false;
}
- /* Skip creating OptiX module if only doing denoising. */
- if (!(kernel_features & (KERNEL_FEATURE_PATH_TRACING | KERNEL_FEATURE_BAKING))) {
+ if (!need_optix_kernels) {
return true;
}
@@ -469,28 +500,11 @@ bool OptiXDevice::load_kernels(const uint kernel_features)
}
{ /* Load and compile PTX module with OptiX kernels. */
- string ptx_data, ptx_filename = path_get(
- (kernel_features & (KERNEL_FEATURE_NODE_RAYTRACE | KERNEL_FEATURE_MNEE)) ?
- "lib/kernel_optix_shader_raytrace.ptx" :
- "lib/kernel_optix.ptx");
+ string ptx_data;
if (use_adaptive_compilation() || path_file_size(ptx_filename) == -1) {
- std::string optix_include_dir = get_optix_include_dir();
- if (optix_include_dir.empty()) {
- set_error(
- "Unable to compile OptiX kernels at runtime. Set OPTIX_ROOT_DIR environment variable "
- "to a directory containing the OptiX SDK.");
- return false;
- }
- else if (!path_is_directory(optix_include_dir)) {
- set_error(string_printf(
- "OptiX headers not found at %s, unable to compile OptiX kernels at runtime. Install "
- "OptiX SDK in the specified location, or set OPTIX_ROOT_DIR environment variable to a "
- "directory containing the OptiX SDK.",
- optix_include_dir.c_str()));
- return false;
- }
+ string cflags = compile_kernel_get_common_cflags(kernel_features);
ptx_filename = compile_kernel(
- kernel_features,
+ cflags,
(kernel_features & (KERNEL_FEATURE_NODE_RAYTRACE | KERNEL_FEATURE_MNEE)) ?
"kernel_shader_raytrace" :
"kernel",
diff --git a/intern/cycles/device/optix/device_impl.h b/intern/cycles/device/optix/device_impl.h
index 817afdc8384..76c8af9bc3f 100644
--- a/intern/cycles/device/optix/device_impl.h
+++ b/intern/cycles/device/optix/device_impl.h
@@ -103,7 +103,7 @@ class OptiXDevice : public CUDADevice {
private:
BVHLayoutMask get_bvh_layout_mask() const override;
- string compile_kernel_get_common_cflags(const uint kernel_features) override;
+ string compile_kernel_get_common_cflags(const uint kernel_features);
bool load_kernels(const uint kernel_features) override;