DOOM-3-BFG

DOOM 3 BFG Edition
Log | Files | Refs

RenderLog.h (5748B)


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