RenderLog.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /*
  2. ===========================================================================
  3. Doom 3 BFG Edition GPL Source Code
  4. Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
  6. Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #ifndef __RENDERLOG_H__
  21. #define __RENDERLOG_H__
  22. /*
  23. ================================================================================================
  24. Contains the RenderLog declaration.
  25. ================================================================================================
  26. */
  27. #if defined(ID_RETAIL) && !defined(ID_RETAIL_INTERNAL)
  28. #define STUB_RENDER_LOG
  29. #endif
  30. enum renderLogMainBlock_t {
  31. MRB_NONE,
  32. MRB_BEGIN_DRAWING_VIEW,
  33. MRB_FILL_DEPTH_BUFFER,
  34. MRB_DRAW_INTERACTIONS,
  35. MRB_DRAW_SHADER_PASSES,
  36. MRB_FOG_ALL_LIGHTS,
  37. MRB_DRAW_SHADER_PASSES_POST,
  38. MRB_DRAW_DEBUG_TOOLS,
  39. MRB_CAPTURE_COLORBUFFER,
  40. MRB_POSTPROCESS,
  41. MRB_GPU_SYNC,
  42. MRB_END_FRAME,
  43. MRB_BINK_FRAME,
  44. MRB_BINK_NEXT_FRAME,
  45. MRB_TOTAL,
  46. MRB_MAX
  47. };
  48. // these are used to make sure each Indent() is properly paired with an Outdent()
  49. enum renderLogIndentLabel_t {
  50. RENDER_LOG_INDENT_DEFAULT,
  51. RENDER_LOG_INDENT_MAIN_BLOCK,
  52. RENDER_LOG_INDENT_BLOCK,
  53. RENDER_LOG_INDENT_TEST
  54. };
  55. // using this macro avoids printf parameter overhead if the renderlog isn't active
  56. #define RENDERLOG_PRINTF( ... ) if ( renderLog.activeLevel ) renderLog.Printf( __VA_ARGS__ );
  57. #if !defined( STUB_RENDER_LOG )
  58. /*
  59. ================================================
  60. idRenderLog contains block-based performance-tuning information. It combines
  61. logfile, and msec accumulation code.
  62. ================================================
  63. */
  64. class idRenderLog {
  65. public:
  66. idRenderLog();
  67. void StartFrame();
  68. void EndFrame();
  69. void Close();
  70. int Active() { return activeLevel; } // returns greater than 1 for more detailed logging
  71. // The label must be a constant string literal and may not point to a temporary.
  72. void OpenMainBlock( renderLogMainBlock_t block );
  73. void CloseMainBlock();
  74. void OpenBlock( const char * label );
  75. void CloseBlock();
  76. void Indent( renderLogIndentLabel_t label = RENDER_LOG_INDENT_DEFAULT );
  77. void Outdent( renderLogIndentLabel_t label = RENDER_LOG_INDENT_DEFAULT );
  78. void Printf( VERIFY_FORMAT_STRING const char *fmt, ... );
  79. static const int MAX_LOG_LEVELS = 20;
  80. int activeLevel;
  81. renderLogIndentLabel_t indentLabel[MAX_LOG_LEVELS];
  82. char indentString[MAX_LOG_LEVELS * 4];
  83. int indentLevel;
  84. const char * lastLabel;
  85. renderLogMainBlock_t lastMainBlock;
  86. idFile* logFile;
  87. struct logStats_t {
  88. uint64 startTiming;
  89. int startDraws;
  90. int startIndexes;
  91. };
  92. uint64 frameStartTime;
  93. uint64 closeBlockTime;
  94. logStats_t logStats[MAX_LOG_LEVELS];
  95. int logLevel;
  96. void LogOpenBlock( renderLogIndentLabel_t label, const char * fmt, va_list args );
  97. void LogCloseBlock( renderLogIndentLabel_t label );
  98. };
  99. /*
  100. ========================
  101. idRenderLog::Indent
  102. ========================
  103. */
  104. ID_INLINE void idRenderLog::Indent( renderLogIndentLabel_t label ) {
  105. if ( logFile != NULL ) {
  106. indentLabel[indentLevel] = label;
  107. indentLevel++;
  108. for ( int i = 4; i > 0; i-- ) {
  109. indentString[indentLevel * 4 - i] = ' ';
  110. }
  111. indentString[indentLevel * 4] = '\0';
  112. }
  113. }
  114. /*
  115. ========================
  116. idRenderLog::Outdent
  117. ========================
  118. */
  119. ID_INLINE void idRenderLog::Outdent( renderLogIndentLabel_t label ) {
  120. if ( logFile != NULL && indentLevel > 0 ) {
  121. indentLevel--;
  122. assert( indentLabel[indentLevel] == label ); // indent and outdent out of sync ?
  123. indentString[indentLevel * 4] = '\0';
  124. }
  125. }
  126. #else // !STUB_RENDER_LOG
  127. /*
  128. ================================================
  129. idRenderLog stubbed version for the SPUs and high
  130. performance rendering in retail builds.
  131. ================================================
  132. */
  133. class idRenderLog {
  134. public:
  135. idRenderLog() {}
  136. void StartFrame() {}
  137. void EndFrame() {}
  138. void Close() {}
  139. int Active() { return 0; }
  140. void OpenBlock( const char * label );
  141. void CloseBlock();
  142. void OpenMainBlock( renderLogMainBlock_t block ){}
  143. void CloseMainBlock(){}
  144. void Indent( renderLogIndentLabel_t label = RENDER_LOG_INDENT_DEFAULT ) {}
  145. void Outdent( renderLogIndentLabel_t label = RENDER_LOG_INDENT_DEFAULT ) {}
  146. void Printf( VERIFY_FORMAT_STRING const char *fmt, ... ) {}
  147. int activeLevel;
  148. };
  149. #endif // !STUB_RENDER_LOG
  150. extern idRenderLog renderLog;
  151. #endif // !__RENDERLOG_H__