Skip to content

Commit 25ab77d

Browse files
refactor(ww3d2): Simplify dx8wrapper's frame statistics with struct (#2507)
1 parent 2d13736 commit 25ab77d

4 files changed

Lines changed: 131 additions & 229 deletions

File tree

Generals/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp

Lines changed: 17 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ const int DEFAULT_BIT_DEPTH = 32;
8989
const int DEFAULT_TEXTURE_BIT_DEPTH = 16;
9090
const D3DMULTISAMPLE_TYPE DEFAULT_MSAA = D3DMULTISAMPLE_NONE;
9191

92+
DX8FrameStatistics DX8Wrapper::FrameStatistics;
93+
static DX8FrameStatistics LastFrameStatistics;
94+
9295
bool DX8Wrapper_IsWindowed = true;
9396

9497
// FPU_PRESERVE
@@ -146,15 +149,6 @@ IDirect3DSurface8 * DX8Wrapper::DefaultRenderTarget = nullptr;
146149
IDirect3DSurface8 * DX8Wrapper::DefaultDepthBuffer = nullptr;
147150
bool DX8Wrapper::IsRenderToTexture = false;
148151

149-
unsigned DX8Wrapper::matrix_changes = 0;
150-
unsigned DX8Wrapper::material_changes = 0;
151-
unsigned DX8Wrapper::vertex_buffer_changes = 0;
152-
unsigned DX8Wrapper::index_buffer_changes = 0;
153-
unsigned DX8Wrapper::light_changes = 0;
154-
unsigned DX8Wrapper::texture_changes = 0;
155-
unsigned DX8Wrapper::render_state_changes = 0;
156-
unsigned DX8Wrapper::texture_stage_state_changes = 0;
157-
unsigned DX8Wrapper::draw_calls = 0;
158152
unsigned DX8Wrapper::_MainThreadID = 0;
159153
bool DX8Wrapper::CurrentDX8LightEnables[4];
160154
bool DX8Wrapper::IsDeviceLost;
@@ -175,18 +169,6 @@ unsigned long DX8Wrapper::FrameCount = 0;
175169

176170
bool _DX8SingleThreaded = false;
177171

178-
unsigned number_of_DX8_calls = 0;
179-
static unsigned last_frame_matrix_changes = 0;
180-
static unsigned last_frame_material_changes = 0;
181-
static unsigned last_frame_vertex_buffer_changes = 0;
182-
static unsigned last_frame_index_buffer_changes = 0;
183-
static unsigned last_frame_light_changes = 0;
184-
static unsigned last_frame_texture_changes = 0;
185-
static unsigned last_frame_render_state_changes = 0;
186-
static unsigned last_frame_texture_stage_state_changes = 0;
187-
static unsigned last_frame_number_of_DX8_calls = 0;
188-
static unsigned last_frame_draw_calls = 0;
189-
190172
static D3DPRESENT_PARAMETERS _PresentParameters;
191173
static DynamicVectorClass<StringClass> _RenderDeviceNameTable;
192174
static DynamicVectorClass<StringClass> _RenderDeviceShortNameTable;
@@ -1527,67 +1509,25 @@ bool DX8Wrapper::Test_Z_Mode(D3DFORMAT colorbuffer,D3DFORMAT backbuffer, D3DFORM
15271509

15281510
void DX8Wrapper::Reset_Statistics()
15291511
{
1530-
matrix_changes = 0;
1531-
material_changes = 0;
1532-
vertex_buffer_changes = 0;
1533-
index_buffer_changes = 0;
1534-
light_changes = 0;
1535-
texture_changes = 0;
1536-
render_state_changes =0;
1537-
texture_stage_state_changes =0;
1538-
draw_calls =0;
1539-
1540-
number_of_DX8_calls = 0;
1541-
last_frame_matrix_changes = 0;
1542-
last_frame_material_changes = 0;
1543-
last_frame_vertex_buffer_changes = 0;
1544-
last_frame_index_buffer_changes = 0;
1545-
last_frame_light_changes = 0;
1546-
last_frame_texture_changes = 0;
1547-
last_frame_render_state_changes = 0;
1548-
last_frame_texture_stage_state_changes = 0;
1549-
last_frame_number_of_DX8_calls = 0;
1550-
last_frame_draw_calls =0;
1512+
FrameStatistics = DX8FrameStatistics();
1513+
LastFrameStatistics = DX8FrameStatistics();
15511514
}
15521515

15531516
void DX8Wrapper::Begin_Statistics()
15541517
{
1555-
matrix_changes=0;
1556-
material_changes=0;
1557-
vertex_buffer_changes=0;
1558-
index_buffer_changes=0;
1559-
light_changes=0;
1560-
texture_changes = 0;
1561-
render_state_changes =0;
1562-
texture_stage_state_changes =0;
1563-
number_of_DX8_calls=0;
1564-
draw_calls=0;
1518+
FrameStatistics = DX8FrameStatistics();
15651519
}
15661520

15671521
void DX8Wrapper::End_Statistics()
15681522
{
1569-
last_frame_matrix_changes=matrix_changes;
1570-
last_frame_material_changes=material_changes;
1571-
last_frame_vertex_buffer_changes=vertex_buffer_changes;
1572-
last_frame_index_buffer_changes=index_buffer_changes;
1573-
last_frame_light_changes=light_changes;
1574-
last_frame_texture_changes = texture_changes;
1575-
last_frame_render_state_changes = render_state_changes;
1576-
last_frame_texture_stage_state_changes = texture_stage_state_changes;
1577-
last_frame_number_of_DX8_calls=number_of_DX8_calls;
1578-
last_frame_draw_calls=draw_calls;
1523+
LastFrameStatistics = FrameStatistics;
1524+
}
1525+
1526+
const DX8FrameStatistics& DX8Wrapper::Get_Last_Frame_Statistics()
1527+
{
1528+
return LastFrameStatistics;
15791529
}
15801530

1581-
unsigned DX8Wrapper::Get_Last_Frame_Matrix_Changes() { return last_frame_matrix_changes; }
1582-
unsigned DX8Wrapper::Get_Last_Frame_Material_Changes() { return last_frame_material_changes; }
1583-
unsigned DX8Wrapper::Get_Last_Frame_Vertex_Buffer_Changes() { return last_frame_vertex_buffer_changes; }
1584-
unsigned DX8Wrapper::Get_Last_Frame_Index_Buffer_Changes() { return last_frame_index_buffer_changes; }
1585-
unsigned DX8Wrapper::Get_Last_Frame_Light_Changes() { return last_frame_light_changes; }
1586-
unsigned DX8Wrapper::Get_Last_Frame_Texture_Changes() { return last_frame_texture_changes; }
1587-
unsigned DX8Wrapper::Get_Last_Frame_Render_State_Changes() { return last_frame_render_state_changes; }
1588-
unsigned DX8Wrapper::Get_Last_Frame_Texture_Stage_State_Changes() { return last_frame_texture_stage_state_changes; }
1589-
unsigned DX8Wrapper::Get_Last_Frame_DX8_Calls() { return last_frame_number_of_DX8_calls; }
1590-
unsigned DX8Wrapper::Get_Last_Frame_Draw_Calls() { return last_frame_draw_calls; }
15911531
unsigned long DX8Wrapper::Get_FrameCount() {return FrameCount;}
15921532

15931533
void DX8_Assert()
@@ -1624,7 +1564,7 @@ void DX8Wrapper::End_Scene(bool flip_frames)
16241564
hr=_Get_D3D_Device8()->Present(nullptr, nullptr, nullptr, nullptr);
16251565
}
16261566

1627-
number_of_DX8_calls++;
1567+
DX8_RECORD_DX8_CALLS();
16281568

16291569
if (SUCCEEDED(hr)) {
16301570
#ifdef EXTENDED_STATS
@@ -2982,7 +2922,7 @@ DX8Wrapper::Create_Render_Target (int width, int height, WW3DFormat format)
29822922
{
29832923
DX8_THREAD_ASSERT();
29842924
DX8_Assert();
2985-
number_of_DX8_calls++;
2925+
DX8_RECORD_DX8_CALLS();
29862926

29872927
// Use the current display format if format isn't specified
29882928
if (format==WW3D_FORMAT_UNKNOWN) {
@@ -3048,7 +2988,7 @@ void DX8Wrapper::Create_Render_Target
30482988
{
30492989
DX8_THREAD_ASSERT();
30502990
DX8_Assert();
3051-
number_of_DX8_calls++;
2991+
DX8_RECORD_DX8_CALLS();
30522992

30532993
// Use the current display format if format isn't specified
30542994
if (format==WW3D_FORMAT_UNKNOWN)
@@ -3449,7 +3389,7 @@ void DX8Wrapper::Flush_DX8_Resource_Manager(unsigned int bytes)
34493389
unsigned int DX8Wrapper::Get_Free_Texture_RAM()
34503390
{
34513391
DX8_Assert();
3452-
number_of_DX8_calls++;
3392+
DX8_RECORD_DX8_CALLS();
34533393
return DX8Wrapper::_Get_D3D_Device8()->GetAvailableTextureMem();
34543394
}
34553395

@@ -3465,7 +3405,7 @@ void DX8Wrapper::Set_Gamma(float gamma,float bright,float contrast,bool calibrat
34653405
float oo_gamma=1.0f/gamma;
34663406

34673407
DX8_Assert();
3468-
number_of_DX8_calls++;
3408+
DX8_RECORD_DX8_CALLS();
34693409

34703410
DWORD flag=(calibrate?D3DSGR_CALIBRATE:D3DSGR_NO_CALIBRATION);
34713411

Generals/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.h

Lines changed: 48 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,45 @@ class TextureClass;
9191
class LightClass;
9292
class SurfaceClass;
9393

94-
#define DX8_RECORD_MATRIX_CHANGE() matrix_changes++
95-
#define DX8_RECORD_MATERIAL_CHANGE() material_changes++
96-
#define DX8_RECORD_VERTEX_BUFFER_CHANGE() vertex_buffer_changes++
97-
#define DX8_RECORD_INDEX_BUFFER_CHANGE() index_buffer_changes++
98-
#define DX8_RECORD_LIGHT_CHANGE() light_changes++
99-
#define DX8_RECORD_TEXTURE_CHANGE() texture_changes++
100-
#define DX8_RECORD_RENDER_STATE_CHANGE() render_state_changes++
101-
#define DX8_RECORD_TEXTURE_STAGE_STATE_CHANGE() texture_stage_state_changes++
102-
#define DX8_RECORD_DRAW_CALLS() draw_calls++
103-
104-
extern unsigned number_of_DX8_calls;
94+
struct DX8FrameStatistics
95+
{
96+
DX8FrameStatistics() :
97+
matrix_changes(0),
98+
material_changes(0),
99+
vertex_buffer_changes(0),
100+
index_buffer_changes(0),
101+
light_changes(0),
102+
texture_changes(0),
103+
render_state_changes(0),
104+
texture_stage_state_changes(0),
105+
dx8_calls(0),
106+
draw_calls(0)
107+
{
108+
}
109+
110+
unsigned matrix_changes;
111+
unsigned material_changes;
112+
unsigned vertex_buffer_changes;
113+
unsigned index_buffer_changes;
114+
unsigned light_changes;
115+
unsigned texture_changes;
116+
unsigned render_state_changes;
117+
unsigned texture_stage_state_changes;
118+
unsigned dx8_calls;
119+
unsigned draw_calls;
120+
};
121+
122+
#define DX8_RECORD_MATRIX_CHANGE() FrameStatistics.matrix_changes++
123+
#define DX8_RECORD_MATERIAL_CHANGE() FrameStatistics.material_changes++
124+
#define DX8_RECORD_VERTEX_BUFFER_CHANGE() FrameStatistics.vertex_buffer_changes++
125+
#define DX8_RECORD_INDEX_BUFFER_CHANGE() FrameStatistics.index_buffer_changes++
126+
#define DX8_RECORD_LIGHT_CHANGE() FrameStatistics.light_changes++
127+
#define DX8_RECORD_TEXTURE_CHANGE() FrameStatistics.texture_changes++
128+
#define DX8_RECORD_RENDER_STATE_CHANGE() FrameStatistics.render_state_changes++
129+
#define DX8_RECORD_TEXTURE_STAGE_STATE_CHANGE() FrameStatistics.texture_stage_state_changes++
130+
#define DX8_RECORD_DX8_CALLS() FrameStatistics.dx8_calls++
131+
#define DX8_RECORD_DRAW_CALLS() FrameStatistics.draw_calls++
132+
105133
extern bool _DX8SingleThreaded;
106134

107135
void DX8_Assert();
@@ -114,14 +142,14 @@ WWINLINE void DX8_ErrorCode(unsigned res)
114142
}
115143

116144
#ifdef WWDEBUG
117-
#define DX8CALL_HRES(x,res) DX8_Assert(); res = DX8Wrapper::_Get_D3D_Device8()->x; DX8_ErrorCode(res); number_of_DX8_calls++;
118-
#define DX8CALL(x) DX8_Assert(); DX8_ErrorCode(DX8Wrapper::_Get_D3D_Device8()->x); number_of_DX8_calls++;
119-
#define DX8CALL_D3D(x) DX8_Assert(); DX8_ErrorCode(DX8Wrapper::_Get_D3D8()->x); number_of_DX8_calls++;
145+
#define DX8CALL_HRES(x,res) DX8_Assert(); res = DX8Wrapper::_Get_D3D_Device8()->x; DX8_ErrorCode(res); DX8Wrapper::Increment_DX8_CallCount();
146+
#define DX8CALL(x) DX8_Assert(); DX8_ErrorCode(DX8Wrapper::_Get_D3D_Device8()->x); DX8Wrapper::Increment_DX8_CallCount();
147+
#define DX8CALL_D3D(x) DX8_Assert(); DX8_ErrorCode(DX8Wrapper::_Get_D3D8()->x); DX8Wrapper::Increment_DX8_CallCount();
120148
#define DX8_THREAD_ASSERT() if (_DX8SingleThreaded) { WWASSERT_PRINT(DX8Wrapper::_Get_Main_Thread_ID()==ThreadClass::_Get_Current_Thread_ID(),"DX8Wrapper::DX8 calls must be called from the main thread!"); }
121149
#else
122-
#define DX8CALL_HRES(x,res) res = DX8Wrapper::_Get_D3D_Device8()->x; number_of_DX8_calls++;
123-
#define DX8CALL(x) DX8Wrapper::_Get_D3D_Device8()->x; number_of_DX8_calls++;
124-
#define DX8CALL_D3D(x) DX8Wrapper::_Get_D3D8()->x; number_of_DX8_calls++;
150+
#define DX8CALL_HRES(x,res) res = DX8Wrapper::_Get_D3D_Device8()->x; DX8Wrapper::Increment_DX8_CallCount();
151+
#define DX8CALL(x) DX8Wrapper::_Get_D3D_Device8()->x; DX8Wrapper::Increment_DX8_CallCount();
152+
#define DX8CALL_D3D(x) DX8Wrapper::_Get_D3D8()->x; DX8Wrapper::Increment_DX8_CallCount();
125153
#define DX8_THREAD_ASSERT() ;
126154
#endif
127155

@@ -407,18 +435,9 @@ class DX8Wrapper
407435
*/
408436
static void Begin_Statistics();
409437
static void End_Statistics();
410-
static unsigned Get_Last_Frame_Matrix_Changes();
411-
static unsigned Get_Last_Frame_Material_Changes();
412-
static unsigned Get_Last_Frame_Vertex_Buffer_Changes();
413-
static unsigned Get_Last_Frame_Index_Buffer_Changes();
414-
static unsigned Get_Last_Frame_Light_Changes();
415-
static unsigned Get_Last_Frame_Texture_Changes();
416-
static unsigned Get_Last_Frame_Render_State_Changes();
417-
static unsigned Get_Last_Frame_Texture_Stage_State_Changes();
418-
static unsigned Get_Last_Frame_DX8_Calls();
419-
static unsigned Get_Last_Frame_Draw_Calls();
420-
438+
static const DX8FrameStatistics& Get_Last_Frame_Statistics();
421439
static unsigned long Get_FrameCount();
440+
static void Increment_DX8_CallCount() { DX8_RECORD_DX8_CALLS(); }
422441

423442
// Needed by shader class
424443
static bool Get_Fog_Enable() { return FogEnable; }
@@ -651,15 +670,7 @@ class DX8Wrapper
651670
static bool FogEnable;
652671
static D3DCOLOR FogColor;
653672

654-
static unsigned matrix_changes;
655-
static unsigned material_changes;
656-
static unsigned vertex_buffer_changes;
657-
static unsigned index_buffer_changes;
658-
static unsigned light_changes;
659-
static unsigned texture_changes;
660-
static unsigned render_state_changes;
661-
static unsigned texture_stage_state_changes;
662-
static unsigned draw_calls;
673+
static DX8FrameStatistics FrameStatistics;
663674
static bool CurrentDX8LightEnables[4];
664675

665676
static unsigned long FrameCount;

0 commit comments

Comments
 (0)