diff --git a/panda/src/display/graphicsStateGuardian.cxx b/panda/src/display/graphicsStateGuardian.cxx index 171348c51b..c45042f12c 100644 --- a/panda/src/display/graphicsStateGuardian.cxx +++ b/panda/src/display/graphicsStateGuardian.cxx @@ -24,6 +24,7 @@ PStatCollector GraphicsStateGuardian::_vertices_tristrip_pcollector("Vertices:Tr PStatCollector GraphicsStateGuardian::_vertices_trifan_pcollector("Vertices:Triangle fans"); PStatCollector GraphicsStateGuardian::_vertices_tri_pcollector("Vertices:Triangles"); PStatCollector GraphicsStateGuardian::_vertices_other_pcollector("Vertices:Other"); +PStatCollector GraphicsStateGuardian::_state_changes_pcollector("State changes"); #endif TypeHandle GraphicsStateGuardian::_type_handle; @@ -155,7 +156,7 @@ set_state(const NodeAttributes &new_state, bool complete) { gsg_cat.debug() << "Issuing new attrib " << *(*new_i).second << "\n"; } - + _state_changes_pcollector.add_level(1); (*new_i).second->issue(this); // And store the new value. @@ -178,6 +179,7 @@ set_state(const NodeAttributes &new_state, bool complete) { << "Unissuing attrib " << *(*current_i).second << " (previously set, not now)\n"; } + _state_changes_pcollector.add_level(1); PT(NodeAttribute) initial = (*current_i).second->make_initial(); initial->issue(this); @@ -206,6 +208,7 @@ set_state(const NodeAttributes &new_state, bool complete) { << "Unissuing attrib " << *(*current_i).second << " (previously set, now NULL)\n"; } + _state_changes_pcollector.add_level(1); // Issue the initial attribute before clearing the state. PT(NodeAttribute) initial = (*current_i).second->make_initial(); @@ -230,6 +233,7 @@ set_state(const NodeAttributes &new_state, bool complete) { gsg_cat.debug() << "Reissuing attrib " << *(*new_i).second << "\n"; } + _state_changes_pcollector.add_level(1); (*new_i).second->issue(this); // And store the new value. @@ -255,6 +259,7 @@ set_state(const NodeAttributes &new_state, bool complete) { gsg_cat.debug() << "Issuing new attrib " << *(*new_i).second << "\n"; } + _state_changes_pcollector.add_level(1); (*new_i).second->issue(this); @@ -274,6 +279,7 @@ set_state(const NodeAttributes &new_state, bool complete) { << "Unissuing attrib " << *(*current_i).second << " (previously set, end of list)\n"; } + _state_changes_pcollector.add_level(1); // If we're in the "complete state" model, that means this // attribute should now get the default initial value. @@ -437,7 +443,7 @@ mark_prepared_texture(TextureContext *tc) { bool prepared = _prepared_textures.insert(tc).second; #ifdef DO_PSTATS if (prepared) { - _total_texusage_pcollector.add_level(tc->estimate_texture_memory() / 1048576.0); + _total_texusage_pcollector.add_level(tc->estimate_texture_memory()); } #endif return prepared; @@ -457,13 +463,34 @@ unmark_prepared_texture(TextureContext *tc) { bool removed = (_prepared_textures.erase(tc) != 0); #ifdef DO_PSTATS if (removed) { - _total_texusage_pcollector.add_level(-(tc->estimate_texture_memory() / 1048576.0)); + _total_texusage_pcollector.sub_level(tc->estimate_texture_memory()); } #endif return removed; } #ifdef DO_PSTATS + +//////////////////////////////////////////////////////////////////// +// Function: GraphicsStateGuardian::init_frame_pstats +// Access: Protected +// Description: Initializes the relevant PStats data at the beginning +// of the frame. +//////////////////////////////////////////////////////////////////// +void GraphicsStateGuardian:: +init_frame_pstats() { + _current_textures.clear(); + _active_texusage_pcollector.clear_level(); + + // Also clear out our other counters while we're here. + _vertices_tristrip_pcollector.clear_level(); + _vertices_trifan_pcollector.clear_level(); + _vertices_tri_pcollector.clear_level(); + _vertices_other_pcollector.clear_level(); + + _state_changes_pcollector.clear_level(); +} + //////////////////////////////////////////////////////////////////// // Function: GraphicsStateGuardian::add_to_texture_record // Access: Protected @@ -476,23 +503,9 @@ unmark_prepared_texture(TextureContext *tc) { void GraphicsStateGuardian:: add_to_texture_record(TextureContext *tc) { if (_current_textures.insert(tc).second) { - _active_texusage_pcollector.add_level(tc->estimate_texture_memory() / 1048576.0); + _active_texusage_pcollector.add_level(tc->estimate_texture_memory()); } } - -//////////////////////////////////////////////////////////////////// -// Function: GraphicsStateGuardian::clear_texture_record -// Access: Protected -// Description: Empties the texture record at the beginning of the -// frame, in preparation for calling -// add_to_texture_record() each time a texture is -// applied. -//////////////////////////////////////////////////////////////////// -void GraphicsStateGuardian:: -clear_texture_record() { - _current_textures.clear(); - _active_texusage_pcollector.set_level(0); -} #endif // DO_PSTATS diff --git a/panda/src/display/graphicsStateGuardian.h b/panda/src/display/graphicsStateGuardian.h index 1bf115e9c0..43f77f78db 100644 --- a/panda/src/display/graphicsStateGuardian.h +++ b/panda/src/display/graphicsStateGuardian.h @@ -135,14 +135,14 @@ protected: bool unmark_prepared_texture(TextureContext *tc); #ifdef DO_PSTATS - // These functions are used to update the current texture memory - // usage record in Pstats. + // These functions are used to update the active texture memory + // usage record (and other frame-based measurements) in Pstats. + void init_frame_pstats(); void add_to_texture_record(TextureContext *tc); - void clear_texture_record(); set _current_textures; #else + INLINE void init_frame_pstats() { } INLINE void add_to_texture_record(TextureContext *) { } - INLINE void clear_texture_record() { } #endif protected: @@ -180,6 +180,7 @@ protected: static PStatCollector _vertices_trifan_pcollector; static PStatCollector _vertices_tri_pcollector; static PStatCollector _vertices_other_pcollector; + static PStatCollector _state_changes_pcollector; private: typedef set Textures; diff --git a/panda/src/glgsg/glGraphicsStateGuardian.cxx b/panda/src/glgsg/glGraphicsStateGuardian.cxx index 27b9c34173..49c59e5502 100644 --- a/panda/src/glgsg/glGraphicsStateGuardian.cxx +++ b/panda/src/glgsg/glGraphicsStateGuardian.cxx @@ -476,7 +476,7 @@ render_frame(const AllAttributesWrapper &initial_state) { #ifdef DO_PSTATS // For Pstats to track our current texture memory usage, we have to // reset the set of current textures each frame. - clear_texture_record(); + init_frame_pstats(); // But since we don't get sent a new issue_texture() unless our // texture state has changed, we have to be sure to clear the @@ -485,12 +485,6 @@ render_frame(const AllAttributesWrapper &initial_state) { NodeAttributes state; state.set_attribute(TextureTransition::get_class_type(), new TextureAttribute); set_state(state, false); - - // Also clear out our vertex counters while we're here. - _vertices_tristrip_pcollector.set_level(0); - _vertices_trifan_pcollector.set_level(0); - _vertices_tri_pcollector.set_level(0); - _vertices_other_pcollector.set_level(0); #endif if (_clear_buffer_type != 0) { diff --git a/panda/src/pstatclient/pStatClient.cxx b/panda/src/pstatclient/pStatClient.cxx index b5b3aae6dc..f3fe88a6c0 100644 --- a/panda/src/pstatclient/pStatClient.cxx +++ b/panda/src/pstatclient/pStatClient.cxx @@ -540,6 +540,7 @@ clear_level(int collector_index, int thread_index) { //////////////////////////////////////////////////////////////////// void PStatClient:: set_level(int collector_index, int thread_index, float level) { + level *= _collectors[collector_index]._def->_factor; _collectors[collector_index]._per_thread[thread_index]._has_level = true; _collectors[collector_index]._per_thread[thread_index]._level = level; } @@ -557,6 +558,7 @@ set_level(int collector_index, int thread_index, float level) { //////////////////////////////////////////////////////////////////// void PStatClient:: add_level(int collector_index, int thread_index, float increment) { + increment *= _collectors[collector_index]._def->_factor; _collectors[collector_index]._per_thread[thread_index]._has_level = true; _collectors[collector_index]._per_thread[thread_index]._level += increment; } diff --git a/panda/src/pstatclient/pStatCollector.I b/panda/src/pstatclient/pStatCollector.I index 1cdaca9e3b..ef2a923e5e 100644 --- a/panda/src/pstatclient/pStatCollector.I +++ b/panda/src/pstatclient/pStatCollector.I @@ -260,4 +260,32 @@ add_level(const PStatThread &thread, float increment) { _client->add_level(_index, thread._index, increment); } +//////////////////////////////////////////////////////////////////// +// Function: PStatCollector::sub_level +// Access: Public +// Description: Subtracts the indicated decrement (which may be +// negative) to the level setting associated with this +// collector for the main thread. If the collector did +// not already have a level setting for the main thread, +// it is initialized to 0. +//////////////////////////////////////////////////////////////////// +INLINE void PStatCollector:: +sub_level(float decrement) { + _client->add_level(_index, 0, -decrement); +} + +//////////////////////////////////////////////////////////////////// +// Function: PStatCollector::sub_level +// Access: Public +// Description: Subtracts the indicated decrement (which may be +// negative) to the level setting associated with this +// collector for the indicated thread. If the collector +// did not already have a level setting for this thread, +// it is initialized to 0. +//////////////////////////////////////////////////////////////////// +INLINE void PStatCollector:: +sub_level(const PStatThread &thread, float decrement) { + _client->add_level(_index, thread._index, -decrement); +} + #endif // DO_PSTATS diff --git a/panda/src/pstatclient/pStatCollector.h b/panda/src/pstatclient/pStatCollector.h index b74742343b..cd161ffb92 100644 --- a/panda/src/pstatclient/pStatCollector.h +++ b/panda/src/pstatclient/pStatCollector.h @@ -67,6 +67,8 @@ public: INLINE void set_level(const PStatThread &thread, float level); INLINE void add_level(float increment); INLINE void add_level(const PStatThread &thread, float increment); + INLINE void sub_level(float decrement); + INLINE void sub_level(const PStatThread &thread, float decrement); private: PStatClient *_client; diff --git a/panda/src/pstatclient/pStatCollectorDef.cxx b/panda/src/pstatclient/pStatCollectorDef.cxx index f6ae6aeeb1..2bdb992ba7 100644 --- a/panda/src/pstatclient/pStatCollectorDef.cxx +++ b/panda/src/pstatclient/pStatCollectorDef.cxx @@ -21,6 +21,7 @@ PStatCollectorDef() { _suggested_color.set(0.0, 0.0, 0.0); _sort = -1; _suggested_scale = 0.0; + _factor = 1.0; } //////////////////////////////////////////////////////////////////// @@ -37,6 +38,7 @@ PStatCollectorDef(int index, const string &name) : _suggested_color.set(0.0, 0.0, 0.0); _sort = -1; _suggested_scale = 0.0; + _factor = 1.0; } //////////////////////////////////////////////////////////////////// @@ -52,6 +54,7 @@ set_parent(const PStatCollectorDef &parent) { _parent_index = parent._index; _level_units = parent._level_units; _suggested_scale = parent._suggested_scale; + _factor = parent._factor; } //////////////////////////////////////////////////////////////////// @@ -69,6 +72,7 @@ write_datagram(Datagram &destination) const { destination.add_int16(_sort); destination.add_string(_level_units); destination.add_float32(_suggested_scale); + destination.add_float32(_factor); } //////////////////////////////////////////////////////////////////// @@ -85,4 +89,5 @@ read_datagram(DatagramIterator &source) { _sort = source.get_int16(); _level_units = source.get_string(); _suggested_scale = source.get_float32(); + _factor = source.get_float32(); } diff --git a/panda/src/pstatclient/pStatCollectorDef.h b/panda/src/pstatclient/pStatCollectorDef.h index 20d9b33d17..94542d9467 100644 --- a/panda/src/pstatclient/pStatCollectorDef.h +++ b/panda/src/pstatclient/pStatCollectorDef.h @@ -35,6 +35,7 @@ public: int _sort; string _level_units; float _suggested_scale; + float _factor; }; #endif diff --git a/panda/src/pstatclient/pStatProperties.cxx b/panda/src/pstatclient/pStatProperties.cxx index f43101f572..2cf9b32600 100644 --- a/panda/src/pstatclient/pStatProperties.cxx +++ b/panda/src/pstatclient/pStatProperties.cxx @@ -46,6 +46,7 @@ struct LevelCollectorProperties { ColorDef color; const char *units; float suggested_scale; + float inv_factor; }; static TimeCollectorProperties time_properties[] = { @@ -64,15 +65,17 @@ static TimeCollectorProperties time_properties[] = { }; static LevelCollectorProperties level_properties[] = { - { "Texture usage", { 1.0, 0.0, 0.0 }, "MB", 12.0 }, + { "Texture usage", { 1.0, 0.0, 0.0 }, "MB", 12, 1048576 }, { "Texture usage:Active", { 1.0, 1.0, 0.0 } }, - { "Texture memory", { 0.0, 0.0, 1.0 }, "MB", 12.0 }, + { "Texture memory", { 0.0, 0.0, 1.0 }, "MB", 12, 1048576 }, { "Texture memory:In use", { 0.0, 1.0, 1.0 } }, - { "Vertices", { 0.5, 0.2, 0.0 }, "", 10000.0 }, + { "Vertices", { 0.5, 0.2, 0.0 }, "K", 10, 1000 }, { "Vertices:Other", { 0.2, 0.2, 0.2 } }, { "Vertices:Triangles", { 0.8, 0.8, 0.8 } }, { "Vertices:Triangle fans", { 0.8, 0.5, 0.2 } }, { "Vertices:Triangle strips", { 0.2, 0.5, 0.8 } }, + { "Nodes", { 0.4, 0.2, 0.5 }, "", 1000.0 }, + { "State changes", { 1.0, 0.5, 0.2 }, "", 500.0 }, { NULL } }; @@ -123,6 +126,9 @@ initialize_collector_def(PStatClient *client, PStatCollectorDef *def) { if (lp.units != (const char *)NULL) { def->_level_units = lp.units; } + if (lp.inv_factor != 0.0) { + def->_factor = 1.0 / lp.inv_factor; + } return; } }