Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 17 additions & 77 deletions Generals/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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<StringClass> _RenderDeviceNameTable;
static DynamicVectorClass<StringClass> _RenderDeviceShortNameTable;
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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();
}

Expand All @@ -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);

Expand Down
85 changes: 48 additions & 37 deletions Generals/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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

Expand Down Expand Up @@ -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; }
Expand Down Expand Up @@ -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;
Expand Down
Loading
Loading