1 /*---------------------------------------------------------------------------* 2 Project: NintendoWare 3 File: SmPerf.h 4 5 Copyright (C)2009-2011 Nintendo/HAL Laboratory, Inc. All rights reserved. 6 7 These coded instructions, statements, and computer programs contain proprietary 8 information of Nintendo and/or its licensed developers and are protected by 9 national and international copyright laws. They may not be disclosed to third 10 parties or copied or duplicated in any form, in whole or in part, without the 11 prior written consent of Nintendo. 12 13 The content herein is highly confidential and should be handled accordingly. 14 15 $Revision: $ 16 *---------------------------------------------------------------------------*/ 17 #ifndef SM_PERF_H_ 18 #define SM_PERF_H_ 19 20 //#include <nw/demo.h> 21 22 #include "../include/SmPrimitive.h" 23 #include "../include/SmCommandUtility.h" 24 25 //------------------------------------------------------------------------------ 26 // 27 //! @brief �R�X�g 28 struct Cost 29 { 30 uint constId; 31 char costName[64]; 32 s64 costMicro; 33 s64 costStart; 34 s64 costEnd; 35 36 uint gpuStart; 37 uint gpuEnd; 38 39 nw::ut::Color8 costColor; 40 initCost41 void init() 42 { 43 constId = 0; 44 std::memset( costName, 32, 0 ); 45 costMicro = 0; 46 costStart = 0; 47 costEnd = 0; 48 costColor = 0; 49 gpuStart = 0; 50 gpuEnd = 0; 51 } 52 }; 53 54 typedef nw::ut::FixedSizeArray<Cost, 32> CostArray; 55 56 //------------------------------------------------------------------------------ 57 // �����R�X�g���v������N���X 58 class SmPerf 59 { 60 public: SmPerf()61 SmPerf() 62 : m_CostArrayFlip( 0 ), 63 m_CurrentCost( -1 ) 64 { 65 m_CostArray[0].clear(); 66 m_CostArray[1].clear(); 67 } 68 ~SmPerf()69 ~SmPerf() 70 { 71 m_CostArray[0].clear(); 72 m_CostArray[1].clear(); 73 } 74 75 // �v�����J�n���� Begin(const char * costName,u32 costColor)76 virtual void Begin( const char* costName, u32 costColor ) 77 { 78 NW_UNUSED_VARIABLE(costName); 79 NW_UNUSED_VARIABLE(costColor); 80 } 81 82 // �v�����I������ End()83 virtual void End(){} 84 85 // ���Z�b�g���� 86 // �t���[���̏I���ō��t���[���̌��ʂ����Z�b�g���� Reset()87 virtual void Reset() 88 { 89 // �t���b�v���� 90 if ( m_CostArrayFlip ) 91 { 92 m_CostArrayFlip = 0; 93 } 94 else 95 { 96 m_CostArrayFlip = 1; 97 } 98 99 m_CostArray[m_CostArrayFlip].clear(); 100 m_CurrentCost = -1; 101 } 102 103 104 // ���݂̃^�C�����擾���� GetTime()105 s64 GetTime() 106 { 107 return nn::os::Tick::GetSystemCurrent().ToTimeSpan().GetMicroSeconds(); 108 } 109 110 111 // ���ݓo�^����Ă���R�X�g�����擾���� GetCostCount()112 uint GetCostCount() 113 { 114 if ( m_CostArrayFlip ) 115 { 116 return m_CostArray[0].size(); 117 } 118 else 119 { 120 return m_CostArray[1].size(); 121 } 122 } 123 124 125 // �o�^����Ă���R�X�g�����擾���� GetCostName(uint costNo)126 const char* GetCostName( uint costNo ) 127 { 128 if ( m_CostArrayFlip ) 129 { 130 return m_CostArray[0][costNo].costName; 131 } 132 else 133 { 134 return m_CostArray[1][costNo].costName; 135 } 136 } 137 138 139 // �o�^����Ă���R�X�g�J���[���擾���� GetCostColor(uint costNo)140 nw::ut::Color8 GetCostColor( uint costNo ) 141 { 142 if ( m_CostArrayFlip ) 143 { 144 return m_CostArray[0][costNo].costColor; 145 } 146 else 147 { 148 return m_CostArray[1][costNo].costColor; 149 } 150 } 151 152 153 // �o�^����Ă���R�X�g(msec)���擾���� GetCost(uint costNo)154 virtual f32 GetCost( uint costNo ) 155 { 156 f32 millisec = 0.f; 157 158 if ( m_CostArrayFlip ) 159 { 160 millisec = static_cast<f32>(m_CostArray[0][costNo].costMicro) / 1000.f; 161 } 162 else 163 { 164 millisec = static_cast<f32>(m_CostArray[1][costNo].costMicro) / 1000.f; 165 } 166 167 return millisec; 168 } 169 170 protected: 171 CostArray m_CostArray[2]; 172 uint m_CostArrayFlip; 173 s32 m_CurrentCost; 174 }; 175 176 177 178 179 //------------------------------------------------------------------------------ 180 // CPU�����R�X�g���v������N���X 181 class SmCpuPerf : public SmPerf 182 { 183 public: 184 // �R���X�g���N�^ 185 SmCpuPerf(); 186 187 // �v�����J�n���� 188 virtual void Begin( const char* costName, u32 costColor ); 189 190 // �v�����I������ 191 virtual void End(); 192 }; 193 194 195 //------------------------------------------------------------------------------ 196 // GPU�����R�X�g���v������N���X 197 class SmGpuPerf : public SmPerf 198 { 199 public: 200 // �R���X�g���N�^ 201 SmGpuPerf(); 202 203 // �f�X�g���N�^ 204 ~SmGpuPerf(); 205 206 // �v�����J�n���� 207 virtual void Begin( const char* costName, u32 costColor ); 208 209 // �v�����I������ 210 virtual void End(); 211 212 // �o�^����R�[���o�b�N���ł� 213 void Invoke(GLint id); 214 static void Callback(GLint id); 215 216 // ���Z�b�g���� 217 virtual void Reset(); 218 219 // �o�^����Ă���R�X�g(msec)���擾���� 220 virtual f32 GetCost( uint costNo ); 221 222 private: 223 f32 m_MillisecCost; 224 uint m_StartReqCount; 225 uint m_EndReqCount; 226 uint m_CurrentReqCount; 227 }; 228 229 230 //------------------------------------------------------------------------------ 231 // �R�X�g���v�����ʂ�`�悷��N���X 232 class SmPerfDrawer : public SmBase 233 { 234 // 1frame �̕� 235 #define PERF_ONE_FRAME_WIDTH (160.f) 236 237 public: 238 SmPerfDrawer(); 239 ~SmPerfDrawer(); 240 241 void Render( SmPerf* cpuPerf, SmPerf* gpuPerf ); 242 void RenderBar(); 243 244 private: 245 Sm2DDynamicPrimPC m_PerfBar; 246 Sm2DPrimPC* m_pPerfBarSplit; 247 SmCommandReuser m_PerfBarSplitCmd; 248 }; 249 250 251 #endif // SM_PERF_H_ 252