Skip to content

Commit

Permalink
Validate depth formats used with "IDirect3DDevice8::CopyRects" (#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
WinterSnowfall authored Oct 10, 2024
1 parent 7136cbf commit b65caf1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions source/d3d8to9_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,9 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::CopyRects(IDirect3DSurface8 *pSourceS
if (SourceDesc.Format != DestinationDesc.Format)
return D3DERR_INVALIDCALL;

if (IsDepthStencil(SourceDesc.Format))
return D3DERR_INVALIDCALL;

HRESULT hr = D3DERR_INVALIDCALL;

if (cRects == 0)
Expand Down
10 changes: 10 additions & 0 deletions source/d3d8types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ bool SupportsPalettes()
return hasPalette;
}

bool IsDepthStencil(D3DFORMAT &Format) {
return Format == D3DFMT_D16_LOCKABLE
|| Format == D3DFMT_D16
|| Format == D3DFMT_D32
|| Format == D3DFMT_D15S1
|| Format == D3DFMT_D24X4S4
|| Format == D3DFMT_D24S8
|| Format == D3DFMT_D24X8;
}

static UINT CalcTextureSize(UINT Width, UINT Height, UINT Depth, D3DFORMAT Format)
{
switch (static_cast<DWORD>(Format))
Expand Down
1 change: 1 addition & 0 deletions source/d3d8types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ struct D3DADAPTER_IDENTIFIER8
};

bool SupportsPalettes();
bool IsDepthStencil(D3DFORMAT &format);

void ConvertCaps(D3DCAPS9 &input, D3DCAPS8 &output);
void ConvertVolumeDesc(D3DVOLUME_DESC &input, D3DVOLUME_DESC8 &output);
Expand Down

0 comments on commit b65caf1

Please sign in to comment.