From 2be539a940d3e31a3825c7e2ab14844ec924fbb2 Mon Sep 17 00:00:00 2001 From: Alexander Jaus Date: Mon, 29 Jan 2024 14:42:57 -0800 Subject: [PATCH] Special case the optional send/wait for return in calling most Create* functions. --- bridge.conf | 8 +++++++ src/client/d3d9_device.cpp | 32 +++++++++++++------------- src/server/main.cpp | 39 +++++++++++++++++++------------- src/util/config/global_options.h | 10 ++++++++ src/util/util_bridgecommand.h | 12 ++++++++++ 5 files changed, 69 insertions(+), 32 deletions(-) diff --git a/bridge.conf b/bridge.conf index 950d885..22df39c 100644 --- a/bridge.conf +++ b/bridge.conf @@ -478,3 +478,11 @@ # Supported value: True, False # sendAllServerResponses = False + +# Create API calls from the client wait for a response from the server by default, +# but the wait can be disabled if both sendCreateFunctionServerResponses and +# sendAllServerResponses are set to False. + +# Supported value: True, False + +# sendCreateFunctionServerResponses = True diff --git a/src/client/d3d9_device.cpp b/src/client/d3d9_device.cpp index ea70d6f..44d0d5b 100644 --- a/src/client/d3d9_device.cpp +++ b/src/client/d3d9_device.cpp @@ -366,7 +366,7 @@ HRESULT Direct3DDevice9Ex_LSS::CreateAdditionalSwapChain(D3DPRESENT_ c.send_data((uint32_t) pLssSwapChain->getId()); c.send_data(sizeof(D3DPRESENT_PARAMETERS), &presentationParameters); } - WAIT_FOR_OPTIONAL_SERVER_RESPONSE("CreateAdditionalSwapChain()", D3DERR_NOTAVAILABLE, currentUID); + WAIT_FOR_OPTIONAL_CREATE_FUNCTION_SERVER_RESPONSE("CreateAdditionalSwapChain()", D3DERR_NOTAVAILABLE, currentUID); } template @@ -600,7 +600,7 @@ HRESULT Direct3DDevice9Ex_LSS::CreateTexture(UINT Width, UINT Height c.send_many(Width, Height, Levels, Usage, Format, Pool, (uint32_t) pLssTexture->getId()); } } - WAIT_FOR_OPTIONAL_SERVER_RESPONSE("CreateTexture()", D3DERR_INVALIDCALL, currentUID); + WAIT_FOR_OPTIONAL_CREATE_FUNCTION_SERVER_RESPONSE("CreateTexture()", D3DERR_INVALIDCALL, currentUID); } template @@ -628,7 +628,7 @@ HRESULT Direct3DDevice9Ex_LSS::CreateVolumeTexture(UINT Width, UINT c.send_many(Width, Height, Depth, Levels, Usage, Format, Pool, (uint32_t) pLssVolumeTexture->getId()); } } - WAIT_FOR_OPTIONAL_SERVER_RESPONSE("CreateVolumeTexture()", D3DERR_INVALIDCALL, currentUID); + WAIT_FOR_OPTIONAL_CREATE_FUNCTION_SERVER_RESPONSE("CreateVolumeTexture()", D3DERR_INVALIDCALL, currentUID); } template @@ -656,7 +656,7 @@ HRESULT Direct3DDevice9Ex_LSS::CreateCubeTexture(UINT EdgeLength, UI c.send_many(EdgeLength, Levels, Usage, Format, Pool, (uint32_t) pLssCubeTexture->getId()); } } - WAIT_FOR_OPTIONAL_SERVER_RESPONSE("CreateCubeTexture()", D3DERR_INVALIDCALL, currentUID); + WAIT_FOR_OPTIONAL_CREATE_FUNCTION_SERVER_RESPONSE("CreateCubeTexture()", D3DERR_INVALIDCALL, currentUID); } template @@ -682,7 +682,7 @@ HRESULT Direct3DDevice9Ex_LSS::CreateVertexBuffer(UINT Length, DWORD c.send_many(Length, Usage, FVF, Pool, (uint32_t) pLssVertexBuffer->getId()); } } - WAIT_FOR_OPTIONAL_SERVER_RESPONSE("CreateVertexBuffer()", D3DERR_INVALIDCALL, currentUID); + WAIT_FOR_OPTIONAL_CREATE_FUNCTION_SERVER_RESPONSE("CreateVertexBuffer()", D3DERR_INVALIDCALL, currentUID); } template @@ -709,7 +709,7 @@ HRESULT Direct3DDevice9Ex_LSS::CreateIndexBuffer(UINT Length, DWORD c.send_many(Length, Usage, Format, Pool, (uint32_t) pLssIndexBuffer->getId()); } } - WAIT_FOR_OPTIONAL_SERVER_RESPONSE("CreateIndexBuffer()", D3DERR_INVALIDCALL, currentUID); + WAIT_FOR_OPTIONAL_CREATE_FUNCTION_SERVER_RESPONSE("CreateIndexBuffer()", D3DERR_INVALIDCALL, currentUID); } template @@ -744,7 +744,7 @@ HRESULT Direct3DDevice9Ex_LSS::CreateRenderTarget(UINT Width, UINT H c.send_many(Width, Height, Format, MultiSample, MultisampleQuality, Lockable, pLssSurface->getId()); } } - WAIT_FOR_OPTIONAL_SERVER_RESPONSE("CreateRenderTarget()", D3DERR_INVALIDCALL, currentUID); + WAIT_FOR_OPTIONAL_CREATE_FUNCTION_SERVER_RESPONSE("CreateRenderTarget()", D3DERR_INVALIDCALL, currentUID); } template @@ -777,7 +777,7 @@ HRESULT Direct3DDevice9Ex_LSS::CreateDepthStencilSurface(UINT Width, c.send_many(Width, Height, Format, MultiSample, MultisampleQuality, Discard, pLssSurface->getId()); } } - WAIT_FOR_OPTIONAL_SERVER_RESPONSE("CreateDepthStencilSurface()", D3DERR_INVALIDCALL, currentUID); + WAIT_FOR_OPTIONAL_CREATE_FUNCTION_SERVER_RESPONSE("CreateDepthStencilSurface()", D3DERR_INVALIDCALL, currentUID); } template @@ -970,7 +970,7 @@ HRESULT Direct3DDevice9Ex_LSS::CreateOffscreenPlainSurface(UINT Widt c.send_many(Width, Height, Format, Pool, pLssSurface->getId()); } } - WAIT_FOR_OPTIONAL_SERVER_RESPONSE("CreateOffscreenPlainSurface()", D3DERR_INVALIDCALL, currentUID); + WAIT_FOR_OPTIONAL_CREATE_FUNCTION_SERVER_RESPONSE("CreateOffscreenPlainSurface()", D3DERR_INVALIDCALL, currentUID); } template @@ -1728,7 +1728,7 @@ HRESULT Direct3DDevice9Ex_LSS::CreateStateBlock(D3DSTATEBLOCKTYPE Ty c.send_many(Type, (uint32_t) pLssSB->getId()); } } - WAIT_FOR_OPTIONAL_SERVER_RESPONSE("CreateStateBlock()", D3DERR_INVALIDCALL, currentUID); + WAIT_FOR_OPTIONAL_CREATE_FUNCTION_SERVER_RESPONSE("CreateStateBlock()", D3DERR_INVALIDCALL, currentUID); } template @@ -2380,7 +2380,7 @@ HRESULT Direct3DDevice9Ex_LSS::CreateVertexDeclaration(CONST D3DVERT c.send_data((uint32_t) pLssVtxDecl->getId()); } } - WAIT_FOR_OPTIONAL_SERVER_RESPONSE("CreateVertexDeclaration()", D3DERR_INVALIDCALL, currentUID); + WAIT_FOR_OPTIONAL_CREATE_FUNCTION_SERVER_RESPONSE("CreateVertexDeclaration()", D3DERR_INVALIDCALL, currentUID); } template @@ -2495,7 +2495,7 @@ HRESULT Direct3DDevice9Ex_LSS::CreateVertexShader(CONST DWORD* pFunc c.send_data(dataSize, (void*) pFunction); } - WAIT_FOR_OPTIONAL_SERVER_RESPONSE("CreateVertexShader()", D3DERR_INVALIDCALL, currentUID); + WAIT_FOR_OPTIONAL_CREATE_FUNCTION_SERVER_RESPONSE("CreateVertexShader()", D3DERR_INVALIDCALL, currentUID); } template @@ -2882,7 +2882,7 @@ HRESULT Direct3DDevice9Ex_LSS::CreatePixelShader(CONST DWORD* pFunct c.send_data(dataSize); c.send_data(dataSize, (void*) pFunction); } - WAIT_FOR_OPTIONAL_SERVER_RESPONSE("CreatePixelShader()", D3DERR_INVALIDCALL, currentUID); + WAIT_FOR_OPTIONAL_CREATE_FUNCTION_SERVER_RESPONSE("CreatePixelShader()", D3DERR_INVALIDCALL, currentUID); } template @@ -3270,7 +3270,7 @@ HRESULT Direct3DDevice9Ex_LSS::CreateRenderTargetEx(UINT Width, UINT c.send_many(Width, Height, Format, MultiSample, MultisampleQuality, Lockable, Usage, pLssSurface->getId()); } - WAIT_FOR_OPTIONAL_SERVER_RESPONSE("CreateRenderTargetEx()", D3DERR_INVALIDCALL, currentUID); + WAIT_FOR_OPTIONAL_CREATE_FUNCTION_SERVER_RESPONSE("CreateRenderTargetEx()", D3DERR_INVALIDCALL, currentUID); } template @@ -3305,7 +3305,7 @@ HRESULT Direct3DDevice9Ex_LSS::CreateOffscreenPlainSurfaceEx(UINT Wi c.send_many(Width, Height, Format, Pool, Usage, pLssSurface->getId()); } - WAIT_FOR_OPTIONAL_SERVER_RESPONSE("CreateOffscreenPlainSurfaceEx()", D3DERR_INVALIDCALL, currentUID); + WAIT_FOR_OPTIONAL_CREATE_FUNCTION_SERVER_RESPONSE("CreateOffscreenPlainSurfaceEx()", D3DERR_INVALIDCALL, currentUID); } template @@ -3338,7 +3338,7 @@ HRESULT Direct3DDevice9Ex_LSS::CreateDepthStencilSurfaceEx(UINT Widt c.send_many(Width, Height, Format, MultiSample, MultisampleQuality, Discard, Usage, pLssSurface->getId()); } - WAIT_FOR_OPTIONAL_SERVER_RESPONSE("CreateDepthStencilSurfaceEx()", D3DERR_INVALIDCALL, currentUID); + WAIT_FOR_OPTIONAL_CREATE_FUNCTION_SERVER_RESPONSE("CreateDepthStencilSurfaceEx()", D3DERR_INVALIDCALL, currentUID); } template diff --git a/src/server/main.cpp b/src/server/main.cpp index 2a474de..783a124 100644 --- a/src/server/main.cpp +++ b/src/server/main.cpp @@ -65,6 +65,13 @@ using namespace bridge_util; } \ } +#define SEND_OPTIONAL_CREATE_FUNCTION_SERVER_RESPONSE(hresult, uid) { \ + if (GlobalOptions::getSendCreateFunctionServerResponses() || GlobalOptions::getSendAllServerResponses()) { \ + ServerMessage c(Commands::Bridge_Response, uid); \ + c.send_data(hresult); \ + } \ + } + #define PULL(type, name) const auto& name = (type)DeviceBridge::get_data() #define PULL_I(name) PULL(INT, name) #define PULL_U(name) PULL(UINT, name) @@ -309,7 +316,7 @@ void ProcessDeviceCommandQueue() { gpD3DResources[pHandle] = pSurface; } assert(SUCCEEDED(hresult)); - SEND_OPTIONAL_SERVER_RESPONSE(hresult, currentUID); + SEND_OPTIONAL_CREATE_FUNCTION_SERVER_RESPONSE(hresult, currentUID); break; } case IDirect3DDevice9Ex_CreateOffscreenPlainSurfaceEx: @@ -327,7 +334,7 @@ void ProcessDeviceCommandQueue() { gpD3DResources[pHandle] = pSurface; } assert(SUCCEEDED(hresult)); - SEND_OPTIONAL_SERVER_RESPONSE(hresult, currentUID); + SEND_OPTIONAL_CREATE_FUNCTION_SERVER_RESPONSE(hresult, currentUID); break; } case IDirect3DDevice9Ex_CreateDepthStencilSurfaceEx: @@ -347,7 +354,7 @@ void ProcessDeviceCommandQueue() { gpD3DResources[pHandle] = pSurface; } assert(SUCCEEDED(hresult)); - SEND_OPTIONAL_SERVER_RESPONSE(hresult, currentUID); + SEND_OPTIONAL_CREATE_FUNCTION_SERVER_RESPONSE(hresult, currentUID); break; } @@ -517,7 +524,7 @@ void ProcessDeviceCommandQueue() { if (SUCCEEDED(hresult)) { gpD3DSwapChains[pHandle] = pSwapChain; } - SEND_OPTIONAL_SERVER_RESPONSE(hresult, currentUID); + SEND_OPTIONAL_CREATE_FUNCTION_SERVER_RESPONSE(hresult, currentUID); break; } case IDirect3DDevice9Ex_GetSwapChain: @@ -656,7 +663,7 @@ void ProcessDeviceCommandQueue() { gpD3DResources[pHandle] = pTexture; } assert(SUCCEEDED(hresult)); - SEND_OPTIONAL_SERVER_RESPONSE(hresult, currentUID); + SEND_OPTIONAL_CREATE_FUNCTION_SERVER_RESPONSE(hresult, currentUID); break; } case IDirect3DDevice9Ex_CreateVolumeTexture: @@ -676,7 +683,7 @@ void ProcessDeviceCommandQueue() { gpD3DResources[pHandle] = pVolumeTexture; } assert(SUCCEEDED(hresult)); - SEND_OPTIONAL_SERVER_RESPONSE(hresult, currentUID); + SEND_OPTIONAL_CREATE_FUNCTION_SERVER_RESPONSE(hresult, currentUID); break; } case IDirect3DDevice9Ex_CreateCubeTexture: @@ -694,7 +701,7 @@ void ProcessDeviceCommandQueue() { gpD3DResources[pHandle] = pCubeTexture; } assert(SUCCEEDED(hresult)); - SEND_OPTIONAL_SERVER_RESPONSE(hresult, currentUID); + SEND_OPTIONAL_CREATE_FUNCTION_SERVER_RESPONSE(hresult, currentUID); break; } case IDirect3DDevice9Ex_CreateVertexBuffer: @@ -711,7 +718,7 @@ void ProcessDeviceCommandQueue() { gpD3DResources[pHandle] = pVertexBuffer; } assert(SUCCEEDED(hresult)); - SEND_OPTIONAL_SERVER_RESPONSE(hresult, currentUID); + SEND_OPTIONAL_CREATE_FUNCTION_SERVER_RESPONSE(hresult, currentUID); break; } case IDirect3DDevice9Ex_CreateIndexBuffer: @@ -728,7 +735,7 @@ void ProcessDeviceCommandQueue() { gpD3DResources[pHandle] = pIndexBuffer; } assert(SUCCEEDED(hresult)); - SEND_OPTIONAL_SERVER_RESPONSE(hresult, currentUID); + SEND_OPTIONAL_CREATE_FUNCTION_SERVER_RESPONSE(hresult, currentUID); break; } case IDirect3DDevice9Ex_CreateRenderTarget: @@ -747,7 +754,7 @@ void ProcessDeviceCommandQueue() { gpD3DResources[pHandle] = pSurface; } assert(SUCCEEDED(hresult)); - SEND_OPTIONAL_SERVER_RESPONSE(hresult, currentUID); + SEND_OPTIONAL_CREATE_FUNCTION_SERVER_RESPONSE(hresult, currentUID); break; } case IDirect3DDevice9Ex_CreateDepthStencilSurface: @@ -766,7 +773,7 @@ void ProcessDeviceCommandQueue() { gpD3DResources[pHandle] = pSurface; } assert(SUCCEEDED(hresult)); - SEND_OPTIONAL_SERVER_RESPONSE(hresult, currentUID); + SEND_OPTIONAL_CREATE_FUNCTION_SERVER_RESPONSE(hresult, currentUID); break; } case IDirect3DDevice9Ex_UpdateSurface: @@ -870,7 +877,7 @@ void ProcessDeviceCommandQueue() { gpD3DResources[pHandle] = pSurface; } assert(SUCCEEDED(hresult)); - SEND_OPTIONAL_SERVER_RESPONSE(hresult, currentUID); + SEND_OPTIONAL_CREATE_FUNCTION_SERVER_RESPONSE(hresult, currentUID); break; } case IDirect3DDevice9Ex_SetRenderTarget: @@ -1066,7 +1073,7 @@ void ProcessDeviceCommandQueue() { gpD3DStateBlocks[pHandle] = pSB; } assert(SUCCEEDED(hresult)); - SEND_OPTIONAL_SERVER_RESPONSE(hresult, currentUID); + SEND_OPTIONAL_CREATE_FUNCTION_SERVER_RESPONSE(hresult, currentUID); break; } case IDirect3DDevice9Ex_BeginStateBlock: @@ -1262,7 +1269,7 @@ void ProcessDeviceCommandQueue() { gpD3DVertexDeclarations[pHandle] = pDecl; } assert(SUCCEEDED(hresult)); - SEND_OPTIONAL_SERVER_RESPONSE(hresult, currentUID); + SEND_OPTIONAL_CREATE_FUNCTION_SERVER_RESPONSE(hresult, currentUID); break; } case IDirect3DDevice9Ex_SetVertexDeclaration: @@ -1304,7 +1311,7 @@ void ProcessDeviceCommandQueue() { gpD3DVertexShaders[pHandle] = pShader; } assert(SUCCEEDED(hresult)); - SEND_OPTIONAL_SERVER_RESPONSE(hresult, currentUID); + SEND_OPTIONAL_CREATE_FUNCTION_SERVER_RESPONSE(hresult, currentUID); break; } case IDirect3DDevice9Ex_SetVertexShader: @@ -1422,7 +1429,7 @@ void ProcessDeviceCommandQueue() { gpD3DPixelShaders[pHandle] = pShader; } assert(SUCCEEDED(hresult)); - SEND_OPTIONAL_SERVER_RESPONSE(hresult, currentUID); + SEND_OPTIONAL_CREATE_FUNCTION_SERVER_RESPONSE(hresult, currentUID); break; } case IDirect3DDevice9Ex_SetPixelShader: diff --git a/src/util/config/global_options.h b/src/util/config/global_options.h index 3c68d8d..c9f18ee 100644 --- a/src/util/config/global_options.h +++ b/src/util/config/global_options.h @@ -102,6 +102,10 @@ class GlobalOptions { return get().sendAllServerResponses; } + static bool getSendCreateFunctionServerResponses() { + return get().sendCreateFunctionServerResponses; + } + static bool getLogAllCalls() { return get().logAllCalls; } @@ -284,6 +288,11 @@ class GlobalOptions { // to wait for a response. sendAllServerResponses = bridge_util::Config::getOption("sendAllServerResponses", false); + // Create API calls from the client wait for a response from the server by default, + // but the wait can be disabled if both sendCreateFunctionServerResponses and + // sendAllServerResponses are set to False. + sendCreateFunctionServerResponses = bridge_util::Config::getOption("sendCreateFunctionServerResponses", true); + // In most cases it is only useful to log those D3D calls that have not been // implemented on the server side yet, but by toggling this you will get the // first usage of all D3D calls logged, including the implemented ones. @@ -391,6 +400,7 @@ class GlobalOptions { uint32_t serverDataQueueSize; bool sendReadOnlyCalls; bool sendAllServerResponses; + bool sendCreateFunctionServerResponses; bool logAllCalls; uint32_t commandTimeout; uint32_t startupTimeout; diff --git a/src/util/util_bridgecommand.h b/src/util/util_bridgecommand.h index dd3b786..025f684 100644 --- a/src/util/util_bridgecommand.h +++ b/src/util/util_bridgecommand.h @@ -59,6 +59,18 @@ extern bool gbBridgeRunning; } \ } +#define WAIT_FOR_OPTIONAL_CREATE_FUNCTION_SERVER_RESPONSE(func, value, uidVal) \ + { \ + if (GlobalOptions::getSendCreateFunctionServerResponses() || GlobalOptions::getSendAllServerResponses()) { \ + WAIT_FOR_SERVER_RESPONSE(func, value, uidVal) \ + HRESULT res = (HRESULT) DeviceBridge::get_data(); \ + DeviceBridge::pop_front(); \ + return res; \ + } else { \ + return D3D_OK; \ + } \ + } + using namespace bridge_util; // Used structs over class enum for explicit type names while debugging