[Bf-blender-cvs] [0f8df1b350f] cycles_path_guiding: Guiding: create device on demand, store in unique_ptr, simplify device API
Brecht Van Lommel
noreply at git.blender.org
Thu Aug 11 17:12:50 CEST 2022
Commit: 0f8df1b350fa7dae540b38c776a5d988850aed24
Author: Brecht Van Lommel
Date: Thu Aug 11 16:24:32 2022 +0200
Branches: cycles_path_guiding
https://developer.blender.org/rB0f8df1b350fa7dae540b38c776a5d988850aed24
Guiding: create device on demand, store in unique_ptr, simplify device API
===================================================================
M intern/cycles/device/cpu/device_impl.cpp
M intern/cycles/device/cpu/device_impl.h
M intern/cycles/device/device.h
M intern/cycles/integrator/path_trace.cpp
===================================================================
diff --git a/intern/cycles/device/cpu/device_impl.cpp b/intern/cycles/device/cpu/device_impl.cpp
index b8beaf01a27..d89aea2c0e7 100644
--- a/intern/cycles/device/cpu/device_impl.cpp
+++ b/intern/cycles/device/cpu/device_impl.cpp
@@ -73,11 +73,6 @@ CPUDevice::CPUDevice(const DeviceInfo &info_, Stats &stats_, Profiler &profiler_
embree_device = rtcNewDevice("verbose=0");
#endif
need_texture_info = false;
-
-#ifdef WITH_PATH_GUIDING
- // TODO(sherholz): we need to replace this with PGL_DEVICE_TYPE_CPU_AUTO
- openpgl_device = new openpgl::cpp::Device(PGL_DEVICE_TYPE_CPU_4);
-#endif
}
CPUDevice::~CPUDevice()
@@ -86,10 +81,6 @@ CPUDevice::~CPUDevice()
rtcReleaseDevice(embree_device);
#endif
-#ifdef WITH_PATH_GUIDING
- delete openpgl_device;
-#endif
-
texture_info.free();
}
@@ -292,15 +283,16 @@ void CPUDevice::build_bvh(BVH *bvh, Progress &progress, bool refit)
Device::build_bvh(bvh, progress, refit);
}
-void *CPUDevice::create_guiding_field(void *guiding_field_args_) const
+void *CPUDevice::get_guiding_device() const
{
#ifdef WITH_PATH_GUIDING
- PGLFieldArguments guiding_field_args = *(static_cast<PGLFieldArguments *>(guiding_field_args_));
- openpgl::cpp::Field *guiding_field_ptr = new openpgl::cpp::Field(openpgl_device,
- guiding_field_args);
- return static_cast<void *>(guiding_field_ptr);
+ if (!guiding_device) {
+ // TODO(sherholz): we need to replace this with PGL_DEVICE_TYPE_CPU_AUTO
+ guiding_device = make_unique<openpgl::cpp::Device>(PGL_DEVICE_TYPE_CPU_4);
+ }
+ return guiding_device.get();
#else
- return NULL;
+ return nullptr;
#endif
}
diff --git a/intern/cycles/device/cpu/device_impl.h b/intern/cycles/device/cpu/device_impl.h
index 3f75bef84c6..6c0a58e8179 100644
--- a/intern/cycles/device/cpu/device_impl.h
+++ b/intern/cycles/device/cpu/device_impl.h
@@ -27,6 +27,8 @@
#include "kernel/osl/globals.h"
// clang-format on
+#include "util/unique_ptr.h"
+
CCL_NAMESPACE_BEGIN
class CPUDevice : public Device {
@@ -44,7 +46,7 @@ class CPUDevice : public Device {
RTCDevice embree_device;
#endif
#ifdef WITH_PATH_GUIDING
- openpgl::cpp::Device *openpgl_device = NULL;
+ mutable unique_ptr<openpgl::cpp::Device> guiding_device;
#endif
CPUDevice(const DeviceInfo &info_, Stats &stats_, Profiler &profiler_);
@@ -76,7 +78,7 @@ class CPUDevice : public Device {
void build_bvh(BVH *bvh, Progress &progress, bool refit) override;
- void *create_guiding_field(void *guiding_field_args) const override;
+ void *get_guiding_device() const override;
virtual void get_cpu_kernel_thread_globals(
vector<CPUKernelThreadGlobals> &kernel_thread_globals) override;
diff --git a/intern/cycles/device/device.h b/intern/cycles/device/device.h
index 7953040a83f..2e4d18241cf 100644
--- a/intern/cycles/device/device.h
+++ b/intern/cycles/device/device.h
@@ -221,8 +221,8 @@ class Device {
/* Guiding */
- /* Creating and returning a new, empty guiding field. */
- virtual void *create_guiding_field(void *) const
+ /* Returns path guiding device handle. */
+ virtual void *get_guiding_device() const
{
LOG(ERROR) << "Request guiding field from a device which does not support it.";
return nullptr;
diff --git a/intern/cycles/integrator/path_trace.cpp b/intern/cycles/integrator/path_trace.cpp
index 7700766cadd..effa90515f6 100644
--- a/intern/cycles/integrator/path_trace.cpp
+++ b/intern/cycles/integrator/path_trace.cpp
@@ -1239,13 +1239,13 @@ void PathTrace::set_guiding_params(const GuidingParams &guiding_params, const bo
guiding_params_ = guiding_params;
if (guiding_params_.use) {
- PGLFieldArguments guidingFieldArgs;
+ PGLFieldArguments field_args;
switch (guiding_params_.type) {
default:
/* Parallax-aware von Mises-Fisher mixture models. */
case GUIDING_TYPE_PARALLAX_AWARE_VMM: {
pglFieldArgumentsSetDefaults(
- guidingFieldArgs,
+ field_args,
PGL_SPATIAL_STRUCTURE_TYPE::PGL_SPATIAL_STRUCTURE_KDTREE,
PGL_DIRECTIONAL_DISTRIBUTION_TYPE::PGL_DIRECTIONAL_DISTRIBUTION_PARALLAX_AWARE_VMM);
break;
@@ -1253,7 +1253,7 @@ void PathTrace::set_guiding_params(const GuidingParams &guiding_params, const bo
/* Directional quad-trees. */
case GUIDING_TYPE_DIRECTIONAL_QUAD_TREE: {
pglFieldArgumentsSetDefaults(
- guidingFieldArgs,
+ field_args,
PGL_SPATIAL_STRUCTURE_TYPE::PGL_SPATIAL_STRUCTURE_KDTREE,
PGL_DIRECTIONAL_DISTRIBUTION_TYPE::PGL_DIRECTIONAL_DISTRIBUTION_QUADTREE);
break;
@@ -1261,16 +1261,17 @@ void PathTrace::set_guiding_params(const GuidingParams &guiding_params, const bo
/* von Mises-Fisher mixture models. */
case GUIDING_TYPE_VMM: {
pglFieldArgumentsSetDefaults(
- guidingFieldArgs,
+ field_args,
PGL_SPATIAL_STRUCTURE_TYPE::PGL_SPATIAL_STRUCTURE_KDTREE,
PGL_DIRECTIONAL_DISTRIBUTION_TYPE::PGL_DIRECTIONAL_DISTRIBUTION_VMM);
break;
}
}
+ openpgl::cpp::Device *guiding_device = static_cast<openpgl::cpp::Device *>(
+ device_->get_guiding_device());
guiding_sample_data_storage_ = make_unique<openpgl::cpp::SampleStorage>();
- guiding_field_.reset(
- static_cast<openpgl::cpp::Field *>(device_->create_guiding_field(&guidingFieldArgs)));
+ guiding_field_ = make_unique<openpgl::cpp::Field>(guiding_device, field_args);
}
else {
guiding_sample_data_storage_ = nullptr;
More information about the Bf-blender-cvs
mailing list