From feff330cb2214b96046aa7a65af51af87c868095 Mon Sep 17 00:00:00 2001 From: stm <14291421+stephanmeesters@users.noreply.github.com> Date: Mon, 30 Mar 2026 13:20:45 +0200 Subject: [PATCH 1/8] chore(ww3d2): Remove frame statistics getters --- .../Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp | 10 ---------- .../Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.h | 11 ----------- 2 files changed, 21 deletions(-) diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp index f7c0982646..1ffc0bb6cc 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp @@ -1700,16 +1700,6 @@ void DX8Wrapper::End_Statistics() last_frame_draw_calls=draw_calls; } -unsigned DX8Wrapper::Get_Last_Frame_Matrix_Changes() { return last_frame_matrix_changes; } -unsigned DX8Wrapper::Get_Last_Frame_Material_Changes() { return last_frame_material_changes; } -unsigned DX8Wrapper::Get_Last_Frame_Vertex_Buffer_Changes() { return last_frame_vertex_buffer_changes; } -unsigned DX8Wrapper::Get_Last_Frame_Index_Buffer_Changes() { return last_frame_index_buffer_changes; } -unsigned DX8Wrapper::Get_Last_Frame_Light_Changes() { return last_frame_light_changes; } -unsigned DX8Wrapper::Get_Last_Frame_Texture_Changes() { return last_frame_texture_changes; } -unsigned DX8Wrapper::Get_Last_Frame_Render_State_Changes() { return last_frame_render_state_changes; } -unsigned DX8Wrapper::Get_Last_Frame_Texture_Stage_State_Changes() { return last_frame_texture_stage_state_changes; } -unsigned DX8Wrapper::Get_Last_Frame_DX8_Calls() { return last_frame_number_of_DX8_calls; } -unsigned DX8Wrapper::Get_Last_Frame_Draw_Calls() { return last_frame_draw_calls; } unsigned long DX8Wrapper::Get_FrameCount() {return FrameCount;} void DX8_Assert() diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.h index adcbe2cd8e..2f3f85906c 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.h +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.h @@ -413,19 +413,8 @@ class DX8Wrapper */ static void Begin_Statistics(); static void End_Statistics(); - static unsigned Get_Last_Frame_Matrix_Changes(); - static unsigned Get_Last_Frame_Material_Changes(); - static unsigned Get_Last_Frame_Vertex_Buffer_Changes(); - static unsigned Get_Last_Frame_Index_Buffer_Changes(); - static unsigned Get_Last_Frame_Light_Changes(); - static unsigned Get_Last_Frame_Texture_Changes(); - static unsigned Get_Last_Frame_Render_State_Changes(); - static unsigned Get_Last_Frame_Texture_Stage_State_Changes(); - static unsigned Get_Last_Frame_DX8_Calls(); - static unsigned Get_Last_Frame_Draw_Calls(); static unsigned long Get_FrameCount(); - // Needed by shader class static bool Get_Fog_Enable() { return FogEnable; } static D3DCOLOR Get_Fog_Color() { return FogColor; } From 43ca0232356d076742c8911f65d28f79e12615ea Mon Sep 17 00:00:00 2001 From: stm <14291421+stephanmeesters@users.noreply.github.com> Date: Mon, 30 Mar 2026 20:47:10 +0200 Subject: [PATCH 2/8] refactor(ww3d2): Add statistics struct --- .../Source/WWVegas/WW3D2/dx8wrapper.cpp | 16 ++++++++++++++++ .../Libraries/Source/WWVegas/WW3D2/dx8wrapper.h | 17 ++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp index 1ffc0bb6cc..04bc3dafad 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp @@ -1700,6 +1700,22 @@ void DX8Wrapper::End_Statistics() last_frame_draw_calls=draw_calls; } +DX8FrameStatistics DX8Wrapper::Get_Last_Frame_Statistics() +{ + DX8FrameStatistics stats; + stats.matrix_changes = last_frame_matrix_changes; + stats.material_changes = last_frame_material_changes; + stats.vertex_buffer_changes = last_frame_vertex_buffer_changes; + stats.index_buffer_changes = last_frame_index_buffer_changes; + stats.light_changes = last_frame_light_changes; + stats.texture_changes = last_frame_texture_changes; + stats.render_state_changes = last_frame_render_state_changes; + stats.texture_stage_state_changes = last_frame_texture_stage_state_changes; + stats.dx8_calls = last_frame_number_of_DX8_calls; + stats.draw_calls = last_frame_draw_calls; + return stats; +} + unsigned long DX8Wrapper::Get_FrameCount() {return FrameCount;} void DX8_Assert() diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.h index 2f3f85906c..7e3269b6b4 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.h +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.h @@ -94,6 +94,20 @@ class TextureClass; class LightClass; class SurfaceClass; +struct DX8FrameStatistics +{ + unsigned matrix_changes; + unsigned material_changes; + unsigned vertex_buffer_changes; + unsigned index_buffer_changes; + unsigned light_changes; + unsigned texture_changes; + unsigned render_state_changes; + unsigned texture_stage_state_changes; + unsigned dx8_calls; + unsigned draw_calls; +}; + #define DX8_RECORD_MATRIX_CHANGE() matrix_changes++ #define DX8_RECORD_MATERIAL_CHANGE() material_changes++ #define DX8_RECORD_VERTEX_BUFFER_CHANGE() vertex_buffer_changes++ @@ -413,8 +427,9 @@ class DX8Wrapper */ static void Begin_Statistics(); static void End_Statistics(); - + static DX8FrameStatistics Get_Last_Frame_Statistics(); static unsigned long Get_FrameCount(); + // Needed by shader class static bool Get_Fog_Enable() { return FogEnable; } static D3DCOLOR Get_Fog_Color() { return FogColor; } From e2ff87cd81f924a230f55fe8efef9e90d384e154 Mon Sep 17 00:00:00 2001 From: stm <14291421+stephanmeesters@users.noreply.github.com> Date: Tue, 31 Mar 2026 12:08:08 +0200 Subject: [PATCH 3/8] refactor(ww3d2): Use statistics struct for bookkeeping --- .../Source/WWVegas/WW3D2/dx8wrapper.cpp | 84 +++---------------- .../Source/WWVegas/WW3D2/dx8wrapper.h | 30 +++---- 2 files changed, 22 insertions(+), 92 deletions(-) diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp index 04bc3dafad..569c96accc 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp @@ -93,6 +93,9 @@ const int DEFAULT_BIT_DEPTH = 32; const int DEFAULT_TEXTURE_BIT_DEPTH = 16; const D3DMULTISAMPLE_TYPE DEFAULT_MSAA = D3DMULTISAMPLE_NONE; +DX8FrameStatistics DX8Wrapper::FrameStatistics = { 0 }; +static DX8FrameStatistics LastFrameStatistics = { 0 }; + bool DX8Wrapper_IsWindowed = true; // FPU_PRESERVE @@ -150,15 +153,6 @@ IDirect3DSurface8 * DX8Wrapper::DefaultRenderTarget = nullptr; IDirect3DSurface8 * DX8Wrapper::DefaultDepthBuffer = nullptr; bool DX8Wrapper::IsRenderToTexture = false; -unsigned DX8Wrapper::matrix_changes = 0; -unsigned DX8Wrapper::material_changes = 0; -unsigned DX8Wrapper::vertex_buffer_changes = 0; -unsigned DX8Wrapper::index_buffer_changes = 0; -unsigned DX8Wrapper::light_changes = 0; -unsigned DX8Wrapper::texture_changes = 0; -unsigned DX8Wrapper::render_state_changes = 0; -unsigned DX8Wrapper::texture_stage_state_changes = 0; -unsigned DX8Wrapper::draw_calls = 0; unsigned DX8Wrapper::_MainThreadID = 0; bool DX8Wrapper::CurrentDX8LightEnables[4]; bool DX8Wrapper::IsDeviceLost; @@ -178,18 +172,7 @@ D3DADAPTER_IDENTIFIER8 DX8Wrapper::CurrentAdapterIdentifier; unsigned long DX8Wrapper::FrameCount = 0; bool _DX8SingleThreaded = false; - unsigned number_of_DX8_calls = 0; -static unsigned last_frame_matrix_changes = 0; -static unsigned last_frame_material_changes = 0; -static unsigned last_frame_vertex_buffer_changes = 0; -static unsigned last_frame_index_buffer_changes = 0; -static unsigned last_frame_light_changes = 0; -static unsigned last_frame_texture_changes = 0; -static unsigned last_frame_render_state_changes = 0; -static unsigned last_frame_texture_stage_state_changes = 0; -static unsigned last_frame_number_of_DX8_calls = 0; -static unsigned last_frame_draw_calls = 0; static D3DPRESENT_PARAMETERS _PresentParameters; static DynamicVectorClass _RenderDeviceNameTable; @@ -1649,71 +1632,26 @@ bool DX8Wrapper::Test_Z_Mode(D3DFORMAT colorbuffer,D3DFORMAT backbuffer, D3DFORM void DX8Wrapper::Reset_Statistics() { - matrix_changes = 0; - material_changes = 0; - vertex_buffer_changes = 0; - index_buffer_changes = 0; - light_changes = 0; - texture_changes = 0; - render_state_changes =0; - texture_stage_state_changes =0; - draw_calls =0; - - number_of_DX8_calls = 0; - last_frame_matrix_changes = 0; - last_frame_material_changes = 0; - last_frame_vertex_buffer_changes = 0; - last_frame_index_buffer_changes = 0; - last_frame_light_changes = 0; - last_frame_texture_changes = 0; - last_frame_render_state_changes = 0; - last_frame_texture_stage_state_changes = 0; - last_frame_number_of_DX8_calls = 0; - last_frame_draw_calls =0; + memset(&FrameStatistics, 0, sizeof(FrameStatistics)); + memset(&LastFrameStatistics, 0, sizeof(FrameStatistics)); + number_of_DX8_calls=0; } void DX8Wrapper::Begin_Statistics() { - matrix_changes=0; - material_changes=0; - vertex_buffer_changes=0; - index_buffer_changes=0; - light_changes=0; - texture_changes = 0; - render_state_changes =0; - texture_stage_state_changes =0; + memset(&FrameStatistics, 0, sizeof(FrameStatistics)); number_of_DX8_calls=0; - draw_calls=0; } void DX8Wrapper::End_Statistics() { - last_frame_matrix_changes=matrix_changes; - last_frame_material_changes=material_changes; - last_frame_vertex_buffer_changes=vertex_buffer_changes; - last_frame_index_buffer_changes=index_buffer_changes; - last_frame_light_changes=light_changes; - last_frame_texture_changes = texture_changes; - last_frame_render_state_changes = render_state_changes; - last_frame_texture_stage_state_changes = texture_stage_state_changes; - last_frame_number_of_DX8_calls=number_of_DX8_calls; - last_frame_draw_calls=draw_calls; + LastFrameStatistics = FrameStatistics; + LastFrameStatistics.dx8_calls = number_of_DX8_calls; } -DX8FrameStatistics DX8Wrapper::Get_Last_Frame_Statistics() +const DX8FrameStatistics& DX8Wrapper::Get_Last_Frame_Statistics() { - DX8FrameStatistics stats; - stats.matrix_changes = last_frame_matrix_changes; - stats.material_changes = last_frame_material_changes; - stats.vertex_buffer_changes = last_frame_vertex_buffer_changes; - stats.index_buffer_changes = last_frame_index_buffer_changes; - stats.light_changes = last_frame_light_changes; - stats.texture_changes = last_frame_texture_changes; - stats.render_state_changes = last_frame_render_state_changes; - stats.texture_stage_state_changes = last_frame_texture_stage_state_changes; - stats.dx8_calls = last_frame_number_of_DX8_calls; - stats.draw_calls = last_frame_draw_calls; - return stats; + return LastFrameStatistics; } unsigned long DX8Wrapper::Get_FrameCount() {return FrameCount;} diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.h index 7e3269b6b4..b6a9355920 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.h +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.h @@ -108,15 +108,15 @@ struct DX8FrameStatistics unsigned draw_calls; }; -#define DX8_RECORD_MATRIX_CHANGE() matrix_changes++ -#define DX8_RECORD_MATERIAL_CHANGE() material_changes++ -#define DX8_RECORD_VERTEX_BUFFER_CHANGE() vertex_buffer_changes++ -#define DX8_RECORD_INDEX_BUFFER_CHANGE() index_buffer_changes++ -#define DX8_RECORD_LIGHT_CHANGE() light_changes++ -#define DX8_RECORD_TEXTURE_CHANGE() texture_changes++ -#define DX8_RECORD_RENDER_STATE_CHANGE() render_state_changes++ -#define DX8_RECORD_TEXTURE_STAGE_STATE_CHANGE() texture_stage_state_changes++ -#define DX8_RECORD_DRAW_CALLS() draw_calls++ +#define DX8_RECORD_MATRIX_CHANGE() FrameStatistics.matrix_changes++ +#define DX8_RECORD_MATERIAL_CHANGE() FrameStatistics.material_changes++ +#define DX8_RECORD_VERTEX_BUFFER_CHANGE() FrameStatistics.vertex_buffer_changes++ +#define DX8_RECORD_INDEX_BUFFER_CHANGE() FrameStatistics.index_buffer_changes++ +#define DX8_RECORD_LIGHT_CHANGE() FrameStatistics.light_changes++ +#define DX8_RECORD_TEXTURE_CHANGE() FrameStatistics.texture_changes++ +#define DX8_RECORD_RENDER_STATE_CHANGE() FrameStatistics.render_state_changes++ +#define DX8_RECORD_TEXTURE_STAGE_STATE_CHANGE() FrameStatistics.texture_stage_state_changes++ +#define DX8_RECORD_DRAW_CALLS() FrameStatistics.draw_calls++ extern unsigned number_of_DX8_calls; extern bool _DX8SingleThreaded; @@ -427,7 +427,7 @@ class DX8Wrapper */ static void Begin_Statistics(); static void End_Statistics(); - static DX8FrameStatistics Get_Last_Frame_Statistics(); + static const DX8FrameStatistics& Get_Last_Frame_Statistics(); static unsigned long Get_FrameCount(); // Needed by shader class @@ -661,15 +661,7 @@ class DX8Wrapper static bool FogEnable; static D3DCOLOR FogColor; - static unsigned matrix_changes; - static unsigned material_changes; - static unsigned vertex_buffer_changes; - static unsigned index_buffer_changes; - static unsigned light_changes; - static unsigned texture_changes; - static unsigned render_state_changes; - static unsigned texture_stage_state_changes; - static unsigned draw_calls; + static DX8FrameStatistics FrameStatistics; static bool CurrentDX8LightEnables[4]; static unsigned long FrameCount; From 83db1e821ace201d83c1abcab8999c465dce2ea5 Mon Sep 17 00:00:00 2001 From: stm <14291421+stephanmeesters@users.noreply.github.com> Date: Tue, 31 Mar 2026 12:48:31 +0200 Subject: [PATCH 4/8] refactor(ww3d2): Better sizeof target --- .../Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp index 569c96accc..0ac9c8bc62 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp @@ -1632,14 +1632,14 @@ bool DX8Wrapper::Test_Z_Mode(D3DFORMAT colorbuffer,D3DFORMAT backbuffer, D3DFORM void DX8Wrapper::Reset_Statistics() { - memset(&FrameStatistics, 0, sizeof(FrameStatistics)); - memset(&LastFrameStatistics, 0, sizeof(FrameStatistics)); + memset(&FrameStatistics, 0, sizeof(DX8FrameStatistics)); + memset(&LastFrameStatistics, 0, sizeof(DX8FrameStatistics)); number_of_DX8_calls=0; } void DX8Wrapper::Begin_Statistics() { - memset(&FrameStatistics, 0, sizeof(FrameStatistics)); + memset(&FrameStatistics, 0, sizeof(DX8FrameStatistics)); number_of_DX8_calls=0; } From 0c8216c15e86239327babcae1edd9e20be2bad68 Mon Sep 17 00:00:00 2001 From: stm <14291421+stephanmeesters@users.noreply.github.com> Date: Tue, 31 Mar 2026 20:50:43 +0200 Subject: [PATCH 5/8] refactor(ww3d2): Use sizeof() --- .../Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp index 0ac9c8bc62..3c5f25dd0e 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp @@ -1632,14 +1632,14 @@ bool DX8Wrapper::Test_Z_Mode(D3DFORMAT colorbuffer,D3DFORMAT backbuffer, D3DFORM void DX8Wrapper::Reset_Statistics() { - memset(&FrameStatistics, 0, sizeof(DX8FrameStatistics)); - memset(&LastFrameStatistics, 0, sizeof(DX8FrameStatistics)); + memset(&FrameStatistics, 0, sizeof(FrameStatistics)); + memset(&LastFrameStatistics, 0, sizeof(LastFrameStatistics)); number_of_DX8_calls=0; } void DX8Wrapper::Begin_Statistics() { - memset(&FrameStatistics, 0, sizeof(DX8FrameStatistics)); + memset(&FrameStatistics, 0, sizeof(FrameStatistics)); number_of_DX8_calls=0; } From db3f0354cfe5b9ab6617a7acef800e63468395b6 Mon Sep 17 00:00:00 2001 From: stm <14291421+stephanmeesters@users.noreply.github.com> Date: Tue, 31 Mar 2026 21:07:57 +0200 Subject: [PATCH 6/8] refactor(ww3d2): Replace number_of_DX8_calls --- .../Source/WWVegas/WW3D2/dx8wrapper.cpp | 16 ++++++---------- .../Libraries/Source/WWVegas/WW3D2/dx8wrapper.h | 15 ++++++++------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp index 3c5f25dd0e..5faedf829e 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp @@ -172,7 +172,6 @@ D3DADAPTER_IDENTIFIER8 DX8Wrapper::CurrentAdapterIdentifier; unsigned long DX8Wrapper::FrameCount = 0; bool _DX8SingleThreaded = false; -unsigned number_of_DX8_calls = 0; static D3DPRESENT_PARAMETERS _PresentParameters; static DynamicVectorClass _RenderDeviceNameTable; @@ -1634,19 +1633,16 @@ void DX8Wrapper::Reset_Statistics() { memset(&FrameStatistics, 0, sizeof(FrameStatistics)); memset(&LastFrameStatistics, 0, sizeof(LastFrameStatistics)); - number_of_DX8_calls=0; } void DX8Wrapper::Begin_Statistics() { memset(&FrameStatistics, 0, sizeof(FrameStatistics)); - number_of_DX8_calls=0; } void DX8Wrapper::End_Statistics() { LastFrameStatistics = FrameStatistics; - LastFrameStatistics.dx8_calls = number_of_DX8_calls; } const DX8FrameStatistics& DX8Wrapper::Get_Last_Frame_Statistics() @@ -1690,7 +1686,7 @@ void DX8Wrapper::End_Scene(bool flip_frames) hr=_Get_D3D_Device8()->Present(nullptr, nullptr, nullptr, nullptr); } - number_of_DX8_calls++; + DX8_RECORD_DX8_CALLS(); if (SUCCEEDED(hr)) { #ifdef EXTENDED_STATS @@ -1799,7 +1795,7 @@ void DX8Wrapper::Clear(bool clear_color, bool clear_z_stencil, const Vector3 &co IDirect3DSurface8* depthbuffer; _Get_D3D_Device8()->GetDepthStencilSurface(&depthbuffer); - number_of_DX8_calls++; + DX8_RECORD_DX8_CALLS(); if (depthbuffer) { @@ -3161,7 +3157,7 @@ DX8Wrapper::Create_Render_Target (int width, int height, WW3DFormat format) { DX8_THREAD_ASSERT(); DX8_Assert(); - number_of_DX8_calls++; + DX8_RECORD_DX8_CALLS(); // Use the current display format if format isn't specified if (format==WW3D_FORMAT_UNKNOWN) { @@ -3227,7 +3223,7 @@ void DX8Wrapper::Create_Render_Target { DX8_THREAD_ASSERT(); DX8_Assert(); - number_of_DX8_calls++; + DX8_RECORD_DX8_CALLS(); // Use the current display format if format isn't specified if (format==WW3D_FORMAT_UNKNOWN) @@ -3628,7 +3624,7 @@ void DX8Wrapper::Flush_DX8_Resource_Manager(unsigned int bytes) unsigned int DX8Wrapper::Get_Free_Texture_RAM() { DX8_Assert(); - number_of_DX8_calls++; + DX8_RECORD_DX8_CALLS(); return DX8Wrapper::_Get_D3D_Device8()->GetAvailableTextureMem(); } @@ -3644,7 +3640,7 @@ void DX8Wrapper::Set_Gamma(float gamma,float bright,float contrast,bool calibrat float oo_gamma=1.0f/gamma; DX8_Assert(); - number_of_DX8_calls++; + DX8_RECORD_DX8_CALLS(); DWORD flag=(calibrate?D3DSGR_CALIBRATE:D3DSGR_NO_CALIBRATION); diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.h index b6a9355920..37fa98dc75 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.h +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.h @@ -116,9 +116,9 @@ struct DX8FrameStatistics #define DX8_RECORD_TEXTURE_CHANGE() FrameStatistics.texture_changes++ #define DX8_RECORD_RENDER_STATE_CHANGE() FrameStatistics.render_state_changes++ #define DX8_RECORD_TEXTURE_STAGE_STATE_CHANGE() FrameStatistics.texture_stage_state_changes++ +#define DX8_RECORD_DX8_CALLS() FrameStatistics.dx8_calls++ #define DX8_RECORD_DRAW_CALLS() FrameStatistics.draw_calls++ -extern unsigned number_of_DX8_calls; extern bool _DX8SingleThreaded; void DX8_Assert(); @@ -131,14 +131,14 @@ WWINLINE void DX8_ErrorCode(unsigned res) } #ifdef WWDEBUG -#define DX8CALL_HRES(x,res) DX8_Assert(); res = DX8Wrapper::_Get_D3D_Device8()->x; DX8_ErrorCode(res); number_of_DX8_calls++; -#define DX8CALL(x) DX8_Assert(); DX8_ErrorCode(DX8Wrapper::_Get_D3D_Device8()->x); number_of_DX8_calls++; -#define DX8CALL_D3D(x) DX8_Assert(); DX8_ErrorCode(DX8Wrapper::_Get_D3D8()->x); number_of_DX8_calls++; +#define DX8CALL_HRES(x,res) DX8_Assert(); res = DX8Wrapper::_Get_D3D_Device8()->x; DX8_ErrorCode(res); DX8Wrapper::Increment_DX8_CallCount(); +#define DX8CALL(x) DX8_Assert(); DX8_ErrorCode(DX8Wrapper::_Get_D3D_Device8()->x); DX8Wrapper::Increment_DX8_CallCount(); +#define DX8CALL_D3D(x) DX8_Assert(); DX8_ErrorCode(DX8Wrapper::_Get_D3D8()->x); DX8Wrapper::Increment_DX8_CallCount(); #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!"); } #else -#define DX8CALL_HRES(x,res) res = DX8Wrapper::_Get_D3D_Device8()->x; number_of_DX8_calls++; -#define DX8CALL(x) DX8Wrapper::_Get_D3D_Device8()->x; number_of_DX8_calls++; -#define DX8CALL_D3D(x) DX8Wrapper::_Get_D3D8()->x; number_of_DX8_calls++; +#define DX8CALL_HRES(x,res) res = DX8Wrapper::_Get_D3D_Device8()->x; DX8Wrapper::Increment_DX8_CallCount(); +#define DX8CALL(x) DX8Wrapper::_Get_D3D_Device8()->x; DX8Wrapper::Increment_DX8_CallCount(); +#define DX8CALL_D3D(x) DX8Wrapper::_Get_D3D8()->x; DX8Wrapper::Increment_DX8_CallCount(); #define DX8_THREAD_ASSERT() ; #endif @@ -429,6 +429,7 @@ class DX8Wrapper static void End_Statistics(); static const DX8FrameStatistics& Get_Last_Frame_Statistics(); static unsigned long Get_FrameCount(); + static void Increment_DX8_CallCount() { DX8_RECORD_DX8_CALLS(); } // Needed by shader class static bool Get_Fog_Enable() { return FogEnable; } From a1d98640952b700de5bf496768f3cfa4a1d5b674 Mon Sep 17 00:00:00 2001 From: stm <14291421+stephanmeesters@users.noreply.github.com> Date: Wed, 1 Apr 2026 20:09:24 +0200 Subject: [PATCH 7/8] refactor(ww3d2): Use constructor initialization --- .../Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp | 10 +++++----- .../Libraries/Source/WWVegas/WW3D2/dx8wrapper.h | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp index 5faedf829e..956540ddae 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp @@ -93,8 +93,8 @@ const int DEFAULT_BIT_DEPTH = 32; const int DEFAULT_TEXTURE_BIT_DEPTH = 16; const D3DMULTISAMPLE_TYPE DEFAULT_MSAA = D3DMULTISAMPLE_NONE; -DX8FrameStatistics DX8Wrapper::FrameStatistics = { 0 }; -static DX8FrameStatistics LastFrameStatistics = { 0 }; +DX8FrameStatistics DX8Wrapper::FrameStatistics; +static DX8FrameStatistics LastFrameStatistics; bool DX8Wrapper_IsWindowed = true; @@ -1631,13 +1631,13 @@ bool DX8Wrapper::Test_Z_Mode(D3DFORMAT colorbuffer,D3DFORMAT backbuffer, D3DFORM void DX8Wrapper::Reset_Statistics() { - memset(&FrameStatistics, 0, sizeof(FrameStatistics)); - memset(&LastFrameStatistics, 0, sizeof(LastFrameStatistics)); + FrameStatistics = DX8FrameStatistics(); + LastFrameStatistics = DX8FrameStatistics(); } void DX8Wrapper::Begin_Statistics() { - memset(&FrameStatistics, 0, sizeof(FrameStatistics)); + FrameStatistics = DX8FrameStatistics(); } void DX8Wrapper::End_Statistics() diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.h index 37fa98dc75..937aa6ea6a 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.h +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.h @@ -96,6 +96,20 @@ class SurfaceClass; struct DX8FrameStatistics { + DX8FrameStatistics() : + matrix_changes(0), + material_changes(0), + vertex_buffer_changes(0), + index_buffer_changes(0), + light_changes(0), + texture_changes(0), + render_state_changes(0), + texture_stage_state_changes(0), + dx8_calls(0), + draw_calls(0) + { + } + unsigned matrix_changes; unsigned material_changes; unsigned vertex_buffer_changes; From 71e5bedbc3f0e83cb93b799532e46cda1cba2512 Mon Sep 17 00:00:00 2001 From: stm <14291421+stephanmeesters@users.noreply.github.com> Date: Thu, 2 Apr 2026 00:21:22 +0200 Subject: [PATCH 8/8] Replicate in Generals --- .../Source/WWVegas/WW3D2/dx8wrapper.cpp | 94 ++++--------------- .../Source/WWVegas/WW3D2/dx8wrapper.h | 85 +++++++++-------- 2 files changed, 65 insertions(+), 114 deletions(-) diff --git a/Generals/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp b/Generals/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp index 52b44c3061..4dc573beee 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp +++ b/Generals/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp @@ -89,6 +89,9 @@ const int DEFAULT_BIT_DEPTH = 32; const int DEFAULT_TEXTURE_BIT_DEPTH = 16; const D3DMULTISAMPLE_TYPE DEFAULT_MSAA = D3DMULTISAMPLE_NONE; +DX8FrameStatistics DX8Wrapper::FrameStatistics; +static DX8FrameStatistics LastFrameStatistics; + bool DX8Wrapper_IsWindowed = true; // FPU_PRESERVE @@ -146,15 +149,6 @@ IDirect3DSurface8 * DX8Wrapper::DefaultRenderTarget = nullptr; IDirect3DSurface8 * DX8Wrapper::DefaultDepthBuffer = nullptr; bool DX8Wrapper::IsRenderToTexture = false; -unsigned DX8Wrapper::matrix_changes = 0; -unsigned DX8Wrapper::material_changes = 0; -unsigned DX8Wrapper::vertex_buffer_changes = 0; -unsigned DX8Wrapper::index_buffer_changes = 0; -unsigned DX8Wrapper::light_changes = 0; -unsigned DX8Wrapper::texture_changes = 0; -unsigned DX8Wrapper::render_state_changes = 0; -unsigned DX8Wrapper::texture_stage_state_changes = 0; -unsigned DX8Wrapper::draw_calls = 0; unsigned DX8Wrapper::_MainThreadID = 0; bool DX8Wrapper::CurrentDX8LightEnables[4]; bool DX8Wrapper::IsDeviceLost; @@ -175,18 +169,6 @@ unsigned long DX8Wrapper::FrameCount = 0; bool _DX8SingleThreaded = false; -unsigned number_of_DX8_calls = 0; -static unsigned last_frame_matrix_changes = 0; -static unsigned last_frame_material_changes = 0; -static unsigned last_frame_vertex_buffer_changes = 0; -static unsigned last_frame_index_buffer_changes = 0; -static unsigned last_frame_light_changes = 0; -static unsigned last_frame_texture_changes = 0; -static unsigned last_frame_render_state_changes = 0; -static unsigned last_frame_texture_stage_state_changes = 0; -static unsigned last_frame_number_of_DX8_calls = 0; -static unsigned last_frame_draw_calls = 0; - static D3DPRESENT_PARAMETERS _PresentParameters; static DynamicVectorClass _RenderDeviceNameTable; static DynamicVectorClass _RenderDeviceShortNameTable; @@ -1527,67 +1509,25 @@ bool DX8Wrapper::Test_Z_Mode(D3DFORMAT colorbuffer,D3DFORMAT backbuffer, D3DFORM void DX8Wrapper::Reset_Statistics() { - matrix_changes = 0; - material_changes = 0; - vertex_buffer_changes = 0; - index_buffer_changes = 0; - light_changes = 0; - texture_changes = 0; - render_state_changes =0; - texture_stage_state_changes =0; - draw_calls =0; - - number_of_DX8_calls = 0; - last_frame_matrix_changes = 0; - last_frame_material_changes = 0; - last_frame_vertex_buffer_changes = 0; - last_frame_index_buffer_changes = 0; - last_frame_light_changes = 0; - last_frame_texture_changes = 0; - last_frame_render_state_changes = 0; - last_frame_texture_stage_state_changes = 0; - last_frame_number_of_DX8_calls = 0; - last_frame_draw_calls =0; + FrameStatistics = DX8FrameStatistics(); + LastFrameStatistics = DX8FrameStatistics(); } void DX8Wrapper::Begin_Statistics() { - matrix_changes=0; - material_changes=0; - vertex_buffer_changes=0; - index_buffer_changes=0; - light_changes=0; - texture_changes = 0; - render_state_changes =0; - texture_stage_state_changes =0; - number_of_DX8_calls=0; - draw_calls=0; + FrameStatistics = DX8FrameStatistics(); } void DX8Wrapper::End_Statistics() { - last_frame_matrix_changes=matrix_changes; - last_frame_material_changes=material_changes; - last_frame_vertex_buffer_changes=vertex_buffer_changes; - last_frame_index_buffer_changes=index_buffer_changes; - last_frame_light_changes=light_changes; - last_frame_texture_changes = texture_changes; - last_frame_render_state_changes = render_state_changes; - last_frame_texture_stage_state_changes = texture_stage_state_changes; - last_frame_number_of_DX8_calls=number_of_DX8_calls; - last_frame_draw_calls=draw_calls; + LastFrameStatistics = FrameStatistics; +} + +const DX8FrameStatistics& DX8Wrapper::Get_Last_Frame_Statistics() +{ + return LastFrameStatistics; } -unsigned DX8Wrapper::Get_Last_Frame_Matrix_Changes() { return last_frame_matrix_changes; } -unsigned DX8Wrapper::Get_Last_Frame_Material_Changes() { return last_frame_material_changes; } -unsigned DX8Wrapper::Get_Last_Frame_Vertex_Buffer_Changes() { return last_frame_vertex_buffer_changes; } -unsigned DX8Wrapper::Get_Last_Frame_Index_Buffer_Changes() { return last_frame_index_buffer_changes; } -unsigned DX8Wrapper::Get_Last_Frame_Light_Changes() { return last_frame_light_changes; } -unsigned DX8Wrapper::Get_Last_Frame_Texture_Changes() { return last_frame_texture_changes; } -unsigned DX8Wrapper::Get_Last_Frame_Render_State_Changes() { return last_frame_render_state_changes; } -unsigned DX8Wrapper::Get_Last_Frame_Texture_Stage_State_Changes() { return last_frame_texture_stage_state_changes; } -unsigned DX8Wrapper::Get_Last_Frame_DX8_Calls() { return last_frame_number_of_DX8_calls; } -unsigned DX8Wrapper::Get_Last_Frame_Draw_Calls() { return last_frame_draw_calls; } unsigned long DX8Wrapper::Get_FrameCount() {return FrameCount;} void DX8_Assert() @@ -1624,7 +1564,7 @@ void DX8Wrapper::End_Scene(bool flip_frames) hr=_Get_D3D_Device8()->Present(nullptr, nullptr, nullptr, nullptr); } - number_of_DX8_calls++; + DX8_RECORD_DX8_CALLS(); if (SUCCEEDED(hr)) { #ifdef EXTENDED_STATS @@ -2982,7 +2922,7 @@ DX8Wrapper::Create_Render_Target (int width, int height, WW3DFormat format) { DX8_THREAD_ASSERT(); DX8_Assert(); - number_of_DX8_calls++; + DX8_RECORD_DX8_CALLS(); // Use the current display format if format isn't specified if (format==WW3D_FORMAT_UNKNOWN) { @@ -3048,7 +2988,7 @@ void DX8Wrapper::Create_Render_Target { DX8_THREAD_ASSERT(); DX8_Assert(); - number_of_DX8_calls++; + DX8_RECORD_DX8_CALLS(); // Use the current display format if format isn't specified if (format==WW3D_FORMAT_UNKNOWN) @@ -3449,7 +3389,7 @@ void DX8Wrapper::Flush_DX8_Resource_Manager(unsigned int bytes) unsigned int DX8Wrapper::Get_Free_Texture_RAM() { DX8_Assert(); - number_of_DX8_calls++; + DX8_RECORD_DX8_CALLS(); return DX8Wrapper::_Get_D3D_Device8()->GetAvailableTextureMem(); } @@ -3465,7 +3405,7 @@ void DX8Wrapper::Set_Gamma(float gamma,float bright,float contrast,bool calibrat float oo_gamma=1.0f/gamma; DX8_Assert(); - number_of_DX8_calls++; + DX8_RECORD_DX8_CALLS(); DWORD flag=(calibrate?D3DSGR_CALIBRATE:D3DSGR_NO_CALIBRATION); diff --git a/Generals/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.h b/Generals/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.h index 32a86393c8..dbdbd5b9c8 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.h +++ b/Generals/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.h @@ -91,17 +91,45 @@ class TextureClass; class LightClass; class SurfaceClass; -#define DX8_RECORD_MATRIX_CHANGE() matrix_changes++ -#define DX8_RECORD_MATERIAL_CHANGE() material_changes++ -#define DX8_RECORD_VERTEX_BUFFER_CHANGE() vertex_buffer_changes++ -#define DX8_RECORD_INDEX_BUFFER_CHANGE() index_buffer_changes++ -#define DX8_RECORD_LIGHT_CHANGE() light_changes++ -#define DX8_RECORD_TEXTURE_CHANGE() texture_changes++ -#define DX8_RECORD_RENDER_STATE_CHANGE() render_state_changes++ -#define DX8_RECORD_TEXTURE_STAGE_STATE_CHANGE() texture_stage_state_changes++ -#define DX8_RECORD_DRAW_CALLS() draw_calls++ - -extern unsigned number_of_DX8_calls; +struct DX8FrameStatistics +{ + DX8FrameStatistics() : + matrix_changes(0), + material_changes(0), + vertex_buffer_changes(0), + index_buffer_changes(0), + light_changes(0), + texture_changes(0), + render_state_changes(0), + texture_stage_state_changes(0), + dx8_calls(0), + draw_calls(0) + { + } + + unsigned matrix_changes; + unsigned material_changes; + unsigned vertex_buffer_changes; + unsigned index_buffer_changes; + unsigned light_changes; + unsigned texture_changes; + unsigned render_state_changes; + unsigned texture_stage_state_changes; + unsigned dx8_calls; + unsigned draw_calls; +}; + +#define DX8_RECORD_MATRIX_CHANGE() FrameStatistics.matrix_changes++ +#define DX8_RECORD_MATERIAL_CHANGE() FrameStatistics.material_changes++ +#define DX8_RECORD_VERTEX_BUFFER_CHANGE() FrameStatistics.vertex_buffer_changes++ +#define DX8_RECORD_INDEX_BUFFER_CHANGE() FrameStatistics.index_buffer_changes++ +#define DX8_RECORD_LIGHT_CHANGE() FrameStatistics.light_changes++ +#define DX8_RECORD_TEXTURE_CHANGE() FrameStatistics.texture_changes++ +#define DX8_RECORD_RENDER_STATE_CHANGE() FrameStatistics.render_state_changes++ +#define DX8_RECORD_TEXTURE_STAGE_STATE_CHANGE() FrameStatistics.texture_stage_state_changes++ +#define DX8_RECORD_DX8_CALLS() FrameStatistics.dx8_calls++ +#define DX8_RECORD_DRAW_CALLS() FrameStatistics.draw_calls++ + extern bool _DX8SingleThreaded; void DX8_Assert(); @@ -114,14 +142,14 @@ WWINLINE void DX8_ErrorCode(unsigned res) } #ifdef WWDEBUG -#define DX8CALL_HRES(x,res) DX8_Assert(); res = DX8Wrapper::_Get_D3D_Device8()->x; DX8_ErrorCode(res); number_of_DX8_calls++; -#define DX8CALL(x) DX8_Assert(); DX8_ErrorCode(DX8Wrapper::_Get_D3D_Device8()->x); number_of_DX8_calls++; -#define DX8CALL_D3D(x) DX8_Assert(); DX8_ErrorCode(DX8Wrapper::_Get_D3D8()->x); number_of_DX8_calls++; +#define DX8CALL_HRES(x,res) DX8_Assert(); res = DX8Wrapper::_Get_D3D_Device8()->x; DX8_ErrorCode(res); DX8Wrapper::Increment_DX8_CallCount(); +#define DX8CALL(x) DX8_Assert(); DX8_ErrorCode(DX8Wrapper::_Get_D3D_Device8()->x); DX8Wrapper::Increment_DX8_CallCount(); +#define DX8CALL_D3D(x) DX8_Assert(); DX8_ErrorCode(DX8Wrapper::_Get_D3D8()->x); DX8Wrapper::Increment_DX8_CallCount(); #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!"); } #else -#define DX8CALL_HRES(x,res) res = DX8Wrapper::_Get_D3D_Device8()->x; number_of_DX8_calls++; -#define DX8CALL(x) DX8Wrapper::_Get_D3D_Device8()->x; number_of_DX8_calls++; -#define DX8CALL_D3D(x) DX8Wrapper::_Get_D3D8()->x; number_of_DX8_calls++; +#define DX8CALL_HRES(x,res) res = DX8Wrapper::_Get_D3D_Device8()->x; DX8Wrapper::Increment_DX8_CallCount(); +#define DX8CALL(x) DX8Wrapper::_Get_D3D_Device8()->x; DX8Wrapper::Increment_DX8_CallCount(); +#define DX8CALL_D3D(x) DX8Wrapper::_Get_D3D8()->x; DX8Wrapper::Increment_DX8_CallCount(); #define DX8_THREAD_ASSERT() ; #endif @@ -407,18 +435,9 @@ class DX8Wrapper */ static void Begin_Statistics(); static void End_Statistics(); - static unsigned Get_Last_Frame_Matrix_Changes(); - static unsigned Get_Last_Frame_Material_Changes(); - static unsigned Get_Last_Frame_Vertex_Buffer_Changes(); - static unsigned Get_Last_Frame_Index_Buffer_Changes(); - static unsigned Get_Last_Frame_Light_Changes(); - static unsigned Get_Last_Frame_Texture_Changes(); - static unsigned Get_Last_Frame_Render_State_Changes(); - static unsigned Get_Last_Frame_Texture_Stage_State_Changes(); - static unsigned Get_Last_Frame_DX8_Calls(); - static unsigned Get_Last_Frame_Draw_Calls(); - + static const DX8FrameStatistics& Get_Last_Frame_Statistics(); static unsigned long Get_FrameCount(); + static void Increment_DX8_CallCount() { DX8_RECORD_DX8_CALLS(); } // Needed by shader class static bool Get_Fog_Enable() { return FogEnable; } @@ -651,15 +670,7 @@ class DX8Wrapper static bool FogEnable; static D3DCOLOR FogColor; - static unsigned matrix_changes; - static unsigned material_changes; - static unsigned vertex_buffer_changes; - static unsigned index_buffer_changes; - static unsigned light_changes; - static unsigned texture_changes; - static unsigned render_state_changes; - static unsigned texture_stage_state_changes; - static unsigned draw_calls; + static DX8FrameStatistics FrameStatistics; static bool CurrentDX8LightEnables[4]; static unsigned long FrameCount;