From 5804a1cc2ce59c5e47949ada8d42d177aa3a3221 Mon Sep 17 00:00:00 2001 From: Patrick Mours Date: Thu, 31 Oct 2024 17:21:30 +0100 Subject: [PATCH] Fix #124200: OptiX error when updating 3D curves in viewport rendering Changing 3D curve properties while viewport rendering was active resulted in an error, because Cycles would attempt to update the acceleration structure containing the curves, but that acceleration structure was built without the `OPTIX_BUILD_FLAG_ALLOW_UPDATE` flag allowing updates. This fixes that by adding the flag to all curve build inputs. Ideally could just use the same flags as for other build inputs and differentiate between viewport and final rendering (based on `bvh_type`), but that's not currently an option since the same flags have to be specified to query the curve intersection module in `load_kernels()`, where that differentiation is not known. See also commit 5c6053ccb1cbbe57d5a9d0aa33eadc6cb3e9dc9a. Pull Request: https://projects.blender.org/blender/blender/pulls/129634 --- intern/cycles/device/optix/device_impl.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/intern/cycles/device/optix/device_impl.cpp b/intern/cycles/device/optix/device_impl.cpp index 3b86de4ffb0..f571c29744d 100644 --- a/intern/cycles/device/optix/device_impl.cpp +++ b/intern/cycles/device/optix/device_impl.cpp @@ -450,7 +450,8 @@ bool OptiXDevice::load_kernels(const uint kernel_features) # if OPTIX_ABI_VERSION >= 55 builtin_options.builtinISModuleType = OPTIX_PRIMITIVE_TYPE_ROUND_CATMULLROM; builtin_options.buildFlags = OPTIX_BUILD_FLAG_PREFER_FAST_TRACE | - OPTIX_BUILD_FLAG_ALLOW_COMPACTION; + OPTIX_BUILD_FLAG_ALLOW_COMPACTION | + OPTIX_BUILD_FLAG_ALLOW_UPDATE; builtin_options.curveEndcapFlags = OPTIX_CURVE_ENDCAP_DEFAULT; /* Disable end-caps. */ # else builtin_options.builtinISModuleType = OPTIX_PRIMITIVE_TYPE_ROUND_CUBIC_BSPLINE; @@ -1031,17 +1032,20 @@ bool OptiXDevice::build_optix_bvh(BVHOptiX *bvh, const CUDAContextScope scope(this); - const bool use_fast_trace_bvh = (bvh->params.bvh_type == BVH_TYPE_STATIC); + bool use_fast_trace_bvh = (bvh->params.bvh_type == BVH_TYPE_STATIC); /* Compute memory usage. */ OptixAccelBufferSizes sizes = {}; OptixAccelBuildOptions options = {}; options.operation = operation; - if (use_fast_trace_bvh || - /* The build flags have to match the ones used to query the built-in curve intersection - * program (see optixBuiltinISModuleGet above) */ - build_input.type == OPTIX_BUILD_INPUT_TYPE_CURVES) - { + if (build_input.type == OPTIX_BUILD_INPUT_TYPE_CURVES) { + /* The build flags have to match the ones used to query the built-in curve intersection + * program (see optixBuiltinISModuleGet above) */ + options.buildFlags = OPTIX_BUILD_FLAG_PREFER_FAST_TRACE | OPTIX_BUILD_FLAG_ALLOW_COMPACTION | + OPTIX_BUILD_FLAG_ALLOW_UPDATE; + use_fast_trace_bvh = true; + } + else if (use_fast_trace_bvh) { VLOG_INFO << "Using fast to trace OptiX BVH"; options.buildFlags = OPTIX_BUILD_FLAG_PREFER_FAST_TRACE | OPTIX_BUILD_FLAG_ALLOW_COMPACTION; }