Panda3D
 All Classes Functions Variables Enumerations
bufferResidencyTracker.h
00001 // Filename: bufferResidencyTracker.h
00002 // Created by:  drose (16Mar06)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef BUFFERRESIDENCYTRACKER_H
00016 #define BUFFERRESIDENCYTRACKER_H
00017 
00018 #include "pandabase.h"
00019 #include "bufferContextChain.h"
00020 #include "pStatCollector.h"
00021 
00022 class BufferContext;
00023 
00024 ////////////////////////////////////////////////////////////////////
00025 //       Class : BufferResidencyTracker
00026 // Description : This class is used to keep track of the current state
00027 //               of all the BufferContexts for a particular graphics
00028 //               context: whether each one is active (rendered this
00029 //               frame) or inactive (not rendered this frame), and
00030 //               whether it is resident or nonresident in video
00031 //               memory.
00032 //
00033 //               The primary purpose of this class is to facilitate
00034 //               PStats reporting of video card memory usage.
00035 ////////////////////////////////////////////////////////////////////
00036 class EXPCL_PANDA_GOBJ BufferResidencyTracker {
00037 public:
00038   BufferResidencyTracker(const string &pgo_name, const string &type_name);
00039   ~BufferResidencyTracker();
00040 
00041   void begin_frame(Thread *current_thread);
00042   void end_frame(Thread *current_thread);
00043   void set_levels();
00044 
00045   INLINE BufferContextChain &get_inactive_nonresident();
00046   INLINE BufferContextChain &get_active_nonresident();
00047   INLINE BufferContextChain &get_inactive_resident();
00048   INLINE BufferContextChain &get_active_resident();
00049 
00050   void write(ostream &out, int indent_level) const;
00051 
00052 private:
00053   void move_inactive(BufferContextChain &inactive, BufferContextChain &active);
00054 
00055 private:
00056   enum State {
00057     // Individual bits.
00058     S_active   = 0x01,
00059     S_resident = 0x02,
00060 
00061     // Aggregate bits: unions of the above.
00062     S_inactive_nonresident = 0x00,
00063     S_active_nonresident   = 0x01,
00064     S_inactive_resident    = 0x02,
00065     S_active_resident      = 0x03,
00066 
00067     // The total number of different states.
00068     S_num_states = 4,
00069   };
00070 
00071   // One chain for each of the possible states, ordered as above.
00072   BufferContextChain _chains[S_num_states];
00073 
00074   // A couple of PStatCollectors just to organize names.
00075   static PStatCollector _gmem_collector;
00076   PStatCollector _pgo_collector;
00077 
00078   // One PStatCollector for each state.  These are ordered in reverse
00079   // order that we would like them to appear in the PStats graph.
00080   PStatCollector _active_resident_collector;
00081   PStatCollector _active_nonresident_collector;
00082   PStatCollector _inactive_resident_collector;
00083   PStatCollector _inactive_nonresident_collector;
00084 
00085   // The frame number currently considered "active".
00086   int _active_frame;
00087   friend class BufferContext;
00088 };
00089 
00090 #include "bufferResidencyTracker.I"
00091 
00092 #endif
 All Classes Functions Variables Enumerations