diff options
author | Kévin Dietrich <kevin.dietrich@mailoo.org> | 2021-06-21 10:40:40 +0300 |
---|---|---|
committer | Kévin Dietrich <kevin.dietrich@mailoo.org> | 2021-06-22 08:38:28 +0300 |
commit | cd39e3dec1fd0dd2ede4c0eaa10e4d285fd78b64 (patch) | |
tree | bdbdd5d9c2226b5c46e5ada76904be2334c6eb1e /intern/cycles | |
parent | 338be95874bddec300a863c9583652cda0ccf5de (diff) |
OptiX: select BVH build options from Scene params
Currently, the OptiX BVH build options are selected based on whether
we are in background mode (final renders) or not (viewport renders).
In background mode, the BVH is built for fast path tracing and low
memory footprint, while in viewport, it is built for fast updates.
However, on platforms without OpenGL support, the background flag is
always set to true and prevents using fast BVH builds in the viewport.
Now, the BVH options derive from the Scene BVH settings:
* if BVH is static, a fast to trace BVH is built
* if BVH is dynamic, a fast to update BVH is built
Reviewed By: #cycles, brecht
Differential Revision: https://developer.blender.org/D11154
Diffstat (limited to 'intern/cycles')
-rw-r--r-- | intern/cycles/device/device_optix.cpp | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/intern/cycles/device/device_optix.cpp b/intern/cycles/device/device_optix.cpp index b008dfa376f..392fec4d57b 100644 --- a/intern/cycles/device/device_optix.cpp +++ b/intern/cycles/device/device_optix.cpp @@ -1196,16 +1196,18 @@ class OptiXDevice : public CUDADevice { const CUDAContextScope scope(cuContext); + const bool use_fast_trace_bvh = (bvh->params.bvh_type == SceneParams::BVH_STATIC); + // Compute memory usage OptixAccelBufferSizes sizes = {}; OptixAccelBuildOptions options = {}; options.operation = operation; - if (background) { - // Prefer best performance and lowest memory consumption in background + if (use_fast_trace_bvh) { + VLOG(2) << "Using fast to trace OptiX BVH"; options.buildFlags = OPTIX_BUILD_FLAG_PREFER_FAST_TRACE | OPTIX_BUILD_FLAG_ALLOW_COMPACTION; } else { - // Prefer fast updates in viewport + VLOG(2) << "Using fast to update OptiX BVH"; options.buildFlags = OPTIX_BUILD_FLAG_PREFER_FAST_BUILD | OPTIX_BUILD_FLAG_ALLOW_UPDATE; } @@ -1253,15 +1255,16 @@ class OptiXDevice : public CUDADevice { out_data.device_pointer, sizes.outputSizeInBytes, &out_handle, - background ? &compacted_size_prop : NULL, - background ? 1 : 0)); + use_fast_trace_bvh ? &compacted_size_prop : NULL, + use_fast_trace_bvh ? 1 : 0)); bvh->traversable_handle = static_cast<uint64_t>(out_handle); // Wait for all operations to finish check_result_cuda_ret(cuStreamSynchronize(NULL)); - // Compact acceleration structure to save memory (do not do this in viewport for faster builds) - if (background) { + // Compact acceleration structure to save memory (only if using fast trace as the + // OPTIX_BUILD_FLAG_ALLOW_COMPACTION flag is only set in this case). + if (use_fast_trace_bvh) { uint64_t compacted_size = sizes.outputSizeInBytes; check_result_cuda_ret( cuMemcpyDtoH(&compacted_size, compacted_size_prop.result, sizeof(compacted_size))); @@ -1306,6 +1309,8 @@ class OptiXDevice : public CUDADevice { return; } + const bool use_fast_trace_bvh = (bvh->params.bvh_type == SceneParams::BVH_STATIC); + free_bvh_memory_delayed(); BVHOptiX *const bvh_optix = static_cast<BVHOptiX *>(bvh); @@ -1315,10 +1320,10 @@ class OptiXDevice : public CUDADevice { if (!bvh->params.top_level) { assert(bvh->objects.size() == 1 && bvh->geometry.size() == 1); - // Refit is only possible in viewport for now (because AS is built with - // OPTIX_BUILD_FLAG_ALLOW_UPDATE only there, see above) OptixBuildOperation operation = OPTIX_BUILD_OPERATION_BUILD; - if (refit && !background) { + /* Refit is only possible when using fast to trace BVH (because AS is built with + * OPTIX_BUILD_FLAG_ALLOW_UPDATE only there, see above). */ + if (refit && !use_fast_trace_bvh) { assert(bvh_optix->traversable_handle != 0); operation = OPTIX_BUILD_OPERATION_UPDATE; } |