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