1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
#include "UnityPrefix.h"
#include "GfxDevice.h"
#include "GfxDeviceStats.h"
#include "Runtime/Graphics/Texture.h"
#include "Runtime/Input/TimeManager.h"
#if UNITY_IPHONE
#include <mach/mach_time.h>
#elif UNITY_ANDROID
#include <sys/time.h>
#endif
#include "Runtime/Profiler/MemoryProfiler.h"
GfxDeviceStats::GfxDeviceStats()
{
#if ENABLE_PROFILER
m_StatsEnabled = false; // off by default!
m_ClientFrameTime = 0.0f;
m_RenderFrameTime = 0.0f;
m_EnableStartTime = 0.0;
#endif
// just initialize to some sane values
SetScreenParams( 64, 64, 4, 4, 4, 0 );
m_Memory.renderTextureBytes = 0;
}
void GfxDeviceStats::StateStats::Reset()
{
renderTexture = 0;
vboUploads = 0;
vboUploadBytes = 0;
ibUploads = 0;
ibUploadBytes = 0;
}
void GfxDeviceStats::ClientStats::Reset()
{
shadowCasters = 0;
ABSOLUTE_TIME_INIT(cullingDt);
ABSOLUTE_TIME_INIT(clearDt);
}
void GfxDeviceStats::DrawStats::Reset()
{
calls = 0;
tris = 0;
trisSent = 0;
verts = 0;
batches = 0;
batchedCalls = 0;
batchedTris = 0;
batchedVerts = 0;
ABSOLUTE_TIME_INIT(dt);
ABSOLUTE_TIME_INIT(batchDt);
usedTextureCount = 0;
usedTextureBytes = 0;
#if ENABLE_PROFILER
usedTextures.clear();
#endif
}
void GfxDeviceStats::AccumulateUsedTextureUsage()
{
#if ENABLE_PROFILER
m_Draw.usedTextureCount += m_Draw.usedTextures.size();
#if ENABLE_MEM_PROFILER
for (GfxDeviceStats::DrawStats::TextureIDSet::const_iterator i=m_Draw.usedTextures.begin();i != m_Draw.usedTextures.end();i++)
m_Draw.usedTextureBytes += GetMemoryProfiler()->GetRelatedIDMemorySize(i->m_ID);
#endif
m_Draw.usedTextures.clear();
#endif
}
void GfxDeviceStats::ResetFrame()
{
m_Changes.Reset();
m_Draw.Reset();
m_Client.Reset();
#if ENABLE_PROFILER
m_ClientFrameTime = 0.0f;
m_RenderFrameTime = 0.0f;
#endif
}
void GfxDeviceStats::ResetClientStats()
{
m_Client.Reset();
m_ClientFrameTime = 0.0f;
}
#if ENABLE_PROFILER
void GfxDeviceStats::AddUsedTexture(TextureID tex)
{
CHECK_STATS_ENABLED
if(m_Draw.usedTextures.find(tex) == m_Draw.usedTextures.end())
m_Draw.usedTextures.insert(tex);
}
#endif
void GfxDeviceStats::SetScreenParams( int width, int height, int backbufferBPP, int frontbufferBPP, int depthBPP, int fsaa )
{
m_Memory.screenWidth = width;
m_Memory.screenHeight = height;
// can pass -1 for BPP params to keep current ones
if (frontbufferBPP >= 0)
m_Memory.screenFrontBPP = frontbufferBPP;
if (backbufferBPP >= 0)
m_Memory.screenBackBPP = backbufferBPP;
if (depthBPP >= 0)
m_Memory.screenDepthBPP = depthBPP;
if (fsaa >= 0)
m_Memory.screenFSAA = fsaa;
m_Memory.screenBytes = width * height * (std::max(m_Memory.screenFSAA,1) * (m_Memory.screenBackBPP + m_Memory.screenDepthBPP) + m_Memory.screenFrontBPP);
//printf_console("set screen params: %ix%i %ixAA mem=%.1fMB\n", width, height, fsaa, m_Memory.screenBytes/1024.0f/1024.0f);
}
void GfxDeviceStats::BeginFrameStats()
{
m_StatsEnabled = true;
m_EnableStartTime = GetTimeSinceStartup();
}
void GfxDeviceStats::EndClientFrameStats()
{
m_StatsEnabled = false;
m_ClientFrameTime += GetTimeSinceStartup() - m_EnableStartTime;
}
void GfxDeviceStats::EndRenderFrameStats()
{
m_StatsEnabled = false;
m_RenderFrameTime += GetTimeSinceStartup() - m_EnableStartTime;
}
void GfxDeviceStats::CopyAllDrawStats( const GfxDeviceStats& s )
{
m_Draw = s.m_Draw;
m_Changes = s.m_Changes;
m_RenderFrameTime = s.m_RenderFrameTime;
}
void GfxDeviceStats::CopyClientStats( const GfxDeviceStats& s )
{
m_Client = s.m_Client;
m_ClientFrameTime = s.m_ClientFrameTime;
}
#if UNITY_IPHONE || UNITY_ANDROID
ABSOLUTE_TIME GfxDeviceStats::GetHighResolutionAbsTime ()
{
#if UNITY_IPHONE
return mach_absolute_time ();
#elif UNITY_ANDROID
timespec ts;
clock_gettime (CLOCK_REALTIME, &ts);
long long nanosecs = ts.tv_sec;
nanosecs <<= 32;
nanosecs |= ts.tv_nsec;
return nanosecs;
#endif
}
#endif
|