forked from bartvdbraak/blender
Cycles: optimize camera inside volume tests
Only run when there are volumes in the scene, and compute in parallel. Ref T56939 Differential Revision: https://developer.blender.org/D8261
This commit is contained in:
parent
d8e648c352
commit
ad45b8d6a4
@ -26,6 +26,7 @@
|
|||||||
#include "util/util_function.h"
|
#include "util/util_function.h"
|
||||||
#include "util/util_logging.h"
|
#include "util/util_logging.h"
|
||||||
#include "util/util_math_cdf.h"
|
#include "util/util_math_cdf.h"
|
||||||
|
#include "util/util_task.h"
|
||||||
#include "util/util_vector.h"
|
#include "util/util_vector.h"
|
||||||
|
|
||||||
/* needed for calculating differentials */
|
/* needed for calculating differentials */
|
||||||
@ -496,20 +497,35 @@ void Camera::device_update_volume(Device * /*device*/, DeviceScene *dscene, Scen
|
|||||||
if (!need_device_update && !need_flags_update) {
|
if (!need_device_update && !need_flags_update) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
KernelCamera *kcam = &dscene->data.cam;
|
|
||||||
BoundBox viewplane_boundbox = viewplane_bounds_get();
|
KernelIntegrator *kintegrator = &dscene->data.integrator;
|
||||||
for (size_t i = 0; i < scene->objects.size(); ++i) {
|
if (kintegrator->use_volumes) {
|
||||||
Object *object = scene->objects[i];
|
KernelCamera *kcam = &dscene->data.cam;
|
||||||
if (object->geometry->has_volume && viewplane_boundbox.intersects(object->bounds)) {
|
BoundBox viewplane_boundbox = viewplane_bounds_get();
|
||||||
/* TODO(sergey): Consider adding more grained check. */
|
|
||||||
VLOG(1) << "Detected camera inside volume.";
|
/* Parallel object update, with grain size to avoid too much threading overhead
|
||||||
kcam->is_inside_volume = 1;
|
* for individual objects. */
|
||||||
break;
|
static const int OBJECTS_PER_TASK = 32;
|
||||||
|
parallel_for(blocked_range<size_t>(0, scene->objects.size(), OBJECTS_PER_TASK),
|
||||||
|
[&](const blocked_range<size_t> &r) {
|
||||||
|
for (size_t i = r.begin(); i != r.end(); i++) {
|
||||||
|
Object *object = scene->objects[i];
|
||||||
|
if (object->geometry->has_volume &&
|
||||||
|
viewplane_boundbox.intersects(object->bounds)) {
|
||||||
|
/* TODO(sergey): Consider adding more grained check. */
|
||||||
|
VLOG(1) << "Detected camera inside volume.";
|
||||||
|
kcam->is_inside_volume = 1;
|
||||||
|
parallel_for_cancel();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!kcam->is_inside_volume) {
|
||||||
|
VLOG(1) << "Camera is outside of the volume.";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!kcam->is_inside_volume) {
|
|
||||||
VLOG(1) << "Camera is outside of the volume.";
|
|
||||||
}
|
|
||||||
need_device_update = false;
|
need_device_update = false;
|
||||||
need_flags_update = false;
|
need_flags_update = false;
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,11 @@ using tbb::blocked_range;
|
|||||||
using tbb::enumerable_thread_specific;
|
using tbb::enumerable_thread_specific;
|
||||||
using tbb::parallel_for;
|
using tbb::parallel_for;
|
||||||
|
|
||||||
|
static inline void parallel_for_cancel()
|
||||||
|
{
|
||||||
|
tbb::task::self().cancel_group_execution();
|
||||||
|
}
|
||||||
|
|
||||||
CCL_NAMESPACE_END
|
CCL_NAMESPACE_END
|
||||||
|
|
||||||
#endif /* __UTIL_TBB_H__ */
|
#endif /* __UTIL_TBB_H__ */
|
||||||
|
Loading…
Reference in New Issue
Block a user