Panda3D
bufferResidencyTracker.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file bufferResidencyTracker.h
10  * @author drose
11  * @date 2006-03-16
12  */
13 
14 #ifndef BUFFERRESIDENCYTRACKER_H
15 #define BUFFERRESIDENCYTRACKER_H
16 
17 #include "pandabase.h"
18 #include "bufferContextChain.h"
19 #include "pStatCollector.h"
20 
21 class BufferContext;
22 
23 /**
24  * This class is used to keep track of the current state of all the
25  * BufferContexts for a particular graphics context: whether each one is
26  * active (rendered this frame) or inactive (not rendered this frame), and
27  * whether it is resident or nonresident in video memory.
28  *
29  * The primary purpose of this class is to facilitate PStats reporting of
30  * video card memory usage.
31  */
32 class EXPCL_PANDA_GOBJ BufferResidencyTracker {
33 public:
34  BufferResidencyTracker(const std::string &pgo_name, const std::string &type_name);
36 
37  void begin_frame(Thread *current_thread);
38  void end_frame(Thread *current_thread);
39  void set_levels();
40 
41  INLINE BufferContextChain &get_inactive_nonresident();
42  INLINE BufferContextChain &get_active_nonresident();
43  INLINE BufferContextChain &get_inactive_resident();
44  INLINE BufferContextChain &get_active_resident();
45 
46  void write(std::ostream &out, int indent_level) const;
47 
48 private:
49  void move_inactive(BufferContextChain &inactive, BufferContextChain &active);
50 
51 private:
52  enum State {
53  // Individual bits.
54  S_active = 0x01,
55  S_resident = 0x02,
56 
57  // Aggregate bits: unions of the above.
58  S_inactive_nonresident = 0x00,
59  S_active_nonresident = 0x01,
60  S_inactive_resident = 0x02,
61  S_active_resident = 0x03,
62 
63  // The total number of different states.
64  S_num_states = 4,
65  };
66 
67  // One chain for each of the possible states, ordered as above.
68  BufferContextChain _chains[S_num_states];
69 
70  // A couple of PStatCollectors just to organize names.
71  static PStatCollector _gmem_collector;
72  PStatCollector _pgo_collector;
73 
74  // One PStatCollector for each state. These are ordered in reverse order
75  // that we would like them to appear in the PStats graph.
76  PStatCollector _active_resident_collector;
77  PStatCollector _active_nonresident_collector;
78  PStatCollector _inactive_resident_collector;
79  PStatCollector _inactive_nonresident_collector;
80 
81  // The frame number currently considered "active".
82  int _active_frame;
83  friend class BufferContext;
84 };
85 
86 #include "bufferResidencyTracker.I"
87 
88 #endif
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This class maintains a linked list of BufferContexts that might be allocated on the graphics card in ...
This is a base class for those kinds of SavedContexts that occupy an easily-measured (and substantial...
Definition: bufferContext.h:38
This class is used to keep track of the current state of all the BufferContexts for a particular grap...
A lightweight class that represents a single element that may be timed and/or counted via stats.
A thread; that is, a lightweight process.
Definition: thread.h:46
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.