[Bf-blender-cvs] [9af4e1d1e68] cycles_embree: Cycles: added memory and progress callbacks to embree
Stefan Werner
noreply at git.blender.org
Sun Nov 26 23:11:11 CET 2017
Commit: 9af4e1d1e68985b97ec8eda33de34766ed4f52c1
Author: Stefan Werner
Date: Thu Jun 8 11:21:42 2017 +0200
Branches: cycles_embree
https://developer.blender.org/rB9af4e1d1e68985b97ec8eda33de34766ed4f52c1
Cycles: added memory and progress callbacks to embree
===================================================================
M intern/cycles/blender/addon/ui.py
M intern/cycles/bvh/bvh.cpp
M intern/cycles/bvh/bvh.h
M intern/cycles/bvh/bvh_embree.cpp
M intern/cycles/bvh/bvh_embree.h
M intern/cycles/kernel/bvh/bvh.h
M intern/cycles/kernel/bvh/bvh_embree_traversal.h
M intern/cycles/render/mesh.cpp
===================================================================
diff --git a/intern/cycles/blender/addon/ui.py b/intern/cycles/blender/addon/ui.py
index 28d323e018e..fc098b52eac 100644
--- a/intern/cycles/blender/addon/ui.py
+++ b/intern/cycles/blender/addon/ui.py
@@ -422,9 +422,7 @@ class CYCLES_RENDER_PT_performance(CyclesButtonsPanel, Panel):
col.label(text="Acceleration structure:")
col.prop(cscene, "use_bvh_embree")
- row = col.row()
- row.active = not cscene.use_bvh_embree
- row.prop(cscene, "debug_use_spatial_splits")
+ col.prop(cscene, "debug_use_spatial_splits")
row = col.row()
row.active = not cscene.use_bvh_embree
row.prop(cscene, "debug_use_hair_bvh")
diff --git a/intern/cycles/bvh/bvh.cpp b/intern/cycles/bvh/bvh.cpp
index 37d96ce99c9..81fa47a4830 100644
--- a/intern/cycles/bvh/bvh.cpp
+++ b/intern/cycles/bvh/bvh.cpp
@@ -67,7 +67,7 @@ BVH *BVH::create(const BVHParams& params, const vector<Object*>& objects)
/* Building */
-void BVH::build(Progress& progress)
+void BVH::build(Progress& progress, Stats*)
{
progress.set_substatus("Building BVH");
diff --git a/intern/cycles/bvh/bvh.h b/intern/cycles/bvh/bvh.h
index ea8f0970c77..d445bf2a68d 100644
--- a/intern/cycles/bvh/bvh.h
+++ b/intern/cycles/bvh/bvh.h
@@ -25,6 +25,7 @@
CCL_NAMESPACE_BEGIN
+class Stats;
class BVHNode;
struct BVHStackEntry;
class BVHParams;
@@ -85,7 +86,7 @@ public:
static BVH *create(const BVHParams& params, const vector<Object*>& objects);
virtual ~BVH() {}
- virtual void build(Progress& progress);
+ virtual void build(Progress& progress, Stats *stats=NULL);
void refit(Progress& progress);
protected:
diff --git a/intern/cycles/bvh/bvh_embree.cpp b/intern/cycles/bvh/bvh_embree.cpp
index 030a4787a42..09aaf6d7c2b 100644
--- a/intern/cycles/bvh/bvh_embree.cpp
+++ b/intern/cycles/bvh/bvh_embree.cpp
@@ -45,7 +45,7 @@ CCL_NAMESPACE_BEGIN
* Cycles' own BVH does that directly inside the traversal calls.
*/
-void cclFilterFunc(void* userDataPtr, RTCRay& ray_)
+void rtc_filter_func(void* userDataPtr, RTCRay& ray_)
{
CCLRay &ray = (CCLRay&)ray_;
KernelGlobals *kg = ray.kg;
@@ -137,13 +137,39 @@ void cclFilterFunc(void* userDataPtr, RTCRay& ray_)
return;
}
+bool rtc_memory_monitor_func(void* userPtr, const ssize_t bytes, const bool post)
+{
+ BVHEmbree *bvh = (BVHEmbree*)userPtr;
+ if(bvh) {
+ bvh->mem_monitor(bytes);
+ }
+ return true;
+}
+
+static double progress_start_time = 0.0f;
+
+bool rtc_progress_func(void* user_ptr, const double n)
+{
+ Progress *progress = (Progress*)user_ptr;
+
+ if(time_dt() - progress_start_time < 0.25)
+ return true;
+
+ string msg = string_printf("Building BVH %.0f%%", n * 100.0);
+
+ progress->set_substatus(msg);
+ progress_start_time = time_dt();
+
+ return !progress->get_cancel();
+}
+
/* This is to have a shared device between all BVH instances */
RTCDevice BVHEmbree::rtc_shared_device = NULL;
int BVHEmbree::rtc_shared_users = 0;
thread_mutex BVHEmbree::rtc_shared_mutex;
BVHEmbree::BVHEmbree(const BVHParams& params_, const vector<Object*>& objects_)
-: BVH(params_, objects_), scene(NULL)
+: BVH(params_, objects_), scene(NULL), mem_used(0), stats(NULL)
{
_MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON);
_MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON);
@@ -153,6 +179,8 @@ BVHEmbree::BVHEmbree(const BVHParams& params_, const vector<Object*>& objects_)
}
rtc_shared_users++;
+ rtcDeviceSetMemoryMonitorFunction2(rtc_shared_device, rtc_memory_monitor_func, this);
+
/* BVH_CUSTOM as root index signals to the rest of the code that this is not Cycle's own BVH */
pack.root_index = BVH_CUSTOM;
}
@@ -186,8 +214,22 @@ void BVHEmbree::delete_rtcScene()
}
}
-void BVHEmbree::build(Progress& progress)
+void BVHEmbree::mem_monitor(ssize_t bytes)
+{
+ if(stats) {
+ if(bytes > 0) {
+ stats->mem_alloc(bytes);
+ } else {
+ stats->mem_free(-bytes);
+ }
+ }
+ mem_used += bytes;
+}
+
+void BVHEmbree::build(Progress& progress, Stats *stats_)
{
+ stats = stats_;
+
progress.set_substatus("Building BVH");
if (scene) {
@@ -195,7 +237,11 @@ void BVHEmbree::build(Progress& progress)
scene = NULL;
}
- scene = rtcDeviceNewScene(rtc_shared_device, RTC_SCENE_STATIC|RTC_SCENE_INCOHERENT|RTC_SCENE_HIGH_QUALITY|RTC_SCENE_ROBUST, RTC_INTERSECT1);
+ RTCSceneFlags flags = RTC_SCENE_STATIC|RTC_SCENE_INCOHERENT|RTC_SCENE_ROBUST;
+ if(params.use_spatial_split) {
+ flags = flags|RTC_SCENE_HIGH_QUALITY;
+ }
+ scene = rtcDeviceNewScene(rtc_shared_device, flags, RTC_INTERSECT1);
int i = 0;
@@ -225,21 +271,25 @@ void BVHEmbree::build(Progress& progress)
if(progress.get_cancel()) {
delete_rtcScene();
+ stats = NULL;
return;
}
- progress.set_substatus("Building embree acceleration structure");
+ rtcSetProgressMonitorFunction(scene, rtc_progress_func, &progress);
rtcCommit(scene);
pack_primitives();
if(progress.get_cancel()) {
delete_rtcScene();
+ stats = NULL;
return;
}
progress.set_substatus("Packing geometry");
pack_nodes(NULL);
+
+ stats = NULL;
}
unsigned BVHEmbree::add_object(Object *ob, int i)
@@ -250,16 +300,16 @@ unsigned BVHEmbree::add_object(Object *ob, int i)
size_t prim_offset = pack.prim_index.size();
geom_id = add_triangles(mesh, i);
rtcSetUserData(scene, geom_id, (void*)prim_offset);
- rtcSetIntersectionFilterFunction(scene, geom_id, cclFilterFunc);
- rtcSetOcclusionFilterFunction(scene, geom_id, cclFilterFunc);
+ rtcSetIntersectionFilterFunction(scene, geom_id, rtc_filter_func);
+ rtcSetOcclusionFilterFunction(scene, geom_id, rtc_filter_func);
rtcSetMask(scene, geom_id, ob->visibility);
}
if(params.primitive_mask & PRIMITIVE_ALL_CURVE && mesh->num_curves() > 0) {
size_t prim_offset = pack.prim_index.size();
geom_id = add_curves(mesh, i);
rtcSetUserData(scene, geom_id, (void*)prim_offset);
- rtcSetIntersectionFilterFunction(scene, geom_id, cclFilterFunc);
- rtcSetOcclusionFilterFunction(scene, geom_id, cclFilterFunc);
+ rtcSetIntersectionFilterFunction(scene, geom_id, rtc_filter_func);
+ rtcSetOcclusionFilterFunction(scene, geom_id, rtc_filter_func);
rtcSetMask(scene, geom_id, ob->visibility);
}
return geom_id;
@@ -541,7 +591,9 @@ void BVHEmbree::pack_nodes(const BVHNode *root)
continue;
}
- BVH *bvh = mesh->bvh;
+ BVHEmbree *bvh = (BVHEmbree*)mesh->bvh;
+
+ mem_monitor(bvh->mem_used);
int mesh_tri_offset = mesh->tri_offset;
int mesh_curve_offset = mesh->curve_offset;
diff --git a/intern/cycles/bvh/bvh_embree.h b/intern/cycles/bvh/bvh_embree.h
index b52d1fd481f..d4443f33ecc 100644
--- a/intern/cycles/bvh/bvh_embree.h
+++ b/intern/cycles/bvh/bvh_embree.h
@@ -36,10 +36,11 @@ class Mesh;
class BVHEmbree : public BVH
{
public:
- void build(Progress& progress);
+ void build(Progress& progress, Stats *stats);
virtual ~BVHEmbree();
RTCScene scene;
static void destroy(RTCScene);
+ void mem_monitor(ssize_t mem);
protected:
/* constructor */
friend class BVH;
@@ -52,12 +53,16 @@ protected:
unsigned add_instance(Object *ob, int i);
unsigned add_curves(Mesh *mesh, int i);
unsigned add_triangles(Mesh *mesh, int i);
+
+ ssize_t mem_used;
private:
void delete_rtcScene();
static RTCDevice rtc_shared_device;
static int rtc_shared_users;
static thread_mutex rtc_shared_mutex;
+
+ Stats *stats;
};
CCL_NAMESPACE_END
diff --git a/intern/cycles/kernel/bvh/bvh.h b/intern/cycles/kernel/bvh/bvh.h
index 43be3756e08..c8db09c3357 100644
--- a/intern/cycles/kernel/bvh/bvh.h
+++ b/intern/cycles/kernel/bvh/bvh.h
@@ -230,9 +230,9 @@ ccl_device_intersect void scene_intersect_local(KernelGlobals *kg,
CCLRay rtc_ray(ray, kg, PATH_RAY_ALL_VISIBILITY, CCLRay::RAY_SSS);
rtc_ray.lcg_state = lcg_state;
rtc_ray.max_hits = max_hits;
- rtc_ray.ss_isect = ss_isect;
- ss_isect->num_hits = 0;
- rtc_ray.sss_object_id = subsurface_object;
+ rtc_ray.ss_isect = local_isect;
+ local_isect->num_hits = 0;
+ rtc_ray.sss_object_id = local_object;
rtcOccluded(kernel_data.bvh.scene, rtc_ray);
return;
}
diff --git a/intern/cycles/kernel/bvh/bvh_embree_traversal.h b/intern/cycles/kernel/bvh/bvh_embree_traversal.h
index 373fde9787d..17942e08154 100644
--- a/intern/cycles/kernel/bvh/bvh_embree_traversal.h
+++ b/intern/cycles/kernel/bvh/bvh_embree_traversal.h
@@ -36,7 +36,7 @@ struct RTCORE_ALIGN(16) CCLRay : public RTCRay {
int num_hits;
// for SSS Rays:
- ccl::SubsurfaceIntersection *ss_isect;
+ ccl::LocalIntersection *ss_isect;
int sss_object_id;
uint *lcg_state;
diff --git a/intern/cycles/render/mesh.cpp b/intern/cycles/render/mesh.cpp
index 09616673dd1..cae8d25f10e 100644
--- a/intern/cycles/render/mesh.cpp
+++ b/intern/cycles/render/mesh.cpp
@@ -1845,7 +1845,7 @@ void MeshManager::device_update_bvh(Device *device, DeviceScene *dscene, Scene *
#endif
BVH *bvh = BVH::create(bparams, scene->objects);
- bvh->build(progress);
+ bvh->build(progress, &device->stats);
if(progress.get_cancel()) {
#ifdef WITH_EMBREE
More information about the Bf-blender-cvs
mailing list