Skip to content

Commit

Permalink
Merge branch 'ajaus/create_function_send_option' into 'main'
Browse files Browse the repository at this point in the history
Special case the optional send/wait for return in calling most Create* functions.

See merge request lightspeedrtx/bridge-remix-nv!65
  • Loading branch information
nv-ajaus committed Jan 29, 2024
2 parents 745c463 + 2be539a commit b61a2ab
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 32 deletions.
8 changes: 8 additions & 0 deletions bridge.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
32 changes: 16 additions & 16 deletions src/client/d3d9_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ HRESULT Direct3DDevice9Ex_LSS<EnableSync>::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<bool EnableSync>
Expand Down Expand Up @@ -600,7 +600,7 @@ HRESULT Direct3DDevice9Ex_LSS<EnableSync>::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<bool EnableSync>
Expand Down Expand Up @@ -628,7 +628,7 @@ HRESULT Direct3DDevice9Ex_LSS<EnableSync>::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<bool EnableSync>
Expand Down Expand Up @@ -656,7 +656,7 @@ HRESULT Direct3DDevice9Ex_LSS<EnableSync>::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<bool EnableSync>
Expand All @@ -682,7 +682,7 @@ HRESULT Direct3DDevice9Ex_LSS<EnableSync>::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<bool EnableSync>
Expand All @@ -709,7 +709,7 @@ HRESULT Direct3DDevice9Ex_LSS<EnableSync>::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<bool EnableSync>
Expand Down Expand Up @@ -744,7 +744,7 @@ HRESULT Direct3DDevice9Ex_LSS<EnableSync>::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<bool EnableSync>
Expand Down Expand Up @@ -777,7 +777,7 @@ HRESULT Direct3DDevice9Ex_LSS<EnableSync>::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<bool EnableSync>
Expand Down Expand Up @@ -970,7 +970,7 @@ HRESULT Direct3DDevice9Ex_LSS<EnableSync>::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<bool EnableSync>
Expand Down Expand Up @@ -1728,7 +1728,7 @@ HRESULT Direct3DDevice9Ex_LSS<EnableSync>::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<bool EnableSync>
Expand Down Expand Up @@ -2380,7 +2380,7 @@ HRESULT Direct3DDevice9Ex_LSS<EnableSync>::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<bool EnableSync>
Expand Down Expand Up @@ -2495,7 +2495,7 @@ HRESULT Direct3DDevice9Ex_LSS<EnableSync>::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<bool EnableSync>
Expand Down Expand Up @@ -2882,7 +2882,7 @@ HRESULT Direct3DDevice9Ex_LSS<EnableSync>::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<bool EnableSync>
Expand Down Expand Up @@ -3270,7 +3270,7 @@ HRESULT Direct3DDevice9Ex_LSS<EnableSync>::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<bool EnableSync>
Expand Down Expand Up @@ -3305,7 +3305,7 @@ HRESULT Direct3DDevice9Ex_LSS<EnableSync>::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<bool EnableSync>
Expand Down Expand Up @@ -3338,7 +3338,7 @@ HRESULT Direct3DDevice9Ex_LSS<EnableSync>::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<bool EnableSync>
Expand Down
39 changes: 23 additions & 16 deletions src/server/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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;
}

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
10 changes: 10 additions & 0 deletions src/util/config/global_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ class GlobalOptions {
return get().sendAllServerResponses;
}

static bool getSendCreateFunctionServerResponses() {
return get().sendCreateFunctionServerResponses;
}

static bool getLogAllCalls() {
return get().logAllCalls;
}
Expand Down Expand Up @@ -284,6 +288,11 @@ class GlobalOptions {
// to wait for a response.
sendAllServerResponses = bridge_util::Config::getOption<bool>("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<bool>("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.
Expand Down Expand Up @@ -391,6 +400,7 @@ class GlobalOptions {
uint32_t serverDataQueueSize;
bool sendReadOnlyCalls;
bool sendAllServerResponses;
bool sendCreateFunctionServerResponses;
bool logAllCalls;
uint32_t commandTimeout;
uint32_t startupTimeout;
Expand Down
12 changes: 12 additions & 0 deletions src/util/util_bridgecommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b61a2ab

Please sign in to comment.