From 39abc6602512631f29f9d6201e298330618e6520 Mon Sep 17 00:00:00 2001 From: rdb Date: Wed, 27 Dec 2017 23:51:16 +0100 Subject: [PATCH] gobj: reduce unnecessary use of threading primitives in constructors --- panda/src/gobj/geom.I | 21 ++++++---------- panda/src/gobj/geom.cxx | 34 ++++++++++---------------- panda/src/gobj/geom.h | 5 ++-- panda/src/gobj/geomVertexArrayData.I | 16 ++++++++++-- panda/src/gobj/geomVertexArrayData.cxx | 17 ++++--------- panda/src/gobj/geomVertexArrayData.h | 3 ++- panda/src/gobj/geomVertexData.I | 17 ++++++------- panda/src/gobj/geomVertexData.cxx | 18 ++------------ panda/src/gobj/geomVertexData.h | 3 ++- panda/src/pipeline/cycleData.I | 7 ------ panda/src/pipeline/cycleData.h | 4 ++- panda/src/pipeline/pipelineCycler.I | 21 ++++++++++++++++ panda/src/pipeline/pipelineCycler.h | 4 ++- 13 files changed, 83 insertions(+), 87 deletions(-) diff --git a/panda/src/gobj/geom.I b/panda/src/gobj/geom.I index d553c12977..340cfd099c 100644 --- a/panda/src/gobj/geom.I +++ b/panda/src/gobj/geom.I @@ -512,22 +512,17 @@ CData() : * */ INLINE Geom::CData:: -CData(const Geom::CData ©) : - _data(copy._data), - _primitives(copy._primitives), - _primitive_type(copy._primitive_type), - _shade_model(copy._shade_model), - _geom_rendering(copy._geom_rendering), - _modified(copy._modified), - _internal_bounds(copy._internal_bounds), - _nested_vertices(copy._nested_vertices), - _internal_bounds_stale(copy._internal_bounds_stale), - _bounds_type(copy._bounds_type), - _user_bounds(copy._user_bounds) +CData(GeomVertexData *data) : + _data(data), + _primitive_type(PT_none), + _shade_model(SM_uniform), + _geom_rendering(0), + _nested_vertices(0), + _internal_bounds_stale(true), + _bounds_type(BoundingVolume::BT_default) { } - /** * */ diff --git a/panda/src/gobj/geom.cxx b/panda/src/gobj/geom.cxx index 8590342010..efdd4ba5ca 100644 --- a/panda/src/gobj/geom.cxx +++ b/panda/src/gobj/geom.cxx @@ -46,13 +46,7 @@ make_cow_copy() { * */ Geom:: -Geom(const GeomVertexData *data) { - // Let's ensure the vertex data gets set on all stages at once. - OPEN_ITERATE_ALL_STAGES(_cycler) { - CDStageWriter cdata(_cycler, pipeline_stage); - cdata->_data = (GeomVertexData *)data; - } - CLOSE_ITERATE_ALL_STAGES(_cycler); +Geom(const GeomVertexData *data) : _cycler(CData((GeomVertexData *)data)) { } /** @@ -631,7 +625,7 @@ unify_in_place(int max_indices, bool preserve_order) { } else { // We have already encountered another primitive of this type. Combine // them. - combine_primitives((*npi).second, primitive, current_thread); + combine_primitives((*npi).second, move(primitive), current_thread); } } @@ -1491,31 +1485,29 @@ reset_geom_rendering(Geom::CData *cdata) { * is modified to append the vertices from b_prim, which is unmodified. */ void Geom:: -combine_primitives(GeomPrimitive *a_prim, const GeomPrimitive *b_prim, +combine_primitives(GeomPrimitive *a_prim, CPT(GeomPrimitive) b_prim, Thread *current_thread) { nassertv(a_prim != b_prim); nassertv(a_prim->get_type() == b_prim->get_type()); - CPT(GeomPrimitive) b_prim2 = b_prim; - - if (a_prim->get_index_type() != b_prim2->get_index_type()) { - GeomPrimitive::NumericType index_type = max(a_prim->get_index_type(), b_prim2->get_index_type()); + if (a_prim->get_index_type() != b_prim->get_index_type()) { + GeomPrimitive::NumericType index_type = max(a_prim->get_index_type(), b_prim->get_index_type()); a_prim->set_index_type(index_type); - if (b_prim2->get_index_type() != index_type) { - PT(GeomPrimitive) b_prim_copy = b_prim2->make_copy(); + if (b_prim->get_index_type() != index_type) { + PT(GeomPrimitive) b_prim_copy = b_prim->make_copy(); b_prim_copy->set_index_type(index_type); - b_prim2 = b_prim_copy; + b_prim = b_prim_copy; } } - if (!b_prim2->is_indexed()) { - PT(GeomPrimitive) b_prim_copy = b_prim2->make_copy(); + if (!b_prim->is_indexed()) { + PT(GeomPrimitive) b_prim_copy = b_prim->make_copy(); b_prim_copy->make_indexed(); - b_prim2 = b_prim_copy; + b_prim = b_prim_copy; } PT(GeomVertexArrayData) a_vertices = a_prim->modify_vertices(); - CPT(GeomVertexArrayData) b_vertices = b_prim2->get_vertices(); + CPT(GeomVertexArrayData) b_vertices = b_prim->get_vertices(); if (a_prim->requires_unused_vertices()) { GeomVertexReader index(b_vertices, 0); @@ -1536,7 +1528,7 @@ combine_primitives(GeomPrimitive *a_prim, const GeomPrimitive *b_prim, if (a_prim->is_composite()) { // Also copy the ends array. PTA_int a_ends = a_prim->modify_ends(); - CPTA_int b_ends = b_prim2->get_ends(); + CPTA_int b_ends = b_prim->get_ends(); for (size_t i = 0; i < b_ends.size(); ++i) { a_ends.push_back(b_ends[i] + orig_a_vertices); } diff --git a/panda/src/gobj/geom.h b/panda/src/gobj/geom.h index 8b220a5a4a..ec81442703 100644 --- a/panda/src/gobj/geom.h +++ b/panda/src/gobj/geom.h @@ -196,7 +196,7 @@ private: void reset_geom_rendering(CData *cdata); - void combine_primitives(GeomPrimitive *a_prim, const GeomPrimitive *b_prim, + void combine_primitives(GeomPrimitive *a_prim, CPT(GeomPrimitive) b_prim, Thread *current_thread); private: @@ -302,7 +302,8 @@ private: class EXPCL_PANDA_GOBJ CData : public CycleData { public: INLINE CData(); - INLINE CData(const CData ©); + INLINE CData(GeomVertexData *data); + ALLOC_DELETED_CHAIN(CData); virtual CycleData *make_copy() const; virtual void write_datagram(BamWriter *manager, Datagram &dg) const; diff --git a/panda/src/gobj/geomVertexArrayData.I b/panda/src/gobj/geomVertexArrayData.I index 351f56cd53..624525360d 100644 --- a/panda/src/gobj/geomVertexArrayData.I +++ b/panda/src/gobj/geomVertexArrayData.I @@ -229,8 +229,20 @@ mark_used() { * */ INLINE GeomVertexArrayData::CData:: -CData() : - _usage_hint(UH_unspecified), +CData(UsageHint usage_hint) : + _usage_hint(usage_hint), + _rw_lock("GeomVertexArrayData::CData::_rw_lock") +{ +} + +/** + * + */ +INLINE GeomVertexArrayData::CData:: +CData(GeomVertexArrayData::CData &&from) NOEXCEPT : + _usage_hint(move(from._usage_hint)), + _buffer(move(from._buffer)), + _modified(move(from._modified)), _rw_lock("GeomVertexArrayData::CData::_rw_lock") { } diff --git a/panda/src/gobj/geomVertexArrayData.cxx b/panda/src/gobj/geomVertexArrayData.cxx index 2747e22395..50a4529159 100644 --- a/panda/src/gobj/geomVertexArrayData.cxx +++ b/panda/src/gobj/geomVertexArrayData.cxx @@ -77,16 +77,10 @@ GeomVertexArrayData:: GeomVertexArrayData(const GeomVertexArrayFormat *array_format, GeomVertexArrayData::UsageHint usage_hint) : SimpleLruPage(0), - _array_format(array_format) + _array_format(array_format), + _cycler(CData(usage_hint)), + _contexts(nullptr) { - OPEN_ITERATE_ALL_STAGES(_cycler) { - CDStageWriter cdata(_cycler, pipeline_stage); - cdata->_usage_hint = usage_hint; - } - CLOSE_ITERATE_ALL_STAGES(_cycler); - - _contexts = NULL; - set_lru_size(0); nassertv(_array_format->is_registered()); } @@ -99,10 +93,9 @@ GeomVertexArrayData(const GeomVertexArrayData ©) : CopyOnWriteObject(copy), SimpleLruPage(copy), _array_format(copy._array_format), - _cycler(copy._cycler) + _cycler(copy._cycler), + _contexts(nullptr) { - _contexts = NULL; - copy.mark_used_lru(); set_lru_size(get_data_size_bytes()); diff --git a/panda/src/gobj/geomVertexArrayData.h b/panda/src/gobj/geomVertexArrayData.h index c16c5831d9..4a49d26881 100644 --- a/panda/src/gobj/geomVertexArrayData.h +++ b/panda/src/gobj/geomVertexArrayData.h @@ -150,7 +150,8 @@ private: // This is the data that must be cycled between pipeline stages. class EXPCL_PANDA_GOBJ CData : public CycleData { public: - INLINE CData(); + INLINE CData(UsageHint usage_hint = UH_unspecified); + INLINE CData(CData &&from) NOEXCEPT; INLINE CData(const CData ©); INLINE void operator = (const CData ©); diff --git a/panda/src/gobj/geomVertexData.I b/panda/src/gobj/geomVertexData.I index 53c1c76367..5a24b166a5 100644 --- a/panda/src/gobj/geomVertexData.I +++ b/panda/src/gobj/geomVertexData.I @@ -583,17 +583,14 @@ CData() : * */ INLINE GeomVertexData::CData:: -CData(const GeomVertexData::CData ©) : - _usage_hint(copy._usage_hint), - _format(copy._format), - _arrays(copy._arrays), - _transform_table(copy._transform_table), - _transform_blend_table(copy._transform_blend_table), - _slider_table(copy._slider_table), - _animated_vertices(copy._animated_vertices), - _animated_vertices_modified(copy._animated_vertices_modified), - _modified(copy._modified) +CData(const GeomVertexFormat *format, GeomVertexData::UsageHint usage_hint) : + _format(format), + _usage_hint(usage_hint) { + size_t num_arrays = format->get_num_arrays(); + for (size_t i = 0; i < num_arrays; ++i) { + _arrays.push_back(new GeomVertexArrayData(format->get_array(i), usage_hint)); + } } /** diff --git a/panda/src/gobj/geomVertexData.cxx b/panda/src/gobj/geomVertexData.cxx index 339f38114e..b692c36bf5 100644 --- a/panda/src/gobj/geomVertexData.cxx +++ b/panda/src/gobj/geomVertexData.cxx @@ -67,24 +67,10 @@ GeomVertexData(const string &name, _char_pcollector(PStatCollector(_animation_pcollector, name)), _skinning_pcollector(_char_pcollector, "Skinning"), _morphs_pcollector(_char_pcollector, "Morphs"), - _blends_pcollector(_char_pcollector, "Calc blends") + _blends_pcollector(_char_pcollector, "Calc blends"), + _cycler(GeomVertexData::CData(format, usage_hint)) { nassertv(format->is_registered()); - - // Create some empty arrays as required by the format. Let's ensure the - // vertex data gets set on all stages at once. - OPEN_ITERATE_ALL_STAGES(_cycler) { - CDStageWriter cdata(_cycler, pipeline_stage); - cdata->_format = format; - cdata->_usage_hint = usage_hint; - int num_arrays = format->get_num_arrays(); - for (int i = 0; i < num_arrays; i++) { - PT(GeomVertexArrayData) array = new GeomVertexArrayData - (format->get_array(i), usage_hint); - cdata->_arrays.push_back(array.p()); - } - } - CLOSE_ITERATE_ALL_STAGES(_cycler); } /** diff --git a/panda/src/gobj/geomVertexData.h b/panda/src/gobj/geomVertexData.h index f2858d5a16..d86dd36fc4 100644 --- a/panda/src/gobj/geomVertexData.h +++ b/panda/src/gobj/geomVertexData.h @@ -293,7 +293,8 @@ private: class EXPCL_PANDA_GOBJ CData : public CycleData { public: INLINE CData(); - INLINE CData(const CData ©); + INLINE CData(const GeomVertexFormat *format, UsageHint usage_hint); + ALLOC_DELETED_CHAIN(CData); virtual CycleData *make_copy() const; virtual void write_datagram(BamWriter *manager, Datagram &dg) const; diff --git a/panda/src/pipeline/cycleData.I b/panda/src/pipeline/cycleData.I index 53c0224eab..b66184d145 100644 --- a/panda/src/pipeline/cycleData.I +++ b/panda/src/pipeline/cycleData.I @@ -10,10 +10,3 @@ * @author drose * @date 2002-02-21 */ - -/** - * - */ -INLINE CycleData:: -CycleData() { -} diff --git a/panda/src/pipeline/cycleData.h b/panda/src/pipeline/cycleData.h index 4a020c9940..72ba074088 100644 --- a/panda/src/pipeline/cycleData.h +++ b/panda/src/pipeline/cycleData.h @@ -49,7 +49,9 @@ class EXPCL_PANDA_PIPELINE CycleData #endif // DO_PIPELINING { public: - INLINE CycleData(); + INLINE CycleData() DEFAULT_CTOR; + INLINE CycleData(CycleData &&from) DEFAULT_CTOR; + INLINE CycleData(const CycleData ©) DEFAULT_CTOR; virtual ~CycleData(); virtual CycleData *make_copy() const=0; diff --git a/panda/src/pipeline/pipelineCycler.I b/panda/src/pipeline/pipelineCycler.I index 8efce5450a..06c6c1e5dc 100644 --- a/panda/src/pipeline/pipelineCycler.I +++ b/panda/src/pipeline/pipelineCycler.I @@ -25,6 +25,16 @@ PipelineCycler(Pipeline *pipeline) : { } +/** + * + */ +template +INLINE PipelineCycler:: +PipelineCycler(CycleDataType &&initial_data, Pipeline *pipeline) : + PipelineCyclerBase(new CycleDataType(move(initial_data)), pipeline) +{ +} + /** * */ @@ -182,6 +192,17 @@ PipelineCycler(Pipeline *pipeline) : { } +/** + * + */ +template +INLINE PipelineCycler:: +PipelineCycler(CycleDataType &&initial_data, Pipeline *pipeline) : + _typed_data(move(initial_data)), + PipelineCyclerBase(&_typed_data, pipeline) +{ +} + /** * */ diff --git a/panda/src/pipeline/pipelineCycler.h b/panda/src/pipeline/pipelineCycler.h index f87475c192..adc7abd1a8 100644 --- a/panda/src/pipeline/pipelineCycler.h +++ b/panda/src/pipeline/pipelineCycler.h @@ -45,7 +45,9 @@ template struct PipelineCycler : public PipelineCyclerBase { public: - INLINE PipelineCycler(Pipeline *pipeline = NULL); + INLINE PipelineCycler(Pipeline *pipeline = nullptr); + INLINE PipelineCycler(CycleDataType &&initial_data, Pipeline *pipeline = nullptr); + INLINE PipelineCycler(const PipelineCycler ©); INLINE void operator = (const PipelineCycler ©);