diff --git a/panda/src/display/graphicsStateGuardian.cxx b/panda/src/display/graphicsStateGuardian.cxx index 209f8b32c1..50b8597951 100644 --- a/panda/src/display/graphicsStateGuardian.cxx +++ b/panda/src/display/graphicsStateGuardian.cxx @@ -19,6 +19,8 @@ PStatCollector GraphicsStateGuardian::_total_texusage_pcollector("Texture usage" PStatCollector GraphicsStateGuardian::_active_texusage_pcollector("Texture usage:Active"); PStatCollector GraphicsStateGuardian::_total_texmem_pcollector("Texture memory"); PStatCollector GraphicsStateGuardian::_used_texmem_pcollector("Texture memory:In use"); +PStatCollector GraphicsStateGuardian::_texmgrmem_total_pcollector("Texture manager"); +PStatCollector GraphicsStateGuardian::_texmgrmem_resident_pcollector("Texture manager:Resident"); PStatCollector GraphicsStateGuardian::_vertices_pcollector("Vertices"); PStatCollector GraphicsStateGuardian::_vertices_tristrip_pcollector("Vertices:Triangle strips"); PStatCollector GraphicsStateGuardian::_vertices_trifan_pcollector("Vertices:Triangle fans"); diff --git a/panda/src/display/graphicsStateGuardian.h b/panda/src/display/graphicsStateGuardian.h index 5afec2ca2d..27b4091de6 100644 --- a/panda/src/display/graphicsStateGuardian.h +++ b/panda/src/display/graphicsStateGuardian.h @@ -180,6 +180,8 @@ public: static PStatCollector _active_texusage_pcollector; static PStatCollector _total_texmem_pcollector; static PStatCollector _used_texmem_pcollector; + static PStatCollector _texmgrmem_total_pcollector; + static PStatCollector _texmgrmem_resident_pcollector; static PStatCollector _vertices_pcollector; static PStatCollector _vertices_tristrip_pcollector; static PStatCollector _vertices_trifan_pcollector; diff --git a/panda/src/display/textureContext.cxx b/panda/src/display/textureContext.cxx index 592950241e..c52b816243 100644 --- a/panda/src/display/textureContext.cxx +++ b/panda/src/display/textureContext.cxx @@ -25,6 +25,9 @@ estimate_texture_memory() { size_t pixels = pb->get_xsize() * pb->get_ysize(); + size_t bpp = 4; + + /* size_t bpp = 1; switch (pb->get_format()) { case PixelBuffer::F_rgb332: @@ -60,6 +63,7 @@ estimate_texture_memory() { bpp = 6; break; } + */ size_t bytes = pixels * bpp; diff --git a/panda/src/dxgsg/dxGraphicsStateGuardian.cxx b/panda/src/dxgsg/dxGraphicsStateGuardian.cxx index 173f26f5bd..238cf5db3d 100644 --- a/panda/src/dxgsg/dxGraphicsStateGuardian.cxx +++ b/panda/src/dxgsg/dxGraphicsStateGuardian.cxx @@ -67,6 +67,7 @@ #include #include #include +#include #define DISABLE_POLYGON_OFFSET_DECALING // currently doesnt work well enough in toontown models for us to use @@ -777,6 +778,12 @@ render_frame(const AllAttributesWrapper &initial_state) { show_frame(); +#ifdef DO_PSTATS + if (_texmgrmem_total_pcollector.is_active()) { + report_texmgr_stats(); + } +#endif + #ifdef PRINT_TEXSTATS { @@ -840,6 +847,28 @@ render_frame(const AllAttributesWrapper &initial_state) { #endif } +#ifdef DO_PSTATS +//////////////////////////////////////////////////////////////////// +// Function: DXGraphicsStateGuardian::report_texmgr_stats +// Access: Protected +// Description: Reports the DX texture manager's activity to PStats. +//////////////////////////////////////////////////////////////////// +void DXGraphicsStateGuardian:: +report_texmgr_stats() { + HRESULT hr; + + D3DDEVINFO_TEXTUREMANAGER tminfo; + ZeroMemory(&tminfo, sizeof(tminfo)); + hr = _d3dDevice->GetInfo(D3DDEVINFOID_TEXTUREMANAGER, + &tminfo, sizeof(tminfo)); + + // Quietly ignore an error in GetInfo(). + if (hr == D3D_OK) { + _texmgrmem_total_pcollector.set_level(tminfo.dwTotalBytes); + _texmgrmem_resident_pcollector.set_level(tminfo.dwWorkingSetBytes); + } +} +#endif // DO_PSTATS //////////////////////////////////////////////////////////////////// // Function: DXGraphicsStateGuardian::render_scene diff --git a/panda/src/dxgsg/dxGraphicsStateGuardian.h b/panda/src/dxgsg/dxGraphicsStateGuardian.h index 96237eae90..39999f030c 100644 --- a/panda/src/dxgsg/dxGraphicsStateGuardian.h +++ b/panda/src/dxgsg/dxGraphicsStateGuardian.h @@ -265,6 +265,10 @@ protected: size_t draw_prim_setup(const Geom *geom) ; void draw_multitri(const Geom *geom, D3DPRIMITIVETYPE tri_id); +#ifdef DO_PSTATS + void report_texmgr_stats(); +#endif + // for drawing primitives Colorf p_color; Normalf p_normal; diff --git a/panda/src/pstatclient/config_pstats.cxx b/panda/src/pstatclient/config_pstats.cxx index 380e8dcb77..a0c54e1779 100644 --- a/panda/src/pstatclient/config_pstats.cxx +++ b/panda/src/pstatclient/config_pstats.cxx @@ -30,6 +30,7 @@ const float pstats_target_frame_rate = config_pstats.GetFloat("pstats-target-fra // not the client. const bool pstats_scroll_mode = config_pstats.GetBool("pstats-scroll-mode", true); const float pstats_history = config_pstats.GetFloat("pstats-history", 30.0); +const bool pstats_threaded_write = config_pstats.GetBool("pstats-threaded-write", false); //////////////////////////////////////////////////////////////////// // Function: init_libpstatclient diff --git a/panda/src/pstatclient/config_pstats.h b/panda/src/pstatclient/config_pstats.h index 53a71b877b..84b60c77ab 100644 --- a/panda/src/pstatclient/config_pstats.h +++ b/panda/src/pstatclient/config_pstats.h @@ -25,6 +25,8 @@ extern EXPCL_PANDA const float pstats_target_frame_rate; extern EXPCL_PANDA const bool pstats_scroll_mode; extern EXPCL_PANDA const float pstats_history; +extern EXPCL_PANDA const bool pstats_threaded_write; + extern EXPCL_PANDA void init_libpstatclient(); #endif diff --git a/panda/src/pstatclient/pStatClient.I b/panda/src/pstatclient/pStatClient.I index 807110f02b..7fc86e5b03 100644 --- a/panda/src/pstatclient/pStatClient.I +++ b/panda/src/pstatclient/pStatClient.I @@ -67,7 +67,7 @@ get_max_rate() const { //////////////////////////////////////////////////////////////////// INLINE bool PStatClient:: connect(const string &hostname, int port) { - return get_global_pstats()->ns_connect(hostname, port); + return get_global_pstats()->client_connect(hostname, port); } //////////////////////////////////////////////////////////////////// @@ -77,7 +77,7 @@ connect(const string &hostname, int port) { //////////////////////////////////////////////////////////////////// INLINE void PStatClient:: disconnect() { - get_global_pstats()->ns_disconnect(); + get_global_pstats()->client_disconnect(); } //////////////////////////////////////////////////////////////////// @@ -88,5 +88,5 @@ disconnect() { //////////////////////////////////////////////////////////////////// INLINE bool PStatClient:: is_connected() { - return get_global_pstats()->ns_is_connected(); + return get_global_pstats()->client_is_connected(); } diff --git a/panda/src/pstatclient/pStatClient.cxx b/panda/src/pstatclient/pStatClient.cxx index df7262415e..2563bb4796 100644 --- a/panda/src/pstatclient/pStatClient.cxx +++ b/panda/src/pstatclient/pStatClient.cxx @@ -46,7 +46,7 @@ PerThreadData() { PStatClient:: PStatClient() : _reader(this, 0), - _writer(this, 0) + _writer(this, pstats_threaded_write ? 1 : 0) { _is_connected = false; _got_udp_port = false; @@ -369,13 +369,13 @@ get_global_pstats() { } //////////////////////////////////////////////////////////////////// -// Function: PStatClient::ns_connect +// Function: PStatClient::client_connect // Access: Private // Description: The nonstatic implementation of connect(). //////////////////////////////////////////////////////////////////// bool PStatClient:: -ns_connect(string hostname, int port) { - ns_disconnect(); +client_connect(string hostname, int port) { + client_disconnect(); if (hostname.empty()) { hostname = pstats_host; @@ -410,12 +410,12 @@ ns_connect(string hostname, int port) { } //////////////////////////////////////////////////////////////////// -// Function: PStatClient::ns_disconnect +// Function: PStatClient::client_disconnect // Access: Private // Description: The nonstatic implementation of disconnect(). //////////////////////////////////////////////////////////////////// void PStatClient:: -ns_disconnect() { +client_disconnect() { if (_is_connected) { _reader.remove_connection(_tcp_connection); close_connection(_tcp_connection); @@ -451,15 +451,35 @@ ns_disconnect() { } //////////////////////////////////////////////////////////////////// -// Function: PStatClient::ns_is_connected +// Function: PStatClient::client_is_connected // Access: Public // Description: The nonstatic implementation of is_connected(). //////////////////////////////////////////////////////////////////// bool PStatClient:: -ns_is_connected() const { +client_is_connected() const { return _is_connected; } +//////////////////////////////////////////////////////////////////// +// Function: PStatClient::is_active +// Access: Private +// Description: Returns true if the indicated collector/thread +// combination is active, and we are transmitting stats +// data, or false otherwise. +// +// Normally you would not use this interface directly; +// instead, call PStatCollector::is_active(). +//////////////////////////////////////////////////////////////////// +bool PStatClient:: +is_active(int collector_index, int thread_index) const { + nassertr(collector_index >= 0 && collector_index < (int)_collectors.size(), false); + nassertr(thread_index >= 0 && thread_index < (int)_threads.size(), false); + + return (_is_connected && + _collectors[collector_index]._def->_is_active && + _threads[thread_index]._is_active); +} + //////////////////////////////////////////////////////////////////// // Function: PStatClient::start_collector // Access: Private diff --git a/panda/src/pstatclient/pStatClient.h b/panda/src/pstatclient/pStatClient.h index 04368209b8..c1dc203d49 100644 --- a/panda/src/pstatclient/pStatClient.h +++ b/panda/src/pstatclient/pStatClient.h @@ -31,6 +31,14 @@ class PStatThread; // Description : Manages the communications to report statistics via a // network connection to a remote PStatServer. // +// Normally, there is only one PStatClient in the world, +// although it is possible to have multiple PStatClients +// if extraordinary circumstances require in. Since +// each PStatCollector registers itself with the +// PStatClient when it is created, having multiple +// PStatClients requires special care when constructing +// the various PStatCollectors. +// // If DO_PSTATS is not defined, we don't want to use // stats at all. This class is therefore defined as a // stub class. @@ -59,23 +67,26 @@ public: const ClockObject &get_clock() const; PStatThread get_main_thread() const; - static void main_tick(); - static PStatClient *get_global_pstats(); - PUBLISHED: INLINE static bool connect(const string &hostname = string(), int port = -1); INLINE static void disconnect(); INLINE static bool is_connected(); -private: - bool ns_connect(string hostname, int port); - void ns_disconnect(); - bool ns_is_connected() const; +public: + static void main_tick(); + static PStatClient *get_global_pstats(); + bool client_connect(string hostname, int port); + void client_disconnect(); + bool client_is_connected() const; + +private: PStatCollector make_collector_with_relname(int parent_index, string relname); PStatCollector make_collector_with_name(int parent_index, const string &name); PStatThread make_thread(const string &name); + bool is_active(int collector_index, int thread_index) const; + void start(int collector_index, int thread_index, float as_of); void stop(int collector_index, int thread_index, float as_of); diff --git a/panda/src/pstatclient/pStatCollector.I b/panda/src/pstatclient/pStatCollector.I index ef2a923e5e..06c01fd165 100644 --- a/panda/src/pstatclient/pStatCollector.I +++ b/panda/src/pstatclient/pStatCollector.I @@ -112,6 +112,30 @@ operator = (const PStatCollector ©) { _index = copy._index; } +//////////////////////////////////////////////////////////////////// +// Function: PStatCollector::is_active +// Access: Public +// Description: Returns true if this particular collector is active +// on the default thread, and we are currently +// transmitting PStats data. +//////////////////////////////////////////////////////////////////// +INLINE bool PStatCollector:: +is_active() { + return _client->is_active(_index, 0); +} + +//////////////////////////////////////////////////////////////////// +// Function: PStatCollector::is_active +// Access: Public +// Description: Returns true if this particular collector is active +// on the indicated thread, and we are currently +// transmitting PStats data. +//////////////////////////////////////////////////////////////////// +INLINE bool PStatCollector:: +is_active(const PStatThread &thread) { + return _client->is_active(_index, thread._index); +} + //////////////////////////////////////////////////////////////////// // Function: PStatCollector::start // Access: Public diff --git a/panda/src/pstatclient/pStatCollector.h b/panda/src/pstatclient/pStatCollector.h index cd161ffb92..998d7da03e 100644 --- a/panda/src/pstatclient/pStatCollector.h +++ b/panda/src/pstatclient/pStatCollector.h @@ -53,6 +53,9 @@ public: INLINE PStatCollector(const PStatCollector ©); INLINE void operator = (const PStatCollector ©); + INLINE bool is_active(); + INLINE bool is_active(const PStatThread &thread); + INLINE void start(); INLINE void start(const PStatThread &thread); INLINE void start(const PStatThread &thread, float as_of); @@ -87,6 +90,9 @@ public: const RGBColorf & = RGBColorf::zero(), int = -1) { } + INLINE bool is_active() { return false; } + INLINE bool is_active(const PStatThread &) { return false; } + INLINE void start() { } INLINE void start(const PStatThread &) { } INLINE void start(const PStatThread &, float) { } diff --git a/panda/src/pstatclient/pStatProperties.cxx b/panda/src/pstatclient/pStatProperties.cxx index d2a8754b71..dc45f22794 100644 --- a/panda/src/pstatclient/pStatProperties.cxx +++ b/panda/src/pstatclient/pStatProperties.cxx @@ -108,10 +108,12 @@ static TimeCollectorProperties time_properties[] = { }; static LevelCollectorProperties level_properties[] = { - { 1, "Texture usage", { 1.0, 0.0, 0.0 }, "MB", 12, 1048576 }, - { 1, "Texture usage:Active", { 1.0, 1.0, 0.0 } }, + { 1, "Texture usage", { 1.0, 0.0, 0.5 }, "MB", 12, 1048576 }, + { 1, "Texture usage:Active", { 0.5, 1.0, 0.8 } }, { 1, "Texture memory", { 0.0, 0.0, 1.0 }, "MB", 12, 1048576 }, { 1, "Texture memory:In use", { 0.0, 1.0, 1.0 } }, + { 1, "Texture manager", { 1.0, 0.0, 0.0 }, "MB", 12, 1048576 }, + { 1, "Texture manager:Resident", { 1.0, 1.0, 0.0 } }, { 1, "Vertices", { 0.5, 0.2, 0.0 }, "K", 10, 1000 }, { 1, "Vertices:Other", { 0.2, 0.2, 0.2 } }, { 1, "Vertices:Triangles", { 0.8, 0.8, 0.8 } },