Skip to content

Commit

Permalink
Add profiling for dd7to9
Browse files Browse the repository at this point in the history
  • Loading branch information
elishacloud committed Sep 9, 2024
1 parent 970ef6d commit 7459793
Show file tree
Hide file tree
Showing 10 changed files with 221 additions and 29 deletions.
2 changes: 1 addition & 1 deletion Dllmain/BuildNo.rc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define BUILD_NUMBER 7125
#define BUILD_NUMBER 7126
2 changes: 1 addition & 1 deletion External/Logging
Submodule Logging updated 1 files
+24 −0 Logging.h
2 changes: 1 addition & 1 deletion External/d3d8to9
36 changes: 36 additions & 0 deletions Logging/Logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,18 @@ std::ostream& operator<<(std::ostream& os, const DDCOLORKEY& ck)
<< Logging::hex(ck.dwColorSpaceHighValue);
}

std::ostream& operator<<(std::ostream& os, const DDSURFACEDESC* lpDesc)
{
if (lpDesc)
{
return os << *lpDesc;
}
else
{
return os << nullptr;
}
}

std::ostream& operator<<(std::ostream& os, const DDSURFACEDESC& sd)
{
return Logging::LogStruct(os)
Expand All @@ -464,6 +476,18 @@ std::ostream& operator<<(std::ostream& os, const DDSURFACEDESC& sd)
<< sd.ddsCaps;
}

std::ostream& operator<<(std::ostream& os, const DDSURFACEDESC2* lpDesc)
{
if (lpDesc)
{
return os << *lpDesc;
}
else
{
return os << nullptr;
}
}

std::ostream& operator<<(std::ostream& os, const DDSURFACEDESC2& sd)
{
return Logging::LogStruct(os)
Expand Down Expand Up @@ -2364,6 +2388,18 @@ std::ostream& operator<<(std::ostream& os, const POINTS& p)
<< p.y;
}

std::ostream& operator<<(std::ostream& os, const RECT* lpRect)
{
if (lpRect)
{
return os << *lpRect;
}
else
{
return os << nullptr;
}
}

std::ostream& operator<<(std::ostream& os, const RECT& rect)
{
return Logging::LogStruct(os)
Expand Down
3 changes: 3 additions & 0 deletions Logging/Logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ std::ostream& operator<<(std::ostream& os, const DDSCAPS& caps);
std::ostream& operator<<(std::ostream& os, const DDSCAPS2& caps);
std::ostream& operator<<(std::ostream& os, const DDPIXELFORMAT& pf);
std::ostream& operator<<(std::ostream& os, const DDCOLORKEY& ck);
std::ostream& operator<<(std::ostream& os, const DDSURFACEDESC* lpDesc);
std::ostream& operator<<(std::ostream& os, const DDSURFACEDESC& sd);
std::ostream& operator<<(std::ostream& os, const DDSURFACEDESC2* lpDesc);
std::ostream& operator<<(std::ostream& os, const DDSURFACEDESC2& sd);
#endif
#ifdef _D3DCAPS_H
Expand Down Expand Up @@ -93,6 +95,7 @@ std::ostream& operator<<(std::ostream& os, const NCCALCSIZE_PARAMS& nccs);
std::ostream& operator<<(std::ostream& os, const NMHDR& nm);
std::ostream& operator<<(std::ostream& os, const POINT& p);
std::ostream& operator<<(std::ostream& os, const POINTS& p);
std::ostream& operator<<(std::ostream& os, const RECT* lpRect);
std::ostream& operator<<(std::ostream& os, const RECT& rect);
std::ostream& operator<<(std::ostream& os, const SIZE& size);
std::ostream& operator<<(std::ostream& os, const STYLESTRUCT& ss);
Expand Down
77 changes: 73 additions & 4 deletions ddraw/IDirect3DDeviceX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1836,6 +1836,11 @@ HRESULT m_IDirect3DDeviceX::BeginScene()
if (SUCCEEDED(hr))
{
IsInScene = true;

#ifdef ENABLE_PROFILING
Logging::Log() << __FUNCTION__ << " (" << this << ") hr = " << (D3DERR)hr;
sceneTime = std::chrono::high_resolution_clock::now();
#endif
}

return hr;
Expand Down Expand Up @@ -1879,6 +1884,10 @@ HRESULT m_IDirect3DDeviceX::EndScene()
{
IsInScene = false;

#ifdef ENABLE_PROFILING
Logging::Log() << __FUNCTION__ << " (" << this << ") hr = " << (D3DERR)hr << " Timing = " << Logging::GetTimeLapseInMS(sceneTime);
#endif

if (!ddrawParent->IsPrimaryFlipSurface())
{
ddrawParent->PresentScene(nullptr);
Expand Down Expand Up @@ -3207,7 +3216,13 @@ HRESULT m_IDirect3DDeviceX::EndStateBlock(LPDWORD lpdwBlockHandle)

HRESULT m_IDirect3DDeviceX::DrawPrimitive(D3DPRIMITIVETYPE dptPrimitiveType, DWORD dwVertexTypeDesc, LPVOID lpVertices, DWORD dwVertexCount, DWORD dwFlags, DWORD DirectXVersion)
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ")";
Logging::LogDebug() << __FUNCTION__ << " (" << this << ")" <<
" VertexType = " << Logging::hex(dptPrimitiveType) <<
" VertexDesc = " << Logging::hex(dwVertexTypeDesc) <<
" Vertices = " << lpVertices <<
" VertexCount = " << dwVertexCount <<
" Flags = " << Logging::hex(dwFlags) <<
" Version = " << DirectXVersion;

if (DirectXVersion == 2 && ProxyDirectXVersion > 2)
{
Expand All @@ -3232,6 +3247,10 @@ HRESULT m_IDirect3DDeviceX::DrawPrimitive(D3DPRIMITIVETYPE dptPrimitiveType, DWO
return DDERR_INVALIDOBJECT;
}

#ifdef ENABLE_PROFILING
auto startTime = std::chrono::high_resolution_clock::now();
#endif

dwFlags = (dwFlags & D3DDP_FORCE_DWORD);

// Update vertices for Direct3D9 (needs to be first)
Expand All @@ -3258,6 +3277,10 @@ HRESULT m_IDirect3DDeviceX::DrawPrimitive(D3DPRIMITIVETYPE dptPrimitiveType, DWO
LOG_LIMIT(100, __FUNCTION__ << " Error: 'DrawPrimitiveUP' call failed: " << (D3DERR)hr);
}

#ifdef ENABLE_PROFILING
Logging::Log() << __FUNCTION__ << " (" << this << ") hr = " << (D3DERR)hr << " Timing = " << Logging::GetTimeLapseInMS(startTime);
#endif

return hr;
}

Expand Down Expand Up @@ -3337,7 +3360,13 @@ HRESULT m_IDirect3DDeviceX::DrawPrimitiveStrided(D3DPRIMITIVETYPE dptPrimitiveTy

HRESULT m_IDirect3DDeviceX::DrawPrimitiveVB(D3DPRIMITIVETYPE dptPrimitiveType, LPDIRECT3DVERTEXBUFFER7 lpd3dVertexBuffer, DWORD dwStartVertex, DWORD dwNumVertices, DWORD dwFlags, DWORD DirectXVersion)
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ")";
Logging::LogDebug() << __FUNCTION__ << " (" << this << ")" <<
" VertexType = " << Logging::hex(dptPrimitiveType) <<
" VertexBuffer = " << lpd3dVertexBuffer <<
" StartVertex = " << dwStartVertex <<
" NumVertices = " << dwNumVertices <<
" Flags = " << Logging::hex(dwFlags) <<
" Version = " << DirectXVersion;

if (Config.Dd7to9)
{
Expand All @@ -3352,6 +3381,10 @@ HRESULT m_IDirect3DDeviceX::DrawPrimitiveVB(D3DPRIMITIVETYPE dptPrimitiveType, L
return DDERR_INVALIDOBJECT;
}

#ifdef ENABLE_PROFILING
auto startTime = std::chrono::high_resolution_clock::now();
#endif

dwFlags = (dwFlags & D3DDP_FORCE_DWORD);

// ToDo: Validate vertex buffer
Expand Down Expand Up @@ -3396,6 +3429,10 @@ HRESULT m_IDirect3DDeviceX::DrawPrimitiveVB(D3DPRIMITIVETYPE dptPrimitiveType, L
LOG_LIMIT(100, __FUNCTION__ << " Error: 'DrawPrimitive' call failed: " << (D3DERR)hr);
}

#ifdef ENABLE_PROFILING
Logging::Log() << __FUNCTION__ << " (" << this << ") hr = " << (D3DERR)hr << " Timing = " << Logging::GetTimeLapseInMS(startTime);
#endif

return hr;
}

Expand Down Expand Up @@ -3441,7 +3478,15 @@ HRESULT m_IDirect3DDeviceX::DrawPrimitiveVB(D3DPRIMITIVETYPE dptPrimitiveType, L

HRESULT m_IDirect3DDeviceX::DrawIndexedPrimitive(D3DPRIMITIVETYPE dptPrimitiveType, DWORD dwVertexTypeDesc, LPVOID lpVertices, DWORD dwVertexCount, LPWORD lpIndices, DWORD dwIndexCount, DWORD dwFlags, DWORD DirectXVersion)
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ")";
Logging::LogDebug() << __FUNCTION__ << " (" << this << ")" <<
" VertexType = " << Logging::hex(dptPrimitiveType) <<
" VertexDesc = " << Logging::hex(dwVertexTypeDesc) <<
" Vertices = " << lpVertices <<
" VertexCount = " << dwVertexCount <<
" Indices = " << lpIndices <<
" IndexCount = " << dwIndexCount <<
" Flags = " << Logging::hex(dwFlags) <<
" Version = " << DirectXVersion;

if (DirectXVersion == 2 && ProxyDirectXVersion > 2)
{
Expand All @@ -3466,6 +3511,10 @@ HRESULT m_IDirect3DDeviceX::DrawIndexedPrimitive(D3DPRIMITIVETYPE dptPrimitiveTy
return DDERR_INVALIDOBJECT;
}

#ifdef ENABLE_PROFILING
auto startTime = std::chrono::high_resolution_clock::now();
#endif

dwFlags = (dwFlags & D3DDP_FORCE_DWORD);

// Update vertices for Direct3D9 (needs to be first)
Expand All @@ -3492,6 +3541,10 @@ HRESULT m_IDirect3DDeviceX::DrawIndexedPrimitive(D3DPRIMITIVETYPE dptPrimitiveTy
LOG_LIMIT(100, __FUNCTION__ << " Error: 'DrawIndexedPrimitiveUP' call failed: " << (D3DERR)hr);
}

#ifdef ENABLE_PROFILING
Logging::Log() << __FUNCTION__ << " (" << this << ") hr = " << (D3DERR)hr << " Timing = " << Logging::GetTimeLapseInMS(startTime);
#endif

return hr;
}

Expand Down Expand Up @@ -3571,7 +3624,15 @@ HRESULT m_IDirect3DDeviceX::DrawIndexedPrimitiveStrided(D3DPRIMITIVETYPE dptPrim

HRESULT m_IDirect3DDeviceX::DrawIndexedPrimitiveVB(D3DPRIMITIVETYPE dptPrimitiveType, LPDIRECT3DVERTEXBUFFER7 lpd3dVertexBuffer, DWORD dwStartVertex, DWORD dwNumVertices, LPWORD lpwIndices, DWORD dwIndexCount, DWORD dwFlags, DWORD DirectXVersion)
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ")";
Logging::LogDebug() << __FUNCTION__ << " (" << this << ")" <<
" VertexType = " << Logging::hex(dptPrimitiveType) <<
" VertexBuffer = " << lpd3dVertexBuffer <<
" StartVertex = " << dwStartVertex <<
" NumVertices = " << dwNumVertices <<
" Indices = " << lpwIndices <<
" IndexCount = " << dwIndexCount <<
" Flags = " << Logging::hex(dwFlags) <<
" Version = " << DirectXVersion;

if (Config.Dd7to9)
{
Expand All @@ -3586,6 +3647,10 @@ HRESULT m_IDirect3DDeviceX::DrawIndexedPrimitiveVB(D3DPRIMITIVETYPE dptPrimitive
return DDERR_INVALIDOBJECT;
}

#ifdef ENABLE_PROFILING
auto startTime = std::chrono::high_resolution_clock::now();
#endif

dwFlags = (dwFlags & D3DDP_FORCE_DWORD);

// ToDo: Validate vertex buffer
Expand Down Expand Up @@ -3640,6 +3705,10 @@ HRESULT m_IDirect3DDeviceX::DrawIndexedPrimitiveVB(D3DPRIMITIVETYPE dptPrimitive
LOG_LIMIT(100, __FUNCTION__ << " Error: 'DrawIndexedPrimitive' call failed: " << (D3DERR)hr);
}

#ifdef ENABLE_PROFILING
Logging::Log() << __FUNCTION__ << " (" << this << ") hr = " << (D3DERR)hr << " Timing = " << Logging::GetTimeLapseInMS(startTime);
#endif

return hr;
}

Expand Down
4 changes: 4 additions & 0 deletions ddraw/IDirect3DDeviceX.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ class m_IDirect3DDeviceX : public IUnknown, public AddressLookupTableDdrawObject
LPDIRECT3DVIEWPORT3 lpCurrentViewport = nullptr;
m_IDirect3DViewportX* lpCurrentViewportX = nullptr;

#ifdef ENABLE_PROFILING
std::chrono::steady_clock::time_point sceneTime;
#endif

struct {
DWORD rsClipping = 0;
DWORD rsLighting = 0;
Expand Down
Loading

0 comments on commit 7459793

Please sign in to comment.