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
3 changes: 3 additions & 0 deletions vendor/d3d8to9/res/d3d8.def
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
EXPORTS
ValidatePixelShader
ValidateVertexShader
DebugSetMute
Direct3DCreate8
4 changes: 2 additions & 2 deletions vendor/d3d8to9/res/d3d8to9.rc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ END
//

VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,12,0,0
FILEVERSION 1,13,0,0
PRODUCTVERSION 3,0,0,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
Expand All @@ -70,7 +70,7 @@ BEGIN
BEGIN
VALUE "CompanyName", "crosire"
VALUE "FileDescription", "d3d8to9"
VALUE "FileVersion", "1.12.0.0"
VALUE "FileVersion", "1.13.0.0"
VALUE "LegalCopyright", "Copyright © 2015. All rights reserved."
VALUE "OriginalFilename", "d3d8.dll"
VALUE "ProductName", "ReShade"
Expand Down
114 changes: 114 additions & 0 deletions vendor/d3d8to9/source/d3d8to9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,120 @@ PFN_D3DXLoadSurfaceFromSurface D3DXLoadSurfaceFromSurface = nullptr;
std::ofstream LOG;
#endif

extern "C" HRESULT WINAPI ValidatePixelShader(const DWORD* pPixelShader, const D3DCAPS8* pCaps, BOOL ReturnErrors, char** pErrorsString)
{
#ifndef D3D8TO9NOLOG
LOG << "Redirecting '" << "ValidatePixelShader " << "(" << pPixelShader << ", " << pCaps << ", " << ReturnErrors << ", " << pErrorsString << ")' ..." << std::endl;
#endif

HRESULT hr = E_FAIL;
const char* errorMessage = "";

if (!pPixelShader)
{
errorMessage = "Invalid code pointer.\n";
}
else
{
switch (*pPixelShader)
{
case D3DPS_VERSION(1, 0):
case D3DPS_VERSION(1, 1):
case D3DPS_VERSION(1, 2):
case D3DPS_VERSION(1, 3):
case D3DPS_VERSION(1, 4):
if (pCaps && *pPixelShader > pCaps->PixelShaderVersion)
{
errorMessage = "Shader version not supported by caps.\n";
break;
}
hr = S_OK;
break;

default:
errorMessage = "Unsupported shader version.\n";
}
}

if (!ReturnErrors)
{
errorMessage = "";
}

if (pErrorsString)
{
const size_t size = strlen(errorMessage) + 1;

*pErrorsString = (char*) HeapAlloc(GetProcessHeap(), 0, size);
if (*pErrorsString)
{
memcpy(*pErrorsString, errorMessage, size);
}
}

return hr;
}

extern "C" HRESULT WINAPI ValidateVertexShader(const DWORD* pVertexShader, const DWORD* pVertexDecl, const D3DCAPS8* pCaps, BOOL ReturnErrors, char** pErrorsString)
{
UNREFERENCED_PARAMETER(pVertexDecl);

#ifndef D3D8TO9NOLOG
LOG << "Redirecting '" << "ValidateVertexShader " << "(" << pVertexShader << ", " << pVertexDecl << ", " << pCaps << ", " << ReturnErrors << ", " << pErrorsString << ")' ..." << std::endl;
#endif

HRESULT hr = E_FAIL;
const char* errorMessage = "";

if (!pVertexShader)
{
errorMessage = "Invalid code pointer.\n";
}
else
{
switch (*pVertexShader)
{
case D3DVS_VERSION(1, 0):
case D3DVS_VERSION(1, 1):
if (pCaps && *pVertexShader > pCaps->VertexShaderVersion)
{
errorMessage = "Shader version not supported by caps.\n";
break;
}
hr = S_OK;
break;

default:
errorMessage = "Unsupported shader version.\n";
}
}

if (!ReturnErrors)
{
errorMessage = "";
}

if (pErrorsString)
{
const size_t size = strlen(errorMessage) + 1;

*pErrorsString = (char*) HeapAlloc(GetProcessHeap(), 0, size);
if (*pErrorsString)
{
memcpy(*pErrorsString, errorMessage, size);
}
}

return hr;
}

extern "C" void WINAPI DebugSetMute()
{
#ifndef D3D8TO9NOLOG
LOG << "Redirecting '" << "DebugSetMute ()" << "'..." << std::endl;
#endif
}

extern "C" IDirect3D8 *WINAPI Direct3DCreate8(UINT SDKVersion)
{
#ifndef D3D8TO9NOLOG
Expand Down
10 changes: 6 additions & 4 deletions vendor/d3d8to9/source/d3d8to9.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Direct3DDevice8 : public IDirect3DDevice8
Direct3DDevice8 &operator=(const Direct3DDevice8 &) = delete;

public:
Direct3DDevice8(Direct3D8 *d3d, IDirect3DDevice9 *ProxyInterface, BOOL EnableZBufferDiscarding = FALSE);
Direct3DDevice8(Direct3D8 *d3d, IDirect3DDevice9 *ProxyInterface, DWORD BehaviorFlags, BOOL EnableZBufferDiscarding = FALSE);
~Direct3DDevice8();

IDirect3DDevice9 *GetProxyInterface() const { return ProxyInterface; }
Expand Down Expand Up @@ -161,7 +161,7 @@ class Direct3DDevice8 : public IDirect3DDevice8

private:
void ApplyClipPlanes();
void ReleaseShaders();
void ReleaseShadersAndStateBlocks();

Direct3D8 *const D3D;
IDirect3DDevice9 *const ProxyInterface;
Expand All @@ -170,13 +170,15 @@ class Direct3DDevice8 : public IDirect3DDevice8
DWORD CurrentVertexShaderHandle = 0, CurrentPixelShaderHandle = 0;
IDirect3DSurface9 *pCurrentRenderTarget = nullptr;
bool PaletteFlag = false;
bool IsRecordingState = false;
bool IsMixedVPModeDevice = false;

static constexpr size_t MAX_CLIP_PLANES = 6;
float StoredClipPlanes[MAX_CLIP_PLANES][4] = {};
DWORD ClipPlaneRenderState = 0;

// Store Shader Handles so they can be destroyed later to mirror D3D8 behavior
std::unordered_set<DWORD> PixelShaderHandles, VertexShaderHandles;
// Store Shader Handles and State Block Tokens so they can be destroyed later to mirror D3D8 behavior
std::unordered_set<DWORD> PixelShaderHandles, VertexShaderHandles, StateBlockTokens;
unsigned int VertexShaderAndDeclarationCount = 0;
};

Expand Down
2 changes: 1 addition & 1 deletion vendor/d3d8to9/source/d3d8to9_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ HRESULT STDMETHODCALLTYPE Direct3D8::CreateDevice(UINT Adapter, D3DDEVTYPE Devic
if (FAILED(hr))
return hr;

*ppReturnedDeviceInterface = new Direct3DDevice8(this, DeviceInterface, (PresentParams.Flags & D3DPRESENTFLAG_DISCARD_DEPTHSTENCIL) != 0);
*ppReturnedDeviceInterface = new Direct3DDevice8(this, DeviceInterface, BehaviorFlags, (PresentParams.Flags & D3DPRESENTFLAG_DISCARD_DEPTHSTENCIL) != 0);

// Set default vertex declaration
DeviceInterface->SetFVF(D3DFVF_XYZ);
Expand Down
Loading