Skip to content

Commit 147e908

Browse files
Improved MI_DECLARE_TRAVERSE_CB macro
1 parent 37449cd commit 147e908

15 files changed

+44
-24
lines changed

include/mitsuba/core/fwd.h

+18-4
Original file line numberDiff line numberDiff line change
@@ -368,15 +368,22 @@ extern "C" {
368368
})
369369
#endif
370370

371-
#define MI_DECLARE_TRAVERSE_CB() \
371+
#define MI_DECLARE_TRAVERSE_CB(...) \
372+
DRJIT_INLINE auto traverse_1_cb_fields_() { \
373+
return drjit::tie(__VA_ARGS__); \
374+
} \
375+
DRJIT_INLINE auto traverse_1_cb_fields_() const { \
376+
return drjit::tie(__VA_ARGS__); \
377+
} \
378+
\
372379
public: \
373380
void traverse_1_cb_ro(void *payload, \
374381
drjit::detail::traverse_callback_ro fn) \
375382
const override; \
376383
void traverse_1_cb_rw( \
377384
void *payload, drjit::detail::traverse_callback_rw fn) override;
378385

379-
#define MI_IMPLEMENT_TRAVERSE_CB(Type, Base, ...) \
386+
#define MI_IMPLEMENT_TRAVERSE_CB(Type, Base) \
380387
MI_VARIANT \
381388
void Type<Float, Spectrum>::traverse_1_cb_ro( \
382389
void *payload, drjit::detail::traverse_callback_ro fn) const { \
@@ -391,7 +398,11 @@ extern "C" {
391398
\
392399
if constexpr (!std ::is_same_v<Base, drjit ::TraversableBase>) \
393400
Base::traverse_1_cb_ro(payload, fn); \
394-
DRJIT_MAP(DR_TRAVERSE_MEMBER_RO, __VA_ARGS__) \
401+
\
402+
drjit::traverse_1(this->traverse_1_cb_fields_(), \
403+
[payload, fn](auto &x) { \
404+
drjit::traverse_1_fn_ro(x, payload, fn); \
405+
}); \
395406
} \
396407
MI_VARIANT \
397408
void Type<Float, Spectrum>::traverse_1_cb_rw( \
@@ -407,7 +418,10 @@ extern "C" {
407418
\
408419
if constexpr (!std ::is_same_v<Base, drjit ::TraversableBase>) \
409420
Base::traverse_1_cb_rw(payload, fn); \
410-
DRJIT_MAP(DR_TRAVERSE_MEMBER_RW, __VA_ARGS__) \
421+
drjit::traverse_1(this->traverse_1_cb_fields_(), \
422+
[payload, fn](auto &x) { \
423+
drjit::traverse_1_fn_rw(x, payload, fn); \
424+
}); \
411425
}
412426

413427
//! @}

include/mitsuba/render/endpoint.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ class MI_EXPORT_LIB Endpoint : public Object {
398398
bool m_needs_sample_3 = true;
399399
std::string m_id;
400400

401-
MI_DECLARE_TRAVERSE_CB()
401+
MI_DECLARE_TRAVERSE_CB(m_to_world, m_medium)
402402
};
403403

404404
MI_EXTERN_CLASS(Endpoint)

include/mitsuba/render/film.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ class MI_EXPORT_LIB Film : public Object {
225225
ref<ReconstructionFilter> m_filter;
226226
ref<Texture> m_srf;
227227

228-
MI_DECLARE_TRAVERSE_CB()
228+
MI_DECLARE_TRAVERSE_CB(m_srf)
229229
};
230230

231231
MI_EXTERN_CLASS(Film)

include/mitsuba/render/medium.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class MI_EXPORT_LIB Medium : public Object {
113113
/// Identifier (if available)
114114
std::string m_id;
115115

116-
MI_DECLARE_TRAVERSE_CB()
116+
MI_DECLARE_TRAVERSE_CB(m_phase_function)
117117
};
118118

119119
MI_EXTERN_CLASS(Medium)

include/mitsuba/render/mesh.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,9 @@ class MI_EXPORT_LIB Mesh : public Shape<Float, Spectrum> {
602602
/// Pointer to the scene that owns this mesh
603603
Scene<Float, Spectrum>* m_scene = nullptr;
604604

605-
MI_DECLARE_TRAVERSE_CB()
605+
MI_DECLARE_TRAVERSE_CB(m_vertex_positions, m_vertex_normals,
606+
m_vertex_texcoords, m_faces, m_E2E, m_sil_dedge_pmf,
607+
m_mesh_attributes, m_area_pmf, m_parameterization)
606608
};
607609

608610
MI_EXTERN_CLASS(Mesh)

include/mitsuba/render/scene.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,10 @@ class MI_EXPORT_LIB Scene : public Object {
654654
void traverse_1_cb_rw_cpu(void *payload,
655655
drjit::detail::traverse_callback_rw fn);
656656

657-
MI_DECLARE_TRAVERSE_CB()
657+
MI_DECLARE_TRAVERSE_CB(m_accel_handle, m_emitters, m_emitters_dr, m_shapes,
658+
m_shapes_dr, m_shapegroups, m_sensors, m_sensors_dr,
659+
m_children, m_integrator, m_environment,
660+
m_emitter_pmf, m_emitter_distr, m_silhouette_shapes)
658661
};
659662

660663
/// Dummy function which can be called to ensure that the librender shared library is loaded

include/mitsuba/render/shape.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,9 @@ class MI_EXPORT_LIB Shape : public Object {
10361036
/// True if the shape has called iniatlize() at least once
10371037
bool m_initialized = false;
10381038

1039-
MI_DECLARE_TRAVERSE_CB()
1039+
MI_DECLARE_TRAVERSE_CB(m_bsdf, m_emitter, m_sensor, m_interior_medium,
1040+
m_exterior_medium, m_texture_attributes, m_to_world,
1041+
m_to_object)
10401042
};
10411043

10421044
// -----------------------------------------------------------------------

include/mitsuba/render/shapegroup.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class MI_EXPORT_LIB ShapeGroup : public Shape<Float, Spectrum> {
109109

110110
bool m_has_meshes, m_has_bspline_curves, m_has_linear_curves, m_has_others;
111111

112-
MI_DECLARE_TRAVERSE_CB()
112+
MI_DECLARE_TRAVERSE_CB(m_shapes, m_shapes_registry_ids, m_accel_handles)
113113
};
114114

115115
MI_EXTERN_CLASS(ShapeGroup)

src/render/endpoint.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ MI_VARIANT void Endpoint<Float, Spectrum>::parameters_changed(const std::vector<
118118
}
119119
}
120120

121-
MI_IMPLEMENT_TRAVERSE_CB(Endpoint, Object, m_to_world, m_medium)
121+
MI_IMPLEMENT_TRAVERSE_CB(Endpoint, Object)
122122
MI_IMPLEMENT_CLASS_VARIANT(Endpoint, Object)
123123
MI_INSTANTIATE_CLASS(Endpoint)
124124
NAMESPACE_END(mitsuba)

src/render/film.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ MI_VARIANT std::string Film<Float, Spectrum>::to_string() const {
117117
return oss.str();
118118
}
119119

120-
MI_IMPLEMENT_TRAVERSE_CB(Film, Object, m_srf)
120+
MI_IMPLEMENT_TRAVERSE_CB(Film, Object)
121121
MI_IMPLEMENT_CLASS_VARIANT(Film, Object, "film")
122122
MI_INSTANTIATE_CLASS(Film)
123123
NAMESPACE_END(mitsuba)

src/render/medium.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ Medium<Float, Spectrum>::transmittance_eval_pdf(const MediumInteraction3f &mi,
102102
return { tr, pdf };
103103
}
104104

105-
MI_IMPLEMENT_TRAVERSE_CB(Medium, Object, m_phase_function)
105+
MI_IMPLEMENT_TRAVERSE_CB(Medium, Object)
106106
MI_IMPLEMENT_CLASS_VARIANT(Medium, Object, "medium")
107107
MI_INSTANTIATE_CLASS(Medium)
108108
NAMESPACE_END(mitsuba)

src/render/mesh.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -1889,9 +1889,7 @@ MI_VARIANT bool Mesh<Float, Spectrum>::parameters_grad_enabled() const {
18891889
return dr::grad_enabled(m_vertex_positions);
18901890
}
18911891

1892-
MI_IMPLEMENT_TRAVERSE_CB(Mesh, Base, m_vertex_positions, m_vertex_normals,
1893-
m_vertex_texcoords, m_faces, m_E2E, m_sil_dedge_pmf,
1894-
m_mesh_attributes, m_area_pmf, m_parameterization)
1892+
MI_IMPLEMENT_TRAVERSE_CB(Mesh, Base)
18951893
MI_IMPLEMENT_CLASS_VARIANT(Mesh, Shape)
18961894
MI_INSTANTIATE_CLASS(Mesh)
18971895
NAMESPACE_END(mitsuba)

src/render/scene.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,9 @@ void Scene<Float, Spectrum>::traverse_1_cb_ro(
615615

616616
if constexpr (!std::is_same_v<Object, drjit::TraversableBase>)
617617
Object::traverse_1_cb_ro(payload, fn);
618-
DRJIT_MAP(DR_TRAVERSE_MEMBER_RO, MI_SCENE_FIELDS)
618+
drjit::traverse_1(this->traverse_1_cb_fields_(), [payload, fn](auto &x) {
619+
drjit::traverse_1_fn_ro(x, payload, fn);
620+
});
619621
if constexpr (dr::is_cuda_v<Float>) {
620622
// Nothing to traverse for now
621623
} else {
@@ -634,7 +636,9 @@ void Scene<Float, Spectrum>::traverse_1_cb_rw(
634636

635637
if constexpr (!std::is_same_v<Object, drjit::TraversableBase>)
636638
Object::traverse_1_cb_rw(payload, fn);
637-
DRJIT_MAP(DR_TRAVERSE_MEMBER_RW, MI_SCENE_FIELDS)
639+
drjit::traverse_1(this->traverse_1_cb_fields_(), [payload, fn](auto &x) {
640+
drjit::traverse_1_fn_rw(x, payload, fn);
641+
});
638642
if constexpr (dr::is_cuda_v<Float>) {
639643
// Nothing to traverse for now
640644
} else {

src/render/shape.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -698,9 +698,7 @@ MI_VARIANT std::string Shape<Float, Spectrum>::get_children_string() const {
698698
return oss.str();
699699
}
700700

701-
MI_IMPLEMENT_TRAVERSE_CB(Shape, Object, m_bsdf, m_emitter, m_sensor,
702-
m_interior_medium, m_exterior_medium,
703-
m_texture_attributes, m_to_world, m_to_object);
701+
MI_IMPLEMENT_TRAVERSE_CB(Shape, Object);
704702

705703
MI_IMPLEMENT_CLASS_VARIANT(Shape, Object, "shape")
706704
MI_INSTANTIATE_CLASS(Shape)

src/render/shapegroup.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,7 @@ MI_VARIANT std::string ShapeGroup<Float, Spectrum>::to_string() const {
262262
return oss.str();
263263
}
264264

265-
MI_IMPLEMENT_TRAVERSE_CB(ShapeGroup, Base, m_shapes, m_shapes_registry_ids,
266-
m_accel_handles)
265+
MI_IMPLEMENT_TRAVERSE_CB(ShapeGroup, Base)
267266
MI_IMPLEMENT_CLASS_VARIANT(ShapeGroup, Shape)
268267
MI_INSTANTIATE_CLASS(ShapeGroup)
269268
NAMESPACE_END(mitsuba)

0 commit comments

Comments
 (0)